public override TemplateCollection GetTemplates(CallContext context) { #if DEBUG var timer = Stopwatch.StartNew(); #endif var headTemplates = HeadProvider.GetTemplates(context) ?? EmptyTemplates; var readOnlyTemplates = ReadOnlyProviders .SelectMany(x => x .GetTemplates(context) ?? EmptyTemplates); var templates = headTemplates .Concat(readOnlyTemplates) .GroupBy(x => x.ID).Select(x => x.First()) // .Distinct() .ToArray(); var result = new TemplateCollection(); result.Reset(templates); #if DEBUG this.Trace(result, timer, context); #endif return(result); }
private IEnumerable <ID> DoGetChildIDs(ItemDefinition itemDefinition, CallContext context) { var headChildIDs = HeadProvider .GetChildIDs(itemDefinition, context)? .Cast <ID>().ToArray() ?? EmptyIds; var readOnlyChildIDs = ReadOnlyProviders .SelectMany(x => x .GetChildIDs(itemDefinition)? .Select(ID.Parse) ?? EmptyIds); var childIDs = headChildIDs.Concat(readOnlyChildIDs) // .Join() .GroupBy(x => x.Guid).Select(x => x.First()); // .Distinct() // deleted or moved out items must be get off the list var itemId = itemDefinition.ID; foreach (var childID in childIDs) { var parentId = HeadProvider.GetParentID(new ItemDefinition(childID, string.Empty, ID.Null, ID.Null), context); if (ReferenceEquals(parentId, null) || parentId == itemId) { yield return(childID); } } }
public override bool SaveItem([NotNull] ItemDefinition itemDefinition, [NotNull] ItemChanges changes, [NotNull] CallContext context) { Assert.ArgumentNotNull(itemDefinition, nameof(itemDefinition)); Assert.ArgumentNotNull(changes, nameof(changes)); Assert.ArgumentNotNull(context, nameof(context)); #if DEBUG var timer = Stopwatch.StartNew(); #endif if (HeadProvider.GetItemDefinition(itemDefinition.ID, context) == null) { var item = changes.Item; Assert.IsNotNull(item, nameof(item)); if (!MigrateDefaultItem(itemDefinition, item, context)) { return(false); } } var saved = HeadProvider.SaveItem(itemDefinition, changes, context); #if DEBUG this.Trace(saved, timer, itemDefinition.ID, context); #endif return(saved); }
public override IdCollection GetTemplateItemIds(CallContext context) { #if DEBUG var timer = Stopwatch.StartNew(); #endif var result = new IdCollection(); var headIds = HeadProvider.GetTemplateItemIds(context) ?? new IdCollection(); var readOnlyIds = ReadOnlyProviders .SelectMany(x => x .GetTemplateItemIds()? .Select(ID.Parse) ?? EmptyIds); var ids = headIds .Concat(readOnlyIds) .GroupBy(x => x.Guid).Select(x => x.First()) // .Distinct() .ToArray(); result.Add(ids); #if DEBUG this.Trace(result, timer, context); #endif return(result); }
public bool CanBeRemovedFromHead([NotNull] ID itemId) { Assert.ArgumentNotNull(itemId, nameof(itemId)); var dataManager = Database.DataManager; if (HeadProvider.GetItemDefinition(itemId, new CallContext(dataManager, 1)) == null) { return(false); } if (ReadOnlyProviders.All(x => x.GetItemDefinition(itemId) == null)) { return(false); } var itemDefinition = new ItemDefinition(itemId, string.Empty, ID.Undefined, ID.Undefined); foreach (VersionUri version in GetItemVersions(itemDefinition, new CallContext(dataManager, 1))) { var versionUri = new VersionUri(version.Language, version.Version); var actualFields = HeadProvider.GetItemFields(itemDefinition, versionUri, new CallContext(dataManager, 1)); var defaultFields = ReadOnlyProviders.FirstNotNull(x => x.GetItemFields(itemDefinition, versionUri)); if (actualFields?.Count != defaultFields?.Count) { return(false); } foreach (var i in actualFields.FieldValues.Keys.Cast <ID>()) { if ( !defaultFields.FieldValues.Contains(i) || actualFields[i] != defaultFields[i] || false) { return(false); } } foreach (var i in defaultFields.FieldValues.Keys.Cast <ID>()) { if ( !actualFields.FieldValues.Contains(i) || actualFields[i] != defaultFields[i] || false) { return(false); } } } return(true); }
protected override void Initialize() { base.Initialize(); HeadProvider.SetDatabase(Database); foreach (var provider in ReadOnlyProviders) { provider?.SetDatabase(Database); } }
public override bool ChangeFieldSharing(TemplateField fieldDefinition, TemplateFieldSharing sharing, CallContext context) { if (HeadProvider.ChangeFieldSharing(fieldDefinition, sharing, context)) { this.Trace(true, null, context); return(true); } throw new NotImplementedException(); }
public override bool ChangeTemplate(ItemDefinition itemDefinition, TemplateChangeList changes, CallContext context) { this.Trace(true, null, itemDefinition, context); if (HeadProvider.ChangeTemplate(itemDefinition, changes, context)) { return(true); } throw new NotImplementedException(); }
public override void RenameLanguageData(string fromLanguage, string toLanguage, CallContext context) { #if DEBUG var timer = Stopwatch.StartNew(); #endif HeadProvider.RenameLanguageData(fromLanguage, toLanguage, context); #if DEBUG this.Trace(null, timer, fromLanguage, toLanguage, context); #endif }
public override void RemoveLanguageData(Language language, CallContext context) { #if DEBUG var timer = Stopwatch.StartNew(); #endif HeadProvider.RemoveLanguageData(language, context); #if DEBUG this.Trace(null, timer, language, context); #endif }
public override bool DeleteItem(ItemDefinition itemDefinition, CallContext context) { #if DEBUG var timer = Stopwatch.StartNew(); #endif // check if already deleted in head var headParentId = HeadProvider.GetParentID(itemDefinition, context); if (headParentId == ID.Undefined) { #if DEBUG this.Trace(true, timer, itemDefinition.ID, context); #endif return(true); } var itemId = itemDefinition.ID; if (ReadOnlyProviders.FirstNotNull(x => x.GetItemDefinition(itemId)) == null) { // item may only exist in head provider // so we can simply delete it var deleted = HeadProvider.DeleteItem(itemDefinition, context); #if DEBUG this.Trace(deleted, timer, itemDefinition.ID, context); #endif return(deleted); } if (HeadProvider.GetItemDefinition(itemId, context) != null) { // item exists both in read-only data provider and in HEAD // so we first delete it in HEAD HeadProvider.DeleteItem(itemDefinition, context); // and pretend it was only in read-only data provider } // item only exists in read-only data provider // so we create item definition beneath undefied parent var deleted2 = CreateItem(itemId, itemDefinition.Name, itemDefinition.TemplateID, new ItemDefinition(ID.Undefined, "undefined", ID.Null, ID.Null), context); #if DEBUG this.Trace(deleted2, timer, itemDefinition.ID, context); #endif return(deleted2); }
public override bool RemoveVersion(ItemDefinition itemDefinition, VersionUri version, CallContext context) { #if DEBUG var timer = Stopwatch.StartNew(); #endif var removed = HeadProvider.RemoveVersion(itemDefinition, version, context); #if DEBUG this.Trace(removed, timer, itemDefinition, version, context); #endif return(removed); }
public override bool CreateItem(ID itemID, string itemName, ID templateID, ItemDefinition parent, CallContext context) { #if DEBUG var timer = Stopwatch.StartNew(); #endif var isCreated = HeadProvider.CreateItem(itemID, itemName, templateID, parent, context); #if DEBUG this.Trace(isCreated, timer, itemID, itemName, templateID, parent.ID, context); #endif return(isCreated); }
public override bool RemoveVersions(ItemDefinition itemDefinition, Language language, bool removeSharedData, CallContext context) { #if DEBUG var timer = Stopwatch.StartNew(); #endif var removed = HeadProvider.RemoveVersions(itemDefinition, language, removeSharedData, context); #if DEBUG this.Trace(removed, timer, itemDefinition, language, context); #endif return(removed); }
public override Stream GetBlobStream(Guid blobId, CallContext context) { #if DEBUG var timer = Stopwatch.StartNew(); #endif var stream = HeadProvider.GetBlobStream(blobId, context); #if DEBUG this.Trace(stream, timer, blobId, context); #endif return(stream); }
public override int AddVersion(ItemDefinition itemDefinition, VersionUri baseVersion, CallContext context) { #if DEBUG var timer = Stopwatch.StartNew(); #endif var version = HeadProvider.AddVersion(itemDefinition, baseVersion, context); #if DEBUG this.Trace(version, timer, itemDefinition, baseVersion, context); #endif return(version); }
public override bool RemoveBlobStream(Guid blobId, CallContext context) { #if DEBUG var timer = Stopwatch.StartNew(); #endif var removed = HeadProvider.RemoveBlobStream(blobId, context); #if DEBUG this.Trace(removed, timer, blobId, context); #endif return(removed); }
/* Media part of DataProvider */ public override bool BlobStreamExists(Guid blobId, CallContext context) { #if DEBUG var timer = Stopwatch.StartNew(); #endif var exists = HeadProvider.BlobStreamExists(blobId, context); #if DEBUG this.Trace(exists, timer, blobId, context); #endif return(exists); }
public override bool SetBlobStream(Stream stream, Guid blobId, CallContext context) { #if DEBUG var timer = Stopwatch.StartNew(); #endif var set = HeadProvider.SetBlobStream(stream, blobId, context); #if DEBUG this.Trace(set, timer, stream, blobId, context); #endif return(set); }
/* Items.ItemTree part of DataProvider */ public override ItemDefinition GetItemDefinition(ID itemId, CallContext context) { #if DEBUG var timer = Stopwatch.StartNew(); #endif var definition = HeadProvider.GetItemDefinition(itemId, context) ?? ReadOnlyProviders.FirstNotNull(x => x.GetItemDefinition(itemId)); #if DEBUG this.Trace(definition, timer, itemId, context); #endif return(definition); }
public override bool HasChildren(ItemDefinition itemDefinition, CallContext context) { #if DEBUG var timer = Stopwatch.StartNew(); #endif var hasChildren = HeadProvider.HasChildren(itemDefinition, context) || // speed optimization DoGetChildIDs(itemDefinition, context).Any(); #if DEBUG this.Trace(hasChildren, timer, itemDefinition, context); #endif return(hasChildren); }
public override ID GetParentID(ItemDefinition itemDefinition, CallContext context) { #if DEBUG var timer = Stopwatch.StartNew(); #endif var parentId = HeadProvider.GetParentID(itemDefinition, context) ?? ReadOnlyProviders.FirstNotNull(x => x.GetParentID(itemDefinition)); #if DEBUG this.Trace(parentId, timer, itemDefinition, context); #endif return(parentId); }
/* Items.ItemData part of DataProvider */ public override FieldList GetItemFields(ItemDefinition itemDefinition, VersionUri versionUri, CallContext context) { #if DEBUG var timer = Stopwatch.StartNew(); #endif var itemFields = HeadProvider.GetItemFields(itemDefinition, versionUri, context) ?? ReadOnlyProviders.FirstNotNull(x => x.GetItemFields(itemDefinition, versionUri)); // do not print fields #if DEBUG this.Trace(null, timer, itemDefinition, versionUri, context); #endif return(itemFields); }
public override bool CopyItem(ItemDefinition source, ItemDefinition destination, string copyName, ID copyID, CallContext context) { #if DEBUG this.Trace(true, null, source.ID, destination.ID, copyName, copyID, context); #endif // source item is in head provider if (HeadProvider.GetItemDefinition(source.ID, context) != null) { if (HeadProvider.CopyItem(source, destination, copyName, copyID, context)) { return(true); } } var database = context.DataManager.Database; var itemId = source.ID; using (new SecurityDisabler()) { var item = database.GetItem(itemId); Assert.IsNotNull(item, nameof(item)); using (var limit = new RecursionLimit($"{nameof(CopyItem)}-{item.ID}-{destination.ID}", 1)) { if (limit.Exceeded) { return(true); } var defaultOptions = ItemSerializerOptions.GetDefaultOptions(); defaultOptions.AllowDefaultValues = false; // TODO: needs checking defaultOptions.AllowStandardValues = false; defaultOptions.IncludeBlobFields = true; defaultOptions.ProcessChildren = true; // TODO: slow, needs optimization var outerXml = item.GetOuterXml(defaultOptions); var target = database.GetItem(destination.ID); Assert.IsNotNull(target, nameof(target)); target.Paste(outerXml, true, PasteMode.Overwrite); Log.Audit(this, "Default item {0} ({1}) was copied to {2} in head provider", item.Name, item.ID.ToString(), destination.ID.ToString()); return(true); } } }
public override VersionUriList GetItemVersions(ItemDefinition itemDefinition, CallContext context) { #if DEBUG var timer = Stopwatch.StartNew(); #endif var headList = HeadProvider.GetItemVersions(itemDefinition, context); if (headList != null && headList.Count > 0) { return(headList); } var itemVersions = ReadOnlyProviders.Select(provider => provider.GetItemVersions(itemDefinition)) .FirstOrDefault(list => list != null && list.Count > 0); #if DEBUG this.Trace(itemVersions, timer, itemDefinition, context); #endif return (itemVersions ?? new VersionUriList()); }
private ID ResolvePath(ID parentId, string[] pathSegments, int segmentIndex, CallContext context) { if (segmentIndex >= pathSegments.Length) { return(parentId); } var segmentName = pathSegments[segmentIndex]; foreach (var provider in ReadOnlyProviders) { var children = provider.GetChildIdsByName(segmentName, parentId); if (children == null) { continue; } foreach (var childId in children) { // TODO: refactor that in kernel var headParentId = HeadProvider.GetParentID(new ItemDefinition(childId, "--fake--", ID.Null, ID.Null), context); if (headParentId != (ID)null && headParentId != parentId) { continue; } var pathId = ResolvePath(childId, pathSegments, segmentIndex + 1, context); if (pathId == (ID)null) { continue; } return(pathId); } } return(ResolveHeadPath(parentId, pathSegments, segmentIndex, context)); }
public override LanguageCollection GetLanguages(CallContext context) { #if DEBUG var timer = Stopwatch.StartNew(); #endif var languages = ReadOnlyProviders.SelectMany(x => x.GetLanguages() ?? EmptyLanguages); var headLanguages = HeadProvider.GetLanguages(context); if (headLanguages != null) { languages = languages.Concat(headLanguages); } languages = languages .GroupBy(x => x.Name).Select(x => x.First()) // .Distinct() .OrderByDescending(x => x.Name == "en"); // en must go first #if DEBUG this.Trace(languages, timer, context); #endif return(new LanguageCollection(languages)); }
public override bool MoveItem([NotNull] ItemDefinition itemDefinition, [NotNull] ItemDefinition destination, [NotNull] CallContext context) { Assert.ArgumentNotNull(itemDefinition, nameof(itemDefinition)); Assert.ArgumentNotNull(destination, nameof(destination)); Assert.ArgumentNotNull(context, nameof(context)); #if DEBUG var timer = Stopwatch.StartNew(); #endif if (HeadProvider.GetItemDefinition(itemDefinition.ID, context) == null) { using (new SecurityDisabler()) { var item = context.DataManager.Database.GetItem(itemDefinition.ID); Assert.IsNotNull(item, nameof(item)); if (!MigrateDefaultItem(itemDefinition, item, context)) { #if DEBUG this.Trace(false, timer, itemDefinition.ID, destination.ID, context); #endif return(false); } } } var moved = HeadProvider.MoveItem(itemDefinition, destination, context); #if DEBUG this.Trace(moved, timer, itemDefinition.ID, destination.ID, context); #endif return(moved); }
/* Properties part of DataProvider */ public override string GetProperty(string name, CallContext context) { return(HeadProvider.GetProperty(name, context)); }
protected override EventQueue DoGetEventQueue() { return(HeadProvider.GetEventQueue()); }