public void ContentIdentitiesAreEncodedWhenOutput() { var identity1 = new ContentIdentity("/foo=bar"); Assert.That(identity1.ToString(), Is.EqualTo("/foo=bar")); var identity2 = new ContentIdentity(@"/foo=bar/abaz=quux\/fr\\ed=foo/yarg=yiu=foo"); Assert.That(identity2.Get("foo"), Is.EqualTo("bar")); Assert.That(identity2.Get("abaz"), Is.EqualTo(@"quux/fr\ed=foo")); Assert.That(identity2.Get("yarg"), Is.EqualTo("yiu=foo")); Assert.That(identity2.ToString(), Is.EqualTo(@"/abaz=quux\/fr\\ed=foo/foo=bar/yarg=yiu=foo")); }
public void ContentIdentitiesAreEncodedWhenOutput() { var identity1 = new ContentIdentity("/foo=bar"); Assert.That(identity1.ToString(), Is.EqualTo("/foo=bar")); var identity2 = new ContentIdentity(@"/foo=bar/abaz=quux\/fr\\ed=foo/yarg=yiu=foo"); Assert.That(identity2.Get("foo"), Is.EqualTo("bar")); Assert.That(identity2.Get("abaz"), Is.EqualTo(@"quux/fr\ed=foo")); Assert.That(identity2.Get("yarg"), Is.EqualTo("yiu=foo")); Assert.That(identity2.ToString(), Is.EqualTo(@"/foo=bar/abaz=quux\/fr\\ed=foo/yarg=yiu=foo")); }
protected override void Importing(CommonPart part, ImportContentContext context) { // Don't do anything if the tag is not specified. if (context.Data.Element(part.PartDefinition.Name) == null) { return; } context.ImportAttribute(part.PartDefinition.Name, "Owner", owner => { var contentIdentity = new ContentIdentity(owner); // use the super user if the referenced one doesn't exist; part.Owner = _membershipService.GetUser(contentIdentity.Get("User.UserName")) ?? _membershipService.GetUser(Services.WorkContext.CurrentSite.SuperUser); }); context.ImportAttribute(part.PartDefinition.Name, "Container", container => part.Container = context.GetItemFromSession(container) ); context.ImportAttribute(part.PartDefinition.Name, "CreatedUtc", createdUtc => part.CreatedUtc = XmlConvert.ToDateTime(createdUtc, XmlDateTimeSerializationMode.Utc) ); context.ImportAttribute(part.PartDefinition.Name, "PublishedUtc", publishedUtc => part.PublishedUtc = XmlConvert.ToDateTime(publishedUtc, XmlDateTimeSerializationMode.Utc) ); context.ImportAttribute(part.PartDefinition.Name, "ModifiedUtc", modifiedUtc => part.ModifiedUtc = XmlConvert.ToDateTime(modifiedUtc, XmlDateTimeSerializationMode.Utc) ); }
public void ContentIdentityParsesIdentities() { var identity1 = new ContentIdentity("/foo=bar"); Assert.That(identity1.Get("foo"), Is.EqualTo("bar")); var identity2 = new ContentIdentity("/foo="); Assert.That(identity2.Get("foo"), Is.EqualTo(String.Empty)); var identity3 = new ContentIdentity("foo"); Assert.That(identity3.Get("foo"), Is.Null); }
private IEnumerable<ContentItem> ResolveIdentity(ContentIdentity identity) { var packageVersionId = identity.Get("package-version-id"); if (packageVersionId == null) { return null; } return _contentManager .Query<PackageVersionPart, PackageVersionPartRecord>(VersionOptions.Latest) .Where(p => p.PackageVersionId == packageVersionId) .List<ContentItem>(); }
private IEnumerable<ContentItem> ResolveIdentity(ContentIdentity identity) { var identifier = identity.Get("alias"); if (identifier == null) { return null; } return _contentManager .Query<AutoroutePart, AutoroutePartRecord>() .Where(p => p.DisplayAlias == identifier) .List<ContentItem>(); }
private IEnumerable<ContentItem> ResolveIdentity(ContentIdentity identity) { var identifier = identity.Get("User.UserName"); if (identifier == null) { return null; } return _contentManager .Query<UserPart, UserPartRecord>() .Where(p => p.NormalizedUserName == identifier) .List<ContentItem>(); }
private IEnumerable <ContentItem> ResolveIdentity(ContentIdentity identity) { var packageVersionId = identity.Get("package-version-id"); if (packageVersionId == null) { return(null); } return(_contentManager .Query <PackageVersionPart, PackageVersionPartRecord>(VersionOptions.Latest) .Where(p => p.PackageVersionId == packageVersionId) .List <ContentItem>()); }
private IEnumerable<ContentItem> ResolveIdentity(ContentIdentity identity) { var identifier = identity.Get("User.UserName"); if (identifier == null) { return null; } var comparer = new ContentIdentity.ContentIdentityEqualityComparer(); return _contentManager .Query<UserPart, UserPartRecord>() .Where(p => p.UserName == identifier) .List<ContentItem>() .Where(c => comparer.Equals(identity, _contentManager.GetItemMetadata(c).Identity)); }
public void ContentIdentityParsesIdentities() { var identity1 = new ContentIdentity("/foo=bar"); Assert.That(identity1.Get("foo"), Is.EqualTo("bar")); var identity2 = new ContentIdentity("/foo="); Assert.That(identity2.Get("foo"), Is.EqualTo(String.Empty)); var identity3 = new ContentIdentity("foo"); Assert.That(identity3.Get("foo"), Is.Null); }
private IEnumerable <ContentItem> ResolveIdentity(ContentIdentity identity) { var identifier = identity.Get("alias"); if (identifier == null) { return(null); } return(_contentManager .Query <AutoroutePart, AutoroutePartRecord>(VersionOptions.Latest) .Where(p => p.DisplayAlias == identifier) .List <ContentItem>()); }
private IEnumerable<ContentItem> ResolveIdentity(ContentIdentity identity) { var identifier = identity.Get("Layer.LayerName"); if (identifier == null) { return null; } return _contentManager .Query<LayerPart, LayerPartRecord>() .Where(p => p.Name == identifier) .List<ContentItem>() .Where(c => ContentIdentity.ContentIdentityEqualityComparer.AreEquivalent( identity, _contentManager.GetItemMetadata(c).Identity)); }
private IEnumerable<ContentItem> ResolveIdentity(ContentIdentity identity) { var identifier = identity.Get("Identifier"); if (identifier == null) { return null; } return _contentManager .Query<IdentityPart, IdentityPartRecord>(VersionOptions.Latest) .Where(p => p.Identifier == identifier) .List<ContentItem>() .Where(c => ContentIdentity.ContentIdentityEqualityComparer.AreEquivalent( identity, _contentManager.GetItemMetadata(c).Identity)); }
private IEnumerable <ContentItem> ResolveIdentity(ContentIdentity identity) { var identifier = identity.Get("User.UserName"); if (identifier == null) { return(null); } return(_contentManager .Query <UserPart, UserPartRecord>() .Where(p => p.NormalizedUserName == identifier) .List <ContentItem>()); }
private IEnumerable <ContentItem> ResolveIdentity(ContentIdentity identity) { var identifier = identity.Get("User.UserName"); if (identifier == null) { return(null); } return(_contentManager .Query <UserPart, UserPartRecord>(VersionOptions.Latest) .Where(p => p.UserName == identifier) .List <ContentItem>() .Where(c => ContentIdentity.ContentIdentityEqualityComparer.AreEquivalent( identity, _contentManager.GetItemMetadata(c).Identity))); }
private IEnumerable <ContentItem> ResolveIdentity(ContentIdentity identity) { var identifier = identity.Get("Sku"); if (identifier == null) { return(null); } return(_contentManager .Query <ProductPart, ProductPartRecord>() .Where(p => p.Sku == identifier) .List <ContentItem>() .Where(c => ContentIdentity.ContentIdentityEqualityComparer.AreEquivalent( identity, _contentManager.GetItemMetadata(c).Identity))); }
private IEnumerable <ContentItem> ResolveIdentity(ContentIdentity identity) { var identifier = identity.Get("User.UserName"); if (identifier == null) { return(null); } var comparer = new ContentIdentity.ContentIdentityEqualityComparer(); return(_contentManager .Query <UserPart, UserPartRecord>() .Where(p => p.UserName == identifier) .List <ContentItem>() .Where(c => comparer.Equals(identity, _contentManager.GetItemMetadata(c).Identity))); }
protected override void Importing(CommonPart part, ImportContentContext context) { var owner = context.Attribute(part.PartDefinition.Name, "Owner"); if (owner != null) { var contentIdentity = new ContentIdentity(owner); part.Owner = _membershipService.GetUser(contentIdentity.Get("User.UserName")); } // use the super user if the referenced one doesn't exist else { part.Owner = _membershipService.GetUser(Services.WorkContext.CurrentSite.SuperUser); } var container = context.Attribute(part.PartDefinition.Name, "Container"); if (container != null) { part.Container = context.GetItemFromSession(container); } var createdUtc = context.Attribute(part.PartDefinition.Name, "CreatedUtc"); if (createdUtc != null) { part.CreatedUtc = XmlConvert.ToDateTime(createdUtc, XmlDateTimeSerializationMode.Utc); } var publishedUtc = context.Attribute(part.PartDefinition.Name, "PublishedUtc"); if (publishedUtc != null) { part.PublishedUtc = XmlConvert.ToDateTime(publishedUtc, XmlDateTimeSerializationMode.Utc); } var modifiedUtc = context.Attribute(part.PartDefinition.Name, "ModifiedUtc"); if (modifiedUtc != null) { part.ModifiedUtc = XmlConvert.ToDateTime(modifiedUtc, XmlDateTimeSerializationMode.Utc); } }
protected override void Importing(ThreadPart part, ImportContentContext context) { var postCount = context.Attribute(part.PartDefinition.Name, "PostCount"); if (postCount != null) { part.PostCount = Convert.ToInt32(postCount); } var isSticky = context.Attribute(part.PartDefinition.Name, "IsSticky"); if (isSticky != null) { part.IsSticky = Convert.ToBoolean(isSticky); } var closedOnUtc = context.Attribute(part.PartDefinition.Name, "ClosedOnUtc"); if (closedOnUtc != null) { part.ClosedOnUtc = XmlConvert.ToDateTime(closedOnUtc, XmlDateTimeSerializationMode.Utc); var closedBy = context.Attribute(part.PartDefinition.Name, "ClosedBy"); if (closedBy != null) { var contentIdentity = new ContentIdentity(closedBy); part.ClosedBy = _membershipService.GetUser(contentIdentity.Get("User.UserName")); } var closedDescription = context.Attribute(part.PartDefinition.Name, "ClosedDescription"); if (closedDescription != null) { part.ClosedDescription = closedDescription; } } }
private void Replace(ImportSyncAction action, ImportContentSession session) { // update the identifier on the item in the local instance // then let the import continue so the existing item gets paved over if (action.Action == "Replace" && !string.IsNullOrWhiteSpace(action.TargetId)) { var item = session.Get(action.TargetId); if (item == null) { return; } var newIdentifier = action.Step.Step.Attribute("Id"); if (newIdentifier == null) return; var newIdentity = new ContentIdentity(newIdentifier.Value); var existingIdentity = new ContentIdentity(action.TargetId); if (!newIdentity.Equals(existingIdentity)) { Logger.Debug("import - items {0} and {1} have different identifiers", existingIdentity.Get("Identifier"), newIdentity.Get("Identifier")); item.As<IdentityPart>().Identifier = newIdentity.Get("Identifier"); session.Store(newIdentity.Get("Identifier"), item); } } }