public static void SetMediaContent(this IInformationObject rootObject, IContainerOwner containerOwner, string containerID, string containedField, object mediaContent) { List <IInformationObject> containerList = new List <IInformationObject>(); rootObject.FindObjectsFromTree(containerList, iObj => iObj.ID == containerID, false); foreach (var iObj in containerList) { var type = iObj.GetType(); var prop = type.GetProperty(containedField); if (prop == null) { throw new InvalidDataException(String.Format("No property {0} found in type {1}", containedField, type.Name)); } MediaContent propValue = (MediaContent)prop.GetValue(iObj, null); if (propValue == null && mediaContent == null) { continue; } if (propValue != null && mediaContent == null) { propValue.ClearCurrentContent(containerOwner); prop.SetValue(iObj, null, null); continue; } if (propValue == null && mediaContent != null) { propValue = MediaContent.CreateDefault(); prop.SetValue(iObj, propValue, null); } propValue.SetMediaContent(containerOwner, propValue.ID, mediaContent); } }
public bool PerformAddOperation(string commandName, InformationSourceCollection sources, string requesterLocation, HttpFileCollection files) { string[] cmdIDList = commandName.Split('_'); if (cmdIDList.Length < 2) { return(false); } string cmd = cmdIDList[0]; string cmdID = cmdIDList[1]; if (cmdID != this.ID) { return(false); } var defaultSource = sources.GetDefaultSource(typeof(ImageGroup).FullName); ImageGroup currImageGroup = (ImageGroup)defaultSource.RetrieveInformationObject(); VirtualOwner owner = VirtualOwner.FigureOwner(this); Image addedImage = Image.CreateDefault(); addedImage.CopyContentFrom(this); addedImage.ImageData = MediaContent.CreateDefault(); HttpPostedFile postedFile = files[this.ImageData.ID]; if (postedFile != null && String.IsNullOrWhiteSpace(postedFile.FileName) == false) { addedImage.SetMediaContent(owner, addedImage.ImageData.ID, postedFile); } currImageGroup.ImagesCollection.CollectionContent.Add(addedImage); currImageGroup.StoreInformationMasterFirst(owner, true); return(true); }
private static void setTextContentImage(TextContent textContent, MediaContent legacyContent) { var owner = VirtualOwner.FigureOwner(textContent); var existingImageData = textContent.ImageData; if (existingImageData != null && legacyContent != null) { // If actual content is equal, return without doing anything if(existingImageData.GetMD5FromStorage() == legacyContent.GetMD5FromStorage()) return; var legacyData = legacyContent.GetContentData(); if (legacyData == null) { existingImageData.ClearCurrentContent(owner); textContent.ImageData = null; return; } string fileNameWithExtension = "data" + legacyContent.FileExt; existingImageData.SetMediaContent(fileNameWithExtension, legacyContent.GetContentData()); } if (existingImageData != null && legacyContent == null) { existingImageData.ClearCurrentContent(owner); textContent.ImageData = null; return; } if (existingImageData == null && legacyContent != null) { var legacyData = legacyContent.GetContentData(); if (legacyData == null) return; string fileNameWithExtension = "data" + legacyContent.FileExt; var newImageData = new MediaContent(); newImageData.SetLocationAsOwnerContent(owner, newImageData.ID); newImageData.SetMediaContent(fileNameWithExtension, legacyContent.GetContentData()); textContent.ImageData = newImageData; } }