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


C# Item.ChangeTemplate方法代码示例

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


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

示例1: MigrateItem

        public void MigrateItem(Item item)
        {
            if (ShouldMigrate(database.GetTemplate(item.TemplateID)))
             {
            TemplateItem oldTemplate = database.GetTemplate(item.TemplateID);
            TemplateItem newTemplate = GetVersionedMediaTemplateItem(oldTemplate);

            item.ChangeTemplate(newTemplate);
            Log.Info("Item modified: " + item.Paths.FullPath, this);
            Log.Info("Source template: " + oldTemplate.InnerItem.Paths.FullPath, this);
            Log.Info("Target template: " + newTemplate.InnerItem.Paths.FullPath, this);
            MakeVersionedFields(item);
             }
             else
             {
            Log.Info("Item skipped: " + item.Paths.FullPath, this);
             }
        }
开发者ID:ivansharamok,项目名称:VersionableMedia,代码行数:18,代码来源:UnversionedToVersioned.cs

示例2: ChangeTemplateIfNeeded

		protected void ChangeTemplateIfNeeded(IItemData serializedItemData, Item targetItem)
		{
			if (targetItem.TemplateID.Guid == serializedItemData.TemplateId) return;

			var oldTemplate = targetItem.Template;
			var newTemplate = targetItem.Database.Templates[new ID(serializedItemData.TemplateId)];

			Assert.IsNotNull(newTemplate, "Cannot change template of {0} because its new template {1} does not exist!", targetItem.ID, serializedItemData.TemplateId);

			using (new EditContext(targetItem))
			{
				targetItem.RuntimeSettings.ReadOnlyStatistics = true;
				try
				{
					targetItem.ChangeTemplate(newTemplate);
				}
				catch
				{
					// this generally means that we tried to sync an item and change its template AND we already deleted the item's old template in the same sync
					// the Sitecore change template API chokes if the item's CURRENT template is unavailable, but we can get around that
					// issure reported to Sitecore Support (406546)
					lock (targetItem.SyncRoot)
					{
						Template sourceTemplate = TemplateManager.GetTemplate(targetItem);
						Template targetTemplate = TemplateManager.GetTemplate(newTemplate.ID, targetItem.Database);

						Error.AssertNotNull(targetTemplate, "Could not get target in ChangeTemplate");

						// this is probably true if we got here. This is the check the Sitecore API fails to make, and throws a NullReferenceException.
						if (sourceTemplate == null) sourceTemplate = targetTemplate;

						TemplateChangeList templateChangeList = sourceTemplate.GetTemplateChangeList(targetTemplate);
						TemplateManager.ChangeTemplate(targetItem, templateChangeList);
					}
				}
			}

			ClearCaches(targetItem.Database, targetItem.ID);
			targetItem.Reload();

			_logger.ChangedTemplate(targetItem, oldTemplate);
		}
开发者ID:OlegJytnik,项目名称:Rainbow,代码行数:42,代码来源:DefaultDeserializer.cs

示例3: UpdateItem

        protected virtual bool UpdateItem(Item item, object importRow, string itemName, Item parentItem, ref LevelLogger logger)
        {
            var updateItemLogger = logger.CreateLevelLogger("Update Item");
            var updatedItem = false;
            try
            {
                using (new LanguageSwitcher(ImportToLanguageVersion))
                {
                    using (new SecurityDisabler())
                    {
                        if (AddLanguageVersionIfNoneExists(item, ref logger))
                        {
                            updateItemLogger.IncrementCounter(IncrementConstants.LanguageVersionAdded);
                        }

                        // Move the item to it's correct position
                        if (!DoNotMoveItemToParentFromImport)
                        {
                            if (item.ParentID != parentItem.ID)
                            {
                                MoveItem(item, parentItem, ref updateItemLogger);
                            }
                        }
                        else
                        {
                            // When we do not move the item to it's importet parent, then we must set the parentItem to the currenct parent, to enable the validation of duplicate items names.
                            parentItem = item.Parent;
                        }

                        if (OnDuplicateItemNamesGeneratePostfixNumber)
                        {
                            string errorMessage = "";
                            var checkIfItemNameLogger = updateItemLogger.CreateLevelLogger();
                            var newItemName = CheckIfItemNameIsUniqueAndGeneratePostFixNumberIfNot(importRow, item, itemName, itemName, parentItem, 1, ref checkIfItemNameLogger);
                            if (checkIfItemNameLogger.HasErrors())
                            {
                                checkIfItemNameLogger.AddError("Error in 'CheckIfItemNameIsUniqueAndGeneratePostFixNumberIfNot'", String.Format(
                                         "The 'CheckIfItemNameIsUniqueAndGeneratePostFixNumberIfNot' method failed with an error. The itemname was not changed to a postfixnumber since the check failed. But the Update process was continued. ImportRow: {0}. ErrorMessage: {1}",
                                         GetImportRowDebugInfo(importRow), errorMessage));
                                logger.IncrementCounter(IncrementConstants.FailureItems);
                            }
                            if (!itemName.Equals(newItemName))
                            {
                                updateItemLogger.AddInfo("Item name regenerated", String.Format("The item name '{0}' was regenerated to '{1}' to avoid duplicate item name.", itemName, newItemName));
                                itemName = newItemName;
                                logger.IncrementCounter(IncrementConstants.ItemNameRegenerated);
                            }
                        }
                        if(OnDuplicateItemNamesGeneratePostfixNumber || UpdateItemName)
                        {
                            if (item.Name != itemName)
                            {
                                item.Editing.BeginEdit();
                                updateItemLogger.AddInfo("Item name updated", String.Format("The item name '{0}' was updated to '{1}'.", item.Name, itemName));
                                item.Name = itemName;
                                item.Editing.EndEdit();
                                logger.IncrementCounter(IncrementConstants.RenamedItems);
                            }
                        }

                        if (ValidateIfItemKeyIsUnique)
                        {
                            if (!IsItemNameUnique(parentItem, item, ref updateItemLogger))
                            {
                                // The validation of the item found that there exists more than one item under the parent with the same item key.
                                // We logged the error, but continue processing item. The duplicated item names must be corrected manually.
                                updateItemLogger.IncrementCounter(IncrementConstants.FailureItems);
                                return false;
                            }
                        }

                        // Change template if type has changed and we are not explicit told not to
                        if (!DoNotChangeTemplate && ToWhatTemplates.Count > 0)
                        {
                            string errorMessage = String.Empty;
                            var getToWhatLogger = updateItemLogger.CreateLevelLogger();
                            var toWhatTemplate = GetToWhatTemplateItem(importRow, ref getToWhatLogger);
                            if (getToWhatLogger.HasErrors())
                            {
                                getToWhatLogger.AddError("Failure in 'GetToWhatTemplateItem' method", String.Format(
                                        "The 'GetToWhatTemplateItem' method failed with an error. ImportRow: {0}. Therefor it was not possible to determine wheether the item template should change. The Change template process was aborted as well as the rest of the update item process. {1}",
                                        GetImportRowDebugInfo(importRow), errorMessage));
                                updateItemLogger.IncrementCounter(IncrementConstants.FailureItems);
                                return false;
                            }
                            if (toWhatTemplate != null)
                            {
                                var templateItem = toWhatTemplate as TemplateItem;
                                if (templateItem != null)
                                {
                                    if (item.TemplateID != toWhatTemplate.ID)
                                    {
                                        string fromTemplateDebugInfo = GetTemplateDebugInfo(item.Template);
                                        item.Editing.BeginEdit();
                                        item.ChangeTemplate(templateItem);
                                        updateItemLogger.AddInfo("Change Template",
                                            String.Format("Changed template from '{0}' to '{1}'.", fromTemplateDebugInfo,
                                                GetTemplateDebugInfo(item.Template)));
                                        item.Editing.EndEdit();
                                        updateItemLogger.IncrementCounter(IncrementConstants.ChangedTemplate);
//.........这里部分代码省略.........
开发者ID:NetlabSharedSource,项目名称:SitecoreDataSync,代码行数:101,代码来源:BaseDataMap.cs


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