Exemplo n.º 1
0
		public static StepResult InstallContent(Content content)
		{
			bool isNewContent;
			try
			{
				SnC.Content snContent = CreateOrLoadContent(content, out isNewContent);
				foreach (var attachment in content.Attachments)
				{
					var data = new BinaryData() { FileName = attachment.FileName };
					data.SetStream(attachment.Manifest.GetStream(attachment.FileName));
					snContent[attachment.FieldName] = data;
				}
				snContent.Save();
				content.IsNewContent = isNewContent;
                if (!SetMetadata(snContent, content, isNewContent, false))
                {
                    Logger.LogWarningMessage(PrintFieldErrors(snContent));
                    return new StepResult { Kind = StepResultKind.Warning };
                }
			}
			catch (Exception transferEx)
			{
                Logger.LogException(transferEx);
				return new StepResult { Kind = StepResultKind.Error };
			}
			return new StepResult { Kind = StepResultKind.Successful };
		}
Exemplo n.º 2
0
		public static StepResult UpdateReferences(Content content)
		{
			try
			{
				SnC.Content snContent = SnC.Content.Load(content.Path);
				//snContent.Save();
				if (!SetMetadata(snContent, content, content.IsNewContent, true))
                {
                    Logger.LogWarningMessage(PrintFieldErrors(snContent));
                    return new StepResult { Kind = StepResultKind.Warning };
                }
			}
			catch (Exception transferEx)
			{
                Logger.LogException(transferEx);
				return new StepResult { Kind = StepResultKind.Error };
			}
			return new StepResult { Kind = StepResultKind.Successful };
		}
Exemplo n.º 3
0
		private static SnC.Content CreateOrLoadContent(Content contentInfo, out bool isNewContent)
		{
			var parentPath = ContentManager.Path.GetParentPath(contentInfo.Path);
			Node parent = Node.LoadNode(parentPath);
			if(parent == null)
				parent = EnsureFolder(parentPath);

			//if (!(parent is IFolder))
			//    throw new InstallException("");

			SnC.Content content = SnC.Content.Load(contentInfo.Path);
			isNewContent = content == null;
			if(isNewContent)
				content = SnC.Content.CreateNew(contentInfo.ContentType, parent, contentInfo.Name);

			return content;
		}
Exemplo n.º 4
0
		private static bool SetMetadata(SnC.Content snContent, Content content, bool isNewContent, bool updateReferences)
		{
			XmlDocument xml = new XmlDocument();
			xml.LoadXml(content.Data);
			var context = new ImportContext(xml.SelectNodes("/ContentMetaData/Fields/*"), null, isNewContent, true, updateReferences);
			bool result = snContent.ImportFieldData(context);
			var contentId = snContent.ContentHandler.Id;
			content.HasReference = context.HasReference;
			return result;
		}