예제 #1
0
        protected async Task <(IAllowSync, IDeleteGraphSyncer?)> GetDeleteGraphSyncerIfDeleteAllowed(
            ContentItem contentItem,
            IContentItemVersion contentItemVersion,
            SyncOperation syncOperation)
        {
            try
            {
                IDeleteGraphSyncer deleteGraphSyncer = _serviceProvider.GetRequiredService <IDeleteGraphSyncer>();

                IAllowSync allowSync = await deleteGraphSyncer.DeleteAllowed(
                    contentItem,
                    contentItemVersion,
                    syncOperation);

                return(allowSync, deleteGraphSyncer);
            }
            catch (Exception exception)
            {
                string contentType = GetContentTypeDisplayName(contentItem);

                //todo: will get logged twice, but want to keep the param version
                _logger.LogError(exception, "Unable to check if the '{ContentItem}' {ContentType} can be {DeleteOperation} from the {GraphReplicaSetName} graph.",
                                 contentItem.DisplayText, contentType, syncOperation.ToString("PrP", null).ToLower(), contentItemVersion.GraphReplicaSetName);

                await _notifier.Add(GetSyncOperationCancelledUserMessage(syncOperation, contentItem.DisplayText, contentType),
                                    $"Unable to check if the '{contentItem.DisplayText}' {contentType} can be {syncOperation.ToString("PrP", null).ToLower()} from the {contentItemVersion.GraphReplicaSetName} graph.",
                                    exception : exception);

                throw;
            }
        }
예제 #2
0
        protected async Task DeleteFromGraphReplicaSet(
            IDeleteGraphSyncer deleteGraphSyncer,
            ContentItem contentItem,
            SyncOperation syncOperation)
        {
            try
            {
                await deleteGraphSyncer.Delete();
            }
            catch (CommandValidationException ex)
            {
                // don't fail when node was not found in the graph
                // at the moment, we only add published items to the graph,
                // so if you try to delete a draft only item, this task fails and the item isn't deleted
                //todo: if this check is needed after the published/draft work, don't rely on the message!
                if (ex.Message == "Expecting 1 node to be deleted, but 0 were actually deleted.")
                {
                    return;
                }

                AddFailureNotifier(deleteGraphSyncer, contentItem, ex, syncOperation);
                throw;
            }
            catch (Exception ex)
            {
                AddFailureNotifier(deleteGraphSyncer, contentItem, ex, syncOperation);
                throw;
            }
        }
예제 #3
0
        private void AddFailureNotifier(IDeleteGraphSyncer deleteGraphSyncer,
                                        ContentItem contentItem,
                                        Exception exception,
                                        SyncOperation syncOperation)
        {
            string contentType = GetContentTypeDisplayName(contentItem);

            string operation = syncOperation.ToString("PrP", null);

            _logger.LogError(exception, "{Operation} the '{ContentItem}' {ContentType} has been cancelled because the {GraphReplicaSetName} graph couldn't be updated.",
                             operation, contentItem.DisplayText, contentType, deleteGraphSyncer.GraphReplicaSetName);

            _notifier.Add(GetSyncOperationCancelledUserMessage(syncOperation, contentItem.DisplayText, contentType),
                          $"{operation} the '{contentItem.DisplayText}' {contentType} has been cancelled because the {deleteGraphSyncer.GraphReplicaSetName} graph couldn't be updated.",
                          exception: exception);
        }
예제 #4
0
        public SyncOrchestrator_RestoreTests()
        {
            SyncOperation = SyncOperation.Restore;

            PublishedDeleteGraphSyncer = A.Fake <IDeleteGraphSyncer>();

            A.CallTo(() => PublishedDeleteGraphSyncer.DeleteAllowed(
                         A <ContentItem> ._,
                         A <IContentItemVersion> .That.Matches(v => v.GraphReplicaSetName == GraphReplicaSetNames.Published),
                         SyncOperation,
                         null,
                         null))
            .Returns(PublishedAllowSync);

            A.CallTo(() => ServiceProvider.GetService(A <Type> .That.Matches(
                                                          t => t.Name == (nameof(IMergeGraphSyncer)))))
            .Returns(PreviewMergeGraphSyncer);

            A.CallTo(() => ServiceProvider.GetService(A <Type> .That.Matches(
                                                          t => t.Name == (nameof(IDeleteGraphSyncer)))))
            .Returns(PublishedDeleteGraphSyncer);
        }
 public GraphDeleteContext(ContentItem contentItem,
                           IDeleteNodeCommand deleteNodeCommand,
                           IDeleteGraphSyncer deleteGraphSyncer,
                           SyncOperation syncOperation,
                           ISyncNameProvider syncNameProvider,
                           IContentManager contentManager,
                           IContentItemVersion contentItemVersion,
                           IEnumerable <KeyValuePair <string, object> >?deleteIncomingRelationshipsProperties,
                           IGraphDeleteContext?parentGraphDeleteContext,
                           IServiceProvider serviceProvider)
     : base(
         contentItem,
         syncNameProvider,
         contentManager,
         contentItemVersion,
         parentGraphDeleteContext,
         serviceProvider.GetRequiredService <ILogger <GraphDeleteContext> >())
 {
     DeleteGraphSyncer = deleteGraphSyncer;
     DeleteNodeCommand = deleteNodeCommand;
     SyncOperation     = syncOperation;
     DeleteIncomingRelationshipsProperties = deleteIncomingRelationshipsProperties;
 }