public frmOptions() { InitializeComponent(); cOptions = new CollectionOptions(); txtZipPath.Text = cOptions.ZipFolderPath; }
public string CollectFiles(CollectionOptions cOptions) { Logging.RsiLog("WindowsServer.CollectFiles"); try { //Set up the log folder and make sure it exists string logFileCollectionPath = Path.GetTempPath() + "Revit_Server_Diagnostics_" + Name; Logging.RsiLog("logFileCollectionPath: " + logFileCollectionPath); string zipFilePath = cOptions.ZipFolderPath + "\\Revit_Server_Diagnostics_" + Name + ".zip"; Logging.RsiLog("zipFilePath: " + zipFilePath); if (cOptions.AnyOption()) { if (Directory.Exists(logFileCollectionPath)) { Directory.Delete(logFileCollectionPath, true); } Directory.CreateDirectory(logFileCollectionPath); Logging.RsiLog("Creating: " + logFileCollectionPath); } // collect the files try { if (cOptions.ServerInfo) { Logging.RsiLog("Collecting RS info..."); CollectServerInfo(logFileCollectionPath); } if (cOptions.RSLogs) { Logging.RsiLog("Collecting RS Server logs..."); CollectLogs(logFileCollectionPath, cOptions.Version); } if (cOptions.RsnIni) { Logging.RsiLog("Collecting RSN.ini files..."); CollectRsnIni(logFileCollectionPath, cOptions.Version); } if (cOptions.EventLogs) { Logging.RsiLog("Collecting Windows event logs..."); CollectEventLogs(logFileCollectionPath); } if (cOptions.MsInfo) { Logging.RsiLog("Collecting Windows System Information..."); CollectMsInfo(logFileCollectionPath); } if (cOptions.WebConfig) { Logging.RsiLog("Collecting ApplicationHost.config and web.config files..."); CollectAppHostConfig(logFileCollectionPath); CollectWebConfig(logFileCollectionPath, cOptions.Version); } } catch (Exception ex) { Logging.RsiLog(ex.Message + "\r\n" + ex.StackTrace); throw new Exception("Unable to collect some information. Check the " + logFileCollectionPath + " folder for unzipped files and delete them.", ex); } if (cOptions.AnyOption()) { // Zip the files together Console.WriteLine("Zip File Location: " + zipFilePath); try { Logging.RsiLog("Zipping files to " + zipFilePath); if (File.Exists(zipFilePath)) { Logging.RsiLog("Deleting previous zip file: " + zipFilePath); File.Delete(zipFilePath); } ZipFile.CreateFromDirectory(logFileCollectionPath, zipFilePath); Logging.RsiLog("Files zipped."); } catch (Exception ex) { Logging.RsiLog(ex.Message); throw new Exception("Unable to zip the files. Check the " + logFileCollectionPath + " folder for unzipped files.", ex); } // Delete the temp folder try { Logging.RsiLog("Deleting unzipped files."); Directory.Delete(logFileCollectionPath, true); } catch (Exception ex) { Logging.RsiLog(ex.Message); throw new Exception("Unable to delete the files after zipping them. Check the " + logFileCollectionPath + " folder for unzipped files and delete them.", ex); } } return zipFilePath; } catch (Exception ex) { Logging.RsiLog(ex.Message); throw new Exception("Unable to complete the collection of all information. Check the inner exception message for more information.", ex); } }
static void Main(string[] args) { try { // options for information to collect CollectionOptions cOptions = new CollectionOptions(); // if the user doesn't provide options, then don't run collection bool startCollection = false; //start logging; Logging.RsiLog("Starting log..."); Logging.RsiLog("Number of Command Line Arguments: " + args.Length); int count = 0; foreach (string arg in args) { count++; Logging.RsiLog("Argument " + count + ": " + arg); } //set some defaults, get everything if no arguments are provided. if (args.Length != 0) { cOptions.SetAllOptions(false); startCollection = true; foreach (string arg in args) { if (arg.ToUpper().Contains("/S")) { cOptions.ServerInfo = true; } if (arg.ToUpper().Contains("/R")) { cOptions.RsnIni = true; } if (arg.ToUpper().Contains("/L")) { cOptions.RSLogs = true; } if (arg.ToUpper().Contains("/E")) { cOptions.EventLogs = true; } if (arg.ToUpper().Contains("/P")) { cOptions.ZipFolderPath = arg.Substring(3); } if (arg.ToUpper().Contains("/V")) { cOptions.Version = arg.Substring(3); } if (arg.ToUpper().Contains("/W")) { cOptions.WebConfig = true; } if (arg.ToUpper().Contains("/M")) { cOptions.MsInfo = true; } if (arg.ToUpper().Contains("/?")) { frmHelp h = new frmHelp(); h.ShowDialog(); //global::System.Windows.Forms.MessageBox.Show("Command Line Parameters:\r\n" + // "/S : Gets basic server configuration information and writes that to a text file.\r\n" + // "/R : Collects RSN.ini files.\r\n" + // "/L : Collects all Revit Server Log files.\r\n" + // "/E : Collects the Windows System and Application Event Logs.\r\n" + // "/W : Collects the web.config file and IIS Application Host Configuration file.\r\n" + // "/M : Collects information from msinfo.exe in a .nfo file.\r\n" + // "/P : Path to place the contents of the zip file containing the collected files.\r\n" + // " The zip file will be placed on your Desktop if this is not specified.\r\n" + // @" Usage: 'RevitServerInfo.exe /P:C:\Temp' Enclose paths with spaces in double-quotes.\r\n" + // "/V : The Revit Server version you want information for. All versions will be collected by default.\r\n" + // " Usage: 'RevitServerInfo.exe /V:2016'"); startCollection = false; } } } else //no arguments provided, show a dialog... { frmOptions options = new frmOptions(); if (options.ShowDialog() == System.Windows.Forms.DialogResult.OK) { cOptions = options.GetOptions(); startCollection = true; } } if (startCollection) { Logging.RsiLog(cOptions.ToString()); //BackgroundWorker bw = new BackgroundWorker(); //bw.WorkerReportsProgress = true; //bw.WorkerSupportsCancellation = true; //frmProgress pr = new frmProgress(); //pr.Canceled += new EventHandler<EventArgs>(pr.btnCancel_Click); RS.Models.WindowsServer ws = new RS.Models.WindowsServer(); ws.CollectFiles(cOptions); Logging.RsiLog("Finishing log.\r\n\r\n"); } else { Logging.RsiLog("No options provided via command line or options dialog. Exiting.\r\n\r\n"); } } catch (Exception ex) { Logging.RsiLog(ex.Message + "\r\n" + ex.StackTrace + "\r\n\r\n"); } }