今天升级10.10 发生问题:错误提示
E:Error, pkgProblemResolver::Resolve generated breaks, this may be caused by held packages.
感觉很奇怪,以前用 update-manager都没有出现问题。
上网查看了一些帖子发现有很多朋友都有这个问题,但是并没有得到正面到解答。只知道可能是某个包冲突了。
首先禁用了第三方源。但是故障依旧。
查看升级日志发现故障发生在
Investigating xserver-xorg-video-all
Package xserver-xorg-video-all has broken Depends on xserver-xorg-video-tseng
Considering xserver-xorg-video-tseng 1 as a solution to xserver-xorg-video-all 10005
Added xserver-xorg-video-tseng to the remove list
Fixing xserver-xorg-video-all via keep of xserver-xorg-video-tseng

后来在google上发现了解答:
卸载xserver-xorg-video-nouveau后再次升级成功。

老电脑,没有光驱,无意间想起网络安装方式,现将整个安装过程整理如下:
感谢poet前辈的指引
1、安装apache,将ubuntu server iso挂载到apache服务目录中
下面给出设置 Ubuntu Linux 服务器的办法:

先把下载的映像放到这个服务器上,我们假定放到 $HOME/cd.iso

然后: sudo apt-get apache2 (已经安装了的可以省略此步骤)

然后: sudo mount -o loop $HOME/cd.iso /mnt

然后: sudo ln -s /mnt /var/www/ubunutu

做好上面几个步骤之后,一个Linux服务器就架好了。
2、由于系统原装有grub,现ubuntu中grub已升级为2版本,因此原帖的内容要更新一下:
首先下载http://192.168.1.1/ubuntu/install/netboot/ubuntu-installer/i386/initrd.gz
和vmlinuz文件到硬盘根目录中
之后重启,grub2菜单时按c键进入命令行模式,输入以下命令:
linux (hd0,1)/vmlinuz root=/dev/ram0 ramdisk_size=256000
initrd (hd0,1)/initrd.gz
boot
之后即可进入安装程序引导。
3、手动选择安装源:
将安装源手动选择成apache服务器主机(不选也可,即为从internet下载)
按提示安装即可。

Overview:

1, HTTP1.1 protocal

2, C# multi-threaded server

3, using reflection to achieve Active Website

Details:

1, HTTP protocol

We all know that HTTP protocol is used by web browsers(IE,chrome,FF,Opera…),web server to transfer informations.

All web pages,files,pictures,videos are carried out through the HTTP protocol.

Need to do:

HTTP GET request to achieve our main response, including the 200 OK and 404Not found.

When the browser request a dynamic page, server use HTTP POST handling the information.

Transport layer Of the OSI model use 80 port and TCP for sending and recving HTTP package.

HTTP Response Example:

switch (strHttpActionPieces [0])
(
case "GET":
/ / Get directory
string strPath = strHttpActionPieces [1];
AddLog ("HTTP Get request received");
/ / If the Get request is "/" at the end is not treated to remove the symbol
if (strPath.EndsWith ("/"))
(
strPath = strPath.Remove (strPath.Length-1);
)
/ / Check whether the URL with parameters
string strArgues;
if (strPath.Contains ("?"))
(
/ / If the incidental parameters, parameters will be separated
int intUrlCount = strPath.Length;
int intSeperatorIndex = strPath.IndexOf ('?');
string strArgument = strPath.Substring (intSeperatorIndex +1); / / used to save the parameters
AddLog ("the current access to the virtual path parameters:" + strArgument);
strPath = strPath.Substring (0, intSeperatorIndex);
AddLog ("virtual path for the current request:" + strPath);
strArgues = strArgument;
)
else
(
/ / Request parameter not included
AddLog ("the current request URL:" + strPath);
strArgues = "";
)
/ / Will convert the requested URL "/" to "\ \"
strPath = strPath.Replace ("/", "\ \");
/ / Parameters for the time being not to do treatment first
/ / Detect the existence of the virtual path to expand the name of development if there were, then open the URL points to the file
/ / If there is to expand the name of said application URL for the directory, then increase the default file for directory: index.html)
if (! strPath.Contains ("."))
(
/ / URL does not exist to expand the application name
strPath + = "\ \ index.html";
)
/ / Test whether the request is nsp page, and if so, to expand into a dll name
strPath = strPath.Replace (". nsp", ". dll");

/ / Determine whether the requested file exists
Debug.WriteLine ("is returned:" + _root + strPath);
if (! File.Exists (_root + strPath))
(
/ / File does not exist, then return to 404NOT Found
AddLog ("does not exist" + _root + strPath + ", return 404 Not Found response");
const string httpContent = "<html> <head> </ head> <body> <h1> Can't Find Your Page </ h1> </ body> </ html>";
var notFoundMemStream = new MemoryStream ();
var streamWriter = new StreamWriter (notFoundMemStream);
streamWriter.WriteLine ("HTTP/1.1 404 Not Found");
streamWriter.WriteLine ("Date:" + DateTime.UtcNow);
streamWriter.WriteLine ("Server: ww2521's");
streamWriter.WriteLine ("Content-Length:" + httpContent.Length);
streamWriter.WriteLine ("Keep-Alive: timeout = 10, max = 10");
streamWriter.WriteLine ("Connection: Keep-Alive");
streamWriter.WriteLine ("Content-Type: text / html; Charset = UTF-8");
streamWriter.WriteLine ("");
streamWriter.WriteLine (httpContent);
streamWriter.Flush ();
SendFromMemStreamUseSocket (mySocket, notFoundMemStream);
mySocket.Close ();
return;
)

2, C # implementation of multi-threaded server

To ensure a timely response for multi-user, of course, multi-threaded approach. My design architecture are as follows:

UI thread: User UI thread, do not write your own

Listen Thread: The machine used to monitor port 80, and derived sub-thread to respond to user requests. Derived after the child thread to re-listen.

User requests to respond to child thread: monitor thread is derived for a single user's request processing. After processing, automatic termination and recycling of resources.

/ / / <summary>
/ / / Open the monitor master thread
/ / / </ Summary>
private void OpenListenThread ()
(
IPAddress ipa = IPAddress.Parse (_hostIp);
_myListener = new TcpListener (ipa, int.Parse (_hostProt));
try
(
_myListener.Start ();
)
catch (Exception e)
(
AddLog (e.ToString ());
return;
)
Debug.WriteLine (_hostIp);
Debug.WriteLine ("Start listening thread:" + _hostIp + ":" + _hostProt);
AddLog ("Start listening thread:" + _hostIp + ":" + _hostProt);
/ / Open listening

while (true)
(
while (! _myListener.Pending ())
(
)
Socket mySocket = _myListener.AcceptSocket ();
Thread.Sleep (100);
AddLog ("received a request .... Are analyzing the request ....");
DelegateDoThread doThread = DoThread;
doThread.Invoke (mySocket);
AddLog ("the end of processing threads created to continue to listen ...");
)
)

/ / / <summary>
/ / / When a connection request comes, the socket to send to this method and derive a new thread processing
/ / / </ Summary>
/ / / <param Name="mySocket"> send socket </ param>
private void DoThread (Socket mySocket)
(
var cache = new byte [1024];
if (mySocket.Available> 0)
(
mySocket.Receive (cache);
)

var memStream = new MemoryStream (cache);
var streamReader = new StreamReader (memStream);
/ / Of HTTP request
string strHttpAction = streamReader.ReadLine ();
string [] strHttpActionPieces = strHttpAction.Split ('');
switch (strHttpActionPieces [0])
(
case "GET":
/ / Get directory

3, using reflection to achieve dynamic pages

In JSP SERVERLET,A request send to a serverlet,and the serverlet handle it,send response to browser.

We create a Interface here to standardlization dll files.

 

public interface IServerLet
(
string Name (get;)
string DoPost (string prarms);
string DoGet (string prarms);
)

 

Response to child thread in the request to call DoPost and DoGet to be processed.Method using dynamic invocation LateBinding user form.

severlet example:

namespace ServerLet
(
public class ServerLetMainClass: IServerLet
(
public string Name
(
get
(
return "DemoServerPage by ww2521";
)
)
public string DoPost (string param)
(
string [] paramEvals = param.Split ('&');
var dictParam = new Dictionary <string, string> ();
foreach (string paramEval in paramEvals)
(
string [] parts = paramEval.Split ('=');
dictParam.Add (parts [0], parts [1]);
)
var stringBuilder = new StringBuilder ();
stringBuilder.Append ("<html> <head> <title> From DemoServerLet </ title> </ head> <body>");
stringBuilder.Append ("your input detail:");
foreach (KeyValuePair <string, string> pair in dictParam)
(
stringBuilder.Append ("argu:" + pair.Key +",");
stringBuilder.Append ("value:" + pair.Value + "<br/>");
)
stringBuilder.Append ("</ body> </ html>");
return stringBuilder.ToString ();
)
public string DoGet (string param)
(
if (param == "")
return
@ "<html> <head> <title> ServerLet Demo </ title> </ head> <body> <form action='ServerLet.nsp'> <table> <tr> <td> Argu1: </ td> < td> <input type='text' name='username'/> </ td> </ tr> <tr> <td> Argu2: </ td> <td> <input type = 'text'name =' username2 '/> </ td> </ tr> <tr> <td colspan='2'> <input type='submit' value='submit' /> </ td> </ tr> </ table> </ form> </ body> </ html> ";
return DoPost (param);
)
)
)

ServerLet call methods:

Assembly nspAssembly = Assembly.LoadFrom (_root + strPath);
Type nspServerLetType = nspAssembly.GetType ("ServerLet.ServerLetMainClass");
object serverLetMainClass = Activator.CreateInstance (nspServerLetType);
MethodInfo getmethod = nspServerLetType.GetMethod ("DoGet");
var contextstr = (string) getmethod.Invoke (serverLetMainClass, new object [] (strArgues));
var contextMemStream = new MemoryStream ();
var contextMemWriter = new StreamWriter (contextMemStream);
contextMemWriter.WriteLine ("HTTP/1.1 200 OK");
contextMemWriter.WriteLine ("Date:" + DateTime.UtcNow);
contextMemWriter.WriteLine ("Server: ww2521's");
contextMemWriter.WriteLine ("Content-Length:" + contextstr.Length);
contextMemWriter.WriteLine ("Keep-Alive: timeout = 10, max = 10");
contextMemWriter.WriteLine ("Connection: Keep-Alive");
contextMemWriter.WriteLine ("Content-Type: text / html; Charset = UTF-8");
contextMemWriter.WriteLine ("");
contextMemWriter.WriteLine (contextstr);
contextMemWriter.Flush ();
SendFromMemStreamUseSocket (mySocket, contextMemStream);
mySocket.Close ();

That’s all.

(.dll file in URL like:http://abc.com/serverlet.dll is not good looking,so I maped it to .nsp,like http://abc.com/serverlet.nsp stand for “dot net server page… Just joking).

Thank you all.

This is my first artical written in English,sorry for my English speaking….

Replys are welcome.

image

概述:

1、HTTP1.1协议

2、C#多线程服务器实现

3、用反射实现动态网页制作

详细内容:

1、HTTP协议

我们知道HTTP协议是浏览互联网的协议标准,web浏览器其实也就是web服务器的客户端,服务器与浏览器之间的通讯,是通过HTTP协议来进行的。

关于HTTP的各字段及其意义大家请google,在此不再赘述。

我们主要实现HTTP GET请求的应答,包括200 OK及 404Not found。

当药实现动态网站时,也要加上HTTP POST的处理事件。

HTTP默认是通过80端口进行通讯的。

HTTP响应示例:

switch(strHttpActionPieces[0])
               {
                   case "GET":
                       //获取目录
                       string strPath = strHttpActionPieces[1];
                       AddLog("接收到HTTP Get请求");
                       //如果Get请求是以"/"结尾则去掉该符号不做处理
                       if(strPath.EndsWith("/"))
                       {
                           strPath=strPath.Remove(strPath.Length-1);
                       }
                       //检查是否URL附带参数
                       string strArgues;
                       if(strPath.Contains("?"))
                       {
                           //如果附带参数,则将参数分离
                           int intUrlCount = strPath.Length;
                           int intSeperatorIndex = strPath.IndexOf('?');
                           string strArgument=strPath.Substring(intSeperatorIndex+1);//用于保存参数
                           AddLog("当前获取的虚拟路径参数为:" + strArgument);
                           strPath = strPath.Substring(0, intSeperatorIndex);
                           AddLog("当前请求的虚拟路径为:"+strPath);
                           strArgues = strArgument;
                       }
                       else
                       {
                           //不附带参数的请求
                           AddLog("当前请求URL:"+strPath);
                           strArgues = "";
                       }
                       //将请求的URL转换"/"为"\\"
                       strPath = strPath.Replace("/", "\\");
                       //暂且先不将参数做处理
                       //检测虚拟路径是否存在拓展名,若存在拓展名,则打开其URL指向的文件
                       //若不存在拓展名,则表示申请的URL为目录,则为其目录增加默认文件:index.html)
                       if(!strPath.Contains("."))
                       {
                           //申请的URL不存在拓展名
                           strPath += "\\index.html";
                       }
                       //检测是否请求的是nsp页面,若是,则转化为dll拓展名
                       strPath=strPath.Replace(".nsp", ".dll");

                   //判断是否存在请求的文件
                   Debug.WriteLine("正在返回:"+_root+strPath);   
                   if(!File.Exists(_root+strPath))
                       {
                           //不存在文件,则返回404NOT Found
                           AddLog("不存在"+_root+strPath+",返回404 Not Found响应");
                           const string httpContent = "<html><head></head><body><h1>Can't Find Your Page</h1></body></html>";
                           var notFoundMemStream = new MemoryStream();
                           var streamWriter=new StreamWriter(notFoundMemStream);
                           streamWriter.WriteLine("HTTP/1.1 404 Not Found");
                           streamWriter.WriteLine("Date: "+DateTime.UtcNow);
                           streamWriter.WriteLine("Server: ww2521's");
                           streamWriter.WriteLine("Content-Length: "+httpContent.Length);
                           streamWriter.WriteLine("Keep-Alive: timeout=10, max=10");
                           streamWriter.WriteLine("Connection: Keep-Alive");
                           streamWriter.WriteLine("Content-Type: text/html; Charset=UTF-8");
                           streamWriter.WriteLine("");
                           streamWriter.WriteLine(httpContent);
                           streamWriter.Flush();
                           SendFromMemStreamUseSocket(mySocket, notFoundMemStream);
                           mySocket.Close();
                           return;
                       }

2、C#的多线程服务器实现

为了保证能为多用户及时响应,当然要采用多线程的处理方式。我的设计架构如下:

UI线程:用户UI线程,不必自己编写

监听线程:用于监听本机80端口,及派生用户请求响应子线程。派生子线程后继续重新监听。

用户请求响应子线程:被监听线程所派生,用于单个用户的请求的处理工作。处理结束后,自动终止并回收资源。

/// <summary>
/// 开启监听母线程
/// </summary>
private void OpenListenThread()
{
    IPAddress ipa = IPAddress.Parse(_hostIp);
    _myListener = new TcpListener(ipa, int.Parse(_hostProt));
    try
    {
        _myListener.Start();
    }
    catch(Exception e)
    {
        AddLog(e.ToString());
        return;
    }
    Debug.WriteLine(_hostIp);
    Debug.WriteLine("开始监听线程:" + _hostIp + ":" + _hostProt);
    AddLog("开始监听线程:" + _hostIp + ":" + _hostProt);
    //开启监听

    while (true)
    {
        while (!_myListener.Pending())
        {
        }
        Socket mySocket = _myListener.AcceptSocket();
        Thread.Sleep(100);
        AddLog("接收到请求....正在分析请求....");
        DelegateDoThread doThread = DoThread;
        doThread.Invoke(mySocket);
        AddLog("创建处理线程结束,继续监听...");
    }
}

 

/// <summary>
     /// 当有连接请求到来时,将socket发送到此方法中并派生新线程处理
     /// </summary>
     /// <param name="mySocket">发送的套接字</param>
     private void DoThread(Socket mySocket)
     {
         var cache = new byte[1024];
         if (mySocket.Available > 0)
         {
             mySocket.Receive(cache);
         }

         var memStream = new MemoryStream(cache);
         var streamReader=new StreamReader(memStream);
         //分析HTTP请求
             string strHttpAction = streamReader.ReadLine();
             string[] strHttpActionPieces = strHttpAction.Split(' ');
             switch(strHttpActionPieces[0])
             {
                 case "GET":
                     //获取目录

3、用反射实现动态网页

借用JSP的SERVERLET思想,创建接口

    public interface IServerLet
    {
        string Name { get; }
        string DoPost(string prarms);
        string DoGet(string prarms);
    }

分别用于实现POST,GET响应

在请求响应子线程中调用DoPost和DoGet来进行处理。使用LateBinding方法动态调用用户组建。

severlet示例:

namespace ServerLet
{
    public class ServerLetMainClass:IServerLet
    {
        public string Name
        {
            get
            {
                return "DemoServerPage by ww2521";
            }
        }
        public string DoPost(string param)
        {
            string[] paramEvals = param.Split('&');
            var dictParam=new Dictionary<string, string>();
            foreach (string paramEval in paramEvals)
            {
                string[] parts = paramEval.Split('=');
                dictParam.Add(parts[0],parts[1]);
            }
            var stringBuilder=new StringBuilder();
            stringBuilder.Append("<html><head><title>From DemoServerLet</title></head><body>");
            stringBuilder.Append("your input detail:");
            foreach (KeyValuePair<string, string> pair in dictParam)
            {
                stringBuilder.Append("argu:" + pair.Key+",");
                stringBuilder.Append("value:" + pair.Value + "<br/>");
            }
            stringBuilder.Append("</body></html>");
            return stringBuilder.ToString();
        }
        public string DoGet(string param)
        {
            if (param == "")
                return
                    @"<html><head><title>ServerLet Demo</title></head><body><form action='ServerLet.nsp'><table><tr><td>Argu1:</td><td><input type='text' name='username'/></td></tr><tr><td>Argu2:</td><td><input type='text'name='username2' /></td></tr><tr><td colspan='2'><input type='submit' value='submit' /></td></tr></table></form></body></html>";
           return DoPost(param);
        }
    }
}

ServerLet的调用方法:

Assembly nspAssembly = Assembly.LoadFrom(_root + strPath);
                               Type nspServerLetType = nspAssembly.GetType("ServerLet.ServerLetMainClass");
                               object serverLetMainClass = Activator.CreateInstance(nspServerLetType);
                               MethodInfo getmethod = nspServerLetType.GetMethod("DoGet");
                               var contextstr = (string) getmethod.Invoke(serverLetMainClass, new object[] {strArgues});
                               var contextMemStream = new MemoryStream();
                               var contextMemWriter = new StreamWriter(contextMemStream);
                               contextMemWriter.WriteLine("HTTP/1.1 200 OK");
                               contextMemWriter.WriteLine("Date: " + DateTime.UtcNow);
                               contextMemWriter.WriteLine("Server: ww2521's");
                               contextMemWriter.WriteLine("Content-Length: " + contextstr.Length);
                               contextMemWriter.WriteLine("Keep-Alive: timeout=10, max=10");
                               contextMemWriter.WriteLine("Connection: Keep-Alive");
                               contextMemWriter.WriteLine("Content-Type: text/html; Charset=UTF-8");
                               contextMemWriter.WriteLine("");
                               contextMemWriter.WriteLine(contextstr);
                               contextMemWriter.Flush();
                               SendFromMemStreamUseSocket(mySocket, contextMemStream);
                               mySocket.Close();

这样就OK了。

还有就是生成的serverlet拓展名是.dll,为了美观起见,在服务器端映射为.nsp,意为 dot net server page :P 娱乐一下……

欢迎大家抛砖头。

最近为了写网络工程技术的实验,做了一个简单的http服务器,在处理图片过程中发现了一些问题,

由于需要对比分析本机服务器和本机客户端之间的传送数据包,所以用wireshark来抓包。但是在

抓包的过程中发现根本无法实现,动了一番脑筋之后想到了一个方法:就是将本机路由到网关再路由

回来。

具体方法如下:

以管理员身份运行cmd,然后route add 本机ip mask 255.255.255.255 网关ip

ok,wireshark一下。搞定。

翻译自:http://www.c-sharpcorner.com/UploadFile/archak/704/Default.aspx欢迎转裁,但请保留链接信息。

作者: 

翻译:ww2521

问题阐述
The problem
有很多情况,我们想要检测一个postback事件是不是由于F5的按动造成的的。
There are situations where we would like to detect if the post back is from a form interaction (i.e. submit or button clicks) or is it by hitting the browser F5 refresh button.

许多人会站起来说,检测Ispostback属性不就完啦。IsPostback属性值是有优先值的。就像如果页面一次postback之前刷新,那么该属性值事true,但是如果界面在刷新前没有postback,该属性值将会是false。

Many of them will jump saying how about checking 'Ispostback' value. 'IsPostback' will always have the value which was set previously. So for instance if the page was posted back before refresh, then the value will be true and if the page is not posted back before refresh, then the value will be false.

这篇article将会首先阐释如何解决以上问题的基础,之后会展示源代码给大家。
This article will first explain the fundamentals of how to solve the above problem and later this article will go in depth of how the source code looks like.

【这一段是广告,就不浪费笔墨了】
Please feel free to download my free 500 question and answer eBook which covers .NET , ASP.NET , SQL Server, WCF , WPF , WWF , Silver light , Azure @ http://tinyurl.com/4nvp9t

参考

Reference

这个解决方案首先出现在一本asp.net书本上,该书由Dino Esposito所做,由Mr. SimoneB深入讨论一小段开源代码,由以下URL上可以下载。

The solution which this article proposes first came in an ASP.NET book written by Dino Esposito and it was taken further by Mr. SimoneB to make a small open source code which you can get fromhttp://sourceforge.net/projects/busybox.
A brief explanation is also provided at this link.
http://dotnetslackers.com/Community/blogs/simoneb/archive/2007/01/07/Using-an-HttpModule-to-detect-page-refresh.aspx

这篇文章将会一点一点解释Mr. Dino Esposito的看法。
The article will go step by step to explain the ideas proposed by Mr. Dino Esposito in a simplified manner. 

基础

The fundamental

12.jpg

第一步:我们创建了一段javascript代码在提交按钮单击时生成唯一的刷新全局ID。这个ID存储在HttpContext对象中。

第二步(用户单击提交按钮):如果用户单击提交按钮,它将会调用必要的javascript函数来再次生成唯一的刷新全局ID。

第三步:在“HttpHandler”或者“HttpModule”,心得刷新全局ID值会尝试匹配旧的GUID值,如果值不相等,则说明它并不是从一个提交动作中生成,而是一个刷新事件。根据HttpContext Session值的设置情况。

第四步:在页面的load事件我们可以通过session变量区分是刷新还是提交。

  • Step 1 :- We have created a javascript which will generate unique fresh GUID in submit button click. This GUID will be stored in the HttpContext object.
  • Step 2 ( User presses submit click ) :- If user presses submit button it will call the necessary javascript function to create the new fresh GUID again.
  • Step 3 :- In 'HttpHandler' or 'HttpModule' the new GUID value is checked with the old GUID value. If the values are not equal then it means this was not called from a submit click and it's a refresh event. Accordingly the HttpContext session value is set.
  • Step 4 :- In the page load we can then check if this was a refresh or post back using the session variables.
  • 3 代码中的重要部分


3 important parts of the code

这里有三个重要部分的代码需要解释

There are 3 important part of the code to be understood :-

  • Javascript用来生成刷新全局ID
  • Javascript which generates the unique GUID.
  • HttpHandler将会检查旧的ID是否等于新的ID。
  • HtppHandler which checks if the old value is equal to the new value.
  • ASP.NET 页面将会最终做出判断
  • ASP.NET page which finally checks if it's a refresh or postback and handles logic accordingly.

13.jpg

Javascript code

JavaScript代码

所以首先由JavaScript代码开始。‘genereateRandomSequence’函数生成唯一刷新ID,使用math函数

So first lets start with the javascript code. The 'genereateRandomSequence' function generates unique GUID by using 'math' functions like 'random' and 'floor'.

这个'’onPostBackfunction’调用’generateRandomSequence’函数来生成全局刷新唯一ID,并且贴上值到一个隐藏控件上,该控件称为hdnGuid。这个隐藏控件事由HttpHandler模块动态生成的,我们以后慢慢讨论。下面是部分的代码。

The 'onPostBack'function calls 'generateRandomSequence' function to generate GUID and attach the same to a hidden field with name 'hdnGuid'. This hidden field is generated on fly in the 'HttpHandler' module which will be explained shortly. Below is the code snippet for the same. 

 

function onPostBack()
{
var y=generateRandomSequence();
var hdnGuid=document.getElementById("hdnGuid");
hdnGuid.value=y;
}

function generateRandomSequence()
{
var g = "";
for(var i = 0; i < 32; i++)
g += Math.floor(Math.random() * 0xF).toString(0xF)
return g;
}

以上的javascript函数引用到一个js文件中,通过一个按钮的单击事件响应。

The above javascript function is referred in a JS files and called on the button submit click as shown in the below HTML code snippet.

<title>Untitled Page</title>
<script type="text/javascript" language="javascript" src="Client-Side_Validn.js" temp_src="Client-Side_Validn.js"></script>
</script>
</head>
<body>
<form id="form1" runat="server" onsubmit="onPostBack()">
<asp:Button ID="Button1" runat="server" Text="Button" />
</form>
</body>
</html>

HttpModule代码

HttpModule code

接下来事在HttpModule模块中的重要的代码。作为第一步,让我们创建一个简单的GUID类,用来帮助我们保存刷新全局ID。

The next important code is the 'HttpModule' code. As a first step let's create a simple GUID class which help us store the GUID values as shown in the below figure.

 

public class GuidClass
{
public GuidClass()
{
//
// TODO: Add constructor logic here
//
}
private string guid;
public string Guid
{
get
{
return guid;
}
set
{
guid = value;
}
}
}

接下来的步骤是创建一个’HttpModule’类,重写page_init事件和Page_Load事件

The next step is to create a simple 'HttpModule' class which overrides the 'page_Init' event and the 'page_Load' event.

在page_Init事件我们创建了一个隐藏控件,命名为hdnGuid。

In the 'page_Init' event we have created a simple hidden field by name 'hdnGuid' which is attached to the page on the first hit itself.

void _page_Init(object sender, EventArgs e)
{
HiddenField hdnGuid = new HiddenField();
hdnGuid.ID = "hdnGuid";
if (!_page.IsPostBack)
hdnGuid.Value = Guid.NewGuid().ToString();
_page.Form.Controls.Add(hdnGuid);
}

在Page_Load实践中,我们检查隐藏控件值是否等于旧的值。如果值不相同则意味着这是一个postback,如果值相同,则代表是一个刷新。对于每一种情况,我们设定httpContext.Items[“Refresh”]的值。

In the 'page_Load' event we check if the hidden field value is same as the old value. In case the value is not same that means it's a 'postback' and if the value is same then its 'refresh'. As per situation we set the 'httpContent.Items["Refresh"]' value.

void _page_Load(object sender, EventArgs e)
{
HiddenField h1 = (HiddenField)(_page.Form.FindControl("hdnGuid"));
GuidClass currentGuid =new GuidClass();
currentGuid.Guid= h1.Value;
System.Web.HttpContext _httpContext = System.Web.HttpContext.Current;
if (temp.Contains<string>(currentGuid.Guid))
{
_httpContext.Items.Add("IsRefresh",true);
}
else
{
if(!(currentGuid.Guid.Equals(null)||currentGuid.Guid.Equals("")))
temp.Enqueue(currentGuid.Guid);
_httpContext.Items.Add("IsRefresh",false);
}
}

我们同样要确定这个模块注册。

We also need to ensure that the handler is registered in the 'httpModules' tag.

<httpModules> <add name="Myhandler" type="Myhandler"/> </httpModules>

ASP.NET page code

The final part is to detect in the ASP.NET page whether it's a 'refresh' or 'postback'. The below code demostrates how 'HttpContext' session can be referred to check the same and act accordingly. 

if ((bool)HttpContext.Current.Items["IsRefresh"])
{
Response.Write("refreshed");
}
else
{
Response.Write("Postback");
}

Source Code

You can download the course code from top of this article.

Login to add your contents and source code to this article

About the author

archak sainanee

曾经就搜索过,没有出过结果,看到的方法无非是将用户文件夹转移到内存盘中,然后设定计划任务在开机和关机的时候同步内存盘中的数据以

保留用户的书签等数据。不过在google的某个网站上找到了只转移cache的方法:

Well, you guys are in luck (BTW, great work-around, Xenofon), since Chrome now has two startup switches that you can use:

--disk-cache-dir
and
--disk-cache-size

Simply close Chrome, right-click your Chrome shortcut, click Properties, and then in the field labeled "Target:", make it look something like this:

"...chrome.exe" --disk-cache-dir="CACHE_DIR" --disk-cache-size=N

Where 'CACHE_DIR' is the new cache location, and 'N' is the cache size limit, in bytes.

Use whichever switch you need, or both. Keep in mind, however, that these features may not be completely stable yet. But you probably shouldn't have any problem with using them.

And to anyone who's interested, I caught gander of the existence of these switches directly from a source code file for Chrome. See here:

http://src.chromium.org/svn/trunk/src/chrome/common/chrome_switches.cc

Hope this helps!

废话不说了。有用的顶呀~

最近由于中了个恶意软件还是优化大师的原因,反正任务栏上的资源管理器图标不能用了。

试了网上的几种方法,最后找到了个能用的,给大家留个方便:

网上搜到高手alsmlzy的正道解决法:
按着shift——指着任务栏资源管理器图标——右键——属性——在目标栏里输入:
%SystemRoot%\ /e, ::{20D04FE0-3AEA-1069-A2D8-08002B30309D}
然后确定就OK了。估计是用优化大师优化时不知误删了什么,本来好用的。

——摘自http://help.360.cn/5030809/26256219.html

由于经常涉及到背景音乐等流媒体格式的处理,在codeproject上看到了一篇相关文章,比较不错

在此翻译一下,供后来者参考

原文链接:http://www.codeproject.com/KB/dotnet/Windows7_Mp3_Player.aspx

Introduction

简介

In this article, we will see how we can develop an MP3 player, using C#.NET, which

will use some of the new features of Windows 7.
We will show the progress of the song being played using the "Progress bar" in Taskbar.

We will also show the Album art of the song as the "Thumbnail" and we will also have a

Thumbnail Toolbar which has the Play/Pause, Next and Previous buttons.

在这个文章中,我们将会看到如何开发一个使用到一些win7新特性的MP3播放器,

使用C#.net开发。我们将会使用任务栏中的进度条来显示MP3播放进度,

我们也会使用歌曲唱片集的封面图片,并且我们也有一个具有播放,暂停,

下一首和上一首按钮的工具栏。

Prerequisites

预备知识

  1. To play MP3 songs, we will be using the BASS Audio Library.播放MP3歌曲,
  2. 我们将使用BASS Audio Library来完成
  3. We will also need Bass.net which is the .NET API for BASS. 我们也会用到Bass.net,
  4. 这个是上者的.net接口
  5. TagLib Sharp: We will use this library to read tagging information about
  6. the song being played. TagLib Sharp,我们使用这个库来读取歌曲的标签信息
  7. Windows® API Code Pack for Microsoft® .NET Framework Windows API 代码包

Developing the Application

开发应用程序

The Player

播放器

  1. Create a new project in Visual Studio 在Visual Studio中创建一个新项目
  2. Add the existing projects Shell and Core which can be found under the WindowsAPICodePack\shell and WindowsAPICodePack\core
  3. folders 添加已存在的工程框架,在WindowsAPICodePack\Shell和WindowsAPICodePack\core文件夹中可以找到。
  4. Add a reference to the above projects and import the following namespaces:
  5. 在上面的工程中添加以下引用,并引入以下命名空间
    • Microsoft.WindowsAPICodePack.Dialogs
    • Microsoft.WindowsAPICodePack.Taskbar
    • Microsoft.WindowsAPICodePack.Shell

The first part of the development is developing the player which will have the basic

functionality like Play/Pause, Stop, next Previous/

Next and Add/Remove songs

Buttons.  The main form in our application has 7 Buttons, A listbox,

Label and a

Picture Box.

开发的第一个部分是开发具有像播放暂停,停止,下一首和上一首,添加删除歌曲按钮的播放器,

我们的应用程序有7个按钮在主窗体上,还有一个Label,一个listbox,一个picturebox。

We will use the Picture Box to display the Album Art and we will use the Label to

display the seconds remaining while a song is being played.

我们将会使用PictureBox来显示唱片集,我们用label来显示歌曲播放的秒数

Note: Make sure you have added references for Core, Shell, Bass.net and taglib-sharp.

Also add bass.dll to your project (Make sure you have set "Copy to Output Directory"

as "Copy Always".)

注:确定你已经为Core,Shell,Bass.net和taglib-sharp添加了引用,并且添加bass.dll

到你的工程中(确定你已经设定拷贝到输出文件夹项目设定为“一直拷贝”)

Player Class: This class has all the methods which we will be using to play MP3 files.

The first step is to initialize an output device. We useBass.BASS_Init() for this.

Following are the parameters:

Player类:这个类具有所有的播放MP3文件的方法,第一步是初始化一个输出设备,我们使用

Bass.BASS_Init() 来完成这个步骤。按照以下步骤进行

  1. -1 denotes default device. -1代表默认设备
  2. 44100 is the frequency. 44100 是频率
  3. BASSInit.BASS_DEVICE_DEFAULT denotes th default device to use BASSInit.BASS_DEVICE_DEFAULT代表使用的默认设备
  4. System.IntPtr.Zero denotes the application's main window which is the current foreground window. System.IntPtr.Zero代表应用程序的主窗口,作为当前的主窗口

Before playing a song, we must first create a stream. We use BASS_StreamCreateFile()

to create a stream from a file. We then useBASS_ChanelPlay() to play the stream which

we created in the LoadSong() function.

在播放一首歌的值钱,我们必须先创建 一个流。我们使用BASS_StreamCreateFile()

来从文件中创建一个流。我们只用使用BASS_ChangelPlay() 来播放通过LoadSong来创建的流。

 
Song Length and Album Art

歌曲长度及唱片集

Once the player is ready, we will use Taglib sharp to get the length of the song and

album art. We will use the picture box to display the album art. We will also use

this picture box's location and size to create the Thumbnail.

一旦播放器准备就绪,我们使用Taglib sharp来获取歌曲的长度和专辑封面。

我们将会使用picturebox来显示唱片集封面。我们激昂会也使用picture box的地点

和调整封面的大小。

Once we create the TagLib file from a file (in this case, the selected item in the

playlist listbox), we will use Properties.Duration.TotalSeconds to get the

length of the song in seconds. We will be using this value to populate the Label

and the set the progressbar value.

一旦我们从文件中创建了TagLib文件(在这时,选择的项目显示在播放列表listbox中),我们将要使用Properties.duration.TotalSeconds来以秒为单位得到歌曲的长度。我们将要好用这个值来设置Label和设定进度条值。

 

We will also be using taglib sharp to get the album art of the song which is being

currently played. Some songs may not have an Album art so we will useTagLibfile.Tag.Pictures.Length to get the numbers of pictures associated

with the song. If it is more than zero, then we load the picture box with the album art.

我们将要也使用taglibsharp来获取正在播放的歌曲的唱片集封面,一些歌曲可能不会有唱片集封面,

所以我们会使用TagLibfile.Tag.Pictures.Length来获取图片的数目。入股必0打,那么我们在picturebox中显示唱片集封面。

 
Progressbar, Thumbnail Toolbar and Player Buttons

Create Taskbar buttons and instance of TaskbarManager.

 

This is the main function which will play the song. First we call the SetAlbumArt()

function which will set the album art. We use SetTaskBarthumbnail()function to

the set the thumbnail. Explanation for this function comes later in this article.

We will use GetSongLength() and SetTimerforPlay() to get the song length and

activate the timer respectively.

这个主函数用来播放歌曲,首先我们调用SetAlbumArt()函数来设置唱片集封面,

我们是用SetTaskBarthumbnail()函数来设置thumbnail。这个函数我们将在后文解释。

我们将要使用GetSongLength函数和SetTimerforPlay()函数来获得歌曲长度,

并且激活计时器。

 
 
 
 
 
 
 
 

In the below function, we first check whether the song is paused. We use the value

of playState for this. Value zero means the song is paused and we use the PlaySong()

function to continue playing the song. If the value is not zero, then it denotes that

the song should be played from the beginning. In this case, we load the song and

then play it.

在这个函数的中,我们首先检查歌曲是否暂停。我们使用playState的值来确定。

0值代表歌曲暂停,我们使用PlaySong()函数来继续播放歌曲。如果值非0,

代表歌曲应该从头播放。在这个情况,我们读取歌曲然后播放。

 
 

This function is called just before playing the song to enable the timer and set the

progress bar style. TaskbarProgressBarState.Normal denotes that the progress

will be normal. Timer's interval is set as 1000 ms.

这个函数在开始播放歌曲,开启计时器和设置进度条风格之前调用。TaskbarProgressBarState.Normal代表进度将会被初始化。计时器间隔设置为1000ms。

 

This is similar to SetTimerforPlay() but we will disable the timer to stop the

progress in the progress bar. At the same time, we will also set its style toTaskbarProgressBarState.Error so that the color is set as Red. This function

is called when the song is paused.

这个与SetTimerforPlay()类似,但是我们将会禁止计时器来停止进度条。在同时,

我们将会设置这个风格到TaskbarProgressBarState.Error,这样颜色被设置为红色。

这个函数当歌曲暂停时调用。

 
 

We will be using TabbedThumbnail.SetThumbnailClip to set the thumbnail for

our MP3 player. For this, we create a new Rectangle selection inside the main

form and then set it as the thumbnail clip. Our motive is to use the Album art

which we have already loaded in the Picture Box. Note: I had to make some

adjustments in the Height and Width of the rectangle selection to get a proper thumbnail.

我们将会使用TabbedThumbnail.SetThumbnailClip来设置thumbnail为我们的mp3播放器。

为了这个目的,我们创建一个新的矩形选框在主窗口中,然后设置作为thumbnail clip.

我们的目的是是使用已经加载到图片框中的唱片集封面。

注意:我已经做了一些宽度和高度的优化在矩形选框中。

 

Thumbnail Toolbar should be created during the Form's Shown event.

ThumbnailToolbarButton accepts two parameters:

Thumbnail工具来应该在窗体show事件时创建,ThumbnailToolbarButton有以下两个参数

  1. Icon: The Icon to be used for the button.  图标:为按钮使用的图标
  2. Tooltip: The tool tip for the button. 工具条:为按钮的工具条提示

We also add an Event Handler for each of the Button's Click events.

我们也会添加一个事件响应为每个按钮的点击事件。

 
Thumbnail Toolbars : Play/Pause, Next and Previous Buttons
 
 
Progressbar

进度条

Timer's interval is set to 1000ms and it will be enabled as soon as the play button is

pressed. We use the SongLength to set the maximum value of the progressbar. and

increment the progress value every second. Timer will be disabled as soon as the

pause button is pressed.

计时器响应间隔被设置为1000ms,一旦播放按钮按下去就会被激活,我们使用

SongLength来设置进度条的最大值,并且每秒度增加进度条值,计时器将会在暂停按钮

单击时停止。

Player in Action

响应时的播放器

Play
Thumbnail
Thumbnail while Paused
Thumbnail while Playing
Progressbar while Paused
Conclusion

总结

This is a basic MP3 player which was developed in few hours. The idea was to use

progress bar differently. Comments and suggestions are always welcome.

这个简易的MP3播放器可以在若干小时内就能开发成功,开发初衷是用不同的方式使用进度条,

欢迎大家提出建议和参加评论。

References and Useful Links

参考链接

History

  • Initial release: 31st January, 2010

License

This article, along with any associated source code and files, is licensed under

The Code Project Open License (CPOL)

About the Author

Shoban Kumar

Member
Shoban Kumar currently works with Allianz Cornhill India in Trivandrum as

a Senior Software Engineer. He is one of the core member of Kerala Microsoft User's Group http://www.k-mug.org.
He actively writes .net articles in his blog http://www.codegeeks.net and http://www.dotnetcurry.com.
He has also written many open source applications which can be found in Codeplex :http://www.codeplex.com/site/users/view/shobankr

Occupation:
Software Developer (Senior)

Company:
Allianz Cornhill

Location:
India India

杂牌摄像头一个,硬件ID:

USB\VID_17A1&PID_0118&REV_0100
USB\VID_17A1&PID_0118

兼容id

USB\Class_00&SubClass_00&Prot_00
USB\Class_00&SubClass_00
USB\Class_00

设备描述

USB 2.0 Web Cam

曾尝试安装过万能驱动,但是经xp环境试验不能使用。只能安装

专用driver。附带光盘里程序名:cam1210_153v.exe

在xp下运行安装程序可以正常运行。但是经试验在win7下不能正常工作。

google了一上午都没有结果。最后还是搞定了。将解决方案附加如下:

用UniExtract 1.6将cam1210_153v.exe解包。解包后发现时一个msi文件:
USB Video Camera Driver v1.53.msi

再次使用UniExtract解包,出现几个文件夹,分别是:program files,System,

System32,Windows,我们可以发现在windows文件夹下有inf文件等。

在设备管理器中手动选择搜索路径,为msi解压出来的USB Video Camera Driver v1.53文件夹

安装。ok。

© 2011 ww2521's blog Suffusion theme by Sayontan Sinha