当前位置: 首页>>代码示例>>C#>>正文


C# Engine.GetObject方法代码示例

本文整理汇总了C#中Engine.GetObject方法的典型用法代码示例。如果您正苦于以下问题:C# Engine.GetObject方法的具体用法?C# Engine.GetObject怎么用?C# Engine.GetObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Engine的用法示例。


在下文中一共展示了Engine.GetObject方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Transform

        public void Transform(Engine engine, Package package)
        {
            if (package.GetByName(Package.PageName) == null) return;
            Page page = (Page)engine.GetObject(package.GetByName(Package.PageName));
            bool hasHeader = false;
            bool hasFooter = false;

            foreach (CP cp in page.ComponentPresentations)
            {
                if (cp.ComponentTemplate.Title.ToLower().Contains("header")) hasHeader = true;
                if (cp.ComponentTemplate.Title.ToLower().Contains("footer")) hasFooter = true;
            }
            if (!hasHeader)
            {
                ComponentTemplate headerCt = (ComponentTemplate)engine.GetObject(page.ContextRepository.RootFolder.WebDavUrl + HeaderComponentTemplateUrl);
                Component header = (Component)engine.GetObject(page.ContextRepository.RootFolder.WebDavUrl + HeaderComponentUrl);
                package.PushItem("headerCP", package.CreateStringItem(ContentType.Html, string.Format("<tcdl:ComponentPresentation type=\"Dynamic\" componentURI=\"{0}\" templateURI=\"{1}\" />", header.Id, headerCt.Id)));
            }
            if (!hasFooter)
            {
                ComponentTemplate footerCt = (ComponentTemplate)engine.GetObject(page.ContextRepository.RootFolder.WebDavUrl + FooterComponentTemplateUrl);
                Component footer = (Component)engine.GetObject(page.ContextRepository.RootFolder.WebDavUrl + FooterComponentUrl);
                package.PushItem("footerCP", package.CreateStringItem(ContentType.Html, string.Format("<tcdl:ComponentPresentation type=\"Dynamic\" componentURI=\"{0}\" templateURI=\"{1}\" />", footer.Id, footerCt.Id)));

            }
        }
开发者ID:mhassan26,项目名称:SDL-Tridion-Template-Tools,代码行数:26,代码来源:AddHeaderAndFooterToPage.cs

示例2: Transform

        public void Transform(Engine engine, Package package)
        {
            _log = TemplatingLogger.GetLogger(GetType());

            RepositoryLocalObject context =
                engine.GetObject(package.GetByName(Package.PageName)) as RepositoryLocalObject;
            if (context == null)
            {
                _log.Error("Could not retrieve page from package. Exiting.");
                return;
            }
            string categoryUrl = context.ContextRepository.WebDavUrl + NavigationCategoryWebDavUrl;
            Category navigation = (Category)engine.GetObject(categoryUrl);

            using (MemoryStream ms = new MemoryStream())
            {
                XmlTextWriter w = new XmlTextWriter(ms, new UTF8Encoding(false))
                {
                    Indentation = 4,
                    Formatting = Formatting.Indented
                };

                w.WriteStartDocument();
                w.WriteStartElement(Navigation.RootNodeName);
                KeywordsFilter filter = new KeywordsFilter(engine.GetSession()) { IsRoot = true };
                foreach (XmlNode rootChildren in navigation.GetListKeywords(filter))
                {
                    Keyword rootKeyword = (Keyword)engine.GetObject(rootChildren.Attributes["ID"].Value);
                    w.WriteStartElement(Navigation.NodeName);
                    NavigationNode n = new NavigationNode(rootKeyword);

                }
            }
        }
开发者ID:mhassan26,项目名称:SDL-Tridion-Template-Tools,代码行数:34,代码来源:GetSiteNavigationXml-Keywords.cs

示例3: Transform

 public void Transform(Engine engine, Package package)
 {
     RepositoryLocalObject context;
     if (package.GetByName(Package.ComponentName) != null)
     {
         context = (RepositoryLocalObject)engine.GetObject(package.GetByName(Package.ComponentName));
     }
     else if (package.GetByName(Package.PageName) != null)
     {
         context = (RepositoryLocalObject)engine.GetObject(package.GetByName(Package.PageName));
     }
     else
     {
         throw new Exception("Could not determine context from package. Did not find page or component in package");
     }
     Repository contextPublication = context.ContextRepository;
     if (contextPublication.Metadata == null) return;
     ItemFields metadata = new ItemFields(contextPublication.Metadata, contextPublication.MetadataSchema);
     ComponentLinkField configuration = (ComponentLinkField)metadata["SiteConfiguration"];
     foreach (Component c in configuration.Values)
     {
         ItemFields content = new ItemFields(c.Content, c.Schema);
         foreach (ItemField field in content)
         {
             var textField = field as TextField;
             if (textField != null)
             {
                 package.PushItem(textField.Name, package.CreateStringItem(ContentType.Text, textField.Value));
             }
         }
     }
 }
开发者ID:mhassan26,项目名称:SDL-Tridion-Template-Tools,代码行数:32,代码来源:GetSiteVariables.cs

示例4: Transform

        public void Transform(Engine engine, Package package)
        {
            const string componentTemplateWebdavUrl = "/System/Component%20Templates/Promo%20Content.tctcmp";
            if (package.GetByName(Package.PageName) == null) return;
            Page page = (Page)engine.GetObject(package.GetByName(Package.PageName));

            ComponentTemplate promoCt = (ComponentTemplate)engine.GetObject(page.ContextRepository.RootFolder.WebDavUrl + componentTemplateWebdavUrl);
            package.PushItem("promoCtId", package.CreateStringItem(ContentType.Text, promoCt.Id));
        }
开发者ID:mhassan26,项目名称:SDL-Tridion-Template-Tools,代码行数:9,代码来源:GetAuthorIndexDCT.cs

示例5: GetSG

		private StructureGroup GetSG(string sgWebDav, string Start_SG_Images, Publication pub, Engine engine) {
			String rootSGwebdav = pub.RootStructureGroup.WebDavUrl + "/" + Start_SG_Images + "/" + sgWebDav;
			StructureGroup result = engine.GetObject(rootSGwebdav) as StructureGroup;

			if (result == null) // SG not found, creating it
			{
				FindOrCreateSG(engine, rootSGwebdav);
				result = engine.GetObject(rootSGwebdav) as StructureGroup;
			} else {
				log.Debug(string.Format("SG '{0}' exists", rootSGwebdav));
			}
			return result;
		}
开发者ID:amarildopps,项目名称:yet-another-tridion-blog,代码行数:13,代码来源:Utilities.cs

示例6: Transform

        public void Transform(Engine engine, Package package)
        {
            TemplatingLogger log = TemplatingLogger.GetLogger(GetType());
            if (package.GetByName(Package.ComponentName) == null)
            {
                log.Info("This template should only be used with Component Templates. Could not find component in package, exiting");
                return;
            }
            var c = (Component)engine.GetObject(package.GetByName(Package.ComponentName));
            var container = (Folder)c.OrganizationalItem;
            var filter = new OrganizationalItemItemsFilter(engine.GetSession()) { ItemTypes = new[] { ItemType.Component } };

            // Always faster to use GetListItems if we only need limited elements
            foreach (XmlNode node in container.GetListItems(filter))
            {
                string componentId = node.Attributes["ID"].Value;
                string componentTitle = node.Attributes["Title"].Value;
            }

            // If we need more info, use GetItems instead
            foreach (Component component in container.GetItems(filter))
            {
                // If your filter is messed up, GetItems will return objects that may
                // not be a Component, in which case the code will blow up with an
                // InvalidCastException. Be careful with filter.ItemTypes[]
                Schema componentSchema = component.Schema;
                SchemaPurpose purpose = componentSchema.Purpose;
                XmlElement content = component.Content;
            }
        }
开发者ID:mhassan26,项目名称:SDL-Tridion-Template-Tools,代码行数:30,代码来源:GetComponentsInSameFolder.cs

示例7: Transform

        public void Transform(Engine engine, Package package)
        {
            TemplatingLogger log = TemplatingLogger.GetLogger(GetType());
            if (package.GetByName(Package.PageName) == null)
            {
                log.Info("Do not use this template building block in Component Templates");
                return;
            }

            Page page = (Page)engine.GetObject(package.GetByName(Package.PageName));

            string output;
            if (page.Title.ToLower().Contains("index"))
                output = StripNumbersFromTitle(page.OrganizationalItem.Title);
            else
            {
                output = GetLinkToSgIndexPage((StructureGroup)page.OrganizationalItem, engine.GetSession()) + Separator + StripNumbersFromTitle(page.Title);
            }

            foreach (OrganizationalItem parent in page.OrganizationalItem.GetAncestors())
            {
                output = GetLinkToSgIndexPage((StructureGroup)parent, engine.GetSession()) + Separator + output;
            }

            package.PushItem("breadcrumb", package.CreateStringItem(ContentType.Html, output));
        }
开发者ID:mhassan26,项目名称:SDL-Tridion-Template-Tools,代码行数:26,代码来源:GetPageBreadcrumb.cs

示例8: Transform

        public void Transform(Engine engine, Package package)
        {
            TemplatingLogger log = TemplatingLogger.GetLogger(GetType());
            RepositoryLocalObject context;
            if (package.GetByName(Package.PageName) != null)
            {

                context = (RepositoryLocalObject)engine.GetObject(package.GetByName(Package.PageName));
                log.Debug("Setting context to page with ID " + context.Id);
            }
            else
            {
                log.Info("This template building block should only run on a page. Exiting.");
                return;
            }

            if (!(context is Page)) return;

            Page page = (Page)context;

            package.PushItem(SiteEditPageContext, package.CreateStringItem(ContentType.Text, page.OwningRepository.Id));
            package.PushItem(SiteEditPublishContext, package.CreateStringItem(ContentType.Text, page.ContextRepository.Id));

            if (page.ComponentPresentations.Count <= 0) return;
            Component component = page.ComponentPresentations[0].Component;
            package.PushItem(SiteEditComponentContext, package.CreateStringItem(ContentType.Text, component.OwningRepository.Id));
        }
开发者ID:mhassan26,项目名称:SDL-Tridion-Template-Tools,代码行数:27,代码来源:SetSiteEditBlueprintContext.cs

示例9: IsInPublishingQueue

        /// <summary>
        /// Check the Publishing queue and determine whether the given TcmUri is already present in the queue.
        /// </summary>
        /// <param name="engine">Engine object</param>
        /// <param name="tcmUri">String representing the tcmuri of the item to check</param>
        /// <param name="state">PublishTransactionState the publish state to filter on</param>
        public static bool IsInPublishingQueue(Engine engine, String tcmUri, PublishTransactionState state)
        {
            Log.Debug(String.Format("Check Publishing queue for item '{0}'", tcmUri));

            Session session = engine.GetSession();
            PublishTransactionsFilter filter = new PublishTransactionsFilter(session);

            filter.PublishTransactionState = state;
            RepositoryLocalObject item = engine.GetObject(tcmUri) as RepositoryLocalObject;
            if (item != null) filter.ForRepository = item.ContextRepository;

            PublicationTarget publicationTarget = engine.PublishingContext.PublicationTarget;
            if (publicationTarget != null)
            {
                filter.PublicationTarget = publicationTarget;
            }

            XmlElement element = PublishEngine.GetListPublishTransactions(filter);
            XmlNamespaceManager namespaceManager = new XmlNamespaceManager(new NameTable());
            namespaceManager.AddNamespace("tcm", "http://www.tridion.com/ContentManager/5.0");

            String xPath = String.Format("tcm:ListPublishTransactions/tcm:Item[@ItemID='{0}']", tcmUri);
            XmlNodeList nodeList = element.SelectNodes(xPath, namespaceManager);

            return nodeList.Count > 0;
        }
开发者ID:mhassan26,项目名称:SDL-Tridion-Template-Tools,代码行数:32,代码来源:TemplateUtils.cs

示例10: Transform

 public void Transform(Engine engine, Package package)
 {
     Component component = (Component)engine.GetObject(package.GetByName(Package.ComponentName));
     ItemFields fields = new ItemFields(component.Content, component.Schema);
     TextField code = (TextField)fields["Code"];
     package.PushItem(Package.OutputName, package.CreateStringItem(ContentType.Html, code.Value));
 }
开发者ID:mhassan26,项目名称:SDL-Tridion-Template-Tools,代码行数:7,代码来源:RenderCode.cs

示例11: Transform

        public void Transform(Engine engine, Package package)
        {
            if (package.GetByName(Package.PageName) == null) return;
            comm.Page page = (comm.Page)engine.GetObject(package.GetByName(Package.PageName));
            Dictionary<string, List<ComponentPresentation>> lists = new Dictionary<string, List<ComponentPresentation>>();
            string matchTokens = package.GetValue("ComponentTemplateTitleMatchTokens");
            if (!String.IsNullOrEmpty(matchTokens))
            {
                foreach (string token in matchTokens.Split(','))
                {
                    _matchTokens.Add(token.Trim());
                }
            }

            foreach (comm.ComponentPresentation cp in page.ComponentPresentations)
            {
                string ct = GetPresentationType(cp.ComponentTemplate.Title);
                if (!lists.ContainsKey(ct))
                    lists.Add(ct, new List<ComponentPresentation>());
                lists[ct].Add(new ComponentPresentation(cp.Component.Id, cp.ComponentTemplate.Id));
            }

            foreach (string token in lists.Keys)
            {
                Item item = package.CreateStringItem(ContentType.ComponentArray, ComponentPresentationList.ToXml(lists[token]));
                package.PushItem(token + "Components", item);
            }
        }
开发者ID:mhassan26,项目名称:SDL-Tridion-Template-Tools,代码行数:28,代码来源:GroupComponentsByTemplate.cs

示例12: Transform

        public void Transform(Engine engine, Package package)
        {
            Component c = (Component)engine.GetObject(package.GetByName(Package.ComponentName));

            XmlElement xdoc = c.Content;

            package.PushItem(Package.OutputName, package.CreateStringItem(ContentType.Text, JsonConvert.SerializeXmlNode(xdoc)));
        }
开发者ID:NunoLinhares,项目名称:TridionWebData,代码行数:8,代码来源:BsonFromXml.cs

示例13: Transform

        public void Transform(Engine engine, Package p)
        {
            Component component = (Component)engine.GetObject(p.GetByName(Package.ComponentName));
            ItemFields fields = new ItemFields(component.Content, component.Schema);
            SingleLineTextField field = (SingleLineTextField) fields["ArticleTitle"];

            p.PushItem("AsHtml", p.CreateHtmlItem(System.Security.SecurityElement.Escape(field.Value)));
            p.PushItem("AsText", p.CreateStringItem(ContentType.Text, System.Security.SecurityElement.Escape(field.Value)));
        }
开发者ID:mhassan26,项目名称:SDL-Tridion-Template-Tools,代码行数:9,代码来源:CompareHtmlvsTextItem.cs

示例14: Transform

 public void Transform(Engine engine, Package package)
 {
     Page page = (Page)engine.GetObject(package.GetByName(Package.PageName));
     StringBuilder output = new StringBuilder();
     foreach (CP cp in page.ComponentPresentations)
     {
         output.Append(engine.RenderComponentPresentation(cp.Component.Id, cp.ComponentTemplate.Id));
     }
     package.PushItem(Package.OutputName, package.CreateStringItem(ContentType.Html, output.ToString()));
 }
开发者ID:mhassan26,项目名称:SDL-Tridion-Template-Tools,代码行数:10,代码来源:RenderAllComponentPresentations.cs

示例15: Transform

 public void Transform(Engine engine, Package package)
 {
     Component component = (Component)engine.GetObject(package.GetByName(Package.ComponentName));
     package.PushItem(package.CreateMultimediaItem(component.Id));
     if (package.GetByName(Package.OutputName) == null)
     {
         Item output = package.CreateStringItem(ContentType.Text, string.Empty);
         package.PushItem(Package.OutputName, output);
     }
 }
开发者ID:mhassan26,项目名称:SDL-Tridion-Template-Tools,代码行数:10,代码来源:FilePublisher.cs


注:本文中的Engine.GetObject方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。