/// <summary> /// Initializes unhandledexception and controlc handlers /// </summary> private static ConverterNativeMethods.HandlerRoutine InitializeHandlers() { AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(OnUnhandledException); Console.CancelKeyPress += new ConsoleCancelEventHandler(OnCancelKeyPress); ConverterNativeMethods.HandlerRoutine handler = new ConverterNativeMethods.HandlerRoutine(ConsoleCtrlCheck); if (!ConverterNativeMethods.SetConsoleCtrlHandler(handler, true /*install handler*/)) { //If installation of handler fails Debug.Fail("SetConsoleCtrlHandler call failed"); //How to call GetLastError? int errorCode = ConverterNativeMethods.GetLastWin32Error(); Logger.Write(LogSource.Common, TraceLevel.Warning, "SetConsoleCtrlHandler call failed. Error code:: {0}", errorCode); } return(handler); }
public static void Main(String[] args) { ConverterNativeMethods.HandlerRoutine handlerRoutine = null; try { Display.InitDisplay(ConverterMain.GetErrorsCount); ThreadManager.AddThreadToManagerList(Thread.CurrentThread); handlerRoutine = InitializeHandlers(); Logger.WritePerf(LogSource.Common, "Beginning Converter"); Debug.Assert(!string.IsNullOrEmpty(CurrentConverterSourceName)); CommandLineParser.DisplayCopyRightMessage(); CommandLineParser.AddArgumentDetails(new ArgumentDetails[] { new ArgumentDetails("migrationsettings", "m", HandleConfig, true, false), //new ArgumentDetails("schemamap", "s", HandleSchemaMap, false, false), //new ArgumentDetails("command", "c", HandleMode, true, false), new ArgumentDetails("?", "?", DisplayHelp, false, true), new ArgumentDetails("help", "h", DisplayHelp, false, true), } ); if (!CommandLineParser.Parse(args) || !ValidateArgumentsDependency()) { return; } // Read the configuration schema from the resources XmlDocument xmldoc = UtilityMethods.ValidateXmlFile(convParams.ConfigFile, CommonConstants.WorkItemConfigXsdFile); bool exitOnError = false; string value = GetValueForNode(xmldoc, "ExitOnError"); if (value != null) { if (!Boolean.TryParse(value, out exitOnError)) { string errMsg = UtilityMethods.Format(CommonResource.InvalidBoolean, value, "ExitOnError", convParams.ConfigFile); throw new ConverterException(errMsg); } } EditSourceItemOption editSourceItem = EditSourceItemOption.NoChange; // default value = GetValueForNode(xmldoc, "EditSourceItem"); if (value != null) { editSourceItem = (EditSourceItemOption)Enum.Parse(typeof(EditSourceItemOption), value); } string outputDir = GetValueForNode(xmldoc, "OutputDirectory"); // Get the configuration for PS and make a connection XmlNodeList xmlNodes = xmldoc.GetElementsByTagName("Source"); XmlNode sourceNode = xmlNodes[0]; // Get the configuration for VSTS and make a connection XmlNodeList targetNode = xmldoc.GetElementsByTagName("VSTS"); //LADYBUG RELATED...... // Get the configuration for VSTS and make a connection XmlNodeList ladyBugProcessingNode = xmldoc.GetElementsByTagName("LadyBugProcessing"); XmlNodeList summaryMailNode = xmldoc.GetElementsByTagName("SendSummaryEmail"); // Get the handler class for this [work item] source XmlAttribute attr = sourceNode.Attributes["id"]; string productType = (string)SourceIdToTypeMaps[attr.Value]; Type handlerType = null; if (productType != null) { handlerType = Type.GetType(productType); } // If productType is null, handlerType will also be null. if (handlerType == null) { Logger.Write(LogSource.Common, TraceLevel.Error, "Product Id {0} not registered", attr.Value); throw new ConverterException( UtilityMethods.Format(CurConResource.InvalidSourceId, attr.Value, convParams.ConfigFile)); } // Create the converter/handler for this data source converter = (IWorkItemConverter)Activator.CreateInstance(handlerType); convParams.SourceConfig = sourceNode; convParams.TargetConfig = targetNode[0]; convParams.ExitOnError = exitOnError; convParams.OutputDirectory = outputDir; #region before calling initialize, first initialize the report MigrationReport = new Report(CommonConstants.CQPreMigrationReportName); MigrationReport.UserInput.Options = new string[2]; MigrationReport.UserInput.Options[0] = CurConResource.AnalyzeCommand; MigrationReport.UserInput.Options[1] = UtilityMethods.Format(CurConResource.ConfigFile, convParams.ConfigFile); #endregion ReportConverter convType = CurrentConverter == ConverterType.CQ? ReportConverter.CQConverter : ReportConverter.PSConverter; MigrationReport.StartReporting(convType); // now the reporting is initialized.. put command line options StringBuilder cmdArgs = new StringBuilder(CurrentAssembly.GetName().Name + ".exe "); foreach (string arg in args) { cmdArgs.Append(arg); cmdArgs.Append(" "); } MigrationReport.UserInput.CommandLine = cmdArgs.ToString(); // Begin the conversion operation // Initialize the converter handler object converter.Initialize(convParams); converter.Convert(); } catch (ConverterException cEx) { HandleTopException(cEx); } catch (InvalidOperationException cEx) { HandleTopException(cEx); } catch (SerializationException cEx) { HandleTopException(cEx); } catch (ThreadInterruptedException cEx) { HandleTopException(cEx); } catch (COMException cEx) { HandleTopException(cEx); } catch (SoapException cEx) { HandleTopException(cEx); } catch (ApplicationException ex) { // add in the migration report HandleTopException(ex); } catch (ThreadAbortException) { Thread.ResetAbort(); } finally { EndConverter(); } }