Exemple #1
0
        public static void SendTestmail(string email,
                                        umbraco.cms.businesslogic.property.Property Property,
                                        string fromName, string fromEmail, bool IsHtml)
        {
            // version
            string version = Property.VersionId.ToString();

            // Get document
            umbraco.cms.businesslogic.web.Document d = new umbraco.cms.businesslogic.web.Document(umbraco.cms.businesslogic.Content.GetContentFromVersion(Property.VersionId).Id);
            System.Web.HttpContext.Current.Items["pageID"] = d.Id;

            // Format mail
            string subject = d.Text;
            string sender  = "\"" + fromName + "\" <" + fromEmail + ">";

            // Get template
            System.Text.StringBuilder    sb     = new System.Text.StringBuilder();
            System.IO.StringWriter       sw     = new StringWriter(sb);
            System.Web.UI.HtmlTextWriter writer = new System.Web.UI.HtmlTextWriter(sw);
            umbraco.template             t      = new template(d.Template);
            t.ParseWithControls(new umbraco.page(d.Id, d.Version)).RenderControl(writer);

            // Embedded emails ;) added by DB, 2005-10-04

            EmailMessage message = mailerHelper.CreateEmbeddedEmail(sb.ToString(), Cms.BusinessLogic.web.Document.GetContentFromVersion(Property.VersionId).Id);

            message.FromAddress = new EmailAddress(fromEmail, fromName);
            message.ToAddresses.Add(new EmailAddress(email));
            message.Subject = subject;
            message.Send(new SmtpServer(GlobalSettings.SmtpServer));
        }
Exemple #2
0
        void Member_New(Member member, NewEventArgs e)
        {
            Type typeMemberType = MemberTypeManager.GetMemberTypeType(member.ContentType.Alias);

            foreach (PropertyInfo propInfo in typeMemberType.GetProperties(BindingFlags.Public | BindingFlags.Instance))
            {
                MemberTypePropertyAttribute propAttr = Util.GetAttribute <MemberTypePropertyAttribute>(propInfo);
                if (propAttr == null)
                {
                    continue; // skip this property - not part of a Member type
                }

                string propertyName;
                string propertyAlias;
                MemberTypeManager.ReadPropertyNameAndAlias(propInfo, propAttr, out propertyName, out propertyAlias);

                if (propAttr.DefaultValue != null)
                {
                    try
                    {
                        umbraco.cms.businesslogic.property.Property property = member.getProperty(propertyAlias);
                        property.Value = Convert.ChangeType(propAttr.DefaultValue, propInfo.PropertyType);
                    }
                    catch (Exception exc)
                    {
                        throw new Exception(string.Format("Cannot set default value ('{0}') for property {1}.{2}. Error: {3}",
                                                          propAttr.DefaultValue, typeMemberType.Name, propInfo.Name, exc.Message), exc);
                    }
                }
            }
        }
        public void update(documentCarrier carrier, string username, string password)
        {
            Authenticate(username, password);

            if (carrier.Id == 0)
            {
                throw new Exception("ID must be specifed when updating");
            }
            if (carrier == null)
            {
                throw new Exception("No carrier specified");
            }

            umbraco.BusinessLogic.User user = GetUser(username, password);

            Document doc = null;

            try
            {
                doc = new Document(carrier.Id);
            }
            catch {}
            if (doc == null)
            {
                // We assign the new values:
                doc.ReleaseDate = carrier.ReleaseDate;
            }
            doc.ExpireDate = carrier.ExpireDate;
            if (carrier.ParentID != 0)
            {
                doc.Move(carrier.ParentID);
            }

            if (carrier.Name.Length != 0)
            {
                doc.Text = carrier.Name;
            }

            // We iterate the properties in the carrier
            if (carrier.DocumentProperties != null)
            {
                foreach (documentProperty updatedproperty in carrier.DocumentProperties)
                {
                    umbraco.cms.businesslogic.property.Property property = doc.getProperty(updatedproperty.Key);

                    if (property == null)
                    {
                    }
                    else
                    {
                        property.Value = updatedproperty.PropertyValue;
                    }
                }
            }
            handlePublishing(doc, carrier, user);
        }
Exemple #4
0
        public int create(memberCarrier carrier, int memberTypeId, string username, string password)
        {
            Authenticate(username, password);

            // Some validation
            if (carrier == null)
            {
                throw new Exception("No carrier specified");
            }
            if (carrier.Id != 0)
            {
                throw new Exception("ID cannot be specifed when creating. Must be 0");
            }
            if (string.IsNullOrEmpty(carrier.DisplayedName))
            {
                carrier.DisplayedName = "unnamed";
            }

            // we fetch the membertype
            umbraco.cms.businesslogic.member.MemberType mtype = new umbraco.cms.businesslogic.member.MemberType(memberTypeId);

            // Check if the membertype exists
            if (mtype == null)
            {
                throw new Exception("Membertype " + memberTypeId + " not found");
            }

            // Get the user that creates
            umbraco.BusinessLogic.User user = GetUser(username, password);

            // Create the new member
            umbraco.cms.businesslogic.member.Member newMember = umbraco.cms.businesslogic.member.Member.MakeNew(carrier.DisplayedName, mtype, user);

            // We iterate the properties in the carrier
            if (carrier.MemberProperties != null)
            {
                foreach (memberProperty updatedproperty in carrier.MemberProperties)
                {
                    umbraco.cms.businesslogic.property.Property property = newMember.getProperty(updatedproperty.Key);
                    if (property != null)
                    {
                        property.Value = updatedproperty.PropertyValue;
                    }
                }
            }
            return(newMember.Id);
        }
Exemple #5
0
        /// <summary>
        /// Raises the <see cref="E:System.Web.UI.Control.Init"/> event.
        /// </summary>
        /// <param name="e">An <see cref="T:System.EventArgs"/> object that contains the event data.</param>
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            this.minSelectionCustomValidator.ServerValidate += new ServerValidateEventHandler(this.MinSelectionCustomValidator_ServerValidate);
            this.maxSelectionCustomValidator.ServerValidate += new ServerValidateEventHandler(this.MaxSelectionCustomValidator_ServerValidate);


            var property      = new CmsProperty(((umbraco.cms.businesslogic.datatype.DefaultData) this.data).PropertyId);
            var documentType  = UmbracoContext.Current.Application.Services.ContentTypeService.GetContentType(property.PropertyType.ContentTypeId);
            var propertyGroup = documentType.PropertyGroups.FirstOrDefault(x => x.Id == property.PropertyType.PropertyTypeGroup);

            if (propertyGroup != null)
            {
                this.minSelectionCustomValidator.ErrorMessage = string.Concat("The ", property.PropertyType.Alias, " field in the ", propertyGroup.Name, " tab requires a minimum of ", this.options.MinSelection.ToString(), " selections<br/>");
                this.maxSelectionCustomValidator.ErrorMessage = string.Concat("The ", property.PropertyType.Alias, " field in the ", propertyGroup.Name, " tab has exceeded the maximum number of selections<br/>");
            }
        }
Exemple #6
0
        public void update(memberCarrier carrier, string username, string password)
        {
            Authenticate(username, password);

            // Some validation
            if (carrier.Id == 0)
            {
                throw new Exception("ID must be specifed when updating");
            }
            if (carrier == null)
            {
                throw new Exception("No carrier specified");
            }

            // Get the user
            umbraco.BusinessLogic.User user = GetUser(username, password);

            // We load the member
            Member member = new Member(carrier.Id);

            // We assign the new values:
            member.LoginName = carrier.LoginName;
            member.Text      = carrier.DisplayedName;
            member.Email     = carrier.Email;
            member.Password  = carrier.Password;

            // We iterate the properties in the carrier
            if (carrier.MemberProperties != null)
            {
                foreach (memberProperty updatedproperty in carrier.MemberProperties)
                {
                    umbraco.cms.businesslogic.property.Property property = member.getProperty(updatedproperty.Key);
                    if (property != null)
                    {
                        property.Value = updatedproperty.PropertyValue;
                    }
                }
            }
        }
        public int create(documentCarrier carrier, string username, string password)
        {
            Authenticate(username, password);

            // Some validation
            if (carrier == null)
            {
                throw new Exception("No carrier specified");
            }
            if (carrier.ParentID == 0)
            {
                throw new Exception("Document needs a parent");
            }
            if (carrier.DocumentTypeID == 0)
            {
                throw new Exception("Documenttype must be specified");
            }
            if (carrier.Id != 0)
            {
                throw new Exception("ID cannot be specifed when creating. Must be 0");
            }
            if (carrier.Name == null || carrier.Name.Length == 0)
            {
                carrier.Name = "unnamed";
            }

            umbraco.BusinessLogic.User user = GetUser(username, password);

            // We get the documenttype
            umbraco.cms.businesslogic.web.DocumentType docType = new umbraco.cms.businesslogic.web.DocumentType(carrier.DocumentTypeID);
            if (docType == null)
            {
                throw new Exception("DocumenttypeID " + carrier.DocumentTypeID + " not found");
            }

            // We create the document
            Document newDoc = Document.MakeNew(carrier.Name, docType, user, carrier.ParentID);

            newDoc.ReleaseDate = carrier.ReleaseDate;
            newDoc.ExpireDate  = carrier.ExpireDate;

            // We iterate the properties in the carrier
            if (carrier.DocumentProperties != null)
            {
                foreach (documentProperty updatedproperty in carrier.DocumentProperties)
                {
                    umbraco.cms.businesslogic.property.Property property = newDoc.getProperty(updatedproperty.Key);
                    if (property == null)
                    {
                        throw new Exception("property " + updatedproperty.Key + " was not found");
                    }
                    property.Value = updatedproperty.PropertyValue;
                }
            }

            // We check the publishaction and do the appropiate
            handlePublishing(newDoc, carrier, user);

            // We return the ID of the document..65
            return(newDoc.Id);
        }
Exemple #8
0
 public DocProperty(umbraco.cms.businesslogic.property.Property property)
 {
     this._property = property;
 }
Exemple #9
0
        public static void SendMail(umbraco.cms.businesslogic.member.MemberGroup Group, umbraco.cms.businesslogic.property.Property Property, string fromName, string fromEmail, bool IsHtml)
        {
            // Create ArrayList with emails who've received the e-mail
            ArrayList sent = new ArrayList();

            // set timeout
            System.Web.HttpContext.Current.Server.ScriptTimeout = 43200;             // 12 hours
            // version
            string version = Property.VersionId.ToString();

            // Get document
            umbraco.cms.businesslogic.web.Document d = new umbraco.cms.businesslogic.web.Document(umbraco.cms.businesslogic.Content.GetContentFromVersion(Property.VersionId).Id);
            int id = d.Id;

            System.Web.HttpContext.Current.Items["pageID"] = id;

            // Format mail
            string subject = d.Text;
            string sender  = "\"" + fromName + "\" <" + fromEmail + ">";

            // Get template
            System.Text.StringBuilder    sb     = new System.Text.StringBuilder();
            System.IO.StringWriter       sw     = new StringWriter(sb);
            System.Web.UI.HtmlTextWriter writer = new System.Web.UI.HtmlTextWriter(sw);
            umbraco.template             t      = new template(d.Template);
            t.ParseWithControls(new umbraco.page(d.Id, d.Version)).RenderControl(writer);


            EmailMessage message = mailerHelper.CreateEmbeddedEmail(sb.ToString(), Cms.BusinessLogic.web.Document.GetContentFromVersion(Property.VersionId).Id);

            message.FromAddress = new EmailAddress(fromEmail, fromName);
            message.Subject     = subject;
            SmtpServer smtpServer = new SmtpServer(GlobalSettings.SmtpServer);

            // Bulk send mails
            int counter = 0;

            System.Text.StringBuilder sbStatus = new System.Text.StringBuilder();
            sbStatus.Append("The Newsletter '" + d.Text + "' was starting at " + DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString() + "\n");
            using (SqlDataReader dr = Microsoft.ApplicationBlocks.Data.SqlHelper.ExecuteReader(umbraco.GlobalSettings.DbDSN, CommandType.Text, "select text, email from cmsMember inner join umbracoNode node on node.id = cmsMember.nodeId inner join cmsMember2memberGroup on cmsmember.nodeId = cmsMember2MemberGroup.member where memberGroup = @memberGroupId", new SqlParameter("@memberGroupId", Group.Id)))
            {
                while (dr.Read())
                {
                    try
                    {
                        if (!sent.Contains(dr["email"].ToString()))
                        {
                            message.ToAddresses.Clear();
                            message.ToAddresses.Add(new EmailAddress(dr["email"].ToString(), dr["text"].ToString()));
                            message.Send(smtpServer);

                            // add to arraylist of receiptients
                            sent.Add(dr["email"].ToString());

                            // Append to status
                            sbStatus.Append("Sent to " + dr["text"].ToString() + " <" + dr["email"].ToString() + "> \n\r");
                        }
                        else
                        {
                            // Append to status
                            sbStatus.Append("E-mail has already been sent to email '" + dr["email"].ToString() + ". You have a duplicate member: " + dr["text"].ToString() + " <" + dr["email"].ToString() + "> \n\r");
                        }
                    }
                    catch (Exception ee)
                    {
                        sbStatus.Append("Error sending to " + dr["text"].ToString() + " <" + dr["email"].ToString() + ">: " +
                                        ee.ToString() + " \n");
                    }

                    // For progress bar
                    counter++;

                    if (counter % 5 == 0)
                    {
                        System.Web.HttpContext.Current.Application.Lock();
                        System.Web.HttpContext.Current.Application["ultraSimpleMailerProgress" + id.ToString() + "Done"] = counter;
                        System.Web.HttpContext.Current.Application.UnLock();
                    }
                }
            }

            sbStatus.Append("Finished at " + DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString() + "\n");

            // Send status mail
            library.SendMail(fromEmail, fromEmail, "Newsletter status", sbStatus.ToString(), false);
        }
        private void AddControlNew(Property p, TabPage tp, string cap)
        {
            IDataType dt = p.PropertyType.DataTypeDefinition.DataType;
            dt.DataEditor.Editor.ID = string.Format("prop_{0}", p.PropertyType.Alias);
            dt.Data.PropertyId = p.Id;

            //Add the DataType to an internal dictionary, which will be used to call the save method on the IDataEditor
            //and to retrieve the value from IData in editContent.aspx.cs, so that it can be set on the legacy Document class.
            DataTypes.Add(p.PropertyType.Alias, dt);

            // check for buttons
            IDataFieldWithButtons df1 = dt.DataEditor.Editor as IDataFieldWithButtons;
            if (df1 != null)
            {
                ((Control)df1).ID = p.PropertyType.Alias;


                if (df1.MenuIcons.Length > 0)
                    tp.Menu.InsertSplitter();


                // Add buttons
                int c = 0;
                bool atEditHtml = false;
                bool atSplitter = false;
                foreach (object o in df1.MenuIcons)
                {
                    try
                    {
                        MenuIconI m = (MenuIconI)o;
                        MenuIconI mi = tp.Menu.NewIcon();
                        mi.ImageURL = m.ImageURL;
                        mi.OnClickCommand = m.OnClickCommand;
                        mi.AltText = m.AltText;
                        mi.ID = tp.ID + "_" + m.ID;

                        if (m.ID == "html")
                            atEditHtml = true;
                        else
                            atEditHtml = false;

                        atSplitter = false;
                    }
                    catch
                    {
                        tp.Menu.InsertSplitter();
                        atSplitter = true;
                    }

                    // Testing custom styles in editor
                    if (atSplitter && atEditHtml && dt.DataEditor.TreatAsRichTextEditor)
                    {
                        DropDownList ddl = tp.Menu.NewDropDownList();

                        ddl.Style.Add("margin-bottom", "5px");
                        ddl.Items.Add(ui.Text("buttons", "styleChoose", null));
                        ddl.ID = tp.ID + "_editorStyle";
                        if (StyleSheet.GetAll().Length > 0)
                        {
                            foreach (StyleSheet s in StyleSheet.GetAll())
                            {
                                foreach (StylesheetProperty sp in s.Properties)
                                {
                                    ddl.Items.Add(new ListItem(sp.Text, sp.Alias));
                                }
                            }
                        }
                        ddl.Attributes.Add("onChange", "addStyle(this, '" + p.PropertyType.Alias + "');");
                        atEditHtml = false;
                    }
                    c++;
                }
            }

            // check for element additions
            IMenuElement menuElement = dt.DataEditor.Editor as IMenuElement;
            if (menuElement != null)
            {
                // add separator
                tp.Menu.InsertSplitter();

                // add the element
                tp.Menu.NewElement(menuElement.ElementName, menuElement.ElementIdPreFix + p.Id.ToString(),
                                   menuElement.ElementClass, menuElement.ExtraMenuWidth);
            }

            Pane pp = new Pane();
            Control holder = new Control();
            holder.Controls.Add(dt.DataEditor.Editor);
            if (p.PropertyType.DataTypeDefinition.DataType.DataEditor.ShowLabel)
            {
                string caption = p.PropertyType.Name;
                if (p.PropertyType.Description != null && p.PropertyType.Description != String.Empty)
                    switch (UmbracoSettings.PropertyContextHelpOption)
                    {
                        case "icon":
                            caption += " <img src=\"" + this.ResolveUrl(SystemDirectories.Umbraco) + "/images/help.png\" class=\"umbPropertyContextHelp\" alt=\"" + p.PropertyType.Description + "\" title=\"" + p.PropertyType.Description + "\" />";
                            break;
                        case "text":
                            caption += "<br /><small>" + umbraco.library.ReplaceLineBreaks(p.PropertyType.Description) + "</small>";
                            break;
                    }
                pp.addProperty(caption, holder);
            }
            else
                pp.addProperty(holder);

            // Validation
            if (p.PropertyType.Mandatory)
            {
                try
                {
                    var rq = new RequiredFieldValidator
                        {
                            ControlToValidate = dt.DataEditor.Editor.ID,
                            CssClass = "error"
                        };
                    rq.Style.Add(HtmlTextWriterStyle.Display, "block");
                    rq.Style.Add(HtmlTextWriterStyle.Padding, "2px");
                    var component = dt.DataEditor.Editor; // holder.FindControl(rq.ControlToValidate);
                    var attribute = (ValidationPropertyAttribute)TypeDescriptor.GetAttributes(component)[typeof(ValidationPropertyAttribute)];
                    PropertyDescriptor pd = null;
                    if (attribute != null)
                    {
                        pd = TypeDescriptor.GetProperties(component, null)[attribute.Name];
                    }
                    if (pd != null)
                    {
                        rq.EnableClientScript = false;
                        rq.Display = ValidatorDisplay.Dynamic;
                        string[] errorVars = { p.PropertyType.Name, cap };
                        rq.ErrorMessage = ui.Text("errorHandling", "errorMandatory", errorVars, null) + "<br/>";
                        holder.Controls.AddAt(0, rq);
                    }
                }
                catch (Exception valE)
                {
                    HttpContext.Current.Trace.Warn("contentControl",
                                                   "EditorControl (" + dt.DataTypeName + ") does not support validation",
                                                   valE);
                }
            }

            // RegExp Validation
            if (p.PropertyType.ValidationRegExp != "")
            {
                try
                {
                    var rv = new RegularExpressionValidator
                        {
                            ControlToValidate = dt.DataEditor.Editor.ID,
                            CssClass = "error"
                        };
                    rv.Style.Add(HtmlTextWriterStyle.Display, "block");
                    rv.Style.Add(HtmlTextWriterStyle.Padding, "2px");
                    var component = dt.DataEditor.Editor; // holder.FindControl(rq.ControlToValidate);
                    var attribute = (ValidationPropertyAttribute)TypeDescriptor.GetAttributes(component)[typeof(ValidationPropertyAttribute)];
                    PropertyDescriptor pd = null;
                    if (attribute != null)
                    {
                        pd = TypeDescriptor.GetProperties(component, null)[attribute.Name];
                    }
                    if (pd != null)
                    {
                        rv.ValidationExpression = p.PropertyType.ValidationRegExp;
                        rv.EnableClientScript = false;
                        rv.Display = ValidatorDisplay.Dynamic;
                        string[] errorVars = { p.PropertyType.Name, cap };
                        rv.ErrorMessage = ui.Text("errorHandling", "errorRegExp", errorVars, null) + "<br/>";
                        holder.Controls.AddAt(0, rv);
                    }
                }
                catch (Exception valE)
                {
                    HttpContext.Current.Trace.Warn("contentControl",
                                                   "EditorControl (" + dt.DataTypeName + ") does not support validation",
                                                   valE);
                }
            }

            // This is once again a nasty nasty hack to fix gui when rendering wysiwygeditor
            if (dt.DataEditor.TreatAsRichTextEditor)
            {
                tp.Controls.Add(dt.DataEditor.Editor);
            }
            else
            {
                Panel ph = new Panel();
                ph.Attributes.Add("style", "padding: 0; position: relative;"); // NH 4.7.1, latest styles added to support CP item: 30363
                ph.Controls.Add(pp);

                tp.Controls.Add(ph);
            }
        }
Exemple #11
0
        private void AddControlNew(Property p, TabPage tp, string cap)
        {
            IDataType dt = p.PropertyType.DataTypeDefinition.DataType;

            dt.DataEditor.Editor.ID = string.Format("prop_{0}", p.PropertyType.Alias);
            dt.Data.PropertyId      = p.Id;

            //Add the DataType to an internal dictionary, which will be used to call the save method on the IDataEditor
            //and to retrieve the value from IData in editContent.aspx.cs, so that it can be set on the legacy Document class.
            DataTypes.Add(p.PropertyType.Alias, dt);

            // check for buttons
            IDataFieldWithButtons df1 = dt.DataEditor.Editor as IDataFieldWithButtons;

            if (df1 != null)
            {
                ((Control)df1).ID = p.PropertyType.Alias;


                if (df1.MenuIcons.Length > 0)
                {
                    tp.Menu.InsertSplitter();
                }


                // Add buttons
                int  c          = 0;
                bool atEditHtml = false;
                bool atSplitter = false;
                foreach (object o in df1.MenuIcons)
                {
                    try
                    {
                        MenuIconI m  = (MenuIconI)o;
                        MenuIconI mi = tp.Menu.NewIcon();
                        mi.ImageURL       = m.ImageURL;
                        mi.OnClickCommand = m.OnClickCommand;
                        mi.AltText        = m.AltText;
                        mi.ID             = tp.ID + "_" + m.ID;

                        if (m.ID == "html")
                        {
                            atEditHtml = true;
                        }
                        else
                        {
                            atEditHtml = false;
                        }

                        atSplitter = false;
                    }
                    catch
                    {
                        tp.Menu.InsertSplitter();
                        atSplitter = true;
                    }

                    // Testing custom styles in editor
                    if (atSplitter && atEditHtml && dt.DataEditor.TreatAsRichTextEditor)
                    {
                        DropDownList ddl = tp.Menu.NewDropDownList();

                        ddl.Style.Add("margin-bottom", "5px");
                        ddl.Items.Add(ui.Text("buttons", "styleChoose", null));
                        ddl.ID = tp.ID + "_editorStyle";
                        if (StyleSheet.GetAll().Length > 0)
                        {
                            foreach (StyleSheet s in StyleSheet.GetAll())
                            {
                                foreach (StylesheetProperty sp in s.Properties)
                                {
                                    ddl.Items.Add(new ListItem(sp.Text, sp.Alias));
                                }
                            }
                        }
                        ddl.Attributes.Add("onChange", "addStyle(this, '" + p.PropertyType.Alias + "');");
                        atEditHtml = false;
                    }
                    c++;
                }
            }

            // check for element additions
            IMenuElement menuElement = dt.DataEditor.Editor as IMenuElement;

            if (menuElement != null)
            {
                // add separator
                tp.Menu.InsertSplitter();

                // add the element
                tp.Menu.NewElement(menuElement.ElementName, menuElement.ElementIdPreFix + p.Id.ToString(),
                                   menuElement.ElementClass, menuElement.ExtraMenuWidth);
            }

            Pane    pp     = new Pane();
            Control holder = new Control();

            holder.Controls.Add(dt.DataEditor.Editor);
            if (p.PropertyType.DataTypeDefinition.DataType.DataEditor.ShowLabel)
            {
                string caption = p.PropertyType.Name;
                if (p.PropertyType.Description != null && p.PropertyType.Description != String.Empty)
                {
                    switch (UmbracoSettings.PropertyContextHelpOption)
                    {
                    case "icon":
                        caption += " <img src=\"" + this.ResolveUrl(SystemDirectories.Umbraco) + "/images/help.png\" class=\"umbPropertyContextHelp\" alt=\"" + p.PropertyType.Description + "\" title=\"" + p.PropertyType.Description + "\" />";
                        break;

                    case "text":
                        caption += "<br /><small>" + umbraco.library.ReplaceLineBreaks(p.PropertyType.Description) + "</small>";
                        break;
                    }
                }
                pp.addProperty(caption, holder);
            }
            else
            {
                pp.addProperty(holder);
            }

            // Validation
            if (p.PropertyType.Mandatory)
            {
                try
                {
                    RequiredFieldValidator rq = new RequiredFieldValidator();
                    rq.ControlToValidate = dt.DataEditor.Editor.ID;
                    Control component = dt.DataEditor.Editor; // holder.FindControl(rq.ControlToValidate);
                    ValidationPropertyAttribute attribute =
                        (ValidationPropertyAttribute)
                        TypeDescriptor.GetAttributes(component)[typeof(ValidationPropertyAttribute)];
                    PropertyDescriptor pd = null;
                    if (attribute != null)
                    {
                        pd = TypeDescriptor.GetProperties(component, (Attribute[])null)[attribute.Name];
                    }
                    if (pd != null)
                    {
                        rq.EnableClientScript = false;
                        rq.Display            = ValidatorDisplay.Dynamic;
                        string[] errorVars = { p.PropertyType.Name, cap };
                        rq.ErrorMessage = ui.Text("errorHandling", "errorMandatory", errorVars, null) + "<br/>";
                        holder.Controls.AddAt(0, rq);
                    }
                }
                catch (Exception valE)
                {
                    HttpContext.Current.Trace.Warn("contentControl",
                                                   "EditorControl (" + dt.DataTypeName + ") does not support validation",
                                                   valE);
                }
            }

            // RegExp Validation
            if (p.PropertyType.ValidationRegExp != "")
            {
                try
                {
                    RegularExpressionValidator rv = new RegularExpressionValidator();
                    rv.ControlToValidate = dt.DataEditor.Editor.ID;

                    Control component = dt.DataEditor.Editor; // holder.FindControl(rq.ControlToValidate);
                    ValidationPropertyAttribute attribute =
                        (ValidationPropertyAttribute)
                        TypeDescriptor.GetAttributes(component)[typeof(ValidationPropertyAttribute)];
                    PropertyDescriptor pd = null;
                    if (attribute != null)
                    {
                        pd = TypeDescriptor.GetProperties(component, (Attribute[])null)[attribute.Name];
                    }
                    if (pd != null)
                    {
                        rv.ValidationExpression = p.PropertyType.ValidationRegExp;
                        rv.EnableClientScript   = false;
                        rv.Display = ValidatorDisplay.Dynamic;
                        string[] errorVars = { p.PropertyType.Name, cap };
                        rv.ErrorMessage = ui.Text("errorHandling", "errorRegExp", errorVars, null) + "<br/>";
                        holder.Controls.AddAt(0, rv);
                    }
                }
                catch (Exception valE)
                {
                    HttpContext.Current.Trace.Warn("contentControl",
                                                   "EditorControl (" + dt.DataTypeName + ") does not support validation",
                                                   valE);
                }
            }

            // This is once again a nasty nasty hack to fix gui when rendering wysiwygeditor
            if (dt.DataEditor.TreatAsRichTextEditor)
            {
                tp.Controls.Add(dt.DataEditor.Editor);
            }
            else
            {
                Panel ph = new Panel();
                ph.Attributes.Add("style", "padding: 0; position: relative;"); // NH 4.7.1, latest styles added to support CP item: 30363
                ph.Controls.Add(pp);

                tp.Controls.Add(ph);
            }
        }
Exemple #12
0
        internal static object GetPropertyValue(Member member, PropertyInfo propInfo, MemberTypePropertyAttribute propAttr)
        {
            object value = null;

            string propertyName;
            string propertyAlias;

            if (propAttr == null)
            {
                propAttr = Util.GetAttribute <MemberTypePropertyAttribute>(propInfo);
            }

            MemberTypeManager.ReadPropertyNameAndAlias(propInfo, propAttr, out propertyName, out propertyAlias);

            umbraco.cms.businesslogic.property.Property property = member.getProperty(propertyAlias);

            if (property == null)
            {
                value = null;
            }
            else if (propInfo.PropertyType.Equals(typeof(System.Boolean)))
            {
                if (property.Value == null || String.IsNullOrEmpty(Convert.ToString(property.Value)) ||
                    Convert.ToString(property.Value) == "0")
                {
                    value = false;
                }
                else
                {
                    value = true;
                }
            }
            else if (ContentHelper.PropertyConvertors.ContainsKey(propInfo.PropertyType))
            {
                // will be transformed later. TODO: move transformation here
                value = property.Value;
            }
            else if (propInfo.PropertyType.IsGenericType &&
                     propInfo.PropertyType.GetGenericTypeDefinition() == typeof(Nullable <>))
            {
                if (String.IsNullOrEmpty(Convert.ToString(property.Value)))
                {
                    value = null;
                }
                else
                {
                    value = Convert.ChangeType(property.Value, Nullable.GetUnderlyingType(propInfo.PropertyType));
                }

                // TODO: If data type is DateTime and is nullable and is less than 1.1.1000 than set it to NULL
            }
            else
            {
                value = Convert.ChangeType(property.Value, propInfo.PropertyType);
            }

            if (ContentHelper.PropertyConvertors.ContainsKey(propInfo.PropertyType))
            {
                value = ContentHelper.PropertyConvertors[propInfo.PropertyType].ConvertValueWhenRead(value);
            }

            return(value);
        }
Exemple #13
0
        /// <summary>
        /// Updates or adds the member. If member already exists, it updates it.
        /// If member doesn't exists, it creates new member.
        /// </summary>
        /// <param name="member">Member to update/add</param>
        /// <param name="user">User used for add or updating the content</param>
        private static void Save(MemberTypeBase member, User user)
        {
            if (user == null)
            {
                throw new Exception("User cannot be null!");
            }

            if (string.IsNullOrEmpty(member.LoginName))
            {
                throw new Exception("Member Login Name cannot be empty");
            }

            MemberType memberType = MemberTypeManager.GetMemberType(member.GetType());

            Member umember;

            if (member.Id == 0) // member is new so create Member
            {
                umember = Member.MakeNew(member.LoginName, member.Email, memberType, user);

                // reload
                umember          = Member.GetMemberFromLoginName(member.LoginName);
                umember.Password = member.Password;
                member.Id        = umember.Id;
            }
            else // member already exists, so load it
            {
                umember = new Member(member.Id);
            }

            umember.Email     = member.Email;
            umember.LoginName = member.LoginName;

            foreach (PropertyInfo propInfo in member.GetType().GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance))
            {
                DocumentTypePropertyAttribute propAttr = Util.GetAttribute <DocumentTypePropertyAttribute>(propInfo);
                if (propAttr == null)
                {
                    continue; // skip this property - not part of a Document Type
                }

                string propertyName;
                string propertyAlias;
                MemberTypeManager.ReadPropertyNameAndAlias(propInfo, propAttr, out propertyName, out propertyAlias);

                umbraco.cms.businesslogic.property.Property property = umember.getProperty(propertyAlias);
                if (property == null)
                {
                    throw new Exception(string.Format("Property '{0}' not found in this node: {1}. Content type: {2}.",
                                                      propertyAlias, member.Id, memberType.Alias));
                }

                if (ContentHelper.PropertyConvertors.ContainsKey(propInfo.PropertyType))
                {
                    property.Value = ContentHelper.PropertyConvertors[propInfo.PropertyType].ConvertValueWhenWrite(propInfo.GetValue(member, null));
                }
                else
                {
                    property.Value = propInfo.GetValue(member, null);
                }
            }

            umember.Save();
        }
        /// <summary>
        /// Raises the <see cref="E:System.Web.UI.Control.Init"/> event.
        /// </summary>
        /// <param name="e">An <see cref="T:System.EventArgs"/> object that contains the event data.</param>
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            this.minSelectionCustomValidator.ServerValidate += new ServerValidateEventHandler(this.MinSelectionCustomValidator_ServerValidate);
            this.maxSelectionCustomValidator.ServerValidate += new ServerValidateEventHandler(this.MaxSelectionCustomValidator_ServerValidate);

            var property = new CmsProperty(((umbraco.cms.businesslogic.datatype.DefaultData)this.data).PropertyId);
            var documentType = UmbracoContext.Current.Application.Services.ContentTypeService.GetContentType(property.PropertyType.ContentTypeId);
            var propertyGroup = documentType.PropertyGroups.FirstOrDefault(x => x.Id == property.PropertyType.PropertyTypeGroup);

            if (propertyGroup != null)
            {
                this.minSelectionCustomValidator.ErrorMessage = string.Concat("The ", property.PropertyType.Alias, " field in the ", propertyGroup.Name, " tab requires a minimum of ", this.options.MinSelection.ToString(), " selections<br/>");
                this.maxSelectionCustomValidator.ErrorMessage = string.Concat("The ", property.PropertyType.Alias, " field in the ", propertyGroup.Name, " tab has exceeded the maximum number of selections<br/>");
            }
        }