zoukankan      html  css  js  c++  java
  • [CSharp]模拟软件升级器的功能

    引言:

    今天看了博客园一位博友“菜菜灰”写的博文:《关于软件多版本升级的一些思考》,有感而发,虽然是做Web应用,在线升级版本的功能还是很必要。

    上午花费了2个小时写了一个“模拟软件在线升级的类”,希望对博友“菜菜灰”有点帮助。

    软件类:

        /// <summary>
    
        /// 软件类
    
        /// </summary>
    
        public class Soft
    
        {
    
            private string v = "1.0";
    
            private IList<string> vl = new List<string>() { "1.0", "2.0", "3.0", "4.0" };
    
    
    
            /// <summary>
    
            /// 当前版本
    
            /// </summary>
    
            public string Version
    
            {
    
                get
    
                {
    
                    return this.v;
    
                }
    
                set
    
                {
    
                    this.v = value;
    
                }
    
            }
    
    
    
            /// <summary>
    
            /// 版本列表
    
            /// </summary>
    
            public IList<string> VersionList
    
            {
    
                get
    
                {
    
                    return this.vl;
    
                }
    
                set
    
                {
    
                    this.vl = value;
    
                }
    
            }
    
        }

    软件升级器:

        /// <summary>
    
        /// 软件升级器
    
        /// </summary>
    
        public class SoftUpdater
    
        {
    
            public Soft soft = new Soft();
    
            
    
            /// <summary>
    
            /// 更新版本
    
            /// </summary>
    
            /// <returns></returns>
    
            public bool Update()
    
            {
    
                // 当前版本
    
                string ver1 = soft.Version;
    
    
    
                // 目标版本
    
                string ver2 = (soft.VersionList.IndexOf(ver1) == soft.VersionList.Count - 1) ? ver1 : soft.VersionList[soft.VersionList.IndexOf(ver1) + 1];
    
    
    
                return this.Update(ver1, ver2);
    
            }
    
    
    
            /// <summary>
    
            /// 更新版本
    
            /// </summary>
    
            /// <param name="ver1">当前版本</param>
    
            /// <param name="ver2">目标版本</param>
    
            /// <returns></returns>
    
            public bool Update(string ver1, string ver2)
    
            {
    
                if (ver1.Equals(ver2))
    
                {
    
                    HttpContext.Current.Response.Write("已经是最新版本");
    
                    HttpContext.Current.Response.Write("<br />");
    
                }
    
                else
    
                {
    
                    HttpContext.Current.Response.Write(string.Format("{0} 升级到 {1}", ver1, ver2));
    
                    HttpContext.Current.Response.Write("<br />");
    
    
    
                    string ver3 = ver2;
    
                    string ver4 = (soft.VersionList.IndexOf(ver3) == soft.VersionList.Count - 1) ? ver3 : soft.VersionList[soft.VersionList.IndexOf(ver3) + 1];
    
    
    
                    return this.Update(ver3, ver4);
    
                }
    
    
    
                return true;
    
            }
    
        }

    输出结果:

    1

    安布雷拉 标签: 在线升级
  • 相关阅读:
    飘逸的python
    hdu 4512 吉哥系列故事——完美队形I(最长公共上升自序加强版)
    Codeforces 482B. Interesting Array 线段树
    《开源框架那些事儿21》:巧借力与借巧力
    openNebula libvirt-virsh attach disk device for kvm
    configure mount nfs
    opennebula kvm attach disk
    openNebula 运维系列虚拟机virtual machines operations
    yum subversion puppet puppet-server
    文件系统,快存储,对象存储
  • 原文地址:https://www.cnblogs.com/JavCof/p/2045284.html
Copyright © 2011-2022 走看看