Exemplo n.º 1
0
        public async Task PatchSingleItem(IArchiveFileEntry file, CancellationToken cancellationToken)
        {
            OnProgress(new ProgressUpdateEventArgs(file, 0, 0));
            if (await PatchWriter.Exists(file).ConfigureAwait(false))
            {
                return;
            }
            int              counter    = 0;
            Stream           fileData   = null;
            List <Exception> exceptions = new List <Exception>();

            do
            {
                try
                {
                    fileData = await PatchSource.DownloadHashAsync((int)Index.RootIndex.BuildNumber, file.Hash,
                                                                   cancellationToken);
                }
                catch (Exception ex)
                {
                    counter++;
                    exceptions.Add(ex);
                }
            } while (fileData == null && counter < FileRetryCount);

            if (fileData == null)
            {
                throw new AggregateException(exceptions);
            }

            counter = 0;
            do
            {
                try
                {
                    await PatchWriter.AppendAsync(fileData, file).ConfigureAwait(false);

                    break;
                }
                catch (Exception ex)
                {
                    exceptions.Add(ex);
                    counter++;
                }
            } while (counter < FileRetryCount);

            if (counter >= FileRetryCount)
            {
                throw new AggregateException(exceptions);
            }
        }