Ejemplo n.º 1
0
        public string Create()
        {
            var schema = _schemaReader.Read();
            // create a process based on the schema
            var process = new Process {
                Name = "JunkDrawer"
            }.WithDefaults();

            process.Connections.Clear();
            process.Connections.Add(schema.Connection.Clone());
            process.Connections.Add(_cfg.Output());
            process.Entities = schema.Entities;
            foreach (var entity in process.Entities)
            {
                entity.PrependProcessNameToOutputName = false;
                entity.CalculateHashCode = _cfg.CalculateHashCode;
            }
            if (!string.IsNullOrEmpty(_cfg.Output().Table) && _cfg.Output().Table != Constants.DefaultSetting)
            {
                process.Entities.First().Alias = _cfg.Output().Table;
            }
            process.Mode = "init";

            return(process.Serialize());
        }
Ejemplo n.º 2
0
        public void Draw(Configuration configuration)
        {
            SchemaEntity schema;

            using (var fileStream = FileManager.OpenFileStream(configuration.SchemaFilePath))
            {
                schema = _schemaReader.Read(fileStream);
            }

            var points = _pointPositionCalculator.Handle(schema);

            if (FileManager.IsExist(configuration.DirectoryPath))
            {
                throw new Exception("Такая папка уже существует");
            }
            FileManager.CreateDirectory(configuration.DirectoryPath);
            FileManager.CopyFile("readme.md", Path.Combine(configuration.DirectoryPath, "readme.md"));
            using (var repo = new Repository(Repository.Init(configuration.DirectoryPath)))
            {
                Commands.Stage(repo, "readme.md");
                var maxCommitsCount = configuration.MaxCommitsCount > 4 ? configuration.MaxCommitsCount : 4;
                _commitCreator.Create(points, repo, maxCommitsCount, configuration.FileName, configuration.UserName,
                                      configuration.UserEmail);
            }
        }
Ejemplo n.º 3
0
        public string Create()
        {
            var schema = _schemaReader.Read();
            // create a process based on the schema
            var process = new Process {
                Name = "JunkDrawer"
            };

            process.Connections.Add(schema.Connection.Clone());
            process.Connections.Add(_cfg.Output());
            process.Entities = new List <Entity> {
                schema.Entities.First()
            };

            var entity = process.Entities.First();

            entity.PrependProcessNameToOutputName = false;

            if (!string.IsNullOrEmpty(_cfg.Output().Table) && _cfg.Output().Table != Constants.DefaultSetting)
            {
                entity.Alias = _cfg.Output().Table;
            }
            process.Mode = "init";

            // sqlce does not support views
            if (_cfg.Output().Provider == "sqlce")
            {
                process.Flatten = true;
                process.Flat    = entity.Alias;
            }

            return(process.Serialize());
        }
Ejemplo n.º 4
0
        public ImportResult Import(Connection connection)
        {
            if (_reader is NullSchemaReader)
            {
                _context.Error($"Unable to read schema of {connection}.");
                return(new ImportResult {
                    Connection = connection,
                    Fields = new List <Field>(),
                    Rows = Enumerable.Empty <IRow>(),
                    Schema = null
                });
            }

            var schema = _reader.Read();

            var entity = schema.Entities.First();

            foreach (var field in entity.Fields.Where(f => Constants.InvalidFieldNames.Contains(f.Name)).Where(field => field.Alias == field.Name))
            {
                field.Alias = field.Name + "Source";
                _context.Warn($"Reserved column name {field.Name} aliased as {field.Alias}.");
            }

            var cfg = new Process {
                Name        = "Import",
                Connections = new List <Connection> {
                    schema.Connection
                },
                Entities = new List <Entity> {
                    entity
                }
            }.Serialize();

            var process = new Process();

            process.Load(cfg);

            if (process.Errors().Any())
            {
                foreach (var error in process.Errors())
                {
                    _context.Error(error);
                }
                return(new ImportResult {
                    Connection = schema.Connection,
                    Fields = new List <Field>(),
                    Rows = Enumerable.Empty <IRow>(),
                    Schema = schema
                });
            }

            return(new ImportResult {
                Connection = schema.Connection,
                Fields = process.Entities.First().Fields.Where(f => !f.System).ToList(),
                Schema = schema,
                Rows = _runner.Run(process),
            });
        }
Ejemplo n.º 5
0
 public T Read(byte[] bytes, int offset, int length)
 {
     return(providerSchemaReader.Read(bytes));
 }
Ejemplo n.º 6
0
        private void Parse(TestCase testCase)
        {
            var schema = SchemaReader.Read((MemoryStream)testCase.Value);

            schema.ToString().Should().BeEquivalentTo((string)testCase.Expectation);
        }