码迷,mamicode.com
首页 > Windows程序 > 详细

Winform版本发布更新

时间:2015-03-14 18:32:36      阅读:228      评论:0      收藏:0      [点我收藏+]

标签:

 

版本发布:

一、局域网共享文件方式

 

发布界面:

技术分享

更新界面:

技术分享

 

二、FTP方式

发布界面

技术分享

更新界面:

技术分享

 

 

(只会更新有变动的文件)
同步新增,替换与删除
实现方式XML(文件名+文件最后修改时间)
状态判断:LINQ(通过对比本地XML和服务器XML的不同)

 

XML实质是一张DataSet

包含两张表

#region 获得数据集结构
        /// <summary>
        /// 获得数据集结构
        /// </summary>
        /// <returns></returns>
        protected DataSet GenerateDataSchema()
        {
            DataTable dtV = new DataTable(DataSchema.VersionSchema.TableName);
            dtV.Columns.Add(DataSchema.VersionSchema.Version);


            DataTable dtD = new DataTable(DataSchema.DetailSchema.TableName);
            dtD.Columns.Add(DataSchema.DetailSchema.Name, typeof(System.String));//名称
            dtD.Columns.Add(DataSchema.DetailSchema.EditDate, typeof(System.DateTime));//修改时间
            dtD.Columns.Add(DataSchema.DetailSchema.Size, typeof(System.String));//大小
            dtD.Columns.Add(DataSchema.DetailSchema.Path, typeof(System.String));//路径


            DataSet ds = new DataSet();

            ds.Tables.Add(dtV);
            ds.Tables.Add(dtD);

            return ds;
        }
        #endregion

 

LINQ服务器和本地对比代码:

版本发布:

//需要新增的
            //需要删除的
            //需要替换的

            var DataEdit = from dtLocation in LocalDetailFiles.AsEnumerable()
                           join dtServer in ServerDetailFiles.AsEnumerable()
                           on dtLocation.Field<string>(DataSchema.DetailSchema.Path) + dtLocation.Field<string>(DataSchema.DetailSchema.Name) equals
                              dtServer.Field<string>(DataSchema.DetailSchema.Path) + dtServer.Field<string>(DataSchema.DetailSchema.Name)
                           where dtLocation.Field<DateTime>(DataSchema.DetailSchema.EditDate) > dtServer.Field<DateTime>(DataSchema.DetailSchema.EditDate)
                           select new
                           {
                               Name = dtLocation.Field<string>(DataSchema.DetailSchema.Name),
                               Path = dtLocation.Field<string>(DataSchema.DetailSchema.Path)
                           };
            var DataAdd = from dtLocal in LocalDetailFiles.AsEnumerable()
                          where !ServerDetailFiles.AsEnumerable().Any(y => y.Field<string>(DataSchema.DetailSchema.Path) + y.Field<string>(DataSchema.DetailSchema.Name) == dtLocal.Field<string>(DataSchema.DetailSchema.Path) + dtLocal.Field<string>(DataSchema.DetailSchema.Name))
                          select new
                          {
                              Name = dtLocal.Field<string>(DataSchema.DetailSchema.Name),
                              Path = dtLocal.Field<string>(DataSchema.DetailSchema.Path)
                          };
            var DataDelete = from dtServer in ServerDetailFiles.AsEnumerable()
                             where !LocalDetailFiles.AsEnumerable().Any(y => y.Field<string>(DataSchema.DetailSchema.Path) + y.Field<string>(DataSchema.DetailSchema.Name) == dtServer.Field<string>(DataSchema.DetailSchema.Path) + dtServer.Field<string>(DataSchema.DetailSchema.Name))
                             select new
                             {
                                 Name = dtServer.Field<string>(DataSchema.DetailSchema.Name),
                                 Path = dtServer.Field<string>(DataSchema.DetailSchema.Path)
                             };

            dtUpdateFiles = new DataTable();
            dtUpdateFiles.Columns.Add("Name", typeof(System.String));
            dtUpdateFiles.Columns.Add("Path", typeof(System.String));
            dtUpdateFiles.Columns.Add("Type", typeof(System.String));

            foreach (var v in DataAdd)
            {
                DataRow dr = dtUpdateFiles.Rows.Add();
                dr["Type"] = "1";
                dr["Name"] = v.Name;
                dr["Path"] = v.Path;

                //ListViewItem item = new ListViewItem("新增");
                //item.SubItems.Add(v.Name);//文件名
                //item.SubItems.Add(v.Path);//路径
                //LVFile.Items.Add(item);
            }
            foreach (var v in DataEdit)
            {
                DataRow dr = dtUpdateFiles.Rows.Add();
                dr["Type"] = "2";
                dr["Name"] = v.Name;
                dr["Path"] = v.Path;

                //ListViewItem item = new ListViewItem("替换");
                //item.SubItems.Add(v.Name);//文件名
                //item.SubItems.Add(v.Path);//路径
                //LVFile.Items.Add(item);
            }
            foreach (var v in DataDelete)
            {
                DataRow dr = dtUpdateFiles.Rows.Add();
                dr["Type"] = "3";
                dr["Name"] = v.Name;
                dr["Path"] = v.Path;

                //ListViewItem item = new ListViewItem("删除");
                //item.SubItems.Add(v.Name);//文件名
                //item.SubItems.Add(v.Path);//路径
                //LVFile.Items.Add(item);
            }

版本更新:

//需要新增的
            //需要删除的
            //需要替换的

            var DataEdit = from dtServer in ServerDetailFiles.AsEnumerable()
                           join dtLocation in LocalDetailFiles.AsEnumerable()
                           on dtServer.Field<string>(DataSchema.DetailSchema.Path) + dtServer.Field<string>(DataSchema.DetailSchema.Name) equals
                                dtLocation.Field<string>(DataSchema.DetailSchema.Path) + dtLocation.Field<string>(DataSchema.DetailSchema.Name)
                           where dtServer.Field<DateTime>(DataSchema.DetailSchema.EditDate) > dtLocation.Field<DateTime>(DataSchema.DetailSchema.EditDate)
                           select new
                           {
                               Name = dtServer.Field<string>(DataSchema.DetailSchema.Name),
                               Path = dtServer.Field<string>(DataSchema.DetailSchema.Path)
                           };
            var DataAdd = from dtServer in ServerDetailFiles.AsEnumerable()
                          where !LocalDetailFiles.AsEnumerable().Any(y => y.Field<string>(DataSchema.DetailSchema.Path) + y.Field<string>(DataSchema.DetailSchema.Name) == dtServer.Field<string>(DataSchema.DetailSchema.Path) + dtServer.Field<string>(DataSchema.DetailSchema.Name))
                          select new
                          {
                              Name = dtServer.Field<string>(DataSchema.DetailSchema.Name),
                              Path = dtServer.Field<string>(DataSchema.DetailSchema.Path)
                          };
            var DataDelete = from dtLocation in LocalDetailFiles.AsEnumerable()
                             where !ServerDetailFiles.AsEnumerable().Any(y => y.Field<string>(DataSchema.DetailSchema.Path) + y.Field<string>(DataSchema.DetailSchema.Name) == dtLocation.Field<string>(DataSchema.DetailSchema.Path) + dtLocation.Field<string>(DataSchema.DetailSchema.Name))
                             select new
                             {
                                 Name = dtLocation.Field<string>(DataSchema.DetailSchema.Name),
                                 Path = dtLocation.Field<string>(DataSchema.DetailSchema.Path)
                             };

Winform版本发布更新

标签:

原文地址:http://www.cnblogs.com/GarsonZhang/p/4337870.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!