示例#1
0
        private void PopulateFields(Data.Guid siteGuid, Control parent, CmsContent item, String oldFilename)
        {
            if (item.ContentType.IsFileType)
            {
                FileUpload upload = (FileUpload)ControlHelper.FindRecursive(parent, "fileupload");
                if ((!upload.HasFile) && (oldFilename == null))
                    throw new ArgumentException("This content type requires that a file be uploaded");

                if (upload.HasFile)
                {
                    byte[] data = upload.FileBytes;
                    String filename = (oldFilename == null) ? upload.FileName : oldFilename;
                    String mimeType = upload.PostedFile.ContentType;

                    Boolean overwrite = false;
                    if (!String.IsNullOrWhiteSpace(oldFilename))
                        overwrite = true;

                    if (!ContentFileUploadImpl.IsValidFileType(filename))
                        throw new ArgumentException("The specified filetype is not currently supported by the CMS. Valid file types are:" + ContentFileUploadImpl.ValidExtensionsString);

                    ContentFileUploadImpl handler = new ContentFileUploadImpl();
                    handler.Save(siteGuid,data, filename, overwrite);

                    CmsContentField filenameField = new CmsContentField();
                    CmsContentField mimeTypeField = new CmsContentField();

                    filenameField.Name = "filename";
                    filenameField.ObjectType = "System.String";
                    filenameField.Value = filename;
                    filenameField.Parent = item;

                    mimeTypeField.Name = "mimetype";
                    mimeTypeField.ObjectType = "System.String";
                    mimeTypeField.Value = mimeType;
                    mimeTypeField.Parent = item;

                    item.AddField(filenameField);
                    item.AddField(mimeTypeField);
                }
            }

            //Loop through each expected id and build up the CMS content item
            IList<CmsContentTypeField> typeFields = ContentManager.Instance.GetContentTypeFields(item.ContentType.Guid);
            foreach (CmsContentTypeField typeField in typeFields)
            {
                String id = ContentWebControlManager.GetControlId(typeField);
                String[] parts = id.Split('_');
                String objectType = parts[1];
                String propertyName = parts[2];

                String result = null;
                Control control = ControlHelper.FindRecursive(parent, id);
                switch (objectType.ToLower())
                {
                    case CmsContentTypeField.Textbox:
                    case CmsContentTypeField.Textarea:
                        result = ContentWebControlManager.GetTextboxValue(control);
                        break;
                    case CmsContentTypeField.Datetime:
                        result = ContentWebControlManager.GetDateTimeValue(control);
                        break;
                    case CmsContentTypeField.Dropdown:
                        result = ContentWebControlManager.GetDropdownValue(control);
                        break;
                }

                CmsContentField field = new CmsContentField();
                field.Name = typeField.SystemName;
                field.ObjectType = typeField.ObjectType;
                field.Value = result;

                field.Parent = item;
                item.AddField(field);
            }
        }
示例#2
0
 public virtual void RemoveField(CmsContentField field)
 {
     this.fields.Remove(field);
     field.Parent = null;
 }
示例#3
0
 public virtual void AddField(CmsContentField field)
 {
     field.Parent = this;
     this.fields.Add(field);
 }
示例#4
0
        public virtual CmsContentField FindField(String key)
        {
            CmsContentField result = null;

            if (key.ToLower().Equals("id"))
            {
                result = new CmsContentField();
                result.Name = "Id";
                result.Value = this.Id.ToString();
                result.ObjectType = "System.String";
            }
            else if (key.ToLower().Equals("guid"))
            {
                result = new CmsContentField();
                result.Name = "Guid";
                result.Value = this.Guid.ToString();
                result.ObjectType = "System.String";
            }
            else if (key.ToLower().Equals("content"))
            {
                result = new CmsContentField();
                result.Name = "Content";
                result.Value = this.Content.ToString();
                result.ObjectType = "System.String";
            }
            else
            {
                result = ((List<CmsContentField>)this.Fields).Find(
                   delegate(CmsContentField f) { return f.Name.ToLower().Equals(key.ToLower()); });
            }

            return result;
        }
        private void DeployContent(SitePackage sitepackage, Data.Guid guid)
        {
            foreach (SiteContent ct in sitepackage.SiteContent)
            {
                CmsContent newcontent = new CmsContent();
                CmsContent content = ct.Content;
                IList<CmsContentField> fields = new List<CmsContentField>(content.Fields);

                newcontent.Guid = System.Guid.NewGuid().ToString();
                newcontent.SubscriptionId = guid.Value;
                newcontent.ContentType = content.ContentType;
                newcontent.Content = content.Content;
                newcontent.Culture = content.Culture;
                newcontent.ExpireDate = content.ExpireDate;
                newcontent.IsApproved = content.IsApproved;
                newcontent.LastSaved = content.LastSaved;
                newcontent.PublishDate = content.PublishDate;
                newcontent.RegistrationPage = content.RegistrationPage;
                newcontent.RequiresRegistration = content.RequiresRegistration;
                foreach (CmsContentField field in fields)
                {
                    CmsContentField newfield = new CmsContentField();
                    newfield.Name = field.Name;
                    newfield.ObjectType = field.ObjectType;
                    newfield.Value = field.Value;

                    newcontent.AddField(newfield);
                }

                ContentManager.Instance.Save(newcontent);
            }
        }