public void ApplicationProcessFailThresholdInvalid() { using (ApplicationProcess process = new ApplicationProcess(Logger, @"C:\Path")) { process.Threshold = 0; } }
public void StartGameServer() { if (!IsGameServerInstalled()) // If our Game Server directory does not exist with the srcds executable in { try { Update(); } catch { this.State = ApplicationState.Failed; return; } } this.State = ApplicationState.PreStart; IssueUpdateEvent = true; if (!IsGameServerInstalled()) { this.State = ApplicationState.Failed; module.log.Warning("Rust is not installed!"); return; } SetupProcess(); ApplicationProcess.Start(); SetupRCON(); this.State = ApplicationState.Starting; }
public override bool Parse(XmlNode profileBodyNode) { bool result = true; foreach (XmlNode childNode in profileBodyNode.ChildNodes) { if (childNode.Name == "ApplicationProcess") { if (!ApplicationProcess.Parse(childNode)) { result = false; break; } } else if (childNode.Name == "DeviceManager") { if (!DeviceManager.Parse(childNode)) { result = false; break; } } } DeviceManager.ResolveParameterReferences(ApplicationProcess.ParameterList); return(result); }
public void ApplicationProcessStopForce() { string path = ApplicationUtils.CreateValidExampleApplication(); ManualResetEvent handle = new ManualResetEvent(false); try { using (ApplicationProcess process = new ApplicationProcess(Logger, path, Path.GetFullPath("Collar.exe"))) { process.Exited += (object sender, EventArgs e) => { Assert.Fail(); handle.Set(); }; process.KillTimeout += (object sender, EventArgs e) => { Assert.Fail(); handle.Set(); }; Assert.IsTrue(process.Start()); process.Stop(true); WaitHandle.WaitAll(new WaitHandle[] { handle }, 11000); } } finally { handle.Close(); } }
public void ApplicationProcessBasePath() { using (ApplicationProcess process = new ApplicationProcess(Logger, @"C:\Path")) { Assert.AreEqual(Path.GetFullPath(Path.GetDirectoryName(GetType().Assembly.Location)), process.BasePath); } }
public void ApplicationProcessFailConfigPathInvalid() { using (ApplicationProcess process = new ApplicationProcess(Logger, @"C:\Path")) { process.ConfigPath = @"C:\Path\Invalid>"; } }
public void ApplicationProcessFailFrameworkVersionInvalid() { using (ApplicationProcess process = new ApplicationProcess(Logger, @"C:\Path")) { process.FrameworkVersion = "1.0"; } }
public void Kill() { if (this.State != ApplicationState.Stopped) { ApplicationProcess.Kill(); } }
protected void Update() { if (closeCurrentProcess) { closeCurrentProcess = false; ApplicationProcess.CloseLastOpenProcess(); } }
public string GetExternalDrives(ApplicationProcess process, string args) { string systemDrive = Path.GetPathRoot(Environment.GetFolderPath(Environment.SpecialFolder.System)); string[] drives = Array.FindAll(Directory.GetLogicalDrives(), c => c != systemDrive); return(Response(drives)); }
public void ApplicationProcessStart() { string path = ApplicationUtils.CreateValidExampleApplication(); using (ApplicationProcess process = new ApplicationProcess(Logger, path, Path.GetFullPath("Collar.exe"))) { Assert.IsTrue(process.Start()); } }
public string StartApplication(ApplicationProcess invoker, string appName) { if (invoker.Domain != appName) { RunOnUIThread(invoker, () => { Launcher.GetInstance().StartApplication(appName); }); } return(null); }
/// <summary> /// Start main application process if not already started. /// </summary> protected void StartApplicationProcess() { GRoggle.Write("Try starting Aida process", RoggleLogLevel.Debug); if (ApplicationProcess != null && ApplicationFile.Exists) { ApplicationProcess.Start(); GRoggle.Write("Aida process started successfuly", RoggleLogLevel.Debug); } else { GRoggle.Write("There is no Aida process to start", RoggleLogLevel.Debug); } }
/// <summary> /// Execute request /// </summary> /// <param name="process">Application process</param> /// <param name="controllerName">Controller name</param> /// <param name="actionName">Action name</param> /// <param name="data">JSON data</param> /// <returns></returns> public string InvokeRequest(ApplicationProcess process, string controllerName, string actionName, string data) { if (!Controllers.ContainsKey(controllerName)) { throw new ArgumentOutOfRangeException($"Requested request handler not found: {controllerName}"); } RequestController ctrl = Controllers[controllerName]; if (!ctrl.HasAction(actionName)) { throw new ArgumentOutOfRangeException($"Requested action '{actionName}' not available in {controllerName}"); } ActionHandler handler = ctrl.GetActionHandler(actionName); return(handler(process, data)); }
public static void ProvideDependencies(string[] dependencies, ApplicationProcess proc) { if (dependencies == null) { return; } List <Injectable> items = new List <Injectable>(); foreach (string dependency in dependencies) { if (!Injectables.ContainsKey(dependency)) { throw new RuntimeException($"Application requested undefined dependency: {dependency}"); } Type type = Injectables[dependency]; items.Add((Injectable)Activator.CreateInstance(type)); } proc.Host.DefineDependencies(items.ToArray()); }
public string GetUserDirectory(ApplicationProcess process, string args) { return(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)); }
public void ApplicationProcessFailPathInvalid() { using (ApplicationProcess process = new ApplicationProcess(Logger, @"C:\Invalid\Path>")) { } }
public void ApplicationProcessFailPathEmpty() { using (ApplicationProcess process = new ApplicationProcess(Logger, null)) { } }
/// <summary> /// Executes the command. /// </summary> /// <param name="environment">The <see cref="CommandEnvironment"/> to use in executing the command.</param> /// <param name="parameters">The <see cref="Dictionary{string, object}"/> containing the command parameters.</param> /// <returns>The JSON serialized string representing the command response.</returns> public override Response Execute(CommandEnvironment environment, Dictionary <string, object> parameters) { Dictionary <string, object> responseValue = new Dictionary <string, object>(); responseValue["browserName"] = "WinFormsApp"; responseValue["cssSelectorsEnabled"] = false; responseValue["javascriptEnabled"] = false; responseValue["takesScreenshot"] = true; responseValue["handlesAlerts"] = true; var desiredCapabilities = JObject.Parse(parameters["desiredCapabilities"]?.ToString() ?? "{}").ToObject <Dictionary <string, object> >(); //parameters["desiredCapabilities"] as Dictionary<string, string> ?? new Dictionary<string, string>(); // extend capabilities with one more required parameter if (!desiredCapabilities.TryGetValue("mode", out var mode)) { return(Response.CreateMissingParametersResponse("mode")); } // check does mode is process and capabilities contain processName simultaneounsy if (mode?.ToString() == "attach" & !desiredCapabilities.TryGetValue("processName", out var processName)) { return(Response.CreateMissingParametersResponse("processName")); } // check does mode is process and capabilities contain exePath simultaneounsy if (mode?.ToString() == "start" & !desiredCapabilities.TryGetValue("exePath", out var exePath)) { return(Response.CreateMissingParametersResponse("exePath")); } Process process = null; if (processName != null) { process = Process.GetProcessesByName(processName.ToString()).FirstOrDefault(); // searching by name as regular expression pattern if (process == null) { var regex = new Regex(processName.ToString()); process = Process.GetProcesses() .Where(x => regex.IsMatch(x.ProcessName)).FirstOrDefault(); } if (process == null) { return(Response.CreateErrorResponse(-1, $"Cannot attach to process '{processName}', no such process found.")); } } if (exePath != null) { process = ApplicationProcess.StartProcessFromPath(exePath.ToString()); if (process == null) { return(Response.CreateErrorResponse(-1, "Cannot start process.")); } } var sessionId = process?.MainWindowHandle.ToString(); if (sessionId != null) { /*if (CacheStore.Store.TryGetValue(sessionId, out var elementCache)) * { * CacheStore.Store.TryRemove(sessionId, out elementCache); * } * else * { * CacheStore.Store.AddOrUpdate(sessionId, ElementCacheFactory.Get(sessionId), (k, c) => * { * c.Handle = process.MainWindowHandle; * return c; * }); * }*/ if (CacheStore.CommandStore.TryGetValue(sessionId, out var commandEnvironment)) { CacheStore.CommandStore.TryRemove(sessionId, out commandEnvironment); } //var cache = ElementCacheFactory.Get(sessionId); commandEnvironment = new CommandEnvironment(sessionId, desiredCapabilities); //var e = cache.AutomationElement; //e = AutomationElement.FromHandle(cache.Handle); //cache.AddHandler(UnexpectedAlertBehavior.CreateHandler(e, cache.Handle, commandEnvironment)); //CacheStore.CommandStore.AddOrUpdate(sessionId, commandEnvironment, (k, c) => c); } Response response = Response.CreateSuccessResponse(responseValue); response.SessionId = sessionId; response.Status = null; return(response); }
/// <summary> /// Creates a new instance of a Opening object, and initializes it with the specified property values. /// </summary> /// <param name="activity"></param> /// <param name="name"></param> /// <param name="minParticipants"></param> /// <param name="maxParticipants"></param> /// <param name="type"></param> /// <param name="process"></param> public Opening(Activity activity, string name, int minParticipants, int maxParticipants, OpeningType type, ApplicationProcess process, CriteriaRule criteriaRule = CriteriaRule.Participate, OpeningState state = OpeningState.Published) { if (String.IsNullOrWhiteSpace(name)) { throw new ArgumentException($"Argument 'name' cannot be null, empty or whitespace."); } if (minParticipants <= 0) { throw new ArgumentException($"Argument 'minParticipants' must be greater than 0."); } if (maxParticipants < minParticipants) { throw new ArgumentException($"Argument 'maxParticipants' must be greater than or equal to 'minParticipants'."); } this.ActivityId = activity?.Id ?? throw new ArgumentNullException(nameof(activity)); this.Activity = activity; this.Name = name; this.MinParticipants = minParticipants; this.MaxParticipants = maxParticipants; this.OpeningType = type; this.ApplicationProcess = process; this.Key = Guid.NewGuid(); this.State = state; this.CriteriaRule = criteriaRule; }
static void Main(string[] args) { var process = new ApplicationProcess(); process.Run(); }
public string GetPackagesList(ApplicationProcess invoker, string args) { return(Response(PackageManager.GetInstance().GetPackages())); }
/// <summary> /// Executes the command. /// </summary> /// <param name="environment">The <see cref="CommandEnvironment"/> to use in executing the command.</param> /// <param name="parameters">The <see cref="Dictionary{string, object}"/> containing the command parameters.</param> /// <returns>The JSON serialized string representing the command response.</returns> public override Response Execute(CommandEnvironment environment, Dictionary <string, object> parameters, System.Threading.CancellationToken cancellationToken) { Dictionary <string, object> responseValue = new Dictionary <string, object>(); responseValue["browserName"] = "WinFormsApp"; responseValue["cssSelectorsEnabled"] = false; responseValue["javascriptEnabled"] = false; responseValue["takesScreenshot"] = true; responseValue["handlesAlerts"] = true; var desiredCapabilities = JObject.Parse(parameters["desiredCapabilities"]?.ToString() ?? "{}").ToObject <Dictionary <string, object> >(); // extend capabilities with one more required parameter if (!desiredCapabilities.TryGetValue("mode", out var mode)) { mode = "start"; //return Response.CreateMissingParametersResponse("mode"); } var mainWindowTitle = ""; if (desiredCapabilities.TryGetValue("mainWindowTitle", out var mwt)) { mainWindowTitle = mwt?.ToString() ?? ""; } var attached = false; Process process = null; // check does mode is process and capabilities contain processName simultaneounsy if (mode?.ToString() == "attach")// & !desiredCapabilities.TryGetValue("processName", out var processName)) { var processName = desiredCapabilities.GetParameterValue <string>("processName"); process = Process.GetProcessesByName(processName).FirstOrDefault(); // searching by name as regular expression pattern if (process == null) { var regex = new Regex(processName); process = Process.GetProcesses().FirstOrDefault(x => regex.IsMatch(x.ProcessName)); } if (process == null) { return(Response.CreateErrorResponse(-1, $"Cannot attach to process '{processName}', no such process found.")); } attached = true; } else { object exePath = string.Empty; // check does mode is process and capabilities contain exePath simultaneounsy if (mode?.ToString() == "start") { if (!desiredCapabilities.TryGetValue("exePath", out exePath) && !desiredCapabilities.TryGetValue("app", out exePath)) { return(Response.CreateMissingParametersResponse("exePath or app")); } desiredCapabilities.TryGetParameterValue <string>("processName", out var processName); process = ApplicationProcess.StartProcessFromPath(exePath.ToString(), processName, mainWindowTitle); if (process == null) { return(Response.CreateErrorResponse(-1, "Cannot start process.")); } } } if (process == null) { return(Response.CreateErrorResponse(WebDriverStatusCode.UnhandledError, $"Cannot start process or attach to process")); } var sessionId = process.MainWindowHandle.ToString(); NLog.MappedDiagnosticsContext.Set("SessionId", sessionId); var processId = $"'{process.ProcessName}', pid = {process.Id}"; if (sessionId == null) { return(Response.CreateErrorResponse(WebDriverStatusCode.UnhandledError, $"Cannot get main windows handle for the process {processId}.")); } // new session is starting, remove the old command environment context if (CacheStore.CommandStore.TryGetValue(sessionId, out var commandEnvironment)) { CacheStore.CommandStore.TryRemove(sessionId, out commandEnvironment); commandEnvironment.Dispose(); } commandEnvironment = new CommandEnvironment(sessionId, desiredCapabilities); if (!attached) { commandEnvironment.Pid = process.Id; Logger.Info($"Session '{sessionId}' created process {processId}."); } else { Logger.Info($"Session '{sessionId}' attached to process {processId}."); } CacheStore.CommandStore.AddOrUpdate(sessionId, commandEnvironment, (key, _) => _); Response response = Response.CreateSuccessResponse(responseValue); response.SessionId = sessionId; response.Status = null; return(response); }
/// <summary> /// Constructor /// </summary> /// <param name="process">Application process</param> public ClientAsyncBridge(ApplicationProcess process) { CurrentProcess = process; }
protected void Start() { string path = ApplicationProcess.ProjectDir(filePath); ApplicationProcess.PlayVideo(path); }
/// <summary> /// Execute action on root UI thread /// </summary> /// <param name="process">Current application process</param> /// <param name="action">Lambda action</param> protected void RunOnUIThread(ApplicationProcess process, Action action) { ProcessManager.RootThreadTask task = new ProcessManager.RootThreadTask(action); process.Host.Invoke(task); }
public string GetFiles(ApplicationProcess process, string args) { string path = args; return(Response(Directory.GetFiles(path))); }
/// <summary> /// Create a new client-host bridge and bind it to the web view /// </summary> /// <param name="process">Application process</param> /// <param name="webView">Client web view</param> public static void PrepareEnvironment(ApplicationProcess process, ChromiumWebBrowser webView) { webView.RegisterJsObject("application", new WindowApplication(process), BindingOptions.DefaultBinder); webView.RegisterAsyncJsObject("runtime", new ClientAsyncBridge(process), BindingOptions.DefaultBinder); }
public WindowApplication(ApplicationProcess process) { CurrentProcess = process; Version = Application.ProductVersion; }