public async Task <IMergeGraphSyncer?> SyncEmbedded(ContentItem contentItem) { _logger.LogDebug("Syncing embedded {ContentItem}.", contentItem.ToString()); JObject?graphSyncPartContent = (JObject?)contentItem.Content[nameof(GraphSyncPart)]; if (graphSyncPartContent == null) { return(null); } var embeddedMergeContext = _graphMergeContext !.ChildContexts .Single(c => c.ContentItem.ContentItemId == contentItem.ContentItemId); _logger.LogDebug("Found existing GraphMergeContext for {ContentItem}.", contentItem.ToString()); var embeddedMergeGraphSyncer = (MergeGraphSyncer)embeddedMergeContext.MergeGraphSyncer; if (!embeddedMergeGraphSyncer._syncNameProvider.GraphSyncPartSettings.PreexistingNode) { await((MergeGraphSyncer)embeddedMergeContext.MergeGraphSyncer).SyncEmbedded(); } return(embeddedMergeGraphSyncer); }
protected override void OnInit(EventArgs e) { selectedItem = Selection.SelectedItem; if (selectedItem != null) { itemsToDelete.CurrentItem = selectedItem; itemsToDelete.DataBind(); if (String.IsNullOrEmpty(selectedItem.Title)) _title = selectedItem.ToString(); // TODO see edit.aspx InitTitle else _title = selectedItem.Title; ParameterCollection query = Parameter.Equal("State", ContentState.Deleted); if (selectedItem.ID != 0) query &= (Parameter.Like(LinkTracker.Tracker.LinkDetailName, selectedItem.Url).Detail() | Parameter.Equal(null, selectedItem).Detail()); else query &= Parameter.Like(LinkTracker.Tracker.LinkDetailName, selectedItem.Url).Detail(); var count = Engine.Persister.Repository.Count(query); if (count > 0) { chkAllow.Text += " (" + count + ")"; rptReferencing.DataSource = Engine.Persister.Repository.Find(query.Take(10)).Where(Content.Is.Distinct()); rptReferencing.DataBind(); hlReferencingItems.Visible = (count > 10); } else referencingItems.Visible = false; this.hlReferencingItems.NavigateUrl = "Dependencies.aspx?" + SelectionUtility.SelectedQueryKey + "=" + selectedItem.Path + "&returnUrl=" + Server.HtmlEncode(Request.RawUrl); } base.OnInit(e); }
private async Task <Result <List <ManifestFile> > > VerifyAllFiles(ContentItem contentItem, CancellationToken cancellationToken) { return(await _contentFileVerifier.EnsureDirectoryExists(contentItem) .Bind(x => GetManifest(x, cancellationToken)) // TODO: Move redundant files removing out of verification, returning redundant files should be separate from removing them. .Tap(_ => _logger.LogTrace("Searching redundant files for {Item}", contentItem.ToString())) .Tap(x => _contentFileVerifier.RemoveRedundantFiles(contentItem.Directory !, x)) .Tap(_ => _logger.LogTrace("Searching outdated files for {Item}", contentItem.ToString())) .Bind(manifest => IsAnyFileOutdated(contentItem, manifest))); }
private void WriteChildrenRecursive(ContentItem contentItem) { contentItem.HasChildren = contentItem.Children.Any() ? true : false; File.AppendAllText(filename, contentItem.ToString() + "\r\n"); if (contentItem.Children == null) { return; } foreach (var child in contentItem.Children) { WriteChildrenRecursive(child); } }
/// <returns>false if deleting from either graph was blocked.</returns> public async Task <bool> Delete(ContentItem contentItem) { // we could be more selective deciding which replica set to delete from, // but the context doesn't seem to be there, and our delete is idempotent _logger.LogDebug("Delete: Removing '{ContentItem}' {ContentType} from Published and/or Preview.", contentItem.ToString(), contentItem.ContentType); var deleteGraphSyncers = await Task.WhenAll( GetDeleteGraphSyncerIfDeleteAllowed( contentItem, _publishedContentItemVersion, SyncOperation.Delete), GetDeleteGraphSyncerIfDeleteAllowed( contentItem, _previewContentItemVersion, SyncOperation.Delete)); (IAllowSync publishedAllowSync, IDeleteGraphSyncer? publishedDeleteGraphSyncer) = deleteGraphSyncers[0]; (IAllowSync previewAllowSync, IDeleteGraphSyncer? previewDeleteGraphSyncer) = deleteGraphSyncers[1]; if (publishedAllowSync.Result == AllowSyncResult.Blocked || previewAllowSync.Result == AllowSyncResult.Blocked) { var graphBlockers = new List <(string GraphReplicaSetName, IAllowSync AllowSyncResult)>(); if (publishedAllowSync.Result == AllowSyncResult.Blocked) { graphBlockers.Add((_publishedContentItemVersion.GraphReplicaSetName, publishedAllowSync)); } if (previewAllowSync.Result == AllowSyncResult.Blocked) { graphBlockers.Add((_previewContentItemVersion.GraphReplicaSetName, previewAllowSync)); } await _notifier.AddBlocked(SyncOperation.Delete, contentItem, graphBlockers); return(false); } // the preview graph contains a superset of the published graph, // so we try deleting from the preview graph first, and only move onto published // if the preview sync worked //todo: add any failure checks into allow check await DeleteFromGraphReplicaSet(previewDeleteGraphSyncer !, contentItem, SyncOperation.Delete); await DeleteFromGraphReplicaSet(publishedDeleteGraphSyncer !, contentItem, SyncOperation.Delete); await CallContentOrchestrationHandlers(contentItem, async (handler, context) => await handler.Deleted(context)); return(true); }
protected override void OnInit(EventArgs e) { selectedItem = Selection.SelectedItem; if (selectedItem != null) { itemsToDelete.CurrentItem = selectedItem; itemsToDelete.DataBind(); if (String.IsNullOrEmpty(selectedItem.Title)) { _title = selectedItem.ToString(); // TODO see edit.aspx InitTitle } else { _title = selectedItem.Title; } ParameterCollection query = Parameter.Equal("State", ContentState.Deleted); if (selectedItem.ID != 0) { query &= (Parameter.Like(LinkTracker.Tracker.LinkDetailName, selectedItem.Url).Detail() | Parameter.Equal(null, selectedItem).Detail()); } else { query &= Parameter.Like(LinkTracker.Tracker.LinkDetailName, selectedItem.Url).Detail(); } var count = Engine.Persister.Repository.Count(query); if (count > 0) { chkAllow.Text += " (" + count + ")"; rptReferencing.DataSource = Engine.Persister.Repository.Find(query.Take(10)).Where(Content.Is.Distinct()); rptReferencing.DataBind(); hlReferencingItems.Visible = (count > 10); } else { referencingItems.Visible = false; } this.hlReferencingItems.NavigateUrl = "Dependencies.aspx?" + SelectionUtility.SelectedQueryKey + "=" + selectedItem.Path + "&returnUrl=" + Server.HtmlEncode(Request.RawUrl); } base.OnInit(e); }
/// <returns>false if unpublish to publish graph was blocked.</returns> public async Task <bool> Unpublish(ContentItem contentItem) { _logger.LogDebug("Unpublish: Removing '{ContentItem}' {ContentType} from Published.", contentItem.ToString(), contentItem.ContentType); // no need to touch the draft graph, there should always be a valid version in there // (either a separate draft version, or the published version) if (!await DeleteFromGraphReplicaSetIfAllowed( contentItem, _publishedContentItemVersion, SyncOperation.Unpublish)) { return(false); } await CallContentOrchestrationHandlers(contentItem, async (handler, context) => await handler.Unpublished(context)); return(true); }
public async Task <bool> Restore(ContentItem contentItem) { _logger.LogDebug("Restore: Syncing '{ContentItem}' {ContentType} to Preview and deleting from Published.", contentItem.ToString(), contentItem.ContentType); IContentManager contentManager = _serviceProvider.GetRequiredService <IContentManager>(); //todo: could/should we use WhenAll? (IAllowSync previewAllowSync, IMergeGraphSyncer? previewMergeGraphSyncer) = await GetMergeGraphSyncerIfSyncAllowed( SyncOperation.Restore, GraphReplicaSetNames.Preview, contentItem, contentManager); if (previewAllowSync.Result == AllowSyncResult.Blocked) { await _notifier.AddBlocked( SyncOperation.Restore, contentItem, new[] { (GraphReplicaSetNames.Preview, previewAllowSync) });
public async Task <IAllowSync> SyncAllowed( IGraphReplicaSet graphReplicaSet, ContentItem contentItem, IContentManager contentManager, IGraphMergeContext?parentGraphMergeContext = null) { _logger.LogDebug("SyncAllowed to {GraphReplicaSetName} for '{ContentItem}' {ContentType}?", graphReplicaSet.Name, contentItem.ToString(), contentItem.ContentType); _logger.LogDebug("ContentItem content: {Content}", ((JObject)contentItem.Content).ToString()); // we use the existence of a GraphSync content part as a marker to indicate that the content item should be synced JObject?graphSyncPartContent = (JObject?)contentItem.Content[nameof(GraphSyncPart)]; if (graphSyncPartContent == null) { return(AllowSync.NotRequired); } //todo: ContentType belongs in the context, either combine helper & context, or supply context to helper? _syncNameProvider.ContentType = contentItem.ContentType; _graphMergeContext = new GraphMergeContext( this, _syncNameProvider, graphReplicaSet, MergeNodeCommand, _replaceRelationshipsCommand, contentItem, contentManager, _contentItemVersionFactory, parentGraphMergeContext, _serviceProvider); await PopulateMergeNodeCommand(graphSyncPartContent); SetSourceNodeInReplaceRelationshipsCommand(); //should it go in the context? _incomingPreviewContentPickerRelationships = await GetIncomingPreviewContentPickerRelationshipsWhenPublishing( graphReplicaSet, graphSyncPartContent, contentItem.ContentItemId); return(await SyncAllowed()); }