Exemplo n.º 1
0
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            taskInstance.Canceled += OnCanceled;
            _deferral              = taskInstance.GetDeferral();

            try
            {
                var fileSystem = new FileSystemAdapter(true, null);
                var webDav     = new WebDavAdapter(true, Configuration.ServerUrl, Configuration.Credential, fileSystem);
                fileSystem.LinkedAdapter = webDav;
                _worker = new BackgroundSyncProcess(fileSystem, webDav, true);
                await _worker.Run();
            }
            catch (Exception e)
            {
                await LogHelper.Write($"BackgroundTask Exception: {e.Message}" + Environment.NewLine +
                                      $"{e.StackTrace}" + Environment.NewLine +
                                      $"Status:{ExecutionContext.Instance.Status.ToString()}" + Environment.NewLine +
                                      $"File: {ExecutionContext.Instance.CurrentFileNumber}" + Environment.NewLine +
                                      $"of {ExecutionContext.Instance.TotalFileCount}");
            }
            finally
            {
                await LogHelper.Write("BackgroundTask finished");

                _deferral.Complete();
            }
        }
        private void _Initialize()
        {
            var fileSystem = new FileSystemAdapter(false, null);
            var webDav     = new WebDavAdapter(false, Configuration.ServerUrl, Configuration.Credential, fileSystem);

            fileSystem.LinkedAdapter = webDav;
            _worker = new BackgroundSyncProcess(fileSystem, webDav, false);
        }