private async Task SyncToPreviewGraph(ContentItem contentItem)
        {
            // sonar can't see that the set value could be used in the event of an exception
            #pragma warning disable S1854
            AllowSyncResult allowSyncResult = AllowSyncResult.Blocked;
            string          message         = $"Unable to sync '{contentItem.DisplayText}' Page to {GraphReplicaSetNames.Preview} graph(s).";

            try
            {
                IMergeGraphSyncer mergeGraphSyncer = _serviceProvider.GetRequiredService <IMergeGraphSyncer>();
                IContentManager   contentManager   = _serviceProvider.GetRequiredService <IContentManager>();
                IAllowSync        allowSync        = await mergeGraphSyncer.SyncToGraphReplicaSetIfAllowed(
                    _graphCluster.GetGraphReplicaSet(GraphReplicaSetNames.Preview), contentItem, contentManager);

                allowSyncResult = allowSync.Result;
            }
            catch (Exception exception)
            {
                _logger.LogError(exception, "Unable to sync '{ContentItemDisplayText}' Page to {GraphReplicaSetName} graph(s).",
                                 contentItem.DisplayText, GraphReplicaSetNames.Preview);
            }

            if (allowSyncResult == AllowSyncResult.Blocked)
            {
                _notifier.Add(NotifyType.Error, new LocalizedHtmlString(nameof(DefaultPageLocationsContentHandler), message));
            }
            #pragma warning restore S1854
        }
示例#2
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;
            }
        }
        public void AddRelated(IAllowSync allowSync)
        {
            if (allowSync.Result != AllowSyncResult.Blocked)
            {
                return;
            }

            Result       = AllowSyncResult.Blocked;
            SyncBlockers = new ConcurrentBag <ISyncBlocker>(SyncBlockers.Union(allowSync.SyncBlockers));
        }
示例#4
0
        private async Task <List <CommandRelationship> > GetRequiredRelationshipsAndOptionallySync(
            JArray?contentItems,
            IGraphMergeContext context,
            IAllowSync?allowSync = null)
        {
            ContentItem[] embeddedContentItems = ConvertToContentItems(contentItems);

            List <CommandRelationship> requiredRelationships = new List <CommandRelationship>();

            int relationshipOrdinal = 0;

            foreach (ContentItem contentItem in embeddedContentItems)
            {
                IMergeGraphSyncer?mergeGraphSyncer;

                if (allowSync == null)
                {
                    // we're actually syncing, not checking if it's allowed
                    mergeGraphSyncer = await context.MergeGraphSyncer.SyncEmbedded(contentItem);
                }
                else
                {
                    mergeGraphSyncer = GetNewMergeGraphSyncer();

                    IAllowSync embeddedAllowSync = await mergeGraphSyncer.SyncAllowed(context.GraphReplicaSet, contentItem, context.ContentManager, context);

                    allowSync.AddRelated(embeddedAllowSync);
                    if (embeddedAllowSync.Result != AllowSyncResult.Allowed)
                    {
                        continue;
                    }
                }

                //todo: check embedded items with no graphsyncpart attached
                if (mergeGraphSyncer == null)
                {
                    continue;
                }

                IMergeNodeCommand containedContentMergeNodeCommand = mergeGraphSyncer.MergeNodeCommand;
                containedContentMergeNodeCommand.CheckIsValid();

                string relationshipType = await RelationshipType(contentItem.ContentType);

                var properties = await GetRelationshipProperties(contentItem, relationshipOrdinal, context.SyncNameProvider);

                ++relationshipOrdinal;

                requiredRelationships.Add(new CommandRelationship(
                                              relationshipType,
                                              await TwoWayIncomingRelationshipType(contentItem.ContentType),
                                              properties,
                                              containedContentMergeNodeCommand.NodeLabels,
                                              containedContentMergeNodeCommand.IdPropertyName !,
                                              Enumerable.Repeat(containedContentMergeNodeCommand.Properties[containedContentMergeNodeCommand.IdPropertyName !], 1)));
示例#5
0
        public async Task <IAllowSync> SyncToGraphReplicaSetIfAllowed(
            IGraphReplicaSet graphReplicaSet,
            ContentItem contentItem,
            IContentManager contentManager,
            IGraphMergeContext?parentGraphMergeContext = null)
        {
            IAllowSync allowSync = await SyncAllowed(graphReplicaSet, contentItem, contentManager, parentGraphMergeContext);

            if (allowSync.Result == AllowSyncResult.Allowed)
            {
                await SyncToGraphReplicaSet();
            }

            return(allowSync);
        }
        public override async Task AllowSync(
            JArray?contentItems,
            IGraphMergeContext context,
            IAllowSync allowSync)
        {
            IAllowSync baseAllowSync = new AllowSync();
            await base.AllowSync(contentItems, context, baseAllowSync);

            var baseBlockersWithoutIncomingTaxonomyBlocker =
                baseAllowSync.SyncBlockers.Where(sb => sb.ContentType != "Taxonomy");

            if (baseBlockersWithoutIncomingTaxonomyBlocker.Any())
            {
                allowSync.AddSyncBlockers(baseBlockersWithoutIncomingTaxonomyBlocker);
            }
        }
        public async Task <IAllowSync> DeleteIfAllowed(
            ContentItem contentItem,
            IContentItemVersion contentItemVersion,
            SyncOperation syncOperation,
            IEnumerable <KeyValuePair <string, object> >?deleteIncomingRelationshipsProperties = null)
        {
            IAllowSync allowSync = await DeleteAllowed(
                contentItem,
                contentItemVersion,
                syncOperation,
                deleteIncomingRelationshipsProperties);

            if (allowSync.Result == AllowSyncResult.Allowed)
            {
                await Delete();
            }

            return(allowSync);
        }
 public override Task AllowSync(JObject content, IGraphMergeContext context, IAllowSync allowSync)
 {
     return(Task.WhenAll(
                base.AllowSync(content, context, allowSync),
                _contentFieldsGraphSyncer.AllowSync(content, context, allowSync)));
 }
示例#9
0
 public async Task AllowDelete(IGraphDeleteItemSyncContext context, IAllowSync allowSync)
 {
     await IteratePartSyncers(context,
                              async (partSyncer, partContent) => await partSyncer.AllowDelete(partContent, context, allowSync));
 }
示例#10
0
 public async Task AllowSync(IGraphMergeItemSyncContext context, IAllowSync allowSync)
 {
     await IteratePartSyncers(context,
                              async (partSyncer, partContent) => await partSyncer.AllowSync(partContent, context, allowSync),
                              async (partSyncer, partContent) => await partSyncer.AllowSyncDetaching(context, allowSync));
 }
示例#11
0
 public override async Task AllowSync(JObject content, IGraphMergeContext context, IAllowSync allowSync)
 {
     await _contentFieldsGraphSyncer.AllowSync(content, context, allowSync);
 }
示例#12
0
 public virtual Task AllowSyncDetaching(IGraphMergeContext context, IAllowSync allowSync)
 {
     return(Task.CompletedTask);
 }
示例#13
0
        public virtual async Task AllowSync(
            JArray?contentItems,
            IGraphMergeContext context,
            IAllowSync allowSync)
        {
            _logger.LogDebug("Do embedded items allow sync?");

            List <CommandRelationship> requiredRelationships = await GetRequiredRelationshipsAndOptionallySync(contentItems, context, allowSync);

            INodeAndOutRelationshipsAndTheirInRelationships?existing = (await context.GraphReplicaSet.Run(
                                                                            new NodeAndOutRelationshipsAndTheirInRelationshipsQuery(
                                                                                context.ReplaceRelationshipsCommand.SourceNodeLabels,
                                                                                context.ReplaceRelationshipsCommand.SourceIdPropertyName !,
                                                                                context.ReplaceRelationshipsCommand.SourceIdPropertyValue !)))
                                                                       .FirstOrDefault();

            if (existing?.OutgoingRelationships.Any() != true)
            {
                // nothing to do here, node is being newly created or existing node has no relationships
                return;
            }

            (string[] embeddableContentTypes, IEnumerable <string> relationshipTypes) =
                await GetEmbeddableContentTypesAndRelationshipTypes(context);

            existing = new NodeAndOutRelationshipsAndTheirInRelationships(
                existing.SourceNode,
                existing.OutgoingRelationships
                .Where(or =>
                       embeddableContentTypes.Contains(
                           context.SyncNameProvider.GetContentTypeFromNodeLabels(
                               or.outgoingRelationship.DestinationNode.Labels)) &&
                       relationshipTypes.Contains(or.outgoingRelationship.Relationship.Type)));

            IEnumerable <CommandRelationship> existingRelationshipsForEmbeddableContentTypes =
                existing.ToCommandRelationships(context.SyncNameProvider);

            _removingRelationships = GetRemovingRelationships(
                existingRelationshipsForEmbeddableContentTypes,
                requiredRelationships,
                context.SyncNameProvider);

            if (!_removingRelationships.Any())
            {
                // nothing to do here, not removing any relationships
                return;
            }

            foreach (var removingRelationship in _removingRelationships)
            {
                foreach (object destinationNodeIdPropertyValue in removingRelationship.DestinationNodeIdPropertyValues)
                {
                    var existingForRemoving = existing.OutgoingRelationships
                                              .Where(er =>
                                                     er.outgoingRelationship.DestinationNode.Properties[
                                                         context.SyncNameProvider.IdPropertyName(
                                                             context.SyncNameProvider.GetContentTypeFromNodeLabels(
                                                                 er.outgoingRelationship.DestinationNode.Labels))] ==
                                                     destinationNodeIdPropertyValue);

                    var nonTwoWayIncomingRelationshipsToEmbeddedItems = existingForRemoving
                                                                        .SelectMany(or => or.incomingRelationships) //todo: null or throws?
                                                                        .Where(ir => !ir.Relationship.Properties.ContainsKey(
                                                                                   NodeWithOutgoingRelationshipsCommand.TwoWayRelationshipPropertyName));

                    allowSync.AddSyncBlockers(
                        nonTwoWayIncomingRelationshipsToEmbeddedItems.Select(r =>
                    {
                        string contentType =
                            context.SyncNameProvider.GetContentTypeFromNodeLabels(r.DestinationNode.Labels);
                        return(new SyncBlocker(
                                   contentType,
                                   r.DestinationNode.Properties[context.SyncNameProvider.IdPropertyName(contentType)],
                                   (string?)r.DestinationNode.Properties[TitlePartGraphSyncer.NodeTitlePropertyName]));
                    }));
                }
            }
        }
示例#14
0
 public Task AllowDelete(IGraphDeleteItemSyncContext context, IAllowSync allowSync)
 {
     return(_taxonomyPartGraphSyncer.AllowDelete(context.ContentItem.Content, context, allowSync));
 }
 public override Task AllowDelete(JObject content, IGraphDeleteContext context, IAllowSync allowSync)
 {
     return(_embeddedContentItemsGraphSyncer.AllowDelete((JArray?)content[ContainerName], context, allowSync));
 }
 public override Task AllowSyncDetaching(IGraphMergeContext context, IAllowSync allowSync)
 {
     return(_embeddedContentItemsGraphSyncer.AllowSyncDetaching(context, allowSync));
 }
示例#17
0
 public virtual Task AllowDelete(JObject content, IGraphDeleteContext context, IAllowSync allowSync)
 {
     return(Task.CompletedTask);
 }