/// <summary> /// Main task execution method /// </summary> protected override void ExecuteTask() { Open(); const int FILE_ALREADY_ADDED = -2147166572; // Attempt to add each file to SourceSafe. If file is already in SourceSafe // then log a message and continue otherwise throw an exception. foreach (string currentFile in AddFileSet.FileNames) { try { IVSSItem actualProject = CreateProjectPath(currentFile); if (actualProject != null) { actualProject.Add(currentFile, Comment, 0); } else { Item.Add(currentFile, Comment, 0); } Log(Level.Info, "Added file '{0}.", currentFile); } catch (System.Runtime.InteropServices.COMException ex) { if (ex.ErrorCode == FILE_ALREADY_ADDED) { Log(Level.Warning, "File '{0}' was already added before.", currentFile); } else { throw new BuildException(string.Format(CultureInfo.InvariantCulture, "Failure adding '{0}' to SourceSafe.", currentFile), Location, ex); } } catch (Exception ex) { throw new BuildException(string.Format(CultureInfo.InvariantCulture, "Failure adding '{0}' to SourceSafe.", currentFile), Location, ex); } } }
//Unpin + Checkout (PrepareToPush) + Checkin + Pin or Add + Pin + + Exception handling public bool PushFile(string vssDir, string localDir, string localFileName, string patchName, out VSSItem item) { if (!PrepareToPushFile(vssDir, localDir, localFileName)) { item = null; return(false); } string vssPath = $"{vssDir}/{localFileName}"; string localPath = Path.Combine(localDir, localFileName); try { item = VSSDB.get_VSSItem(vssPath, false); item.Checkin("", localPath); if (item.IsCheckedOut == 0) { sender($"{item.Spec} checked in"); try { Pin(item, item.VersionNumber); sender($"{item.Spec} pinned"); } catch { sender($"Cannot pin {item.Spec}"); } } else { if (MessageBox.Show($"Файл {localFileName} не зачекинился. Требуется повторить попытку или выложить патч заново", "Предупреждение", MessageBoxButtons.RetryCancel, MessageBoxIcon.Warning) == DialogResult.Retry) { return(PushFile(vssDir, localDir, localFileName, patchName, out item)); } /* * Process pr = new Process(); * pr.StartInfo.FileName = "cmd.exe"; * pr.StartInfo.UseShellExecute = false; * pr.StartInfo.RedirectStandardOutput = true; * pr.StartInfo.RedirectStandardInput = true; * pr.StartInfo.CreateNoWindow = true; * pr.Start(); * * string drive = Path.GetPathRoot(localDir).Replace("\\", ""); * pr.StandardInput.WriteLine(drive); * pr.StandardInput.WriteLine($"set SSDIR={basePath}"); * pr.StandardInput.WriteLine($"\"{SSExeFullName}\" checkin \"{item.Spec}\""); * pr.StandardInput.WriteLine($"\"{SSExeFullName}\" pin \"{item.Spec}\" -V{item.VersionNumber}"); * * sender($"{item.Spec} checked in and pinned via cmd"); * MessageBox.Show($"Костыль. Запинили с помощью консоли файл {item.Spec}. Требуется проверить вручную.", "Предупреждение", MessageBoxButtons.OK, MessageBoxIcon.Warning); */ } } catch (System.Runtime.InteropServices.COMException exc) { if (!IsFileNotFoundError(exc)) { throw exc; } else { sender($"{vssPath} не найден. Добавление нового файла..."); IVSSItem dir = VSSDB.get_VSSItem(vssDir, false); item = dir.Add(localPath); sender($"{item.Spec} добавлен"); try { Pin(item, item.VersionNumber); sender($"{item.Spec} pinned"); } catch { sender($"Cannot pin {item.Spec}"); } } } Process p = new Process(); p.StartInfo.FileName = "cmd.exe"; p.StartInfo.UseShellExecute = false; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.RedirectStandardInput = true; p.StartInfo.CreateNoWindow = true; p.Start(); p.StandardInput.WriteLine($"set SSDIR={basePath}"); p.StandardInput.WriteLine($"\"{SSExeFullName}\" Comment \"{item.Spec}\""); p.StandardInput.WriteLine($"Patch {patchName}"); return(true); }