/// <summary> /// Code handled by Thread. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ScriptThread_DoWork(object sender, DoWorkEventArgs e) { // Stores "Thread" to var var worker = (BackgroundWorker)sender; // Invokes Thread safe Actions onto UI. In this case disable play button , enable stop button. Invoke((MethodInvoker) delegate { tsbplay.Enabled = false; }); Invoke((MethodInvoker) delegate { tsbstop.Enabled = true; }); //Enables logger methods from SDK ScriptLogger.Initialize(); //Initializes Loggin Event, wich performs an action whenever ScriptLogger gets new Logfiles. ScriptLogger.OnLogging += ScriptLogger_OnLogging; //Sample loop to repeat code inside, until thread gets stopped or application closed. while (!worker.CancellationPending) { //Sends Text to Logger, wich shares it onto UI through event. ScriptLogger.WriteLine("Hello Thread!"); // Let the thread sleep when not requiring actions. Thread.Sleep works better then "Waits" via Api-Call. Thread.Sleep(500); } // Invokes Thread safe Actions onto UI. In this case disable stop button, enable play button. Invoke((MethodInvoker) delegate { tsbplay.Enabled = true; }); Invoke((MethodInvoker) delegate { tsbstop.Enabled = false; }); }
/// <summary> /// Wait for a container to be accessible /// </summary> /// <param name="container">Container to wait for</param> /// <param name="maximumDelay">Maximum delay</param> /// <returns>true if container is accessible</returns> public static bool WaitForContainer(Container container, TimeSpan maximumDelay) { DateTime timeout = DateTime.Now.Add(maximumDelay); while (DateTime.Now < timeout) { if (container.Valid) { return(true); } Thread.Sleep(250); } ScriptLogger.WriteLine("[ERROR] Failed to open container '" + container.Serial.Value + "'"); return(false); }
public static void Run() { ScriptLogger.Initialize(); ScriptLogger.LogToStealth = true; if (ValidateConfig()) { try { var data = xmlconfig.Parse(); Stealth.Client.UseObject(data.ContainerID); while (Stealth.Client.GetLastContainer() != data.ContainerID) { Stealth.Client.Wait(data.WaitDelay); } if (Stealth.Client.FindTypeEx(0xFFFF, 0xFFFF, data.ContainerID, true) > 0) { var r = Stealth.Client.GetFindList(); var l = new List<string>(); foreach (var e in r) { Stealth.Client.ClickOnObject(e); var t = string.Empty; while (t.Trim() == "") t = Stealth.Client.GetTooltip(e, data.ToolTipDelay); l.Add(e + ";" + t.Replace("|", ";")); } File.WriteAllLines(data.FileName, l); } } catch (Exception) { ScriptLogger.WriteLine("Error on Export Handling!"); } } else { ScriptLogger.WriteLine(string.Format("Unable to find {0}", cfgname)); } }
/// <summary> /// Deletes old Context Attachment and generate a new attachment, then parsing the context and store it to the corrosponding object. /// </summary> /// <returns></returns> public bool Parse() { if (ContextOptions.AssignedObject == null) { return(false); } Entries.Clear(); if (Owner == null) { return(false); } var LastUser = ContextOptions.AssignedObject; if (!LastUser.Value.Equals(0) && !LastUser.Equals(Owner.Serial)) { return(false); } Stealth.Client.ClearContextMenu(); Entries = new List <ContextMenuEntry>(); if (Owner == null) { return(false); } Stealth.Client.RequestContextMenu(Owner.Serial.Value); if (ContextOptions.ParserDelay > 0) { Stealth.Client.Wait(ContextOptions.ParserDelay); } var list = Stealth.Client.GetContextMenu(); if (!list.Contains("\r\n")) { const string Code = "ContextMenu Parsing Error!\nFollowing choices could solve the issue:\n* Increase Parser Delay\n* visit https://bitbucket.org/Stealthadmin/stealth-beta-client/issue/11/70411-update"; ScriptLogger.WriteLine(Code); return(false); } list = list.Replace("\r\n", ContextOptions.ParserSymbol.ToString()); var s = list.Split(ContextOptions.ParserSymbol); Entries.Clear(); foreach (var e in s) { Entries.Add(new ContextMenuEntry(e, this)); } ContextOptions.AssignedObject = Owner.Serial; return(true); }