當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。