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


C# Item.Reload方法代码示例

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


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

示例1: PasteSharedFields

		protected virtual void PasteSharedFields(IItemData serializedItemData, Item targetItem, bool newItemWasCreated, List<TemplateMissingFieldException> softErrors)
		{
			bool commitEditContext = false;

			try
			{
				targetItem.Editing.BeginEdit();

				targetItem.RuntimeSettings.ReadOnlyStatistics = true;
				targetItem.RuntimeSettings.SaveAll = true;

				var allTargetSharedFields = serializedItemData.SharedFields.ToLookup(field => field.FieldId);

				foreach (Field field in targetItem.Fields)
				{
					if (field.Shared && !allTargetSharedFields.Contains(field.ID.Guid))
					{
						_logger.ResetFieldThatDidNotExistInSerialized(field);

						field.Reset();

						commitEditContext = true;
					}
				}

				foreach (var field in serializedItemData.SharedFields)
				{
					try
					{
						if (PasteField(targetItem, field, newItemWasCreated))
							commitEditContext = true;
					}
					catch (TemplateMissingFieldException tex)
					{
						softErrors.Add(tex);
					}
				}

				// we commit the edit context - and write to the DB - only if we changed something
				if (commitEditContext)
				{
					targetItem.Editing.EndEdit();

					ClearCaches(targetItem.Database, new ID(serializedItemData.Id));

					targetItem.Reload();

					ResetTemplateEngineIfItemIsTemplate(targetItem);
				}
			}
			finally
			{
				if (targetItem.Editing.IsEditing)
					targetItem.Editing.CancelEdit();
			}
		}
开发者ID:OlegJytnik,项目名称:Rainbow,代码行数:56,代码来源:DefaultDeserializer.cs

示例2: RenameIfNeeded

		protected void RenameIfNeeded(IItemData serializedItemData, Item targetItem)
		{
			if (targetItem.Name == serializedItemData.Name && targetItem.BranchId.Guid.Equals(serializedItemData.BranchId)) return;

			string oldName = targetItem.Name;
			Guid oldBranchId = targetItem.BranchId.Guid;

			using (new EditContext(targetItem))
			{
				targetItem.RuntimeSettings.ReadOnlyStatistics = true;
				targetItem.Name = serializedItemData.Name;
				targetItem.BranchId = ID.Parse(serializedItemData.BranchId);
			}

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

			if (oldName != serializedItemData.Name)
				_logger.RenamedItem(targetItem, oldName);

			if (oldBranchId != serializedItemData.BranchId)
				_logger.ChangedBranchTemplate(targetItem, new ID(oldBranchId).ToString());
		}
开发者ID:OlegJytnik,项目名称:Rainbow,代码行数:23,代码来源:DefaultDeserializer.cs

示例3: 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

示例4: RenameIfNeeded

        protected void RenameIfNeeded(SyncItem syncItem, Item targetItem)
        {
            if (targetItem.Name != syncItem.Name || targetItem.BranchId.ToString() != syncItem.BranchId)
            {
                string oldName = targetItem.Name;
                string oldBranchId = targetItem.BranchId.ToString();

                using (new EditContext(targetItem))
                {
                    targetItem.RuntimeSettings.ReadOnlyStatistics = true;
                    targetItem.Name = syncItem.Name;
                    targetItem.BranchId = ID.Parse(syncItem.BranchId);
                }

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

                if (oldName != syncItem.Name)
                    _logger.RenamedItem(targetItem, oldName);

                if (oldBranchId != syncItem.BranchId)
                    _logger.ChangedBranchTemplate(targetItem, oldBranchId);
            }
        }
开发者ID:BerserkerDotNet,项目名称:Unicorn,代码行数:24,代码来源:FiatSitecoreSerializationFormatter.cs


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