Esempio n. 1
0
        public void UnregisterPendingImportResource(PendingImportResourceNewGen pendingImportResource)
        {
            // We need to make sure that only the PendingImportResource object that is registered can unregister itself, hence
            // the ReferenceEquals condition. If we don't do that and have two different PendingImportResource objects pointing
            // to the same ResourcePath (which are therefore "equal"), the registration fails as described above, but the
            // deregistration succeeds. As a result, the ImportJob will not be saved to disk completely on shutdown.
            PendingImportResourceNewGen registeredPendingImportResourceNewGen;

            if (_pendingImportResources.TryGetValue(pendingImportResource.PendingResourcePath, out registeredPendingImportResourceNewGen))
            {
                if (ReferenceEquals(pendingImportResource, registeredPendingImportResourceNewGen))
                {
                    PendingImportResourceNewGen removedPendingImportResource;
                    if (!_pendingImportResources.TryRemove(pendingImportResource.PendingResourcePath, out removedPendingImportResource))
                    {
                        ServiceRegistration.Get <ILogger>().Warn("ImporterWorker.{0}: Could not unregister {1}", this, pendingImportResource);
                    }
                }
            }

            // If this ImportJobController is not completed, notify the ImporterWorker
            // every 25 disposed (i.e. completed) PendingImportResources
            if (_notifyProgress && Interlocked.Increment(ref _numberOfDisposedPendingImportResources) % 25 == 0)
            {
                _parentImporterWorker.NotifyProgress(false);
            }
        }
Esempio n. 2
0
        public ImportJobController(ImportJobNewGen importJob, int importJobNumber, ImporterWorkerNewGen parentImporterWorker)
        {
            _importJobInformation = importJob.ImportJobInformation;
            _importJobNumber      = importJobNumber;
            _parentImporterWorker = parentImporterWorker;
            _numberOfLastPendingImportResource      = 0;
            _numberOfDisposedPendingImportResources = 0;
            _notifyProgress                = true;
            _pendingImportResources        = new ConcurrentDictionary <ResourcePath, PendingImportResourceNewGen>();
            _importJobControllerCompletion = new TaskCompletionSource <object>();
            _firstBlockHasFinished         = new TaskCompletionSource <object>();
            _cts = new CancellationTokenSource();
            _parentImporterWorker.NotifyProgress(true);

            _dataflowBlocks = new List <ImporterWorkerDataflowBlockBase>();
            SetupDataflowBlocks(importJob.PendingImportResources);
            _dataflowBlocks.ForEach(block => block.Completion.ContinueWith(OnAnyBlockFaulted, TaskContinuationOptions.OnlyOnFaulted));
            Task.WhenAll(_dataflowBlocks.Select(block => block.Completion)).ContinueWith(OnFinished);
        }
    public ImportJobController(ImportJobNewGen importJob, int importJobNumber, ImporterWorkerNewGen parentImporterWorker)
    {
      _importJobInformation = importJob.ImportJobInformation;
      _importJobNumber = importJobNumber;
      _parentImporterWorker = parentImporterWorker;
      _numberOfLastPendingImportResource = 0;
      _numberOfDisposedPendingImportResources = 0;
      _notifyProgress = true;
      _pendingImportResources = new ConcurrentDictionary<ResourcePath, PendingImportResourceNewGen>();
      _importJobControllerCompletion = new TaskCompletionSource<object>();
      _firstBlockHasFinished = new TaskCompletionSource<object>();
      _cts = new CancellationTokenSource();
      _parentImporterWorker.NotifyProgress(true);

      _dataflowBlocks = new List<ImporterWorkerDataflowBlockBase>();
      SetupDataflowBlocks(importJob.PendingImportResources);
      _dataflowBlocks.ForEach(block => block.Completion.ContinueWith(OnAnyBlockFaulted, TaskContinuationOptions.OnlyOnFaulted));
      Task.WhenAll(_dataflowBlocks.Select(block => block.Completion)).ContinueWith(OnFinished);
    }