国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
網(wǎng)站自動(dòng)更新程序及代碼

1、自動(dòng)更新程序主要負(fù)責(zé)從服務(wù)器中獲取相應(yīng)的更新文件,并且把這些文件下載到本地,替換現(xiàn)有的文件。達(dá)到修復(fù)Bug,更新功能的目的。用戶手工點(diǎn)擊更新按鈕啟動(dòng)更新程序。已測(cè)試。
2、環(huán)境VS2008,采用C#.NET和ASP.NET實(shí)現(xiàn)。
3、服務(wù)器:提供下載文件,發(fā)布出去。 文件包括:dll, xml,aspx等格式文件。其中update.xml 是記錄更新文件的。
4、客戶端:項(xiàng)目里面添加一個(gè)autoupdate.xml 文件,該文件里有連接服務(wù)器的發(fā)布更新文件的服務(wù)器地址。當(dāng)客戶端里userupdate.xml文件里的版本號(hào)和服務(wù)器中update.xml里的版本號(hào)對(duì)比,如果服務(wù)器的版本號(hào)高,提醒客戶端更新。
5、源代碼如下所示。

1)、服務(wù)端發(fā)布至IIS如下圖所示。

 圖1

 

其中bin目錄下的dll文件屬性寫入打勾。

圖2

Update.xml源碼如下所示。

 

代碼
<update>
   
<version>1.0.1.9</version>     
   
<datetime>2009-12-14 </datetime>       
   
<filelist filescount="5" itemcount="11" sourcepath="http://Localhost/UpdateServ/">

   
<file filesname="" > 
   
<item name="xiaxia.txt" size=""> 
    
</item>
   
</file>
 
  
<file filesname="UpFile"> 
    
<item name="2222.dll" size=""> 
    
</item> 
    
<item name="1162193918505.doc" size="">  
    
</item> 
    
<item name="xd.doc" size=""> 
    
</item> 
    
<item name="s2.txt" size=""> 
    
</item>
    
<item name="a.dll" size=""> 
    
</item>
    
<item name="WebUPFILE.dll" size=""> 
    
</item>
  
</file>


<file filesname="test"> 

<item name="aa.txt" size="">  
</item> 
<item name="2.txt" size="">  
</item> 
</file>


<file filesname="Copy">


<item name="bb.doc" size="">  
</item>
<item name="b.dll" size=""> 
</item>
</file> 


<file filesname="hehe">

<item name="hehe.txt" size=""> 
</item>
<item name="WebUPFILE.dll" size=""> 
</item>
</file> 

</filelist> 
</update> 

 

 

2)、客戶端代碼,結(jié)構(gòu)如下圖所示。

圖3

代碼內(nèi)有注釋,在此不再多說。

Config.cs

 

代碼
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Xml;

namespace WebUpdate
{
    
public class Config
    {
        
public string url = null;
        
public string cmd = null;

        
//讀文件autoUpdate.xml
        public Config()
        {
            
string path = AppDomain.CurrentDomain.BaseDirectory + "autoUpdate.xml";

            
try
            {
                
if (path != null)
                {
                    XmlDocument xmlDoc 
= new XmlDocument();
                    xmlDoc.Load(path);
                    url 
= xmlDoc.SelectSingleNode("/update/url").InnerText;

                }
            }
            
catch (Exception ex)
            {
                
throw new Exception("找不到autoUpdate.xml文件" + ex.Message);

            }
        }

        
//獲取服務(wù)器的版本
        public Version GetServerVersion()
        {
            XmlDocument xmlDoc 
= new XmlDocument();
            xmlDoc.Load(url);
            
return new Version(xmlDoc.SelectSingleNode("/update/version").InnerText);
        }

        
//獲取客戶端版本
        public string GetClientVersion()
        {
            url 
= AppDomain.CurrentDomain.BaseDirectory + "userVersion.xml";
            XmlDocument xmlUser 
= new XmlDataDocument();
            xmlUser.Load(url);
            XmlElement root 
= xmlUser.DocumentElement;
            XmlNode updateNode 
= root.SelectSingleNode("version");
            
string version = updateNode.Attributes["value"].Value;
            
return version;

        }

        
//為了進(jìn)行版本比較,進(jìn)行轉(zhuǎn)換為整數(shù)比較
        public int ConvertVersion(string value)
        {
            
int w, z, x, y, temp;
            w 
= int.Parse(value.Substring(01));
            z 
= int.Parse(value.Substring(21));
            x 
= int.Parse(value.Substring(41));
            y 
= int.Parse(value.Substring(61));
            temp 
= w * 1000 + z * 100 + x * 10 + y;
            
return temp;
        }

        
//更新客戶版本號(hào)為服務(wù)器的版本號(hào)
        public string UpdateVersion(string serVersion)
        {
            url 
= AppDomain.CurrentDomain.BaseDirectory + "userVersion.xml";
            XmlDocument xmlUser 
= new XmlDataDocument();
            xmlUser.Load(url);
            XmlElement root 
= xmlUser.DocumentElement;
            XmlNode updateNode 
= root.SelectSingleNode("version");
            
string strVer = updateNode.Attributes["value"].Value;
            updateNode.Attributes[
"value"].Value = serVersion;
            xmlUser.Save(url);
            
return serVersion;
        }

    }
}

DownFile.cs

 

代碼
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.IO;


namespace WebUpdate
{
    
public class DownFile
    {
        
//從服務(wù)器下載文件,若目錄存在,直接復(fù)制新文件,不存在則新建目錄并復(fù)制文件,成功后返回1
        public bool DownFileFromServ(string url, string fileName)
        {
            
bool downsucess = false;
            
try
            {
                
string fileExtraName = url.Split(char.Parse("."))[0];                              //文件名
                string fileAfterName = System.IO.Path.GetExtension(url);                //文件的擴(kuò)展名
                if (fileAfterName == ".aspx")
                    url 
= fileAfterName + ".txt";
                HttpWebRequest myReq 
= (HttpWebRequest)WebRequest.Create(url);
                myReq.KeepAlive 
= true;
                HttpWebResponse myRes 
= (HttpWebResponse)myReq.GetResponse();

                downsucess 
= this.CopyFileAndDirectory(myRes, fileName);

            }
            
catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }

            
return downsucess;
        }

        
//返回復(fù)制文件或創(chuàng)建目錄是否成功
        public bool CopyFileAndDirectory(WebResponse myResp, string fileName)
        {
            
bool flag = true;
            
byte[] buffer = new byte[0x400];
            
try
            {
                
int num;
                
//若本身已有該目錄則刪除
                if (System.IO.File.Exists(fileName))
                {
                    System.IO.File.Delete(fileName);
                }
                
//創(chuàng)建目錄更新到Updat目錄下
                string directoryName = Path.GetDirectoryName(fileName);
                
if (!Directory.Exists(directoryName))
                {
                    Directory.CreateDirectory(directoryName);
                }

                
//指定文件fileName不存在時(shí)創(chuàng)建它
                Stream streamRead = System.IO.File.Open(fileName, FileMode.Create);

                Stream responseStream 
= myResp.GetResponseStream();

                
do
                {
                    
//從當(dāng)前讀取的字節(jié)流數(shù),復(fù)制
                    num = responseStream.Read(buffer, 0, buffer.Length);
                    
if (num > 0)
                    {
                        streamRead.Write(buffer, 
0, num);
                    }
                }
                
while (num > 0);
                streamRead.Close();
                responseStream.Close();
            }
            
catch
            {
                flag 
= false;
            }

            
return flag;

        }

    }
}

 

Update.cs

 

代碼
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace WebUpdate
{
    
public class Update
    {
        
//從服務(wù)器文件update.xml中獲取要下載的文件列表
        public bool flag = false;

        
public string[] GetFileList(string url)
        {
            XmlDocument xmlDoc 
= new XmlDocument();
            xmlDoc.Load(url);
            XmlElement root 
= xmlDoc.DocumentElement;
            XmlNode updateNode 
= root.SelectSingleNode("filelist");
            
string soucePath = updateNode.Attributes["sourcepath"].Value;

            
string fileName = null;
            
string fileList = null;
            
//取出服務(wù)器里update.xml里更新的file文件
            XmlNodeList fileNode = updateNode.SelectNodes("file");
            
if (fileNode != null)
            {
                
foreach (XmlNode i in fileNode)
                {
                    
foreach (XmlNode j in i)
                    {
                        
if (i.Attributes["filesname"].Value != "")
                            fileName 
= soucePath + i.Attributes["filesname"].Value + "/" + j.Attributes["name"].Value +
                                
"$" + i.Attributes["filesname"].Value + "/" + j.Attributes["name"].Value;
                        
else
                            fileName 
= soucePath + j.Attributes["name"].Value +
                                
"$" + j.Attributes["name"].Value;

                        fileName 
+= ",";
                        fileList 
+= fileName;
                    }
                }

                
string[] splitFile = fileList.Split(',');
                flag 
= true;
                
return splitFile;
            }
            
return null;
        }

    }
}

 

 

autoUpdate.xml

 

<update>
  
<url>http://Localhost/UpdateServ/update.xml</url>
</update>

 

 

userVersion.xml

 

<?xml version="1.0" encoding="utf-8"?>
<update>
  
<version value="1.0.1.9">客戶端版本號(hào)</version>
</update>

 

 

Update.aspx

 

代碼
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Update.aspx.cs" Inherits="_Default" %>   
  
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">   
  
<html xmlns="http://www.w3.org/1999/xhtml">   
<head runat="server">   
    
<title>自動(dòng)更新</title>   
</head>   
<body>   
    
<form id="form1" runat="server">   
    
<div>   
       
        
<br />   
        
<br />   
                                                                          
        
<asp:Label ID="lblDisplay" runat="server" style="text-align: center" mce_style="text-align: center"    
            Text
="Label" Visible="False"></asp:Label>   
        
<br />   
        
<br />   
                                                              
        
<asp:Button ID="btnUpdate" runat="server" style="text-align: center" mce_style="text-align: center"    
            Text
="更新" onclick="btnUpdate_Click" Visible="False" Height="34px"    
            Width
="145px" />   
        
<br />   
                              
       
        
<br />   
        
<asp:Label ID="NewVersion" runat="server" Text="Label1" Visible="false"></asp:Label>   
        
<br />   
        
<br />   
        
<asp:Label ID="CurrentVersion" runat="server" Text="Label2" Visible="false"></asp:Label>   
       
    
</div>   
    
</form>   
</body>   
</html>  

 

Update.aspx.cs

 

代碼
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using WebUpdate;

public partial class _Default : System.Web.UI.Page 
{
    
protected void Page_Load(object sender, EventArgs e)
    {
        lblDisplay.Text 
= "";
        btnUpdate.Visible 
= false;


        Config cf 
= new Config();

        NewVersion.Text 
= cf.GetServerVersion().ToString();
        CurrentVersion.Text 
= cf.GetClientVersion().ToString();

        
int clientversion = cf.ConvertVersion(CurrentVersion.Text);
        
int serverversion = cf.ConvertVersion(NewVersion.Text);
        
if (serverversion > clientversion)
        {
            btnUpdate.Visible 
= true;
        }
        
else
        {
            lblDisplay.Text 
= "已是最新版本,不需要更新!";
            lblDisplay.Visible 
= true;
        }

    }
    
protected void btnUpdate_Click(object sender, EventArgs e)
    {
        
string url = null;
        
string[] files = null;
        Config updatecf 
= new Config();
        url 
= updatecf.url;
        Update upd 
= new Update();
        files 
= upd.GetFileList(url);

        UpdateFile(files);

        CurrentVersion.Text 
= updatecf.UpdateVersion(NewVersion.Text);

        lblDisplay.Text 
= "更新完成。";
        lblDisplay.Visible 
= true;
        btnUpdate.Visible 
= false;

    }

    
private void UpdateFile(string[] files)
    {
        
if ((files == null|| (files.Length <= 0))
        {
            Response.Write(
"升級(jí)完成");
        }
        
else
        {
            
int num = 0;
            
for (int i = 0; i < files.Length; i++)
            {
                
string str = files[i];
                
if ((str != null&& (str.Split(new char[] { '$' }).Length == 2))
                {
                    
string[] strArray = str.Split(new char[] { '$' });
                    
this.UpdateFile(strArray[0], strArray[1]);
                    num
++;
                }
            }
            
if (num == 0)
            {
                Response.Write(
"升級(jí)完成");
            }
        }
    }

    
private void UpdateFile(string url, string filename)
    {
        
string fileName = AppDomain.CurrentDomain.BaseDirectory + filename;
        
try
        {
            DownFile file 
= new DownFile();
            
bool flag = file.DownFileFromServ(url, fileName);
        }
        
catch
        {

        }
    }
}

 

 

本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
AssetBundle系列游戲資源打包(二)
C# Winform實(shí)現(xiàn)手機(jī)號(hào)碼歸屬地查詢工具
ASP.NET生成HTML初級(jí)解決方案
RichTextBox實(shí)現(xiàn)關(guān)鍵字自定義顏色顯示(C#)
doExport導(dǎo)出為excel
如何將XMLDocument轉(zhuǎn)化成String
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服