예제 #1
0
    /// <summary>
    /// Get a List of PreValues by Id
    /// </summary>
    /// <param name="id">Id of the PreValue</param>
    /// <returns>List of PreValues</returns>
    public static IEnumerable <PreValue> DataTypeValue(int id)
    {
        DataTypeDefinition dataTypeDefinition = DataTypeDefinition.GetDataTypeDefinition(id);
        SortedList         data = PreValues.GetPreValues(dataTypeDefinition.Id);

        return(data.Values.Cast <PreValue>());
    }
예제 #2
0
        /// <summary>
        ///   Gets the parameters.
        /// </summary>
        /// <returns></returns>
        private static TextImageParameters GetParameters(string text, DataTypeDefinition typeDefinition)
        {
            TextImageParameters parameters;
            try
            {
                var datatype = (TextImageDataType)typeDefinition.DataType;
                var prevalueEditor = (TextImagePrevalueEditor)datatype.PrevalueEditor;

                parameters = new TextImageParameters(text,
                                                     prevalueEditor.OutputFormat,
                                                     prevalueEditor.CustomFontPath,
                                                     prevalueEditor.FontName,
                                                     prevalueEditor.FontSize,
                                                     prevalueEditor.FontStyles,
                                                     prevalueEditor.ForegroundColor,
                                                     prevalueEditor.BackgroundColor,
                                                     prevalueEditor.ShadowColor,
                                                     prevalueEditor.HorizontalAlignment,
                                                     prevalueEditor.VerticalAlignment,
                                                     prevalueEditor.ImageHeight,
                                                     prevalueEditor.ImageWidth,
                                                     prevalueEditor.BackgroundMedia);
            }
            catch (Exception ex)
            {
                parameters = new TextImageParameters(ex.Message, OutputFormat.Jpg, string.Empty, "ARIAL", 12,
                                                     new[] { FontStyle.Regular }, "000", "FFF", "transparent",
                                                     HorizontalAlignment.Left, VerticalAlignment.Top, -1, -1, null);
            }

            return parameters;
        }
예제 #3
0
    /// <summary>
    /// Get a List of PreValues by Id
    /// </summary>
    /// <param name="parameter">UmbracoType</param>
    /// <returns>List of PreValues</returns>
    public static IEnumerable <PreValue> DataTypeValue(UmbracoType parameter)
    {
        int id = Convert.ToInt32(GetParameterValue(parameter));
        DataTypeDefinition dataTypeDefinition = DataTypeDefinition.GetDataTypeDefinition(id);
        SortedList         data = PreValues.GetPreValues(dataTypeDefinition.Id);

        return(data.Values.Cast <PreValue>());
    }
예제 #4
0
        private DataTypeItem BuildDataTypeItem(DataTypeDefinition dataTypeDefinition)
        {
            var dataTypeItem = new DataTypeItem();
            dataTypeItem.Id = dataTypeDefinition.DataType.DataTypeDefinitionId;
            dataTypeItem.ControlTypeName = dataTypeDefinition.DataType.GetType().FullName;

            var node = new CMSNode(dataTypeItem.Id);
            dataTypeItem.DataTypeName = node.Text;

            dataTypeItem.PreValueItems = this.BuildPreValues(dataTypeDefinition);
            dataTypeItem.Type = this.DetermineType(dataTypeItem);
            dataTypeItem.ModelType = DetermineModelType(dataTypeItem);
            return dataTypeItem;
        }
예제 #5
0
        public static DataTypeDefinition Import(XmlNode xmlData)
        {
            string _name = xmlData.Attributes["Name"].Value;
            string _id   = xmlData.Attributes["Id"].Value;
            string _def  = xmlData.Attributes["Definition"].Value;


            //Make sure that the dtd is not already present
            if (!CMSNode.IsNode(new Guid(_def))
                )
            {
                BusinessLogic.User u = umbraco.BusinessLogic.User.GetCurrent();

                if (u == null)
                {
                    u = BusinessLogic.User.GetUser(0);
                }

                cms.businesslogic.datatype.controls.Factory f = new umbraco.cms.businesslogic.datatype.controls.Factory();


                DataTypeDefinition dtd = MakeNew(u, _name, new Guid(_def));
                var dataType           = f.DataType(new Guid(_id));
                if (dataType == null)
                {
                    throw new NullReferenceException("Could not resolve a data type with id " + _id);
                }

                dtd.DataType = dataType;
                dtd.Save();

                //add prevalues
                foreach (XmlNode xmlPv in xmlData.SelectNodes("PreValues/PreValue"))
                {
                    XmlAttribute val = xmlPv.Attributes["Value"];

                    if (val != null)
                    {
                        PreValue p = new PreValue(0, 0, val.Value);
                        p.DataTypeId = dtd.Id;
                        p.Save();
                    }
                }

                return(dtd);
            }

            return(null);
        }
예제 #6
0
        public static DataTypeDefinition Import(XmlNode xmlData)
        {
            string _name = xmlData.Attributes["Name"].Value;
            string _id   = xmlData.Attributes["Id"].Value;
            string _def  = xmlData.Attributes["Definition"].Value;


            //Make sure that the dtd is not already present
            if (!CMSNode.IsNode(new Guid(_def))
                )
            {
                BasePages.UmbracoEnsuredPage uep = new umbraco.BasePages.UmbracoEnsuredPage();
                BusinessLogic.User           u   = uep.getUser();

                if (u == null)
                {
                    u = BusinessLogic.User.GetUser(0);
                }

                cms.businesslogic.datatype.controls.Factory f = new umbraco.cms.businesslogic.datatype.controls.Factory();


                DataTypeDefinition dtd = MakeNew(u, _name, new Guid(_def));
                dtd.DataType = f.DataType(new Guid(_id));
                dtd.Save();

                //add prevalues
                foreach (XmlNode xmlPv in xmlData.SelectNodes("PreValues/PreValue"))
                {
                    XmlAttribute val = xmlPv.Attributes["Value"];

                    if (val != null && !string.IsNullOrEmpty(val.Value))
                    {
                        PreValue p = new PreValue(0, 0, val.Value);
                        p.DataTypeId = dtd.Id;
                        p.Save();
                    }
                }

                return(dtd);
            }

            return(null);
        }
        /// <summary>
        /// Creates a new datatypedefinition given its name and the user which creates it.
        /// </summary>
        /// <param name="u">The user who creates the datatypedefinition</param>
        /// <param name="Text">The name of the DataTypeDefinition</param>
        /// <param name="UniqueId">Overrides the CMSnodes uniqueID</param>
        /// <returns></returns>
        public static DataTypeDefinition MakeNew(BusinessLogic.User u, string Text, Guid UniqueId)
        {
            int newId = CMSNode.MakeNew(-1, _objectType, u.Id, 1, Text, UniqueId).Id;

            cms.businesslogic.datatype.controls.Factory f = new cms.businesslogic.datatype.controls.Factory();

            // initial control id changed to empty to ensure that it'll always work no matter if 3rd party configurators fail
            // ref: http://umbraco.codeplex.com/workitem/29788
            Guid FirstcontrolId = Guid.Empty;

            SqlHelper.ExecuteNonQuery("Insert into cmsDataType (nodeId, controlId, dbType) values (" + newId.ToString() + ",@controlId,'Ntext')",
                                      SqlHelper.CreateParameter("@controlId", FirstcontrolId));

            DataTypeDefinition dtd = new DataTypeDefinition(newId);

            dtd.OnNew(EventArgs.Empty);

            return(dtd);
        }
 public static void SaveToDisk(DataTypeDefinition item)
 {
     if (item != null)
     {
         try
         {
             XmlDocument xmlDoc = helpers.XmlDoc.CreateDoc();
             xmlDoc.AppendChild(DataTypeToXml(item, xmlDoc));
             helpers.XmlDoc.SaveXmlDoc(item.GetType().ToString(), item.Text, xmlDoc);
         }
         catch (Exception ex)
         {
             Log.Add(LogTypes.Error, 0, string.Format("Saving DataType Failed {0} {1}", item.Text, ex.ToString() ));
         }
     }
     else
     {
         Log.Add(LogTypes.Error, 0, "Null DataType Save attempt - aborted");
     }
 }
예제 #9
0
 public static void SaveToDisk(DataTypeDefinition item)
 {
     if (item != null)
     {
         try
         {
             XmlDocument xmlDoc = helpers.XmlDoc.CreateDoc();
             xmlDoc.AppendChild(DataTypeToXml(item, xmlDoc));
             helpers.XmlDoc.SaveXmlDoc(item.GetType().ToString(), item.Text, xmlDoc);
         }
         catch (Exception ex)
         {
             helpers.uSyncLog.ErrorLog(ex, "Saving DataType Failed {0}", item.Text );
         }
     }
     else
     {
         helpers.uSyncLog.DebugLog("Null DataType Save attempt - aborted");
     }
 }
예제 #10
0
        /// <summary>
        /// Returns an XPathNodeIterator of the specified data-type by Id.
        /// </summary>
        /// <param name="dataTypeId">The data-type Id.</param>
        /// <returns>A node-set of the specified data-type</returns>
        public static XPathNodeIterator GetDataTypeById(int dataTypeId)
        {
            try
            {
                var xd = new XmlDocument();
                var dataType = new DataTypeDefinition(dataTypeId);

                if (dataType != null)
                {
                    var dataTypeNode = dataType.ToXml(xd);

                    xd.AppendChild(dataTypeNode);
                }

                return xd.CreateNavigator().Select("/DataType");

            }
            catch (Exception ex)
            {
                return ex.ToXPathNodeIterator();
            }
        }
        /// <summary>
        /// Retrieves a list of all datatypedefinitions
        /// </summary>
        /// <returns>A list of all datatypedefinitions</returns>
        public static DataTypeDefinition[] GetAll()
        {
            SortedList retvalSort = new SortedList();

            Guid[] tmp = CMSNode.getAllUniquesFromObjectType(_objectType);
            DataTypeDefinition[] retval = new DataTypeDefinition[tmp.Length];
            for (int i = 0; i < tmp.Length; i++)
            {
                DataTypeDefinition dt = DataTypeDefinition.GetDataTypeDefinition(tmp[i]);
                retvalSort.Add(dt.Text + "|||" + Guid.NewGuid().ToString(), dt);
            }

            IDictionaryEnumerator ide = retvalSort.GetEnumerator();
            int counter = 0;

            while (ide.MoveNext())
            {
                retval[counter] = (DataTypeDefinition)ide.Value;
                counter++;
            }
            return(retval);
        }
예제 #12
0
        private DataTypeItem BuildDataTypeItem(DataTypeDefinition dataTypeDefinition)
        {
            try
            {
                var dataTypeItem = new DataTypeItem();
                dataTypeItem.Id = dataTypeDefinition.DataType.DataTypeDefinitionId;
                dataTypeItem.ControlTypeName = dataTypeDefinition.DataType.GetType().FullName;

                var node = new CMSNode(dataTypeItem.Id);
                dataTypeItem.DataTypeName = node.Text;

                dataTypeItem.PreValueItems = this.BuildPreValues(dataTypeDefinition);
                dataTypeItem.Type = this.DetermineType(dataTypeItem);
                dataTypeItem.ModelType = DetermineModelType(dataTypeItem);
                return dataTypeItem;

            }
            catch (Exception ex)
            {
                throw new DataTypeException(string.Format("Data type {0} '{1}' could not be loaded.", dataTypeDefinition.Id.ToString(), dataTypeDefinition.Text));
            }
        }
        /// <summary>
        /// Retrieve a list of datatypedefinitions which share the same IDataType datatype
        /// </summary>
        /// <param name="DataTypeId">The unique id of the IDataType</param>
        /// <returns>A list of datatypedefinitions which are based on the IDataType specified</returns>
        public static DataTypeDefinition GetByDataTypeId(Guid DataTypeId)
        {
            int dfId = 0;

            foreach (DataTypeDefinition df in DataTypeDefinition.GetAll())
            {
                if (df.DataType.Id == DataTypeId)
                {
                    dfId = df.Id;
                    break;
                }
            }

            if (dfId == 0)
            {
                return(null);
            }
            else
            {
                return(new DataTypeDefinition(dfId));
            }
        }
        /// <summary>
        /// Creates a new datatypedefinition given its name and the user which creates it.
        /// </summary>
        /// <param name="u">The user who creates the datatypedefinition</param>
        /// <param name="Text">The name of the DataTypeDefinition</param>
        /// <param name="UniqueId">Overrides the CMSnodes uniqueID</param>
        /// <returns></returns>
        public static DataTypeDefinition MakeNew(BusinessLogic.User u, string Text, Guid UniqueId)
        {
            var found = ApplicationContext.Current.Services.DataTypeService.GetDataTypeDefinitionByName(Text);

            if (found != null)
            {
                throw new DuplicateNameException("A data type with the name " + Text + " already exists");
            }

            var created = new Umbraco.Core.Models.DataTypeDefinition("")
            {
                Name = Text,
                Key  = UniqueId
            };

            ApplicationContext.Current.Services.DataTypeService.Save(created);

            var dtd = new DataTypeDefinition(created);

            dtd.OnNew(EventArgs.Empty);

            return(dtd);
        }
예제 #15
0
        /// <summary>
        /// Retrieve a list of datatypedefinitions which share the same IDataType datatype
        /// </summary>
        /// <param name="DataTypeId">The unique id of the IDataType</param>
        /// <returns>A list of datatypedefinitions which are based on the IDataType specified</returns>
        public static DataTypeDefinition GetByDataTypeId(Guid DataTypeId)
        {
            int dfId = 0;

            // When creating a datatype and not saving it, it will be null, so we need this check
            foreach (DataTypeDefinition df in DataTypeDefinition.GetAll().Where(x => x.DataType != null))
            {
                if (df.DataType.Id == DataTypeId)
                {
                    dfId = df.Id;
                    break;
                }
            }

            if (dfId == 0)
            {
                return(null);
            }
            else
            {
                return(new DataTypeDefinition(dfId));
            }
        }
        private void UpdatePrevalues(XmlElement fieldTypeElement, DataTypeDefinition df, StringBuilder log)
        {
            var prevalueHashA = new StringBuilder();
            foreach (var value in _context.cmsDataTypePreValues.Where(v => v.datatypeNodeId == df.Id).OrderBy(v => v.sortorder))
            {
                prevalueHashA.Append(value.alias);
                prevalueHashA.Append("|");
                prevalueHashA.Append(value.value);
                prevalueHashA.Append("|");
                prevalueHashA.Append(value.sortorder.ToString());
            }
            var prevalueHashB = new StringBuilder();
            foreach (XmlElement prevalue in fieldTypeElement.SelectNodes("preValue"))
            {
                prevalueHashB.Append(prevalue.HasAttribute("alias") ? prevalue.GetAttribute("alias") : string.Empty);
                prevalueHashB.Append("|");
                prevalueHashB.Append(prevalue.GetAttribute("value"));
                prevalueHashB.Append("|");
                prevalueHashB.Append(prevalue.GetAttribute("sortOrder"));
            }

            if (prevalueHashA.ToString() != prevalueHashB.ToString())
            {
                PreValues.DeleteByDataTypeDefinition(df.Id);
                foreach (XmlElement prevalue in fieldTypeElement.SelectNodes("preValue"))
                {
                    var value = new cmsDataTypePreValue();
                    value.datatypeNodeId = df.Id;
                    value.alias = prevalue.HasAttribute("alias") ? prevalue.GetAttribute("alias") : string.Empty;
                    value.datatypeNodeId = df.Id;
                    value.sortorder = Convert.ToInt32(prevalue.GetAttribute("sortOrder"));
                    value.value = prevalue.GetAttribute("value");
                    _context.cmsDataTypePreValues.InsertOnSubmit(value);
                    log.AppendLine("Updated prevalue: " + value.alias);
                }
            }
        }
        private bool CompareProperties(Type dataType, DataTypeDefinition existingDataType)
        {
            var dataTypeAttr = DataTypeManager.GetDataTypeAttribute(dataType);
            if (existingDataType.Text != dataTypeAttr.Name)
            {
                return false;
            }
            if (existingDataType.DataType == null || existingDataType.DataType.Id != new Guid(dataTypeAttr.RenderControlGuid))
            {
                return false;
            }

            var instance = Activator.CreateInstance(dataType, null) as DataTypeBase;
            var prevalues = instance.Prevalues;

            var settingsStorage = new DataEditorSettingsStorage();
            var existingSettings = settingsStorage.GetSettings(existingDataType.Id);

            if (existingSettings.Count != prevalues.Count())
            {
                return false;
            }

            int counter = 0;
            foreach (var setting in existingSettings)
            {
                if (setting.Key != prevalues[counter].Alias || setting.Value != prevalues[counter].Value)
                {
                    return false;
                }

                counter++;
            }

            return true;
        }
예제 #18
0
        private List<PreValueItem> BuildPreValues(DataTypeDefinition dataTypeDefinition)
        {
            try
            {
                bool allEmpty = true;
                var prevalues = PreValues.GetPreValues(dataTypeDefinition.DataType.DataTypeDefinitionId);
                if (prevalues != null && prevalues.Count > 0)
                {
                    var preValueItems = new List<PreValueItem>();
                    foreach (DictionaryEntry item in prevalues)
                    {
                        var preValue = item.Value as PreValue;
                        if (preValue != null)
                        {
                            var preValueItem = new PreValueItem()
                                {
                                    Id = preValue.Id,
                                    SortOrder = preValue.SortOrder,
                                    Value = preValue.Value
                                };
                            preValueItems.Add(preValueItem);
                            if (!string.IsNullOrEmpty(preValueItem.Value)) allEmpty = false;
                        }

                    }
                    if (allEmpty) return null;

                    return preValueItems;
                }
                return null;
            }
            catch (Exception ex)
            {
                throw new DataTypeException(string.Format("Data type {0} '{1}' prevalues could not be loaded.", dataTypeDefinition.Id.ToString(), dataTypeDefinition.Text), ex);
            }
        }
예제 #19
0
        /// <summary>
        /// Adding a PropertyType to the ContentType, will add a new datafield/Property on all Documents of this Type.
        /// </summary>
        /// <param name="dt">The DataTypeDefinition of the PropertyType</param>
        /// <param name="Alias">The Alias of the PropertyType</param>
        /// <param name="Name">The userfriendly name</param>
        public PropertyType AddPropertyType(DataTypeDefinition dt, string Alias, string Name)
        {
            PropertyType pt = PropertyType.MakeNew(dt, this, Name, Alias);

            // Optimized call
            populatePropertyData(pt, this.Id);

            // Inherited content types (document types only)
            populateMasterContentTypes(pt, this.Id);

            //			foreach (Content c in Content.getContentOfContentType(this)) 
            //				c.addProperty(pt,c.Version);

            // Remove from cache
            FlushFromCache(Id);

            return pt;
        }
예제 #20
0
        private List<PreValueItem> BuildPreValues(DataTypeDefinition dataTypeDefinition)
        {
            bool allEmpty = true;
            var prevalues = PreValues.GetPreValues(dataTypeDefinition.DataType.DataTypeDefinitionId);
            if (prevalues != null && prevalues.Count > 0)
            {
                var preValueItems = new List<PreValueItem>();
                foreach (DictionaryEntry item in prevalues)
                {
                    var preValue = item.Value as PreValue;
                    if (preValue != null)
                    {
                        var preValueItem = new PreValueItem()
                            {
                                Id = preValue.Id,
                                SortOrder = preValue.SortOrder,
                                Value = preValue.Value
                            };
                        preValueItems.Add(preValueItem);
                        if (!string.IsNullOrEmpty(preValueItem.Value)) allEmpty = false;
                    }

                }
                if (allEmpty) return null;

                return preValueItems;
            }
            return null;
        }
예제 #21
0
        public static PropertyType MakeNew(DataTypeDefinition dt, ContentType ct, string name, string alias)
        {
            //make sure that the alias starts with a letter
            if (string.IsNullOrEmpty(alias))
                throw new ArgumentNullException("alias");
            if (string.IsNullOrEmpty(name))
                throw new ArgumentNullException("name");
            if (!Char.IsLetter(alias[0]))
                throw new ArgumentException("alias must start with a letter", "alias");

            PropertyType pt;
            try
            {
                // The method is synchronized, but we'll still look it up with an additional parameter (alias)
                SqlHelper.ExecuteNonQuery(
                    "INSERT INTO cmsPropertyType (DataTypeId, ContentTypeId, alias, name) VALUES (@DataTypeId, @ContentTypeId, @alias, @name)",
                    SqlHelper.CreateParameter("@DataTypeId", dt.Id),
                    SqlHelper.CreateParameter("@ContentTypeId", ct.Id),
                    SqlHelper.CreateParameter("@alias", alias),
                    SqlHelper.CreateParameter("@name", name));
                pt =
                    new PropertyType(
                        SqlHelper.ExecuteScalar<int>("SELECT MAX(id) FROM cmsPropertyType WHERE alias=@alias",
                                                     SqlHelper.CreateParameter("@alias", alias)));
            }
            finally
            {
                // Clear cached items
                Cache.ClearCacheByKeySearch(UmbracoPropertyTypeCacheKey);
            }

            return pt;
        }
예제 #22
0
 public static DataTypeDefinition GetDataTypeDefinition(Guid id)
 {
     if (System.Web.HttpRuntime.Cache[string.Format("UmbracoDataTypeDefinition{0}", id.ToString())] == null)
     {
         DataTypeDefinition dt = new DataTypeDefinition(id);
         System.Web.HttpRuntime.Cache.Insert(string.Format("UmbracoDataTypeDefinition{0}", id.ToString()), dt);
     }
     return (DataTypeDefinition)System.Web.HttpRuntime.Cache[string.Format("UmbracoDataTypeDefinition{0}", id.ToString())];
 }
예제 #23
0
 private static List<PreValue> GetPreValues(DataTypeDefinition dataType)
 {
     return PreValues.GetPreValues(dataType.Id).Values.OfType<PreValue>().OrderBy(p => p.SortOrder).ThenBy(p => p.Id).ToList();
 }
예제 #24
0
        /// <summary>
        /// DataType ToXML - taken from the core (must learn to patch sometime)
        /// 
        /// fixing basic problem, of prevalues not coming out sorted by id (and sort-order)
        /// with thanks to Kenn Jacobsen for info on this. 
        /// </summary>
        /// <param name="dataType">the datatype to export</param>
        /// <param name="xd">the xmldocument</param>
        /// <returns>the xmlelement representation of the type</returns>
        public static XmlElement DataTypeToXml(DataTypeDefinition dataType, XmlDocument xd)
        {
            XmlElement dt = xd.CreateElement("DataType");
            dt.Attributes.Append(xmlHelper.addAttribute(xd, "Name", dataType.Text));
            dt.Attributes.Append(xmlHelper.addAttribute(xd, "Id", dataType.DataType.Id.ToString()));
            dt.Attributes.Append(xmlHelper.addAttribute(xd, "Definition", dataType.UniqueId.ToString()));

            // templates
            XmlElement prevalues = xd.CreateElement("PreValues");
            foreach (PreValue item in GetPreValues(dataType))
            {
                
                XmlElement prevalue = xd.CreateElement("PreValue");
                prevalue.Attributes.Append(xmlHelper.addAttribute(xd, "Id", item.Id.ToString()));
                prevalue.Attributes.Append(xmlHelper.addAttribute(xd, "Value", item.Value));

                prevalues.AppendChild(prevalue);
            }

            dt.AppendChild(prevalues);

            return dt;
        }
예제 #25
0
        /// <summary>
        /// Creates a new datatypedefinition given its name and the user which creates it.
        /// </summary>
        /// <param name="u">The user who creates the datatypedefinition</param>
        /// <param name="Text">The name of the DataTypeDefinition</param>
        /// <param name="UniqueId">Overrides the CMSnodes uniqueID</param>
        /// <returns></returns>
        public static DataTypeDefinition MakeNew(BusinessLogic.User u, string Text, Guid UniqueId)
        {

            var newId = MakeNew(-1, ObjectType, u.Id, 1, Text, UniqueId).Id;

            //insert empty prop ed alias
            SqlHelper.ExecuteNonQuery("Insert into cmsDataType (nodeId, propertyEditorAlias, dbType) values (" + newId + ",'','Ntext')");

            var dtd = new DataTypeDefinition(newId);
            dtd.OnNew(EventArgs.Empty);

            return dtd;
        }
		protected void Page_Load(object sender, EventArgs e)
		{
			var umbracoVersion = IO.Container.Resolve<IUmbracoVersion>();

			bool storePresent;
			IO.Container.Resolve<ICMSInstaller>().InstallStarterkit("demo", out storePresent);

			var admin = User.GetUser(0);
			var configuration = WebConfigurationManager.OpenWebConfiguration("~");

			//  change UmbracoMembershipProvider to this:
			// <add name="UmbracoMembershipProvider" minRequiredPasswordLength="4" minRequiredNonalphanumericCharacters="0" type="umbraco.providers.members.UmbracoMembershipProvider" enablePasswordRetrieval="false" enablePasswordReset="false" requiresQuestionAndAnswer="false" defaultMemberTypeAlias="Customers" passwordFormat="Hashed" />

			var systemWeb = configuration.SectionGroups["system.web"];

			var membershipSection = (MembershipSection)systemWeb.Sections["membership"];
			
			var umbracoMembershipProvider = membershipSection.Providers["UmbracoMembershipProvider"];

			if (umbracoMembershipProvider.Parameters["defaultMemberTypeAlias"] != "Customers")
			{
				if (umbracoMembershipProvider.Parameters.Get("minRequiredPasswordLength") == null)
				{
					umbracoMembershipProvider.Parameters.Add("minRequiredPasswordLength", "4");
				}

				if (umbracoMembershipProvider.Parameters.Get("minRequiredNonalphanumericCharacters") == null)
				{
					umbracoMembershipProvider.Parameters.Add("minRequiredNonalphanumericCharacters", "0");
				}

				umbracoMembershipProvider.Parameters.Set("defaultMemberTypeAlias", "Customers");
			}
			
			
			// add profile to system.web, or add new fields if they are not there yet
			var profileSection = (ProfileSection)systemWeb.Sections["profile"];

			if (profileSection.DefaultProvider != "UmbracoMemberProfileProvider")
			{

				profileSection.DefaultProvider = "UmbracoMemberProfileProvider";
				profileSection.Enabled = true;
				profileSection.AutomaticSaveEnabled = false;

				//	<profile defaultProvider="UmbracoMemberProfileProvider" enabled="true" automaticSaveEnabled="false">
				//	<providers>
				//		<clear />
				//		<add name="UmbracoMemberProfileProvider" type="umbraco.providers.members.UmbracoProfileProvider, umbraco.providers" />
				//	</providers>
				//	<properties>
				//		<clear />
				//		<add name="customerFirstName" allowAnonymous="false" provider="UmbracoMemberProfileProvider" type="System.String" />
				//		<add name="customerLastName" allowAnonymous="false" provider="UmbracoMemberProfileProvider" type="System.String" />
				//		<add name="customerStreet" allowAnonymous="false" provider="UmbracoMemberProfileProvider" type="System.String" />
				//		<add name="customerStreetNumber" allowAnonymous="false" provider="UmbracoMemberProfileProvider" type="System.String" />
				//		<add name="customerZipCode" allowAnonymous="false" provider="UmbracoMemberProfileProvider" type="System.String" />
				//		<add name="customerCity" allowAnonymous="false" provider="UmbracoMemberProfileProvider" type="System.String" />
				//		<add name="customerCountry" allowAnonymous="false" provider="UmbracoMemberProfileProvider" type="System.String" />
				//	</properties>
				//</profile>
				
				var providerSettings = new ProviderSettings
									   {
										   Name = "UmbracoMemberProfileProvider",
										   Type =
											   "umbraco.providers.members.UmbracoProfileProvider, umbraco.providers"
									   };
				
				profileSection.Providers.Add(providerSettings);
				profileSection.PropertySettings.Clear();
				var customerFirstName = new ProfilePropertySettings("customerFirstName", false, SerializationMode.String,
					"UmbracoMemberProfileProvider", string.Empty, "System.String", false, string.Empty);
				profileSection.PropertySettings.Add(customerFirstName);
				var customerLastName = new ProfilePropertySettings("customerLastName", false, SerializationMode.String,
					"UmbracoMemberProfileProvider", string.Empty, "System.String", false, string.Empty);
				profileSection.PropertySettings.Add(customerLastName);
				var customerStreet = new ProfilePropertySettings("customerStreet", false, SerializationMode.String,
					"UmbracoMemberProfileProvider", string.Empty, "System.String", false, string.Empty);
				profileSection.PropertySettings.Add(customerStreet);
				var customerStreetNumber = new ProfilePropertySettings("customerStreetNumber", false, SerializationMode.String,
					"UmbracoMemberProfileProvider", string.Empty, "System.String", false, string.Empty);
				profileSection.PropertySettings.Add(customerStreetNumber);
				var customerZipCode = new ProfilePropertySettings("customerZipCode", false, SerializationMode.String,
					"UmbracoMemberProfileProvider", string.Empty, "System.String", false, string.Empty);
				profileSection.PropertySettings.Add(customerZipCode);
				var customerCity = new ProfilePropertySettings("customerCity", false, SerializationMode.String,
					"UmbracoMemberProfileProvider", string.Empty, "System.String", false, string.Empty);
				profileSection.PropertySettings.Add(customerCity);
				var customerCountry = new ProfilePropertySettings("customerCountry", false, SerializationMode.String,
					"UmbracoMemberProfileProvider", string.Empty, "System.String", false, string.Empty);
				profileSection.PropertySettings.Add(customerCountry);
			}

			configuration.Save();

			// generate new membertype based on properties above
			// add them to both customer profile and order

			var customersType = MemberType.GetByAlias("Customers");

			if (customersType == null)
			{
				try
				{
					customersType = MemberType.MakeNew(admin, "Customers");
				}
				catch
				{
					Log.Instance.LogError("Umbraco Failed to create 'Customers' MemberType");
					// Umbraco bug with SQLCE + MemberType.MakeNew requires this catch, membertype will not be created...
				}
			}

			var uwbsOrdersType = DocumentType.GetByAlias(Order.NodeAlias);

			if (customersType != null && uwbsOrdersType != null)
			{
				var customerTab = uwbsOrdersType.getVirtualTabs.FirstOrDefault(x => x.Caption.ToLowerInvariant() == "customer");
				var customerTabId = customerTab == null ? uwbsOrdersType.AddVirtualTab("Customer") : customerTab.Id;

				var shippingTab = uwbsOrdersType.getVirtualTabs.FirstOrDefault(x => x.Caption.ToLowerInvariant() == "shipping");
				var shippingTabId = shippingTab == null ? uwbsOrdersType.AddVirtualTab("Shipping") : shippingTab.Id;

				// todo V7 version!
				var stringDataType = umbracoVersion.GetDataTypeDefinition("Umbraco.Textbox", new Guid("0cc0eba1-9960-42c9-bf9b-60e150b429ae"));
				var stringDataTypeDef = new DataTypeDefinition(stringDataType.Id);
				var textboxMultipleDataType = umbracoVersion.GetDataTypeDefinition("Umbraco.TextboxMultiple", new Guid("c6bac0dd-4ab9-45b1-8e30-e4b619ee5da3"));
				var textboxMultipleDataTypeDef = new DataTypeDefinition(textboxMultipleDataType.Id);

				foreach (var propertyKey in profileSection.PropertySettings.AllKeys)
				{
					customersType.AddPropertyType(stringDataTypeDef, propertyKey, "#" + UppercaseFirstCharacter(propertyKey));

					if (uwbsOrdersType.PropertyTypes.All(x => x.Alias.ToLowerInvariant() != propertyKey.ToLowerInvariant()))
					{
						var property = uwbsOrdersType.AddPropertyType(stringDataTypeDef, propertyKey, "#" + UppercaseFirstCharacter(propertyKey));

						var propertyShippingKey = propertyKey.Replace("customer", "shipping");

						var shippingProperty = uwbsOrdersType.AddPropertyType(stringDataTypeDef, propertyShippingKey, "#" + UppercaseFirstCharacter(propertyShippingKey));

						property.TabId = customerTabId;
						shippingProperty.TabId = shippingTabId;
					}
				}

				customersType.Save();

				// todo V7 version!
				var extraMessageProperty = uwbsOrdersType.AddPropertyType(textboxMultipleDataTypeDef, "extraMessage", "#ExtraMessage");
				extraMessageProperty.TabId = customerTabId;

				uwbsOrdersType.Save();
			}

			// create membergroup "customers", as set in the UmbracoMembershipProvider -> defaultMemberTypeAlias
			if (MemberGroup.GetByName("Customers") == null)
			{
				MemberGroup.MakeNew("Customers", admin);
			}

			Document.RePublishAll();
			library.RefreshContent();
		}
예제 #27
0
 private static List<PreValue> GetPreValues(DataTypeDefinition dataType)
 {
     helpers.uSyncLog.DebugLog("Getting Pre-Values"); 
     return PreValues.GetPreValues(dataType.Id).Values.OfType<PreValue>().OrderBy(p => p.SortOrder).ThenBy(p => p.Id).ToList();
 }
예제 #28
0
        /// <summary>
        ///  the more agressive pre-value manager - basically for Multi-Node Tree Pickers
        ///  
        /// does a like for like change - so goes through exsting values (in order) and sets
        /// their values to those in the import file (in same order) 
        /// 
        /// if the DataType doesn't maintain order (ie in lists) you would loose values doing this
        /// </summary>
        /// <param name="xmlData"></param>
        /// <param name="u"></param>
        /// <returns></returns>
        public static DataTypeDefinition MatchImport(DataTypeDefinition dtd, XmlNode xmlData, User u)
        {
            helpers.uSyncLog.DebugLog("usync - Match Import: for {0}", dtd.Text);

            List<PreValue> current = GetPreValues(dtd);
            XmlNodeList target = xmlData.SelectNodes("PreValues/PreValue");

            helpers.uSyncLog.DebugLog("uSync - Match Import: Counts [{0} Existing] [{1} New]", current.Count, target.Count); 

            for(int n = 0; n < current.Count(); n++)
            {
                XmlAttribute val = target[n].Attributes["Value"];
                if (current[n].Value != val.Value)
                {
                    helpers.uSyncLog.DebugLog("uSync - Match Import: Overwrite {0} with {1}", current[n].Value, val.Value );
                    current[n].Value = val.Value; 
                    current[n].Save(); 
                }
            }

            helpers.uSyncLog.DebugLog("uSync - Match Import: Complete");  
            return dtd;
        }
예제 #29
0
        /// <summary>
        /// Retrieves a list of all datatypedefinitions
        /// </summary>
        /// <returns>A list of all datatypedefinitions</returns>
        public static DataTypeDefinition[] GetAll()
        {
            SortedList retvalSort = new SortedList();
            Guid[] tmp = CMSNode.getAllUniquesFromObjectType(_objectType);
            DataTypeDefinition[] retval = new DataTypeDefinition[tmp.Length];
            for (int i = 0; i < tmp.Length; i++)
            {
                DataTypeDefinition dt = DataTypeDefinition.GetDataTypeDefinition(tmp[i]);
                retvalSort.Add(dt.Text + "|||" + Guid.NewGuid().ToString(), dt);
            }

            IDictionaryEnumerator ide = retvalSort.GetEnumerator();
            int counter = 0;
            while (ide.MoveNext())
            {
                retval[counter] = (DataTypeDefinition)ide.Value;
                counter++;
            }
            return retval;
        }
예제 #30
0
 public static void DataTypeDefinition_Saving(DataTypeDefinition sender, EventArgs e)
 {
     SaveToDisk((DataTypeDefinition)sender);
 }
예제 #31
0
        /// <summary>
        /// Creates a new datatypedefinition given its name and the user which creates it.
        /// </summary>
        /// <param name="u">The user who creates the datatypedefinition</param>
        /// <param name="Text">The name of the DataTypeDefinition</param>
        /// <param name="UniqueId">Overrides the CMSnodes uniqueID</param>
        /// <returns></returns>
        public static DataTypeDefinition MakeNew(BusinessLogic.User u, string Text, Guid UniqueId)
        {

            int newId = CMSNode.MakeNew(-1, _objectType, u.Id, 1, Text, UniqueId).Id;
            cms.businesslogic.datatype.controls.Factory f = new cms.businesslogic.datatype.controls.Factory();

            // initial control id changed to empty to ensure that it'll always work no matter if 3rd party configurators fail
            // ref: http://umbraco.codeplex.com/workitem/29788
            Guid FirstcontrolId = Guid.Empty;

            SqlHelper.ExecuteNonQuery("Insert into cmsDataType (nodeId, controlId, dbType) values (" + newId.ToString() + ",@controlId,'Ntext')",
                SqlHelper.CreateParameter("@controlId", FirstcontrolId));

            DataTypeDefinition dtd = new DataTypeDefinition(newId);
            dtd.OnNew(EventArgs.Empty);

            return dtd;
        }
예제 #32
0
 //
 // umbraco 6.0.4 changed the defintion of this event! 
 //
 public static void DataTypeDefinition_AfterDelete(DataTypeDefinition sender, EventArgs e)
예제 #33
0
        // after save doesn't fire on DataTypes (it still uses saving)
        /*
        static void DataTypeDefinition_AfterSave(object sender, SaveEventArgs e)
        {
            helpers.uSyncLog.DebugLog("DataType After Save (not checked)"); 
            if (typeof(DataTypeDefinition) == sender.GetType())
            {
                helpers.uSyncLog.DebugLog("DataType Saving (OnSave)");
                SaveToDisk((DataTypeDefinition)sender);
                helpers.uSyncLog.DebugLog("DataType Saved (OnSave-Complete)");
            }
        }
        */ 

        public static void DataTypeDefinition_Saving(DataTypeDefinition sender, EventArgs e)
        {
            helpers.uSyncLog.DebugLog("DataType Saving (Saving)");
            SaveToDisk((DataTypeDefinition)sender);
            helpers.uSyncLog.DebugLog("DataType Saved (Saving-complete)");
        }
        /// <summary>
        /// Generates the add box to add new items to the list
        /// </summary>
        /// <returns>Html representation of the fields in the add box.</returns>
        /// <remarks>
        /// There are actually a few things happening here:
        /// 1. The prevalue properties are examined one after the other, 
        ///    for each item the appropriate control is added to the box (e.g. textstring, true/false).
        ///    The control gets the id field{DTDId}_{id of the prevalue property}
        /// 2. While looping through the prevalues the xml schema is build up alongside and stored in m_hiddenXmlSchema.
        ///    This schema is used to build the xml representation of the value for this property as well as to build the relationship
        ///    in JS between the data and the dynamically added fields of each item.
        /// </remarks>
        private Table GenerateAddBox()
        {
            var table = new Table();
            table.Attributes.Add("class", "ECaddBoxTable");
            TableRow row;
            TableCell cell;

            var xmlSchema = new StringBuilder();

            xmlSchema.Append("<item id=\"\">");

            //decode the list of controls in the prevalue field and add them to the controls
            var prevalueSplit = _prevalue.Split(new[] { "||" }, 1000, StringSplitOptions.None);

            foreach (var pv in prevalueSplit)
            {
                if (string.IsNullOrEmpty(pv.Trim())) continue;

                var id = string.Empty;
                var name = string.Empty;
                var alias = string.Empty;
                var description = string.Empty;
                var showInTitle = false;
                var type = "Textstring";
                var required = false;
                var validation = string.Empty;

                var attributes = pv.Split('|');
                foreach (var attribute in attributes)
                {
                    if (!string.IsNullOrEmpty(attribute.Trim()))
                    {
                        var attr = attribute.Trim();
                        if (attr.StartsWith("id:"))
                        {
                            id = attr.Substring(3).Trim();
                        }
                        if (attr.StartsWith("Name:"))
                        {
                            name = attr.Substring(5).Trim();
                        }
                        if (attr.StartsWith("Alias:"))
                        {
                            alias = attr.Substring(6).Trim();
                        }
                        if (attr.StartsWith("Description:"))
                        {
                            description = System.Web.HttpUtility.HtmlEncode(attr.Substring(12).Trim().Replace("&lt;", "<").Replace("&gt;", ">"));
                        }
                        if (attr.StartsWith("Show in title?"))
                        {
                            bool.TryParse(attr.Substring(14).Trim(), out showInTitle);
                        }
                        if (attr.StartsWith("Type:"))
                        {
                            type = attr.Substring(5).Trim();
                        }
                        if (attr.StartsWith("Required?"))
                        {
                            bool.TryParse(attr.Substring(9).Trim(), out required);
                        }
                        if (attr.StartsWith("Validation:"))
                        {
                            validation = attr.Substring(11).Trim().Replace("@@@", "|");
                        }

                    }
                }
                if (!string.IsNullOrEmpty(id) && !string.IsNullOrEmpty(name) &&
                    !string.IsNullOrEmpty(alias) && !string.IsNullOrEmpty(type))
                {
                    row = new TableRow();
                    cell = new TableCell
                               {
            // ReSharper disable LocalizableElement
                                   Text = name + "<br /><small>" + description + "</small>"
            // ReSharper restore LocalizableElement
                               };
                    cell.Attributes.Add("class", "ECfirst");
                    row.Cells.Add(cell);

                    cell = new TableCell();
                    if (type == "-87")
                    {
                        var dataTypeDefinition = new DataTypeDefinition(-87);
                        //var dt = dataTypeDefinition.DataType;
                        var dt = new editorctrls_tinyMCE3.tinyMCE3dataType();
                        dt.DataTypeDefinitionId = -87;
                        //cell.Controls.Add(new TextBox { Text = dataTypeDefinition.DataType.DataTypeName });
                        //addControlNew(dataTypeDefinition.DataType, cell, alias, int.Parse(id));
                        dt.DataEditor.Editor.ID = string.Format("prop_{0}", alias);
                        dt.Data.PropertyId = int.Parse(id);
                        //IDataEditor de = new dt.DataEditor.Editor();
                        cell.Controls.Add(dt.DataEditor.Editor);
                    }
                    else
                    {
                        switch (type)
                        {
                            case "Textstring":
                                var tfe =
                                    new editorctrls_textfield.TextFieldEditor(
                                        new DefaultData(new editorctrls_textfield.TextFieldDataType()))
                                        {ID = string.Format("field{0}_{1}", DTDId, id)};
                                cell.Controls.Add(tfe);
                                break;
                            case "Textbox multiple":
                                var tfm =
                                    new editorctrls_textfield.TextFieldEditor(
                                        new DefaultData(
                                            new editorctrls_textfieldmultiple.textfieldMultipleDataType()))
                                        {
                                            ID = string.Format("field{0}_{1}", DTDId, id),
                                            TextMode = TextBoxMode.MultiLine,
                                            Rows = 5
                                        };
                                cell.Controls.Add(tfm);
                                break;
                            case "True/false":
                                var yesno =
                                    new yesNo(
                                        new DefaultData(
                                            new editorctrls_yesno.YesNoDataType())) { ID = string.Format("field{0}_{1}", DTDId, id) };
                                yesno.LabelAttributes.Add("style", "display: none;");
                                cell.Controls.Add(yesno);
                                break;
                            case "Content picker":
                                cell.Controls.Add(new SimpleContentPicker
                                                      {
                                                          ID = string.Format("field{0}_{1}", DTDId, id)
                                                      });
                                break;
                            case "Media picker":
                                cell.Controls.Add(new SimpleMediaPicker
                                                      {
                                                          ID = string.Format("field{0}_{1}", DTDId, id)
                                                      });
                                break;
                            case "Simple editor":
                                var simpleEditor =
                                    new editorctrls_simpleEditor.SimpleEditor(
                                        new DefaultData(
                                            new editorctrls_simpleEditor.simpleEditorDataType())) { ID = string.Format("field{0}_{1}", DTDId, id) };
                                cell.Controls.Add(simpleEditor);
                                break;
                            case "Date picker":
                                var datePicker = new dateField(
                                    new DefaultData(
                                        new editorctrls_datepicker.DateDataType()));
                                cell.Controls.Add(datePicker);
                                cell.ID = string.Format("field{0}_{1}", DTDId, id);
                                break;
                            case "Richtext editor":
                                //ataType
                                //var d = new Document(123);
                                //Property p = d.getProperty("asdf");
                                //PropertyType.GetAll()
                                //var richtextBox = new TinyMCE(
                                //    new DefaultData(
                                //        new tinyMCE3dataType()), ((editorCtrls.tinymce.tinyMCEPreValueConfigurator)PrevalueEditor).Configuration);
                                break;
                            default:
                                var tfeDefault =
                                    new editorctrls_textfield.TextFieldEditor(
                                        new DefaultData(new editorctrls_textfield.TextFieldDataType()))
                                        {ID = string.Format("field{0}_{1}", DTDId, id)};
                                cell.Controls.Add(tfeDefault);
                                break;
                        }
                    }

                cell.Attributes.Add("class", "ECsecond");
                    row.Cells.Add(cell);

                    table.Rows.Add(row);

                    xmlSchema.Append(string.Format("<{0} propertyid=\"{1}\" name=\"{2}\" description=\"{3}\" type=\"{4}\" showintitle=\"{5}\" required=\"{6}\" validation=\"{7}\">|value{1}|</{0}>", alias, id, name, description, type, showInTitle, required, validation));
                }
            }

            xmlSchema.Append("</item>");

            _hiddenXmlSchema = new HtmlInputHidden
            {
                ID = string.Format("EChiddenXmlSchema{0}", DTDId),
                Value = Uri.EscapeDataString(xmlSchema.ToString()),
                EnableViewState = true
            };

            row = new TableRow();
            row.Cells.Add(new TableCell());
            cell = new TableCell();
            // ReSharper disable LocalizableElement
            cell.Controls.Add(new Literal { Text = "<a href=\"#\" id=\"addPropertyLink" + DTDId + "\" title=\"create a new item with the above values\" class=\"ECaddPropertyLink\"><div class=\"ECbigButton\"></div></a>" });
            // ReSharper restore LocalizableElement
            cell.Attributes.Add("class", "ECsecond");
            row.Cells.Add(cell);
            table.Rows.Add(row);

            return table;
        }
예제 #35
0
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            instanceNodeID=((Widget_Builder_Default_Data)savedData).DataTypeDefinitionId;
            dataTypeDefinition = DataTypeDefinition.GetAll().Where(d =>d.DataType != null && d.DataType.DataTypeDefinitionId == instanceNodeID).First();

            string basicCSS = string.Format("<link href=\"{0}\" type=\"text/css\" rel=\"stylesheet\" />", "/umbraco/plugins/WidgetBuilder/WidgetBuilder.css");
            ScriptManager.RegisterClientScriptBlock(Page, typeof(Widget_Builder_DataEditor), "WidgetBuilderCSS", basicCSS, false);

            saveBox = new TextBox();
            wrapperDiv.Controls.Add(saveBox);
            saveBox.CssClass = "widgetSaveBox";
            saveBox.TextMode = TextBoxMode.MultiLine;
            ContentTemplateContainer.Controls.Add(saveBox);

            //set widget permissions
            try
            {
                widgetPermission = user.WidgetPermissions.widgets[dataTypeDefinition.UniqueId.ToString()];
            }
            catch (Exception e2)
            { }

            //determine if hidden
            string hideWidgetClass = "";
            if (widgetPermission.hide)
            {
                hideWidgetClass = "widgetHidden";
            }

            wrapperDiv.TagName = "div";
            wrapperDiv.Attributes["class"] = Regex.Replace(this.dataTypeDefinition.Text, @"[^a-zA-z0-9]", "") + " widgetWrapperDiv " + hideWidgetClass;
            wrapperDiv.Attributes["widgetMaxWidgets"] = savedOptions.maxWidgets.ToString();
            ContentTemplateContainer.Controls.Add(wrapperDiv);
        }
예제 #36
0
        /// <summary>
        /// Retrieves a list of all datatypedefinitions
        /// </summary>
        /// <returns>A list of all datatypedefinitions</returns>
        public static DataTypeDefinition[] GetAll()
        {
            var retvalSort = new SortedList();
            var tmp = getAllUniquesFromObjectType(ObjectType);
            var retval = new DataTypeDefinition[tmp.Length];
            for (var i = 0; i < tmp.Length; i++)
            {
                var dt = GetDataTypeDefinition(tmp[i]);
                retvalSort.Add(dt.Text + "|||" + Guid.NewGuid(), dt);
            }

            var ide = retvalSort.GetEnumerator();
            var counter = 0;
            while (ide.MoveNext())
            {
                retval[counter] = (DataTypeDefinition)ide.Value;
                counter++;
            }
            return retval;
        }