示例#1
0
        public void Write(SchemaDefinition schema)
        {
            var shouldWriteSchema = _settingsRepository
                                    .Get()
                                    .FileLocations
                                    .GenerateSchemaDefinitionFiles;

            if (!shouldWriteSchema)
            {
                _logger.Log(LogLevel.Information, "Save schema ... skipped");
                return;
            }

            _logger.Log(LogLevel.Information, "Save schema ... start");
            _logger.Log(string.Empty);

            var filePath = _settingsRepository
                           .Get()
                           .FileLocations
                           .SchemaDefinitionFilesLocation;

            // NOTE : XML is getting too big, needs to be split up..
            var groups = schema.GroupBy(
                pair => pair.Value.Type,
                pair => pair,
                (type, pairs) =>
            {
                var partialSchema = new SchemaDefinition();
                partialSchema.AddRange(pairs.ToDictionary(k => k.Key, v => v.Value));
                return(new KeyValuePair <SchemaObjectType, SchemaDefinition>(type, partialSchema));
            });

            foreach (var partial in groups)
            {
                using (var writer = new FileStream($"{filePath}\\{partial.Key}.xml", FileMode.Create))
                {
                    var serializer = new DataContractSerializer(typeof(SchemaDefinition));
                    serializer.WriteObject(writer, partial.Value);
                }
            }

            _logger.Log(LogLevel.Information, "Save schema ... end");
            _logger.Log(string.Empty);
        }
示例#2
0
        public SchemaDefinition GenerateSchema()
        {
            _logger.Log(LogLevel.Information, "Generate schema ... start");
            _logger.Log(string.Empty);

            _databaseSchema = new SchemaDefinition();

            var settings = _settingsRepository.Get();

            Create(SchemaObjectType.UserDefinedType, settings);
            Create(SchemaObjectType.UserDefinedTableType, settings);
            Create(SchemaObjectType.Table, settings);
            Create(SchemaObjectType.View, settings);
            Create(SchemaObjectType.Function, settings);
            Create(SchemaObjectType.StoredProcedure, settings);

            _logger.Log(LogLevel.Information, "Generate schema ... end");
            _logger.Log(string.Empty);

            return(_databaseSchema);
        }