コード例 #1
0
        private Yield Copy_Helper(Result <BulkCopy> result)
        {
            foreach (var importItem in _importer.Items)
            {
                Result <ExportItem> exportResult;
                yield return(exportResult = _exporter.GetItemAsync(importItem.DataId, new Result <ExportItem>()));

                ExportItem exportItem = exportResult.Value;
                if (_copyIntercept != null)
                {
                    Result <ExportItem> interceptResult;
                    yield return(interceptResult = Coroutine.Invoke(_copyIntercept, this, exportItem, new Result <ExportItem>()));

                    if (interceptResult.Value == null)
                    {
                        exportItem.Dispose();
                        continue;
                    }
                    exportItem = interceptResult.Value;
                }
                yield return(_importer.WriteDataAsync(importItem.WithData(exportItem.Data, exportItem.DataLength), new Result()));

                Interlocked.Increment(ref _completed);
            }
            result.Return(this);
            yield break;
        }
コード例 #2
0
        private Yield Import_Helper(Result result)
        {
            foreach (var importItem in _importer.Items)
            {
                var retry = 0;
                while (true)
                {
                    // capturing item since we may modify its slot
                    var item = importItem;
                    if (item.NeedsData)
                    {
                        Result <ImportItem> readResult;
                        yield return(readResult = _packager.ReadData(item, new Result <ImportItem>()).Catch());

                        if (readResult.HasException)
                        {
                            retry++;
                            _log.DebugFormat("failed to read data item {0} on try {1}", (CompletedItems + 1), retry);
                            if (retry < MaxRetries)
                            {
                                continue;
                            }
                            throw new ImportException(item.Manifest, readResult.Exception);
                        }

                        item = readResult.Value;
                    }
                    Result writeResult;
                    yield return(writeResult = _importer.WriteDataAsync(item, new Result()).Catch());

                    if (writeResult.HasException)
                    {
                        retry++;
                        _log.DebugFormat("failed to write item {0} on try {1}", (CompletedItems + 1), retry);
                        if (retry < MaxRetries)
                        {
                            continue;
                        }
                        throw new ImportException(item.Manifest, writeResult.Exception);
                    }
                    break;
                }
                Interlocked.Increment(ref _completed);
            }
            _packager.Dispose();
            result.Return();
        }