Esempio n. 1
0
 protected override void SaveItem(IDataType item)
 {
     if (item.IsDirty())
     {
         dataTypeService.Save(item);
     }
 }
Esempio n. 2
0
        private SyncAttempt <IDataTypeDefinition> DeserializeItem(XElement node, IDataTypeDefinition item)
        {
            // pre import
            var  mappedNode = DeserializeGetMappedValues(node);
            Guid key        = node.Attribute("Key").ValueOrDefault(Guid.Empty);

            var name         = node.Attribute("Name").ValueOrDefault(string.Empty);
            var editorAlias  = node.Attribute("Id").ValueOrDefault(string.Empty);
            var dbType       = node.Attribute("DatabaseType").ValueOrDefault(string.Empty);
            var databaseType = !string.IsNullOrEmpty(dbType) ? dbType.EnumParse <DataTypeDatabaseType>(true) : DataTypeDatabaseType.Ntext;

            if (item == null && !string.IsNullOrEmpty(name))
            {
                // lookup by alias.
                LogHelper.Debug <DataTypeSerializer>("Looking up datatype by name: {0}", () => name);
                item = _dataTypeService.GetDataTypeDefinitionByName(name);
            }

            if (item == null)
            {
                // create
                item = new DataTypeDefinition(editorAlias)
                {
                    Key = key, Name = name, DatabaseType = databaseType
                };
            }

            if (item.Name != name)
            {
                item.Name = name;
            }

            if (item.Key != key)
            {
                item.Key = key;
            }

            if (item.PropertyEditorAlias != editorAlias)
            {
                item.PropertyEditorAlias = editorAlias;
            }

            if (item.DatabaseType != databaseType)
            {
                item.DatabaseType = databaseType;
            }

            _dataTypeService.Save(item);

            DeserializeUpdatePreValues(item, mappedNode);

            _dataTypeService.Save(item);
            return(SyncAttempt <IDataTypeDefinition> .Succeed(item.Name, item, ChangeType.Import));
        }
Esempio n. 3
0
        public void Updating_DataType()
        {
            const string expectedName = "An edited fancy datatype";
            var          id           = CreateAndSaveDataType().Id;

            var toUpdate = dataTypeService.GetDataTypeDefinitionById(id);

            toUpdate.Name = expectedName;
            dataTypeService.Save(toUpdate);

            var updated = dataTypeService.GetDataTypeDefinitionById(id);

            Assert.AreEqual(expectedName, updated.Name);
        }
Esempio n. 4
0
        private void UpdateHomeDocumentType()
        {
            const string
                propertyName    = "Tenant Preferences",
                dataTypeName    = "Total Code Tenant Properties",
                oldDataTypeName = "Total Tode Tenant Properties";

            try
            {
                var existingDataType = dataTypeService.GetDataType(oldDataTypeName);
                if (existingDataType != null)
                {
                    existingDataType.Name = dataTypeName;
                    dataTypeService.Save(existingDataType);

                    var container   = dataTypeService.GetContainers(CONTAINER, 1).FirstOrDefault();
                    var containerId = -1;

                    if (container != null)
                    {
                        containerId = container.Id;
                    }

                    dataTypeService.Move(existingDataType, containerId);
                    ConnectorContext.AuditService.Add(AuditType.Move, -1, existingDataType.Id, "Data Type", $"Data Type '{propertyName}' has been updated and moved");
                }
            }
            catch (System.Exception ex)
            {
                logger.Error(typeof(_16_MoveTenantPreferencesPropertyType), ex.Message);
                logger.Error(typeof(_16_MoveTenantPreferencesPropertyType), ex.StackTrace);
            }
        }
        public void Initialize()
        {
            DataTypeService.Deleting += StopFormRteDelete;

            if (_dataTypeService.GetDataType(FormRteName) != null || !_propertyEditorCollection.TryGet(Constants.PropertyEditors.Aliases.TinyMce, out var editor))
            {
                return;
            }

            var formsRTE = new DataType(editor)
            {
                Name          = FormRteName,
                Configuration = new Dictionary <string, object>
                {
                    ["editor"] = new Dictionary <string, object>
                    {
                        ["toolbar"]      = new[] { "ace", "bold", "italic", "bullist", "numlist", "link", "umbmediapicker" },
                        ["stylesheets"]  = new string[0],
                        ["maxImageSize"] = 500,
                        ["mode"]         = "classic"
                    },
                    ["hideLabel"]            = false,
                    ["ignoreUserStartNodes"] = false,
                    ["mediaParentId"]        = null
                }
            };

            _dataTypeService.Save(formsRTE);
        }
Esempio n. 6
0
        private void Synchronize(IDataTypeDefinition[] dataTypes, DataType model)
        {
            var dataType = _dataTypeFinder.Find(model, dataTypes).SingleOrDefault();

            if (dataType == null)
            {
                // Create new data type.
                dataType = CreateDataType(model);

                _dataTypeService.SaveDataTypeAndPreValues(dataType, GetPreValues(model));
            }
            else
            {
                // Update the data type and its pre-values.
                _dataTypeService.Save(UpdateDataTypeDefinition(dataType, model));

                var existingPreValues = _dataTypeService.GetPreValuesCollectionByDataTypeId(dataType.Id).FormatAsDictionary();

                var preValuesToSave = existingPreValues.Any()
                    ? GetUpdatedPreValues(existingPreValues, model.PreValues)
                    : GetPreValues(model);

                _dataTypeService.SavePreValues(dataType.Id, preValuesToSave);
            }

            // We get the data type once more to refresh it after saving it.
            dataType = _dataTypeService.GetDataTypeDefinitionByName(dataType.Name);

            // Set/update tracking.
            SetDataTypeId(model, dataType);
        }
Esempio n. 7
0
        /// <summary>
        /// Convert ContentPickerAlias data types with the given name
        ///
        /// Converts the content from ids to UDIs
        /// Swaps the data type alias itself over
        /// </summary>
        /// <param name="name"></param>
        public void Convert(string name)
        {
            var oldDataTypeDefinition = _dataTypeService.GetDataTypeDefinitionByName(name);

            oldDataTypeDefinition.Name = oldDataTypeDefinition.Name + " (Obsolete)";
            _dataTypeService.Save(oldDataTypeDefinition);

            var oldPreValues = _dataTypeService.GetPreValuesCollectionByDataTypeId(oldDataTypeDefinition.Id);

            var newDataTypeDefinition = new DataTypeDefinition(_newDataTypeAlias);

            newDataTypeDefinition.Name = name;
            _dataTypeService.SaveDataTypeAndPreValues(newDataTypeDefinition, _preValueConversion == null ? new Dictionary <string, PreValue>() : _preValueConversion(oldPreValues.PreValuesAsDictionary));

            var allContentTypes       = _contentTypeService.GetAllContentTypes();
            var contentTypesToConvert = allContentTypes
                                        .Where(c =>
                                               c.PropertyTypes.Any(a => a.DataTypeDefinitionId == oldDataTypeDefinition.Id) ||
                                               c.CompositionPropertyTypes.Any(a => a.DataTypeDefinitionId == oldDataTypeDefinition.Id))
                                        .ToArray();

            AddReplacementDataType(contentTypesToConvert, oldDataTypeDefinition, newDataTypeDefinition);
            ConvertContent(contentTypesToConvert, oldDataTypeDefinition);
            DeleteOldDataType(oldDataTypeDefinition);
        }
Esempio n. 8
0
        /// <summary>
        /// Creates a custom list view - give a document type alias
        /// </summary>
        /// <param name="contentTypeAlias"></param>
        /// <returns></returns>
        public DataTypeDisplay PostCreateCustomListView(string contentTypeAlias)
        {
            var dt = _dataTypeService.GetDataType(Constants.Conventions.DataTypes.ListViewPrefix + contentTypeAlias);

            //if it doesn't exist yet, we will create it.
            if (dt == null)
            {
                var editor = _propertyEditors[Constants.PropertyEditors.Aliases.ListView];
                dt = new DataType(editor, _serializer)
                {
                    Name = Constants.Conventions.DataTypes.ListViewPrefix + contentTypeAlias
                };
                _dataTypeService.Save(dt);
            }

            return(_umbracoMapper.Map <IDataType, DataTypeDisplay>(dt));
        }
Esempio n. 9
0
        public IDataTypeDefinition Create(string name, string propertyEditorAlias, int parentId,
                                          DataTypeDatabaseType databaseType, IDictionary <string, string> preValues)
        {
            if (Exists(name))
            {
                return(null);
            }

            var dataType = new DataTypeDefinition(propertyEditorAlias)
            {
                Name         = name,
                DatabaseType = databaseType,
            };

            if (parentId > 0)
            {
                dataType.ParentId = parentId;
            }

            _dataTypeService.Save(dataType);

            var itemPreValues = _dataTypeService.GetPreValuesCollectionByDataTypeId(dataType.Id)
                                .FormatAsDictionary();


            foreach (var preValue in preValues)
            {
                LogHelper.Info <DataTypeBuilder>("PreValue: {0} [{1}]", () => preValue.Key, () => preValue.Value);

                if (itemPreValues.ContainsKey(preValue.Key))
                {
                    LogHelper.Info <DataTypeBuilder>("Update");
                    itemPreValues[preValue.Key].Value = preValue.Value;
                }
                else
                {
                    LogHelper.Info <DataTypeBuilder>("Add");
                    itemPreValues.Add(preValue.Key, new PreValue(preValue.Value));
                }
            }

            _dataTypeService.SavePreValues(dataType, itemPreValues);
            _dataTypeService.Save(dataType);

            return(dataType);
        }
    public void MemberTypeSave_To_IMemberType()
    {
        // Arrange
        // TODO use builder
        var dataType = new DataType(Services.GetRequiredService <LabelPropertyEditor>(), _serializer)
        {
            Name = "TODO"
        };

        _dataTypeService.Save(dataType);

        var display = CreateMemberTypeSave(dataType.Id);

        // Act
        var result = _sut.Map <IMemberType>(display);

        // Assert
        Assert.AreEqual(display.Alias, result.Alias);
        Assert.AreEqual(display.Description, result.Description);
        Assert.AreEqual(display.Icon, result.Icon);
        Assert.AreEqual(display.Id, result.Id);
        Assert.AreEqual(display.Name, result.Name);
        Assert.AreEqual(display.ParentId, result.ParentId);
        Assert.AreEqual(display.Path, result.Path);
        Assert.AreEqual(display.Thumbnail, result.Thumbnail);
        Assert.AreEqual(display.IsContainer, result.IsContainer);
        Assert.AreEqual(display.AllowAsRoot, result.AllowedAsRoot);
        Assert.AreEqual(display.CreateDate, result.CreateDate);
        Assert.AreEqual(display.UpdateDate, result.UpdateDate);

        // TODO: Now we need to assert all of the more complicated parts
        Assert.AreEqual(display.Groups.Count(), result.PropertyGroups.Count);
        for (var i = 0; i < display.Groups.Count(); i++)
        {
            Assert.AreEqual(display.Groups.ElementAt(i).Id, result.PropertyGroups.ElementAt(i).Id);
            Assert.AreEqual(display.Groups.ElementAt(i).Name, result.PropertyGroups.ElementAt(i).Name);
            var propTypes = display.Groups.ElementAt(i).Properties;
            Assert.AreEqual(propTypes.Count(), result.PropertyTypes.Count());
            for (var j = 0; j < propTypes.Count(); j++)
            {
                Assert.AreEqual(propTypes.ElementAt(j).Id, result.PropertyTypes.ElementAt(j).Id);
                Assert.AreEqual(propTypes.ElementAt(j).DataTypeId, result.PropertyTypes.ElementAt(j).DataTypeId);
                Assert.AreEqual(propTypes.ElementAt(j).MemberCanViewProperty, result.MemberCanViewProperty(result.PropertyTypes.ElementAt(j).Alias));
                Assert.AreEqual(propTypes.ElementAt(j).MemberCanEditProperty, result.MemberCanEditProperty(result.PropertyTypes.ElementAt(j).Alias));
                Assert.AreEqual(propTypes.ElementAt(j).IsSensitiveData, result.IsSensitiveProperty(result.PropertyTypes.ElementAt(j).Alias));
            }
        }

        Assert.AreEqual(display.AllowedContentTypes.Count(), result.AllowedContentTypes.Count());
        for (var i = 0; i < display.AllowedContentTypes.Count(); i++)
        {
            Assert.AreEqual(display.AllowedContentTypes.ElementAt(i), result.AllowedContentTypes.ElementAt(i).Id.Value);
        }
    }
Esempio n. 11
0
        private int?CreateDataType(Item item, int parentId, int userId = 0)
        {
            var dataType = new DataTypeDefinition(parentId, "Umbraco.ContentPicker2");

            dataType.Name = item.Name;
            //need to create content in order to select start node

            var ttt = _dataTypeService.GetAllDataTypeDefinitions();

            _dataTypeService.Save(dataType);

            return(dataType.Id);
        }
Esempio n. 12
0
        /// <summary>
        /// Imports and saves package xml as <see cref="IDataTypeDefinition"/>
        /// </summary>
        /// <param name="element">Xml to import</param>
        /// <param name="userId"></param>
        /// <returns>An enumrable list of generated DataTypeDefinitions</returns>
        public IEnumerable <IDataTypeDefinition> ImportDataTypeDefinitions(XElement element, int userId = 0)
        {
            var name = element.Name.LocalName;

            if (name.Equals("DataTypes") == false && name.Equals("DataType") == false)
            {
                throw new ArgumentException("The passed in XElement is not valid! It does not contain a root element called 'DataTypes' for multiple imports or 'DataType' for a single import.");
            }

            var dataTypes        = new Dictionary <string, IDataTypeDefinition>();
            var dataTypeElements = name.Equals("DataTypes")
                                       ? (from doc in element.Elements("DataType") select doc).ToList()
                                       : new List <XElement> {
                element.Element("DataType")
            };

            foreach (var dataTypeElement in dataTypeElements)
            {
                var dataTypeDefinitionName = dataTypeElement.Attribute("Name").Value;
                var dataTypeId             = new Guid(dataTypeElement.Attribute("Id").Value);
                var dataTypeDefinitionId   = new Guid(dataTypeElement.Attribute("Definition").Value);
                var databaseTypeAttribute  = dataTypeElement.Attribute("DatabaseType");

                var definition = _dataTypeService.GetDataTypeDefinitionById(dataTypeDefinitionId);
                //If the datatypedefinition doesn't already exist we create a new new according to the one in the package xml
                if (definition == null)
                {
                    var databaseType = databaseTypeAttribute != null
                                           ? databaseTypeAttribute.Value.EnumParse <DataTypeDatabaseType>(true)
                                           : DataTypeDatabaseType.Ntext;

                    var dataTypeDefinition = new DataTypeDefinition(-1, dataTypeId)
                    {
                        Key          = dataTypeDefinitionId,
                        Name         = dataTypeDefinitionName,
                        DatabaseType = databaseType
                    };
                    dataTypes.Add(dataTypeDefinitionName, dataTypeDefinition);
                }
            }

            var list = dataTypes.Select(x => x.Value).ToList();

            if (list.Any())
            {
                _dataTypeService.Save(list, userId);

                SavePrevaluesFromXml(list, dataTypeElements);
            }
            return(list);
        }
Esempio n. 13
0
        private void Synchronize(IDataTypeDefinition[] dataTypes, DataType model)
        {
            var dataType = _dataTypeFinder.Find(model, dataTypes).SingleOrDefault();

            dataType = dataType == null
                ? CreateDataType(model)
                : UpdateDataTypeDefinition(dataType, model);

            _dataTypeService.Save(dataType);

            // We get the data type once more to refresh it after saving it.
            dataType = _dataTypeService.GetDataTypeDefinitionByName(dataType.Name);

            // Set the pre-values, if any.
            SetDataTypePreValues(dataType, model);

            // Set/update tracking.
            SetDataTypeId(model, dataType);
        }
Esempio n. 14
0
        public static Attempt <string> Copy(this IDataTypeService service, IDataType dataType, EntityContainer parent)
        {
            if (dataType == null)
            {
                return(Attempt.Fail(string.Empty, new NullReferenceException("Data Type Not Found")));
            }

            var clone = (IDataType)dataType.DeepClone();

            clone.Id  = 0;
            clone.Key = Guid.Empty;

            if (parent != null)
            {
                clone.SetParent(parent);
            }

            service.Save(clone);

            return(Attempt.Succeed(clone.Path));
        }
Esempio n. 15
0
        private void CreateExampleBlockDataType(string contentTypeAlias, Guid dataTypeKey)
        {
            if (_dataTypeService.GetDataType(dataTypeKey) != null)
            {
                // Already there
                return;
            }

            if (!(_propertyEditors.TryGet("Umbraco.NestedContent", out var editor) && editor is NestedContentPropertyEditor nestedContentEditor))
            {
                throw new InvalidOperationException("Nested Content property editor not found!");
            }

            var dataType = new DataType(nestedContentEditor, -1)
            {
                Name          = "Perplex.ContentBlocks - ExampleBlock",
                Key           = dataTypeKey,
                Configuration = new NestedContentConfiguration
                {
                    ConfirmDeletes = false,
                    HideLabel      = true,
                    MinItems       = 1,
                    MaxItems       = 1,
                    ShowIcons      = false,
                    ContentTypes   = new[]
                    {
                        new NestedContentConfiguration.ContentType
                        {
                            Alias    = contentTypeAlias,
                            TabAlias = "Content",
                            Template = "{{title}}"
                        }
                    }
                }
            };

            _dataTypeService.Save(dataType);
        }
        private void UpdateDocumentType()
        {
            const string
                propertyAlias       = "bannerSlider",
                propertyName        = "Banner Slider",
                propertyDescription = "Slider with banner images";

            try
            {
                #region Nested Document Type
                var container   = contentTypeService.GetContainers(DOCUMENT_TYPE_CONTAINER, 1).FirstOrDefault();
                int containerId = -1;

                if (container != null)
                {
                    containerId = container.Id;
                }

                var contentType = contentTypeService.Get(NESTED_DOCUMENT_TYPE_ALIAS);
                if (contentType == null)
                {
                    ContentType docType = (ContentType)contentType ?? new ContentType(containerId)
                    {
                        Name          = NESTED_DOCUMENT_TYPE_NAME,
                        Alias         = NESTED_DOCUMENT_TYPE_ALIAS,
                        AllowedAsRoot = false,
                        Description   = NESTED_DOCUMENT_TYPE_DESCRIPTION,
                        Icon          = NESTED_DOCUMENT_TYPE_ICON,
                        IsElement     = true,
                        SortOrder     = 0,
                        ParentId      = contentTypeService.Get(NESTED_DOCUMENT_TYPE_PARENT_ALIAS).Id,
                        Variations    = ContentVariation.Culture
                    };

                    docType.AddPropertyGroup(SLIDERS_TAB);

                    #region Nested Document Type Properties
                    PropertyType ImagePropType = new PropertyType(dataTypeService.GetDataType(-88), "sliderItemImage")
                    {
                        Name        = "Image",
                        Description = "Image used in the Slider",
                        Variations  = ContentVariation.Nothing
                    };
                    docType.AddPropertyType(ImagePropType, SLIDERS_TAB);

                    PropertyType ButtonLabelPropType = new PropertyType(dataTypeService.GetDataType(-88), "sliderItemButtonLabel")
                    {
                        Name        = " Button Label",
                        Description = "Label for the Button",
                        Variations  = ContentVariation.Nothing
                    };
                    docType.AddPropertyType(ButtonLabelPropType, SLIDERS_TAB);

                    PropertyType TitlePropType = new PropertyType(dataTypeService.GetDataType(-88), "sliderItemTitle")
                    {
                        Name        = "Title",
                        Description = "Title for the banner item",
                        Variations  = ContentVariation.Nothing
                    };
                    docType.AddPropertyType(TitlePropType, SLIDERS_TAB);

                    PropertyType SubtitlePropType = new PropertyType(dataTypeService.GetDataType(-88), "sliderItemSubtitle")
                    {
                        Name        = "Subtitle",
                        Description = "Subtitle for the banner item",
                        Variations  = ContentVariation.Nothing
                    };
                    docType.AddPropertyType(SubtitlePropType, SLIDERS_TAB);

                    PropertyType UrlPropType = new PropertyType(dataTypeService.GetDataType(-88), "sliderItemUrl")
                    {
                        Name        = "Url",
                        Description = "The Link to the item",
                        Variations  = ContentVariation.Nothing
                    };
                    docType.AddPropertyType(UrlPropType, SLIDERS_TAB);
                    #endregion

                    contentTypeService.Save(docType);
                    ConnectorContext.AuditService.Add(AuditType.New, -1, docType.Id, "Document Type", $"Document Type '{NESTED_DOCUMENT_TYPE_ALIAS}' has been created");
                }

                else
                {
                    if (contentType.PropertyTypeExists("sliderItemImage") && contentType.PropertyTypes.Single(x => x.Alias == "sliderItemImage").DataTypeId == -88)
                    {
                        var mediaPickerContainer   = dataTypeService.GetContainers(DATA_TYPE_CONTAINER, 1).FirstOrDefault();
                        var mediaPickerContainerId = -1;

                        if (mediaPickerContainer != null)
                        {
                            mediaPickerContainerId = mediaPickerContainer.Id;
                        }

                        var dataTypeExists = dataTypeService.GetDataType("sliderItemImageMediaPicker") != null;
                        if (!dataTypeExists)
                        {
                            var created = Web.Composing.Current.PropertyEditors.TryGet("Umbraco.MediaPicker", out IDataEditor editor);
                            if (created)
                            {
                                DataType mediaPickerSliderImage = new DataType(editor, mediaPickerContainerId)
                                {
                                    Name          = "sliderItemImageMediaPicker",
                                    ParentId      = mediaPickerContainerId,
                                    Configuration = new MediaPickerConfiguration
                                    {
                                        DisableFolderSelect = true,
                                        Multiple            = false,
                                        OnlyImages          = true
                                    }
                                };
                                dataTypeService.Save(mediaPickerSliderImage);
                                contentType.PropertyTypes.Single(x => x.Alias == "sliderItemImage").DataTypeId = mediaPickerSliderImage.Id;
                                contentTypeService.Save(contentType);
                            }
                        }
                    }
                }
                #endregion

                #region Update Home Document Type
                var homeDocumentType = contentTypeService.Get(DOCUMENT_TYPE_ALIAS);

                var dataTypeContainer   = dataTypeService.GetContainers(DATA_TYPE_CONTAINER, 1).FirstOrDefault();
                var dataTypeContainerId = -1;

                if (dataTypeContainer != null)
                {
                    dataTypeContainerId = dataTypeContainer.Id;
                }

                var exists = dataTypeService.GetDataType(propertyName) != null;
                if (!exists)
                {
                    var created = Web.Composing.Current.PropertyEditors.TryGet("Umbraco.NestedContent", out IDataEditor editor);
                    if (!created)
                    {
                        DataType bannerSliderNestedDataType = new DataType(editor, dataTypeContainerId)
                        {
                            Name          = propertyName,
                            ParentId      = dataTypeContainerId,
                            Configuration = new NestedContentConfiguration
                            {
                                MinItems       = 0,
                                MaxItems       = 999,
                                ConfirmDeletes = true,
                                HideLabel      = false,
                                ShowIcons      = true,
                                ContentTypes   = new[]
                                {
                                    new NestedContentConfiguration.ContentType {
                                        Alias = NESTED_DOCUMENT_TYPE_ALIAS, TabAlias = SLIDERS_TAB
                                    }
                                }
                            }
                        };
                        dataTypeService.Save(bannerSliderNestedDataType);
                    }
                }
                if (!homeDocumentType.PropertyTypeExists("bannerSlider"))
                {
                    var          bannerSliderNestedDataType = dataTypeService.GetDataType(propertyName);
                    PropertyType BannerSlider = new PropertyType(bannerSliderNestedDataType, propertyAlias)
                    {
                        Name        = propertyName,
                        Description = propertyDescription,
                        Variations  = ContentVariation.Culture
                    };

                    var propertyGroup = homeDocumentType.PropertyGroups.SingleOrDefault(x => x.Name == SLIDERS_TAB);
                    if (propertyGroup == null)
                    {
                        homeDocumentType.AddPropertyGroup(SLIDERS_TAB);
                    }

                    homeDocumentType.AddPropertyType(BannerSlider, SLIDERS_TAB);
                    contentTypeService.Save(homeDocumentType);

                    ConnectorContext.AuditService.Add(AuditType.Save, -1, homeDocumentType.Id, "Document Type", $"Document Type '{DOCUMENT_TYPE_ALIAS}' has been updated");
                }

                #endregion
            }
            catch (System.Exception ex)
            {
                logger.Error(typeof(_17_HomeDocumentTypeSlider), ex.Message);
                logger.Error(typeof(_17_HomeDocumentTypeSlider), ex.StackTrace);
            }
        }
        public override PipelineResult <InstallPipelineContext> Execute(PipelineArgs <InstallPipelineContext> args)
        {
            // Theme Color Picker
            var currentColorPicker = _dataTypeService.GetDataType(VendrCheckoutConstants.DataTypes.Guids.ThemeColorPickerGuid);

            if (currentColorPicker == null)
            {
                if (_propertyEditors.TryGet(Constants.PropertyEditors.Aliases.ColorPicker, out IDataEditor editor))
                {
                    var dataType = CreateDataType(editor, x =>
                    {
                        x.Key           = VendrCheckoutConstants.DataTypes.Guids.ThemeColorPickerGuid;
                        x.Name          = "[Vendr Checkout] Theme Color Picker";
                        x.DatabaseType  = ValueStorageType.Nvarchar;
                        x.Configuration = new ColorPickerConfiguration
                        {
                            Items = VendrCheckoutConstants.ColorMap.Select((kvp, idx) => new ValueListConfiguration.ValueListItem
                            {
                                Id    = idx,
                                Value = "{\"value\":\"" + kvp.Key + "\", \"label\":\"" + kvp.Value + "\"}"
                            }).ToList(),
                            UseLabel = false
                        };
                    });

                    _dataTypeService.Save(dataType);
                }
            }
            else
            {
                currentColorPicker.Configuration = new ColorPickerConfiguration
                {
                    Items = VendrCheckoutConstants.ColorMap.Select((kvp, idx) => new ValueListConfiguration.ValueListItem
                    {
                        Id    = idx,
                        Value = "{\"value\":\"" + kvp.Key + "\", \"label\":\"" + kvp.Value + "\"}"
                    }).ToList(),
                    UseLabel = false
                };

                _dataTypeService.Save(currentColorPicker);
            }

            // Step Picker
            var stepPickerItems = new List <ValueListConfiguration.ValueListItem>
            {
                new ValueListConfiguration.ValueListItem {
                    Id = 1, Value = "Information"
                },
                new ValueListConfiguration.ValueListItem {
                    Id = 2, Value = "ShippingMethod"
                },
                new ValueListConfiguration.ValueListItem {
                    Id = 3, Value = "PaymentMethod"
                },
                new ValueListConfiguration.ValueListItem {
                    Id = 4, Value = "Review"
                },
                new ValueListConfiguration.ValueListItem {
                    Id = 5, Value = "Payment"
                },
                new ValueListConfiguration.ValueListItem {
                    Id = 6, Value = "Confirmation"
                }
            };

            var currentStepPicker = _dataTypeService.GetDataType(VendrCheckoutConstants.DataTypes.Guids.StepPickerGuid);

            if (currentStepPicker == null)
            {
                if (_propertyEditors.TryGet(Constants.PropertyEditors.Aliases.DropDownListFlexible, out IDataEditor editor))
                {
                    var dataType = CreateDataType(editor, x =>
                    {
                        x.Key           = VendrCheckoutConstants.DataTypes.Guids.StepPickerGuid;
                        x.Name          = "[Vendr Checkout] Step Picker";
                        x.DatabaseType  = ValueStorageType.Nvarchar;
                        x.Configuration = new DropDownFlexibleConfiguration
                        {
                            Items    = stepPickerItems,
                            Multiple = false
                        };
                    });

                    _dataTypeService.Save(dataType);
                }
            }
            else
            {
                currentStepPicker.Configuration = new DropDownFlexibleConfiguration
                {
                    Items    = stepPickerItems,
                    Multiple = false
                };

                _dataTypeService.Save(currentStepPicker);
            }

            // Continue the pipeline
            return(Ok());
        }
        private void Reconfigure()
        {
            const string
                propertyAlias       = "gameSlider",
                propertyName        = "Game Slider",
                propertyDescription = "Slider with game banners";

            try
            {
                var casinoDocType = contentTypeService.Get(DOCUMENT_TYPE_ALIAS);
                // Create the Template if it doesn't exist
                if (fileService.GetTemplate(TEMPLATE_ALIAS) == null)
                {
                    //then create the template
                    Template  newTemplate    = new Template(TEMPLATE_NAME, TEMPLATE_ALIAS);
                    ITemplate masterTemplate = fileService.GetTemplate(PARENT_TEMPLATE_ALIAS);
                    newTemplate.SetMasterTemplate(masterTemplate);
                    fileService.SaveTemplate(newTemplate);

                    // Set template for document type
                    casinoDocType.AddTemplate(contentTypeService, newTemplate);

                    ContentHelper.CopyPhysicalAssets(new ReconfigureCasinoPageEmbeddedResources());

                    ConnectorContext.AuditService.Add(AuditType.Save, -1, newTemplate.Id, "Template", $"Teplate '{TEMPLATE_NAME}' has been created and assigned");
                }

                var dataTypeContainer   = dataTypeService.GetContainers(DATA_TYPE_CONTAINER, 1).FirstOrDefault();
                var dataTypeContainerId = -1;

                if (dataTypeContainer != null)
                {
                    dataTypeContainerId = dataTypeContainer.Id;
                }
                var exists = dataTypeService.GetDataType(propertyName) != null;
                if (!exists)
                {
                    var created = Web.Composing.Current.PropertyEditors.TryGet("Umbraco.NestedContent", out IDataEditor editor);
                    if (created)
                    {
                        DataType bannerSliderNestedDataType = new DataType(editor, dataTypeContainerId)
                        {
                            Name          = propertyName,
                            ParentId      = dataTypeContainerId,
                            Configuration = new NestedContentConfiguration
                            {
                                MinItems       = 0,
                                MaxItems       = 999,
                                ConfirmDeletes = true,
                                HideLabel      = false,
                                ShowIcons      = true,
                                ContentTypes   = new[]
                                {
                                    new NestedContentConfiguration.ContentType {
                                        Alias = NESTED_DOCUMENT_TYPE_ALIAS, TabAlias = SLIDERS_TAB
                                    }
                                }
                            }
                        };
                        dataTypeService.Save(bannerSliderNestedDataType);
                        ConnectorContext.AuditService.Add(AuditType.Save, -1, casinoDocType.Id, "Document Type", $"Document Type '{DOCUMENT_TYPE_ALIAS}' has been updated");
                    }
                }
                if (!casinoDocType.PropertyTypeExists(propertyAlias))
                {
                    var          bannerSliderNestedDataType = dataTypeService.GetDataType(propertyName);
                    PropertyType BannerSlider = new PropertyType(bannerSliderNestedDataType, propertyAlias)
                    {
                        Name        = propertyName,
                        Description = propertyDescription,
                        Variations  = ContentVariation.Culture
                    };
                    casinoDocType.AddPropertyGroup(SLIDERS_TAB);
                    casinoDocType.AddPropertyType(BannerSlider, SLIDERS_TAB);
                    contentTypeService.Save(casinoDocType);
                }
            }

            catch (Exception ex)
            {
                logger.Error(typeof(_10_CasinoPageIntegration), ex.Message);
                logger.Error(typeof(_10_CasinoPageIntegration), ex.StackTrace);
            }
        }
        public void Initialize()
        {
            try
            {
                var homeDocType = _contentTypeService.Get(DOCUMENT_TYPE_ALIAS);
                if (!homeDocType.PropertyTypeExists(HOME_SPINNER_PROPERTY_ALIAS))
                {
                    PropertyType spinner = new PropertyType(_dataTypeService.GetDataType(SPINNER_PROPERTY_TYPE_NAME), HOME_SPINNER_PROPERTY_ALIAS)
                    {
                        Name        = HOME_SPINNER_PROPERTY_NAME,
                        Description = HOME_SPINNER_PROPERTY_DESCRIPTION,
                        Variations  = ContentVariation.Culture
                    };
                    homeDocType.AddPropertyType(spinner, TAB_NAME);
                    _contentTypeService.Save(homeDocType);
                }

                var imgCropper = _dataTypeService.GetDataType(IMAGE_CROPPER_PROPERTY_TYPE_NAME);
                if (imgCropper != null)
                {
                    if (imgCropper.Configuration is Umbraco.Core.PropertyEditors.ImageCropperConfiguration)
                    {
                        var imageCropperConfiguration = (Umbraco.Core.PropertyEditors.ImageCropperConfiguration)imgCropper.Configuration;

                        if (imageCropperConfiguration == null)
                        {
                            imageCropperConfiguration = new Umbraco.Core.PropertyEditors.ImageCropperConfiguration()
                            {
                                Crops = new Core.PropertyEditors.ImageCropperConfiguration.Crop[0]
                            };
                        }

                        if (imageCropperConfiguration.Crops == null)
                        {
                            imageCropperConfiguration.Crops = new Core.PropertyEditors.ImageCropperConfiguration.Crop[0];
                        }

                        if (imageCropperConfiguration.Crops.FirstOrDefault(p => p.Alias == FORM_IMAGE_CROPPER_ALIAS) == null)
                        {
                            var crops = new List <Core.PropertyEditors.ImageCropperConfiguration.Crop>();
                            crops.AddRange(imageCropperConfiguration.Crops);
                            crops.Add(new Core.PropertyEditors.ImageCropperConfiguration.Crop()
                            {
                                Alias  = FORM_IMAGE_CROPPER_ALIAS,
                                Height = FORM_IMAGE_CROPPER_ALIAS_HEIGHT,
                                Width  = FORM_IMAGE_CROPPER_ALIAS_WIDTH
                            });
                            imageCropperConfiguration.Crops = crops.ToArray();

                            _dataTypeService.Save(imgCropper);

                            _logger.Info(typeof(_38_HomeDocumentTypeSpinner), $"{IMAGE_CROPPER_PROPERTY_TYPE_NAME} Alias saved: {JsonConvert.SerializeObject(imageCropperConfiguration.Crops)}");
                        }
                        else
                        {
                            _logger.Info(typeof(_38_HomeDocumentTypeSpinner), $"{IMAGE_CROPPER_PROPERTY_TYPE_NAME} Alias {FORM_IMAGE_CROPPER_ALIAS} Already Exists");
                        }
                    }
                    else
                    {
                        _logger.Info(typeof(_38_HomeDocumentTypeSpinner), $"Invalid type for imgCropper.Configuration TYPE: {imgCropper.Configuration.GetType()}");
                    }
                }
                else
                {
                    _logger.Info(typeof(_38_HomeDocumentTypeSpinner), $"Datatype {IMAGE_CROPPER_PROPERTY_TYPE_NAME} Not Found");
                }
            }
            catch (System.Exception ex)
            {
                _logger.Error(typeof(_38_HomeDocumentTypeSpinner), ex.Message);
                _logger.Error(typeof(_38_HomeDocumentTypeSpinner), ex.StackTrace);
            }
        }
        public void Initialize()
        {
            try
            {
                var contentType = contentTypeService.Get(DOCUMENT_TYPE_ALIAS);

                if (contentType == null)
                {
                    return;
                }

                if (!contentType.PropertyGroups.Any(x => x.Name == NOTIFICATION_SETTINGS_TAB))
                {
                    contentType.AddPropertyGroup(NOTIFICATION_SETTINGS_TAB);
                }

                const string ddlNotificationPositions = "ddl Notification Positions";

                var dataTypeContainer   = dataTypeService.GetContainers(DATA_TYPE_CONTAINER, 1).FirstOrDefault();
                var dataTypeContainerId = -1;

                if (dataTypeContainer != null)
                {
                    dataTypeContainerId = dataTypeContainer.Id;
                }
                var exists = dataTypeService.GetDataType(ddlNotificationPositions) != null;
                if (!exists)
                {
                    var created = Web.Composing.Current.PropertyEditors.TryGet("Umbraco.DropDown.Flexible", out IDataEditor editor);
                    if (editor != null)
                    {
                        var positionList = new List <ValueListConfiguration.ValueListItem>();
                        positionList.Add(new ValueListConfiguration.ValueListItem {
                            Id = 1, Value = "Top Right"
                        });
                        positionList.Add(new ValueListConfiguration.ValueListItem {
                            Id = 2, Value = "Bottom Right"
                        });
                        positionList.Add(new ValueListConfiguration.ValueListItem {
                            Id = 3, Value = "Bottom Left"
                        });
                        positionList.Add(new ValueListConfiguration.ValueListItem {
                            Id = 4, Value = "Top Left"
                        });
                        positionList.Add(new ValueListConfiguration.ValueListItem {
                            Id = 5, Value = "Top Center"
                        });
                        positionList.Add(new ValueListConfiguration.ValueListItem {
                            Id = 6, Value = "Bottom Center"
                        });

                        DataType ddlNotificationPositionsDataType = new DataType(editor, dataTypeContainerId)
                        {
                            Name          = ddlNotificationPositions,
                            ParentId      = dataTypeContainerId,
                            Configuration = new DropDownFlexibleConfiguration()
                            {
                                Multiple = false,
                                Items    = positionList
                            }
                        };
                        dataTypeService.Save(ddlNotificationPositionsDataType);
                    }
                }
                var isNewPropertyAdded = false;
                if (!contentType.PropertyTypeExists("notificationPosition"))
                {
                    isNewPropertyAdded = true;
                    var ddlPositionsDataType = dataTypeService.GetDataType(ddlNotificationPositions);

                    PropertyType ddlPositionsPropType = new PropertyType(ddlPositionsDataType, "notificationPosition")
                    {
                        Name       = "Position",
                        Variations = ContentVariation.Culture
                    };
                    contentType.AddPropertyType(ddlPositionsPropType, NOTIFICATION_SETTINGS_TAB);
                }

                if (!contentType.PropertyTypeExists("notificationBgColor"))
                {
                    isNewPropertyAdded = true;
                    PropertyType notificationBackgroundColor = new PropertyType(dataTypeService.GetDataType(6018), "notificationBgColor")
                    {
                        Name       = "Background Color",
                        Variations = ContentVariation.Culture
                    };
                    contentType.AddPropertyType(notificationBackgroundColor, NOTIFICATION_SETTINGS_TAB);
                }

                if (!contentType.PropertyTypeExists("notificationWidth"))
                {
                    isNewPropertyAdded = true;
                    PropertyType widthPropType = new PropertyType(dataTypeService.GetDataType(-88), "notificationWidth")
                    {
                        Name        = "Width",
                        Description = "If required enter only numeric value",
                        Variations  = ContentVariation.Culture
                    };
                    contentType.AddPropertyType(widthPropType, NOTIFICATION_SETTINGS_TAB);
                }

                if (isNewPropertyAdded)
                {
                    contentTypeService.Save(contentType);
                    ConnectorContext.AuditService.Add(AuditType.New, -1, contentType.Id, "Document Type", $"Document Type '{DOCUMENT_TYPE_ALIAS}' has been updated");
                }
            }

            catch (Exception ex)
            {
                logger.Error(typeof(_39_HomeDocTypeNotificationSettings), ex.Message);
                logger.Error(typeof(_39_HomeDocTypeNotificationSettings), ex.StackTrace);
            }
        }
Esempio n. 21
0
 public IDataType Save()
 {
     DataTypeService.Save(DataTypeDefinition);
     return(this);
 }
Esempio n. 22
0
 protected override void SaveItem(IDataType item)
 => dataTypeService.Save(item);
Esempio n. 23
0
        private void Reconfigure()
        {
            try
            {
                var oldControlAlias = "links";
                var contentType     = contentTypeService.Get(DOCUMENT_TYPE_ALIAS);

                if (contentType == null)
                {
                    return;
                }

                if (!contentType.PropertyTypeExists(oldControlAlias))
                {
                    return;
                }


                var MNTPpropertyName          = "Total Code MNTP Menu - Single Site";
                var NestedContentPropertyName = "Nested Content Footer Link Group";

                var dataTypeContainer   = dataTypeService.GetContainers(DATA_TYPE_CONTAINER, 1).FirstOrDefault();
                var dataTypeContainerId = -1;

                if (dataTypeContainer != null)
                {
                    dataTypeContainerId = dataTypeContainer.Id;
                }

                var exists = dataTypeService.GetDataType(MNTPpropertyName) != null;
                if (!exists)
                {
                    var created = Web.Composing.Current.PropertyEditors.TryGet("Umbraco.MultiNodeTreePicker", out IDataEditor editor);
                    if (editor != null)
                    {
                        DataType MNTPMenu_SingleSite = new DataType(editor, dataTypeContainerId)
                        {
                            Name          = MNTPpropertyName,
                            ParentId      = dataTypeContainerId,
                            Configuration = new MultiNodePickerConfiguration()
                            {
                                MaxNumber  = 1,
                                MinNumber  = 1,
                                ShowOpen   = false,
                                TreeSource = new MultiNodePickerConfigurationTreeSource()
                                {
                                    StartNodeQuery = "$site",
                                    ObjectType     = "content"
                                },
                            }
                        };
                        dataTypeService.Save(MNTPMenu_SingleSite);
                    }
                }


                var container   = contentTypeService.GetContainers(DOCUMENT_TYPE_CONTAINER, 1).FirstOrDefault();
                int containerId = -1;

                if (container != null)
                {
                    containerId = container.Id;
                }

                contentType = contentTypeService.Get(NESTED_FOOTERLINKSSETTING_DOCUMENT_TYPE_ALIAS);
                if (contentType == null)
                {
                    ContentType docType = (ContentType)contentType ?? new ContentType(containerId)
                    {
                        Name          = NESTED_FOOTERLINKSSETTING_DOCUMENT_TYPE_NAME,
                        Alias         = NESTED_FOOTERLINKSSETTING_DOCUMENT_TYPE_ALIAS,
                        AllowedAsRoot = false,
                        Description   = "",
                        Icon          = NESTED_DOCUMENT_TYPE_ICON,
                        IsElement     = true,
                        SortOrder     = 0,
                        ParentId      = 1087,
                        Variations    = ContentVariation.Culture
                    };

                    docType.AddPropertyGroup(NESTED_TAB_NAME);

                    #region Nested Document Type Properties

                    var          FooterContent_MNTPpropertyName = dataTypeService.GetDataType(MNTPpropertyName);
                    PropertyType internalLinkPropType           = new PropertyType(FooterContent_MNTPpropertyName, "internalLink")
                    {
                        Name        = "Internal Link",
                        Description = "",
                        Variations  = ContentVariation.Culture
                    };
                    docType.AddPropertyType(internalLinkPropType, NESTED_TAB_NAME);

                    PropertyType ExternalLinkTextPropType = new PropertyType(dataTypeService.GetDataType(-88), "externalLinkText")
                    {
                        Name        = "External Link Text",
                        Description = "",
                        Variations  = ContentVariation.Culture,
                    };
                    docType.AddPropertyType(ExternalLinkTextPropType, NESTED_TAB_NAME);

                    PropertyType LinkUrlPropType = new PropertyType(dataTypeService.GetDataType(-88), "externalLinkUrl")
                    {
                        Name             = "External Link URL",
                        Description      = "",
                        Variations       = ContentVariation.Culture,
                        ValidationRegExp = "https?://[a-zA-Z0-9-.]+.[a-zA-Z]{2,}"
                    };
                    docType.AddPropertyType(LinkUrlPropType, NESTED_TAB_NAME);


                    #endregion

                    contentTypeService.Save(docType);
                    ConnectorContext.AuditService.Add(AuditType.New, -1, docType.Id, "Document Type", $"Document Type '{NESTED_FOOTERLINKSSETTING_DOCUMENT_TYPE_ALIAS}' has been created");
                }


                exists = dataTypeService.GetDataType(NestedContentPropertyName) != null;
                if (!exists)
                {
                    var created = Web.Composing.Current.PropertyEditors.TryGet("Umbraco.NestedContent", out IDataEditor editor);
                    if (editor != null)
                    {
                        DataType bannerSliderNestedDataType = new DataType(editor, dataTypeContainerId)
                        {
                            Name          = NestedContentPropertyName,
                            ParentId      = dataTypeContainerId,
                            Configuration = new NestedContentConfiguration
                            {
                                MinItems       = 0,
                                MaxItems       = 999,
                                ConfirmDeletes = true,
                                HideLabel      = false,
                                ShowIcons      = true,
                                ContentTypes   = new[]
                                {
                                    new NestedContentConfiguration.ContentType {
                                        Alias = NESTED_FOOTERLINKSSETTING_DOCUMENT_TYPE_ALIAS, TabAlias = NESTED_TAB_NAME
                                    }
                                }
                            }
                        };
                        dataTypeService.Save(bannerSliderNestedDataType);
                    }
                }
                contentType = contentTypeService.Get(DOCUMENT_TYPE_ALIAS);
                contentType.RemovePropertyType(oldControlAlias);


                var          FooterContent_NestedContentPropertyName = dataTypeService.GetDataType(NestedContentPropertyName);
                PropertyType linksPropType = new PropertyType(FooterContent_NestedContentPropertyName, "footerLinks")
                {
                    Name        = "Links",
                    Description = "",
                    Variations  = ContentVariation.Culture
                };
                contentType.AddPropertyType(linksPropType, NESTED_TAB_NAME);

                contentTypeService.Save(contentType);
                ConnectorContext.AuditService.Add(AuditType.New, -1, contentType.Id, "Document Type", $"Document Type '{DOCUMENT_TYPE_ALIAS}' has been created");
            }
            catch (Exception ex)
            {
                logger.Error(typeof(_35_FooterLinkGroupChangesDocumentType), ex.Message);
                logger.Error(typeof(_35_FooterLinkGroupChangesDocumentType), ex.StackTrace);
            }
        }
Esempio n. 24
0
        private void CreateDocumentType()
        {
            try
            {
                var richTextContainer   = dataTypeService.GetContainers(DATA_TYPE_CONTAINER, 1).FirstOrDefault();
                var richTextContainerId = -1;

                if (richTextContainer != null)
                {
                    richTextContainerId = richTextContainer.Id;
                }

                var dataTypeExists = dataTypeService.GetDataType("Full Rich Text Editor") != null;
                if (!dataTypeExists)
                {
                    var created = Web.Composing.Current.PropertyEditors.TryGet("Umbraco.TinyMCE", out IDataEditor editor);
                    if (created)
                    {
                        DataType richTextEditor = new DataType(editor, richTextContainerId)
                        {
                            Name          = "Full Rich Text Editor",
                            ParentId      = richTextContainerId,
                            Configuration = new RichTextConfiguration
                            {
                                Editor    = JObject.Parse("{\"toolbar\":[\"ace\",\"removeformat\",\"undo\",\"redo\",\"cut\",\"copy\",\"paste\",\"styleselect\",\"bold\",\"italic\",\"underline\",\"strikethrough\",\"alignleft\",\"aligncenter\",\"alignright\",\"alignjustify\",\"bullist\",\"numlist\",\"outdent\",\"indent\",\"link\",\"unlink\",\"anchor\",\"umbmediapicker\",\"umbmacro\",\"table\",\"umbembeddialog\",\"hr\",\"subscript\",\"superscript\",\"charmap\",\"rtl\",\"ltr\"],\"stylesheets\":[],\"maxImageSize\":500,\"mode\":\"classic\"}"),
                                HideLabel = true
                            }
                        };
                        dataTypeService.Save(richTextEditor);

                        var container   = contentTypeService.GetContainers(CONTAINER, 1).FirstOrDefault();
                        var containerId = container.Id;

                        string propertyName        = "Page Content",
                               propertyDescription = "Text to be displayed on the Page";

                        // categories page
                        var contentCategoriesType = contentTypeService.Get(CATEGORIES_DOCUMENT_TYPE_ALIAS);
                        if (contentCategoriesType != null)
                        {
                            PropertyType richTextPropType = new PropertyType(dataTypeService.GetDataType(richTextEditor.Id), "pageContent")
                            {
                                Name        = propertyName,
                                Description = propertyDescription,
                                Variations  = ContentVariation.Culture
                            };
                            contentCategoriesType.AddPropertyType(richTextPropType, TAB);
                            contentTypeService.Save(contentCategoriesType);
                            ConnectorContext.AuditService.Add(AuditType.Save, -1, contentCategoriesType.Id, "Document Type", $"Document Type '{CATEGORIES_DOCUMENT_TYPE_ALIAS}' has been updated");
                        }

                        // category page
                        var contentCategoryType = contentTypeService.Get(CATEGORY_DOCUMENT_TYPE_ALIAS);
                        if (contentCategoryType != null)
                        {
                            PropertyType richTextPropType = new PropertyType(dataTypeService.GetDataType(richTextEditor.Id), "pageContent")
                            {
                                Name        = propertyName,
                                Description = propertyDescription,
                                Variations  = ContentVariation.Culture
                            };
                            contentCategoryType.AddPropertyType(richTextPropType, TAB);
                            contentTypeService.Save(contentCategoryType);
                            ConnectorContext.AuditService.Add(AuditType.Save, -1, contentCategoryType.Id, "Document Type", $"Document Type '{CATEGORY_DOCUMENT_TYPE_ALIAS}' has been updated");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error(typeof(_20_ContentPagesReconfiguration), ex.Message);
                logger.Error(typeof(_20_ContentPagesReconfiguration), ex.StackTrace);
            }
        }
Esempio n. 25
0
        public void SetUp()
        {
            var complexEditorConfig = new NestedContentConfiguration
            {
                ContentTypes = new[]
                {
                    new NestedContentConfiguration.ContentType {
                        Alias = "feature"
                    }
                }
            };

            ComplexTestEditor complexTestEditor           = Services.GetRequiredService <ComplexTestEditor>();
            TestEditor        testEditor                  = Services.GetRequiredService <TestEditor>();
            IDataTypeService  dataTypeService             = Services.GetRequiredService <IDataTypeService>();
            IConfigurationEditorJsonSerializer serializer = Services.GetRequiredService <IConfigurationEditorJsonSerializer>();

            var complexDataType = new DataType(complexTestEditor, serializer)
            {
                Name          = "ComplexTest",
                Configuration = complexEditorConfig
            };

            var testDataType = new DataType(testEditor, serializer)
            {
                Name = "Test",
            };

            dataTypeService.Save(complexDataType);
            dataTypeService.Save(testDataType);

            IFileService fileService = Services.GetRequiredService <IFileService>();
            Template     template    = TemplateBuilder.CreateTextPageTemplate();

            fileService.SaveTemplate(template);

            _contentType = ContentTypeBuilder.CreateTextPageContentType(ContentTypeAlias, defaultTemplateId: template.Id);

            // add complex editor
            foreach (IPropertyType pt in _contentType.PropertyTypes)
            {
                pt.DataTypeId = testDataType.Id;
            }

            _contentType.AddPropertyType(
                new PropertyType(_shortStringHelper, "complexTest", ValueStorageType.Ntext)
            {
                Alias = "complex", Name = "Complex", Description = string.Empty, Mandatory = false, SortOrder = 1, DataTypeId = complexDataType.Id
            },
                "content", "Content");

            // make them all validate with a regex rule that will not pass
            foreach (IPropertyType prop in _contentType.PropertyTypes)
            {
                prop.ValidationRegExp        = "^donotmatch$";
                prop.ValidationRegExpMessage = "Does not match!";
            }

            IContentTypeService contentTypeService = Services.GetRequiredService <IContentTypeService>();

            contentTypeService.Save(_contentType);
        }