private void btnCheckinAll_Click(object sender, EventArgs e) { foreach (string itemSpec in ltbFilesCheckedOutItems.Items) { if (filesCheckedOutByCurrentUser.ContainsKey(itemSpec)) { VSSItem item = filesCheckedOutByCurrentUser[itemSpec]; item.Checkin(string.Empty, item.LocalSpec, 0); } } }
private void AddToSourcesafe(Database db, string dest) { try { dname.Text = "Check out from Sourcesafe. Objects = " + objectCount.ToString(); oname.Text = ""; string vssPath = m_vssRootPath; VSSItem VssDbItem = GetVssItem(vssPath, VSSItemType.VSSITEM_PROJECT, serverName, db.Name); VssDbItem.LocalSpec = dest; dname.Text = "Checking in to Sourcesafe. Objects = " + objectCount.ToString(); oname.Text = ""; VssDbItem.Checkin("DBScriptManager Automatic Checkin", dest, (int)(VSSFlags.VSSFLAG_DELTAYES | VSSFlags.VSSFLAG_RECURSYES | VSSFlags.VSSFLAG_DELYES)); dname.Text = "Undoing checkouts. Objects = " + objectCount.ToString(); oname.Text = ""; VssDbItem.UndoCheckout(dest, (int)(VSSFlags.VSSFLAG_GETNO | VSSFlags.VSSFLAG_DELYES | VSSFlags.VSSFLAG_RECURSYES)); // Now ensure that all the files that were originally retrieved from Sourcesafe have been removed foreach (string file in preExistingSourcesafeEntries) { File.Delete(file); } dname.Text = "Adding to Sourcesafe. Objects = " + objectCount.ToString(); oname.Text = ""; VssDbItem.Add(dest, "Created by DBScriptManager", (int)(VSSFlags.VSSFLAG_DELYES | VSSFlags.VSSFLAG_RECURSYES)); dname.Text = "Sourcesafe check in complete."; oname.Text = ""; } catch (Exception ex) { dname.Text = "Error in AddToSourcesafe method. [" + ex.Message + "]"; oname.Text = ""; m_vssDatabase.Close(); m_vssDatabase = null; errorsOccurred = true; Logger.Log("AddToSourcesafe Error\r\n" + ex.StackTrace); throw; } }
//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); }