Exemplo n.º 1
0
        /// <summary>
        /// Gets the prevalue editor settings.
        /// </summary>
        /// <param name="dataTypeDefinitionId">The data type definition id.</param>
        /// <returns>The PreValue Editor Settings.</returns>
        public PreValueEditorSettings GetPrevalueEditorSettings(int dataTypeDefinitionId)
        {
            var prevalues = PreValues.GetPreValues(dataTypeDefinitionId);
            var settings  = new PreValueEditorSettings();

            if (prevalues.Count > 0)
            {
                var prevalue = (PreValue)prevalues[0];

                if (!string.IsNullOrEmpty(prevalue.Value))
                {
                    var serializer = new JavaScriptSerializer();

                    try
                    {
                        settings = serializer.Deserialize <PreValueEditorSettings>(prevalue.Value);
                    }
                    catch (Exception ex)
                    {
                        // Cannot understand stored prevalues
                        Helper.Log.Error <DataType>("Error when parsing stored prevalues", ex);
                    }
                }
            }

            return(settings);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets the stored datatype column configurations.
        /// </summary>
        /// <param name="dataTypeDefinitionId">The data type definition id.</param>
        /// <returns>A list of datatype column configurations.</returns>
        private IEnumerable <PreValueRow> GetColumnConfigurations(int dataTypeDefinitionId)
        {
            var prevalues = PreValues.GetPreValues(dataTypeDefinitionId);
            var sl        = new List <PreValueRow>();

            if (prevalues.Count > 1)
            {
                for (var i = 1; i < prevalues.Count; i++)
                {
                    var prevalue = (PreValue)prevalues[i];
                    if (!string.IsNullOrEmpty(prevalue.Value))
                    {
                        // Get the config
                        var serializer = new JavaScriptSerializer();

                        // Return the config
                        var s = serializer.Deserialize <PreValueRow>(prevalue.Value);
                        s.Id        = prevalue.Id;
                        s.SortOrder = prevalue.SortOrder;

                        sl.Add(s);
                    }
                }
            }

            return(sl);
        }
Exemplo n.º 3
0
        private void GenerateAdditionalThumbnails(Image image, int fileWidth, int fileHeight, string ext, string destFilePath)
        {
            var uploadFieldDataTypeId = new Guid("5032a6e6-69e3-491d-bb28-cd31cd11086c");

            DataTypeDefinition dataTypeDef = null;

            try
            {
                // Get DataTypeDefinition of upload field
                dataTypeDef = DataTypeDefinition.GetByDataTypeId(uploadFieldDataTypeId);
            }
            catch { }

            if (dataTypeDef != null)
            {
                // Get PreValues
                var preValues = PreValues.GetPreValues(dataTypeDef.Id);

                var thumbnails = "";
                if (preValues.Count > 0)
                {
                    thumbnails = ((PreValue)preValues[0]).Value;
                }

                if (thumbnails != "")
                {
                    var thumbnailSizes = thumbnails.Split(";".ToCharArray());
                    foreach (var thumb in thumbnailSizes.Where(thumb => thumb != ""))
                    {
                        GenerateThumbnail(image, int.Parse(thumb), fileWidth, fileHeight, ext,
                                          destFilePath + "_" + thumb + ".jpg");
                    }
                }
            }
        }
Exemplo n.º 4
0
        // -------------------------------------------------------------------------

        private static void GenerateAdditionalThumbnails(Image image, int fileWidth, int fileHeight, string destFilePath)
        {
            Guid uploadFieldDataTypeId = new Guid("5032a6e6-69e3-491d-bb28-cd31cd11086c");
            // Get DataTypeDefinition of upload field
            DataTypeDefinition dataTypeDef = DataTypeDefinition.GetByDataTypeId(uploadFieldDataTypeId);
            // Get PreValues
            SortedList preValues = PreValues.GetPreValues(dataTypeDef.Id);

            string thumbnails = "";

            if (preValues.Count > 0)
            {
                thumbnails = ((PreValue)preValues[0]).Value;
            }

            if (thumbnails != "")
            {
                string[] thumbnailSizes = thumbnails.Split(";".ToCharArray());
                foreach (string thumb in thumbnailSizes)
                {
                    if (thumb != "")
                    {
                        GenerateThumbnail(image, int.Parse(thumb), fileWidth, fileHeight, destFilePath + "_" + thumb + ".jpg");
                    }
                }
            }
        }
Exemplo n.º 5
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>());
    }
Exemplo n.º 6
0
        public CategoryInfo[] getCategories(
            string blogid,
            string username,
            string password)
        {
            if (validateUser(username, password))
            {
                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);

                    // check if the datatype uses tags or prevalues
                    CategoryInfo[]      returnedCategories = null;
                    interfaces.IUseTags tags = UseTags(categoryType);
                    if (tags != null)
                    {
                        List <interfaces.ITag> alltags = tags.GetAllTags();
                        returnedCategories = new CategoryInfo[alltags.Count];
                        int counter = 0;
                        foreach (interfaces.ITag t in alltags)
                        {
                            CategoryInfo ci = new CategoryInfo();
                            ci.title       = t.TagCaption;
                            ci.categoryid  = t.Id.ToString();
                            ci.description = "";
                            ci.rssUrl      = "";
                            ci.htmlUrl     = "";
                            returnedCategories[counter] = ci;
                            counter++;
                        }
                    }
                    else
                    {
                        SortedList categories = PreValues.GetPreValues(categoryType.DataTypeDefinition.Id);
                        returnedCategories = new CategoryInfo[categories.Count];
                        IDictionaryEnumerator ide = categories.GetEnumerator();
                        int counter = 0;
                        while (ide.MoveNext())
                        {
                            PreValue     category = (PreValue)ide.Value;
                            CategoryInfo ci       = new CategoryInfo();
                            ci.title       = category.Value;
                            ci.categoryid  = category.Id.ToString();
                            ci.description = "";
                            ci.rssUrl      = "";
                            ci.htmlUrl     = "";
                            returnedCategories[counter] = ci;
                            counter++;
                        }
                    }

                    return(returnedCategories);
                }
            }

            throw new ArgumentException("Categories doesn't work for this channel, they might not have been activated. Contact your umbraco administrator.");
        }
Exemplo n.º 7
0
        public void DataTypeDefinition_Assign_Data_Type_With_PreValues()
        {
            //System.Diagnostics.Debugger.Launch();

            //create datatype definition, assign data type
            var dtd = DataTypeDefinition.MakeNew(m_User, "TEST" + Guid.NewGuid().ToString("N"));

            Assert.IsTrue(dtd.Id > 0);
            Assert.IsInstanceOfType(dtd, typeof(DataTypeDefinition));
            IDataType dt = new TextFieldDataType();

            dt.DataTypeDefinitionId = dtd.Id; //need to set the data types data type definition id
            dtd.DataType            = dt;     //set our data type definition's data type to the text field... i know this is all too weird.

            Assert.AreEqual(dt.Id, dtd.DataType.Id);
            Assert.IsInstanceOfType(dtd.DataType, dt.GetType());
            Assert.AreEqual(dtd.Id, dt.DataTypeDefinitionId);

            //create the prevalues
            ((DefaultPrevalueEditor)dt.PrevalueEditor).Prevalue = "TEST" + Guid.NewGuid().ToString("N");
            dt.PrevalueEditor.Save();

            //verify that the prevalue is there
            Assert.AreEqual <int>(1, PreValues.GetPreValues(dtd.Id).Count);

            //now remove it
            dtd.delete();
            Assert.IsFalse(DataTypeDefinition.IsNode(dtd.Id));
        }
Exemplo n.º 8
0
        public string Import(XElement propertyTag)
        {
            var result = string.Empty;

            if (!string.IsNullOrWhiteSpace(propertyTag.Value))
            {
                var dtd =
                    Services.DataTypeService.GetAllDataTypeDefinitions()
                    .FirstOrDefault(x => x.Name == propertyTag.Attribute("dataTypeName").Value);

                if (dtd != null)
                {
                    var values = PreValues.GetPreValues(dtd.Id);

                    foreach (DictionaryEntry de in values)
                    {
                        var value = (PreValue)de.Value;
                        if (string.Equals(value.Value, propertyTag.Value, StringComparison.CurrentCultureIgnoreCase))
                        {
                            result = value.Id.ToString();
                            break;
                        }
                    }
                }
                else
                {
                    result = propertyTag.Value;
                }
            }

            return(result);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Gets the PreValue options for the data-type.
        /// </summary>
        /// <typeparam name="T">The type of the resulting object.</typeparam>
        /// <returns>
        /// Returns the options for the PreValue Editor
        /// </returns>
        public T GetPreValueOptions <T>()
        {
            var prevalues = PreValues.GetPreValues(this.m_DataType.DataTypeDefinitionId);

            if (prevalues.Count > 0)
            {
                var prevalue = (PreValue)prevalues[0];
                if (!String.IsNullOrEmpty(prevalue.Value))
                {
                    try
                    {
                        // deserialize the options
                        var serializer = new JavaScriptSerializer();

                        // return the options
                        return(serializer.Deserialize <T>(prevalue.Value));
                    }
                    catch (Exception ex)
                    {
                        Log.Add(LogTypes.Error, this.m_DataType.DataTypeDefinitionId, string.Concat("uCloud: Execption thrown: ", ex.Message));
                    }
                }
            }

            // if all else fails, return default options
            return(default(T));
        }
Exemplo n.º 10
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);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Gets the PreValue options for the data-type.
        /// </summary>
        /// <typeparam name="T">The type of the resulting object.</typeparam>
        /// <returns>
        /// Returns the options for the PreValue Editor
        /// </returns>
        public T GetPreValueOptions <T>()
        {
            var prevalues = PreValues.GetPreValues(this.DataType.DataTypeDefinitionId);

            if (prevalues.Count > 0)
            {
                var prevalue = (PreValue)prevalues[0];
                if (!string.IsNullOrEmpty(prevalue.Value))
                {
                    try
                    {
                        // deserialize the options
                        var serializer = new JavaScriptSerializer();

                        // return the options
                        return(serializer.Deserialize <T>(prevalue.Value));
                    }
                    catch (Exception ex)
                    {
                        LogHelper.Error <T>(string.Concat("uComponents: AbstractJsonPrevalueEditor.GetPreValueOptions<T> Exception.", ex.Message), ex);
                    }
                }
            }

            // if all else fails, return default options
            return(default(T));
        }
        /// <summary>
        /// Gets the PreValue options for the data-type.
        /// </summary>
        /// <typeparam name="T">The type of the resulting object.</typeparam>
        /// <returns>
        /// Returns the options for the PreValue Editor
        /// </returns>
        public T GetPreValueOptions <T>()
        {
            var prevalues = PreValues.GetPreValues(this.m_DataType.DataTypeDefinitionId);

            if (prevalues.Count > 0)
            {
                var prevalue = (PreValue)prevalues[0];
                if (!string.IsNullOrEmpty(prevalue.Value))
                {
                    try
                    {
                        // deserialize the options
                        var serializer = new JavaScriptSerializer();

                        // return the options
                        return(serializer.Deserialize <T>(prevalue.Value));
                    }
                    catch (Exception ex)
                    {
                        LogHelper.Error <AbstractJsonPrevalueEditor>("umbraco.editorControls: Execption thrown", ex);
                    }
                }
            }

            // if all else fails, return default options
            return(default(T));
        }
Exemplo n.º 13
0
        /// <summary>
        /// Saves the data for this instance of the PreValue Editor.
        /// </summary>
        public override void Save()
        {
            this.m_DataType.DBType = umbraco.cms.businesslogic.datatype.DBTypes.Ntext;

            lock (m_Locker)
            {
                var vals = PreValues.GetPreValues(this.m_DataType.DataTypeDefinitionId);
                if (vals.Count >= 1)
                {
                    // update
                    ((PreValue)vals[0]).Value = this._pickerType.SelectedValue;

                    ((PreValue)vals[0]).Save();
                }
                else
                {
                    // insert
                    PreValue.MakeNew(this.m_DataType.DataTypeDefinitionId, this._pickerType.SelectedValue);
                }

                // store the xpath
                if (vals.Count >= 2)
                {
                    // update
                    ((PreValue)vals[1]).Value = this._chooseTextBox.Text;
                    ((PreValue)vals[1]).Save();
                }
                else
                {
                    // insert
                    PreValue.MakeNew(this.m_DataType.DataTypeDefinitionId, this._chooseTextBox.Text);
                }
            }
        }
Exemplo n.º 14
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>());
    }
Exemplo n.º 15
0
 public SortedList GetPreValues()
 {
     if (_preValues == null)
     {
         _preValues = PreValues.GetPreValues(_dataType.DataTypeDefinitionId);
     }
     return(_preValues);
 }
Exemplo n.º 16
0
 /// <summary>
 /// Lazy loads the prevalues for this data type
 /// </summary>
 /// <returns></returns>
 private SortedList GetPreValues()
 {
     if (m_PreValues == null)
     {
         m_PreValues = PreValues.GetPreValues(m_DataType.DataTypeDefinitionId);
     }
     return(m_PreValues);
 }
Exemplo n.º 17
0
        /// <summary>
        /// Renders the contents of the control to the specified writer. This method is used primarily by control developers.
        /// </summary>
        /// <param name="writer">A <see cref="T:System.Web.UI.HtmlTextWriter"/> that represents the output stream to render HTML content on the client.</param>
        protected override void RenderContents(HtmlTextWriter writer)
        {
            writer.AddPrevalueRow("Add prevalue:", this.TextControl, this.RequiredControl);

            // get the existing prevalues
            var prevalues = PreValues.GetPreValues(this.m_DataType.DataTypeDefinitionId).GetValueList();

            // check if there are any prevalues
            if (prevalues != null && prevalues.Count > 0)
            {
                // create placeholder DIV tag
                var placeholder = new HtmlGenericControl("div");

                // loop through each of the prevalues
                foreach (PreValue value in prevalues)
                {
                    // if the value is empty, then remove it
                    if (string.IsNullOrEmpty(value.Value))
                    {
                        value.Delete();
                        break;
                    }

                    // create row
                    var row = new HtmlGenericControl("div");
                    row.Attributes.Add("class", "row clearfix");

                    // create the label
                    var label = new HtmlGenericControl("div");
                    label.Attributes.Add("class", "label");
                    label.InnerText = value.Value;

                    // create the field
                    var field = new HtmlGenericControl("div");
                    field.Attributes.Add("class", "field");

                    // create the anchor
                    var anchor = new System.Web.UI.HtmlControls.HtmlAnchor();
                    anchor.HRef      = string.Concat("?id=", this.m_DataType.DataTypeDefinitionId, "&delete=", value.Id);
                    anchor.InnerText = ui.Text("delete");
                    anchor.Attributes.Add("onclick", "javascript:return confirm('Are you sure you want to delete this value?');");

                    // add the anchor to the field
                    field.Controls.Add(anchor);

                    // add the label and field to the row
                    row.Controls.Add(label);
                    row.Controls.Add(field);

                    // add the row to the placeholder
                    placeholder.Controls.Add(row);
                }

                // render the placeholder
                writer.AddPrevalueRow("Values:", placeholder);
            }
        }
Exemplo n.º 18
0
        private void PopulateCacheWithDataTypePreValues()
        {
            var c  = System.Web.HttpContext.Current.Cache;
            var ds = new Umbraco.Core.Services.DataTypeService();

            foreach (var dtd in ds.GetAllDataTypeDefinitions())
            {
                c.Insert(dtd.Name, PreValues.GetPreValues(dtd.Id));
            }
        }
Exemplo n.º 19
0
 /// <summary>
 /// Deletes the specified id.
 /// </summary>
 /// <param name="id">The id.</param>
 private void Delete(string id)
 {
     foreach (PreValue val in PreValues.GetPreValues(this.m_DataType.DataTypeDefinitionId).GetValueList())
     {
         if (val.Id.ToString() == id)
         {
             val.Delete();
             return;
         }
     }
 }
Exemplo n.º 20
0
        /// <summary>
        /// Gets the prevalues for a specified datatype as a strongly typed list.
        /// </summary>
        /// <param name="dataTypeDefinitionId">The datatype definition id.</param>
        /// <returns>The list of PreValues.</returns>
        public static PreValue[] GetPreValues(int dataTypeDefinitionId)
        {
            var values = new List <PreValue>();

            foreach (var entry in PreValues.GetPreValues(dataTypeDefinitionId))
            {
                var prevalue = ((DictionaryEntry)entry).Value as PreValue;
                values.Add(prevalue);
            }

            return(values.ToArray());
        }
        public void Export(Property property, XElement propertyTag, Dictionary <int, ObjectTypes> dependantNodes)
        {
            if (property.Value != null && !string.IsNullOrWhiteSpace(property.Value.ToString()))
            {
                var ups = UrlPickerState.Deserialize(property.Value.ToString());

                if (ups != null)
                {
                    // find the data type definition
                    var dtd =
                        Services.DataTypeService.GetAllDataTypeDefinitions()
                        .FirstOrDefault(x => x.Name == propertyTag.Attribute("dataTypeName").Value);

                    // store how data is saved
                    if (dtd != null)
                    {
                        var values = PreValues.GetPreValues(dtd.Id);

                        if (values.Count >= 1)
                        {
                            var pv = values[1] as PreValue;

                            propertyTag.Add(new XAttribute("format", pv.Value));
                        }
                    }

                    propertyTag.Add(new XAttribute("mode", ups.Mode.ToString()));
                    propertyTag.Value = property.Value.ToString();

                    // find the id and convert it to guid
                    if (ups.NodeId != null && ups.NodeId.Value > 0)
                    {
                        if (ups.Mode == UrlPickerMode.Content)
                        {
                            var content = Services.ContentService.GetById(ups.NodeId.Value);

                            if (content != null)
                            {
                                propertyTag.Add(new XAttribute("nodeId", content.Key.ToString()));
                            }
                        }
                        else if (ups.Mode == UrlPickerMode.Media)
                        {
                            var media = Services.MediaService.GetById(ups.NodeId.Value);
                            if (media != null)
                            {
                                propertyTag.Add(new XAttribute("nodeId", media.Key.ToString()));
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 22
0
 /// <summary>
 /// Deletes the specified id.
 /// </summary>
 /// <param name="id">The id.</param>
 private void Delete(string id)
 {
     foreach (umbraco.cms.businesslogic.datatype.PreValue val in PreValues.GetPreValues(m_DataType.DataTypeDefinitionId).GetValueList())
     {
         if (val.Id.ToString() == id)
         {
             FileInfo fi = new FileInfo(IOHelper.MapPath(val.Value.Split('|')[1]));
             if (fi.Exists)
             {
                 val.Delete();
                 fi.Delete();
             }
             return;
         }
     }
 }
Exemplo n.º 23
0
        /// <summary>
        /// Saves this instance.
        /// </summary>
        public override void Save()
        {
            // it will always be text since people may save a huge amount of selected nodes and serializing to xml could be large.
            this.m_DataType.DBType = umbraco.cms.businesslogic.datatype.DBTypes.Ntext;

            // need to lock this operation since multiple inserts are happening and if 2 threads reach here at the same time, there could be issues.
            lock (m_Locker)
            {
                var vals = PreValues.GetPreValues(this.m_DataType.DataTypeDefinitionId);
                if (vals.Count > 0)
                {
                    // update
                    ((PreValue)vals[0]).Value = this.MinValueTextBox.Text;
                    ((PreValue)vals[0]).Save();
                }
                else
                {
                    // insert
                    PreValue.MakeNew(this.m_DataType.DataTypeDefinitionId, this.MinValueTextBox.Text);
                }

                if (vals.Count > 1)
                {
                    // update
                    ((PreValue)vals[1]).Value = this.MaxValueTextBox.Text;
                    ((PreValue)vals[1]).Save();
                }
                else
                {
                    // insert
                    PreValue.MakeNew(this.m_DataType.DataTypeDefinitionId, this.MaxValueTextBox.Text);
                }

                if (vals.Count > 2)
                {
                    // update
                    ((PreValue)vals[2]).Value = this.IncrementValueTextBox.Text;
                    ((PreValue)vals[2]).Save();
                }
                else
                {
                    // insert
                    PreValue.MakeNew(this.m_DataType.DataTypeDefinitionId, this.IncrementValueTextBox.Text);
                }
            }
        }
Exemplo n.º 24
0
        /// <summary>
        ///
        /// </summary>
        public void Save()
        {
            this.m_DataType.DBType = umbraco.cms.businesslogic.datatype.DBTypes.Ntext;

            lock (m_Locker)
            {
                var    vals = PreValues.GetPreValues(this.m_DataType.DataTypeDefinitionId);
                string selectedValuesAsCsv = GetSelectedPropertyAliases();
                if (vals.Count >= 1)
                {
                    // update
                    ((PreValue)vals[0]).Value = selectedValuesAsCsv;
                    ((PreValue)vals[0]).Save();
                }
                else
                {
                    // insert
                    PreValue.MakeNew(this.m_DataType.DataTypeDefinitionId, selectedValuesAsCsv);
                }

                if (vals.Count >= 2)
                {
                    //update
                    ((PreValue)vals[1]).Value = _txtMaxResults.Text;
                    ((PreValue)vals[1]).Save();
                }
                else
                {
                    //insert
                    PreValue.MakeNew(m_DataType.DataTypeDefinitionId, _txtMaxResults.Text);
                }
                if (vals.Count >= 3)
                {
                    //update
                    ((PreValue)vals[2]).Value = _indexToSearch.SelectedValue;
                    ((PreValue)vals[2]).Save();
                }
                else
                {
                    //insert
                    PreValue.MakeNew(m_DataType.DataTypeDefinitionId, _indexToSearch.SelectedValue);
                }
            }
        }
Exemplo n.º 25
0
        /// <summary>
        /// Saves the data for this instance of the PreValue Editor.
        /// </summary>
        public override void Save()
        {
            this.m_DataType.DBType = umbraco.cms.businesslogic.datatype.DBTypes.Nvarchar;

            lock (m_Locker)
            {
                var vals = PreValues.GetPreValues(this.m_DataType.DataTypeDefinitionId);
                if (vals.Count >= 1)
                {
                    // update
                    ((PreValue)vals[0]).Value = this.RootDirectory.Text;
                    ((PreValue)vals[0]).Save();
                }
                else
                {
                    // insert
                    PreValue.MakeNew(this.m_DataType.DataTypeDefinitionId, this.RootDirectory.Text);
                }
            }
        }
Exemplo n.º 26
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);
            }
        }
Exemplo n.º 27
0
        /// <summary>
        /// Get all the prevalues for a given data type.
        /// </summary>
        /// <param name="dataTypeName">The name of the data type.</param>
        /// <returns>A sorted list with the prevalues.</returns>
        public SortedList GetPreValues(string dataTypeName)
        {
            // Get a sorted list of all prevalues from the cache
            var        c           = System.Web.HttpContext.Current.Cache;
            SortedList statusTypes = c.Get(dataTypeName) as SortedList;

            if (statusTypes == null)
            {
                // Connect to Umbraco DataTypeService
                var ds = new Umbraco.Core.Services.DataTypeService();

                // Get the Definition Id
                int dataTypeDefinitionId = ds.GetAllDataTypeDefinitions().First(x => x.Name == dataTypeName).Id;

                // Get a sorted list of all prevalues and store it in the cache
                statusTypes = PreValues.GetPreValues(dataTypeDefinitionId);
                c.Insert(dataTypeName, statusTypes);
            }

            return(statusTypes);
        }
        /// <summary>
        /// Saves the data-type PreValue options.
        /// </summary>
        public void SaveAsJson(object options)
        {
            // serialize the options into JSON
            var serializer = new JavaScriptSerializer();
            var json       = serializer.Serialize(options);

            lock (m_Locker)
            {
                var prevalues = PreValues.GetPreValues(this.m_DataType.DataTypeDefinitionId);
                if (prevalues.Count > 0)
                {
                    PreValue prevalue = (PreValue)prevalues[0];
                    // update
                    prevalue.Value = json;
                    prevalue.Save();
                }
                else
                {
                    // insert
                    PreValue.MakeNew(this.m_DataType.DataTypeDefinitionId, json);
                }
            }
        }
Exemplo n.º 29
0
        /// <summary>
        /// Saves this instance.
        /// </summary>
        public void Save()
        {
            this.m_DataType.DBType = umbraco.cms.businesslogic.datatype.DBTypes.Nvarchar;

            lock (m_Locker)
            {
                var vals = PreValues.GetPreValues(this.m_DataType.DataTypeDefinitionId);
                var data = string.Concat(this.WidthTextBox.Text, Constants.Common.COMMA, this.StyleTextBox.Text);

                if (vals.Count >= 1)
                {
                    // update
                    ((PreValue)vals[0]).Value = data;
                    ((PreValue)vals[0]).Save();
                }
                else
                {
                    // insert
                    PreValue.MakeNew(this.m_DataType.DataTypeDefinitionId, data);
                }
            }

            this.SetPreviewTextbox();
        }
Exemplo n.º 30
0
        /// <summary>
        /// Sets a property value, and returns self.
        /// </summary>
        /// <param name="item">The content item.</param>
        /// <param name="propertyAlias">The alias of property to set.</param>
        /// <param name="value">The value to set.</param>
        /// <returns>
        /// The same content item on which this is an extension method.
        /// </returns>
        public static Content SetProperty(this Content item, string propertyAlias, object value)
        {
            var property = item.getProperty(propertyAlias);

            if (property != null)
            {
                if (value != null)
                {
                    var dataTypeGuid = property.PropertyType.DataTypeDefinition.DataType.Id.ToString();

                    // switch based on datatype of property being set - if setting a built in ddl or radion button list, then string supplied is checked against prevalues
                    switch (dataTypeGuid.ToUpper())
                    {
                    case Constants.PropertyEditors.DropDownList:                             // DropDownList
                    case Constants.PropertyEditors.RadioButtonList:                          // RadioButtonList

                        var      preValues = PreValues.GetPreValues(property.PropertyType.DataTypeDefinition.Id);
                        PreValue preValue  = null;

                        // switch based on the supplied value type
                        switch (Type.GetTypeCode(value.GetType()))
                        {
                        case TypeCode.String:
                            // attempt to get prevalue from the label
                            preValue = preValues.Values.Cast <PreValue>().Where(x => x.Value == (string)value).FirstOrDefault();
                            break;

                        case TypeCode.Int16:
                        case TypeCode.Int32:
                            // attempt to get prevalue from the id
                            preValue = preValues.Values.Cast <PreValue>().Where(x => x.Id == (int)value).FirstOrDefault();
                            break;
                        }

                        if (preValue != null)
                        {
                            // check db field type being saved to and store prevalue id as an int or a string - note can never save a prevalue id to a date field !
                            switch (((DefaultData)property.PropertyType.DataTypeDefinition.DataType.Data).DatabaseType)
                            {
                            case DBTypes.Ntext:
                            case DBTypes.Nvarchar:
                                property.Value = preValue.Id.ToString();
                                break;

                            case DBTypes.Integer:
                                property.Value = preValue.Id;
                                break;
                            }
                        }

                        break;

                    case Constants.PropertyEditors.Date:                             // Date (NOTE: currently assumes database type is set to Date)

                        switch (Type.GetTypeCode(value.GetType()))
                        {
                        case TypeCode.DateTime:
                            property.Value = ((DateTime)value).Date;
                            break;

                        case TypeCode.String:
                            DateTime valueDateTime;
                            if (DateTime.TryParse((string)value, out valueDateTime))
                            {
                                property.Value = valueDateTime.Date;
                            }
                            ;
                            break;
                        }

                        break;

                    default:
                        // This saves the property value
                        property.Value = value;
                        break;
                    }
                }
                else
                {
                    // the value is NULL
                    property.Value = value;
                }
            }

            item.Save();

            return(item);
        }