Beispiel #1
0
 public void StopListen()
 {
     if (_IsRun == true)
     {
         _Logger.AddItem(LogItem.Create("Stoped function", LogItemType.Stop, FunctionName));
         _IsRun = false;
         Status = "Включить";
         _Listener.Stop();
     }
 }
Beispiel #2
0
        private void OnPreparing(TimeSpan time)
        {
            var entries = new[]
            {
                new LogEntry("Preparing for ", true, false),
                new LogEntry($"{time.TotalSeconds:N0}", false, false, SystemColors.Highlight),
                new LogEntry(" seconds.", false)
            };

            _mainLogProvider.Log(LogItem.Create(entries));
        }
Beispiel #3
0
        private async void bStart_Click(object sender, EventArgs e)
        {
            if (bStart.Text == "Start")
            {
                bStart.Text = "Stop";

                if (lLongerLastRoundTime.Enabled)
                {
                    _kegelTimer = new LongerLastRoundTimer
                    {
                        Rounds          = tbRounds.Value,
                        PreparationTime = new TimeSpan(0, 0, tbPreparationTime.Value),
                        TimeOn          = new TimeSpan(0, 0, tbOnTime.Value),
                        TimeOff         = new TimeSpan(0, 0, tbOffTime.Value),
                        LastRoundTime   = new TimeSpan(0, 0, tbLongerLastRoundTime.Value)
                    };
                }
                else
                {
                    _kegelTimer = new NormalTimer
                    {
                        Rounds          = tbRounds.Value,
                        PreparationTime = new TimeSpan(0, 0, tbPreparationTime.Value),
                        TimeOn          = new TimeSpan(0, 0, tbOnTime.Value),
                        TimeOff         = new TimeSpan(0, 0, tbOffTime.Value)
                    };
                }

                _kegelTimer.Preparing    += OnPreparing;
                _kegelTimer.RoundStarted += OnRoundStarted;
                _kegelTimer.RoundResting += OnRoundResting;
                _kegelTimer.Stopped      += OnStopped;
                _kegelTimer.Finished     += OnFinished;

                var totalExpectedTime = _kegelTimer.TotalWorkoutTime + _kegelTimer.PreparationTime;
                var entries           = new[]
                {
                    new LogEntry("Expected to take ", true, false),
                    new LogEntry($"{totalExpectedTime.TotalSeconds:N0}", false, false, SystemColors.Highlight),
                    new LogEntry(" seconds.", false),
                };
                _mainLogProvider.Log(LogItem.Create(entries));

                _mainLogProvider.Log(LogItem.Create("Started timer."));
                await _kegelTimer.Start();
            }
            else
            {
                _kegelTimer.Stop();
                bStart.Text = "Start";
            }
        }
Beispiel #4
0
        private ClientSpan CreateSaveClientSpans(string tracerId, string traceId, string parentSpanId, string spanId, string opName, bool withLogs = false)
        {
            var clientSpan     = ClientSpan.Create(tracerId, traceId, parentSpanId, spanId, opName);
            var saveClientSpan = new ClientSpan();

            MyModelHelper.SetProperties(saveClientSpan, clientSpan);
            if (withLogs)
            {
                saveClientSpan.Logs.Add("foo-log-key", LogItem.Create("foo-log-key", "foo-log-value", null));
                saveClientSpan.Tags.Add("foo-tag-key", "foo-tag-value");
            }
            return(saveClientSpan);
        }
Beispiel #5
0
        private void OnStopped(TimeSpan time)
        {
            var entries = new[]
            {
                new LogEntry("Stopped after ", true, false),
                new LogEntry($"{time.TotalSeconds:N0}", false, false, SystemColors.Highlight),
                new LogEntry(" seconds.", false)
            };

            _mainLogProvider.Log(LogItem.Create(entries));

            bStart.Text = "Start";
        }
Beispiel #6
0
        private void OnFinished(TimeSpan time)
        {
            Console.Beep(1500, 1000);

            var entries = new[]
            {
                new LogEntry("Finished in ", true, false),
                new LogEntry($"{time.TotalSeconds:N0}", false, false, SystemColors.Highlight),
                new LogEntry(" seconds.", false)
            };

            _mainLogProvider.Log(LogItem.Create(entries));

            bStart.Text = "Start";
        }
Beispiel #7
0
        private void OnRoundResting(ReportUpdateEventArgs eventArgs)
        {
            Console.Beep(3000, 500);

            var entries = new[]
            {
                new LogEntry("Resting after round ", true, false),
                new LogEntry($"#{eventArgs.Round}", false, false, SystemColors.Highlight),
                new LogEntry(" for ", false, false),
                new LogEntry($"{eventArgs.Time.TotalSeconds:N0}", false, false, SystemColors.Highlight),
                new LogEntry(" seconds.", false)
            };

            _mainLogProvider.Log(LogItem.Create(entries));
        }
Beispiel #8
0
 public async void StartListen()
 {
     if (_IsRun == false)
     {
         if (_Listener == null)
         {
             _Listener = new HttpListener();
             _Listener.Prefixes.Add(_address);
         }
         _Logger.AddItem(LogItem.Create("Started function", LogItemType.Start, FunctionName));
         try
         {
             _Listener.Start();
         }
         catch (Exception e)
         {
             throw new InvalidOperationException("Start Function error", e);
         }
         _IsRun = true;
         Status = "Выключить";
         Stopwatch tickCounter = new Stopwatch();
         while (true)
         {
             tickCounter.Reset();
             HttpListenerContext CurrentContext;
             try
             {
                 CurrentContext = await _Listener.GetContextAsync();
             }
             catch (Exception e)
             {
                 if (_Listener != null && _Listener.IsListening)
                 {
                     continue;
                 }
                 else
                 {
                     break;
                 }
             }
             var Request = CurrentContext.Request;
             _Logger.AddItem(LogItem.Create("Receive exchange", LogItemType.Exchange, FunctionName));
             Statistics.RequestCount += 1;
             if (Request.HttpMethod == "GET")
             {
                 var requestString = Request.QueryString;
                 var GetRequest    = Request.RawUrl;
                 Statistics.DataReceive += GetRequest.Length;
                 Dictionary <string, object> Params = GetHttpRequest.GetParams(GetRequest);
                 var par = Params.Values.ToArray();
                 tickCounter.Start();
                 var result = _Runner.Run(_FunctionName, par);
                 tickCounter.Stop();
                 Statistics.TickCounter += tickCounter.ElapsedTicks;
                 var response       = CurrentContext.Response;
                 var responseStream = response.OutputStream;
                 if (FunctionSettings.EnableCors)
                 {
                     response.AddHeader("Access-Control-Allow-Headers", FunctionSettings.GetCorsHeaderString);
                 }
                 string responseString;
                 if (result.GetType() != typeof(string))
                 {
                     responseString = result.ToString();
                 }
                 else
                 {
                     responseString = (string)result;
                 }
                 var returnArray = Encoding.UTF8.GetBytes(responseString);
                 response.ContentLength64 = returnArray.Length;
                 responseStream.Write(returnArray, 0, returnArray.Length);
             }
             else
             {
                 var    stream = Request.InputStream;
                 byte[] array  = new byte[stream.Length];
                 stream.Read(array, 0, array.Length);
                 string strFromRequest = Encoding.UTF8.GetString(array);
             }
         }
     }
 }