Beispiel #1
0
        public DataBaseService(string name, string rootPath, long fileSize, SupportedSources source,
                               IFileWorkerFactory fileWorkerFactory,
                               ITableServiceFactory tableServiceFactory,
                               IDbWriterFactory dbWriterFactory)
        {
            _tableServiceFactory = tableServiceFactory;
            _dbWriterFactory     = dbWriterFactory;

            var regex = new Regex(".*"); //valid

            if (regex.IsMatch(rootPath))
            {
                DataBase = new DataBase
                {
                    Name     = name,
                    Settings = new Settings {
                        RootPath = rootPath, FileSize = fileSize, DefaultSource = source
                    }
                };
                _fileWorker = fileWorkerFactory.GetFileWorker(DataBase);

                _fileWorker.UpdateDataBaseFile();
            }
            else
            {
                throw new ArgumentException($"Incorrect path: {rootPath}");
            }
        }
        public ISource GetSourceObject(SupportedSources type, DataBase dataBase, Table table)
        {
            var sourceType = Type.GetType(type.GetAssemblyDescription(Constants.SourceType));

            var sourceObject = Activator.CreateInstance(sourceType, _dbClientFactory);

            var source = (ISource)sourceObject;

            source.SetUrl(dataBase, table);

            return(source);
        }
        public IDbManager GetDbManagerRest(string name, long fileSize, SupportedSources source)
        {
            try
            {
                _client.CreateDb(name, fileSize, source);

                return(new DbManagerRest(name, _client));
            }
            catch (Exception ex)
            {
                throw new Exception("Can not create db", ex);
            }
        }
Beispiel #4
0
        private static void Rest()
        {
            string name = "FirstDB";
            //string path = @"D:\Education\4 course\InformationTechnologies\DataBases";
            SupportedSources source   = SupportedSources.Json;
            long             fileSize = 1000000;

            //var manager = DbManagerFactory.GetDbManagerRest(name, fileSize, source);
            IDbManager manager = null;// DbManagerFactory.GetDbManagerRest(name);
            //manager.AddTable("Table1");
            //manager.AddTable("Table2");
            var table = manager["Table1"];

            //table.AddNewField("Name", SupportedTypes.String);
            //table.AddNewField("Income", SupportedTypes.RealInterval);

            //var data = new List<List<object>>()
            // {
            //     new List<object>{"name1", new RealInterval { From=12, To=54353} },
            //     new List<object>{"name3", new RealInterval { From=12, To=564353} },
            //     new List<object>{"name2", new RealInterval { From=124, To=543} },
            // };

            //table.InsertDataRange(data);

            var select = table.Select();
            //dataBaseService.DeleteTable("SecondTable");
            ////dataBaseService.AddTable("FirstTable");
            //var table = dataBaseService["FirstTable"];

            ////table.AddNewField("Name", SupportedTypes.String);
            ////table.AddNewField("Age", DBMS_Core.Models.Types.SupportedTypes.Integer,
            ////    new List<IValidator> { new NumericValidator<int>(NumericValidatorOperation.Greater, 0) });
            ////table.AddNewField("Income", DBMS_Core.Models.Types.SupportedTypes.RealInterval);
            //var data = new List<List<object>>()
            // {
            //     new List<object>{"name1", 12, new RealInterval { From=12, To=54353} },
            //     new List<object>{"name3", -12, new RealInterval { From=12, To=564353} },
            //     new List<object>{"name2", 124, new RealInterval { From=124, To=543} },
            // };
            //table.InsertDataRange(data);


            //var selectData = table.Select(3, 1,
            //    new Dictionary<string, List<IValidator>>
            //    {
            //        ["Name"] = new List<IValidator> { new StringValidator(StringValidatorOperation.EndWith, "2") }
            //    });
        }
        public IDbWriter GetDbWriter(SupportedSources source)
        {
            if (Cache.ContainsKey(source.GetAssemblyDescription(Constants.DbWriterType)))
            {
                return(Cache[source.GetAssemblyDescription(Constants.DbWriterType)]);
            }

            var dbWriterType   = Type.GetType(source.GetAssemblyDescription(Constants.DbWriterType));
            var dbWriterObject = Activator.CreateInstance(dbWriterType, _dbClientFactory);
            var dbWriter       = (IDbWriter)dbWriterObject;

            Cache.Add(source.GetAssemblyDescription(Constants.DbWriterType), dbWriter);

            return(dbWriter);
        }
Beispiel #6
0
        private string RootFormat(SupportedSources source, string dbName)
        {
            switch (source)
            {
            case SupportedSources.Json:
                return($"{_setting.RootPath[source]}\\{dbName}{Core.Constants.DataBaseFileExtention}");

            case SupportedSources.SqlServer:
                return($"{_setting.RootPath[source]}{Constants.Separator}{dbName}");

            case SupportedSources.MongoDb:
                return($"{_setting.RootPath[source]}{Constants.Separator}{dbName}");

            default:
                throw new ArgumentException("Unsupported source!");
            }
        }
        public void CreateDb(string name, long fileSize, SupportedSources source)
        {
            var url = RequestBuilder.StartBuild(_settings.Host)
                      .AddUrl(_settings.Constants.DbController)
                      .Build();

            var db = new Dto.DataBase
            {
                Name     = name,
                Settings = new Dto.DbSettings
                {
                    DefaultSource = source,
                    FileSize      = fileSize
                }
            };

            PostRequest(url, db);
        }
Beispiel #8
0
        public DataBaseService(string path,
                               IFileWorkerFactory fileWorkerFactory,
                               ITableServiceFactory tableServiceFactory,
                               IDbWriterFactory dbWriterFactory)
        {
            _tableServiceFactory = tableServiceFactory;
            _dbWriterFactory     = dbWriterFactory;

            SupportedSources source = ResolvePath(path);

            _fileWorker = fileWorkerFactory.GetFileWorker(new DataBase {
                Settings = new Settings {
                    DefaultSource = source
                }
            });
            DataBase = _fileWorker.GetDataBaseFromFile(path);

            _fileWorker.DataBase = DataBase;
        }
Beispiel #9
0
 private List <string> GetDbNamesBySource(SupportedSources source)
 {
     return(_dbWriterFactory.GetDbWriter(source).GetDbsNames(_setting.RootPath[source]));
 }
 public IDbManager GetDbManagerLocal(string name, string rootPath, long fileSize, SupportedSources source)
 {
     return(new DbManagerLocal(_dataBaseServiceFactory.GetDataBaseService(name, rootPath, fileSize, source)));
 }
 public IDataBaseService GetDataBaseService(string name, string rootPath, long fileSize, SupportedSources source)
 {
     return(new DataBaseService(name, rootPath, fileSize, source, _fileWorkerFactory, _tableServiceFactory, _dbWriterFactory));
 }