/// <summary>
        /// Adds the property to the Document Type
        /// </summary>
        /// <param name="documentType"></param>
        /// <param name="property"></param>
        /// <param name="tabName"></param>
        /// <param name="registeredDataTypes"></param>
        /// <returns></returns>
        public virtual bool AddPropertyToDocumentType(IContentType documentType, UmbracoConversionProperty property, string tabName, IEnumerable <IDataTypeDefinition> registeredDataTypes)
        {
            if (property.Editor == "Umbraco.RichEdit")
            {
                property.Editor = "Umbraco.TinyMCEv3";
            }

            if (registeredDataTypes.Any(d => d.PropertyEditorAlias == property.Editor))
            {
                DataTypeDefinition dataTypeDefintion = new DataTypeDefinition(property.Editor);
                PropertyType       propertyType      = new PropertyType(dataTypeDefintion, property.Alias.FirstCharacterToLower());

                propertyType.Name        = property.Label;
                propertyType.Description = property.Description;

                Debug.WriteLine($"Added property: {propertyType.Name} ({property.Tab})");

                documentType.AddPropertyType(propertyType, tabName);

                return(true);
            }
            else
            {
                throw new PropertyParseException($"There was a problem parsing the property for {property.Alias}. Ensure this property editor exists and is registered: { property.Editor}")
                      {
                          Alias               = property.Alias,
                          EditorAttempt       = property.Editor,
                          RegisteredDataTypes = registeredDataTypes.ToList()
                      };
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the files from the defined template file path, and converts them to UmbracoConversionObjects
        /// </summary>
        /// <param name="templateDirectory">The directory that contains the template files</param>
        /// <param name="allowedExtensions">The extensions that will be used within the directory</param>
        /// <returns></returns>
        public IEnumerable <RapidUmbracoConversionObject> Convert(string templateDirectory, string[] allowedExtensions)
        {
            if (String.IsNullOrWhiteSpace(templateDirectory))
            {
                throw new ArgumentNullException("templateDirectory", "Cannot find the files if a file location is not supplied");
            }

            if (allowedExtensions.Count() <= 0)
            {
                throw new ArgumentException("Accepted extensions were not provided");
            }

            //Extract the files into the basic Rapid Umbraco Conversion Object
            List <RapidUmbracoConversionObject> umbracoConversionObjects = ConvertWithoutProperties(templateDirectory, allowedExtensions);

            foreach (var conversionObject in umbracoConversionObjects)
            {
                string fileContents = conversionObject.FileContent;

                int startOfTagIndex = 0,
                    endOfTagIndex   = 0;

                //Get all of the indexes for the position
                while (startOfTagIndex >= 0 && endOfTagIndex >= 0)
                {
                    startOfTagIndex = fileContents.IndexOf(RapidUmbracoSettings.TagStart, startOfTagIndex + 1);
                    endOfTagIndex   = fileContents.IndexOf(RapidUmbracoSettings.TagEnd, endOfTagIndex + 1);

                    if (startOfTagIndex >= 0 && endOfTagIndex >= 0)
                    {
                        Debug.WriteLine($"Found tag at position: {startOfTagIndex} to {endOfTagIndex}");

                        string tag = fileContents.Substring(startOfTagIndex, (endOfTagIndex - startOfTagIndex + RapidUmbracoSettings.TagEnd.Length));
                        Debug.WriteLine($"Tag: {tag}");

                        UmbracoConversionProperty convertedProperty = ConvertMarkupTagToUmbracoConversionProperty(tag);
                        conversionObject.PropertyCollection.Add(convertedProperty);
                    }
                }
            }

            Debug.WriteLine("Umbraco Conversion Objects: " + umbracoConversionObjects.Count());
            return(umbracoConversionObjects);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Converts a well formed Umbraco Conversion Tag into an Umbraco Conversion Property that can then be applied to a ContentType
        /// </summary>
        /// <param name="tag"></param>
        /// <returns></returns>
        public UmbracoConversionProperty ConvertMarkupTagToUmbracoConversionProperty(string tag)
        {
            //Split the values from the tag into a dictionary that can then be used to set the properties
            Dictionary <string, string> tagDictionary = tag.Split(' ')
                                                        .Select(x => x.Split('='))
                                                        .Where(x => x.Length == 2)
                                                        .ToDictionary(x => x.First().RemoveSpecialCharacters(), x => x.Last().RemoveSpecialCharacters());

            var conversionProperty = new UmbracoConversionProperty(tag)
            {
                Alias       = GetPropertyValue(tagDictionary, "alias", isRequired: true),
                Label       = GetPropertyValue(tagDictionary, "label", isRequired: true, defaultValue: GetPropertyValue(tagDictionary, "alias", isRequired: true).FromCamelToWord()),
                Description = GetPropertyValue(tagDictionary, "description", isRequired: false),
                Editor      = GetPropertyValue(tagDictionary, "editorAlias", isRequired: true, defaultValue: "Umbraco.Textbox"),
                Tab         = GetPropertyValue(tagDictionary, "tab")
            };

            return(conversionProperty);
        }