private void btnBackup_Click(object sender, EventArgs e) { if (lstName.CheckedItems.Count == 0) { MessageBox.Show("Not selected anything.", "Information", MessageBoxButtons.OK); return; } List <string> aMsg = new List <string>(); using (new CWaitCursor(this, btnBackup)) { for (int i = 0; i < lstName.CheckedItems.Count; i++) { string NameCur = (string)lstName.CheckedItems[i]; SInfoBackup InfoIs; string ErrMsgIs; if (!IsValidForBackup(NameCur, out InfoIs, out ErrMsgIs)) { MessageBox.Show(ErrMsgIs, "Information", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1); return; } CSyncFile SyncFile = null; if (InfoIs.FtpInfo == null) { SyncFile = new CSyncFile(this.maFullPathFromCmd, InfoIs.RootFolderSrc, new string[] { InfoIs.RootFolderDest }, SyncTypes.AfterSrcTime, InfoIs.MinifyJs, InfoIs.aFullPathReferencingJs, InfoIs.aJsFullPathRefered, DateTime.MinValue, InfoIs.LogFolder); } else { SyncFile = new CSyncFile(this.maFullPathFromCmd, InfoIs.RootFolderSrc, new CFtpInfoSync[] { InfoIs.FtpInfo }, SyncTypes.AfterSrcTime, InfoIs.MinifyJs, InfoIs.aFullPathReferencingJs, InfoIs.aJsFullPathRefered, DateTime.MinValue, InfoIs.LogFolder); } //선택한 파일은 무조건 복사해야 해서 주석 //SyncFile.DisallowedExt = InfoIs.DisallowedExt.Split(';'); //if (InfoIs.DisallowedFolder != "") //{ // SyncFile.DisallowedFolder = InfoIs.DisallowedFolder.Split(';'); //} SyncFile.CopyAll(); if (SyncFile.CountFailed > 0) { aMsg.Add(string.Format("There's {0} count failed from {1}", SyncFile.CountFailed, NameCur)); } } } aMsg.Add("Completed."); MessageBox.Show(string.Join("\r\n\r\n", aMsg.ToArray()), "Information", MessageBoxButtons.OK); }
void tmr_Elapsed(object sender, ElapsedEventArgs e) { const char Delim = '─'; if (this.mRunning) { return; } else { this.mRunning = true; } string LogFullPath = GetLogFullPath(); string LogFolderForSync = Path.GetDirectoryName(LogFullPath); try { CXmlConfig xc = GetXmlConfig(); string[] aRootPathSrc = xc.GetSetting("RootPathSrc", "").Split(Delim); string[] aFtpHost = xc.GetSetting("FtpHost", "").Split(Delim); string[] aFtpId = xc.GetSetting("FtpId", "").Split(Delim); string[] aFtpPassword = xc.GetSetting("FtpPassword", "").Split(Delim); for (int i = 0; i < aFtpPassword.Length; i++) { aFtpPassword[i] = CEncrypt.DecryptPassword(aFtpPassword[i]); } string[] aFtpFolder = xc.GetSetting("FtpFolder", "").Split(Delim); string[] aSyncType = xc.GetSetting("SyncType", "").Split(Delim); string[] aMinifyJs = xc.GetSetting("MinifyJs", "").Split(Delim); string[] aFileNameToAppendParam = xc.GetSetting("FileNameToAppendParam", "").Split(Delim); string[] asDateTimeAfter = xc.GetSetting("DateTimeAfter", "").Split(Delim); DateTime[] aDateTimeAfter = new DateTime[asDateTimeAfter.Length]; for (int i = 0; i < asDateTimeAfter.Length; i++) { aDateTimeAfter[i] = CFindRep.IfNotDateTimeThen19000101(asDateTimeAfter[i]); } for (int i = 0; i < aRootPathSrc.Length; i++) { CFtpInfoSync[] aFtpInfo = new CFtpInfoSync[] { new CFtpInfoSync() { Host = aFtpHost[i], UserId = aFtpId[i], Password = aFtpPassword[i], Folder = aFtpFolder[i] } }; CSyncFile sf = new CSyncFile(aRootPathSrc[i], aFtpInfo, CEnum.GetValueByName <SyncTypes>(aSyncType[i]), (aMinifyJs[i] == "1"), aFileNameToAppendParam, aDateTimeAfter[i], LogFolderForSync); sf.DisallowedFolder = new string[] { LogFolderForSync }; sf.CopyAll(); aDateTimeAfter[i] = DateTime.Now; } for (int i = 0; i < aDateTimeAfter.Length; i++) { asDateTimeAfter[i] = aDateTimeAfter[i].ToString(CConst.Format_yyyy_MM_dd_HH_mm_ss); } xc.SaveSetting("DateTimeAfter", string.Join(Delim.ToString(), asDateTimeAfter)); } catch (Exception ex) { CFile.AppendTextToFile(LogFullPath, "Error " + DateTime.Now.ToString() + "\r\n" + ex.Message + "\r\n" + ex.StackTrace + "\r\n" + ex.Source); } this.mRunning = false; }
private void btnSyncNow_Click(object sender, EventArgs e) { using (new CWaitCursor(this, btnSyncNow)) { SInfo InfoIs; string ErrMsgIs; if (!IsValid(out InfoIs, out ErrMsgIs)) { MessageBox.Show(ErrMsgIs, "Information", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1); return; } CSyncFile SyncFile = null; if (InfoIs.FtpInfo == null) { SyncFile = new CSyncFile(InfoIs.RootFolderSrc, InfoIs.aRootFolderDest, InfoIs.SyncType, InfoIs.MinifyJs, InfoIs.aFullPathReferencingJs, InfoIs.aJsFullPathRefered, InfoIs.DateTimeAfter, InfoIs.LogFolder); } else { SyncFile = new CSyncFile(InfoIs.RootFolderSrc, new CFtpInfoSync[] { InfoIs.FtpInfo }, InfoIs.SyncType, InfoIs.MinifyJs, InfoIs.aFullPathReferencingJs, InfoIs.aJsFullPathRefered, InfoIs.DateTimeAfter, InfoIs.LogFolder); } if (radDisallowedExt.Checked) { SyncFile.DisallowedExt = InfoIs.DisallowedExt.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); } else { SyncFile.AllowedOnlyExt = InfoIs.AllowedOnlyExt.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); } if (radDisallowedFolder.Checked) { SyncFile.DisallowedFolder = InfoIs.DisallowedFolder.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); } else { SyncFile.AllowedOnlyFolder = InfoIs.AllowedOnlyFolder.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); } SyncFile.CopyAll(); if (InfoIs.EmptyFolderHasNoFile) { foreach (string RootFolderDest in InfoIs.aRootFolderDest) { CFile.EmptyFolderHasNoFile(RootFolderDest); } } if (SyncFile.CountFailed > 0) { MessageBox.Show(string.Format("{0} count of file failed.", SyncFile.CountFailed), "Information", MessageBoxButtons.OK); return; } if (InfoIs.SyncType == SyncTypes.AfterSrcTime) { //다음번에 이 시간을 기준할 수 있게 함. DataTable dt = GetTable(); DataGridViewCell dgv = grvList.SelectedCells[0]; dt.Rows[dgv.OwningRow.Index]["DateTimeAfter"] = DateTime.Now; tlsbtnSave.PerformClick(); } sttlblMsg.Text = "Synchronization completed at " + DateTime.Now.ToString(); } }