예제 #1
0
        public void TestQuery()
        {
            MetadataServiceSettings settings = new MetadataServiceSettings();

            settings.Catalog = @"C:\Users\User\Desktop\GitHub\publish\one-c-sharp-sql\bin\metadata";
            IMetadataService metadata = new MetadataService();

            metadata.Configure(settings);
            metadata.UseServer("sqlexpress");
            metadata.UseDatabase("trade_11_2_3_159_demo");
            metadata.UseDatabase("accounting_3_0_72_72_demo");
            IQueryExecutor     executor  = new QueryExecutor(metadata);
            IScriptingService  scripting = new ScriptingService(metadata, executor);
            IList <ParseError> errors;
            string             sql = scripting.PrepareScript(GetTestQueryText(), out errors);

            foreach (ParseError error in errors)
            {
                Console.WriteLine(error.Message);
            }
            if (errors.Count == 0)
            {
                Console.WriteLine(sql);
            }
        }
예제 #2
0
 private static void ConfigureMetadataService(IMetadataService metadata, MetadataServiceSettings settings, IWebHostEnvironment environment)
 {
     if (string.IsNullOrWhiteSpace(settings.Catalog))
     {
         settings.Catalog = MetadataCatalogPath(environment);
     }
     metadata.Configure(settings);
 }
예제 #3
0
        public void SaveMetadataSettings(MetadataServiceSettings settings)
        {
            JavaScriptEncoder     encoder = JavaScriptEncoder.Create(new UnicodeRange(0, 0xFFFF));
            JsonSerializerOptions options = new JsonSerializerOptions()
            {
                Encoder       = encoder,
                WriteIndented = true
            };

            byte[] bytes = JsonSerializer.SerializeToUtf8Bytes(settings.SettingsCopy(), options);
            File.WriteAllBytes(MetadataSettingsFile, bytes);
        }
예제 #4
0
        private void InitializeMetadataService()
        {
            MetadataServiceSettings settings;

            if (File.Exists(MetadataSettingsFile))
            {
                settings = LoadMetadataSettings();
            }
            else
            {
                settings = new MetadataServiceSettings();
                SaveMetadataSettings(settings);
            }
            if (string.IsNullOrWhiteSpace(settings.Catalog))
            {
                settings.Catalog = Path.Combine(ModuleCatalogPath, MODULE_NAME);
            }
            Metadata.Configure(settings);
        }
예제 #5
0
        public void Configure(MetadataServiceSettings settings)
        {
            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }
            if (string.IsNullOrWhiteSpace(settings.Catalog))
            {
                throw new ArgumentNullException(nameof(settings.Catalog));
            }
            if (!Directory.Exists(settings.Catalog))
            {
                throw new DirectoryNotFoundException(settings.Catalog);
            }

            Settings = settings;

            if (settings.Servers.Count == 0)
            {
                return;
            }

            int            s = 0;
            int            i = 0;
            InfoBase       database;
            DatabaseServer server;
            string         serverCatalogPath;
            string         metadataFilePath;

            while (s < settings.Servers.Count)
            {
                server            = settings.Servers[s];
                serverCatalogPath = ServerCatalogPath(server.Name);

                if (server == null || string.IsNullOrWhiteSpace(server.Name) || !Directory.Exists(serverCatalogPath))
                {
                    settings.Servers.RemoveAt(s);
                    continue;
                }
                s++;

                if (server.Databases.Count == 0)
                {
                    continue;
                }

                i = 0;
                while (i < server.Databases.Count)
                {
                    database         = server.Databases[i];
                    metadataFilePath = MetadataFilePath(server.Name, database.Name);

                    if (database == null || string.IsNullOrWhiteSpace(database.Name) || !File.Exists(metadataFilePath))
                    {
                        server.Databases.RemoveAt(i);
                        continue;
                    }
                    i++;

                    InitializeMetadata(database, metadataFilePath);
                }
            }
        }