private static void Run(string[] args) { var argsDictionary = CommandLineArgumentsHelper.GetArgumentsDictionary(args); // Invoke the engine with arguments GetEngineInvoker(argsDictionary).Invoke(argsDictionary); }
// In UWP(App models) Run will act as entry point from Application end, so making this method public public static void Run(string[] args) { WaitForDebuggerIfEnabled(); var argsDictionary = CommandLineArgumentsHelper.GetArgumentsDictionary(args); // Invoke the engine with arguments GetEngineInvoker(argsDictionary).Invoke(argsDictionary); }
public void GetArgumentsDictionaryShouldReturnEmptyDictionaryIfEmptyArgIsPassed() { var argsDictionary = CommandLineArgumentsHelper.GetArgumentsDictionary(null); Assert.IsTrue(argsDictionary.Count == 0); argsDictionary = CommandLineArgumentsHelper.GetArgumentsDictionary(new string[] { }); Assert.IsTrue(argsDictionary.Count == 0); }
// In UWP(App models) Run will act as entry point from Application end, so making this method public public static void Run(string[] args) { DebuggerBreakpoint.WaitForNativeDebugger("VSTEST_HOST_NATIVE_DEBUG"); DebuggerBreakpoint.WaitForDebugger("VSTEST_HOST_DEBUG"); UILanguageOverride.SetCultureSpecifiedByUser(); var argsDictionary = CommandLineArgumentsHelper.GetArgumentsDictionary(args); // Invoke the engine with arguments GetEngineInvoker(argsDictionary).Invoke(argsDictionary); }
public void GetArgumentsDictionaryShouldReturnDictionary() { var args = new List <string>() { "--port", "12312", "--parentprocessid", "2312", "--testsourcepath", @"C:\temp\1.dll" }; var argsDictionary = CommandLineArgumentsHelper.GetArgumentsDictionary(args.ToArray()); Assert.AreEqual("12312", argsDictionary["--port"]); Assert.AreEqual("2312", argsDictionary["--parentprocessid"]); Assert.AreEqual(@"C:\temp\1.dll", argsDictionary["--testsourcepath"]); }
public void GetArgumentsDictionaryShouldTreatValueAsNullIfTwoConsecutiveKeysArePassed() { var args = new List <string>() { "--hello", "--world" }; var argsDictionary = CommandLineArgumentsHelper.GetArgumentsDictionary(args.ToArray()); Assert.IsTrue(argsDictionary.Count == 2); Assert.AreEqual(null, argsDictionary["--hello"]); Assert.AreEqual(null, argsDictionary["--world"]); }
public void TryGetIntArgFromDictShouldReturnFalseIfKeyIsNotPresent() { var args = new List <string>() { "--hello", "--world" }; var argsDictionary = CommandLineArgumentsHelper.GetArgumentsDictionary(args.ToArray()); bool found = CommandLineArgumentsHelper.TryGetIntArgFromDict(argsDictionary, "--port", out var data); Assert.IsFalse(found); }
public void GetIntArgFromDictShouldReturnTheValueIfKeyIsPresent() { var args = new List <string>() { "--port", "1000" }; var argsDictionary = CommandLineArgumentsHelper.GetArgumentsDictionary(args.ToArray()); int data = CommandLineArgumentsHelper.GetIntArgFromDict(argsDictionary, "--port"); Assert.AreEqual(1000, data); }
public void GetStringArgFromDictShouldReturnStringValueOrEmpty() { var args = new List <string>() { "--port", "12312", "--parentprocessid", "2312", "--testsourcepath", @"C:\temp\1.dll" }; var argsDictionary = CommandLineArgumentsHelper.GetArgumentsDictionary(args.ToArray()); string data = CommandLineArgumentsHelper.GetStringArgFromDict(argsDictionary, "--port"); Assert.AreEqual("12312", data); }
public void GetIntArgFromDictShouldReturnZeroIfKeyIsNotPresent() { var args = new List <string>() { "--hello", "--world" }; var argsDictionary = CommandLineArgumentsHelper.GetArgumentsDictionary(args.ToArray()); int data = CommandLineArgumentsHelper.GetIntArgFromDict(argsDictionary, "--port"); Assert.AreEqual(0, data); }
public void Run(string[] args) { WaitForDebuggerIfEnabled(); var argsDictionary = CommandLineArgumentsHelper.GetArgumentsDictionary(args); // Setup logging if enabled string logFile; if (argsDictionary.TryGetValue(LogFileArgument, out logFile)) { EqtTrace.InitializeVerboseTrace(logFile); } else { EqtTrace.DoNotInitailize = true; } EqtTrace.Info("DataCollectorMain.Run: Starting data collector run with args: {0}", string.Join(",", args)); // Attach to exit of parent process var parentProcessId = CommandLineArgumentsHelper.GetIntArgFromDict(argsDictionary, ParentProcessArgument); EqtTrace.Info("DataCollector: Monitoring parent process with id: '{0}'", parentProcessId); this.processHelper.SetExitCallback( parentProcessId, (obj) => { EqtTrace.Info("DataCollector: ParentProcess '{0}' Exited.", parentProcessId); this.environment.Exit(1); }); // Get server port and initialize communication. string portValue; int port = argsDictionary.TryGetValue(PortArgument, out portValue) ? int.Parse(portValue) : 0; if (port <= 0) { throw new ArgumentException("Incorrect/No Port number"); } this.requestHandler.InitializeCommunication(port); // Can only do this after InitializeCommunication because datacollector cannot "Send Log" unless communications are initialized if (!string.IsNullOrEmpty(EqtTrace.LogFile)) { ((DataCollectionRequestHandler)this.requestHandler).SendDataCollectionMessage(new DataCollectionMessageEventArgs(TestMessageLevel.Informational, string.Format("Logging DataCollector Diagnostics in file: {0}", EqtTrace.LogFile))); } // Start processing async in a different task EqtTrace.Info("DataCollector: Start Request Processing."); StartProcessing(); }
private static void Run(string[] args) { var argsDictionary = CommandLineArgumentsHelper.GetArgumentsDictionary(args); // Setup logging if enabled string logFile; if (argsDictionary.TryGetValue(LogFileArgument, out logFile)) { EqtTrace.InitializeVerboseTrace(logFile); } // Attach to exit of parent process var parentProcessId = CommandLineArgumentsHelper.GetIntArgFromDict(argsDictionary, ParentProcessArgument); EqtTrace.Info("DataCollector: Monitoring parent process with id: '{0}'", parentProcessId); var processHelper = new ProcessHelper(); processHelper.SetExitCallback( parentProcessId, (obj) => { EqtTrace.Info("DataCollector: ParentProcess '{0}' Exited.", parentProcessId); Environment.Exit(1); }); // Get server port and initialize communication. string portValue; int port = argsDictionary.TryGetValue(PortArgument, out portValue) ? int.Parse(portValue) : 0; if (port <= 0) { throw new ArgumentException("Incorrect/No Port number"); } var requestHandler = DataCollectionRequestHandler.Create(new SocketCommunicationManager(), new MessageSink()); requestHandler.InitializeCommunication(port); // Can only do this after InitializeCommunication because datacollector cannot "Send Log" unless communications are initialized if (!string.IsNullOrEmpty(EqtTrace.LogFile)) { requestHandler.SendDataCollectionMessage(new DataCollectionMessageEventArgs(TestMessageLevel.Informational, string.Format("Logging DataCollector Diagnostics in file: {0}", EqtTrace.LogFile))); } // Start processing async in a different task EqtTrace.Info("DataCollector: Start Request Processing."); var processingTask = StartProcessingAsync(requestHandler); // Wait for processing to complete. Task.WaitAny(processingTask); }
public void TryGetIntArgFromDictShouldReturnTrueIfKeyIsPresentAndTheValue() { var args = new List <string>() { "--port", "59870" }; var argsDictionary = CommandLineArgumentsHelper.GetArgumentsDictionary(args.ToArray()); bool found = CommandLineArgumentsHelper.TryGetIntArgFromDict(argsDictionary, "--port", out var data); Assert.IsTrue(found); Assert.AreEqual(59870, data); }
public void GetStringArgFromDictShouldReturnNullIfValueIsNotPresent() { var args = new List <string>() { "--hello", "--world" }; var argsDictionary = CommandLineArgumentsHelper.GetArgumentsDictionary(args.ToArray()); string data = CommandLineArgumentsHelper.GetStringArgFromDict(argsDictionary, "--hello"); Assert.IsTrue(argsDictionary.Count == 2); Assert.IsNull(data); }
public void GetStringArgFromDictShouldReturnEmptyStringIfKeyIsNotPresent() { var args = new List <string>() { "--hello", "--world" }; var argsDictionary = CommandLineArgumentsHelper.GetArgumentsDictionary(args.ToArray()); string data = CommandLineArgumentsHelper.GetStringArgFromDict(argsDictionary, "--port"); Assert.IsTrue(argsDictionary.Count == 2); Assert.AreEqual(string.Empty, data); }
private static void Run(string[] args) { var argsDictionary = CommandLineArgumentsHelper.GetArgumentsDictionary(args); var requestHandler = DataCollectionRequestHandler.Create(new SocketCommunicationManager(), new MessageSink()); // Setup logging if enabled string logFile; if (argsDictionary.TryGetValue(LogFileArgument, out logFile)) { EqtTrace.InitializeVerboseTrace(logFile); } // Get server port and initialize communication. string portValue; int port = argsDictionary.TryGetValue(PortArgument, out portValue) ? int.Parse(portValue) : 0; if (port <= 0) { throw new ArgumentException("Incorrect/No Port number"); } requestHandler.InitializeCommunication(port); // Can only do this after InitializeCommunication because datacollector cannot "Send Log" unless communications are initialized if (!string.IsNullOrEmpty(EqtTrace.LogFile)) { requestHandler.SendDataCollectionMessage(new DataCollectionMessageEventArgs(TestMessageLevel.Informational, string.Format("Logging DataCollector Diagnostics in file: {0}", EqtTrace.LogFile))); } // Wait for the connection to the sender and start processing requests from sender if (requestHandler.WaitForRequestSenderConnection(ClientListenTimeOut)) { requestHandler.ProcessRequests(); } else { EqtTrace.Info("DataCollector: RequestHandler timed out while connecting to the Sender."); requestHandler.Close(); throw new TimeoutException(); } }
public void GetArgumentsDictionaryShouldIgnoreValuesWithoutPreceedingHypen() { var args = new List <string>() { "port", "12312", "--parentprocessid", "2312", "--testsourcepath", @"C:\temp\1.dll" }; var argsDictionary = CommandLineArgumentsHelper.GetArgumentsDictionary(args.ToArray()); Assert.IsTrue(argsDictionary.Count == 2); Assert.AreEqual("2312", argsDictionary["--parentprocessid"]); Assert.AreEqual(@"C:\temp\1.dll", argsDictionary["--testsourcepath"]); args = new List <string>() { "--port", "12312", "--parentprocessid", "2312", "testsourcepath", @"C:\temp\1.dll" }; argsDictionary = CommandLineArgumentsHelper.GetArgumentsDictionary(args.ToArray()); Assert.IsTrue(argsDictionary.Count == 2); Assert.AreEqual("12312", argsDictionary["--port"]); Assert.AreEqual("2312", argsDictionary["--parentprocessid"]); }
public void Run(string[] args) { WaitForDebuggerIfEnabled(); var argsDictionary = CommandLineArgumentsHelper.GetArgumentsDictionary(args); // Setup logging if enabled string logFile; if (argsDictionary.TryGetValue(LogFileArgument, out logFile)) { var traceLevelInt = CommandLineArgumentsHelper.GetIntArgFromDict(argsDictionary, TraceLevelArgument); var isTraceLevelArgValid = Enum.IsDefined(typeof(PlatformTraceLevel), traceLevelInt); // In case traceLevelInt is not defined in PlatfromTraceLevel, default it to verbose. var traceLevel = isTraceLevelArgValid ? (PlatformTraceLevel)traceLevelInt : PlatformTraceLevel.Verbose; // Initialize trace. EqtTrace.InitializeTrace(logFile, traceLevel); // Log warning in case tracelevel passed in arg is invalid if (!isTraceLevelArgValid) { EqtTrace.Warning("DataCollectorMain.Run: Invalid trace level: {0}, defaulting to verbose tracelevel.", traceLevelInt); } } else { EqtTrace.DoNotInitailize = true; } if (EqtTrace.IsVerboseEnabled) { var version = typeof(DataCollectorMain) .GetTypeInfo() .Assembly .GetCustomAttribute <AssemblyInformationalVersionAttribute>()?.InformationalVersion; EqtTrace.Verbose($"Version: { version }"); } SetCultureSpecifiedByUser(); EqtTrace.Info("DataCollectorMain.Run: Starting data collector run with args: {0}", string.Join(",", args)); // Attach to exit of parent process var parentProcessId = CommandLineArgumentsHelper.GetIntArgFromDict(argsDictionary, ParentProcessArgument); EqtTrace.Info("DataCollector: Monitoring parent process with id: '{0}'", parentProcessId); this.processHelper.SetExitCallback( parentProcessId, (obj) => { EqtTrace.Info("DataCollector: ParentProcess '{0}' Exited.", parentProcessId); this.environment.Exit(1); }); // Get server port and initialize communication. string portValue; int port = argsDictionary.TryGetValue(PortArgument, out portValue) ? int.Parse(portValue) : 0; if (port <= 0) { throw new ArgumentException("Incorrect/No Port number"); } this.requestHandler.InitializeCommunication(port); // Can only do this after InitializeCommunication because datacollector cannot "Send Log" unless communications are initialized if (!string.IsNullOrEmpty(EqtTrace.LogFile)) { (this.requestHandler as DataCollectionRequestHandler)?.SendDataCollectionMessage(new DataCollectionMessageEventArgs(TestMessageLevel.Informational, string.Format("Logging DataCollector Diagnostics in file: {0}", EqtTrace.LogFile))); } // Start processing async in a different task EqtTrace.Info("DataCollector: Start Request Processing."); StartProcessing(); }