/// <summary> /// Factory method that creates an AssemblyInfo object with the information loaded from the passed file. /// </summary> /// <param name="projectFolder">Folder containing the solution project <c>.sln</c></param> /// <returns>An AssemblyInfo object with the loaded information.</returns> public static IInfoProcessor LoadAssemblyInfo(string projectFolder, IInfoProcessor iinfoProcessor) { string filePath = Path.Combine(projectFolder, iinfoProcessor.RelativeInfoFilePath); IInfoProcessor result = null; try { if (File.Exists(filePath)) { using (StreamReader reader = new StreamReader(filePath)) { TodoManager todoManager = new TodoManager(); result = iinfoProcessor.LoadAssemblyInfo(reader, todoManager); } // Reset the done things after load or it will always add the things already done to the list. ThingTodo.ThingsDoneDuringThisSession.Clear(); string[] parsedPath = Path.GetFullPath(filePath).Split(Path.DirectorySeparatorChar); result.ProjectName = parsedPath[parsedPath.Length - 3]; } } catch (Exception exp) { MessageBox.Show(string.Format("Error {0}", exp.Message)); Environment.Exit(2); } return(result); }
/// <summary> /// Initializes a new instance of the <see cref="MainWindow" /> class. /// </summary> public MainWindow() { IInfoProcessor iinfoProcessor = (IInfoProcessor)Activator.CreateInstance(Registry[languageType]); this.TheAssemblyInfo = AssemblyInfoProcessor.LoadAssemblyInfo(ProjectFolder, iinfoProcessor); if (this.TheAssemblyInfo == null) { MessageBox.Show("The assembly in " + ProjectFolder + " cannot be loaded"); Environment.Exit(1); } Rect rc = ProgramProperty.WinLocation; this.Left = rc.X; this.Top = rc.Y; this.Width = rc.Width; this.Height = rc.Height; Rect virtualScreen = new Rect(SystemParameters.VirtualScreenLeft, SystemParameters.VirtualScreenTop, SystemParameters.VirtualScreenWidth, SystemParameters.VirtualScreenHeight); if (!virtualScreen.Contains(rc)) { // The screen containing all the screens does not contain the stored coordinates. We move the rectangle inside the screen. if (this.Width < virtualScreen.Width) { double horizontalDiff = virtualScreen.Width - this.Width; this.Left = horizontalDiff / 2; } else { this.Left = 10; this.Width = virtualScreen.Width - 20; } if (this.Height < virtualScreen.Height) { double verticalDiff = virtualScreen.Height - this.Height; this.Top = verticalDiff / 2; } else { this.Top = 10; this.Height = virtualScreen.Height - 20; } } this.InitializeComponent(); this.TimeoutProgress.Visibility = ProgramProperty.CloseWinAutomatically ? Visibility.Visible : Visibility.Collapsed; this.Topmost = ProgramProperty.KeepOnTop; this.Title = "Project [" + this.TheAssemblyInfo.ProjectName + "] Current Version :" + this.TheAssemblyInfo; this.Release.Text = "CommentAssembly rel. " + Assembly.GetExecutingAssembly().GetName().Version; foreach (string line in this.TheAssemblyInfo.LastComments) { this.History.AppendText(line); this.History.AppendText(Environment.NewLine); } }
/// <summary> /// Handler called when the main windows is closing that stores the additional comments /// as well as the updated version number into the target AssemblyInfo.cs file /// </summary> /// <param name="sender">The parameter is not used.</param> /// <param name="e">The parameter is not used.</param> private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) { IInfoProcessor iinfoProcessor = (IInfoProcessor)Activator.CreateInstance(Registry[languageType]); if (ThingTodo.ThingsDoneDuringThisSession.Count > 0) { foreach (var todo in ThingTodo.ThingsDoneDuringThisSession) { if (this.Comment.Text.Length > 0) { this.Comment.AppendText("\n"); } this.Comment.AppendText("Done : " + todo.Description); } } AssemblyInfoProcessor.UpdateAssemblyInfo( ProjectFolder, this.TheAssemblyInfo.CurrentVersion.Next(), this.Comment.Text, iinfoProcessor); }
/// <summary> /// Updates the assembly info file with the new information passed, i.e. a new version number /// and a new comment. /// </summary> /// <param name="projectFolder">Pathname of the folder containing the project <c>.sln</c> file</param> /// <param name="version">Version to be inserted in the file.</param> /// <param name="comment">Comment about the current compilation.</param> public static void UpdateAssemblyInfo(string projectFolder, AssemblyVersion version, string comment, IInfoProcessor iinfoProcessor) { string filePath = Path.Combine(projectFolder, iinfoProcessor.RelativeInfoFilePath); string backupPath = filePath + ".bak"; try { File.Copy(filePath, backupPath, true); using (TextReader reader = new StreamReader(backupPath)) { using (TextWriter writer = new StreamWriter(filePath, false, iinfoProcessor.WriteEncoding)) { string line; iinfoProcessor.InitLoading(); while ((line = reader.ReadLine()) != null) { iinfoProcessor.ProcessLine(writer, line, version, comment); } } } } catch (Exception) { MessageBox.Show("Impossible to write AssemblyInfo file"); } }