Ejemplo n.º 1
0
        public override async Task StartAsync(ManagedTaskProgress progress, CancellationToken cancellationToken = default)
        {
            progress.Report(50, 1, "Preparing files...");

            var downloadStream = await _connectionFlatFile.DownloadFiles(_flatFile, _path, _files, _files.Length > 1, cancellationToken);

            var filename = _files.Length == 1 ? _files[0] : _flatFile.Name + "_files.zip";

            progress.Report(100, 2, "Files ready for download...");

            await _sharedSettings.StartDataStream(_messageId, downloadStream, _downloadUrl, "file", filename, false, cancellationToken);

            var url = $"{_sharedSettings.RemoteSettings.Network.ProxyUrl}/download/{_messageId}";

            var downloadMessage = new DownloadReadyMessage()
            {
                InstanceId    = _sharedSettings.InstanceId,
                SecurityToken = _sharedSettings.SecurityToken,
                ConnectionId  = _connectionId,
                Reference     = _reference,
                HubKey        = _hubKey,
                Url           = url
            };

            var returnValue = await _sharedSettings.PostAsync <DownloadReadyMessage, ReturnValue>("Remote/DownloadReady", downloadMessage, cancellationToken);

            if (!returnValue.Success)
            {
                throw new RemoteOperationException($"The file download did not completed.  {returnValue.Message}", returnValue.Exception);
            }
        }
Ejemplo n.º 2
0
        public override async Task StartAsync(ManagedTaskProgress progress, CancellationToken cancellationToken = default)
        {
            var httpClient = _clientFactory.CreateClient();
            var result     = await httpClient.GetAsync(_uploadUrl, cancellationToken);

            await _uploadAction.Invoke(await result.Content.ReadAsStreamAsync());
        }
Ejemplo n.º 3
0
        public override async Task StartAsync(ManagedTaskProgress progress, CancellationToken cancellationToken = default)
        {
            progress.Report(50, 1, "Running data extract...");
            var downloadStream = await _downloadData.GetStream(cancellationToken);

            var filename = downloadStream.FileName;
            var stream   = downloadStream.Stream;

            progress.Report(100, 2, "Download ready...");

            await _sharedSettings.StartDataStream(_reference, stream, _downloadUrl, "file", filename, false, cancellationToken);

            var url = $"{_downloadUrl.Url}/download/{_reference}";

            var downloadMessage = new DownloadReadyMessage()
            {
                InstanceId    = _sharedSettings.InstanceId,
                SecurityToken = _sharedSettings.SecurityToken,
                ConnectionId  = _connectionId,
                Reference     = _reference,
                HubKey        = _hubKey,
                Url           = url
            };

            var returnValue = await _sharedSettings.PostAsync <DownloadReadyMessage, ReturnValue>("Remote/DownloadReady", downloadMessage, cancellationToken);

            if (!returnValue.Success)
            {
                throw new RemoteOperationException($"The data download did not completed.  {returnValue.Message}", returnValue.Exception);
            }
        }
Ejemplo n.º 4
0
        public override async Task StartAsync(ManagedTaskProgress progress, CancellationToken cancellationToken = default)
        {
            for (var i = 0; i < _loops; i++)
            {
                await Task.Delay(_delay, cancellationToken);

                var percent = (i + 1) * (100 / _loops);
                progress.Report(percent, "step: " + percent);
            }
        }
            public override Task StartAsync(ManagedTaskProgress progress, CancellationToken cancellationToken = default)
            {
                var files = Directory.GetFiles(_path);

                foreach (var file in files)
                {
                    File.Delete(file);
                }
                return(Task.CompletedTask);
            }
Ejemplo n.º 6
0
        public override async Task StartAsync(ManagedTaskProgress progress, CancellationToken cancellationToken = default)
        {
            for (var i = 0; i < 5; i++)
            {
                await Task.Delay(1000, cancellationToken);

                var percent = (i + 1) * 5;
                progress.Report($"step: {i+1}");
            }
        }
Ejemplo n.º 7
0
 public override async Task StartAsync(ManagedTaskProgress progress, CancellationToken cancellationToken = default)
 {
     try
     {
         await _httpClient.PostAsync(_isError?_errorUrl : _uploadUrl, new StreamContent(_stream), cancellationToken);
     }
     catch (Exception ex)
     {
         var returnValue = new ReturnValue(false, "Error: " + ex.Message, ex);
         await _httpClient.PostAsync(_errorUrl, new StringContent(returnValue.Serialize()), cancellationToken);
     }
 }
 public override Task StartAsync(ManagedTaskProgress progress, CancellationToken cancellationToken = default)
 {
     throw new Exception("An error");
 }