StreetFoo.Client.BackgroundSyncTask.DoRunAsync C# (CSharp) Method

DoRunAsync() protected method

protected DoRunAsync ( IBackgroundTaskInstance instance ) : System.Threading.Tasks.Task
instance IBackgroundTaskInstance
return System.Threading.Tasks.Task
        protected override async Task DoRunAsync(IBackgroundTaskInstance instance)
        {
            // try and lock...
            if (!(await CreateLockFileAsync()))
            {
                this.Logger.Info("Locked - skipping...");
                return;
            }

            try
            {
                // should we run?
                if (!(await CanRunAsync()))
                    return;

                // send up changes...
                await ReportItem.PushServerUpdatesAsync();

                // still have connectivity?
                if (StreetFooRuntime.HasConnectivity)
                {
                    this.Logger.Info("Getting reports from server...");

                    // get...
                    var proxy = ServiceProxyFactory.Current.GetHandler<IGetReportsByUserServiceProxy>();
                    var reports = await proxy.GetReportsByUserAsync();

                    // errors?
                    if (!(reports.HasErrors))
                    {
                        this.Logger.Info("Stashing reports on disk...");

                        // save...
                        var json = JsonConvert.SerializeObject(reports.Reports);
                        var file = await ApplicationData.Current.TemporaryFolder.CreateFileAsync(SpoolFilename, CreationCollisionOption.ReplaceExisting);
                        await FileIO.WriteTextAsync(file, json);
                    }
                }
            }
            finally
            {
                // reset the lock file...
                ResetLockFileAsync();
            }
        }