예제 #1
0
파일: Image.cs 프로젝트: michlG/Caloom
        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);
        }
예제 #2
0
        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);
            }
        }