private void OutputMsg(Process process) { StreamReader sr = process.StandardOutput; while (!sr.EndOfStream) { output = sr.ReadLine(); if (string.IsNullOrEmpty(output)) { output = "Подготовка. Это может занять продолжительное время. Подождите."; OutputEvent?.Invoke(output, true, false); } else { OutputEvent?.Invoke(output, false, false); } if (output.Contains("Ошибка")) { OutputEvent?.Invoke(output, false, true); break; } } OutputEvent?.Invoke(output, false, true); }
public void Copy(string whereFrom, string to, string fileName) { try { if (fileName.Contains("install")) { CheckInstallWim(to); } #region old conditions //if (fileName == "Winre.wim" && File.Exists($@"{to}\{fileName}")) //{ // File.Delete($@"{to}\{fileName}"); //} //else if (fileName == "install.wim" && File.Exists($@"{to}\{fileName}")) //{ // File.Delete($@"{to}\{fileName}"); //} //else if (fileName == "install.esd" && File.Exists($@"{to}\{fileName}")) //{ // File.Delete($@"{to}\{fileName}"); //} #endregion OutputEvent?.Invoke($"Импорт нового {fileName}", true, false); File.Copy(whereFrom, $@"{to}\{fileName}", true); OutputEvent?.Invoke($"Импорт {fileName} завершен", false, true); } catch (Exception ex) { OutputEvent?.Invoke(ex.Message, false, true); } }
public void Work() { try { _filenames = new ConcurrentQueue <string>(Directory.GetFiles(path, "*.jpg")); } catch (DirectoryNotFoundException) { OutputEvent?.Invoke("No Files"); return; } //Console.CancelKeyPress += (sender, eArgs) => //{ // StopSignal.Set(); // eArgs.Cancel = true; //}; var procNumb = Environment.ProcessorCount; var threads = new Thread[procNumb]; for (var i = 0; i < procNumb; ++i) { OutputEvent?.Invoke("Begining thread"); threads[i] = new Thread(Worker); threads[i].Start(); } for (var i = 0; i < procNumb; ++i) { threads[i].Join(); } OutputEvent?.Invoke("Work Finished"); }
private void SearchForLinks(string URI, int SearchDepth) { Console.WriteLine(SearchDepth); if (SearchDepth >= 0) { WebClient webclient = new WebClient(); Uri uri = new Uri(URI); string page; foreach (IDomObject link in CQ.Create(page = webclient.DownloadString(uri)).Find("a")) { string str = link.GetAttribute("href"); if (str != null) { if (str.StartsWith("/")) { str = uri.GetLeftPart(UriPartial.Authority) + str; } if (str != URI) { if (str.Contains(uri.GetLeftPart(UriPartial.Authority)) && SearchDepth > 0) { SearchForLinks(str, --SearchDepth); } else { OutputEvent?.Invoke(str, SearchDepth, link.GetAttribute("href"), link.GetAttribute("title")); } } } } } }
public void SendInput(double a, double b) { double[] results = Model.Calculate(a, b); OutputEvent?.Invoke(this, $"a+b= {results[0]:G16}"); OutputEvent?.Invoke(this, $"a-b= {results[1]:G16}"); OutputEvent?.Invoke(this, $"a*b= {results[2]:G16}"); OutputEvent?.Invoke(this, $"a/b= {(b is 0.0 or (-0.0) ? "(Помилка ділення на нуль)" : results[3]):G16}"); }
public void Compute() { float[] inputs = inputLayer.inputs; for (int i = 0; i < hiddenLayers.Length; i++) { inputs = hiddenLayers[i].Compute(inputs); } if (outputLayer.Compute(inputs)[0] >= 0.5f) { onOutput.Invoke(true); } else { onOutput.Invoke(false); } }
private void process_data_received(object sender, DataReceivedEventArgs dataReceivedEventArgs) { if (!String.IsNullOrEmpty(dataReceivedEventArgs.Data)) { if (dataReceivedEventArgs.Data.StartsWith("ERROR")) { ProcessErrorEvnet?.Invoke(this, dataReceivedEventArgs.Data); } var outputData = dataReceivedEventArgs.Data + Environment.NewLine; ThreadPool.QueueUserWorkItem(writeLogToFile, outputData); OutputEvent?.Invoke(outputData); } }
private void Worker() { while (_filenames.TryDequeue(out var name)) { if (StopSignal.WaitOne(0)) { OutputEvent?.Invoke("Breaking by signal"); return; } //var prediction = FileRead(name); //Console.WriteLine(name + prediction); EventResult?.Invoke(FileRead(name)); } OutputEvent?.Invoke("Normal finish"); }
private void OnSubmit(CallbackContext context) { if (!inputField.isFocused) { return; } if (inputField.text == "") { inputField.ActivateInputField(); return; } submit.Invoke(inputField.text); inputField.text = ""; inputField.ActivateInputField(); }
private void SearchForContacts(string URI, int SearchDepth) { WebClient client = new WebClient(); Uri uri = new Uri(URI); string HTMLcode = String.Empty; try { HTMLcode = client.DownloadString(uri); } catch (WebException ex) { if (ex.Status == WebExceptionStatus.ProtocolError && ex.Response is HttpWebResponse response) { Console.WriteLine("HTTP Status Code: " + (int)response.StatusCode); } } Regex AddressRegex = new Regex(@"(?<=\>)(Адрес.*?)(?=\<)", RegexOptions.IgnoreCase); Match AddressMatch = AddressRegex.Match(HTMLcode); if (AddressMatch.Success) { Regex PhoneRegex = new Regex(@"((\d{1,3}-\d{1,3}-\d{1,3}))([xX]\d{1,4})?", RegexOptions.IgnoreCase); Match PhoneMatch = PhoneRegex.Match(HTMLcode); while (PhoneMatch.Success) { OutputEvent?.Invoke(URI, SearchDepth, PhoneMatch.Value, AddressMatch.Value); //invoking output PhoneMatch = PhoneMatch.NextMatch(); } } if (SearchDepth > 0) { Regex hrefregex = new Regex("(href\\s*=\\s*(?:\"|')(.*?)(?:\"|'))", RegexOptions.IgnoreCase); Match hrefmatch; hrefmatch = hrefregex.Match(HTMLcode); while (hrefmatch.Success) { string href = hrefmatch.Value.Substring(5).Trim('"', ' '); if (href.StartsWith("/")) { href = uri.GetLeftPart(UriPartial.Authority) + href; } if (href.Contains(uri.GetLeftPart(UriPartial.Authority)) && href != URI) { SearchForContacts(href, SearchDepth--); } hrefmatch = hrefmatch.NextMatch(); } } }
public List <Out> Run(List <In> Files) { ConcurrentQueue <Out> queue = new ConcurrentQueue <Out>(); int NumOfThreads = Environment.ProcessorCount; cts = new CancellationTokenSource(); Thread[] threads = new Thread[NumOfThreads]; int processed = -1; for (int i = 0; i < NumOfThreads; i++) { threads[i] = new Thread(() => { int FileNum; while (!cts.Token.IsCancellationRequested) { FileNum = Interlocked.Increment(ref processed); if (FileNum >= Files.Count()) { break; } else { Out output = model.ProcessFile(Files[FileNum]); if (!UseServer) { OutputEvent?.Invoke(this, output); } queue.Enqueue(output); } } }); threads[i].Start(); } for (int i = 0; i < NumOfThreads; i++) { threads[i].Join(); } return(queue.ToList()); }
/// <summary> /// Метод запуска установки драйверов /// </summary> /// <param name="drivers"></param> private void InstallDrv(List <Driver> drivers) { foreach (var t in drivers) { while (!GetInf(t.DriverPath)) { int i = 1; ConnectionEvent?.Invoke($"Отсутствие подключения. Попытка {i}"); log.Log($"{DateTime.Now} Установка: {t.DriverPath.RemoveText()} Ожидание получения *.inf\n"); Thread.Sleep(3000); i++; } t.InfProgBarMax = infMass.Length; log.Log($"{DateTime.Now} Установка: {t.DriverPath} Начало установки\n"); if (!InstallInf(t)) { log.Log($"{DateTime.Now} Установка: {t.DriverPath} завершена\n"); OutputEvent?.Invoke($"{t.DriverPath} завершена", t.CheckedDrv = false); } else { break; } } if (!abortInstall) { OutputEvent?.Invoke("завершена", false); log.Log($"{DateTime.Now} Установка: полностью завершена\n"); } else { File.AppendAllText("Install_log.txt", $"{DateTime.Now} Установка: отменена\n"); OutputEvent?.Invoke($"отменена", true); } }
public override void Output(IOutput output) { OutputEvent?.Invoke(this, new OutputEventArgs(output.Message, output.OutputLevel)); }
private void Update() { m_isUpdating = true; UpdateState(); var timeNow = Time.unscaledTime; // handle events if (isPress) { if (isDown) { // record click count if (timeNow - m_lastPressDownTime < ViveInput.clickInterval) { ++m_clickCount; } else { m_clickCount = 1; } // record press down time m_lastPressDownTime = timeNow; // PressDown event if (m_onVirtualPressDown != null) { m_onVirtualPressDown.Invoke(new OutputEventArgs() { senderObj = this, eventType = ButtonEventType.Down, }); } } // Press event if (m_onVirtualPress != null) { m_onVirtualPress.Invoke(new OutputEventArgs() { senderObj = this, eventType = ButtonEventType.Press, }); } } else if (isUp) { // PressUp event if (m_onVirtualPressUp != null) { m_onVirtualPressUp.Invoke(new OutputEventArgs() { senderObj = this, eventType = ButtonEventType.Up, }); } if (timeNow - m_lastPressDownTime < ViveInput.clickInterval) { for (int i = m_toggleGameObjectOnVirtualClick.Count - 1; i >= 0; --i) { if (m_toggleGameObjectOnVirtualClick[i] != null) { m_toggleGameObjectOnVirtualClick[i].SetActive(!m_toggleGameObjectOnVirtualClick[i].activeSelf); } } for (int i = m_toggleComponentOnVirtualClick.Count - 1; i >= 0; --i) { if (m_toggleComponentOnVirtualClick[i] != null) { m_toggleComponentOnVirtualClick[i].enabled = !m_toggleComponentOnVirtualClick[i].enabled; } } // Click event if (m_onVirtualClick != null) { m_onVirtualClick.Invoke(new OutputEventArgs() { senderObj = this, eventType = ButtonEventType.Click, }); } } } if (!isActiveAndEnabled) { InternalDisable(); } m_isUpdating = false; }
protected virtual void OnOutput(string text) { OutputEvent?.Invoke(this, new TaskOutputEventArgs(text)); }
public void Run(string dir) { cts = new CancellationTokenSource(); if (!Directory.Exists(dir)) { dir = @"..\DigitRecognitionLibrary\DefaultImages"; Trace.WriteLine("Using library with default images..."); } string[] imagePaths = Directory.GetFiles(dir).Where(s => s.EndsWith(".png") || s.EndsWith(".jpg") || s.EndsWith(".bmp") || s.EndsWith(".gif")).ToArray(); int count = imagePaths.Count(); if (count == 0) { Trace.WriteLine("Your directory is empty."); return; } var events = new AutoResetEvent[count]; for (int i = 0; i < count; i++) { events[i] = new AutoResetEvent(false); ThreadPool.QueueUserWorkItem( pi => { int idx = Convert.ToInt32(pi); Tuple <int, float> res; lock (lockObj) { res = LibContext.FindResults(imagePaths[idx]); } if (res != null) { if (!cts.Token.IsCancellationRequested) { Prediction output = new Prediction(imagePaths[idx], res.Item1, res.Item2); OutputEvent?.Invoke(this, output); } events[idx].Set(); } else { if (!cts.Token.IsCancellationRequested) { Prediction output = OneImgRecognition(imagePaths[idx]); OutputEvent?.Invoke(this, output); lock (lockObj) { LibContext.AddResults(output.Path, output.Label, output.Confidence); } } events[idx].Set(); } }, i); } for (int i = 0; i < count; i++) { events[i].WaitOne(); } return; }
private void OnInputStateUpdated() { var timeNow = Time.unscaledTime; if (m_active) { UpdateState(); if (isPress) { if (isDown) { // record click count if (timeNow - m_lastPressDownTime < ViveInput.clickInterval) { ++m_clickCount; } else { m_clickCount = 1; } // record press down time m_lastPressDownTime = timeNow; // PressDown event if (m_onVirtualPressDown != null) { m_onVirtualPressDown.Invoke(new OutputEventArgs() { senderObj = this, eventType = ButtonEventType.Down, }); } } // Press event if (m_onVirtualPress != null) { m_onVirtualPress.Invoke(new OutputEventArgs() { senderObj = this, eventType = ButtonEventType.Press, }); } } else if (isUp) { // PressUp event if (m_onVirtualPressUp != null) { m_onVirtualPressUp.Invoke(new OutputEventArgs() { senderObj = this, eventType = ButtonEventType.Up, }); } if (timeNow - m_lastPressDownTime < ViveInput.clickInterval) { for (int i = m_toggleGameObjectOnVirtualClick.Count - 1; i >= 0; --i) { if (m_toggleGameObjectOnVirtualClick[i] != null) { m_toggleGameObjectOnVirtualClick[i].SetActive(!m_toggleGameObjectOnVirtualClick[i].activeSelf); } } for (int i = m_toggleComponentOnVirtualClick.Count - 1; i >= 0; --i) { if (m_toggleComponentOnVirtualClick[i] != null) { m_toggleComponentOnVirtualClick[i].enabled = !m_toggleComponentOnVirtualClick[i].enabled; } } // Click event if (m_onVirtualClick != null) { m_onVirtualClick.Invoke(new OutputEventArgs() { senderObj = this, eventType = ButtonEventType.Click, }); } } } } else { // unregister update event ViveInput.onUpdate -= OnInputStateUpdated; m_updateActivated = false; // clean up m_prevState = m_currState; m_currState = false; if (isUp) { // PressUp event if (m_onVirtualPressUp != null) { m_onVirtualPressUp.Invoke(new OutputEventArgs() { senderObj = this, eventType = ButtonEventType.Up, }); } if (timeNow - m_lastPressDownTime < ViveInput.clickInterval) { for (int i = m_toggleGameObjectOnVirtualClick.Count - 1; i >= 0; --i) { if (m_toggleGameObjectOnVirtualClick[i] != null) { m_toggleGameObjectOnVirtualClick[i].SetActive(!m_toggleGameObjectOnVirtualClick[i].activeSelf); } } for (int i = m_toggleComponentOnVirtualClick.Count - 1; i >= 0; --i) { if (m_toggleComponentOnVirtualClick[i] != null) { m_toggleComponentOnVirtualClick[i].enabled = !m_toggleComponentOnVirtualClick[i].enabled; } } // Click event if (m_onVirtualClick != null) { m_onVirtualClick.Invoke(new OutputEventArgs() { senderObj = this, eventType = ButtonEventType.Click, }); } } } m_prevState = false; } }
void InvokeEvent() { var env = _envelope.Evaluate(_envelopeTime); _target.Invoke(Mathf.Max(_mute ? 0 : _externalValue, env)); }
protected internal override Location WriteLineEx(string value, OutputLevel level) { OutputEvent?.Invoke(this, new OutputEventArgs(value, level)); return(new Location(0, 0)); }
private void RaiseOutput(string message) { OutputEvent?.Invoke(this, message); }
private void Log(string message) { string s = DateTime.Now.ToString("HH:mm:ss ") + ": " + message; OutputEvent?.Invoke(s); }