/// <summary>Calculates an item url by walking it's parent path.</summary> /// <param name="item">The item whose url to compute.</param> /// <returns>A friendly url to the supplied item.</returns> public Url BuildUrl(ContentItem item) { if (item.ID == 0) { return(inner.BuildUrl(item)); } var cacheKey = "N2.UrlCache" + webContext.Url.Authority.ToLower(); // e.g. localhost var itemToUrlCache = cache.Get <Dictionary <int, string> >(cacheKey); if (itemToUrlCache == null) { lock (urlLock) { itemToUrlCache = cache.Get <Dictionary <int, string> >(cacheKey); if (itemToUrlCache == null) { itemToUrlCache = new Dictionary <int, string>(); cache.Add(cacheKey, itemToUrlCache, new CacheOptions { SlidingExpiration = SlidingExpiration }); if (!allCacheKeys.Contains(cacheKey)) { allCacheKeys.Add(cacheKey); // remember all keys used for flushing } } } } bool exists; string url; lock (urlLock) { exists = itemToUrlCache.TryGetValue(item.ID, out url); } if (!exists) { url = inner.BuildUrl(item); lock (urlLock) { itemToUrlCache[item.ID] = url; } } return(url); }
public override void SetUp() { base.SetUp(); finder = new FakeTypeFinder(typeof(XmlableItem).Assembly, typeof(XmlableItem), typeof(XmlableItem2)); notifier = mocks.Stub<IItemNotifier>(); mocks.Replay(notifier); activator = new ContentActivator(new N2.Edit.Workflow.StateChanger(), notifier, new InterceptingProxyFactory()); definitions = new DefinitionManager( new[] {new DefinitionProvider(new DefinitionBuilder(new DefinitionMap(), finder, new TransformerBase<IUniquelyNamed>[0], TestSupport.SetupEngineSection()))}, activator, new StateChanger(), new DefinitionMap()); definitions.Start(); parser = mocks.StrictMock<IUrlParser>(); Expect.On(parser) .Call(parser.BuildUrl(null)) .IgnoreArguments() .Do(new BuildUrl(delegate(ContentItem itemToBuild) { string url = "/" + itemToBuild.Name + ".aspx"; foreach (ContentItem parent in Find.EnumerateParents(itemToBuild, null)) { if (parent.Parent != null) url = "/" + parent.Name + url; } return url.ToUrl(); })) .Repeat.Any(); mocks.Replay(parser); persister = TestSupport.SetupFakePersister(); }
protected virtual void WriteDefaultAttributes(ElementWriter itemElement, ContentItem item) { if (itemElement == null) { throw new ArgumentNullException("itemElement"); } if (item == null) { throw new ArgumentNullException("item"); } itemElement.WriteAttribute("id", item.ID); itemElement.WriteAttribute("name", item.ID.ToString() == item.Name ? "" : item.Name); if (item.Parent != null) { if (item.Parent.ID != 0) { itemElement.WriteAttribute("parent", item.Parent.ID.ToString()); } else { itemElement.WriteAttribute("parent", item.Parent.VersionOf.ID.ToString()); if (item.Parent.GetVersionKey() != null) { itemElement.WriteAttribute("parentVersionKey", item.Parent.GetVersionKey()); } } } itemElement.WriteAttribute("title", item.Title); itemElement.WriteAttribute("zoneName", item.ZoneName); itemElement.WriteAttribute("templateKey", item.TemplateKey); if (item.TranslationKey.HasValue) { itemElement.WriteAttribute("translationKey", item.TranslationKey.Value); } itemElement.WriteAttribute("state", (int)item.State); itemElement.WriteAttribute("created", item.Created); itemElement.WriteAttribute("updated", item.Updated); itemElement.WriteAttribute("published", item.Published); itemElement.WriteAttribute("expires", item.Expires); itemElement.WriteAttribute("sortOrder", item.SortOrder); itemElement.WriteAttribute("url", parser == null ? item.Url : (string)parser.BuildUrl(item)); itemElement.WriteAttribute("visible", item.Visible); itemElement.WriteAttribute("savedBy", item.SavedBy); itemElement.WriteAttribute("typeName", SerializationUtility.GetTypeAndAssemblyName(item.GetContentType())); itemElement.WriteAttribute("discriminator", definitions.GetDefinition(item).Discriminator); itemElement.WriteAttribute("versionIndex", item.VersionIndex); itemElement.WriteAttribute("ancestralTrail", item.AncestralTrail); itemElement.WriteAttribute("alteredPermissions", (int)item.AlteredPermissions); itemElement.WriteAttribute("childState", (int)item.ChildState); if (item.VersionOf.HasValue) { Debug.Assert(item.VersionOf.ID != null, "item.VersionOf.ID != null"); itemElement.WriteAttribute("versionOf", item.VersionOf.ID.Value); } }
/// <summary>Gets the url for the preview frame.</summary> /// <param name="selectedItem">The currently selected item.</param> /// <returns>An url.</returns> public virtual string GetPreviewUrl(ContentItem selectedItem) { try { Url url = ResolveResourceUrl(parser.BuildUrl(selectedItem)); return(url); } catch (N2Exception) { return(Url.ResolveTokens("{ManagementUrl}/Empty.aspx?item=" + selectedItem.ID)); } }
/// <summary>Gets the url for the preview frame.</summary> /// <param name="selectedItem">The currently selected item.</param> /// <returns>An url.</returns> public virtual string GetPreviewUrl(ContentItem selectedItem) { try { // If hostname == localhost, then don't use custom hostnames in the management navigation tree if (HttpContext.Current != null && HttpContext.Current.Request.Url.Host == "localhost") { return(selectedItem.FindPath(PathData.DefaultAction).GetRewrittenUrl()); } Url url = ResolveResourceUrl(parser.BuildUrl(selectedItem)); return(url); } catch (N2Exception) { return(Url.ResolveTokens("{ManagementUrl}/Empty.aspx?item=" + selectedItem.ID)); } }
protected virtual void WriteDefaultAttributes(ElementWriter itemElement, ContentItem item) { itemElement.WriteAttribute("id", item.ID); itemElement.WriteAttribute("name", item.ID.ToString() == item.Name ? "" : item.Name); itemElement.WriteAttribute("parent", item.Parent != null ? item.Parent.ID.ToString() : string.Empty); itemElement.WriteAttribute("title", item.Title); itemElement.WriteAttribute("zoneName", item.ZoneName); itemElement.WriteAttribute("created", item.Created); itemElement.WriteAttribute("updated", item.Updated); itemElement.WriteAttribute("published", item.Published); itemElement.WriteAttribute("expires", item.Expires); itemElement.WriteAttribute("sortOrder", item.SortOrder); itemElement.WriteAttribute("url", parser.BuildUrl(item)); itemElement.WriteAttribute("visible", item.Visible); itemElement.WriteAttribute("savedBy", item.SavedBy); itemElement.WriteAttribute("typeName", SerializationUtility.GetTypeAndAssemblyName(item.GetContentType())); itemElement.WriteAttribute("discriminator", definitions.GetDefinition(item.GetContentType()).Discriminator); }
public override void SetUp() { base.SetUp(); finder = new FakeTypeFinder(typeof(XmlableItem).Assembly, typeof(XmlableItem), typeof(XmlableItem2)); notifier = mocks.Stub<IItemNotifier>(); mocks.Replay(notifier); definitions = new DefinitionManager( new DefinitionBuilder( finder, new EngineSection(), new FakeEditUrlManager()), new N2.Edit.Workflow.StateChanger(), notifier, new InterceptingProxyFactory()); parser = mocks.StrictMock<IUrlParser>(); Expect.On(parser) .Call(parser.BuildUrl(null)) .IgnoreArguments() .Do(new BuildUrl(delegate(ContentItem itemToBuild) { string url = "/" + itemToBuild.Name + ".aspx"; foreach (ContentItem parent in Find.EnumerateParents(itemToBuild, null)) { if (parent.Parent != null) url = "/" + parent.Name + url; } return url; })) .Repeat.Any(); mocks.Replay(parser); persister = mocks.StrictMock<IPersister>(); persister.Save(null); LastCall.IgnoreArguments().Repeat.Any(); mocks.Replay(persister); }
protected virtual void WriteDefaultAttributes(ElementWriter itemElement, ContentItem item) { if (itemElement == null) { throw new ArgumentNullException("itemElement"); } if (item == null) { throw new ArgumentNullException("item"); } itemElement.WriteAttribute("id", item.ID); itemElement.WriteAttribute("name", item.ID.ToString() == item.Name ? "" : item.Name, true); if (item.Parent != null) { if (item.Parent.ID != 0) { itemElement.WriteAttribute("parent", item.Parent.ID.ToString()); } else { itemElement.WriteAttribute("parent", item.Parent.VersionOf.ID.ToString()); if (item.Parent.GetVersionKey() != null) { itemElement.WriteAttribute("parentVersionKey", item.Parent.GetVersionKey()); } } } itemElement.WriteAttribute("title", item.Title, true); itemElement.WriteAttribute("zoneName", item.ZoneName, true); itemElement.WriteAttribute("templateKey", item.TemplateKey, true); if (item.TranslationKey.HasValue) { itemElement.WriteAttribute("translationKey", item.TranslationKey.Value); } itemElement.WriteAttribute("state", Enum.GetName(typeof(ContentState), item.State)); // use textual state to avoid future import trouble itemElement.WriteAttribute("created", item.Created); itemElement.WriteAttribute("updated", item.Updated); itemElement.WriteAttribute("published", item.Published); itemElement.WriteAttribute("expires", item.Expires); // TODO expired items could be excluded itemElement.WriteAttribute("sortOrder", item.SortOrder); if (item.IsPage && item.IsPublished()) { itemElement.WriteAttribute("url", (parser != null) ? (string)parser.BuildUrl(item) : item.Url); // generated } itemElement.WriteAttribute("visible", item.Visible); itemElement.WriteAttribute("savedBy", item.SavedBy); itemElement.WriteAttribute("typeName", SerializationUtility.GetTypeAndAssemblyName(item.GetContentType())); itemElement.WriteAttribute("discriminator", definitions.GetDefinition(item).Discriminator); itemElement.WriteAttribute("ancestralTrail", item.AncestralTrail); // generated if (item.AlteredPermissions != 0) { itemElement.WriteAttribute("alteredPermissions", (int)item.AlteredPermissions); } itemElement.WriteAttribute("childState", (int)item.ChildState); if (item.VersionOf.HasValue && item.VersionOf.ID != null) { itemElement.WriteAttribute("versionIndex", item.VersionIndex); // write only if versioned itemElement.WriteAttribute("versionOf", item.VersionOf.ID.Value); } }
/// <summary>Calculates an item url by walking it's parent path.</summary> /// <param name="item">The item whose url to compute.</param> /// <returns>A friendly url to the supplied item.</returns> public string BuildUrl(ContentItem item) { return(inner.BuildUrl(item)); }