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
        }
Ejemplo n.º 2
0
        public GraphMergeContext(
            IMergeGraphSyncer mergeGraphSyncer,
            ISyncNameProvider syncNameProvider,
            IGraphReplicaSet graphReplicaSet,
            IMergeNodeCommand mergeNodeCommand,
            IReplaceRelationshipsCommand replaceRelationshipsCommand,
            ContentItem contentItem,
            IContentManager contentManager,
            IContentItemVersionFactory contentItemVersionFactory,
            IGraphMergeContext?parentGraphMergeContext,
            IServiceProvider serviceProvider)
            : base(
                contentItem,
                syncNameProvider,
                contentManager,
                contentItemVersionFactory.Get(graphReplicaSet.Name),
                parentGraphMergeContext,
                serviceProvider.GetRequiredService <ILogger <GraphMergeContext> >())
        {
            MergeGraphSyncer            = mergeGraphSyncer;
            GraphReplicaSet             = graphReplicaSet;
            MergeNodeCommand            = mergeNodeCommand;
            ReplaceRelationshipsCommand = replaceRelationshipsCommand;

            ExtraCommands = new List <ICommand>();
        }
        private async Task Sync(IEnumerable <ContentItem> contentItems, IGraphReplicaSet graphReplicaSet)
        {
            foreach (ContentItem contentItem in contentItems)
            {
                IMergeGraphSyncer mergeGraphSyncer = _serviceProvider.GetRequiredService <IMergeGraphSyncer>();

                //todo: we need to better handle disallowed and failed syncs
                // can we cancel the part/field detachment?
                //todo: support many items being updated in a transaction
                await mergeGraphSyncer.SyncToGraphReplicaSetIfAllowed(graphReplicaSet, contentItem, _contentManager);
            }
        }