【原创】自动更新程序1网站的部署(技术:spring.net+三层架构+webservice+IrisSkin2换肤)

    因为工作中负责的软件涉及的区域太广,每次换个软件很麻烦,微软自带的 one  key click一直不是很喜欢,可能一部分原因是因为那个key是要自己处理一下,否则时效不够长,还有一部分原因可能是因为每次发布这个东西都很麻烦,并且如果出错路径不好寻找,故软件早就放弃了one key click的方式,现在采取的均为setup安装,但是问题出来了,安装好了之后升级就是个问题了。本文主要是针对setup的升级来的。主要实现如下效果:主程序启动的同时启动更新程序,更新程序通过webservice来获取服务器某个目录下面的文件,然后批量的download到主程序的根目录下,之后解压,解压完成后程序重新启动。

    故本文从以下两个方面讲解1、webservice的部署,2、更新程序的说明。

    主程序图如下:

    QQ截图20130515230359

一、webservice的主要思路及代码

     1、因为我从事的公司用到的技术为spring.net,所以webservice的部署我采取的是三层架构,通过spring.net注入来实现webservice。

      代码如下:IBLL

 public interface ILoadInfoService
    {
        /// <summary>
        /// 获取版本号
        /// </summary>
        /// <returns></returns>
        string GetVersion();

        /// <summary>
        /// 获取url
        /// </summary>
        /// <returns></returns>
        string GetUrl();

        /// <summary>
        /// 获取压缩文件
        /// </summary>
        /// <returns></returns>
        string[] GetZips();

        /// <summary>
        /// 获取日志记录
        /// </summary>
        /// <returns></returns>
        string GetUpdateLog();

        /// <summary>
        /// 返回所有的信息
        /// 0 version
        /// 1 GetUrl
        /// 2 zips
        /// 3 GetUpdateLog
        /// </summary>
        /// <returns></returns>
        string[] GetUpdateInfos();
    }
BLLImpl
public class LoadInfoServiceImpl:ILoadInfoService
    {
        private string version;

        public string Version
        {
            set { version = value; }
        }

        private string url;

        public string Url
        {
            set { url = value; }
        }

        private string directory;

        public string Directory
        {
            set { directory = value; }
        }

        private string updateLog;

        public string UpdateLog
        {
            set { updateLog = value; }
        }

        #region ILoadInfoService 成员

        public string GetVersion()
        {
            return version;
        }

        public string GetUrl()
        {
            return url + directory;
        }

        public string[] GetZips()
        {
            string folder = HttpRuntime.AppDomainAppPath + directory;
            string[] zips = System.IO.Directory.GetFileSystemEntries( folder );
            for (int i = 0; i < zips.Length; i++)
            {
                string fileName = Path.GetFileName( zips[i] );

                zips[i] = fileName;
            }
            return zips;
        }

        public string GetUpdateLog()
        {
            StringBuilder sb = new StringBuilder();
            string path = HttpRuntime.AppDomainAppPath + directory + updateLog;
            if (File.Exists( path ))
            {
                StreamReader sr = new StreamReader( path, Encoding.Default );
                string s;
                while ((s = sr.ReadLine()) != null)
                {
                    //上面一行一行读。然后在里面就看你自己怎么处理了。下面是假设。
                    sb.AppendLine( s );
                }
                sr.Close();
            }
            return sb.ToString();
        }

        public string[] GetUpdateInfos()
        {
            string[] strArray = new string[] { this.GetVersion(), this.GetUrl(), string.Join( ",", this.GetZips() ), this.GetUpdateLog() };
            return strArray;
        }

        #endregion
    }

UpdateWeb

Configs/AutoUpdateWebService.xml 这个文件主要是spring.net用作注入的,实现webservice。这样只要网站部署好了之后,通过如下地址http://ip/SXSUpdateWebService.asmx 即可访问webservice,下面是大概的描述

<?xml version="1.0" encoding="utf-8" ?>
<objects xmlns="http://www.springframework.net" xmlns:db="http://www.springframework.net/database">

  <object id="SXSUpdateWebServiceBLL" type="BJCreation.AutoUpdate.BLLImpl.LoadInfoServiceImpl, BJCreation.AutoUpdate.BLLImpl">
    <property name="Version" value="20132101" /><!-- 这个是版本号 -->
    <property name="Url" value="${local.url}" /> <!-- 这个是url就是http://ip  -->
    <property name="Directory" value="UpdateFile/test/" /><!-- 这个是要从服务器的那个目录下去取更新的文件 -->
    <property name="UpdateLog" value="${local.log}" /> <!-- 这个是此次更新的日志 -->
  </object>
  <object id="SXSUpdateWebService" type="Spring.Web.Services.WebServiceExporter, Spring.Web">
    <property name="TargetName" value="SXSUpdateWebServiceBLL" />
    <property name="Namespace" value="http://www.creation.com" />
    <property name="Description" value="测试webservice" />
    <property name="TypeAttributes">
      <list>
        <object type="System.Web.Script.Services.ScriptServiceAttribute, System.Web.Extensions"/>
      </list>
    </property>
  </object>
</objects>

整个文章的源代码在第二篇会附上。

原文地址:https://www.cnblogs.com/smthts/p/3080922.html