Пример #1
0
        public void GenerateClassFiles(string nameSpace, string folderPath)
        {
            string dataDirectory = Path.Combine(folderPath, "DocumentTypes");

            if (!System.IO.Directory.Exists(dataDirectory))
            {
                System.IO.Directory.CreateDirectory(dataDirectory);
            }

            GenerateContentTypes(nameSpace, dataDirectory, "DocumentType", () => ApplicationContext.Current.Services.ContentTypeService.GetAllContentTypes(), (x, y) =>
            {
                ConfigureTemplates(x as IContentType, y);
                if (x.ParentId == -1)
                {
                    y.ParentAlias     = "DocumentTypeBase";
                    y.ParentClassName = "DocumentTypeBase";
                }
                else
                {
                    var parent        = ApplicationContext.Current.Services.ContentTypeService.GetContentType(x.ParentId);
                    y.ParentAlias     = parent == null ? "DocumentTypeBase" : parent.Alias;
                    y.ParentClassName = parent == null ? "DocumentTypeBase" : TypeGeneratorUtils.GetFormattedMemberName(parent.Alias);
                }
            });
        }
Пример #2
0
        public void GenerateClassFiles(string nameSpace, string folderPath)
        {
            string dataDirectory = Path.Combine(folderPath, "MemberTypes");

            if (!System.IO.Directory.Exists(dataDirectory))
            {
                System.IO.Directory.CreateDirectory(dataDirectory);
            }

            GenerateContentTypes(nameSpace, dataDirectory, "MemberType", () => ApplicationContext.Current.Services.MemberTypeService.GetAll(), (x, y) =>
            {
                y.IgnoredPropertyAliases.AddRange(typeof(MemberTypeBase).GetCodeFirstAttributes <DoNotRemovePropertyAttribute>().Select(t => t.PropertyAlias));
                y.IgnoredTabs.AddRange(typeof(MemberTypeBase).GetCodeFirstAttributes <DoNotRemoveTabAttribute>().Select(t => t.TabName));
                if (x.ParentId == -1)
                {
                    y.ParentAlias     = "MemberTypeBase";
                    y.ParentClassName = "MemberTypeBase";
                }
                else
                {
                    var parent        = ApplicationContext.Current.Services.ContentTypeService.GetContentType(x.ParentId);
                    y.ParentAlias     = parent == null ? "MemberTypeBase" : parent.Alias;
                    y.ParentClassName = parent == null ? "MemberTypeBase" : TypeGeneratorUtils.GetFormattedMemberName(parent.Alias);
                }
            });
        }
Пример #3
0
        private void GenerateDataTypes(string nameSpace, string folderPath)
        {
            var defs = ApplicationContext.Current.Services.DataTypeService.GetAllDataTypeDefinitions();

            if (_typeDefs == null)
            {
                _typeDefs = this.GetType().Assembly.GetTypes().Where(x => x.GetCustomAttribute <BuiltInDataTypeAttribute>() != null && !x.IsGenericTypeDefinition).ToDictionary(x => x.GetInitialisedAttribute <DataTypeAttribute>(), x => x.Name);
            }
            List <DataTypeDescription> types = new List <DataTypeDescription>();

            foreach (var def in defs)
            {
                if (!_typeDefs.Any(x => x.Key.Name == def.Name)) //not a known built-in type
                {
                    var dataType = new DataTypeDescription();
                    dataType.PreValues = ApplicationContext.Current.Services.DataTypeService
                                         .GetPreValuesCollectionByDataTypeId(def.Id)
                                         .PreValuesAsDictionary
                                         .Where(x => x.Value != null && x.Value.Value != null)
                                         .Select(x => new PreValueDescription()
                    {
                        Alias = x.Key, Value = x.Value.Value.Replace("\"", "\"\"")
                    })
                                         .ToList();

                    if (_typeDefs.Any(x => x.Key.PropertyEditorAlias == def.PropertyEditorAlias)) //can base on a known built-in type
                    {
                        var builtIn = _typeDefs.First(x => x.Key.PropertyEditorAlias == def.PropertyEditorAlias);
                        dataType.CustomType           = false;
                        dataType.InheritanceBase      = builtIn.Key.DecoratedType.Name;
                        dataType.DataTypeClassName    = TypeGeneratorUtils.GetDataTypeClassName(def.Id, null);
                        dataType.DataTypeInstanceName = def.Name;
                        dataType.PropertyEditorAlias  = def.PropertyEditorAlias;
                        dataType.DbType = Enum.GetName(typeof(DataTypeDatabaseType), def.DatabaseType);
                    }
                    else
                    {
                        dataType.CustomType = true;
                        switch (def.DatabaseType)
                        {
                        case DataTypeDatabaseType.Date:
                            dataType.InheritanceBase    = "IUmbracoDateDataType";
                            dataType.SerializedTypeName = "DateTime";
                            break;

                        case DataTypeDatabaseType.Integer:
                            dataType.InheritanceBase    = "IUmbracoIntegerDataType";
                            dataType.SerializedTypeName = "int";
                            break;

                        case DataTypeDatabaseType.Ntext:
                            dataType.InheritanceBase    = "IUmbracoNtextDataType";
                            dataType.SerializedTypeName = "string";
                            break;

                        case DataTypeDatabaseType.Nvarchar:
                            dataType.InheritanceBase    = "IUmbracoNvarcharDataType";
                            dataType.SerializedTypeName = "string";
                            break;
                        }
                        dataType.DataTypeClassName    = TypeGeneratorUtils.GetDataTypeClassName(def.Id, null);
                        dataType.DataTypeInstanceName = def.Name;
                        dataType.PropertyEditorAlias  = def.PropertyEditorAlias;
                        dataType.DbType = Enum.GetName(typeof(DataTypeDatabaseType), def.DatabaseType);
                    }
                    types.Add(dataType);
                }
            }
            GenerateClassFiles(nameSpace, folderPath, types);
        }