private void btnStartCopy_Click(object sender, EventArgs e) { PictureBox1.Visible = false; var cp = new CopyParams(txtSourceDir.Text, GetDestinationDirs(lvDrives)); try { // Validate user input on UI ValidateCopyParams(cp._sourceDir, cp._destDirs); // No exceptions, so continue.... // Disable UI controls and set status DisableUI(); lblStatus.Text = "Copying..."; var logStr = string.Format("Starting to copy '{0}' to {1} {2}...", cp._sourceDir, cp._destDirs.Count, "drive".Pluralize(cp._destDirs.Count)); Logger.Log(logStr, rt); // Begin the copy in BackgroundWorker, pass CopyParams object into it bw.RunWorkerAsync(cp); } catch (Exception ex) { var logStr = string.Format("Error: {0}", ex.Message); Logger.Log(logStr, rt, Color.Red); //MessageBox.Show("Error: " + ex.Message, "USB Batch Copy", MessageBoxButtons.OK, MessageBoxIcon.Error); if (ex.Message.Contains("Target destination drive does not exist")) { PopulateListView(lvDrives); } } }
public bool CopyFile(Organization org, string srcFullName, string dstFullName) { Log.DebugFormat("CopyFile: org={0} {1}, srcFullName={2}, dstFullName={3}", org.shortName, org.filespaceId, srcFullName, dstFullName); try { if (!FolderExists(org.filespaceId, dstFullName.Substring(0, dstFullName.LastIndexOf("/")) + "/")) { MkDir mkdirParams = new MkDir() { filespaceid = org.filespaceId, force = true, path = dstFullName.Substring(0, dstFullName.LastIndexOf("/")) + "/" }; var resultCreate = ExecuteRequest(Ticket, Method.GET, "/tcc/MkDir", mkdirParams, typeof(ApiResult)); if (resultCreate == null) { Log.ErrorFormat("Can not create folder for org {0} folder {1}", org.shortName, dstFullName.Substring(0, dstFullName.LastIndexOf("/")) + "/"); return(false); } } CopyParams copyParams = new CopyParams() { filespaceid = org.filespaceId, path = srcFullName, newfilespaceid = org.filespaceId, newPath = dstFullName, merge = false, replace = true }; var result = ExecuteRequest(Ticket, Method.GET, "/tcc/Copy", copyParams, typeof(ApiResult)); if (result != null) { if (result.success) { return(true); } CheckForInvalidTicket(result, "CopyFile"); } else { Log.ErrorFormat("Null result from CopyFile for org {0} file {1}", org.shortName, srcFullName); } } catch (Exception ex) { Log.ErrorFormat("Failed to copy TCC file for org {0} file {1}: {2}", org.shortName, srcFullName, ex.Message); } return(false); }
public async Task <bool> CopyFile(string srcFilespaceId, string dstFilespaceId, string srcFullName, string dstFullName) { Log.LogDebug( $"CopyFile: srcFilespaceId={srcFilespaceId}, srcFilespaceId={srcFilespaceId}, dstFilespaceId={dstFilespaceId} srcFullName={srcFullName}, dstFullName={dstFullName}"); try { var dstPath = dstFullName.Substring(0, dstFullName.LastIndexOf("/", StringComparison.Ordinal)) + "/"; if (!await FolderExists(dstFilespaceId, dstPath)) { var resultCreate = await MakeFolder(dstFilespaceId, dstPath); if (!resultCreate) { Log.LogError("Can not create folder for filespaceId {dstFilespaceId} folder {dstPath}"); return(false); } } var copyParams = new CopyParams { filespaceid = srcFilespaceId, path = srcFullName, newfilespaceid = dstFilespaceId, newPath = dstFullName, merge = false, replace = true//Not sure if we want true or false here }; var copyResult = await ExecuteRequest <ApiResult>(Ticket, "Copy", copyParams); if (copyResult != null) { if (copyResult.success || copyResult.errorid.Contains("INVALID_OPERATION_FILE_IS_LOCKED")) { return(true); } CheckForInvalidTicket(copyResult, "CopyFile"); } else { Log.LogError($"Null result from CopyFile for filespaceId {srcFilespaceId} file {srcFullName}"); } } catch (Exception ex) { Log.LogError($"Failed to copy TCC file for srcFilespaceId={srcFilespaceId}, srcFilespaceId={srcFilespaceId}, dstFilespaceId={dstFilespaceId} srcFullName={srcFullName}, dstFullName={dstFullName} error:{ex.Message}"); } return(false); }
private static void ProcessUpdateLog(string serverRootPath, bool cleanup) { /** UpdateLogxx.txt * Backup d:\Sopbin\Sop\File.dta:62976 to _SystemTransactionDataBackup1:386048 Size=2560 * Backup d:\Sopbin\Sop\File.dta:66048 to _SystemTransactionDataBackup2:388608 Size=2560 */ string[] updateLogs = null; try { updateLogs = Directory.GetFiles(serverRootPath, string.Format("{0}*.txt", UpdateLogLiteral)); } catch { return; } var backupFiles = new Dictionary <string, object>(); var restoreLookup = new List <CopyParams>(); foreach (string s in updateLogs) { restoreLookup.Clear(); //** open the file and do restore for each backed up entry FileStream fs = null; try { fs = new FileStream(s, FileMode.Open, FileAccess.Read, FileShare.None); } catch { if (fs != null) { try { fs.Dispose(); } catch { } } fs = null; } if (fs == null) { continue; } using (fs) { using (var sr = new StreamReader(fs.RealStream)) { while (sr.Peek() >= 0) { string l = sr.ReadLine(); if (l.StartsWith(BackupFromToken)) { const string ToToken = " to "; int i2 = l.IndexOf(ToToken + DataBackupFilenameLiteral, BackupFromToken.Length); string from = l.Substring(BackupFromToken.Length, i2 - BackupFromToken.Length); long fromAddress; int d = from.LastIndexOf(':'); if (d > 0 && long.TryParse(from.Substring(d + 1), out fromAddress)) { from = from.Substring(0, d); string s2 = l.Substring(i2 + ToToken.Length); // + DataBackupFilenameLiteral.Length + 1); if (!string.IsNullOrEmpty(s2)) { string[] toP = s2.Split(new char[] { ' ' }); if (toP.Length > 1) { int indexOfSemi = toP[0].IndexOf(':', DataBackupFilenameLiteral.Length); string addressText = toP[0].Substring(indexOfSemi + 1); long toAddress; if (long.TryParse(addressText, out toAddress)) { int dataSize; if (toP[1].Length > 5 && int.TryParse(toP[1].Substring(5), out dataSize) && Sop.Utility.Utility.FileExists(from)) { string sourceFilename = toP[0].Substring(0, indexOfSemi); if (!backupFiles.ContainsKey(sourceFilename)) { backupFiles.Add(sourceFilename, null); } var rs = new CopyParams(); rs.DataSize = dataSize; rs.TargetAddress = fromAddress; rs.TargetFilename = from; rs.SourceAddress = toAddress; rs.SourceFilename = sourceFilename; restoreLookup.Add(rs); } } } } } } } } } if (restoreLookup.Count > 0) { CopyData(serverRootPath, restoreLookup); } //** delete the Update log file after processing its contents... (we're done with it) if (cleanup) { File.Delete(s); } } //** delete the system transaction backup file if (cleanup && backupFiles.Count > 0) { foreach (string s in backupFiles.Keys) { File.Delete(string.Format("{0}\\{1}", serverRootPath, s)); } } }
private void btnStartCopy_click(object sender, EventArgs e) { var ECL2 = ""; var softwarePartNumber1 = ""; var softwareDir2 = ""; bool eraseUSB = true; PictureBox1.Image = Properties.Resources.questionmark; if (!Directory.Exists(VAULT_PATH)) { Logger.Log(@"Error: Cannot find vault (V:\ drive). Check network connection and try again.", rt, Color.Red); return; } if (cboAssembly.Items.Count == 0) { Logger.Log("Error: No software part numbers found. Check config file.", rt, Color.Red); return; } // if CTRL is held while clicking the Copy button, the USB drive will not be erased before copying. eraseUSB &= Control.ModifierKeys != Keys.Control; try { if (AssemblyDict.TryGetValue(cboAssembly.Text, out string value)) { softwarePartNumber1 = value; } // if there are two softwares for that assembly, parse them if (softwarePartNumber1.Contains(";")) { string softwarePartNumber2 = softwarePartNumber1.Substring(softwarePartNumber1.IndexOf(";") + 1); softwarePartNumber1 = softwarePartNumber1.Substring(0, softwarePartNumber1.IndexOf(";")); ECL2 = GetECL(softwarePartNumber2); string softwareTopDir2 = GetFullSoftwarePath(softwarePartNumber2); softwareDir2 = $@"{softwareTopDir2}\ECL-{ECL2}"; } string ECL1 = GetECL(softwarePartNumber1); string softwareTopDir1 = GetFullSoftwarePath(softwarePartNumber1); string softwareDir1 = $@"{softwareTopDir1}\ECL-{ECL1}"; // Validate user input on UI var cp = new CopyParams(softwareDir1, softwareDir2, GetDestinationDirs(lvDrives), softwarePartNumber1, ECL1, ECL2, eraseUSB); ValidateCopyParams(cp.Source1, cp.Destinations); // No exceptions, so continue.... Logger.Log($"Latest software found: {softwarePartNumber1} ECL-{ECL1}", rt); // Show warning that drive will be erased if (eraseUSB) { if (MessageBox.Show(new Form { TopMost = true }, "The selected USB drive will be erased!\nDo you wish to continue?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No) { Logger.Log("Software loading operation cancelled.", rt, Color.Red); return; } } // Disable UI controls DisableUI(); // Begin the copy in BackgroundWorker, pass CopyParams object into it bw.RunWorkerAsync(cp); } catch (Exception ex) { var logStr = $"Error: {ex.Message}"; Logger.Log(logStr, rt, Color.Red); if (ex.Message.Contains("Target destination drive does not exist")) { PopulateListView(lvDrives, false); } } }