Ejemplo n.º 1
0
        public void MergeWith(GenerationOptions options)
        {
            if (options == null)
            {
                return;
            }

            //if(options.ColumnNameFormatters.Count() > 0)
            //{
            //    this.ColumnNameFormatters = this.ColumnNameFormatters.Concat(options.ColumnNameFormatters).ToArray();
            //}
            this.ColumnNameFormatters    = options.ColumnNameFormatters ?? this.ColumnNameFormatters;
            this.TableNameFormatters     = options.TableNameFormatters ?? this.TableNameFormatters;
            this.DbSetNameFormatters     = options.DbSetNameFormatters ?? this.DbSetNameFormatters;
            this.ConnectionString        = options.ConnectionString ?? this.ConnectionString;
            this.ContextName             = options.ContextName ?? this.ContextName;
            this.ElementToGenerate       = options.ElementToGenerate ?? this.ElementToGenerate;
            this.IgnoreTableRegex        = options.IgnoreTableRegex ?? this.IgnoreTableRegex;
            this.ImplementingClassPath   = options.ImplementingClassPath ?? this.ImplementingClassPath;
            this.Namespace               = options.Namespace ?? this.Namespace;
            this.ProviderType            = options.ProviderType ?? this.ProviderType;
            this.ProviderTypeArguments   = options.ProviderTypeArguments ?? this.ProviderTypeArguments;
            this.SchemaName              = options.SchemaName ?? this.SchemaName;
            this.SerializerType          = options.SerializerType ?? this.SerializerType;
            this.SerializerTypeArguments = options.SerializerTypeArguments ?? this.SerializerTypeArguments;
            this.SkipTableWithoutKey     = options.SkipTableWithoutKey ?? this.SkipTableWithoutKey;
        }
Ejemplo n.º 2
0
        public static EFMGSettings[] Build(String s)
        {
            List <EFMGSettings> settings = new List <EFMGSettings>();

            JObject result = (JObject)JsonConvert.DeserializeObject(s);

            GenerationOptions defaultOptions = GetDefaultOptions(result);

            JArray settingsArray = result["Settings"] as JArray;

            if (settingsArray != null)
            {
                foreach (var setting in settingsArray)
                {
                    var obj = (EFMGSettings)setting.ToObject(typeof(EFMGSettings));
                    obj.Options.MergeWith(defaultOptions);
                    settings.Add(obj);
                }
            }
            else
            {
                var obj = (EFMGSettings)result.ToObject(typeof(EFMGSettings));
                obj.Options.MergeWith(defaultOptions);
                settings.Add(obj);
            }

            return(settings.ToArray());
        }
Ejemplo n.º 3
0
        private Generator(GenerationOptions generatorOptions)
        {
            _applicationInfo.AddStep("In Generator constructor");
            GeneratorOptions = generatorOptions;

            //Initialize the provider
            if (generatorOptions.ProviderType == null)
            {
                _applicationInfo.AddStep("Set Default Provider");
                //default to sqlserver provider
                generatorOptions.ProviderType          = "CExtensions.EFModelGenerator.Providers.SqlDataProvider, CExtensions.EFModelGenerator";
                generatorOptions.ProviderTypeArguments = new Object[] { generatorOptions.ConnectionString, generatorOptions.SchemaName };
            }

            _applicationInfo.AddStep($"Creating Provider of type {generatorOptions.ProviderType}");
            Provider = createInstance(generatorOptions.ProviderType, generatorOptions.ProviderTypeArguments);

            //initialize the serializer
            if (generatorOptions.SerializerType == null)
            {
                _applicationInfo.AddStep("Set Default Serializer");
                generatorOptions.SerializerType          = "CExtensions.EFModelGenerator.Serializers.CoreSerializer, CExtensions.EFModelGenerator";
                generatorOptions.SerializerTypeArguments = new Object[] { generatorOptions.ElementToGenerate, generatorOptions.Namespace, generatorOptions.ContextName };
            }
            _applicationInfo.AddStep($"Creating Serializer of type {generatorOptions.ProviderType}");

            Serializer = createInstance(generatorOptions.SerializerType, generatorOptions.SerializerTypeArguments);
        }
Ejemplo n.º 4
0
        private static GenerationOptions GetDefaultOptions(JObject result)
        {
            JProperty property = result.First as JProperty;

            GenerationOptions defaults = null;

            if (property != null && property.Name == "DefaultOptions")
            {
                defaults = (GenerationOptions)result["DefaultOptions"].ToObject(typeof(GenerationOptions));
            }

            return(defaults);
        }
        public String FormatException(Exception ex, GenerationOptions options)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendLine("-----------------------------------------------------------------");
            sb.AppendLine("Oups !! An exception occured while generating the code !");
            sb.AppendLine($"Go to  https://github.com/CedricDumont/CExtensions-EFModelGenerator to check for known issues");
            sb.AppendLine("Or open an issue with the following Information : ");
            sb.AppendLine("");
            sb.AppendLine("***********************************************************");
            sb.AppendLine("");
            sb.AppendLine($"- Generation Module Info : {GeneratingMutatingAssemblyInfo()}");
            sb.AppendLine("");
            sb.AppendLine($"- Generation steps :");
            sb.AppendLine($"{_GenerationSteps.ToString()}");
            sb.AppendLine("");
            sb.AppendLine("- Options:");
            sb.AppendLine($"{JsonConvert.SerializeObject(options, Formatting.Indented)}");
            sb.AppendLine("");
            sb.AppendLine("- Exception Details:");
            sb.AppendLine($"Message : {ex.Message}");
            if (!TestMode)
            {
                sb.AppendLine($"Stack : {Environment.NewLine}{ex.StackTrace}");
            }

            if (ex.InnerException != null)
            {
                sb.AppendLine("");
                sb.AppendLine($"Inner Exception Message : {ex.Message}");
                if (!TestMode)
                {
                    sb.AppendLine($"Inner Exception Stack :{Environment.NewLine} {ex.StackTrace}");
                }
            }
            sb.AppendLine("");
            sb.AppendLine("***********************************************************");

            return(sb.ToString());
        }
 internal ModelInitializer(Object provider, GenerationOptions options)
 {
     Options = options;
     Provider = provider;
 }