예제 #1
0
        private async Task ColorAsync(TimeSpan dueTime, TimeSpan interval, CancellationToken token)
        {
            if (interval.TotalMilliseconds == 0)
            {
                return;
            }
            Stopwatch ColorTH = new Stopwatch();

            ColorTH.Start();

            // Initial wait time before we begin the periodic loop.
            if (dueTime > TimeSpan.Zero)
            {
                await Task.Delay(dueTime, token);
            }

            DateTime LocalTimestamp = Timestamp;
            WSRColor color          = new WSRColor();

            // Repeat this loop until cancelled.
            while (!token.IsCancellationRequested)
            {
                // Skip already work with given data
                if (Timestamp == LocalTimestamp)
                {
                    await Task.Delay(interval, token);

                    continue;
                }

                // Timestamp data
                LocalTimestamp = Timestamp;
                ColorWatch.Again();

                // Do Job
                try {
                    CopyColorData = true;
                    var rgb = color.GetMostProminentColor(ColorData);
                    if (RGB == null || rgb.r > 50 && rgb.g > 50 && rgb.b > 50)
                    {
                        RGB = rgb;
                    }
                    if (WSRConfig.GetInstance().ColorTH.Milliseconds > 0 && ColorTH.Elapsed > WSRConfig.GetInstance().ColorTH)
                    {
                        WSRHttpManager.GetInstance().SendRequest("http://127.0.01:8080/sarah/hue?r=" + RGB.r + "&g=" + RGB.g + "&b=" + RGB.b);
                        ColorTH.Restart();
                    }
                }
                catch (Exception ex) {
                    WSRConfig.GetInstance().logError("COLOR", ex);
                }
                ColorWatch.Stop();

                // Wait to repeat again.
                if (interval > TimeSpan.Zero)
                {
                    await Task.Delay(interval, token);
                }
            }
        }
예제 #2
0
    private async Task ColorAsync(TimeSpan dueTime, TimeSpan interval, CancellationToken token) {

      if (interval.TotalMilliseconds == 0) return;
      Stopwatch ColorTH = new Stopwatch();
      ColorTH.Start();

      // Initial wait time before we begin the periodic loop.
      if (dueTime > TimeSpan.Zero)
        await Task.Delay(dueTime, token);
      
      DateTime LocalTimestamp = Timestamp;
      WSRColor color = new WSRColor();
      
      // Repeat this loop until cancelled.
      while (!token.IsCancellationRequested) {

        // Skip already work with given data
        if (Timestamp == LocalTimestamp) {
          await Task.Delay(interval, token);
          continue;
        }

        // Timestamp data
        LocalTimestamp = Timestamp;
        ColorWatch.Again();

        // Do Job
        try {
          CopyColorData = true;
          var rgb = color.GetMostProminentColor(ColorData);
          if (RGB == null || rgb.r > 50 && rgb.g > 50 && rgb.b > 50) { RGB = rgb; }
          if (WSRConfig.GetInstance().ColorTH.Milliseconds > 0 && ColorTH.Elapsed > WSRConfig.GetInstance().ColorTH) {
            WSRHttpManager.GetInstance().SendRequest("http://127.0.01:8080/sarah/hue?r=" + RGB.r + "&g=" + RGB.g + "&b=" + RGB.b);
            ColorTH.Restart();
          }
        }
        catch (Exception ex) {
          WSRConfig.GetInstance().logError("COLOR", ex);
        }
        ColorWatch.Stop();

        // Wait to repeat again.
        if (interval > TimeSpan.Zero)
          await Task.Delay(interval, token);
      }
    }