示例#1
0
        private void ensurePrevalue()
        {
            if (!_isEnsured)
            {
                int defId;
                if (_datatype != null)
                {
                    defId = _datatype.DataTypeDefinitionId;
                }
                else if (_datatypeOld != null)
                {
                    defId = _datatypeOld.DataTypeDefinitionId;
                }
                else
                {
                    throw new ArgumentException("Datatype is not initialized");
                }

                bool hasPrevalue = PreValues.CountOfPreValues(defId) > 0;

                if (!hasPrevalue)
                {
                    PreValue.MakeNew(defId, _textbox.Text);
                }
                _isEnsured = true;
            }
        }
示例#2
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);
        }
示例#3
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);
        }
        public static DataTypeDefinition Import(XmlNode xmlData)
        {
            var name = xmlData.Attributes["Name"].Value;
            var id   = xmlData.Attributes["Id"].Value;
            var def  = xmlData.Attributes["Definition"].Value;


            //Make sure that the dtd is not already present
            if (IsNode(new Guid(def)) == false)
            {
                var u = BusinessLogic.User.GetCurrent() ?? BusinessLogic.User.GetUser(0);

                var dtd      = MakeNew(u, name, new Guid(def));
                var dataType = DataTypesResolver.Current.GetById(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"))
                {
                    var val = xmlPv.Attributes["Value"];

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

                return(dtd);
            }

            return(null);
        }
示例#5
0
 /// <summary>
 /// Creates a new blog category / tag.
 /// </summary>
 /// <param name="blogid">The blogid.</param>
 /// <param name="username">The username.</param>
 /// <param name="password">The password.</param>
 /// <param name="category">The category.</param>
 /// <returns></returns>
 public string newCategory(
     string blogid,
     string username,
     string password,
     wpCategory category)
 {
     if (User.validateCredentials(username, password, false))
     {
         Channel userChannel = new Channel(username);
         if (userChannel.FieldCategoriesAlias != null && userChannel.FieldCategoriesAlias != "")
         {
             // Find the propertytype via the document type
             ContentType blogPostType = ContentType.GetByAlias(userChannel.DocumentTypeAlias);
             PropertyType categoryType = blogPostType.getPropertyType(userChannel.FieldCategoriesAlias);
             interfaces.IUseTags tags = UseTags(categoryType);
             if (tags != null)
             {
                 tags.AddTag(category.name);
             }
             else
             {
                 PreValue pv = new PreValue();
                 pv.DataTypeId = categoryType.DataTypeDefinition.Id;
                 pv.Value = category.name;
                 pv.Save();
             }
         }
     }
     return "";
 }
        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 = BusinessLogic.User.GetCurrent();

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

                controls.Factory f = new 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;
        }
        private void updateCategories(Document doc, Post post, Channel userChannel)
        {
            if (userChannel.FieldCategoriesAlias != null && userChannel.FieldCategoriesAlias != "")
            {
                ContentType blogPostType = ContentType.GetByAlias(userChannel.DocumentTypeAlias);
                PropertyType categoryType = blogPostType.getPropertyType(userChannel.FieldCategoriesAlias);

                String[] categories = post.categories;
                string categoryValue = "";
                interfaces.IUseTags tags = UseTags(categoryType);
                if (tags != null)
                {
                    tags.RemoveTagsFromNode(doc.Id);
                    for (int i = 0; i < categories.Length; i++)
                    {
                        tags.AddTagToNode(doc.Id, categories[i]);
                    }
                    //If the IUseTags provider manually set the property value to something on the IData interface then we should persist this
                    //code commented as for some reason, even though the IUseTags control is setting IData.Value it is null here
                    //could be a cache issue, or maybe it's a different instance of the IData or something, rather odd
                    //doc.getProperty(userChannel.FieldCategoriesAlias).Value = categoryType.DataTypeDefinition.DataType.Data.Value;

                    //Instead, set the document property to CSV of the tags - this WILL break custom editors for tags which don't adhere to the
                    //pseudo standard that the .Value of the property contains CSV tags. 
                    doc.getProperty(userChannel.FieldCategoriesAlias).Value = string.Join(",", categories);
                }
                else
                {
                    for (int i = 0; i < categories.Length; i++)
                    {
                        PreValue pv = new PreValue(categoryType.DataTypeDefinition.Id, categories[i]);
                        categoryValue += pv.Id + ",";
                    }
                    if (categoryValue.Length > 0)
                        categoryValue = categoryValue.Substring(0, categoryValue.Length - 1);

                    doc.getProperty(userChannel.FieldCategoriesAlias).Value = categoryValue;
                }
            }
        }
        /// <summary>
        /// DataType Import - taken from the core 
        /// 
        /// the core doesn't pass username, so fails on loading
        /// here we just pass usere User(0) - so we can work)
        /// </summary>
        /// <param name="xmlData"></param>
        /// <returns></returns>
        public static DataTypeDefinition Import(XmlNode xmlData, User u)
        {
            if (xmlData != null)
            {
                string _name = xmlData.Attributes["Name"].Value;
                string _id = xmlData.Attributes["Id"].Value;
                string _def = xmlData.Attributes["Definition"].Value;

                DataTypeDefinition dtd;

                if (CMSNode.IsNode(new Guid(_def)))
                {
                    dtd = DataTypeDefinition.GetDataTypeDefinition(new Guid(_def));
                }
                else
                {

                    if (u == null)
                        u = global::umbraco.BusinessLogic.User.GetUser(0);

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

                    dtd = DataTypeDefinition.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();
                }

                //
                // PREVALUES - HELL :: num 4532
                // 
                // Here we are attempting to add new prevalues to a DataType, and remove old ones.
                // between umbraco installs the IDs will change. we are not trying to match them,
                // we are just trying to match, based on value - problem being, if you change 
                // a value's value then this code would think it's a new ID, delete the old one
                // and create a new one - as we are syncing from a dev point of view we are
                // going to do this for now...
                //

                System.Collections.SortedList prevals = PreValues.GetPreValues(dtd.Id);
                Hashtable oldvals = new Hashtable();
                foreach (DictionaryEntry v in prevals)
                {
                    if ((PreValue)v.Value != null)
                    // if (!String.IsNullOrEmpty(((PreValue)v.Value).Value.ToString()))
                    {
                        oldvals.Add(((PreValue)v.Value).Id, ((PreValue)v.Value).Value.ToString());
                    }
                }

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

                    if (val != null)
                    {
                        // add new values only - because if we mess with old ones. it all goes pete tong..
                        if ((val.Value != null) && (!oldvals.ContainsValue(val.Value)))
                        {
                            Log.Add(LogTypes.Debug, 0, string.Format("Adding Prevalue [{0}]", val.Value));
                            PreValue p = new PreValue(0, 0, val.Value);
                            p.DataTypeId = dtd.Id;
                            p.Save();
                        }

                        newvals.Add(xmlPv.Attributes["Id"], val.Value);
                    }
                }


                // ok now delete any values that have gone missing between syncs..

                if (!uSyncSettings.Preserve || !uSyncSettings.PreservedPreValueDataTypes.Contains(_id))
                {
                    foreach (DictionaryEntry oldval in oldvals)
                    {
                        if (!newvals.ContainsValue(oldval.Value))
                        {
                            PreValue o = new PreValue((int)oldval.Key);
                            Log.Add(LogTypes.Debug, 0, string.Format("In {0} Deleting prevalue [{1}]", dtd.Text, oldval.Value));
                            o.Delete();
                        }
                    }
                }
                return dtd;
            }
            return null;
        }
        private void updateCategories(Document doc, Post post, Channel userChannel)
        {
            if (userChannel.FieldCategoriesAlias != null && userChannel.FieldCategoriesAlias != "")
            {
                ContentType blogPostType = ContentType.GetByAlias(userChannel.DocumentTypeAlias);
                PropertyType categoryType = blogPostType.getPropertyType(userChannel.FieldCategoriesAlias);

                String[] categories = post.categories;
                string categoryValue = "";
                interfaces.IUseTags tags = UseTags(categoryType);
                if (tags != null)
                {
                    tags.RemoveTagsFromNode(doc.Id);
                    for (int i = 0; i < categories.Length; i++)
                    {
                        tags.AddTagToNode(doc.Id, categories[i]);
                    }

                }
                else
                {
                    for (int i = 0; i < categories.Length; i++)
                    {
                        PreValue pv = new PreValue(categoryType.DataTypeDefinition.Id, categories[i]);
                        categoryValue += pv.Id + ",";
                    }
                }
                if (categoryValue.Length > 0)
                    categoryValue = categoryValue.Substring(0, categoryValue.Length - 1);

                doc.getProperty(userChannel.FieldCategoriesAlias).Value = categoryValue;
            }
        }
        public static DataTypeDefinition Import(XmlNode xmlData)
        {
            var name = xmlData.Attributes["Name"].Value;
            var id = xmlData.Attributes["Id"].Value;
            var def = xmlData.Attributes["Definition"].Value;


            //Make sure that the dtd is not already present
            if (IsNode(new Guid(def)) == false)
            {
                var u = BusinessLogic.User.GetCurrent() ?? BusinessLogic.User.GetUser(0);

                var dtd = MakeNew(u, name, new Guid(def));
                var dataType = DataTypesResolver.Current.GetById(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"))
                {
                    var val = xmlPv.Attributes["Value"];

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

                return dtd;
            }

            return null;
        }