Ejemplo n.º 1
0
        private void HandleAppRefresh(BGAppRefreshTask task)
        {
            try
            {
                loggerService.StartMethod();

                ScheduleAppRefresh();

                var queue = new NSOperationQueue();
                queue.MaxConcurrentOperationCount = 1;

                task.ExpirationHandler = () =>
                {
                    loggerService.Info("Task expired.");
                    queue.CancelAllOperations();
                };

                var operation = new DeleteOldLogsOperation(loggerService, logFileService);
                operation.CompletionBlock = () =>
                {
                    loggerService.Info($"Operation completed. operation.IsCancelled: {operation.IsCancelled}");
                    task.SetTaskCompleted(!operation.IsCancelled);
                };

                queue.AddOperation(operation);

                loggerService.EndMethod();
            }
            catch
            {
                // do nothing
            }
        }
Ejemplo n.º 2
0
        // Fetch the latest feed entries from server.
        void HandleAppRefresh(BGAppRefreshTask task)
        {
            ScheduleAppRefresh();

            task.ExpirationHandler = () => operations.CancelOperations();

            operations.FetchLatestPosts(task);
        }
Ejemplo n.º 3
0
    void HandleAppRefresh(BGAppRefreshTask task)
    {
        Schedule();

        var queue     = new NSOperationQueue();
        var operation = new WidgetRefreshOperation(RefreshAction, Verbose);

        task.ExpirationHandler = () => {
            queue.CancelAllOperations();
        };
        operation.CompletionBlock = () => {
            task.SetTaskCompleted(!operation.IsCancelled);
        };

        queue.AddOperation(operation);
    }
Ejemplo n.º 4
0
        private void HandleSendLogAsync(BGAppRefreshTask task)
        {
            _loggerService.StartMethod();

            ScheduleSendEventLog();

            var cancellationTokenSource = new CancellationTokenSource();

            task.ExpirationHandler = cancellationTokenSource.Cancel;

            _ = Task.Run(async() =>
            {
                _loggerService.Info("HandleSendLogAsync() Task.Run() start");
                try
                {
                    await _eventLogRepository.RotateAsync(
                        AppConstants.EventLogFileExpiredSeconds);

                    await _eventLogService.SendAllAsync(
                        AppConstants.EventLogMaxRequestSizeInBytes,
                        AppConstants.EventLogMaxRetry);
                    task.SetTaskCompleted(true);
                }
                catch (OperationCanceledException exception)
                {
                    _loggerService.Exception($"Background task canceled.", exception);
                    task.SetTaskCompleted(false);
                }
                catch (Exception exception)
                {
                    _loggerService.Exception($"Exception", exception);
                    task.SetTaskCompleted(false);
                }
                finally
                {
                    cancellationTokenSource.Dispose();
                    _loggerService.Info("HandleSendLogAsync() Task.Run() end");
                }
            });

            _loggerService.EndMethod();
        }
Ejemplo n.º 5
0
        private void HandleAppRefresh(BGAppRefreshTask task)
        {
            Debug.WriteLine("HandleAppRefresh started");
            ScheduleAppRefresh();

            var queue = new NSOperationQueue();

            queue.MaxConcurrentOperationCount = 1;

            double latitude  = 0;
            double longitude = 0;
            var    n         = new Random().Next(0, 2);

            if (n == 0)
            {
                // H12
                latitude  = 64.096501;
                longitude = -21.890178;
            }
            else
            {
                // Arion
                latitude  = 64.145549;
                longitude = -21.905449;
            }

            var pingOperation = new PingOperation(latitude, longitude, "205558e0-f226-446d-a769-aaceb3b2a880", urlSession);

            task.ExpirationHandler = () =>
            {
                queue.CancelAllOperations();
            };

            pingOperation.CompletionBlock = () =>
            {
                Debug.WriteLine("Ping operation completed");
                task.SetTaskCompleted(!pingOperation.IsCancelled);
            };

            queue.AddOperation(pingOperation);
        }