コード例 #1
0
        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);
        }
コード例 #2
0
        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);
            }
        }
コード例 #3
0
        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");
        }
コード例 #4
0
ファイル: MainParser.cs プロジェクト: cha1n3aw/C-Labs
 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"));
                     }
                 }
             }
         }
     }
 }
コード例 #5
0
ファイル: Presenter.cs プロジェクト: MightyFixie/21H1_Lab3
 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}");
 }
コード例 #6
0
        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);
            }
        }
コード例 #7
0
 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);
     }
 }
コード例 #8
0
        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");
        }
コード例 #9
0
        private void OnSubmit(CallbackContext context)
        {
            if (!inputField.isFocused)
            {
                return;
            }

            if (inputField.text == "")
            {
                inputField.ActivateInputField();
                return;
            }

            submit.Invoke(inputField.text);
            inputField.text = "";
            inputField.ActivateInputField();
        }
コード例 #10
0
        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();
                }
            }
        }
コード例 #11
0
        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());
        }
コード例 #12
0
        /// <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);
            }
        }
コード例 #13
0
 public override void Output(IOutput output)
 {
     OutputEvent?.Invoke(this, new OutputEventArgs(output.Message, output.OutputLevel));
 }
コード例 #14
0
        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;
        }
コード例 #15
0
ファイル: TaskRunner.cs プロジェクト: wlclass/Photon
 protected virtual void OnOutput(string text)
 {
     OutputEvent?.Invoke(this, new TaskOutputEventArgs(text));
 }
コード例 #16
0
        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;
        }
コード例 #17
0
        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;
            }
        }
コード例 #18
0
        void InvokeEvent()
        {
            var env = _envelope.Evaluate(_envelopeTime);

            _target.Invoke(Mathf.Max(_mute ? 0 : _externalValue, env));
        }
コード例 #19
0
 protected internal override Location WriteLineEx(string value, OutputLevel level)
 {
     OutputEvent?.Invoke(this, new OutputEventArgs(value, level));
     return(new Location(0, 0));
 }
コード例 #20
0
 private void RaiseOutput(string message)
 {
     OutputEvent?.Invoke(this, message);
 }
コード例 #21
0
ファイル: MainWindow.cs プロジェクト: backrunner/HashCrash
        private void Log(string message)
        {
            string s = DateTime.Now.ToString("HH:mm:ss ") + ": " + message;

            OutputEvent?.Invoke(s);
        }