static void ParseSyncMap() { maps.Clear(); string currDir = Environment.CurrentDirectory; string mapFile = currDir + "/syncfg.txt"; if (File.Exists(mapFile)) { var lines = File.ReadAllLines(mapFile); foreach (string line in lines) { if (string.IsNullOrEmpty(line) || line.StartsWith("//")) { continue; } var syncData = new SyncDataInfo(); if (line.Contains(":")) { var strs = line.Split(':'); if (ParseKeyValue(strs[0], ref syncData)) { ParseExtName(strs[1], ref syncData); } } else { ParseKeyValue(line, ref syncData); } } } }
/// <summary> /// 添加同步信息到同步信息记录表中 /// </summary> /// <param name="syncInfo"></param> /// <returns></returns> public static bool AddSyncDataRecord(SyncDataInfo syncInfo) { try { if (syncInfo == null || string.IsNullOrEmpty(syncInfo.ProgId) || string.IsNullOrEmpty(syncInfo.InternalId) || string.IsNullOrEmpty(syncInfo.UserId)) { return(false); } string sql = string.Format("insert into AXPSYNCDATAHISTORY(INFOID,PROGID,INTERNALID,BILLNO,USERID,SITEID,SYNCTIME,SYNCOP,SYNCSTATE,SYNCINFO) " + "values({0},{1},{2},{3},{4},{5},{6},{7},{8},{9})", LibStringBuilder.GetQuotString(Guid.NewGuid().ToString()), LibStringBuilder.GetQuotString(syncInfo.ProgId), LibStringBuilder.GetQuotString(syncInfo.InternalId), LibStringBuilder.GetQuotString(syncInfo.BillNo), LibStringBuilder.GetQuotString(syncInfo.UserId), LibStringBuilder.GetQuotString(syncInfo.SiteId), LibDateUtils.DateTimeToLibDateTime(syncInfo.SyncTime), (int)syncInfo.SyncOp, (int)syncInfo.SyncState, LibStringBuilder.GetQuotString(syncInfo.SyncInfo) ); LibDataAccess dataAccess = new LibDataAccess(); int count = dataAccess.ExecuteNonQuery(sql); return(count > 0); } catch (Exception exp) { LibCommUtils.AddOutput("CrossSiteCall", string.Format("error:{0}\r\nStacktrace:{1}", exp.Message, exp.StackTrace)); return(false); } }
//[WebInvoke(Method = "PUT", UriTemplate = "/CodeSync/GetData")] public Stream GetSyncData(SyncDataInfo dataInfo) { var request = new RestRequest(this.ServiceUrl + "/CodeSync/GetData", Method.PUT); request.AddParameter("application/json", SerializeObject(dataInfo), ParameterType.RequestBody); return(ExecuteRequestFor <Stream>(request)); }
static bool ParseKeyValue(string line, ref SyncDataInfo syncData) { line = line.Trim(); var strs = line.Split('='); var currDir = Environment.CurrentDirectory; if (!string.IsNullOrEmpty(strs[0]) && !string.IsNullOrEmpty(strs[1])) { syncData.srcPath = (currDir + "/" + strs[0].Trim()).Replace('\\', '/'); syncData.destPath = (currDir + "/" + strs[1].Trim()).Replace('\\', '/'); syncData.isDirectory = !syncData.srcPath.Contains(".") && !syncData.destPath.Contains("."); maps.Add(syncData); return(true); } return(false); }
static void ParseExtName(string line, ref SyncDataInfo syncData) { line = line.Trim(); if (string.IsNullOrEmpty(line)) { return; } if (line[0] == '+') { var newLine = line.Remove(0, 1); syncData.includes = new List <string>(newLine.Split(',')); } else if (line[0] == '-') { var newLine = line.Remove(0, 1); syncData.excludes = new List <string>(newLine.Split(',')); } }
static void SyncDirOrFile(SyncDataInfo syncData) { string currDir = Environment.CurrentDirectory; if (syncData.isDirectory) //文件夹 { CopyFolder(syncData.srcPath, syncData.destPath, syncData.includes, syncData.excludes); } else { if (File.Exists(syncData.destPath)) { File.Delete(syncData.destPath); } File.Copy(syncData.srcPath, syncData.destPath, true); Console.WriteLine("[{0}]=>[{1}]", syncData.srcPath, syncData.destPath); } }
/// <summary> /// 根据信息唯一标识InfoId更新数据同步的历史结果 /// </summary> /// <param name="syncInfo"></param> /// <returns></returns> public static bool UpdateSyncDataRecord(SyncDataInfo syncInfo) { try { if (syncInfo == null || string.IsNullOrEmpty(syncInfo.InfoId)) { return(false); } string sql = string.Format("update AXPSYNCDATAHISTORY set SYNCSTATE={0},SYNCINFO={1} where INFOID={2}", (int)syncInfo.SyncState, LibStringBuilder.GetQuotString(syncInfo.SyncInfo), LibStringBuilder.GetQuotString(syncInfo.InfoId) ); LibDataAccess dataAccess = new LibDataAccess(); int count = dataAccess.ExecuteNonQuery(sql); return(count > 0); } catch (Exception exp) { LibCommUtils.AddOutput("CrossSiteCall", string.Format("error:{0}\r\nStacktrace:{1}", exp.Message, exp.StackTrace)); return(false); } }