版本发布:
一、局域网共享文件方式
发布界面:
更新界面:
二、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) };