Exemplo n.º 1
0
        private static ILayer CreateMutatingTriangleLayer(BoundingBox envelope)
        {
            var layer = new MemoryLayer();

            var polygon = new Polygon(new LinearRing(GenerateRandomPoints(envelope, 3)));
            var feature = new Feature()
            {
                Geometry = polygon
            };
            var features = new Features();

            features.Add(feature);

            layer.DataSource = new MemoryProvider(features);

            PeriodicTask.Run(() =>
            {
                polygon.ExteriorRing = new LinearRing(GenerateRandomPoints(envelope, 3));
                // Clear cache for change to show
                feature.RenderedGeometry.Clear();
                // Trigger DataChanged notification
                layer.RefreshData(layer.Envelope, 1, true);
            },
                             TimeSpan.FromMilliseconds(1000));

            return(layer);
        }
Exemplo n.º 2
0
        public TimersControlCenter()
        {
            cancellationToken = new CancellationToken();

            // Do NOT await!
            PeriodicTask.Run(CheckRelayTimers, new TimeSpan(0, 0, 10), cancellationToken);
        }
 static void Main(string[] args)
 {
     PeriodicTask
     .Run(GetSomething, TimeSpan.FromSeconds(3))
     .GetAwaiter()
     .GetResult();
 }
        public void Start()
        {
            var isRunning = false;

            PeriodicTask.Run(async() =>
            {
                if (isRunning)
                {
                    return;
                }

                try
                {
                    isRunning = true;
                    await _emailService.SendUnsentEmailsAsync()
                    .ConfigureAwait(false);
                }
#pragma warning disable CA1031 // Do not catch general exception types
                catch (Exception ex)
#pragma warning restore CA1031 // Do not catch general exception types
                {
                    _log.Error(ex, "Emails in batch could not be sent");
                }
                finally
                {
                    isRunning = false;
                }
            },
                             TimeSpan.FromSeconds(10),
                             _tokenSource.Token);
        }
Exemplo n.º 5
0
 public LongListBottomObserver(LongListSelector longList)
 {
     this.longList            = longList;
     longList.ItemRealized   += LLS_ItemRealized;
     longList.ItemUnrealized += LLS_ItemUnrealized;
     pollingTask              = new PeriodicTask(500, checkIfBottom);
     pollingTask.Run();
 }
Exemplo n.º 6
0
    // Start is called before the first frame update
    void Start()
    {
        DataProvider.client.OnSwap += SwapObjects;
        DataProvider.client.OnInteractiveChange += SetCurrentInteractive;
        this.token = new CancellationTokenSource();
        var token = this.token.Token;

        PeriodicTask.Run(() => { SendPlayerPosition(); }, TimeSpan.FromSeconds(1), token);
    }
Exemplo n.º 7
0
        public void ScheduleTask(int intervalTimeInMs, Action action, int delay = 0, bool preExecute = false)
        {
            if (State.PeriodicTaskEntries == null)
            {
                State.PeriodicTaskEntries = new List <IPeriodicTaskEntry>();
            }
            var newTask = new PeriodicTask(intervalTimeInMs, action);

            State.PeriodicTaskEntries.Add(new SimplePeriodicTaskEntry(newTask));
            newTask.Run(delay, preExecute);
        }
Exemplo n.º 8
0
        private void addScrollingHandlers()
        {
            RootFrame.PointerPressed += ContentPanel_PointerPressed;
            speedMonitorTask          = new PeriodicTask(50, monitorSpeed);
            speedMonitorTask.Run();

            var page = ContentPanel.FirstVisualParent <Page>();

            page.PointerMoved    += Page_PointerMoved;
            page.PointerReleased += Page_PointerReleased;
            this.Unloaded        += (sender, args) =>
            {
                page.PointerMoved    -= Page_PointerMoved;
                page.PointerReleased -= Page_PointerReleased;
                speedMonitorTask.Cancel();
            };
        }
Exemplo n.º 9
0
        public void Run()
        {
            Logger.Init();
            InitializeDatastore.Run();

            var tokens = Tokens.Create(PrivateConstants.TwitterConsumerKey, PrivateConstants.TwitterConsumerSecret, PrivateConstants.TwitterAccessToken, PrivateConstants.TwitterAccessTokenSecret);

            _twitterStream = tokens.Streaming.UserAsObservable().Subscribe(new TweetObserver(_messageProcessor));

            PeriodicTask.Run(() => Tools.LiveStatus(), TimeSpan.FromMinutes(2));
            Tools.LiveStatus();
            PeriodicTask.Run(InitializeDatastore.UpdateEmotes, TimeSpan.FromMinutes(5));
            PeriodicTask.Run(PeriodicMessage, TimeSpan.FromMinutes(10));

            _client.Run(_messageProcessor);
            Console.CancelKeyPress += Console_CancelKeyPress;
            //http://stackoverflow.com/questions/14255655/tpl-dataflow-producerconsumer-pattern
            //http://msdn.microsoft.com/en-us/library/hh228601(v=vs.110).aspx

            ProcessConsoleInput();
            Exit();
        }
Exemplo n.º 10
0
        private static ILayer CreateMutatingTriangleLayer(MRect?envelope)
        {
            var layer = new MemoryLayer();

            var polygon  = new Polygon(new LinearRing(GenerateRandomPoints(envelope, 3).ToArray()));
            var feature  = new GeometryFeature(polygon);
            var features = new List <IFeature>
            {
                feature
            };

            layer.DataSource = new MemoryProvider <IFeature>(features);

            PeriodicTask.Run(() => {
                feature.Geometry = new Polygon(new LinearRing(GenerateRandomPoints(envelope, 3).ToArray()));
                // Clear cache for change to show
                feature.RenderedGeometry.Clear();
                // Trigger DataChanged notification
                layer.DataHasChanged();
            },
                             TimeSpan.FromMilliseconds(1000));

            return(layer);
        }
Exemplo n.º 11
0
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            if (e.NavigationMode == NavigationMode.New)
            {
                if (NavigationContext.QueryString.ContainsKey("stopGroupID"))
                {
                    var controller = new StopMapController();
                    controller.Bind(this);
                }
                else if (NavigationContext.QueryString.ContainsKey("tripId"))
                {
                    var controller = new TripMapController();
                    controller.Bind(this);
                }
                else if (NavigationContext.QueryString.ContainsKey("plan"))
                {
                    var controller = new PlanMapController();
                    controller.Bind(this);
                }

                locationMarkingTask = new PeriodicTask(10000, DoLocationMarking);
                locationMarkingTask.Run(preExecute: true);
            }
            else
            {
                if (locationMarkingTask != null)
                {
                    locationMarkingTask.Resume();
                }
                foreach (var task in Tasks)
                {
                    task.Resume();
                }
            }
        }
Exemplo n.º 12
0
        public override void Bind(IMapControl page, object parameter)
        {
            base.Bind(page, parameter);
            base.RegisterElementTypes(typeof(StopPopup), typeof(StopPushpin));
            stopParam = (StopParameter)parameter;

            if (stopParam.StopGroup != null)
            {
                this.stopGroup  = stopParam.StopGroup;
                this.mainStops  = new HashSet <Stop>(stopGroup.Stops);
                this.mainPoints = mainStops.Select(s => s.Coordinate).ToArray();
            }
            else
            {
                this.fromMainPage = true;
                if (StopTransfers.LastNearestStop != null)
                {
                    this.mainPoints = StopTransfers.LastNearestStop.Stop.Group.Stops.Select(s => s.Coordinate).ToArray();
                }
            }

            if (stopParam.Location != null)
            {
                //this.postQuery.Add("location", locationStr);
                if (!stopParam.Location.IsNear)
                {
                    this.sourceStop = stopParam.Location.Stop;
                    this.location   = sourceStop.Coordinate;
                }
                else
                {
                    this.location = CurrentLocation.Last;
                    isNear        = true;
                }
            }
            if (stopParam.DateTime != null)
            {
                //this.postQuery.Add("dateTime", dateTimeStr);
                this.dateTime = stopParam.DateTime.Value;
                isNow         = false;
            }

            if (isNow)
            {
                timeUpdaterTask = new PeriodicTask(DoTimeUpdate);
                timeUpdaterTask.RunEveryMinute();
            }
            if (isNear)
            {
                locationUpdaterTask = new PeriodicTask(10000, DoLocationUpdate);
                locationUpdaterTask.Run(delay: 1000);
            }


            //foreach (var transfer in transfers)
            //{
            //    Microsoft.Phone.Maps.Controls.MapPolyline line = new Microsoft.Phone.Maps.Controls.MapPolyline
            //    {
            //        StrokeColor = Colors.Gray,
            //        StrokeDashed = true,
            //        StrokeThickness = 8
            //    };
            //    line.Path.Add(transfer.Origin.Coordinate);
            //    line.Path.AddRange(transfer.InnerPoints.Select(p => new GeoCoordinate(p.Latitude, p.Longitude)));
            //    line.Path.Add(transfer.Target.Coordinate);
            //    Map.MapElements.Add(line);
            //}
            this.EmptyMapTap   += (sender, args) => clearSelection();
            this.MapElementTap += (sender, element) =>
            {
                if (element is StopPushpin)
                {
                    tapActions[element].Invoke();
                }
            };

            var boundAddition = isNear ? new GeoCoordinate[] { CurrentLocation.Last ?? App.Config.CenterLocation } : new GeoCoordinate[0];
            var boundaries    = calculateBoundaries(mainPoints.Concat(boundAddition));

            SetBoundaries(page, boundaries, stopParam.StopGroup == null);
        }
Exemplo n.º 13
0
 public Task StartAsync(CancellationToken stoppingToken)
 {
     timer = PeriodicTask.Run(() => DoWork(), TimeSpan.Zero, TimeSpan.FromHours(settings.IndexRebuildFrequency), stoppingToken);
     return(timer);
 }
Exemplo n.º 14
0
 public ApplicationManager()
 {
     Instances = new ConcurrentDictionary <string, ApplicationInstance>();
     Load();
     PeriodicTask.Run(MonitorProcess, TimeSpan.FromSeconds(5));
 }
Exemplo n.º 15
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            base.OnNavigatedTo(e);
            if (e.NavigationMode == NavigationMode.New)
            {
                string param = "";

                if (!NavigationContext.QueryString.TryGetValue("id", out param))
                {
                    throw new Exception("RoutePage opened without parameter");
                }
                StopGroup stop       = App.Model.GetStopGroupByID(int.Parse(param));
                DateTime? dateTime   = null;
                bool      near       = false;
                Stop      sourceStop = null;
                bool      noLocation = true;

                if (NavigationContext.QueryString.TryGetValue("dateTime", out param))
                {
                    dateTime        = Convert.ToDateTime(param);
                    this.postQuery += "&dateTime=" + param;
                }

                if (NavigationContext.QueryString.TryGetValue("location", out param))
                {
                    if (param == "near")
                    {
                        near = true;
                    }
                    else
                    {
                        sourceStop = App.Model.GetStopByID(int.Parse(param));
                    }

                    noLocation      = false;
                    this.postQuery += "&location=" + param;
                }

                this.ViewModel = new StopViewModel(addFooter: false);
                //ViewModel.Initialize(parameter, stateManager);
                ViewModel.Initialize(new StopParameter
                {
                    StopGroup = stop,
                    DateTime  = dateTime,
                    Location  = noLocation ? null : new ParameterLocation
                    {
                        IsNear = near,
                        Stop   = sourceStop
                    }
                });

                if (dateTime == null)
                {
                    contentSetterTask = new PeriodicTask(ViewModel.TasksToSchedule.Single());
                    contentSetterTask.RunEveryMinute();

                    flashTask = new PeriodicTask(500, flashTimes);
                    flashTask.Run();
                }
            }
            else
            {
                if (contentSetterTask != null)
                {
                    contentSetterTask.Resume();
                }
                if (flashTask != null)
                {
                    flashTask.Resume();
                }
            }
            if (ShowTransfers)
            {
                llObserver = new LongListBottomObserver(ContentListView);
                llObserver.ScrollToBottom += ContentListView_ScrollToBottom;
            }
        }
Exemplo n.º 16
0
 private async void Selector_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     await PeriodicTask.Run(GetMessages, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(1), CancellationToken.None);
 }
Exemplo n.º 17
0
 private async void ListOfUsers_OnLoaded(object sender, RoutedEventArgs e)
 {
     await PeriodicTask.Run(GetAllUsers, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(5), CancellationToken.None);
 }
 public void StartReading()
 {
     LoadConfigurationSettings();
     PeriodicTask.Run(LoadConfigurationSettings, TimeSpan.FromMilliseconds(_refreshTimerIntervalInMs));
 }
Exemplo n.º 19
0
        public override async void Bind(MapPage page)
        {
            base.Bind(page);
            base.RegisterElementTypes(typeof(StopPushpin));

            int stopGroupId = int.Parse(page.NavigationContext.QueryString["stopGroupID"]);

            if (stopGroupId != 0)
            {
                this.stopGroup  = App.Model.GetStopGroupByID(stopGroupId);
                this.mainStops  = new HashSet <Stop>(stopGroup.Stops);
                this.mainPoints = mainStops.Select(s => s.Coordinate).ToArray();
            }
            else
            {
                this.fromMainPage = true;
                if (StopTransfers.LastNearestStop != null)
                {
                    this.mainPoints = StopTransfers.LastNearestStop.Stop.Group.Stops.Select(s => s.Coordinate).ToArray();
                }
            }
            string locationStr = null, dateTimeStr = null;

            if (page.NavigationContext.QueryString.TryGetValue("location", out locationStr))
            {
                this.postQuery.Add("location", locationStr);
                if (locationStr != "near")
                {
                    this.sourceStop = App.Model.GetStopByID(int.Parse(locationStr));
                    this.location   = sourceStop.Coordinate;
                }
                else
                {
                    this.location = CurrentLocation.Last;
                    isNear        = true;
                }
            }
            if (page.NavigationContext.QueryString.TryGetValue("dateTime", out dateTimeStr))
            {
                this.postQuery.Add("dateTime", dateTimeStr);
                this.dateTime = System.Convert.ToDateTime(dateTimeStr);
                isNow         = false;
            }

            if (isNow)
            {
                timeUpdaterTask = new PeriodicTask(DoTimeUpdate);
                timeUpdaterTask.RunEveryMinute();
                page.Tasks.Add(timeUpdaterTask);
            }
            if (isNear)
            {
                locationUpdaterTask = new PeriodicTask(10000, DoLocationUpdate);
                locationUpdaterTask.Run(delay: 1000);
                page.Tasks.Add(locationUpdaterTask);
            }


            //foreach (var transfer in transfers)
            //{
            //    Microsoft.Phone.Maps.Controls.MapPolyline line = new Microsoft.Phone.Maps.Controls.MapPolyline
            //    {
            //        StrokeColor = Colors.Gray,
            //        StrokeDashed = true,
            //        StrokeThickness = 8
            //    };
            //    line.Path.Add(transfer.Origin.Coordinate);
            //    line.Path.AddRange(transfer.InnerPoints.Select(p => new GeoCoordinate(p.Latitude, p.Longitude)));
            //    line.Path.Add(transfer.Target.Coordinate);
            //    Map.MapElements.Add(line);
            //}
            this.EmptyMapTap   += (sender, args) => clearSelection();
            this.MapElementTap += (sender, element) => tapActions[element].Invoke();

            var boundAddition = isNear ? new GeoCoordinate[] { CurrentLocation.Last ?? App.Config.CenterLocation } : new GeoCoordinate[0];
            var boundaries    = calculateBoundaries(mainPoints.Concat(boundAddition));

            //await Task.Delay(250);
            await initializeMapLabels(page);

            page.Map.SetView(boundaries, MapAnimationKind.None);
            while (page.Map.ZoomLevel < 15)
            {
                page.Map.SetView(boundaries, MapAnimationKind.None);
                await Task.Delay(100);
            }
            //while (page.IsMapEmpty)
            //{
            //    initializeMapLabels(page);
            //    await Task.Delay(100);
            //}

            page.Map.CenterChanged += async(sender, args) =>
            {
                await mapFillingLock.WaitAsync();

                if (page.Map.ZoomLevel >= App.Config.LowStopsMapLevel)
                {
                    var newLocation = page.Map.Center;
                    await tryCreateStopLabelsAt(page, Convert(newLocation));
                }
                else if (page.Map.ZoomLevel >= App.Config.HighStopsMapLevel)
                {
                    var newLocation = page.Map.Center;
                    await tryCreateHighStopLabelsAt(page, Convert(newLocation));

                    clearMap(page, 2.1);
                }
                else
                {
                    clearMap(page);
                }
                mapFillingLock.Release();
            };

            if (isNear && stopGroupId == 0 && mainPoints.Length == 0)
            {
                var nearestResult = await StopTransfers.GetNearestStop(await CurrentLocation.Get());

                if (nearestResult != null)
                {
                    this.location   = CurrentLocation.Last;
                    this.mainPoints = nearestResult.Stop.Group.Stops.Select(s => s.Coordinate).ToArray();
                    boundAddition   = new GeoCoordinate[] { CurrentLocation.Last ?? App.Config.CenterLocation };

                    boundaries = calculateBoundaries(mainPoints.Concat(boundAddition));

                    page.Map.SetView(boundaries, MapAnimationKind.None);
                    await initializeMapLabels(page);
                }
            }
        }
Exemplo n.º 20
0
 private void StartTimer()
 {
     tickCancellationToken = new CancellationTokenSource();
     _ = PeriodicTask.Run(TimerTick, TimeSpan.FromMilliseconds(20), tickCancellationToken.Token);
 }