private void ReadFields(NetDataReader reader, int length, int frame, bool discardOutOfOrderPackets) { int startPosition = reader.Position; // Clear the first byte of the payload. This will be // a StatefulObject.DataType.Object enum. if (reader.Position - startPosition < length) { reader.GetByte(); } while (reader.Position - startPosition < length) { int id = reader.GetInt(); int guid = reader.GetInt(); if (!world.statefulObjects.ContainsKey(id)) { IdentifiableObject clone = Object.Instantiate(world.registeredPrefabsMap[guid], Vector3.zero, Quaternion.identity); world.Add(clone.GetComponent <StatefulObject>(), id); } world.statefulObjects[id].ReadStateFields(reader, startPosition + length, arbiter, frame, discardOutOfOrderPackets, false); } }
/// <summary> /// Removes a test items created during the test. /// </summary> /// <remarks> /// This never throws an exception, so it can safely be used in a finally statement (without hiding the original exception). /// </remarks> protected void Remove(IdentifiableObject item) { if (item == null) { return; } VersionedItem versionedItem = item as VersionedItem; if (versionedItem != null & versionedItem.IsLocked) { try { versionedItem.UndoCheckOut(); } catch (Exception ex) { Console.WriteLine("Unable to undo check out {0}: {1}", item, ex.Message); } } try { versionedItem.Delete(); } catch (Exception ex) { Console.WriteLine("Unable to delete {0}: {1}", item, ex.Message); } }
private void ReadStateful(NetPacketReader reader, int length, int frame, bool discardOutOfOrderPackets) { int startPosition = reader.Position; while (reader.Position - startPosition < length) { int id = reader.GetInt(); int guid = reader.GetInt(); if (!world.statefulObjects.ContainsKey(id)) { IdentifiableObject clone = Object.Instantiate(world.registeredPrefabsMap[guid], Vector3.zero, Quaternion.identity); world.Add(clone.GetComponent <StatefulObject>(), id); } if (world.statefulObjects[id].GetComponent <IStreamable>().LastReadFrame < frame || !discardOutOfOrderPackets) { world.statefulObjects[id].GetComponent <IStreamable>().Read(reader); world.statefulObjects[id].GetComponent <IStreamable>().LastReadFrame = frame; } else { world.statefulObjects[id].GetComponent <IStreamable>().Pass(reader); } } }
/// <summary> /// Publishes a <see cref="T:Tridion.ContentManager.IdentifiableObject"/> to a given <see cref="T:Tridion.ContentManager.CommunicationManagement.PublicationTarget"/> and /// with <see cref="T:Tridion.ContentManager.Publishing.PublishPriority"/> /// </summary> /// <param name="PublishUser"><see cref="T:Tridion.ContentManager.Security.User"/></param> /// <param name="Item"><see cref="T:Tridion.ContentManager.IdentifiableObject"/></param> /// <param name="Target"><see cref="T:Tridion.ContentManager.CommunicationManagement.PublicationTarget"/></param> /// <param name="Priority"><see cref="T:Tridion.ContentManager.Publishing.PublishPriority"/></param> /// <param name="startDate"><see cref="T:System.DateTime"/></param> public void PublishItem(User PublishUser, IdentifiableObject Item, PublicationTarget Target, PublishPriority Priority, DateTime startDate) { if (Engine.RenderMode == RenderMode.Publish) { if (startDate == null) { startDate = DateTime.Now; } using (Session session = new Session(PublishUser.Title)) { PublishInstruction publishInstruction = new PublishInstruction(session) { StartAt = startDate, DeployAt = startDate }; RenderInstruction renderInstruction = new RenderInstruction(session); renderInstruction.RenderMode = RenderMode.Publish; publishInstruction.RenderInstruction = renderInstruction; PublishEngine.Publish(new IdentifiableObject[] { session.GetObject(Item.Id) }, publishInstruction, new PublicationTarget[] { Target }, Priority); } } }
public void TestAreYou() { IdentifiableObject id = new IdentifiableObject(new string[] { "id1", "id2" }); Assert.IsTrue(id.AreYou("id1")); Assert.IsTrue(id.AreYou("id2")); }
private static void ThrowExceptionWhenReturnedIdentifiableObjectIsNull(IdentifiableObject item, string itemUriOrWebDavUrl) { if (item == null) { throw new InvalidOperationException(String.Format("The specified object {0} could not be found.", itemUriOrWebDavUrl)); } }
/// <summary> /// For Publish and UnPublish, remove all items from the website structure Publication from the list. /// Website structure Publication URI is read from the config file. /// </summary> /// <param name="item">Item to be resolved (e.g. a page, structure group, template)</param> /// <param name="instruction">Resolve instruction</param> /// <param name="context">Publish context</param> /// <param name="resolvedItems">List of items that are currently to be rendered and published (added by previous resolvers in the chain)</param> public void Resolve(IdentifiableObject item, ResolveInstruction instruction, PublishContext context, Tridion.Collections.ISet <ResolvedItem> resolvedItems) { List <ResolvedItem> itemsToRemove = new List <ResolvedItem>(); StringBuilder infoMessage = new StringBuilder(); infoMessage.AppendLine(string.Format("Removed the following items from a {0} Transaction to {1}:", instruction.Purpose, context.PublicationTarget.Title)); // check for items from website structure publication (these do not need to be published or unpublished) foreach (ResolvedItem resolvedItem in resolvedItems) { // mark all items from website structure publication for removal if (resolvedItem.Item.Id.PublicationId == _websiteStructurePublicationUri.ItemId) { itemsToRemove.Add(resolvedItem); } } // remove all items that we need to discard foreach (ResolvedItem itemToRemove in itemsToRemove) { infoMessage.AppendLine(string.Format("{0}: {1} ({2})", itemToRemove.Item.Id.ItemType, itemToRemove.Item.Title, itemToRemove.Item.Id)); resolvedItems.Remove(itemToRemove); } if (itemsToRemove.Count > 0) { // log info mesage about which items have been removed (optionally this can be logged as a warning to stand out in the logfile) Logger.Write(infoMessage.ToString(), "ChildPublicationsOnlyResolver", LoggingCategory.General, TraceEventType.Information); } }
private void ReadSpawns(NetDataReader reader, int length) { if (listenRemote) { reader.SkipBytes(length); return; } int startPosition = reader.Position; while (reader.Position - startPosition < length) { // Instantiate, etc. int id = reader.GetInt(); int GUID = reader.GetInt(); // Check if it's already been spawned. if (!world.statefulObjects.ContainsKey(id)) { IdentifiableObject clone = Object.Instantiate(world.registeredPrefabsMap[GUID], Vector3.zero, Quaternion.identity); clone.GetComponent <StatefulObject>().IsDirty = false; world.Add(clone.GetComponent <StatefulObject>(), id); } } }
/// <summary> /// Audits updates to versionless items /// </summary> /// <param name="repositoryObject"><see cref="T:Tridion.ContentManager.ContentManagement.RepositoryLocalObject" /></param> /// <param name="args">The <see cref="SaveEventArgs" /> instance containing the event data.</param> /// <param name="phase"><see cref="T:Tridion.ContentManager.Extensibility.EventPhases" /></param> private void AuditVersionless(IdentifiableObject identifiableObject, SaveEventArgs args, EventPhases phase) { if (phase == EventPhases.Initiated) { try { // Load the original unmodified item XML from the database IdentifiableObject oldIdentifiableObject = identifiableObject.Session.GetObject(identifiableObject.Id); XElement original = XElement.Parse(oldIdentifiableObject.ToXml().OuterXml); XElement updated = XElement.Parse(identifiableObject.ToXml().OuterXml); XElement difference = XMLDelta.Compare(original, updated); if (difference != null) { AuditContentEdit("Update", identifiableObject, identifiableObject.GetType().Name, new SqlXml(difference.CreateReader())); } else { AuditContentEdit("Update", identifiableObject, identifiableObject.GetType().Name, null); } } catch (Exception ex) { Logger.Write(ex, "TcmEvents.Audit", LoggingCategory.General, TraceEventType.Error); } } }
/// <summary> /// Add a new <see cref="T:Tridion.ContentManager.IdentifiableOject"/> Link value to the current <see cref="T:Tridion.ContentManager.Templating.Package" /> /// </summary> /// <param name="package"><see cref="T:Tridion.ContentManager.Templating.Package" /></param> /// <param name="name">Name.</param> /// <param name="value">Value.</param> public static void AddLink(this Package package, String name, IdentifiableObject value) { if (package != null) { package.AddValue(ContentType.ItemLink, name, value != null ? value.Id : TcmUri.UriNull); } }
/// <summary> /// Try to identify if the given publish result contains the TcmUri to check /// </summary> /// <param name="transaction">The transaction to find.</param> /// <param name="tcmUri">String Tcm Uri to check</param> /// <returns>true if found; false, otherwise</returns> private static bool IsPublishTransactionForTcmUri(PublishTransaction transaction, String tcmUri) { IList <IdentifiableObject> items = transaction.Items; foreach (IdentifiableObject item in items) { if (item.Id.ToString().Equals(tcmUri)) { return(true); } } foreach (PublishContext context in transaction.PublishContexts) { foreach (ProcessedItem processedItem in transaction.GetListProcessedItems(context)) { IdentifiableObject item = processedItem.ResolvedItem.Item; if (item.Id.ToString().Equals(tcmUri)) { return(true); } } } return(false); }
/// <summary> /// When an item is published, it is in the context of the publication which it was published from. In order to publish the item in the /// "mirrored" publications - we need to retrieve the item in each of the target publications. /// </summary> /// <param name="item">item published originally by the user</param> /// <param name="publications">list of publications which the item should also be published to</param> /// <returns></returns> public static List <IdentifiableObject> GetItemsInPublications(IdentifiableObject item, List <TcmUri> publicationIds, Session session) { if (item == null) { return(null); } // For each of the publications we should mirror publishing to, create the ID for the item in that publication and query it. return(publicationIds?.Select(p => { IdentifiableObject result = null; var tcmUri = new TcmUri(item.Id.ItemId, item.Id.ItemType, p.ItemId); try { if (session.IsExistingObject(tcmUri.ToString())) { result = session.GetObject(tcmUri.ToString()); } } catch (Exception ex) { logger.Error($"Error {ex.Message} -- {ex.ToString()}"); } return result; })?.Where(i => i != null).ToList()); }
protected string RunTemplate(Type templateType, IdentifiableObject inputItem, Template template = null) { RenderedItem testRenderedItem = CreateTestRenderedItem(inputItem, template); TestEngine testEngine = new TestEngine(testRenderedItem); Package testPackage = new Package(testEngine); Type inputItemType = inputItem.GetType(); string inputItemName = inputItemType.Name; ContentType inputItemContentType = new ContentType($"tridion/{inputItemType.Name.ToLower()}"); testPackage.PushItem(inputItemName, testPackage.CreateTridionItem(inputItemContentType, inputItem)); ITemplate testTemplate = Activator.CreateInstance(templateType) as ITemplate; Assert.IsNotNull(testTemplate, "testTemplate"); testTemplate.Transform(testEngine, testPackage); Item outputItem = testPackage.GetByName(Package.OutputName); Assert.IsNotNull(outputItem, "outputItem"); string result = outputItem.GetAsString(); Assert.IsNotNull(result, "result"); Console.WriteLine("Output Item:"); Console.WriteLine(result); return(result); }
/// <summary> /// For Publish and UnPublish, remove all items from the website structure Publication from the list. /// Website structure Publication URI is read from the config file. /// </summary> /// <param name="item">Item to be resolved (e.g. a page, structure group, template)</param> /// <param name="instruction">Resolve instruction</param> /// <param name="context">Publish context</param> /// <param name="resolvedItems">List of items that are currently to be rendered and published (added by previous resolvers in the chain)</param> public void Resolve(IdentifiableObject item, ResolveInstruction instruction, PublishContext context, Tridion.Collections.ISet<ResolvedItem> resolvedItems) { List<ResolvedItem> itemsToRemove = new List<ResolvedItem>(); StringBuilder infoMessage = new StringBuilder(); infoMessage.AppendLine(string.Format("Removed the following items from a {0} Transaction to {1}:", instruction.Purpose, context.PublicationTarget.Title)); // check for items from website structure publication (these do not need to be published or unpublished) foreach (ResolvedItem resolvedItem in resolvedItems) { // mark all items from website structure publication for removal if (resolvedItem.Item.Id.PublicationId == _websiteStructurePublicationUri.ItemId) { itemsToRemove.Add(resolvedItem); } } // remove all items that we need to discard foreach (ResolvedItem itemToRemove in itemsToRemove) { infoMessage.AppendLine(string.Format("{0}: {1} ({2})", itemToRemove.Item.Id.ItemType, itemToRemove.Item.Title, itemToRemove.Item.Id)); resolvedItems.Remove(itemToRemove); } if (itemsToRemove.Count > 0) { // log info mesage about which items have been removed (optionally this can be logged as a warning to stand out in the logfile) Logger.Write(infoMessage.ToString(), "ChildPublicationsOnlyResolver", LoggingCategory.General, TraceEventType.Information); } }
private string GetFieldValueAsString(XmlElement xmlElement) { string xlinkHref = xmlElement.GetAttribute("href", Constants.XlinkNamespace); if (!string.IsNullOrEmpty(xlinkHref)) { if (!TcmUri.IsValid(xlinkHref)) { // External link field return(xlinkHref); } IdentifiableObject linkedItem = Pipeline.Session.GetObject(xmlElement); Keyword keyword = linkedItem as Keyword; if (keyword == null) { // Component link field or some other linked item (except Keyword) return(xlinkHref); } // Keyword link field return(string.IsNullOrEmpty(keyword.Description) ? keyword.Title : keyword.Description); } if (xmlElement.SelectSingleElement("xhtml:*") != null) { // XHTML field RichTextData richText = BuildRichTextModel(xmlElement); return(string.Join("", richText.Fragments.Select(f => f.ToString()))); } // Text, number or date field // Multi-line text field may use CR+LF to separate lines, but JSON.NET expects LF only. return(xmlElement.InnerText.Replace("\r\n", "\n")); }
private ViewModelData GetLinkFieldValue(IdentifiableObject linkedItem, int expandLinkDepth) { Component linkedComponent = linkedItem as Component; Keyword linkedKeyword = linkedItem as Keyword; if ((linkedComponent == null) && (linkedKeyword == null)) { Logger.Debug("XLink is not a Component or Keyword link."); return(null); } if (expandLinkDepth == 0) { Logger.Debug($"Not expanding link because configured ExpandLinkDepth of {Pipeline.Settings.ExpandLinkDepth} has been reached."); if (linkedComponent != null) { return(new EntityModelData { Id = GetDxaIdentifier(linkedComponent) }); } return(new KeywordModelData { Id = GetDxaIdentifier(linkedKeyword), SchemaId = GetDxaIdentifier(linkedKeyword.MetadataSchema) }); } if (linkedComponent != null) { ComponentTemplate dataPresentationTemplate = Pipeline.DataPresentationTemplate; if ((dataPresentationTemplate != null) && dataPresentationTemplate.RelatedSchemas.Contains(linkedComponent.Schema)) { Logger.Debug($"Not expanding Component link because a Data Presentation exists: {linkedComponent.Schema.FormatIdentifier()}"); return(new EntityModelData { Id = $"{GetDxaIdentifier(linkedComponent)}-{GetDxaIdentifier(dataPresentationTemplate)}" }); } Logger.Debug($"Expanding Component link. expandLinkDepth: {expandLinkDepth}"); return(Pipeline.CreateEntityModel(linkedComponent, null, expandLinkDepth - 1)); } Category category = (Category)linkedKeyword.OrganizationalItem; if (category.UseForNavigation) { Logger.Debug($"Not expanding Keyword link because its Category is publishable: {category.FormatIdentifier()}"); return(new KeywordModelData { Id = GetDxaIdentifier(linkedKeyword), SchemaId = GetDxaIdentifier(linkedKeyword.MetadataSchema) }); } Logger.Debug($"Expanding Keyword link. expandLinkDepth: {expandLinkDepth}"); return(Pipeline.CreateKeywordModel(linkedKeyword, expandLinkDepth - 1)); }
/// <summary> /// Add a new <see cref="T:T:Tridion.ContentManager.IdentifiableOject"/> value to the current <see cref="T:Tridion.ContentManager.Templating.Package" /> /// </summary> /// <param name="package"><see cref="T:Tridion.ContentManager.Templating.Package" /></param> /// <param name="name">Name.</param> /// <param name="value">Value.</param> public static void AddComponent(this Package package, String name, IdentifiableObject value) { if (package != null) { Item packageItem = package.CreateTridionItem(ContentType.Component, value); package.PushItem(name, packageItem); } }
/// <summary> /// Determines whether the <see cref="T:Tridion.ContentManager.IdentifiableObject"/> is a "navigable" item. /// </summary> /// <param name="identifiableObject"><see cref="T:Tridion.ContentManager.IdentifiableObject" /></param> /// <returns><c>True</c> if the item is a "navigable" item.</returns> /// <remarks>Navigable items have to match the following rules: /// 1. Start with a 1 to 5 digit number /// 2. Optionally have a dot "." /// 3. Optionally have a space " " /// </remarks> public static Boolean IsNavigableItem(this IdentifiableObject identifiableObject) { if (identifiableObject != null) { return(mNavigable.IsMatch(identifiableObject.Title)); } return(false); }
/// <summary> /// Determines whether item is published in the current publication context. /// </summary> /// <param name="identifiableObject">The item <see cref="Tridion.ContentManager.IdentifiableObject"/>.</param> /// <param name="publicationTarget">The publication target <see cref="Tridion.ContentManager.CommunicationManagement.PublicationTarget"/>.</param> /// <returns> /// <c>true</c> if item is published in current publication context, otherwise <c>false</c>. /// </returns> public static bool IsPublished(this IdentifiableObject identifiableObject, PublicationTarget publicationTarget) { if (identifiableObject != null && publicationTarget != null) { return(PublishEngine.IsPublished(identifiableObject, publicationTarget, true)); } return(false); }
/// <summary> /// Retrieve the <see cref="T:Tridion.ContentManager.IdentifiableObject" /> published information /// </summary> /// <param name="identifiableObject"><see cref="T:Tridion.ContentManager.IdentifiableObject" /></param> /// <returns><see cref="T:Tridion.ContentManager.Publishing.PublishInfo" /></returns> public static IEnumerable <PublishInfo> PublishInfo(this IdentifiableObject identifiableObject) { if (identifiableObject != null) { return(PublishEngine.GetPublishInfo(identifiableObject)); } return(new PublishInfo[] { }); }
/// <summary> /// Retrieve the <see cref="T:Tridion.ContentManager.IdentifiableObject" /> TcmId /// </summary> /// <param name="identifiableObject"><see cref="T:Tridion.ContentManager.IdentifiableObject" /></param> /// <returns></returns> /// <remarks> /// TcmId allows for a null reference to be passed in. /// </remarks> public static String TcmId(this IdentifiableObject identifiableObject) { if (identifiableObject != null) { return(identifiableObject.Id.ToString()); } return(String.Empty); }
private RenderedItem CreateTestRenderedItem(IdentifiableObject item, Template template) { RenderInstruction testRenderInstruction = new RenderInstruction(item.Session) { BinaryStoragePath = @"C:\Temp\DXA\Test", RenderMode = RenderMode.PreviewDynamic }; return(new RenderedItem(new ResolvedItem(item, template), testRenderInstruction)); }
public void AddIDTest() { IdentifiableObject id = new IdentifiableObject(new string[] { "fred", "bob" }); id.AddIdentifier("wilma"); Assert.IsTrue(id.AreYou("fred")); Assert.IsTrue(id.AreYou("bob")); Assert.IsTrue(id.AreYou("wilma")); }
/// <summary> /// Publishes the specified tcm uri as a binary component /// </summary> /// <param name="uri">TCM URI.</param> /// <returns>Published Url or String.Empty</returns> public String PublishBinary(String uri) { IdentifiableObject identifiableObject = mEngine.GetObject(uri); if (identifiableObject is Component) { return(mTemplateBase.PublishBinary(identifiableObject as Component)); } return(String.Empty); }
/// <summary> /// Returns the Tcm id including the version if its a <see cref="T:Tridion.ContentManager.ContentManagement.VersionedItem" /> /// </summary> /// <param name="identifiableObject"><see cref="T:Tridion.ContentManager.IdentifiableObject" /></param> /// <returns>Tcm id including version or Tcm id</returns> public static String VersionedItemId(this IdentifiableObject identifiableObject) { VersionedItem versionedItem = identifiableObject as VersionedItem; if (versionedItem != null && versionedItem.Id.IsVersionless) { return(String.Format("{0}-v{1}", versionedItem.Id.ToString(), versionedItem.Version)); } return(identifiableObject.Id.ToString()); }
private bool GetReplacement(String tag, String uri, Dictionary <String, String> attributes, out String beginTag, out String endTag) { String tagToRender = String.Empty; beginTag = String.Empty; endTag = String.Empty; IdentifiableObject identifiableObject = GetObject <IdentifiableObject>(uri); if (identifiableObject != null) { // Update link title as necessary ProcessLinkTitle(identifiableObject, ref attributes); Component component = identifiableObject as Component; // Publish multimedia components directly into the supported attributes if (component != null) { if (component.ComponentType == ComponentType.Multimedia) { String binaryUrl = PublishBinary(component); if (String.Equals(tag, "img", StringComparison.OrdinalIgnoreCase)) { attributes["ImageUrl"] = binaryUrl; tagToRender = IMAGE_TAG; } else { attributes["ItemUri"] = identifiableObject.Id; tagToRender = BINARY_TAG; } } else { attributes.Add("ItemUri", identifiableObject.Id); tagToRender = COMPONENT_TAG; } } else if (identifiableObject is Page) { attributes.Add("ItemUri", identifiableObject.Id); tagToRender = PAGE_TAG; } beginTag = String.Format("<{0} runat=\"server\"{1}>", tagToRender, RenderAttributes(attributes)); endTag = String.Format("</{0}>", tagToRender); return(true); } return(false); }
public void SetUp() { List <string> idList = new List <string> { "Fred", "Bob", "Richard" }; _testableObject = new IdentifiableObject(idList); }
public void IdentifiableObjectTest() { IdentifiableObject id = new IdentifiableObject(new string[] { "fred", "bob" }); Assert.IsTrue(id.AreYou("Fred")); Assert.IsTrue(id.AreYou("bob")); Assert.IsFalse(id.AreYou("wilma")); Assert.IsFalse(id.AreYou("boBy")); Assert.IsFalse(id.AreYou("FReD")); Assert.IsFalse(id.AreYou("B0b")); }
public ManagerWithManyIndividualConcrete( ILogger logger, [KeyFilter("First")] IdentifiableObject first, [KeyFilter("Second")] IdentifiableObject second, [KeyFilter("Third")] IdentifiableObject third) { Logger = logger; First = first; Second = second; Third = third; }
private void EventHandler(IdentifiableObject subject, EventArgs eventArgs, EventPhases phase) { var record = new Record(); //Set Environment record.Environment = new CMEnvironment { Name = ConfigurationManager.AppSettings.Get("NF4T_CMEnvironmentKey") }; //Set Subject record.Subject = new Subject { TcmId = subject.Id, Title = subject.Title, Type = subject.GetType(), CreationDate = subject.CreationDate, LastModifiedDate = subject.RevisionDate }; //Extract ItemTypeSpecifics if (subject is Component) { var component = subject as Component; record.Subject.SchemaTcmId = component.Schema.Id.ToString(); } //Set Event record.Event = new Event { Type = eventArgs.GetType(), TimeStamp = DateTime.Now }; //Extract ItemTypeSpecifics if (eventArgs is SaveEventArgs) { var saveEventArgs = eventArgs as SaveEventArgs; record.Event.IsNewItem = saveEventArgs.IsNewItem; } //Extract EventType Specifics switch (eventArgs.GetType().Name) { case "SaveEventArgs": break; default: break; } var events = eventArgs as SaveEventArgs; }
/// <summary> /// Generates a thumbnail for the given tcm uri binary component /// </summary> /// <param name="uri">TCM URI</param> /// <param name="width">Thumbnail width</param> /// <param name="height">Thumbnail height</param> /// <returns></returns> public String GenerateThumbnail(String uri, int width, int height) { IdentifiableObject identifiableObject = mEngine.GetObject(uri); if (identifiableObject is Component) { return(mTemplateBase.GenerateThumbnail(identifiableObject as Component, width, height)); } return(String.Empty); }
/// <summary> /// Gets the (cached) <see cref="T:Tridion.ContentManager.ContentManagement.Fields.ItemFields"/> for a given /// <see cref="T:Tridion.ContentManager.IdentifiableObject"/> and <see cref="T:Tridion.ContentManager.ContentManagement.Schema" /> /// </summary> /// <param name="identifiableObject"><see cref="T:Tridion.ContentManager.IdentifiableObject"/></param> /// <param name="rootElement">Content <see cref="T:System.Xml.XmlElement" /></param> /// <param name="schema"><see cref="T:Tridion.ContentManager.ContentManagement.Schema" /></param> /// <returns>(Cached) <see cref="T:Tridion.ContentManager.ContentManagement.Fields.ItemFields"/></returns> public static ItemFields Get(IdentifiableObject identifiableObject, XmlElement rootElement, Schema schema) { if (identifiableObject != null && rootElement != null && schema != null) { String key = Key(identifiableObject, rootElement.LocalName, schema); ItemFields result = mCache.Value.Get(key); if (result == null) { result = new ItemFields(rootElement, schema); mCache.Value.Add(key, result); } return result; } return null; }
/// <summary> /// Implement the resolver function to control the resolving /// </summary> /// <param name="item">the item published</param> /// <param name="instruction">Resolve Instructiuons</param> /// <param name="context">Publish Context</param> /// <param name="resolvedItems">Collection of Resolved Items</param> public void Resolve(IdentifiableObject item, ResolveInstruction instruction, PublishContext context, Tridion.Collections.ISet<ResolvedItem> resolvedItems) { // Array of schemas which are supposed to publish independently with out resolved items string[] lookupSchemas = { "Schema Title1", "Schema Title2" }; // If published item is a component and it's type belongs to look up schemas array, start the process if (item is Component) { Component comp1 = (Component)item; if (lookupSchemas.Contains(comp1.Schema.Title)) { // Temp collection of resolved items List<ResolvedItem> tempItems = new List<ResolvedItem>(); // Loop through resolved items foreach (var resolvedItem in resolvedItems) { // If the resolved item is the published item // Allow it to be published by adding to temp items collection if (resolvedItem.Item is Component) { Component compResolved = (Component)resolvedItem.Item; if (resolvedItem.Item.Id == item.Id) { tempItems.Add(resolvedItem); } } } // Delete all resolved items resolvedItems.Clear(); // Add temp items(needs to be published) to resolvedItems collection foreach (ResolvedItem tempResolvedItem in tempItems) { resolvedItems.Add(tempResolvedItem); } } } }
/// <summary> /// Determines the cache key for the specified component uri and <see cref="T:Tridion.ContentManager.ContentManagement.Schema"/> /// </summary> /// <param name="identifiableObject"><see cref="T:Tridion.ContentManager.IdentifiableObject"/></param> /// <param name="rootElementName">Schema root element name</param> /// <param name="schema"><see cref="T:Tridion.ContentManager.ContentManagement.Schema"/></param> /// <returns> /// Cache key /// </returns> private static String Key(IdentifiableObject identifiableObject, String rootElementName, Schema schema) { return identifiableObject.Id.ToString() + rootElementName + schema.Id.ToString(); }
/// <summary> /// Audits updates to versionless items /// </summary> /// <param name="repositoryObject"><see cref="T:Tridion.ContentManager.ContentManagement.RepositoryLocalObject" /></param> /// <param name="args">The <see cref="SaveEventArgs" /> instance containing the event data.</param> /// <param name="phase"><see cref="T:Tridion.ContentManager.Extensibility.EventPhases" /></param> private void AuditVersionless(IdentifiableObject identifiableObject, SaveEventArgs args, EventPhases phase) { if (phase == EventPhases.Initiated) { try { // Load the original unmodified item XML from the database IdentifiableObject oldIdentifiableObject = identifiableObject.Session.GetObject(identifiableObject.Id); XElement original = XElement.Parse(oldIdentifiableObject.ToXml().OuterXml); XElement updated = XElement.Parse(identifiableObject.ToXml().OuterXml); XElement difference = XMLDelta.Compare(original, updated); if (difference != null) AuditContentEdit("Update", identifiableObject, identifiableObject.GetType().Name, new SqlXml(difference.CreateReader())); else AuditContentEdit("Update", identifiableObject, identifiableObject.GetType().Name, null); } catch (Exception ex) { Logger.Write(ex, "TcmEvents.Audit", LoggingCategory.General, TraceEventType.Error); } } }
/// <summary> /// Audits the content edit. /// </summary> /// <param name="action">Content Editing Action</param> /// <param name="identifiableObject">The identifiable object.</param> /// <param name="comments">Optional comments.</param> /// <param name="xml">Optional Xml blob.</param> private void AuditContentEdit(String action, IdentifiableObject identifiableObject, String comments, SqlXml xml) { try { using (SqlConnection connection = Connection) { // Register the content editing action using (SqlCommand sqlAuditContentEdit = new SqlCommand() { CommandText = "AuditContentEdit", CommandType = CommandType.StoredProcedure, Connection = connection }) { sqlAuditContentEdit.AddParameter("@Action", SqlDbType.VarChar, action); sqlAuditContentEdit.AddParameter("@ItemID", SqlDbType.VarChar, identifiableObject.VersionedItemId()); sqlAuditContentEdit.AddParameter("@ItemTitle", SqlDbType.NVarChar, identifiableObject.Title); sqlAuditContentEdit.AddParameter("@Username", SqlDbType.VarChar, identifiableObject.Session.User.Title.ToUpper()); sqlAuditContentEdit.AddParameter("@UserDescription", SqlDbType.NVarChar, identifiableObject.Session.User.Description); if (!String.IsNullOrEmpty(comments)) sqlAuditContentEdit.AddParameter("@Comments", SqlDbType.NVarChar, comments); else sqlAuditContentEdit.AddParameter("@Comments", SqlDbType.NVarChar, DBNull.Value); if (xml != null) sqlAuditContentEdit.AddParameter("@Xml", SqlDbType.Xml, xml); else sqlAuditContentEdit.AddParameter("@Xml", SqlDbType.Xml, DBNull.Value); sqlAuditContentEdit.ExecuteNonQuery(); } } } catch (Exception ex) { Logger.Write(ex, "TcmEvents.Audit", LoggingCategory.General, TraceEventType.Error); } }
/// <summary> /// Add a new <see cref="T:Tridion.ContentManager.IdentifiableOject"/> Link value to the current <see cref="T:Tridion.ContentManager.Templating.Package" /> /// </summary> /// <param name="package"><see cref="T:Tridion.ContentManager.Templating.Package" /></param> /// <param name="name">Name.</param> /// <param name="value">Value.</param> public static void AddLink(this Package package, String name, IdentifiableObject value) { if (package != null) package.AddValue(ContentType.ItemLink, name, value != null ? value.Id : TcmUri.UriNull); }
/// <summary> /// Creates a resolved item from the given item and template /// </summary> /// <param name="item">Identifiable object to act as the source item for rendering</param> /// <param name="template">Template to render with</param> /// <returns>ResolvedItem</returns> private ResolvedItem CreateResolvedItem(IdentifiableObject item, Template template) { return new ResolvedItem(item, template); }
private void ProcessLinkTitle(IdentifiableObject identifiableObject, ref Dictionary<String, String> attributes) { String title = String.Empty; if (attributes.TryGetValue("title", out title)) { title = title.Replace("<br/>", " "); // Retrieve the title of a navigable item Match match = mLinkTitle.Match(title); // Tridion numbered links if (match.Success) title = title.Substring(match.Length); attributes["Tooltip"] = title; attributes.Remove("title"); } // If no title was specified, or its a tridion richtext link field if (String.IsNullOrEmpty(title)) { Component component = identifiableObject as Component; if (component != null && component.Content != null) { XmlNode xTitle = component.Content.SelectSingleNode("//node()[local-name() = 'Title']"); if (xTitle != null && !String.IsNullOrEmpty(xTitle.InnerText)) { title = xTitle.InnerText.Replace("<br/>", " "); attributes["Tooltip"] = HttpUtility.HtmlEncode(title); attributes.Remove("title"); } } } }