Source code for the CoDocker CSharp to HTML converter from OfItselfSo.com
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.IO; using System.Threading; using System.Xml; using System.Runtime.Serialization; using OISCommon; /// +------------------------------------------------------------------------------------------------------------------------------+ /// ¦ TERMS OF USE: MIT License ¦ /// +------------------------------------------------------------------------------------------------------------------------------¦ /// ¦Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation ¦ /// ¦files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, ¦ /// ¦modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software¦ /// ¦is furnished to do so, subject to the following conditions: ¦ /// ¦ ¦ /// ¦The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.¦ /// ¦ ¦ /// ¦THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE ¦ /// ¦WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR ¦ /// ¦COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ¦ /// ¦ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ¦ /// +------------------------------------------------------------------------------------------------------------------------------+ namespace CoDocker { /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// The main form for the CoDocker application /// </summary> /// <remarks> /// The icon used for this app is "Swan" part of the Glass Zoo set by /// sirea. (http://www.sireasgallery.com/iconset/glasszoo/) It has not been /// released under the MIT license above and all usage must comply with /// its original CC 3.0 license http://creativecommons.org/licenses/by/3.0/ /// /// The CSharp formatting engine is derived from Jean-Claude Manoli's open /// source CSharp Formatting engine (http://www.manoli.net/csharpformat/) /// /// </remarks> /// <history> /// 02 Jan 11 Cynic - Started /// </history> public partial class frmMain : frmOISBase { // misc constants #if DEBUG private const string DEBUG_LOG_DIRECTORY = @"C:\Dump\Project Logs"; #else private const string RELEASE_LOG_DIRECTORY = @"Logs"; #endif #if DEBUG private const string DEBUG_CONFIG_DIRECTORY = @"C:\Projects\CoDocker"; #endif private const string DEFAULT_CONFIGFILE_NAME = "Default.CoDocCfg"; private const string CODOCKER_MAINHELP_FILE = "CoDockerHelp.html"; private const string CODOCKER_HELPDIR = ""; private const string FILTER_CONFIG = "CoDocCfg files (*.CoDocCfg)|*.CoDocCfg"; private const string BOXTITLE_OPENCONFIG = "Choose Configuration File to Open"; private const string BOXTITLE_SAVEASCONFIG = "Save Configuration File As"; // app constants private const string APPLICATION_NAME = "CoDocker"; private const string APPLICATION_VERSION = "00.90 Beta"; private const string APPLICATION_HOME = @"http://www.OfItselfSo.com/CoDocker/CoDocker.php"; private const string APPLICATION_ROOT = @"http://www.OfItselfSo.com"; private const string WARN01 = "The CoDocker software is released under the MIT License. There"; private const string WARN02 = "is no warranty or guarantee that the HTML files it produces"; private const string WARN03 = "are without error. You use it, and run its output code entirely"; private const string WARN04 = "at your own risk. In particular: "; private const string WARN05 = ""; private const string WARN06 = "THE CODOCKER SOFTWARE, AND THE OUTPUT CODE IT GENERATES, ARE "; private const string WARN07 = "PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR "; private const string WARN08 = "IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF "; private const string WARN09 = "MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND "; private const string WARN10 = "NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT "; private const string WARN11 = "HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, "; private const string WARN12 = "WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING "; private const string WARN13 = "FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR ITS OUTPUT"; private const string WARN14 = "OR FROM THE USE OR OTHER DEALINGS IN THE SOFTWARE. "; private const string EXT_CS = ".cs"; private const string EXT_CSPROJ = ".csproj"; private const string EXT_SLN = ".sln"; private const string FILTER_CS = "CS files (*.cs)|*.cs"; private const string FILTER_CSPROJ = "CSPROJ files (*.csproj)|*.csproj"; private const string FILTER_SLN = "Solution files (*.sln)|*.sln"; private const string BOXTITLE_CS = "Choose CSharp File to Convert"; private const string BOXTITLE_CSPROJ = "Choose CSharp Project File to Convert"; private const string BOXTITLE_SLN = "Choose CSharp Solution File to Convert"; public const string TYPE_SLN_TEXT = "Solution"; public const string TYPE_PROJECT_TEXT = "Project"; public const string TYPE_CS_TEXT = "File"; // these are the various types of element in a csproj xml file private const string CSPROJELEMENT_COMPILE = "Compile"; private const string CSPROJELEMENT_CONTENT = "Content"; private const string CSPROJELEMENT_EMBEDDEDRESOURCE = "EmbeddedResource"; private const string CSPROJELEMENT_PROJECTREFERENCE = "ProjectReference"; private const string CSPROJELEMENT_APPLICATIONDEFINITION = "ApplicationDefinition"; private const string CSPROJELEMENT_PAGE = "Page"; private const string CSPROJELEMENT_RESOURCE = "Resource"; private const string CSPROJELEMENT_SPLASHSCREEN = "SplashScreen"; private const string CSPROJELEMENT_ENTITYDEPLOY = "EntityDeploy"; private const string CSPROJELEMENT_NONE = "None"; private const string CSPROJELEMENT_REFERENCE = "Reference"; // max lines we will process in a solution private const int MAX_LINES_IN_SLN = 10000; private const string SLNELEMENT_PROJECT = "Project"; private const string SLNELEMENT_ENDPROJECT = "EndProject"; // #### css class tags // #### // a link to an html cs page public const string LINKTOCSPAGE = "OISLinkToCSPage"; // a project section block public const string HTMLSECTION = "OISHTMLSection"; // a project section block including HTMLSECTIONTITLE public const string HTMLSECTIONOUTER = "OISHTMLSectionOuter"; // a title on a project output page public const string HTMLSECTIONTITLE = "OISHTMLSectionTitle"; // a block which provides a project page banner public const string HTMLPAGEBANNER = "OISHTMLPageBanner"; // a block which provides a project page footer public const string HTMLPAGEFOOTER = "OISHTMLPageFooter"; // a csFile section block public const string CSFILESECTION = "OISCSFileSection"; // a backlink section block public const string HTMLBACKLINKSECTION = "OISHTMLBacklinkSection"; // a backlink public const string HTMLBACKLINK = "OISHTMLBacklink"; // #### substitution tags public const string USERDEFINED_BODY_BANNERMARKER = "%USERDEFINED_BODY_BANNERMARKER%"; public const string USERDEFINED_BODY_FOOTERMARKER = "%USERDEFINED_BODY_FOOTERMARKER%"; public const string CSSMARKER = "%CSSMARKER%"; public const string TITLEMARKER = "%TITLEMARKER%"; public const string DESCRIPTIONMARKER = "%DESCRIPTIONMARKER%"; public const string CODOCKER_NAME = "%CODOCKER_NAME%"; public const string CODOCKER_VERSION = "%CODOCKER_VERSION%"; public const string CODOCKER_HOME = "%CODOCKER_HOME%"; public const string CODOCKER_ROOT = "%CODOCKER_ROOT%"; public const string CODOCKERLINK = "%CODOCKERLINK%"; public const string CURRENT_DATETIME = "%CURRENT_DATETIME%"; public const string INFILENAME_WITHPATH = "%INFILENAME_WITHPATH%"; public const string INFILENAME = "%INFILENAME%"; public const string INFILENAME_NOEXT = "%INFILENAME_NOEXT%"; public const string INFILEDIRECTORY = "%INFILEDIRECTORY%"; public const string USERNAME = "%USERNAME%"; public const string MACHINENAME = "%MACHINENAME%"; public const string FILETYPE = "%FILETYPE%"; public const string STYLESHEET_NAME = "%STYLESHEET_NAME%"; // fixed content values public const string CODOCKERLINK_CONTENT = "<A class=\"CoDockerLink\" HREF=\"%CODOCKER_HOME%\">%CODOCKER_NAME% v%CODOCKER_VERSION%</A>"; // this is the line to insert at the top of the file so that the output HTML file // picks up the style sheet private const string CODOCKER_DEFAULTCSS = "CoDocker.css"; const string XMLNAMESPACE = @"http://schemas.microsoft.com/developer/msbuild/2003"; // these are settings the user does not explicitly configure such as form size // or some boolean screen control states private ApplicationImplicitSettings implictUserSettings = null; // these are settings the user configures such as file managers private ApplicationExplicitSettings configurationFile = null; // our MostRecentlyUsed filename list private frmOISMRUList mruList = null; /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Constructor /// </summary> /// <history> /// 02 Jan 11 Cynic - Started /// </history> public frmMain() { bool retBOOL = false; int retInt; // set the current directory equal to the exe directory. We do this because // people can start from a link and if the start-in directory is not right // it can put the log file in strange places Directory.SetCurrentDirectory(Application.StartupPath); // set up the Singleton g_Logger instance. if (g_Logger == null) { // did not work, nothing will start say so now in a generic way OISMessageBox("Logger Class Failed to Initialize. Nothing will work well."); return; } // record this in the logger for everybodys use g_Logger.ApplicationMainForm = this; g_Logger.DefaultDialogBoxTitle = APPLICATION_NAME; try { // set the icon for this form and for all subsequent forms g_Logger.AppIcon = new Icon(GetType(), "CoDocker.ico"); this.Icon = new Icon(GetType(), "CoDocker.ico"); } catch (Exception) { } // Register the global error handler as soon as we can in Main // to make sure that we catch as many exceptions as possible // this is a last resort. All execeptions should really be trapped // and handled by the code. OISGlobalExceptions eh = new OISGlobalExceptions(); Application.ThreadException += new ThreadExceptionEventHandler(eh.OnThreadException); // set the culture so our numbers convert consistently System.Threading.Thread.CurrentThread.CurrentCulture = g_Logger.GetDefaultCulture(); InitializeComponent(); // set up our logging #if DEBUG retBOOL = g_Logger.InitLogging(DEBUG_LOG_DIRECTORY, APPLICATION_NAME, false); #else string appPath = Path.GetDirectoryName(Application.ExecutablePath); string logfileDir = Path.Combine(appPath, RELEASE_LOG_DIRECTORY); retBOOL = g_Logger.InitLogging(logfileDir, APPLICATION_NAME, false); #endif if (retBOOL == false) { // did not work, nothing will start say so now in a generic way OISMessageBox("The log file failed to create. No log file will be recorded."); } // pump out the header g_Logger.EmitStandardLogfileheader(APPLICATION_NAME); LogMessage(""); LogMessage("Version: " + APPLICATION_VERSION); LogMessage(""); // set this now mruList = new frmOISMRUList(); // set some defaults ResetApplicationToDefaults(); // now recover the last configuration settings - if saved, we only do this if // the control key is not pressed. This allows the user to start with the // Shift key pressed and reset to defaults if ((Control.ModifierKeys & Keys.Shift) == 0) { try { // the creation of this object automagically reads the saved // settings. Read the comments. implictUserSettings = new ApplicationImplicitSettings(); try { MoveImplicitUserSettingsFromObjectToScreen(); // the configuration file name and path will be set by the implicit // settings retInt = ReadConfiguration(this.ConfigurationFileNameAndPath, true); // was the read successful? if (retInt ==0 ) { // yes it was, put it on the screen MoveConfigurationFileFromObjectToScreen(ConfigurationFile); } } finally { } } catch (Exception ex) { LogMessage("Error recovering previous application settings. Msg=" + ex.Message); } } } // #################################################################### // ##### Screen Management and Setup // #################################################################### #region Screen Management and Setup /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Gets or Sets our MRU list form. Will never get or set a null value /// </summary> /// <history> /// 02 Jan 11 Cynic - Started /// </history> private frmOISMRUList MRUList { get { if (mruList == null) mruList = new frmOISMRUList(); return mruList; } set { mruList = value; if (mruList == null) mruList = new frmOISMRUList(); } } /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Gets the output directory. Will never return null will return /// default output file if anything is dodgy at all /// </summary> /// <history> /// 22 May 11 Cynic - Started /// </history> private string OutputDirectory { get { if ((textBoxOutputDirectory.Text == null) || (textBoxOutputDirectory.Text.Length < 3)) textBoxOutputDirectory.Text = GetDefaultOutputDirectory(); return textBoxOutputDirectory.Text; } set { textBoxOutputDirectory.Text = value; if ((textBoxOutputDirectory.Text == null) || (textBoxOutputDirectory.Text.Length < 3)) textBoxOutputDirectory.Text = GetDefaultOutputDirectory(); } } /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Gets the config file name and path. Will never return null will return /// default config file if anything is dodgy at all /// </summary> /// <history> /// 22 May 11 Cynic - Started /// </history> private string ConfigurationFileNameAndPath { get { if ((textBoxConfigFile.Text == null) || (textBoxConfigFile.Text.Length < 3)) textBoxConfigFile.Text = GetDefaultConfigFileAndPath(); return textBoxConfigFile.Text; } set { textBoxConfigFile.Text = value; if ((textBoxConfigFile.Text == null) || (textBoxConfigFile.Text.Length < 3)) textBoxConfigFile.Text = GetDefaultConfigFileAndPath(); } } /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Does everything necessary to clear the current files and reset the /// application for a new file. /// </summary> /// <history> /// 02 Jan 11 Cynic - Started /// </history> private void ResetApplicationForNewFile() { } /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Does everything necessary to set the entire application back to defaults /// </summary> /// <history> /// 02 Jan 11 Cynic - Started /// </history> private void ResetApplicationToDefaults() { StringBuilder sb = new StringBuilder(); // pick the default settings out of an ApplicationExplicitSettings object ApplicationExplicitSettings exSettings = new ApplicationExplicitSettings(); exSettings.ResetToDefaults(); MoveConfigurationFileFromObjectToScreen(exSettings); // set some defaults ConfigurationFileNameAndPath = GetDefaultConfigFileAndPath(); OutputDirectory = GetDefaultOutputDirectory(); } /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Moves the implicit configuration settings from settings file to the screen /// </summary> /// <history> /// 02 Jan 11 Cynic - Started /// </history> private void MoveImplicitUserSettingsFromObjectToScreen() { // implicit settings this.Size = ImplicitUserSettings.FormSize; MRUList.FileList = ImplicitUserSettings.MRUFileList; ConfigurationFileNameAndPath = ImplicitUserSettings.ConfigFileNameAndPath; } /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Sets the form settings which the user does not really specify. These /// are things like form size etc. /// </summary> /// <history> /// 02 Jan 11 Cynic - Started /// </history> private void MoveImplicitUserSettingsFromScreenToObject() { ImplicitUserSettings.FormSize = this.Size; ImplicitUserSettings.MRUFileList = MRUList.FileList; ImplicitUserSettings.ConfigFileNameAndPath = ConfigurationFileNameAndPath; } /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Moves the explicit configuration settings from settings file to the screen /// </summary> /// <history> /// 02 Jan 11 Cynic - Started /// 22 May 11 Cynic - added in code for the banner etc /// </history> private void MoveConfigurationFileFromObjectToScreen(ApplicationExplicitSettings appSettings) { if (appSettings == null) { ResetApplicationForNewFile(); return; } OutputDirectory = appSettings.LastHTMLOutputDirectory; OutputFileExtension = appSettings.OutputFileExtension; StyleSheetType = appSettings.StyleSheetType; UserStyleSheetName = appSettings.UserStyleSheetName; // pull the data out of the config container and put it on the screen richTextBoxCSBannerContent.Text = appSettings.BannerCSCode; richTextBoxCSFooterContent.Text = appSettings.FooterCSCode; textBoxCSPageDesc.Text = appSettings.TitleCSCode; textBoxCSPageTitle.Text = appSettings.DescriptionCSCode; richTextBoxCSProjBannerContent.Text = appSettings.BannerCSProjCode; richTextBoxCSProjFooterContent.Text = appSettings.FooterCSProjCode; textBoxCSProjPageDesc.Text = appSettings.TitleCSProjCode; textBoxCSProjPageTitle.Text = appSettings.DescriptionCSProjCode; checkBoxProjUseCSBanner.Checked = appSettings.UseCSProjCSBanner; checkBoxProjUseCSFooter.Checked = appSettings.UseCSProjCSFooter; checkBoxProjUseCSTitle.Checked = appSettings.UseCSProjCSTitle; checkBoxProjUseCSDesc.Checked = appSettings.UseCSProjCSDesc; richTextBoxSLNBannerContent.Text = appSettings.BannerSLNCode; richTextBoxSLNFooterContent.Text = appSettings.FooterSLNCode; textBoxSLNPageDesc.Text = appSettings.TitleSLNCode; textBoxSLNPageTitle.Text = appSettings.DescriptionSLNCode; checkBoxSLNUseCSBanner.Checked = appSettings.UseSLNCSBanner; checkBoxSLNUseCSFooter.Checked = appSettings.UseSLNCSFooter; checkBoxSLNUseCSTitle.Checked = appSettings.UseSLNCSTitle; checkBoxSLNUseCSDesc.Checked = appSettings.UseSLNCSDesc; SyncProjTextBoxesToCheckState(); SyncSLNTextBoxesToCheckState(); } /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Sets the form settings which the user specifies. These /// are things like output directory etc. /// </summary> /// <history> /// 03 Jan 11 Cynic - Started /// 22 May 11 Cynic - added in code for the banner etc /// </history> private void MoveConfigurationFileFromScreenToObject(ref ApplicationExplicitSettings appSettings) { if (appSettings == null) return; // set the values appSettings.LastHTMLOutputDirectory = OutputDirectory; appSettings.OutputFileExtension = OutputFileExtension; appSettings.StyleSheetType = StyleSheetType; appSettings.UserStyleSheetName = UserStyleSheetName; // pull the data out of the config container and put it on the screen appSettings.BannerCSCode = richTextBoxCSBannerContent.Text; appSettings.FooterCSCode = richTextBoxCSFooterContent.Text; appSettings.TitleCSCode = textBoxCSPageDesc.Text; appSettings.DescriptionCSCode = textBoxCSPageTitle.Text; appSettings.BannerCSProjCode = richTextBoxCSProjBannerContent.Text; appSettings.FooterCSProjCode = richTextBoxCSProjFooterContent.Text; appSettings.TitleCSProjCode = textBoxCSProjPageDesc.Text; appSettings.DescriptionCSProjCode = textBoxCSProjPageTitle.Text; appSettings.UseCSProjCSBanner = checkBoxProjUseCSBanner.Checked; appSettings.UseCSProjCSFooter = checkBoxProjUseCSFooter.Checked; appSettings.UseCSProjCSTitle = checkBoxProjUseCSTitle.Checked; appSettings.UseCSProjCSDesc = checkBoxProjUseCSDesc.Checked; appSettings.BannerSLNCode = richTextBoxSLNBannerContent.Text; appSettings.FooterSLNCode = richTextBoxSLNFooterContent.Text; appSettings.TitleSLNCode = textBoxSLNPageDesc.Text; appSettings.DescriptionSLNCode = textBoxSLNPageTitle.Text; appSettings.UseSLNCSBanner = checkBoxSLNUseCSBanner.Checked; appSettings.UseSLNCSFooter = checkBoxSLNUseCSFooter.Checked; appSettings.UseSLNCSTitle = checkBoxSLNUseCSTitle.Checked; appSettings.UseSLNCSDesc = checkBoxSLNUseCSDesc.Checked; } /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Save the configuration under a new name, always saves the current configuration file /// </summary> /// <param name="bSilent">if true we do not output error messages</param> /// <param name="errStr">the error string</param> /// <returns>z success, nz fail not reported, +ve fail reported, -1 means cancelled</returns> /// <history> /// 23 May 11 Cynic - Started /// </history> public int SaveConfigurationAs(bool bSilent, ref string errStr) { Cursor tmpCursor = Cursor.Current; int retInt; string fileNameAndPath = ""; LogMessage("SaveConfigurationAs called"); errStr = ""; if (configurationFile == null) { errStr = "No configuration file specified"; LogMessage("SaveConfigurationAs " + errStr); if (bSilent == false) { OISMessageBox(errStr); return 100; } else return -100; } // we use the current Configuration file name as the best name // pick the save file name retInt = PickConfigFileSaveName(Path.GetDirectoryName(ConfigurationFileNameAndPath), Path.GetFileName(ConfigurationFileNameAndPath), ref fileNameAndPath); if (retInt < 0) { // log this errStr = ("SaveConfigurationAs call to PickConfigFileSaveName was cancelled"); LogMessage("SaveConfigurationAs " + errStr); return -1; } if (retInt > 0) { // log this errStr = "Call to PickConfigFileSaveName returned error of " + retInt.ToString(); LogMessage("SaveConfigurationAs " + errStr); if (bSilent == false) { OISMessageBox(errStr); return 150; } else return -150; } if ((fileNameAndPath == null) || (fileNameAndPath.Length == 0)) { // something badly wrong errStr = "No output filename could be constructed. Error message is:" + errStr + "\n\nPlease see the log file for more information."; LogMessage("SaveConfigurationAs " + errStr); if (bSilent == false) { OISMessageBox(errStr); return 160; } else return -160; } // set the cursor, this can take some time tmpCursor = Cursor.Current; Cursor.Current = Cursors.WaitCursor; try { // now save the file retInt = WriteConfigurationFile(fileNameAndPath, ConfigurationFile, bSilent); if (retInt != 0) { // log this LogMessage("SaveConfigurationAs_Click call to WriteConfigurationFile returned" + retInt.ToString()); // yes it did, was it reported? if (retInt < 0) { // no it was not, we always report it errStr = "Error " + retInt.ToString() + " occurred saving the Configuration File.\n\nPlease see the log file."; LogMessage("SaveConfigurationAs " + errStr); if (bSilent == false) { OISMessageBox(errStr); return 170; } else return -170; } } } catch (Exception ex) { // we found something we could not cope with errStr = "An error occurred saving the file. Exception message was:\n\n" + ex.Message; LogMessage("SaveConfigurationAs " + errStr); if (bSilent == false) { OISMessageBox(errStr); return 180; } else return -180; } finally { // restore the cursor back to what it was Cursor.Current = tmpCursor; } // set this now ConfigurationFileNameAndPath = fileNameAndPath; OISMessageBox("The Configuration file has been saved under the name\n\n" + fileNameAndPath); return 0; } /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Picks a GCode SaveFileName /// </summary> /// <param name="filePathAndName">the full file path and name</param> /// <param name="initialDirectory">the initial directory</param> /// <param name="suggestedFile">The suggested file</param> /// <returns>z success, -ve cancel, +ve fail</returns> /// <history> /// 23 May 11 Cynic - Started /// </history> private int PickConfigFileSaveName(string initialDirectory, string suggestedFile, ref string filePathAndName) { LogMessage("PickConfigFileSaveName called"); SaveFileDialog sfDialog = new SaveFileDialog(); sfDialog.RestoreDirectory = true; sfDialog.Filter = FILTER_CONFIG; sfDialog.FilterIndex = 2; // can we set the initial directory? Perform some checks // if we can't set it we just go with whatever windows has // as a default if (initialDirectory != null) { if (Directory.Exists(initialDirectory) == true) { // set it sfDialog.InitialDirectory = initialDirectory; } } // can we set the suggested File? if (suggestedFile != null) { // set it sfDialog.FileName = suggestedFile; } sfDialog.Title = BOXTITLE_SAVEASCONFIG; // Show it DialogResult dlgRes = sfDialog.ShowDialog(); if (dlgRes != DialogResult.OK) { LogMessage("PickConfigFileSaveName user cancelled operation"); return -1; } // get the file name now filePathAndName = sfDialog.FileName; if ((filePathAndName == null) || (filePathAndName.Length == 0)) { LogMessage("PickConfigFileSaveName empty file returned"); return 98; } // return it return 0; } /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Open the configuration file and initialize the system with it /// </summary> /// <param name="bSilent">if true we do not output error messages</param> /// <param name="errStr">the error string</param> /// <returns>z success, nz fail not reported, +ve fail reported, -1 means cancelled</returns> /// <history> /// 23 May 11 Cynic - Started /// </history> private int OpenConfigurationFile(bool bSilent, ref string errStr) { int retInt; Cursor tmpCursor = Cursor.Current; LogMessage("OpenConfigurationFile called"); // we show a message once regarding the license if (implictUserSettings != null) { if (implictUserSettings.OKWithDisclaimer == false) { frmDisclaimer disFrm = new frmDisclaimer(APPLICATION_VERSION); disFrm.ShowDialog(); if (disFrm.OKWithDisclaimer == false) return -1; implictUserSettings.OKWithDisclaimer = disFrm.OKWithDisclaimer; } } else { frmDisclaimer disFrm = new frmDisclaimer(APPLICATION_VERSION); disFrm.ShowDialog(); if (disFrm.OKWithDisclaimer == false) return -1; } string filePathAndName = ""; retInt = PickFile(Path.GetDirectoryName(ConfigurationFileNameAndPath), ConfigurationFileNameAndPath, FILTER_CONFIG, BOXTITLE_OPENCONFIG, ref filePathAndName); if (retInt < 0) { // log this LogMessage("OpenConfigurationFile call to PickFile was cancelled"); return -1; } if (retInt > 0) { // log this errStr = "OpenConfigurationFile call to PickFile returned error of " + retInt.ToString(); LogMessage("OpenConfigurationFile " + errStr); OISMessageBox("Error " + retInt.ToString() + " occurred when choosing the Gerber File.\n\nPlease see the log file."); if (bSilent == false) { OISMessageBox(errStr); return 100; } else return -100; } if ((filePathAndName == null) || (filePathAndName.Length == 0)) { // log this errStr = "Call to PickFile returned no filename)"; LogMessage("OpenConfigurationFile " + errStr); OISMessageBox("Error " + retInt.ToString() + " occurred when choosing the Configuration File.\n\nPlease see the log file."); if (bSilent == false) { OISMessageBox(errStr); return 150; } else return -150; } LogMessage("Preparing to open configuration file: " + filePathAndName); // set the filename for our configuration settings so we return to // it automatically next time we start ConfigurationFileNameAndPath = filePathAndName; // set the cursor, this can take some time tmpCursor = Cursor.Current; Cursor.Current = Cursors.WaitCursor; try { retInt = ReadConfiguration(ConfigurationFileNameAndPath, false); if (retInt != 0) { // log this LogMessage("OpenConfigurationFile call to ReadConfiguration returned " + retInt.ToString()); // yes it did, was it reported? if (retInt < 0) { // no it was not, we always report it errStr = "Error " + retInt.ToString() + " occurred opening the Config File.\n\nPlease see the log file."; LogMessage("OpenConfigurationFile " + errStr); if (bSilent == false) { OISMessageBox("Error " + retInt.ToString() + " occurred when choosing the Configuration File.\n\nPlease see the log file."); return 160; } else return -160; } } else { // the read was successful MoveConfigurationFileFromObjectToScreen(ConfigurationFile); } } catch (Exception ex) { // we found something we could not cope with errStr = "An error occurred opening the file. Exception message was:\n\n" + ex.Message; LogMessage("OpenConfigurationFile " + errStr); if (bSilent == false) { OISMessageBox(errStr); return 180; } else return -180; } finally { // restore the cursor back to what it was Cursor.Current = tmpCursor; } // we are done, ask if the user wants to view the output file OISMessageBox("The configuration file was opened successfully."); return 0; } /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Gets the default configuration file and path /// </summary> /// <returns>default Configuration directory</returns> /// <history> /// 22 May 11 Cynic - Started /// </history> public string GetDefaultConfigFileAndPath() { string appPath; #if DEBUG appPath = DEBUG_CONFIG_DIRECTORY; return Path.Combine(appPath, DEFAULT_CONFIGFILE_NAME); #else appPath = Path.GetDirectoryName(Application.ExecutablePath); return Path.Combine(appPath, DEFAULT_CONFIGFILE_NAME); #endif } /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Gets the default output directory /// </summary> /// <returns>default output directory</returns> /// <history> /// 22 May 11 Cynic - Started /// </history> public string GetDefaultOutputDirectory() { string appPath; #if DEBUG appPath = DEBUG_LOG_DIRECTORY; #else appPath = Path.GetDirectoryName(Application.ExecutablePath); #endif return appPath; } /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Does everything necessary to read the explicit configuration settings /// </summary> /// <param name="configFileNameAndPath">the config file path and name to read</param> /// <param name="bSilent">if true we do not tell the user on error</param> /// <returns>z success, -ve fail not notified, +ve fail notified</returns> /// <history> /// 07 Sep 10 Cynic - Started /// </history> private int ReadConfiguration(string configFileNameAndPath, bool bSilent) { string errStr; XmlReader reader = null; LogMessage("ReadConfiguration called"); if((configFileNameAndPath==null) || (configFileNameAndPath.Length<3)) { errStr = "No file path and name specified "; LogMessage("ReadConfiguration "+ errStr); if (bSilent == false) { OISMessageBox(errStr); return -50; } return 50; } // set this now so that if we retry we default to this ConfigurationFileNameAndPath = configFileNameAndPath; try { // now read the configuration file reader = XmlReader.Create(configFileNameAndPath); DataContractSerializer serializerIn = new DataContractSerializer(typeof(ApplicationExplicitSettings)); ConfigurationFile = (ApplicationExplicitSettings)serializerIn.ReadObject(reader); } catch (Exception ex) { errStr = "Error reading configuration: " + ex.ToString(); LogMessage(errStr); if (bSilent == false) { OISMessageBox("ReadConfiguration " + errStr); return 150; } return -150; } finally { if (reader != null) { reader.Close(); reader = null; } } return 0; } /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Does everything necessary to write the explict configuration settings /// </summary> /// <param name="bSilent">if true we do not tell the user on error</param> /// <param name="configFileNameAndPath">the configuration file name and path</param> /// <returns>z success, -ve fail not notified, +ve fail notified</returns> /// <history> /// 07 Sep 10 Cynic - Started /// </history> private int WriteConfigurationFile(string configFileNameAndPath, ApplicationExplicitSettings configFile, bool bSilent) { string errStr; XmlWriter writer = null; if ((configFileNameAndPath == null) || (configFileNameAndPath.Length < 3)) { errStr = "Invalid file name or path, cannot save config file"; LogMessage(errStr); if (bSilent == false) { OISMessageBox(errStr); return 99; } return -99; } try { // now write the configuration file XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; writer = XmlWriter.Create(configFileNameAndPath, settings); DataContractSerializer serializer = new DataContractSerializer(typeof(ApplicationExplicitSettings)); serializer.WriteObject(writer, configFile); // set this ConfigurationFile = configFile; ConfigurationFileNameAndPath = configFileNameAndPath; } catch (Exception ex) { errStr = "Error saving configuration: " + ex.ToString(); LogMessage(errStr); if (bSilent == false) { OISMessageBox(errStr); return 100; } return -100; } finally { if (writer != null) { writer.Close(); writer = null; } } return 0; } /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Detects if the configuration settings the user explicitly specifies have /// changed. The contents here need to be synced with the actions in /// SetUserConfigurationFile() /// </summary> /// <history> /// 02 Jan 11 Cynic - Started /// </history> private bool DoWeNeedToSaveConfigurationFile() { if (ConfigurationFile.SettingsNeedToBeSaved == true) return true; if (OutputDirectory != ConfigurationFile.LastHTMLOutputDirectory) return true; if (OutputFileExtension != ConfigurationFile.OutputFileExtension) return true; if (StyleSheetType != ConfigurationFile.StyleSheetType) return true; if (UserStyleSheetName != ConfigurationFile.UserStyleSheetName) return true; if (richTextBoxCSBannerContent.Text != ConfigurationFile.BannerCSCode) return true; if (richTextBoxCSFooterContent.Text != ConfigurationFile.FooterCSCode) return true; if (textBoxCSPageDesc.Text != ConfigurationFile.TitleCSCode) return true; if (textBoxCSPageTitle.Text != ConfigurationFile.DescriptionCSCode) return true; if (richTextBoxCSProjBannerContent.Text != ConfigurationFile.BannerCSProjCode) return true; if (richTextBoxCSProjFooterContent.Text != ConfigurationFile.FooterCSProjCode) return true; if (textBoxCSProjPageDesc.Text != ConfigurationFile.TitleCSProjCode) return true; if (textBoxCSProjPageTitle.Text != ConfigurationFile.DescriptionCSProjCode) return true; if (checkBoxProjUseCSBanner.Checked != ConfigurationFile.UseCSProjCSBanner) return true; if (checkBoxProjUseCSFooter.Checked != ConfigurationFile.UseCSProjCSFooter) return true; if (checkBoxProjUseCSTitle.Checked != ConfigurationFile.UseCSProjCSTitle) return true; if (checkBoxProjUseCSDesc.Checked != ConfigurationFile.UseCSProjCSDesc) return true; if (richTextBoxSLNBannerContent.Text != ConfigurationFile.BannerSLNCode) return true; if (richTextBoxSLNFooterContent.Text != ConfigurationFile.FooterSLNCode) return true; if (textBoxSLNPageDesc.Text != ConfigurationFile.TitleSLNCode) return true; if (textBoxSLNPageTitle.Text != ConfigurationFile.DescriptionSLNCode) return true; if (checkBoxSLNUseCSBanner.Checked != ConfigurationFile.UseSLNCSBanner) return true; if (checkBoxSLNUseCSFooter.Checked != ConfigurationFile.UseSLNCSFooter) return true; if (checkBoxSLNUseCSTitle.Checked != ConfigurationFile.UseSLNCSTitle) return true; if (checkBoxSLNUseCSDesc.Checked != ConfigurationFile.UseSLNCSDesc) return true; return false; } /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Returns the implicit user config settings object. Will never get or set null /// </summary> /// <history> /// 02 Jan 11 Cynic - Started /// </history> public ApplicationImplicitSettings ImplicitUserSettings { get { if (implictUserSettings == null) implictUserSettings = new ApplicationImplicitSettings(); return implictUserSettings; } set { implictUserSettings = value; if (implictUserSettings == null) implictUserSettings = new ApplicationImplicitSettings(); } } /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Returns the explicit user config settings object. Will never get or set null /// </summary> /// <history> /// 02 Jan 11 Cynic - Started /// </history> public ApplicationExplicitSettings ConfigurationFile { get { if (configurationFile == null) configurationFile = new ApplicationExplicitSettings(); return configurationFile; } set { configurationFile = value; if (configurationFile == null) configurationFile = new ApplicationExplicitSettings(); } } /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// gets/sets the outputFileExtension. /// </summary> /// <history> /// 03 Jan 11 Cynic - Started /// </history> private OutputFileExtensionEnum OutputFileExtension { get { if (radioButtonExtensionHTM.Checked == true) return OutputFileExtensionEnum.HTM; else if (radioButtonExtensionPHP.Checked == true) return OutputFileExtensionEnum.PHP; else if (radioButtonExtensionASP.Checked == true) return OutputFileExtensionEnum.ASP; else return OutputFileExtensionEnum.HTML; } set { if (value == OutputFileExtensionEnum.HTM) radioButtonExtensionHTM.Checked = true; else if (value == OutputFileExtensionEnum.PHP) radioButtonExtensionPHP.Checked = true; else if (value == OutputFileExtensionEnum.ASP) radioButtonExtensionASP.Checked = true; else radioButtonExtensionHTML.Checked = true; } } /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// gets the outputFileExtension as a string. /// </summary> /// <history> /// 03 Jan 11 Cynic - Started /// </history> private string OutputFileExtensionAsString() { if (OutputFileExtension == OutputFileExtensionEnum.HTM) return "htm"; else if (OutputFileExtension == OutputFileExtensionEnum.PHP) return "php"; else if (OutputFileExtension == OutputFileExtensionEnum.ASP) return "asp"; else return "html"; } /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// gets/sets the styleSheetType. /// </summary> /// <history> /// 03 Jan 11 Cynic - Started /// </history> private StyleSheetTypeEnum StyleSheetType { get { if (radioButtonStyleSheetCustom.Checked == true) return StyleSheetTypeEnum.STYLESHEET_USERDEFINED; else return StyleSheetTypeEnum.STYLESHEET_DEFAULT; } set { if (value == StyleSheetTypeEnum.STYLESHEET_USERDEFINED) radioButtonStyleSheetCustom.Checked = true; else radioButtonStyleSheetDefault.Checked = true; SyncStyleSheetNameTextBoxToStyleSheetOptionState(); } } /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// gets/sets the UserStyleSheetName. will never get/set null /// </summary> /// <history> /// 23 May 11 Cynic - Started /// </history> public string UserStyleSheetName { get { if (textBoxStyleSheetName.Text == null) textBoxStyleSheetName.Text = ApplicationExplicitSettings.DEFAULT_USER_STYLESHEET_NAME; return textBoxStyleSheetName.Text; } set { textBoxStyleSheetName.Text = value; if (textBoxStyleSheetName.Text == null) textBoxStyleSheetName.Text = ApplicationExplicitSettings.DEFAULT_USER_STYLESHEET_NAME; } } /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// gets/sets the StyleSheetName. will never get null, there is no set /// accessor this is a derived value /// </summary> /// <history> /// 23 May 11 Cynic - Started /// </history> public string StyleSheetName { get { if (radioButtonStyleSheetCustom.Checked == true) return UserStyleSheetName; return CODOCKER_DEFAULTCSS; } } /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// syncs the enabled/disabled state of the textBoxStyleSheetName /// </summary> /// <history> /// 03 Jan 11 Cynic - Started /// </history> private void SyncStyleSheetNameTextBoxToStyleSheetOptionState() { if (radioButtonStyleSheetCustom.Checked == false) { this.textBoxStyleSheetName.Enabled = false; } else { this.textBoxStyleSheetName.Enabled = true; } } /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Sync the enabled or disabled state of the CSProj tab checkboxes to reality /// </summary> /// <history> /// 20 May 11 Cynic - Started /// </history> private void SyncProjTextBoxesToCheckState() { if (checkBoxProjUseCSBanner.Checked == true) richTextBoxCSProjBannerContent.Enabled = false; else richTextBoxCSProjBannerContent.Enabled = true; if (checkBoxProjUseCSFooter.Checked == true) richTextBoxCSProjFooterContent.Enabled = false; else richTextBoxCSProjFooterContent.Enabled = true; if (checkBoxProjUseCSTitle.Checked == true) textBoxCSProjPageTitle.Enabled = false; else textBoxCSProjPageTitle.Enabled = true; if (checkBoxProjUseCSDesc.Checked == true) textBoxCSProjPageDesc.Enabled = false; else textBoxCSProjPageDesc.Enabled = true; } /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Sync the enabled or disabled state of the SLN tab checkboxes to reality /// </summary> /// <history> /// 23 May 11 Cynic - Started /// </history> private void SyncSLNTextBoxesToCheckState() { if (checkBoxSLNUseCSBanner.Checked == true) richTextBoxSLNBannerContent.Enabled = false; else richTextBoxSLNBannerContent.Enabled = true; if (checkBoxSLNUseCSFooter.Checked == true) richTextBoxSLNFooterContent.Enabled = false; else richTextBoxSLNFooterContent.Enabled = true; if (checkBoxSLNUseCSTitle.Checked == true) textBoxSLNPageTitle.Enabled = false; else textBoxSLNPageTitle.Enabled = true; if (checkBoxSLNUseCSDesc.Checked == true) textBoxSLNPageDesc.Enabled = false; else textBoxSLNPageDesc.Enabled = true; } #endregion // #################################################################### // ##### File Read and Write // #################################################################### #region File Read and Write /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Picks a File off the disk /// </summary> /// <param name="filePathAndName">the full file path and name</param> /// <param name="initialDirectory">the initial directory</param> /// <param name="suggestedFile">The suggested file</param> /// <param name="fileFilter">the file filter we use for the open box</param> /// <param name="boxTitle">the title we use for the open box</param> /// <returns>z success, -ve cancel, +ve fail</returns> /// <history> /// 02 Jan 11 Cynic - Started /// </history> private int PickFile(string initialDirectory, string suggestedFile, string fileFilter, string boxTitle, ref string filePathAndName) { filePathAndName = string.Empty; LogMessage("PickFile called"); OpenFileDialog ofDialog = new OpenFileDialog(); if ((fileFilter == null) || (fileFilter.Length == 0)) { LogMessage("Invalid File Filter"); return -100; } if ((boxTitle == null) || (boxTitle.Length == 0)) { LogMessage("Invalid Box Title"); return -101; } // TODO set a extension here for the various PCB file software ofDialog.Filter = fileFilter; // can we set the initial directory? Perform some checks // if we can't set it we just go with whatever windows has // as a default if (initialDirectory != null) { if (Directory.Exists(initialDirectory) == true) { // set it ofDialog.InitialDirectory = initialDirectory; } } // can we set the suggested File? if (suggestedFile != null) { // set it ofDialog.FileName = suggestedFile; } ofDialog.Title = boxTitle; // Show it DialogResult dlgRes = ofDialog.ShowDialog(); if (dlgRes != DialogResult.OK) { LogMessage("PickFile user cancelled operation"); return -1; } // get the file name now filePathAndName = ofDialog.FileName; if ((filePathAndName == null) || (filePathAndName.Length == 0)) { LogMessage("PickFile empty file returned"); return 98; } // return it return 0; } /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Opens up a SLN file /// </summary> /// <param name="filePathAndName">the full file path and name</param> /// <param name="bSilent">if true we do not pop up notices indicating failures </param> /// <param name="slnFile">we return the cs file in this</param> /// <param name="errStr">an error string for silent returns</param> /// <param name="outFileNamePrefix">the file name prefix the HTML output file should use, can be null</param> /// <param name="outFilePath">the output file path, must point to a valid directory</param> /// <param name="outputCSSFile">if true we output the css file as a separate file</param> /// <returns>z success, -ve fail user not notified, +ve fail user notified</returns> /// <history> /// 23 May 11 Cynic - Started /// </history> private int ProcessSLNFile(File_SLN slnFile, string outFilePath, string outFileNamePrefix, bool outputCSSFile, bool bSilent, ref string errStr) { TextReader tr = null; TextWriter tw = null; string slnLine = null; char[] slnLineSplitChars = {'=', ','}; string[] splitArray = null; bool retBool = false; string sourceFilePath = null; int retInt; File_CSPROJ csProjFile = null; int secondaryNotImplementedExceptionCount = 0; string secondaryFileName; string secondaryFileNameAndPath; string deSlashedSecondaryFileName; string deSlashedSecondaryOutputFileName; SubstitutionValueContainer subCont = null; OutputFileContainer fileCont = null; errStr = ""; string workingProjName = null; string workingProjRelativePath = null; if (slnFile == null) { LogMessage("ProcessSLNFile slnFile == null"); errStr = "No SLN file supplied.\n\nPlease see the log file."; if (bSilent == false) { OISMessageBox(errStr); return 100; } else return -100; } if ((slnFile.SourceFilePathAndName == null) || (slnFile.SourceFilePathAndName.Length < 3)) { LogMessage("ProcessSLNFile filePathAndName==null"); errStr = "No SLN file name supplied.\n\nPlease see the log file."; if (bSilent == false) { OISMessageBox(errStr); return 101; } else return -101; } if ((outFilePath == null) || (outFilePath.Length < 3)) { LogMessage("ProcessSLNFile outFilePath does not exist"); errStr = "No SLN outfile path supplied.\n\nPlease see the log file."; if (bSilent == false) { OISMessageBox(errStr); return 102; } else return -102; } if (Directory.Exists(outFilePath) == false) { LogMessage("ProcessSLNFile outFilePath==null"); errStr = "The output file path does not exist\n\n" + outFilePath; if (bSilent == false) { OISMessageBox(errStr); return 103; } else return -103; } LogMessage("ProcessSLNFile ProcessingFile>" + slnFile.SourceFilePathAndName); if (File.Exists(slnFile.SourceFilePathAndName) == false) { LogMessage("ProcessSLNFile The file " + slnFile.SourceFilePathAndName + " does not exist."); if (bSilent == false) { OISMessageBox("The file \n\n" + slnFile.SourceFilePathAndName + "\n\ndoes not exist. Please see the log file."); return 223; } else return -223; } // get the output file name string outFileName = BuildHTMLFileNameAndPath(slnFile.SourceFilePathAndName, outFilePath, outFileNamePrefix); if ((outFileName == null) || (outFileName.Length < 3)) { LogMessage("ProcessSLNFile outFileName==null"); errStr = "No SLN outfile name generated.\n\nPlease see the log file."; if (bSilent == false) { OISMessageBox(errStr); return 103; } else return -103; } // set this now, we use it for backlinks later on slnFile.HTMLFilePathAndName = Path.GetFileName(outFileName); // get the input file path sourceFilePath = Path.GetDirectoryName(slnFile.SourceFilePathAndName); if ((sourceFilePath == null) || (sourceFilePath.Length < 3)) { LogMessage("ProcessSLNFile sourceFilePath==null"); errStr = "No SLN infile path generated.\n\nPlease see the log file."; if (bSilent == false) { OISMessageBox(errStr); return 104; } else return -104; } try { // set up the output file FileStream fileStream = new FileStream(slnFile.SourceFilePathAndName, FileMode.Open, FileAccess.Read); tw = new StreamWriter(outFileName); // create a container with substitution values subCont = new SubstitutionValueContainer(InputFileTypeEnum.INPUTFILETYPE_SLN, slnFile); // now output the header HTML tw.Write(BuildHTMLFileHeader(subCont)); tw.Write("\r\n"); tw.Write(BuildHTMLFileBodyStart(subCont)); // set up to process the SLN file - it is just plain text, we parse it the old // fashioned way, create reader & open file tr = new StreamReader(slnFile.SourceFilePathAndName); // write the lead in and block start tw.Write("\r\n"); tw.Write("<div class=\"" + HTMLSECTIONOUTER + "\">\r\n"); tw.Write("<div class=\"" + HTMLSECTIONTITLE + "\">Projects In the Solution</div>\r\n"); tw.Write("<div class=\"" + HTMLSECTION + "\">\r\n"); // I do not like endless loops so we do it this way for (int i = 1; i < MAX_LINES_IN_SLN; i++) { // read a line of text slnLine = tr.ReadLine(); if (slnLine == null) break; // does the line start with the word "Project" if (slnLine.StartsWith(SLNELEMENT_PROJECT) == false) continue; // ok lets bust up the line on the = and , chars splitArray = slnLine.Trim().Split(slnLineSplitChars); // this should never be null if (splitArray == null) continue; // we should get the project name in splitArray[1] and // the path to the project file in splitArray[2] we check // these for "{" characters. If they contain these then // something is wrong if (splitArray.Count() < 3) { errStr = "Unknown format in the sln file. Count=" + splitArray.Count().ToString() + " on line " + i.ToString() + "\n\nPlease see the log file."; if (bSilent == false) { OISMessageBox(errStr); return 200; } else return -200; } // get the two values workingProjName = splitArray[1].Replace("\"", "").Trim(); workingProjRelativePath = splitArray[2].Replace("\"", "").Trim(); // do we have { or } characters in slots 1 or 2 ? these are guid and are not supported if ((workingProjName.Contains("{")) || (workingProjName.Contains("}"))) { errStr = "GUID chars in the proj name on solution file line " + i.ToString() + " cannot process this file.\n\nPlease see the log file."; if (bSilent == false) { OISMessageBox(errStr); return 210; } else return -210; } if ((workingProjRelativePath.Contains("{")) || (workingProjRelativePath.Contains("}"))) { errStr = "GUID chars in the proj filename on solution file line " + i.ToString() + " cannot process this file.\n\nPlease see the log file."; if (bSilent == false) { OISMessageBox(errStr); return 220; } else return -220; } // looks like we are good to go // set the name secondaryFileName = Path.GetFileName(workingProjRelativePath); // now figure out its full path secondaryFileNameAndPath = Path.Combine(sourceFilePath, workingProjRelativePath); // deslash it so we can use it as an output file, we might not use it deSlashedSecondaryFileName = DeSlashPathAndFileName(secondaryFileName); if ((deSlashedSecondaryFileName == null) || (deSlashedSecondaryFileName.Length < 3)) { LogMessage("ProcessSLNFile deSlashedSecondaryFileName==null"); errStr = "No SLN secondary file name generated.\n\nPlease see the log file."; if (bSilent == false) { OISMessageBox(errStr); return 303; } else return -303; } // build the full path to the secondary output file deSlashedSecondaryOutputFileName = BuildHTMLFileName(deSlashedSecondaryFileName, outFileNamePrefix); // build the output file container fileCont = new OutputFileContainer(SLNELEMENT_PROJECT, deSlashedSecondaryOutputFileName, workingProjName, secondaryFileNameAndPath); LogMessage("ProcessSLNFile Found Project>>" + fileCont.FileDisplayName); LogMessage("ProcessSLNFile converting to html, output file is >>" + fileCont.HtmlOutputFileName); LogMessage("\n"); // emit the contents of the CSProj output html file tw.Write("<A class=\"" + LINKTOCSPAGE + "\" HREF=\"" + fileCont.HtmlOutputFileName + "\">" + fileCont.FileDisplayName + "</A>"); tw.Write("<BR/>"); tw.Write("\r\n"); // now we try to write out the CSPROJ file itself try { // build the File_CS container and give it its name csProjFile = new File_CSPROJ(fileCont.FileNameAndPath, slnFile); // process the cs file, By the time this call sucessfully returns, the CS file // will have been converted to HTML and written to the disk. retInt = ProcessCSPROJFile(csProjFile, OutputDirectory, null, false, false, ref errStr); if (retInt != 0) { // log this LogMessage("ProcessSLNFile_Click call to ProcessCSPROJFile returned " + retInt.ToString()); // no it was not, we always report it errStr = "Error " + retInt.ToString() + " occurred processing the CSProj File.\n\n"+fileCont.FileNameAndPath+"\n\nPlease see the log file."; // yes it did, was it reported? if ((retInt < 0) && (bSilent == false)) { OISMessageBox(errStr); return 304; } else return -304; } } catch (NotImplementedException) { // we found something we could not cope with count it secondaryNotImplementedExceptionCount++; // log it LogMessage("ProcessSLNFile: Not Implemented Exception found processing file " + fileCont.FileNameAndPath); } } // bottom of for (int i = 1; i < MAX_LINES_IN_SLN; i++) tw.Write("</div> <!-- " + HTMLSECTION + "-->\r\n"); tw.Write("</div> <!-- " + HTMLSECTIONOUTER + "-->\r\n"); tw.Write("\r\n"); tw.Write(BuildHTMLFileBodyEnd(subCont)); } catch (Exception ex) { // log this LogMessage("ProcessSLNFile failed with exception " + ex.Message); // no it was not, we always report it errStr = "Error occurred processing the .sln File.\n\n" + ex.Message + "\n\nPlease see the log file."; // yes it did, was it reported? if (bSilent == false) { OISMessageBox(errStr); return 405; } else return -405; } finally { if (tw != null) { tw.Close(); } if (tr != null) { tr.Close(); } } // do we want to output the css file if (outputCSSFile == true) { retBool = OutputDefaultCSSFileToDisk(outFilePath, ref errStr); if (retBool == false) { if (bSilent == false) { OISMessageBox(errStr); return 104; } else return -104; } } // set the file path and name now slnFile.HTMLFilePathAndName = outFileName; if (secondaryNotImplementedExceptionCount != 0) { LogMessage("ProcessSLNFile secondaryNotImplementedExceptionCount =" + secondaryNotImplementedExceptionCount.ToString()); errStr = "Exceptions occurred when processing the files contained within the SLN file. Please see the logs."; if (bSilent == false) { OISMessageBox(errStr); return 303; } else return -303; } return 0; } /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Opens up a CSPROJ file /// </summary> /// <param name="filePathAndName">the full file path and name</param> /// <param name="bSilent">if true we do not pop up notices indicating failures </param> /// <param name="csProjFile">we return the cs file in this</param> /// <param name="errStr">an error string for silent returns</param> /// <param name="outFileNamePrefix">the file name prefix the HTML output file should use, can be null</param> /// <param name="outFilePath">the output file path, must point to a valid directory</param> /// <param name="outputCSPROJSFile">if true we output the css file as a separate file</param> /// <returns>z success, -ve fail user not notified, +ve fail user notified</returns> /// <history> /// 09 Jan 11 Cynic - Started /// </history> private int ProcessCSPROJFile(File_CSPROJ csProjFile, string outFilePath, string outFileNamePrefix, bool outputCSSFile, bool bSilent, ref string errStr) { TextWriter tw = null; bool retBool = false; string sourceFilePath = null; int retInt; File_CS csFile = null; int secondaryNotImplementedExceptionCount = 0; string secondaryFileName; string includeType; string secondaryFileNameAndPath; string deSlashedSecondaryFileName; string deSlashedSecondaryOutputFileName; int numberOfIgnoredErrors = 0; SubstitutionValueContainer subCont = null; // lists of our various output file elements List<OutputFileContainer> elementListCOMPILE = new List<OutputFileContainer>(); List<OutputFileContainer> elementListCONTENT = new List<OutputFileContainer>(); List<OutputFileContainer> elementListPROJECTREFERENCE = new List<OutputFileContainer>(); List<OutputFileContainer> elementListAPPLICATIONDEFINITION = new List<OutputFileContainer>(); List<OutputFileContainer> elementListPAGE = new List<OutputFileContainer>(); List<OutputFileContainer> elementListRESOURCE = new List<OutputFileContainer>(); List<OutputFileContainer> elementListSPLASHSCREEN = new List<OutputFileContainer>(); List<OutputFileContainer> elementListENTITYDEPLOY = new List<OutputFileContainer>(); List<OutputFileContainer> elementListNONE = new List<OutputFileContainer>(); List<OutputFileContainer> elementListREFERENCE = new List<OutputFileContainer>(); // this is a list of all of the above lists so that we can iterate through them easily List<List<OutputFileContainer>> listOfLists = new List<List<OutputFileContainer>>(); listOfLists.Add(elementListCOMPILE); listOfLists.Add(elementListCONTENT); listOfLists.Add(elementListPROJECTREFERENCE); listOfLists.Add(elementListAPPLICATIONDEFINITION); listOfLists.Add(elementListPAGE); listOfLists.Add(elementListRESOURCE); listOfLists.Add(elementListSPLASHSCREEN); listOfLists.Add(elementListENTITYDEPLOY); listOfLists.Add(elementListNONE); listOfLists.Add(elementListREFERENCE); errStr = ""; if (csProjFile == null) { LogMessage("ProcessCSPROJFile csProjFile == null"); errStr = "No CSPROJ file supplied.\n\nPlease see the log file."; if (bSilent == false) { OISMessageBox(errStr); return 100; } else return -100; } if ((csProjFile.SourceFilePathAndName == null) || (csProjFile.SourceFilePathAndName.Length < 3)) { LogMessage("ProcessCSPROJFile filePathAndName==null"); errStr = "No CSPROJ file name supplied.\n\nPlease see the log file."; if (bSilent == false) { OISMessageBox(errStr); return 101; } else return -101; } if ((outFilePath == null) || (outFilePath.Length < 3)) { LogMessage("ProcessCSPROJFile outFilePath==null"); errStr = "No CSPROJ outfile path supplied.\n\nPlease see the log file."; if (bSilent == false) { OISMessageBox(errStr); return 102; } else return -102; } if (Directory.Exists(outFilePath) == false) { LogMessage("ProcessCSPROJFile outFilePath does not exist"); errStr = "The output file path does not exist\n\n" + outFilePath; if (bSilent == false) { OISMessageBox(errStr); return 103; } else return -103; } LogMessage("ProcessCSPROJFile ProcessingFile>" + csProjFile.SourceFilePathAndName); if (File.Exists(csProjFile.SourceFilePathAndName) == false) { LogMessage("ProcessCSPROJFile The file " + csProjFile.SourceFilePathAndName + " does not exist."); if (bSilent == false) { OISMessageBox("The file \n\n" + csProjFile.SourceFilePathAndName + "\n\ndoes not exist. Please see the log file."); return 223; } else return -223; } // get the output file name string outFileName = BuildHTMLFileNameAndPath(csProjFile.SourceFilePathAndName, outFilePath, outFileNamePrefix); if ((outFileName == null) || (outFileName.Length < 3)) { LogMessage("ProcessCSPROJFile outFileName==null"); errStr = "No CSPROJ outfile name generated.\n\nPlease see the log file."; if (bSilent == false) { OISMessageBox(errStr); return 103; } else return -103; } // set this now, we use it for backlinks later on csProjFile.HTMLFilePathAndName = Path.GetFileName(outFileName); // get the input file path sourceFilePath = Path.GetDirectoryName(csProjFile.SourceFilePathAndName); if ((sourceFilePath == null) || (sourceFilePath.Length < 3)) { LogMessage("ProcessCSPROJFile sourceFilePath==null"); errStr = "No CSPROJ infile path generated.\n\nPlease see the log file."; if (bSilent == false) { OISMessageBox(errStr); return 104; } else return -104; } try { // set up the output file FileStream fileStream = new FileStream(csProjFile.SourceFilePathAndName, FileMode.Open, FileAccess.Read); tw = new StreamWriter(outFileName); // create a container with substitution values subCont = new SubstitutionValueContainer(InputFileTypeEnum.INPUTFILETYPE_CSPROJ, csProjFile); // now output the header HTML tw.Write(BuildHTMLFileHeader(subCont)); tw.Write("\r\n"); tw.Write(BuildHTMLFileBodyStart(subCont)); // do we have a solution if (csProjFile.SLNContainer != null) { tw.Write("\r\n"); tw.Write("<div class=\"" + HTMLBACKLINKSECTION + "\">\r\n"); tw.Write("<A class=\"" + HTMLBACKLINK + "\" HREF=\"" + csProjFile.SLNContainer.HTMLFilePathAndName + "\">[Back to Solution]</A>\r\n"); tw.Write("</div> <!-- " + HTMLBACKLINKSECTION + "-->\r\n"); tw.Write("\r\n"); } // set up to process the CSPROJ file - it is XML. We use XPATH for this XmlDocument doc = new XmlDocument(); doc.Load(csProjFile.SourceFilePathAndName); // to select elements in a namespace we need to bind a prefix to the namespace XmlNamespaceManager namespaceManager = new XmlNamespaceManager(doc.NameTable); namespaceManager.AddNamespace("ns", XMLNAMESPACE); // select the INCLUDE nodes //old way - only "Compile" elements with an "Include" attribute //XmlNodeList xnList = doc.SelectNodes("//ns:Compile[@Include]", namespaceManager); // new way "all" elements with an "Include" attribute we sort it out within the loop XmlNodeList xnList = doc.SelectNodes("//*[@Include]", namespaceManager); // now write the name of each include file to the output file foreach (XmlNode xn in xnList) { // figure out new file name here secondaryFileName = xn.Attributes["Include"].InnerText; if ((secondaryFileName == null) || (secondaryFileName.Length == 0)) { // we did not get one, we do not know the line number here we try // to leave as much debug information in the log as possible LogMessage("ProcessCSPROJFile (secondaryFileName == null) || (secondaryFileName.Length == 0)==null"); if (xn.OuterXml != null) { LogMessage("ProcessCSPROJFile: XML="+xn.OuterXml); } else { LogMessage("ProcessCSPROJFile no outer xml something very wrong."); } errStr = "No CSPROJ secondary file name generated.\n\nPlease see the log file."; if (bSilent == false) { OISMessageBox(errStr); return 200; } else return -200; } // figure out what include type of file this is from the name of the node includeType = xn.Name; if ((includeType == null) || (includeType.Length == 0)) { LogMessage("ProcessCSPROJFile (includeType == null) || (includeType.Length == 0)==null"); LogMessage("ProcessCSPROJFile Ignoring File:" + secondaryFileName); numberOfIgnoredErrors++; continue; } // also figure out its full path secondaryFileNameAndPath = Path.Combine(sourceFilePath, secondaryFileName); // deslash it so we can use it as an output file, we might not use it deSlashedSecondaryFileName = DeSlashPathAndFileName(secondaryFileName); if ((deSlashedSecondaryFileName == null) || (deSlashedSecondaryFileName.Length < 3)) { LogMessage("ProcessCSPROJFile deSlashedSecondaryFileName==null"); errStr = "No CSPROJ secondary file name generated.\n\nPlease see the log file."; if (bSilent == false) { OISMessageBox(errStr); return 203; } else return -203; } // build the full path to the secondary output file deSlashedSecondaryOutputFileName = BuildHTMLFileName(deSlashedSecondaryFileName, outFileNamePrefix); // build the output file container OutputFileContainer fileCont = new OutputFileContainer(includeType, deSlashedSecondaryOutputFileName, secondaryFileName, secondaryFileNameAndPath); // now add it to the appropriate List class switch (includeType) { case CSPROJELEMENT_EMBEDDEDRESOURCE: case CSPROJELEMENT_COMPILE: { elementListCOMPILE.Add(fileCont); continue; } case CSPROJELEMENT_CONTENT: { elementListCONTENT.Add(fileCont); continue; } case CSPROJELEMENT_PROJECTREFERENCE: { elementListPROJECTREFERENCE.Add(fileCont); continue; } case CSPROJELEMENT_APPLICATIONDEFINITION: { elementListAPPLICATIONDEFINITION.Add(fileCont); continue; } case CSPROJELEMENT_PAGE: { elementListPAGE.Add(fileCont); continue; } case CSPROJELEMENT_RESOURCE: { elementListRESOURCE.Add(fileCont); continue; } case CSPROJELEMENT_SPLASHSCREEN: { elementListSPLASHSCREEN.Add(fileCont); continue; } case CSPROJELEMENT_ENTITYDEPLOY: { elementListENTITYDEPLOY.Add(fileCont); continue; } case CSPROJELEMENT_REFERENCE: { elementListREFERENCE.Add(fileCont); continue; } case CSPROJELEMENT_NONE: default: { elementListNONE.Add(fileCont); continue; } } } // bottom of foreach (XmlNode xn in xnList) // now sort each list elementListCOMPILE.Sort(); elementListCONTENT.Sort(); elementListPROJECTREFERENCE.Sort(); elementListAPPLICATIONDEFINITION.Sort(); elementListPAGE.Sort(); elementListRESOURCE.Sort(); elementListSPLASHSCREEN.Sort(); elementListENTITYDEPLOY.Sort(); elementListNONE.Sort(); elementListREFERENCE.Sort(); // #### // #### now output, list by list // #### if(elementListCOMPILE.Count > 0) { // write the lead in and block start tw.Write("\r\n"); tw.Write("<div class=\"" + HTMLSECTIONOUTER + "\">\r\n"); tw.Write("<div class=\"" + HTMLSECTIONTITLE + "\">COMPILE and EMBEDDED RESOURCE Objects</div>\r\n"); tw.Write("<div class=\"" + HTMLSECTION + "\">\r\n"); // output the list contents foreach(OutputFileContainer fileCont in elementListCOMPILE) { LogMessage("ProcessCSPROJFile Found COMPILE Include File>>" + fileCont.FileDisplayName); LogMessage("ProcessCSPROJFile converting to html, output file is >>" + fileCont.HtmlOutputFileName); LogMessage("\n"); // emit the contents of the CSProj output html file tw.Write("<A class=\"" + LINKTOCSPAGE + "\" HREF=\"" + fileCont.HtmlOutputFileName + "\">" + fileCont.FileDisplayName + "</A>"); tw.Write("<BR/>"); tw.Write("\r\n"); // now we try to write out the CS file itself try { // build the File_CS container and give it its name csFile = new File_CS(fileCont.FileNameAndPath, Path.Combine(outFilePath, fileCont.HtmlOutputFileName), csProjFile); // process the cs file, By the time this call sucessfully returns, the CS file // will have been converted to HTML and written to the disk. retInt = ProcessCSFile(csFile, OutputDirectory, null, false, false, ref errStr); if (retInt != 0) { // log this LogMessage("ProcessCSPROJFile call to ProcessCS returned " + retInt.ToString()); // no it was not, we always report it errStr = "Error " + retInt.ToString() + " occurred processing the CS File.\n\n" + fileCont.FileNameAndPath + "\n\nPlease see the log file."; // yes it did, was it reported? if ((retInt < 0) && (bSilent == false)) { OISMessageBox(errStr); return 304; } else return -304; } } catch (NotImplementedException) { // we found something we could not cope with count it secondaryNotImplementedExceptionCount++; // log it LogMessage("ProcessCSPROJFile: Not Implemented Exception found processing file " + fileCont.FileNameAndPath); } } tw.Write("</div> <!-- " + HTMLSECTION + "-->\r\n"); tw.Write("</div> <!-- " + HTMLSECTIONOUTER + "-->\r\n"); } // bottom of if(elementListCOMPILE.Count > 0) if (elementListCONTENT.Count > 0) { // write the lead in and block start tw.Write("\r\n"); tw.Write("<div class=\"" + HTMLSECTIONOUTER + "\">\r\n"); tw.Write("<div class=\"" + HTMLSECTIONTITLE + "\">CONTENT Objects</div>\r\n"); tw.Write("<div class=\"" + HTMLSECTION + "\">\r\n"); // output the list contents foreach (OutputFileContainer fileCont in elementListCONTENT) { LogMessage("ProcessCSPROJFile Found CONTENT Include File>>" + fileCont.FileDisplayName); LogMessage("ProcessCSPROJFile converting to html, output file is >>" + fileCont.HtmlOutputFileName); // emit the contents of the CSProj output html file tw.Write(fileCont.FileDisplayName); tw.Write("<BR/>"); tw.Write("\r\n"); } tw.Write("</div> <!-- " + HTMLSECTION + "-->\r\n"); tw.Write("</div> <!-- " + HTMLSECTIONOUTER + "-->\r\n"); } // bottom of if(elementListCONTENT.Count > 0) if (elementListPROJECTREFERENCE.Count > 0) { // write the lead in and block start tw.Write("\r\n"); tw.Write("<div class=\"" + HTMLSECTIONOUTER + "\">\r\n"); tw.Write("<div class=\"" + HTMLSECTIONTITLE + "\">PROJECT REFERENCE Objects</div>\r\n"); tw.Write("<div class=\"" + HTMLSECTION + "\">\r\n"); // output the list PROJECTREFERENCEs foreach (OutputFileContainer fileCont in elementListPROJECTREFERENCE) { LogMessage("ProcessCSPROJFile Found PROJECTREFERENCE Include File>>" + fileCont.FileDisplayName); LogMessage("ProcessCSPROJFile converting to html, output file is >>" + fileCont.HtmlOutputFileName); // emit the PROJECTREFERENCEs of the CSProj output html file tw.Write(fileCont.FileDisplayName); tw.Write("<BR/>"); tw.Write("\r\n"); } tw.Write("</div> <!-- " + HTMLSECTION + "-->\r\n"); tw.Write("</div> <!-- " + HTMLSECTIONOUTER + "-->\r\n"); } // bottom of if(elementListPROJECTREFERENCE.Count > 0) if (elementListAPPLICATIONDEFINITION.Count > 0) { // write the lead in and block start tw.Write("\r\n"); tw.Write("<div class=\"" + HTMLSECTIONOUTER + "\">\r\n"); tw.Write("<div class=\"" + HTMLSECTIONTITLE + "\">APPLICATION DEFINITION Objects</div>\r\n"); tw.Write("<div class=\"" + HTMLSECTION + "\">\r\n"); // output the list APPLICATIONDEFINITIONs foreach (OutputFileContainer fileCont in elementListAPPLICATIONDEFINITION) { LogMessage("ProcessCSPROJFile Found APPLICATIONDEFINITION Include File>>" + fileCont.FileDisplayName); LogMessage("ProcessCSPROJFile converting to html, output file is >>" + fileCont.HtmlOutputFileName); // emit the APPLICATIONDEFINITIONs of the CSProj output html file tw.Write(fileCont.FileDisplayName); tw.Write("<BR/>"); tw.Write("\r\n"); } tw.Write("</div> <!-- " + HTMLSECTION + "-->\r\n"); tw.Write("</div> <!-- " + HTMLSECTIONOUTER + "-->\r\n"); } // bottom of if(elementListAPPLICATIONDEFINITION.Count > 0) if (elementListPAGE.Count > 0) { // write the lead in and block start tw.Write("\r\n"); tw.Write("<div class=\"" + HTMLSECTIONOUTER + "\">\r\n"); tw.Write("<div class=\"" + HTMLSECTIONTITLE + "\">PAGE Objects</div>\r\n"); tw.Write("<div class=\"" + HTMLSECTION + "\">\r\n"); // output the list PAGEs foreach (OutputFileContainer fileCont in elementListPAGE) { LogMessage("ProcessCSPROJFile Found PAGE Include File>>" + fileCont.FileDisplayName); LogMessage("ProcessCSPROJFile converting to html, output file is >>" + fileCont.HtmlOutputFileName); // emit the PAGEs of the CSProj output html file tw.Write(fileCont.FileDisplayName); tw.Write("<BR/>"); tw.Write("\r\n"); } tw.Write("</div> <!-- " + HTMLSECTION + "-->\r\n"); tw.Write("</div> <!-- " + HTMLSECTIONOUTER + "-->\r\n"); } // bottom of if(elementListPAGE.Count > 0) if (elementListRESOURCE.Count > 0) { // write the lead in and block start tw.Write("\r\n"); tw.Write("<div class=\"" + HTMLSECTIONOUTER + "\">\r\n"); tw.Write("<div class=\"" + HTMLSECTIONTITLE + "\">RESOURCE Objects</div>\r\n"); tw.Write("<div class=\"" + HTMLSECTION + "\">\r\n"); // output the list RESOURCEs foreach (OutputFileContainer fileCont in elementListRESOURCE) { LogMessage("ProcessCSPROJFile Found RESOURCE Include File>>" + fileCont.FileDisplayName); LogMessage("ProcessCSPROJFile converting to html, output file is >>" + fileCont.HtmlOutputFileName); // emit the RESOURCEs of the CSProj output html file tw.Write(fileCont.FileDisplayName); tw.Write("<BR/>"); tw.Write("\r\n"); } tw.Write("</div> <!-- " + HTMLSECTION + "-->\r\n"); tw.Write("</div> <!-- " + HTMLSECTIONOUTER + "-->\r\n"); } // bottom of if(elementListRESOURCE.Count > 0) if (elementListSPLASHSCREEN.Count > 0) { // write the lead in and block start tw.Write("\r\n"); tw.Write("<div class=\"" + HTMLSECTIONOUTER + "\">\r\n"); tw.Write("<div class=\"" + HTMLSECTIONTITLE + "\">SPLASH SCREEN Objects</div>\r\n"); tw.Write("<div class=\"" + HTMLSECTION + "\">\r\n"); // output the list SPLASHSCREENs foreach (OutputFileContainer fileCont in elementListSPLASHSCREEN) { LogMessage("ProcessCSPROJFile Found SPLASHSCREEN Include File>>" + fileCont.FileDisplayName); LogMessage("ProcessCSPROJFile converting to html, output file is >>" + fileCont.HtmlOutputFileName); // emit the SPLASHSCREENs of the CSProj output html file tw.Write(fileCont.FileDisplayName); tw.Write("<BR/>"); tw.Write("\r\n"); } tw.Write("</div> <!-- " + HTMLSECTION + "-->\r\n"); tw.Write("</div> <!-- " + HTMLSECTIONOUTER + "-->\r\n"); } // bottom of if(elementListSPLASHSCREEN.Count > 0) if (elementListENTITYDEPLOY.Count > 0) { // write the lead in and block start tw.Write("\r\n"); tw.Write("<div class=\"" + HTMLSECTIONOUTER + "\">\r\n"); tw.Write("<div class=\"" + HTMLSECTIONTITLE + "\">ENTITY DEPLOY Objects</div>\r\n"); tw.Write("<div class=\"" + HTMLSECTION + "\">\r\n"); // output the list ENTITYDEPLOYs foreach (OutputFileContainer fileCont in elementListENTITYDEPLOY) { LogMessage("ProcessCSPROJFile Found ENTITYDEPLOY Include File>>" + fileCont.FileDisplayName); LogMessage("ProcessCSPROJFile converting to html, output file is >>" + fileCont.HtmlOutputFileName); // emit the ENTITYDEPLOYs of the CSProj output html file tw.Write(fileCont.FileDisplayName); tw.Write("<BR/>"); tw.Write("\r\n"); } tw.Write("</div> <!-- " + HTMLSECTION + "-->\r\n"); tw.Write("</div> <!-- " + HTMLSECTIONOUTER + "-->\r\n"); } // bottom of if(elementListENTITYDEPLOY.Count > 0) if (elementListREFERENCE.Count > 0) { // write the lead in and block start tw.Write("\r\n"); tw.Write("<div class=\"" + HTMLSECTIONOUTER + "\">\r\n"); tw.Write("<div class=\"" + HTMLSECTIONTITLE + "\">REFERENCE Objects</div>\r\n"); tw.Write("<div class=\"" + HTMLSECTION + "\">\r\n"); // output the list REFERENCEs foreach (OutputFileContainer fileCont in elementListREFERENCE) { LogMessage("ProcessCSPROJFile Found REFERENCE Include File>>" + fileCont.FileDisplayName); LogMessage("ProcessCSPROJFile converting to html, output file is >>" + fileCont.HtmlOutputFileName); // emit the REFERENCEs of the CSProj output html file tw.Write(fileCont.FileDisplayName); tw.Write("<BR/>"); tw.Write("\r\n"); } tw.Write("</div> <!-- " + HTMLSECTION + "-->\r\n"); tw.Write("</div> <!-- " + HTMLSECTIONOUTER + "-->\r\n"); } // bottom of if(elementListREFERENCE.Count > 0) if (elementListNONE.Count > 0) { // write the lead in and block start tw.Write("\r\n"); tw.Write("<div class=\"" + HTMLSECTIONOUTER + "\">\r\n"); tw.Write("<div class=\"" + HTMLSECTIONTITLE + "\">NONE (or Unknown) Objects</div>\r\n"); tw.Write("<div class=\"" + HTMLSECTION + "\">\r\n"); // output the list NONEs foreach (OutputFileContainer fileCont in elementListNONE) { LogMessage("ProcessCSPROJFile Found NONE (or Unknown) File>>" + fileCont.FileDisplayName); LogMessage("ProcessCSPROJFile converting to html, output file is >>" + fileCont.HtmlOutputFileName); // emit the NONEs of the CSProj output html file tw.Write(fileCont.FileDisplayName); tw.Write("<BR/>"); tw.Write("\r\n"); } tw.Write("</div> <!-- " + HTMLSECTION + "-->\r\n"); tw.Write("</div> <!-- " + HTMLSECTIONOUTER + "-->\r\n"); } // bottom of if(elementListNONE.Count > 0) tw.Write("\r\n"); tw.Write(BuildHTMLFileBodyEnd(subCont)); } catch (Exception ex) { // log this LogMessage("ProcessCSPROJFile failed with exception " + ex.Message); // no it was not, we always report it errStr = "Error occurred processing the .csProj File.\n\n" + ex.Message + "\n\nPlease see the log file."; // yes it did, was it reported? if (bSilent == false) { OISMessageBox(errStr); return 405; } else return -405; } finally { if (tw != null) { tw.Close(); } } // do we want to output the css file if (outputCSSFile == true) { retBool = OutputDefaultCSSFileToDisk(outFilePath, ref errStr); if (retBool == false) { if (bSilent == false) { OISMessageBox(errStr); return 104; } else return -104; } } // set the file path and name now csProjFile.HTMLFilePathAndName = outFileName; if (secondaryNotImplementedExceptionCount != 0 ) { LogMessage("ProcessCSPROJFile secondaryNotImplementedExceptionCount =" + secondaryNotImplementedExceptionCount.ToString()); errStr = "Exceptions occurred when processing the files contained within the CSPROJ file. Please see the logs."; if (bSilent == false) { OISMessageBox(errStr); return 503; } else return -503; } return 0; } /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Opens up a CS file /// </summary> /// <param name="filePathAndName">the full file path and name</param> /// <param name="bSilent">if true we do not pop up notices indicating failures </param> /// <param name="outputCSFile">we return the cs file in this</param> /// <param name="errStr">an error string for silent returns</param> /// <param name="outFileNamePrefix">the file name prefix the HTML output file should use, can be null</param> /// <param name="outFilePath">the output file path, must point to a valid directory</param> /// <param name="outputCSSFile">if true we output the css file as a separate file</param> /// <returns>z success, -ve fail user not notified, +ve fail user notified</returns> /// <history> /// 02 Jan 11 Cynic - Started /// </history> private int ProcessCSFile(File_CS outputCSFile, string outFilePath, string outFileNamePrefix, bool outputCSSFile, bool bSilent, ref string errStr) { TextWriter tw = null; bool retBool = false; SubstitutionValueContainer subCont = null; errStr = ""; if (outputCSFile == null) { LogMessage("ProcessCSFile outputCSFile == null"); errStr = "No CS file supplied.\n\nPlease see the log file."; if (bSilent == false) { OISMessageBox(errStr); return 100; } else return -100; } if ((outputCSFile.SourceFilePathAndName == null) || (outputCSFile.SourceFilePathAndName.Length < 3)) { LogMessage("ProcessCSFile filePathAndName==null"); errStr = "No CS file name supplied.\n\nPlease see the log file."; if (bSilent == false) { OISMessageBox(errStr); return 101; } else return -101; } if ((outFilePath == null) || (outFilePath.Length < 3)) { LogMessage("ProcessCSFile outFilePath==null"); errStr = "No CS outfile path supplied.\n\nPlease see the log file."; if (bSilent == false) { OISMessageBox(errStr); return 102; } else return -102; } if (Directory.Exists(outFilePath) == false) { LogMessage("ProcessCSFile outFilePath does not exist"); errStr = "The output file path does not exist\n\n" + outFilePath; if (bSilent == false) { OISMessageBox(errStr); return 103; } else return -103; } LogMessage("ProcessCSFile ProcessingFile>" + outputCSFile.SourceFilePathAndName); if (File.Exists(outputCSFile.SourceFilePathAndName) == false) { LogMessage("ProcessCSFile The file " + outputCSFile.SourceFilePathAndName + " does not exist."); if (bSilent == false) { OISMessageBox("The file \n\n" + outputCSFile.SourceFilePathAndName + "\n\ndoes not exist. Please see the log file."); return 223; } else return -223; } // do we need to make up an output file name? we do if it has not already been made if ((outputCSFile.HTMLFilePathAndName == null) || (outputCSFile.HTMLFilePathAndName.Length == 0)) { // build the output file name outputCSFile.HTMLFilePathAndName = BuildHTMLFileNameAndPath(outputCSFile.SourceFilePathAndName, outFilePath, outFileNamePrefix); } if ((outputCSFile.HTMLFilePathAndName == null) || (outputCSFile.HTMLFilePathAndName.Length < 3)) { LogMessage("ProcessCSFile outputCSFile.HTMLFilePathAndName==null"); errStr = "No CS outfile name generated.\n\nPlease see the log file."; if (bSilent == false) { OISMessageBox(errStr); return 103; } else return -103; } // get the formatter as supplied by Jean-Claude Manoli CSharpFormat sourceFormatter = new CSharpFormat(); // we never want to embed the style sheet sourceFormatter.EmbedStyleSheet = false; try { FileStream fileStream = new FileStream(outputCSFile.SourceFilePathAndName, FileMode.Open, FileAccess.Read); string processedHTML = sourceFormatter.FormatCode(fileStream); tw = new StreamWriter(outputCSFile.HTMLFilePathAndName); // create a container with substitution values subCont = new SubstitutionValueContainer(InputFileTypeEnum.INPUTFILETYPE_CS, outputCSFile); // now output the header HTML tw.Write(BuildHTMLFileHeader(subCont)); tw.Write("\r\n"); tw.Write(BuildHTMLFileBodyStart(subCont)); // do we have a project container if (outputCSFile.CSPROJContainer != null) { tw.Write("\r\n"); tw.Write("<div class=\"" + HTMLBACKLINKSECTION + "\">\r\n"); if (outputCSFile.CSPROJContainer.SLNContainer != null) { tw.Write("\r\n"); tw.Write("<A class=\"" + HTMLBACKLINK + "\" HREF=\"" + outputCSFile.CSPROJContainer.SLNContainer.HTMLFilePathAndName + "\">[Back to Solution]</A>"); } tw.Write("<A class=\"" + HTMLBACKLINK + "\" HREF=\"" + outputCSFile.CSPROJContainer.HTMLFilePathAndName + "\">[Back to Project]</A>\r\n"); tw.Write("</div> <!-- " + HTMLBACKLINKSECTION + "-->\r\n"); tw.Write("\r\n"); } // wrap it in a div tw.Write("<div class=\"" + CSFILESECTION + "\">\r\n"); // now write the actual text tw.Write(processedHTML); // close the div tw.Write("</div> <!-- " + CSFILESECTION + "-->\r\n"); // do we have a project container if (outputCSFile.CSPROJContainer != null) { tw.Write("\r\n"); tw.Write("<div class=\"" + HTMLBACKLINKSECTION + "\">\r\n"); if (outputCSFile.CSPROJContainer.SLNContainer != null) { tw.Write("\r\n"); tw.Write("<A class=\"" + HTMLBACKLINK + "\" HREF=\"" + outputCSFile.CSPROJContainer.SLNContainer.HTMLFilePathAndName + "\">[Back to Solution]</A>"); } tw.Write("<A class=\"" + HTMLBACKLINK + "\" HREF=\"" + outputCSFile.CSPROJContainer.HTMLFilePathAndName + "\">[Back to Project]</A>\r\n"); tw.Write("</div> <!-- " + HTMLBACKLINKSECTION + "-->\r\n"); tw.Write("\r\n"); } // now the footer tw.Write("\r\n"); tw.Write(BuildHTMLFileBodyEnd(subCont)); } finally { if (tw != null) { tw.Close(); } } // do we want to output the css file if(outputCSSFile == true) { retBool = OutputDefaultCSSFileToDisk(outFilePath, ref errStr); if (retBool==false) { if (bSilent == false) { OISMessageBox(errStr); return 104; } else return -104; } } return 0; } /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Emits the CSS file to disk. /// </summary> /// <param name="outFilePath">the path to the output folder</param> /// <history> /// 03 Jan 11 Cynic - Started /// </history> private bool OutputDefaultCSSFileToDisk(string outFilePath, ref string errStr) { TextWriter tw = null; errStr = ""; // sanity check if ((outFilePath == null) || (outFilePath.Length < 3)) { LogMessage("OutputCSSFileToDisk outFilePath==null"); errStr = "No outfile path supplied.\n\nPlease see the log file."; return false; } if (Directory.Exists(outFilePath) == false) { LogMessage("OutputDefaultCSSFileToDisk outFilePath does not exist"); errStr = "The output file path does not exist\n\n" + outFilePath; return false; } // build the outfile name string outFileName = Path.Combine(outFilePath, CODOCKER_DEFAULTCSS); LogMessage("OutputCSSFileToDisk writing Default CSS file>" + outFileName); try { // use the formatter as supplied by Jean-Claude Manoli to get // the css file text contents string outText = CSharpFormat.GetCssString(); if((outText==null) || (outText.Length==0)) outText="stylesheet error"; tw = new StreamWriter(outFileName); // now write the actual text tw.Write(outText); } finally { if (tw != null) { tw.Close(); } } return true; } /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Builds and returns a HTML header /// </summary> /// <param name="subCont">the substitution container</param> /// <history> /// 03 Mar 11 Cynic - Started /// </history> private string BuildHTMLFileHeader(SubstitutionValueContainer subCont) { StringBuilder sb = new StringBuilder(); // get our raw header sb.Append(CoDocker.Properties.Resources.HTMLHeader); // substitute the tags a couple of times to make sure we recurse PerformTagSubstitution(ref sb, subCont); PerformTagSubstitution(ref sb, subCont); PerformTagSubstitution(ref sb, subCont); return sb.ToString(); } /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Builds and returns a HTML body start /// </summary> /// <param name="subCont">the substitution container</param> /// <history> /// 03 Mar 11 Cynic - Started /// </history> private string BuildHTMLFileBodyStart(SubstitutionValueContainer subCont) { StringBuilder sb = new StringBuilder(); // get our raw body start text sb.Append(CoDocker.Properties.Resources.HTMLBodyStart); // substitute the tags a couple of times to make sure we recurse PerformTagSubstitution(ref sb, subCont); PerformTagSubstitution(ref sb, subCont); PerformTagSubstitution(ref sb, subCont); return sb.ToString(); } /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Builds and returns a HTML footer /// </summary> /// <param name="subCont">the substitution container</param> /// <history> /// 03 Mar 11 Cynic - Started /// </history> private string BuildHTMLFileBodyEnd(SubstitutionValueContainer subCont) { StringBuilder sb = new StringBuilder(); // get our raw body start text sb.Append(CoDocker.Properties.Resources.HTMLBodyEnd); // substitute the tags a couple of times to make sure we recurse PerformTagSubstitution(ref sb, subCont); PerformTagSubstitution(ref sb, subCont); PerformTagSubstitution(ref sb, subCont); return sb.ToString(); } /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// The one and only place we perform substitutions on HTML output text. /// This is how the user supplied information gets inserted into the /// HTML file /// </summary> /// <param name="subCont">the substitution container, cannot be null</param> /// <param name="htmlText">The html text to substitute, cannot be null</param> /// <history> /// 20 May 11 Cynic - Started /// </history> private void PerformTagSubstitution(ref StringBuilder htmlText, SubstitutionValueContainer subCont) { if (htmlText == null) return; if (subCont == null) return; // note the order of some of these substitutions matters!! htmlText.Replace(STYLESHEET_NAME, StyleSheetName); if (subCont.InputFileType == InputFileTypeEnum.INPUTFILETYPE_CS) { htmlText.Replace(USERDEFINED_BODY_BANNERMARKER, GetCSBanner()); htmlText.Replace(USERDEFINED_BODY_FOOTERMARKER, GetCSFooter()); htmlText.Replace(TITLEMARKER, GetCSTitle()); htmlText.Replace(DESCRIPTIONMARKER, GetCSDesc()); } else if (subCont.InputFileType == InputFileTypeEnum.INPUTFILETYPE_CSPROJ) { if (checkBoxProjUseCSBanner.Checked == false) htmlText.Replace(USERDEFINED_BODY_BANNERMARKER, GetCSPROJBanner()); else htmlText.Replace(USERDEFINED_BODY_BANNERMARKER, GetCSBanner()); if (checkBoxProjUseCSFooter.Checked == false) htmlText.Replace(USERDEFINED_BODY_FOOTERMARKER, GetCSPROJFooter()); else htmlText.Replace(USERDEFINED_BODY_FOOTERMARKER, GetCSFooter()); if(checkBoxProjUseCSTitle.Checked == false ) htmlText.Replace(TITLEMARKER, GetCSPROJTitle()); else htmlText.Replace(TITLEMARKER, GetCSTitle()); if(checkBoxProjUseCSDesc.Checked == false ) htmlText.Replace(DESCRIPTIONMARKER, GetCSPROJDesc()); else htmlText.Replace(DESCRIPTIONMARKER, GetCSDesc()); } else if (subCont.InputFileType == InputFileTypeEnum.INPUTFILETYPE_SLN) { if (checkBoxSLNUseCSBanner.Checked == false) htmlText.Replace(USERDEFINED_BODY_BANNERMARKER, GetSLNBanner()); else htmlText.Replace(USERDEFINED_BODY_BANNERMARKER, GetCSBanner()); if (checkBoxSLNUseCSFooter.Checked == false) htmlText.Replace(USERDEFINED_BODY_FOOTERMARKER, GetSLNFooter()); else htmlText.Replace(USERDEFINED_BODY_FOOTERMARKER, GetCSFooter()); if (checkBoxSLNUseCSTitle.Checked == false) htmlText.Replace(TITLEMARKER, GetSLNTitle()); else htmlText.Replace(TITLEMARKER, GetCSTitle()); if (checkBoxSLNUseCSDesc.Checked == false) htmlText.Replace(DESCRIPTIONMARKER, GetSLNDesc()); else htmlText.Replace(DESCRIPTIONMARKER, GetCSDesc()); } // things the user can specify htmlText.Replace(CODOCKER_NAME, APPLICATION_NAME); htmlText.Replace(CODOCKER_VERSION, APPLICATION_VERSION); htmlText.Replace(CODOCKER_HOME, APPLICATION_HOME); htmlText.Replace(CODOCKER_ROOT, APPLICATION_ROOT); htmlText.Replace(CODOCKERLINK, CODOCKERLINK_CONTENT); htmlText.Replace(CURRENT_DATETIME, String.Format("{0:ddd, MMM d, yyyy}", DateTime.Now)); htmlText.Replace(INFILENAME, Path.GetFileName(subCont.SourceFilePathAndName)); htmlText.Replace(INFILENAME_NOEXT, Path.GetFileNameWithoutExtension(subCont.SourceFilePathAndName)); htmlText.Replace(INFILENAME_WITHPATH, subCont.SourceFilePathAndName); htmlText.Replace(INFILEDIRECTORY, Path.GetDirectoryName(subCont.SourceFilePathAndName)); htmlText.Replace(USERNAME, Environment.UserName.ToString()); htmlText.Replace(MACHINENAME, Environment.MachineName.ToString()); htmlText.Replace(FILETYPE, GetFILETYPEAsString(subCont)); } /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// gets the file type as a string suitable for substitition /// </summary> /// <history> /// 20 May 11 Cynic - Started /// </history> private string GetFILETYPEAsString(SubstitutionValueContainer subCont) { if (subCont == null) return ""; if (subCont.SourceFilePathAndName.Contains(EXT_CSPROJ) == true) return TYPE_PROJECT_TEXT; if (subCont.SourceFilePathAndName.Contains(EXT_SLN) == true) return TYPE_SLN_TEXT; return TYPE_CS_TEXT; } /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Returns the user defined body header text /// </summary> /// <history> /// 20 May 11 Cynic - Started /// </history> private string GetCSTitle() { StringBuilder sb = new StringBuilder(); sb.Append(textBoxCSPageTitle.Text); return sb.ToString(); } /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Returns the user defined body header text /// </summary> /// <history> /// 20 May 11 Cynic - Started /// </history> private string GetCSDesc() { StringBuilder sb = new StringBuilder(); sb.Append(textBoxCSPageDesc.Text); return sb.ToString(); } /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Returns the user defined body header text /// </summary> /// <history> /// 20 May 11 Cynic - Started /// </history> private string GetCSBanner() { StringBuilder sb = new StringBuilder(); sb.Append(richTextBoxCSBannerContent.Text); return sb.ToString(); } /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Returns the user defined body header text, will never return null /// </summary> /// <history> /// 20 May 11 Cynic - Started /// </history> private string GetCSFooter() { StringBuilder sb = new StringBuilder(); sb.Append(richTextBoxCSFooterContent.Text); return sb.ToString(); } /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Returns the user defined body header text /// </summary> /// <history> /// 20 May 11 Cynic - Started /// </history> private string GetCSPROJTitle() { StringBuilder sb = new StringBuilder(); sb.Append(textBoxCSProjPageTitle.Text); return sb.ToString(); } /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Returns the user defined body header text /// </summary> /// <history> /// 20 May 11 Cynic - Started /// </history> private string GetCSPROJDesc() { StringBuilder sb = new StringBuilder(); sb.Append(textBoxCSProjPageDesc.Text); return sb.ToString(); } /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Returns the user defined body header text /// </summary> /// <history> /// 03 Mar 11 Cynic - Started /// </history> private string GetCSPROJBanner() { StringBuilder sb = new StringBuilder(); sb.Append(richTextBoxCSProjBannerContent.Text); return sb.ToString(); } /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Returns the user defined body header text, will never return null /// </summary> /// <history> /// 03 Mar 11 Cynic - Started /// </history> private string GetCSPROJFooter() { StringBuilder sb = new StringBuilder(); sb.Append(richTextBoxCSProjFooterContent.Text); return sb.ToString(); } /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Returns the user defined body header text /// </summary> /// <history> /// 23 May 11 Cynic - Started /// </history> private string GetSLNTitle() { StringBuilder sb = new StringBuilder(); sb.Append(textBoxSLNPageTitle.Text); return sb.ToString(); } /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Returns the user defined body header text /// </summary> /// <history> /// 23 May 11 Cynic - Started /// </history> private string GetSLNDesc() { StringBuilder sb = new StringBuilder(); sb.Append(textBoxSLNPageDesc.Text); return sb.ToString(); } /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Returns the user defined body header text /// </summary> /// <history> /// 23 May 11 Cynic - Started /// </history> private string GetSLNBanner() { StringBuilder sb = new StringBuilder(); sb.Append(richTextBoxSLNBannerContent.Text); return sb.ToString(); } /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Returns the user defined body header text, will never return null /// </summary> /// <history> /// 23 May 11 Cynic - Started /// </history> private string GetSLNFooter() { StringBuilder sb = new StringBuilder(); sb.Append(richTextBoxSLNFooterContent.Text); return sb.ToString(); } /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Builds the output Path + file name from the inputs /// </summary> /// <param name="inFilePathAndName">the source file path and name</param> /// <param name="outFileNamePrefix">the prefix for the output file, this can be null. usually this /// is the solution.project name we will prepend this with a dot</param> /// <param name="outFilePath">the path to the output folder</param> /// <history> /// 03 Jan 11 Cynic - Started /// </history> private string BuildHTMLFileNameAndPath(string inFilePathAndName, string outFilePath, string outFileNamePrefix) { StringBuilder sb = new StringBuilder(); if ((inFilePathAndName == null) || (inFilePathAndName.Length < 3)) { LogMessage("BuildHTMLFileNameAndPath filePathAndName is null or <3 chars"); return ""; } // we do not test if this exists, this must be done elsewhere if ((outFilePath == null) || (outFilePath.Length < 3)) { LogMessage("BuildHTMLFileNameAndPath outFilePath is null or <3 chars"); return ""; } if ((outFilePath == null) || (outFilePath.Length < 3)) { LogMessage("BuildHTMLFileNameAndPath outFilePath does not exist"); return ""; } // build the full file name if (((outFileNamePrefix == null) || (outFileNamePrefix.Length ==0))==false) { // append on our prefix sb.Append(outFileNamePrefix); sb.Append("."); } sb.Append(Path.Combine(outFilePath, Path.GetFileName(inFilePathAndName))); sb.Append("."); sb.Append(OutputFileExtensionAsString()); return sb.ToString(); } /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Builds the output file name (but no path) from the inputs /// </summary> /// <param name="inFileName">the source file path and name</param> /// <param name="outFileNamePrefix">the prefix for the output file, this can be null. usually this /// is the solution.project name we will prepend this with a dot</param> /// <param name="outFilePath">the path to the output folder</param> /// <history> /// 13 Feb 11 Cynic - Started /// </history> private string BuildHTMLFileName(string inFileName, string outFileNamePrefix) { StringBuilder sb = new StringBuilder(); if ((inFileName == null) || (inFileName.Length < 3)) { LogMessage("BuildHTMLFileName inFileName is null or <3 chars"); return ""; } // build the full file name if (((outFileNamePrefix == null) || (outFileNamePrefix.Length == 0)) == false) { // append on our prefix sb.Append(outFileNamePrefix); sb.Append("."); } sb.Append(inFileName); sb.Append("."); sb.Append(OutputFileExtensionAsString()); return sb.ToString(); } /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Removes slashes from a path and file name. We need this because C# usually /// uses relative path names for files contained in projects and solutions. These /// have to be converted to our dot notation in order to form the output files /// </summary> /// <param name="inFilePathAndName">the source file path and name</param> /// <param name="outFilePath">the path to the output folder</param> /// <history> /// 13 Feb 11 Cynic - Started /// </history> private string DeSlashPathAndFileName(string inFilePathAndName) { StringBuilder sb = new StringBuilder(); if ((inFilePathAndName == null) || (inFilePathAndName.Length < 3)) { LogMessage("DeSlashPathAndFileName filePathAndName is null or <3 chars"); return ""; } return inFilePathAndName.Replace('\\','.'); } /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Gets the CSS String suitable for embedding directly in an HTML document. /// This just follows JCManolis example in the SourceFormat.FormatCode /// function. Split out here so that I do not make changes to that class. /// </summary> /// <history> /// 02 Feb 11 Cynic - Started /// </history> public string GetEmbeddedCssString() { StringBuilder sb = new StringBuilder(); sb.Append("<style type=\"text/css\">\n"); sb.Append(SourceFormat.GetCssString()); sb.Append("</style>\n"); return sb.ToString(); } /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// launches a web browser to view the output file /// </summary> /// <param name="helpFileName">the name of the help file</param> /// <history> /// 03 Jan 11 Cynic - Originally written /// </history> public void LaunchHTMLFile(string htmlFileNameAndPath) { // sanity check if ((htmlFileNameAndPath == null) || (htmlFileNameAndPath.Length == 0)) { LogMessage("LaunchHTMLFile: invalid name supplied, file cannot be launched"); return; } try { // launch the file System.Diagnostics.Process p = new System.Diagnostics.Process(); System.Diagnostics.ProcessStartInfo pi = new System.Diagnostics.ProcessStartInfo(); pi.FileName = htmlFileNameAndPath; p.StartInfo = pi; p.Start(); } catch (Exception) { } } #endregion // #################################################################### // ##### Button Handlers and Events // #################################################################### #region Button Handlers and Events /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Handles a press on the about button /// </summary> /// <history> /// 02 Jan 11 Cynic - Started /// </history> private void buttonAbout_Click(object sender, EventArgs e) { frmAbout aboutForm = new frmAbout(APPLICATION_VERSION); aboutForm.ShowDialog(); } /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Handles a press on the open file button /// </summary> /// <history> /// 02 Jan 11 Cynic - Started /// </history> private void buttonOpenFileCS_Click(object sender, EventArgs e) { int retInt; Cursor tmpCursor = Cursor.Current; File_CS csFile = null; string errStr=""; LogMessage("buttonOpenFileCS_Click called"); // we show a message once regarding the license if (implictUserSettings != null) { if (implictUserSettings.OKWithDisclaimer == false) { frmDisclaimer disFrm = new frmDisclaimer(APPLICATION_VERSION); disFrm.ShowDialog(); if (disFrm.OKWithDisclaimer == false) return; implictUserSettings.OKWithDisclaimer = disFrm.OKWithDisclaimer; } } else { frmDisclaimer disFrm = new frmDisclaimer(APPLICATION_VERSION); disFrm.ShowDialog(); if (disFrm.OKWithDisclaimer == false) return; } string filePathAndName=""; retInt = PickFile(ImplicitUserSettings.LastOpenCSFileDirectory, ImplicitUserSettings.LastOpenCSFileName, FILTER_CS, BOXTITLE_CS, ref filePathAndName); if(retInt<0) { // log this LogMessage("buttonOpenFileCS_Click call to PickFile was cancelled"); return; } if (retInt > 0) { // log this LogMessage("buttonOpenFileCS_Click call to PickFile returned error of "+retInt.ToString()); OISMessageBox("Error " + retInt.ToString() + " occurred when choosing the Gerber File.\n\nPlease see the log file."); return; } if ((filePathAndName == null) || (filePathAndName.Length == 0)) { // log this LogMessage("buttonOpenFileCS_Click call to PickFile returned ((filePathAndName == null) || (filePathAndName.Length == 0))"); OISMessageBox("Error no file name returned when choosing the Gerber File.\n\nPlease see the log file."); return; } LogMessage("Preparing to open file: " + filePathAndName); // if we get here the pick was successful. Add the file to the MRU list MRUList.AddFileNameToTop(filePathAndName); // add the directory to our configuration settings so we return to // it automatically next time we start ImplicitUserSettings.LastOpenCSFileDirectory = Path.GetDirectoryName(filePathAndName); ImplicitUserSettings.LastOpenCSFileName = Path.GetFileName(filePathAndName); // do we want to also emit a single output css file? bool alsoOutputCSSFile = false; if (StyleSheetType == StyleSheetTypeEnum.STYLESHEET_USERDEFINED) { alsoOutputCSSFile = false; } else { alsoOutputCSSFile = true; } // build the File_CS container and give it its name csFile = new File_CS(filePathAndName, null); // set the cursor, this can take some time tmpCursor = Cursor.Current; Cursor.Current = Cursors.WaitCursor; try { // open the file, note that our outputCSFile is mostly a container for the names. By the time this call // sucessfully returns, the CS file will have been converted to HTML and written to // the disk. retInt = ProcessCSFile(csFile, OutputDirectory, null, alsoOutputCSSFile, false, ref errStr); if (retInt != 0) { // log this LogMessage("buttonOpenFileCS_Click call to ProcessCSFile returned " + retInt.ToString()); // yes it did, was it reported? if (retInt < 0) { // no it was not, we always report it OISMessageBox("Error " + retInt.ToString() + " occurred opening the File.\n\nPlease see the log file."); } return; } } catch (NotImplementedException ex) { // we found something we could not cope with OISMessageBox("Sorry, this file cannot be opened because some of its contents are not yet supported. Error message was:\n\n" + ex.Message); return; } finally { // restore the cursor back to what it was Cursor.Current = tmpCursor; } // we are done, ask if the user wants to view the output file DialogResult dlgRes = OISMessageBox_YesNo("The CS file was converted successfully.\n\nWould you like to view the output?"); if (dlgRes == DialogResult.Yes) { LaunchHTMLFile(csFile.HTMLFilePathAndName); } } /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Handles a press on the open CSProj file button /// </summary> /// <history> /// 08 Jan 11 Cynic - Started /// </history> private void buttonOpenFileCSPROJ_Click(object sender, EventArgs e) { int retInt; Cursor tmpCursor = Cursor.Current; File_CSPROJ csProjFile = null; string errStr = ""; LogMessage("buttonOpenFileCSPROJ_Click called"); // we show a message once regarding the license if (implictUserSettings != null) { if (implictUserSettings.OKWithDisclaimer == false) { frmDisclaimer disFrm = new frmDisclaimer(APPLICATION_VERSION); disFrm.ShowDialog(); if (disFrm.OKWithDisclaimer == false) return; implictUserSettings.OKWithDisclaimer = disFrm.OKWithDisclaimer; } } else { frmDisclaimer disFrm = new frmDisclaimer(APPLICATION_VERSION); disFrm.ShowDialog(); if (disFrm.OKWithDisclaimer == false) return; } string filePathAndName = ""; retInt = PickFile(ImplicitUserSettings.LastOpenCSPROJFileDirectory, ImplicitUserSettings.LastOpenCSPROJFileName, FILTER_CSPROJ, BOXTITLE_CSPROJ, ref filePathAndName); if (retInt < 0) { // log this LogMessage("buttonOpenFileCSPROJ_Click call to PickFile was cancelled"); return; } if (retInt > 0) { // log this LogMessage("buttonOpenFileCSPROJ_Click call to PickFile returned error of " + retInt.ToString()); OISMessageBox("Error " + retInt.ToString() + " occurred when choosing the Gerber File.\n\nPlease see the log file."); return; } if ((filePathAndName == null) || (filePathAndName.Length == 0)) { // log this LogMessage("buttonOpenFileCSPROJ_Click call to PickFile returned ((filePathAndName == null) || (filePathAndName.Length == 0))"); OISMessageBox("Error no file name returned when choosing the Gerber File.\n\nPlease see the log file."); return; } LogMessage("Preparing to open file: " + filePathAndName); // if we get here the pick was successful. Add the file to the MRU list MRUList.AddFileNameToTop(filePathAndName); // add the directory to our configuration settings so we return to // it automatically next time we start ImplicitUserSettings.LastOpenCSPROJFileDirectory = Path.GetDirectoryName(filePathAndName); ImplicitUserSettings.LastOpenCSPROJFileName = Path.GetFileName(filePathAndName); // build the File_CSPROJ container and give it its name csProjFile = new File_CSPROJ(filePathAndName, null); // do we want to also emit a single output css file? bool alsoOutputCSSFile = false; if (StyleSheetType == StyleSheetTypeEnum.STYLESHEET_USERDEFINED) { alsoOutputCSSFile = false; } else { alsoOutputCSSFile = true; } // set the cursor, this can take some time tmpCursor = Cursor.Current; Cursor.Current = Cursors.WaitCursor; try { // open the file, note that our outputCSFile is mostly a container for the names. By the time this call // sucessfully returns, the CS file will have been converted to HTML and written to // the disk. retInt = ProcessCSPROJFile(csProjFile, OutputDirectory, null, alsoOutputCSSFile, false, ref errStr); if (retInt != 0) { // log this LogMessage("buttonOpenFileCSPROJ_Click call to ProcessCSPROJFile returned" + retInt.ToString()); // yes it did, was it reported? if (retInt < 0) { // no it was not, we always report it OISMessageBox("Error " + retInt.ToString() + " occurred opening the File.\n\nPlease see the log file."); } return; } } catch (NotImplementedException ex) { // we found something we could not cope with OISMessageBox("Sorry, this file cannot be opened because some of its contents are not yet supported. Error message was:\n\n" + ex.Message); return; } finally { // restore the cursor back to what it was Cursor.Current = tmpCursor; } // we are done, ask if the user wants to view the output file DialogResult dlgRes = OISMessageBox_YesNo("The CSPROJ file and all of its contained CS files was converted successfully.\n\nWould you like to view the output?"); if (dlgRes == DialogResult.Yes) { LaunchHTMLFile(csProjFile.HTMLFilePathAndName); } } /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Handles a press on the open SLN file button /// </summary> /// <history> /// 23 May 11 Cynic - Started /// </history> private void buttonOpenFileSLN_Click(object sender, EventArgs e) { int retInt; Cursor tmpCursor = Cursor.Current; File_SLN slnFile = null; string errStr = ""; LogMessage("buttonOpenFileSLN_Click called"); // we show a message once regarding the license if (implictUserSettings != null) { if (implictUserSettings.OKWithDisclaimer == false) { frmDisclaimer disFrm = new frmDisclaimer(APPLICATION_VERSION); disFrm.ShowDialog(); if (disFrm.OKWithDisclaimer == false) return; implictUserSettings.OKWithDisclaimer = disFrm.OKWithDisclaimer; } } else { frmDisclaimer disFrm = new frmDisclaimer(APPLICATION_VERSION); disFrm.ShowDialog(); if (disFrm.OKWithDisclaimer == false) return; } string filePathAndName = ""; retInt = PickFile(ImplicitUserSettings.LastOpenSLNFileDirectory, ImplicitUserSettings.LastOpenSLNFileName, FILTER_SLN, BOXTITLE_SLN, ref filePathAndName); if (retInt < 0) { // log this LogMessage("buttonOpenFileSLN_Click call to PickFile was cancelled"); return; } if (retInt > 0) { // log this LogMessage("buttonOpenFileSLN_Click call to PickFile returned error of " + retInt.ToString()); OISMessageBox("Error " + retInt.ToString() + " occurred when choosing the Gerber File.\n\nPlease see the log file."); return; } if ((filePathAndName == null) || (filePathAndName.Length == 0)) { // log this LogMessage("buttonOpenFileSLN_Click call to PickFile returned ((filePathAndName == null) || (filePathAndName.Length == 0))"); OISMessageBox("Error no file name returned when choosing the Gerber File.\n\nPlease see the log file."); return; } LogMessage("Preparing to open file: " + filePathAndName); // if we get here the pick was successful. Add the file to the MRU list MRUList.AddFileNameToTop(filePathAndName); // add the directory to our configuration settings so we return to // it automatically next time we start ImplicitUserSettings.LastOpenSLNFileDirectory = Path.GetDirectoryName(filePathAndName); ImplicitUserSettings.LastOpenSLNFileName = Path.GetFileName(filePathAndName); // build the File_SLN container and give it its name slnFile = new File_SLN(filePathAndName); // do we want to also emit a single output css file? bool alsoOutputCSSFile = false; if (StyleSheetType == StyleSheetTypeEnum.STYLESHEET_USERDEFINED) { alsoOutputCSSFile = false; } else { alsoOutputCSSFile = true; } // set the cursor, this can take some time tmpCursor = Cursor.Current; Cursor.Current = Cursors.WaitCursor; try { // open the file, note that our outputCSFile is mostly a container for the names. By the time this call // sucessfully returns, the CS file will have been converted to HTML and written to // the disk. retInt = ProcessSLNFile(slnFile, OutputDirectory, null, alsoOutputCSSFile, false, ref errStr); if (retInt != 0) { // log this LogMessage("buttonOpenFileSLN_Click call to ProcessSLNFile returned" + retInt.ToString()); // yes it did, was it reported? if (retInt < 0) { // no it was not, we always report it OISMessageBox("Error " + retInt.ToString() + " occurred opening the File.\n\nPlease see the log file."); } return; } } catch (NotImplementedException ex) { // we found something we could not cope with OISMessageBox("Sorry, this file cannot be opened because some of its contents are not yet supported. Error message was:\n\n" + ex.Message); return; } finally { // restore the cursor back to what it was Cursor.Current = tmpCursor; } // we are done, ask if the user wants to view the output file DialogResult dlgRes = OISMessageBox_YesNo("The SLN file and all of its contained files was converted successfully.\n\nWould you like to view the output?"); if (dlgRes == DialogResult.Yes) { LaunchHTMLFile(slnFile.HTMLFilePathAndName); } } /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Handles a press on the Set Output Directory button /// </summary> /// <history> /// 03 Jan 11 Cynic - Started /// </history> private void buttonSetOutputDirectory_Click(object sender, EventArgs e) { // get the output directory string outDir; // set the initial directory to the last value and call the function to // set the directory bool retBool = GetDirectoryByPrompt(OutputDirectory, "Set Output Directory", true, out outDir); if (retBool == false) return; if ((outDir == null) || (outDir.Length == 0)) return; textBoxOutputDirectory.Text = outDir; } /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// The form closing handler /// </summary> /// <history> /// 03 Jan 11 Cynic - Started /// </history> private void frmMain_FormClosing(object sender, FormClosingEventArgs e) { LogMessage("frmMain_FormClosing called"); // put the non user specified configuration settings in place now MoveImplicitUserSettingsFromScreenToObject(); // we always save implicit settings on close, unless the Shift key is pressed if ((Control.ModifierKeys & Keys.Shift) == 0) { LogMessage("frmMain_FormClosing close ImplicitUserSettings.Save called"); ImplicitUserSettings.Save(); } if (DoWeNeedToSaveConfigurationFile() == true) { DialogResult dlgRes = OISMessageBox_YesNo("The configuration options have changed.\n\nWould you like to save them?"); if (dlgRes == DialogResult.Yes) { LogMessage("frmMain_FormClosing saving configuration"); // get the data from the screen into the current application settings file ApplicationExplicitSettings appSettings = ConfigurationFile; MoveConfigurationFileFromScreenToObject(ref appSettings); // flag that the settings need to be saved in case the save is cancelled ConfigurationFile.SettingsNeedToBeSaved = false; WriteConfigurationFile(ConfigurationFileNameAndPath, ConfigurationFile, false); } } } /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Radio Button Change handler /// </summary> /// <history> /// 03 Jan 11 Cynic - Started /// </history> private void radioButtonStyleSheetInline_CheckedChanged(object sender, EventArgs e) { SyncStyleSheetNameTextBoxToStyleSheetOptionState(); } /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Radio Button Change handler /// </summary> /// <history> /// 03 Jan 11 Cynic - Started /// </history> private void radioButtonStyleSheetExternal_CheckedChanged(object sender, EventArgs e) { SyncStyleSheetNameTextBoxToStyleSheetOptionState(); } /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Radio Button Change handler /// </summary> /// <history> /// 03 Jan 11 Cynic - Started /// </history> private void radioButtonStyleSheetNone_CheckedChanged(object sender, EventArgs e) { SyncStyleSheetNameTextBoxToStyleSheetOptionState(); } /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Change handler /// </summary> /// <history> /// 20 May 11 Cynic - Started /// </history> private void checkBoxProjUseCSBanner_CheckedChanged(object sender, EventArgs e) { SyncProjTextBoxesToCheckState(); } /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Change handler /// </summary> /// <history> /// 20 May 11 Cynic - Started /// </history> private void checkBoxProjUseCSFooter_CheckedChanged(object sender, EventArgs e) { SyncProjTextBoxesToCheckState(); } /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Change handler /// </summary> /// <history> /// 20 May 11 Cynic - Started /// </history> private void checkBoxProjUseCSTitle_CheckedChanged(object sender, EventArgs e) { SyncProjTextBoxesToCheckState(); } /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Change handler /// </summary> /// <history> /// 20 May 11 Cynic - Started /// </history> private void checkBoxProjUseCSDesc_CheckedChanged(object sender, EventArgs e) { SyncProjTextBoxesToCheckState(); } /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Change handler /// </summary> /// <history> /// 23 May 11 Cynic - Started /// </history> private void checkBoxSLNUseCSBanner_CheckedChanged(object sender, EventArgs e) { SyncSLNTextBoxesToCheckState(); } /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Change handler /// </summary> /// <history> /// 23 May 11 Cynic - Started /// </history> private void checkBoxSLNUseCSFooter_CheckedChanged(object sender, EventArgs e) { SyncSLNTextBoxesToCheckState(); } /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Change handler /// </summary> /// <history> /// 23 May 11 Cynic - Started /// </history> private void checkBoxSLNUseCSTitle_CheckedChanged(object sender, EventArgs e) { SyncSLNTextBoxesToCheckState(); } /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Change handler /// </summary> /// <history> /// 23 May 11 Cynic - Started /// </history> private void checkBoxSLNUseCSDesc_CheckedChanged(object sender, EventArgs e) { SyncSLNTextBoxesToCheckState(); } /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Change handler /// </summary> /// <history> /// 23 May 11 Cynic - Started /// </history> private void radioButtonStyleSheetDefault_CheckedChanged(object sender, EventArgs e) { SyncStyleSheetNameTextBoxToStyleSheetOptionState(); } /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Change handler /// </summary> /// <history> /// 23 May 11 Cynic - Started /// </history> private void radioButtonStyleSheetCustom_CheckedChanged(object sender, EventArgs e) { SyncStyleSheetNameTextBoxToStyleSheetOptionState(); } /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// button handler /// </summary> /// <history> /// 20 May 11 Cynic - Started /// </history> private void buttonResetCSBanner_Click(object sender, EventArgs e) { LogMessage("buttonResetCSBanner_Click called"); DialogResult dlgRes = OISMessageBox_YesNo("Do you really want to reset the banner text to its default value? This will remove any changes you have made."); if (dlgRes != DialogResult.Yes) return; // pick the default settings out of an ApplicationExplicitSettings object ApplicationExplicitSettings exSettings = new ApplicationExplicitSettings(); exSettings.ResetToDefaults(); richTextBoxCSBannerContent.Text = exSettings.BannerCSCode; } /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// button handler /// </summary> /// <history> /// 20 May 11 Cynic - Started /// </history> private void buttonResetCSFooter_Click(object sender, EventArgs e) { LogMessage("buttonResetCSFooter_Click called"); DialogResult dlgRes = OISMessageBox_YesNo("Do you really want to reset the footer text to its default value? This will remove any changes you have made."); if (dlgRes != DialogResult.Yes) return; // pick the default settings out of an ApplicationExplicitSettings object ApplicationExplicitSettings exSettings = new ApplicationExplicitSettings(); exSettings.ResetToDefaults(); richTextBoxCSFooterContent.Text = exSettings.FooterCSCode; } /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// button handler /// </summary> /// <history> /// 20 May 11 Cynic - Started /// </history> private void buttonResetCSTitle_Click(object sender, EventArgs e) { LogMessage("buttonResetCSTitle_Click called"); DialogResult dlgRes = OISMessageBox_YesNo("Do you really want to reset the title text to its default value? This will remove any changes you have made."); if (dlgRes != DialogResult.Yes) return; // pick the default settings out of an ApplicationExplicitSettings object ApplicationExplicitSettings exSettings = new ApplicationExplicitSettings(); exSettings.ResetToDefaults(); textBoxCSPageTitle.Text = exSettings.TitleCSCode; } /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// button handler /// </summary> /// <history> /// 20 May 11 Cynic - Started /// </history> private void buttonResetCSDesc_Click(object sender, EventArgs e) { LogMessage("buttonResetCSDesc_Click called"); DialogResult dlgRes = OISMessageBox_YesNo("Do you really want to reset the description text to its default value? This will remove any changes you have made."); if (dlgRes != DialogResult.Yes) return; // pick the default settings out of an ApplicationExplicitSettings object ApplicationExplicitSettings exSettings = new ApplicationExplicitSettings(); exSettings.ResetToDefaults(); textBoxCSPageDesc.Text = exSettings.DescriptionCSCode; } /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// button handler /// </summary> /// <history> /// 20 May 11 Cynic - Started /// </history> private void buttonResetCSProjBanner_Click(object sender, EventArgs e) { LogMessage("buttonResetCSProjBanner_Click called"); DialogResult dlgRes = OISMessageBox_YesNo("Do you really want to reset the banner text to its default value? This will remove any changes you have made."); if (dlgRes != DialogResult.Yes) return; // pick the default settings out of an ApplicationExplicitSettings object ApplicationExplicitSettings exSettings = new ApplicationExplicitSettings(); exSettings.ResetToDefaults(); richTextBoxCSProjBannerContent.Text = exSettings.BannerCSProjCode; } /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// button handler /// </summary> /// <history> /// 20 May 11 Cynic - Started /// </history> private void buttonResetCSProjFooter_Click(object sender, EventArgs e) { LogMessage("buttonResetCSProjFooter_Click called"); DialogResult dlgRes = OISMessageBox_YesNo("Do you really want to reset the footer text to its default value? This will remove any changes you have made."); if (dlgRes != DialogResult.Yes) return; // pick the default settings out of an ApplicationExplicitSettings object ApplicationExplicitSettings exSettings = new ApplicationExplicitSettings(); exSettings.ResetToDefaults(); richTextBoxCSProjFooterContent.Text = exSettings.FooterCSProjCode; } /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// button handler /// </summary> /// <history> /// 20 May 11 Cynic - Started /// </history> private void buttonResetCSProjTitle_Click(object sender, EventArgs e) { LogMessage("buttonResetCSProjTitle_Click called"); DialogResult dlgRes = OISMessageBox_YesNo("Do you really want to reset the title text to its default value? This will remove any changes you have made."); if (dlgRes != DialogResult.Yes) return; // pick the default settings out of an ApplicationExplicitSettings object ApplicationExplicitSettings exSettings = new ApplicationExplicitSettings(); exSettings.ResetToDefaults(); textBoxCSProjPageTitle.Text = exSettings.TitleCSProjCode; } /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// button handler /// </summary> /// <history> /// 20 May 11 Cynic - Started /// </history> private void buttonResetCSProjDesc_Click(object sender, EventArgs e) { LogMessage("buttonResetCSProjDesc_Click called"); DialogResult dlgRes = OISMessageBox_YesNo("Do you really want to reset the description text to its default value? This will remove any changes you have made."); if (dlgRes != DialogResult.Yes) return; // pick the default settings out of an ApplicationExplicitSettings object ApplicationExplicitSettings exSettings = new ApplicationExplicitSettings(); exSettings.ResetToDefaults(); textBoxCSProjPageDesc.Text = exSettings.DescriptionCSProjCode; } /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// button handler /// </summary> /// <history> /// 23 May 11 Cynic - Started /// </history> private void buttonResetSLNBanner_Click(object sender, EventArgs e) { LogMessage("buttonResetSLNBanner_Click called"); DialogResult dlgRes = OISMessageBox_YesNo("Do you really want to reset the banner text to its default value? This will remove any changes you have made."); if (dlgRes != DialogResult.Yes) return; // pick the default settings out of an ApplicationExplicitSettings object ApplicationExplicitSettings exSettings = new ApplicationExplicitSettings(); exSettings.ResetToDefaults(); richTextBoxSLNBannerContent.Text = exSettings.BannerSLNCode; } /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// button handler /// </summary> /// <history> /// 23 May 11 Cynic - Started /// </history> private void buttonResetSLNFooter_Click(object sender, EventArgs e) { LogMessage("buttonResetSLNFooter_Click called"); DialogResult dlgRes = OISMessageBox_YesNo("Do you really want to reset the footer text to its default value? This will remove any changes you have made."); if (dlgRes != DialogResult.Yes) return; // pick the default settings out of an ApplicationExplicitSettings object ApplicationExplicitSettings exSettings = new ApplicationExplicitSettings(); exSettings.ResetToDefaults(); richTextBoxSLNFooterContent.Text = exSettings.FooterSLNCode; } /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// button handler /// </summary> /// <history> /// 23 May 11 Cynic - Started /// </history> private void buttonResetSLNTitle_Click(object sender, EventArgs e) { LogMessage("buttonResetSLNTitle_Click called"); DialogResult dlgRes = OISMessageBox_YesNo("Do you really want to reset the title text to its default value? This will remove any changes you have made."); if (dlgRes != DialogResult.Yes) return; // pick the default settings out of an ApplicationExplicitSettings object ApplicationExplicitSettings exSettings = new ApplicationExplicitSettings(); exSettings.ResetToDefaults(); textBoxSLNPageTitle.Text = exSettings.TitleSLNCode; } /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// button handler /// </summary> /// <history> /// 23 May 11 Cynic - Started /// </history> private void buttonResetSLNDesc_Click(object sender, EventArgs e) { LogMessage("buttonResetSLNDesc_Click called"); DialogResult dlgRes = OISMessageBox_YesNo("Do you really want to reset the description text to its default value? This will remove any changes you have made."); if (dlgRes != DialogResult.Yes) return; // pick the default settings out of an ApplicationExplicitSettings object ApplicationExplicitSettings exSettings = new ApplicationExplicitSettings(); exSettings.ResetToDefaults(); textBoxSLNPageDesc.Text = exSettings.DescriptionSLNCode; } /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// button handler - open and read a configuration file /// </summary> /// <history> /// 22 May 11 Cynic - Started /// </history> private void buttonOpenConfiguration_Click(object sender, EventArgs e) { int retInt; string errStr=""; LogMessage("buttonOpenConfiguration_Click called"); // do we need to save first? if (DoWeNeedToSaveConfigurationFile() == true) { // yes we do, ask the user DialogResult dlgRes = OISMessageBox_YesNoCancel("The current configuration has not been saved.\n\nWould you like to save those settings now?"); if (dlgRes == DialogResult.Cancel) { LogMessage("buttonOpenConfiguration_Click user cancelled rather than save"); } else if (dlgRes == DialogResult.Yes) { // we do want to save the existing settings // get the data from the screen into the current application settings file ApplicationExplicitSettings appSettings = ConfigurationFile; MoveConfigurationFileFromScreenToObject(ref appSettings); // flag that the settings need to be saved in case the save is cancelled ConfigurationFile.SettingsNeedToBeSaved = true; retInt = SaveConfigurationAs(false, ref errStr); if (retInt < 0) { OISMessageBox("An error occurred saving the configuration file.\n\nPlease see the logs."); return; } else if (retInt == 0) { // the save was successful, note this now ConfigurationFile.SettingsNeedToBeSaved = false; } } } // now open a new configuration retInt = OpenConfigurationFile(false, ref errStr); if (retInt < 0) { OISMessageBox("An error occurred opening the configuration file.\n\nPlease see the logs."); } else if (retInt == 0) { // the save was successful, note this now ConfigurationFile.SettingsNeedToBeSaved = false; } } /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Button handler to save the configuration file /// </summary> /// <history> /// 23 May 11 Cynic - Started /// </history> private void buttonSaveConfiguration_Click(object sender, EventArgs e) { LogMessage("buttonSaveConfiguration_Click called"); // get the data from the screen into the current application settings file ApplicationExplicitSettings appSettings = ConfigurationFile; MoveConfigurationFileFromScreenToObject(ref appSettings); // flag that the settings need to be saved in case the save is cancelled ConfigurationFile.SettingsNeedToBeSaved = true; int retInt = WriteConfigurationFile(ConfigurationFileNameAndPath, ConfigurationFile, false); if (retInt < 0) { OISMessageBox("An error occurred saving the configuration file.\n\nPlease see the logs."); } else if (retInt == 0) { // the save was successful, note this now ConfigurationFile.SettingsNeedToBeSaved = false; } } /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Button handler to save the configuration file under a name /// </summary> /// <history> /// 23 May 11 Cynic - Started /// </history> private void buttonSaveConfigurationAs_Click(object sender, EventArgs e) { string errStr = ""; LogMessage("buttonSaveConfigurationAs_Click called"); // get the data from the screen into the current application settings file ApplicationExplicitSettings appSettings = ConfigurationFile; MoveConfigurationFileFromScreenToObject(ref appSettings); // flag that the settings need to be saved in case the save is cancelled ConfigurationFile.SettingsNeedToBeSaved = true; int retInt = SaveConfigurationAs(false, ref errStr); if (retInt < 0) { OISMessageBox("An error occurred saving the configuration file.\n\nPlease see the logs."); } else if (retInt == 0) { // the save was successful, note this now ConfigurationFile.SettingsNeedToBeSaved = false; } } /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Handles a press on the View Logfile button /// </summary> /// <history> /// 23 May 10 Cynic - Started /// </history> private void buttonViewLogfile_Click(object sender, EventArgs e) { LogMessage("buttonViewLogfile_Click called"); try { // launch the file System.Diagnostics.Process p = new System.Diagnostics.Process(); System.Diagnostics.ProcessStartInfo pi = new System.Diagnostics.ProcessStartInfo(); // these should never be null string dirName = g_Logger.LogFileDirectory; string fileName = g_Logger.LogFileName; if (Path.IsPathRooted(dirName) != true) { pi.FileName = Path.Combine(System.Windows.Forms.Application.StartupPath, dirName); pi.FileName = Path.Combine(pi.FileName, fileName); } else { pi.FileName = Path.Combine(dirName, fileName); } // we expect the quick start guide to be immediately below the exe directory p.StartInfo = pi; p.Start(); } catch (Exception ex) { OISMessageBox("Cannot view the log file an because of an error.\n\n" + ex.Message); return; } } /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Handles a press on the reset button /// </summary> /// <history> /// 23 May 10 Cynic - Started /// </history> private void buttonResetConfig_Click(object sender, EventArgs e) { LogMessage("buttonResetConfig_Click called"); DialogResult dlgRes = OISMessageBox_YesNo("Do you really want to set all of the configuration items back to the default state?\n\nThis will remove any changes you have made."); if (dlgRes == DialogResult.Yes) { ResetApplicationToDefaults(); ConfigurationFile.SettingsNeedToBeSaved = true; } } /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Handles a press on the help button /// </summary> /// <history> /// 23 May 11 Cynic - Started /// </history> private void buttonHelp_Click(object sender, EventArgs e) { #if DEBUG LogMessage(" buttonHelp_Click"); LaunchHelpFile(@"C:\Projects\CoDocker\", CODOCKER_MAINHELP_FILE); #else LogMessage(" buttonHelp_Click"); LaunchHelpFile(CODOCKER_HELPDIR, CODOCKER_MAINHELP_FILE); #endif } /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Handles a press on the close button /// </summary> /// <history> /// 23 May 11 Cynic - Started /// </history> private void buttonExit_Click(object sender, EventArgs e) { LogMessage("buttonExit_Click called"); // the form_closing handler performs all of the // necessary checks this.Close(); } #endregion } }