private void DumpUsers() { var df = new VssDatabaseFactory(vssDirTextBox.Text); var db = df.Open(); var path = vssProjectTextBox.Text; VssProject project; try { project = db.GetItem(path) as VssProject; } catch (VssPathException ex) { MessageBox.Show(ex.Message, "Invalid project path", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (project == null) { MessageBox.Show(path + " is not a project", "Invalid project path", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } var emailDictionary = ReadDictionaryFile("e-mail dictionary", db.BasePath, emailPropertiesFileName); AdvancedTaskbar.EnableItermediate(); this.statusTimer.Enabled = true; this.emailMap.Enabled = false; this.goButton.Enabled = false; this.cancelButton.Text = "Cancel"; revisionAnalyzer = new RevisionAnalyzer(workQueue, logger, db); if (!string.IsNullOrEmpty(excludeTextBox.Text)) { revisionAnalyzer.ExcludeFiles = excludeTextBox.Text; } revisionAnalyzer.AddItem(project); workQueue.AddLast(delegate(object work) { foreach (var dateEntry in revisionAnalyzer.SortedRevisions) { foreach (Revision revision in dateEntry.Value) { var user = revision.User.ToLower(); if (emailDictionary.ContainsKey(user)) { continue; } emailDictionary.Add(user, ""); } } string propsPath = Path.Combine(db.BasePath, emailPropertiesFileName); WriteDictionaryFile(emailDictionary, propsPath); this.BeginInvoke((MethodInvoker) delegate { MessageBox.Show(this, string.Format(emailUserNamesListMessage, propsPath), emailUserNamesListCaption, MessageBoxButtons.OK, MessageBoxIcon.Information); }); }); }
private void statusTimer_Tick(object sender, EventArgs e) { statusLabel.Text = workQueue.LastStatus ?? "Idle"; timeLabel.Text = string.Format("Elapsed: {0:HH:mm:ss}", new DateTime(workQueue.ActiveTime.Ticks)); if (revisionAnalyzer != null) { fileLabel.Text = "Files: " + revisionAnalyzer.FileCount; revisionLabel.Text = "Revisions: " + revisionAnalyzer.RevisionCount; } if (changesetBuilder != null) { changeLabel.Text = "Changesets: " + changesetBuilder.Changesets.Count; if (changesetBuilder.Changesets.Count > 1) { AdvancedTaskbar.EnableProgress((uint)changesetBuilder.Changesets.Count); } } if (workQueue.IsIdle) { revisionAnalyzer = null; changesetBuilder = null; statusTimer.Enabled = false; if (!goButton.Enabled) { LoadRepoSettings(); } emailMap.Enabled = true; goButton.Enabled = true; AdvancedTaskbar.Disable(); cancelButton.Text = "Close"; if (goAndExit && exitOnComplete) { exitOnComplete = false; Close(); } } var exceptions = workQueue.FetchExceptions(); if (exceptions != null) { foreach (var exception in exceptions) { ShowException(exception); } } }
private bool AbortRetryIgnore(ThreadStart work, MessageBoxButtons buttons) { bool retry; do { try { work(); return(true); } catch (Exception e) { var message = LogException(e); AdvancedTaskbar.SetErrorState(); message += "\nSee log file for more information."; if (ignoreVcsErrors) { retry = false; continue; } var button = MessageBox.Show(message, "Error", buttons, MessageBoxIcon.Error); switch (button) { case DialogResult.Retry: retry = true; AdvancedTaskbar.SetUserResponseState(DialogResult.Retry); break; case DialogResult.Ignore: retry = false; AdvancedTaskbar.SetUserResponseState(DialogResult.Ignore); break; default: retry = false; workQueue.Abort(); AdvancedTaskbar.SetUserResponseState(DialogResult.Abort); break; } } } while (retry); return(false); }
public void ExportToVcs(string repoPath, DateTime?continueAfter) { if (resetRepo) { continueAfter = null; } this.continueAfter = continueAfter; workQueue.AddLast(delegate(object work) { var stopwatch = Stopwatch.StartNew(); logger.WriteSectionSeparator(); LogStatus(work, "Initializing repository"); // create repository directory if it does not exist if (!Directory.Exists(repoPath)) { if (continueAfter != null) { throw new ProcessException("Unable to continue: " + repoPath + " does not exist.", null, null); } Directory.CreateDirectory(repoPath); } string vcs = vcsWrapper.GetVcs(); while (!vcsWrapper.FindExecutable()) { var button = MessageBox.Show(vcs + " not found in PATH. " + "If you need to modify your PATH variable, please " + "restart the program for the changes to take effect.", "Error", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error); if (button == DialogResult.Cancel) { workQueue.Abort(); return; } } bool makeInitialCommit = resetRepo; if (!RetryCancel(delegate { vcsWrapper.Init(resetRepo); })) { return; } AbortRetryIgnore(delegate { vcsWrapper.Configure(continueAfter == null); }); var pathMapper = new VssPathMapper(); if (UseProjectsFile) { string rootPath = repoPath; foreach (var rootProject in revisionAnalyzer.RootProjects) { string path = rootProject.RootPath; path = path.Replace("/", "\\"); if (path.StartsWith("\\")) { path = rootPath + path; } else { path = rootPath + "\\" + path; } pathMapper.SetProjectPath(rootProject.PhysicalName, path, rootProject.Path); } } else { // create mappings for root projects foreach (var rootProject in revisionAnalyzer.RootProjects) { // root must be repo path here - the path mapper uses paths relative to this one VssPathMapper vssPathMapper = new VssPathMapper(); var rootPath = repoPath; if (RemovePath != "") { if (rootProject.Path.StartsWith(RemovePath)) { string path = rootProject.Path.Replace(RemovePath, ""); path = path.Replace("/", "\\"); if (path.StartsWith("\\")) { rootPath = rootPath + path; } else { rootPath = rootPath + "\\" + path; } } else { var button = MessageBox.Show($"{RemovePath} not found in path, Do you wanne continue with all contint in the root folder.", "Error", MessageBoxButtons.OKCancel, MessageBoxIcon.Error); if (button == DialogResult.Cancel) { workQueue.Abort(); return; } } } pathMapper.SetProjectPath(rootProject.PhysicalName, rootPath, rootProject.Path); } } var changesets = changesetBuilder.Changesets; // create a log of all MoveFrom and MoveTo actions logger.WriteSectionSeparator(); logger.WriteLine("List of Move Operations"); logger.WriteSectionSeparator(); int changeSetNo = 0; int revisionNo = 0; foreach (var changeset in changesets) { foreach (var revision in changeset.Revisions) { var actionType = revision.Action.Type; VssItemName target = null; var namedAction = revision.Action as VssNamedAction; if (namedAction != null) { target = namedAction.Name; } switch (actionType) { case VssActionType.MoveFrom: var moveFromAction = (VssMoveFromAction)revision.Action; logger.WriteLine("{3}-{4}-{0}: MoveFrom {1} to {2}", revision.Item, moveFromAction.OriginalProject, target, changeSetNo, revisionNo); break; case VssActionType.MoveTo: var moveToAction = (VssMoveToAction)revision.Action; logger.WriteLine("{3}-{4}-{0}: MoveTo {1} from {2}", revision.Item, moveToAction.NewProject, target, changeSetNo, revisionNo); break; } revisionNo++; } changeSetNo++; //AdvancedTaskbar.SetPosition((uint)changeSetNo); } // replay each changeset logger.WriteSectionSeparator(); logger.WriteLine("Replaying Changesets"); var changesetId = 0; var commitCount = 0; var tagCount = 0; var replayStopwatch = new Stopwatch(); var labels = new LinkedList <Revision>(); tagsUsed.Clear(); bool found = continueAfter == null; foreach (var changeset in changesets) { ++changesetId; if (workQueue.IsAborting) { return; } if (!found) { if (continueAfter.Equals(changeset.DateTime)) { found = true; } SkipChangeset(pathMapper, changeset); continue; } var changesetDesc = string.Format("changeset {0} from {1:yyyy-MM-dd HH:mm:ss}", changesetId, changeset.DateTime); // replay each revision in changeset logger.WriteSectionSeparator(); LogStatus(work, "Replaying " + changesetDesc); labels.Clear(); replayStopwatch.Start(); try { ReplayChangeset(pathMapper, changeset, labels); if (makeInitialCommit) { vcsWrapper.Init(changeset, repoPath); makeInitialCommit = false; } vcsWrapper.NeedsCommit(); // to flush outstanding adds/deletes } finally { replayStopwatch.Stop(); } if (workQueue.IsAborting) { return; } // commit changes if (vcsWrapper.NeedsCommit()) { LogStatus(work, "Committing " + changesetDesc); if (CommitChangeset(changeset)) { ++commitCount; } } // create tags for any labels in the changeset if (labels.Count > 0) { foreach (Revision label in labels) { var labelName = ((VssLabelAction)label.Action).Label; if (string.IsNullOrEmpty(labelName)) { logger.WriteLine("NOTE: Ignoring empty label"); } else if (commitCount == 0) { logger.WriteLine("NOTE: Ignoring label '{0}' before initial commit", labelName); } else { //Datell B.V. Specific operation of adding folder structure to label. //It is optional by using the checkbox if (FolderBeforeLabel && label.Item.IsProject) { labelName = pathMapper.GetProjectPath(label.Item.PhysicalName) + "_" + labelName; labelName = labelName.Replace(repoPath, "").TrimStart('\\'); } var tagName = GetTagFromLabel(labelName); var tagMessage = "Creating tag " + tagName; if (tagName != labelName) { tagMessage += " for label '" + labelName + "'"; } LogStatus(work, tagMessage); // tags always get a tag message; var tagComment = label.Comment; if (string.IsNullOrEmpty(tagComment)) { // use the original VSS label as the tag message if none was provided tagComment = labelName; } if (AbortRetryIgnore( delegate { vcsWrapper.Tag(tagName, label.User, GetEmail(label.User), tagComment, label.DateTime); })) { ++tagCount; } } } } AdvancedTaskbar.SetPosition((uint)changesetId); } stopwatch.Stop(); if (!found) { logger.WriteLine("Cannot Sync: VSS changeset at {0} not found.", continueAfter); throw new ProcessException(string.Format("Cannot Sync: VSS changeset at {0} not found.", continueAfter), null, null); } logger.WriteSectionSeparator(); logger.WriteLine(vcs + " export complete in {0:HH:mm:ss}", new DateTime(stopwatch.ElapsedTicks)); logger.WriteLine("Replay time: {0:HH:mm:ss}", new DateTime(replayStopwatch.ElapsedTicks)); logger.WriteLine(vcs + " time: {0:HH:mm:ss}", new DateTime(vcsWrapper.ElapsedTime().Ticks)); logger.WriteLine(vcs + " commits: {0}", commitCount); logger.WriteLine(vcs + " tags: {0}", tagCount); }); }
public MainForm(string[] args) { InitializeComponent(); parseCommandLine(args); AdvancedTaskbar.Init(this); }
private void goButton_Click(object sender, EventArgs e) { try { AdvancedTaskbar.EnableItermediate(); OpenLog(logTextBox.Text); logger.WriteLine("VSS2Git version {0}", Assembly.GetExecutingAssembly().GetName().Version); WriteSettings(); Encoding encoding = Encoding.Default; EncodingInfo encodingInfo; if (codePages.TryGetValue(encodingComboBox.SelectedIndex, out encodingInfo)) { encoding = encodingInfo.GetEncoding(); } logger.WriteLine("VSS encoding: {0} (CP: {1}, IANA: {2})", encoding.EncodingName, encoding.CodePage, encoding.WebName); logger.WriteLine("Comment transcoding: {0}", transcodeCheckBox.Checked ? "enabled" : "disabled"); logger.WriteLine("Ignore VCS errors: {0}", ignoreVcsErrorsCheckBox.Checked ? "enabled" : "disabled"); logger.WriteLine("Collapsing path of output directory", RemovePathTextBox.Text); var df = new VssDatabaseFactory(vssDirTextBox.Text); df.Encoding = encoding; var db = df.Open(); //start here string[] lines; // read the emails dictionary var emailDictionary = ReadDictionaryFile("e-mail dictionary", db.BasePath, emailPropertiesFileName); revisionAnalyzer = new RevisionAnalyzer(workQueue, logger, db); if (!string.IsNullOrEmpty(excludeTextBox.Text)) { revisionAnalyzer.ExcludeFiles = excludeTextBox.Text; } if (UseProjectsFile.Checked) { lines = File.ReadAllLines(ProjectsFileLocation.Text, Encoding.UTF8); foreach (String line in lines) { if (line.Length <= 0) { continue; } string[] variation = line.Split('='); string vssPath = variation[0]; //Here add the paths. VssProject item; try { item = (VssProject)db.GetItem(vssPath.Trim()); } catch (VssPathException ex) { MessageBox.Show(ex.Message, "Invalid project path", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (variation.Length > 1) { item.RootPath = variation[1].Trim(); } else { item.RootPath = ""; } revisionAnalyzer.AddItem(item); } } else { var paths = vssProjectTextBox.Text.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); foreach (var path in paths) { VssItem item; try { item = db.GetItem(path.Trim()); } catch (VssPathException ex) { MessageBox.Show(ex.Message, "Invalid project path", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } var project = item as VssProject; if (project == null) { MessageBox.Show(path + " is not a project", "Invalid project path", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } revisionAnalyzer.AddItem(project); } } changesetBuilder = new ChangesetBuilder(workQueue, logger, revisionAnalyzer); changesetBuilder.AnyCommentThreshold = TimeSpan.FromSeconds((double)anyCommentUpDown.Value); changesetBuilder.SameCommentThreshold = TimeSpan.FromSeconds((double)sameCommentUpDown.Value); changesetBuilder.BuildChangesets(); if (!string.IsNullOrEmpty(outDirTextBox.Text)) { IVcsWrapper vcsWrapper = CreateVcsWrapper(encoding); var vcsExporter = new VcsExporter(workQueue, logger, revisionAnalyzer, changesetBuilder, vcsWrapper, emailDictionary); if (!string.IsNullOrEmpty(domainTextBox.Text)) { vcsExporter.EmailDomain = domainTextBox.Text; } if (!string.IsNullOrEmpty(commentTextBox.Text)) { vcsExporter.DefaultComment = commentTextBox.Text; } if (!transcodeCheckBox.Checked) { vcsExporter.CommitEncoding = encoding; } vcsExporter.RemovePath = RemovePathTextBox.Text; vcsExporter.TryGenerateCommitMessage = tryGenerateCommitMessageCheckBox.Checked; vcsExporter.IgnoreVcsErrors = ignoreVcsErrorsCheckBox.Checked; vcsExporter.ResetRepo = resetRepoCheckBox.Checked; vcsExporter.FolderBeforeLabel = FolderBeforeLabel.Checked; vcsExporter.UseProjectsFile = UseProjectsFile.Checked; if (vcsExporter.ResetRepo) { vcsExporter.ExportToVcs(outDirTextBox.Text, null); } else { vcsExporter.ExportToVcs(outDirTextBox.Text, continueAfter); } } workQueue.Idle += delegate { logger.Dispose(); logger = Logger.Null; LoadRepoSettings(); }; statusTimer.Enabled = true; emailMap.Enabled = false; goButton.Enabled = false; cancelButton.Text = "Cancel"; } catch (Exception ex) { logger.Dispose(); logger = Logger.Null; ShowException(ex); } }
private void goButton_Click(object sender, EventArgs e) { try { AdvancedTaskbar.EnableItermediate(); OpenLog(logTextBox.Text); logger.WriteLine("VSS2Git version {0}", Assembly.GetExecutingAssembly().GetName().Version); WriteSettings(); Encoding encoding = Encoding.Default; EncodingInfo encodingInfo; if (codePages.TryGetValue(encodingComboBox.SelectedIndex, out encodingInfo)) { encoding = encodingInfo.GetEncoding(); } logger.WriteLine("VSS encoding: {0} (CP: {1}, IANA: {2})", encoding.EncodingName, encoding.CodePage, encoding.WebName); logger.WriteLine("Comment transcoding: {0}", transcodeCheckBox.Checked ? "enabled" : "disabled"); logger.WriteLine("Ignore VCS errors: {0}", ignoreVcsErrorsCheckBox.Checked ? "enabled" : "disabled"); var df = new VssDatabaseFactory(vssDirTextBox.Text); df.Encoding = encoding; var db = df.Open(); var path = vssProjectTextBox.Text; VssItem item; try { item = db.GetItem(path); } catch (VssPathException ex) { MessageBox.Show(ex.Message, "Invalid project path", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } var project = item as VssProject; if (project == null) { MessageBox.Show(path + " is not a project", "Invalid project path", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // read the emails dictionary var emailDictionary = ReadDictionaryFile("e-mail dictionary", db.BasePath, emailPropertiesFileName); revisionAnalyzer = new RevisionAnalyzer(workQueue, logger, db); if (!string.IsNullOrEmpty(excludeTextBox.Text)) { revisionAnalyzer.ExcludeFiles = excludeTextBox.Text; } revisionAnalyzer.AddItem(project); changesetBuilder = new ChangesetBuilder(workQueue, logger, revisionAnalyzer); changesetBuilder.AnyCommentThreshold = TimeSpan.FromSeconds((double)anyCommentUpDown.Value); changesetBuilder.SameCommentThreshold = TimeSpan.FromSeconds((double)sameCommentUpDown.Value); changesetBuilder.BuildChangesets(); if (!string.IsNullOrEmpty(outDirTextBox.Text)) { IVcsWrapper vcsWrapper = CreateVcsWrapper(encoding); var vcsExporter = new VcsExporter(workQueue, logger, revisionAnalyzer, changesetBuilder, vcsWrapper, emailDictionary); if (!string.IsNullOrEmpty(domainTextBox.Text)) { vcsExporter.EmailDomain = domainTextBox.Text; } if (!string.IsNullOrEmpty(commentTextBox.Text)) { vcsExporter.DefaultComment = commentTextBox.Text; } if (!transcodeCheckBox.Checked) { vcsExporter.CommitEncoding = encoding; } vcsExporter.TryGenerateCommitMessage = tryGenerateCommitMessageCheckBox.Checked; vcsExporter.IgnoreVcsErrors = ignoreVcsErrorsCheckBox.Checked; vcsExporter.ResetRepo = resetRepoCheckBox.Checked; if (vcsExporter.ResetRepo) { vcsExporter.ExportToVcs(outDirTextBox.Text, null); } else { vcsExporter.ExportToVcs(outDirTextBox.Text, continueAfter); } } workQueue.Idle += delegate { logger.Dispose(); logger = Logger.Null; LoadRepoSettings(); }; statusTimer.Enabled = true; emailMap.Enabled = false; goButton.Enabled = false; cancelButton.Text = "Cancel"; } catch (Exception ex) { logger.Dispose(); logger = Logger.Null; ShowException(ex); } }