Ejemplo n.º 1
0
        public int BatchInsertIncidentCollections(MatchCollection collections, ConfigInitializer.IncidentTableEntity incidentTable, out HashSet<string> duplicateHash, bool SKIP)
        {
            duplicateHash = new HashSet<string>();
            if (SKIP) return 0;

            var queryText = incidentTable.ToString();
            var incident = new DataNormalizer.DataEntity.Incident(incidentTable);
            int successCount = 0;
            //var queryText = $"INSERT into {this.tableInfo.tableName} {this.tableInfo.queryItemPattern} VALUES {this.tableInfo.queryValuePattern}";
            using (var transaction = this._connection.BeginTransaction())
            {
                foreach (Match match in collections)
                {
                    var cmd = new SqlCommand(queryText, this._connection, transaction);
                    incident.registerSqlCommand(match, ref cmd);
                    try
                    {
                        cmd.ExecuteNonQuery();
                        Console.WriteLine($"Insert: {match.Groups[1].Value}");
                        successCount += 1;
                    }
                    catch
                    {
                        var incidentString = match.Groups[1].Value;
                        duplicateHash.Add(incidentString);
                        Console.WriteLine($"Duplicate Incident: {incidentString}");
                    }
                }
                transaction.Commit();
            }
            return successCount;
        }
Ejemplo n.º 2
0
        private void InitializeApplicationConfig()
        {
            ConfigInitializer.DirectoryName = "El Rosario SIGI";

            if (!ConfigInitializer.ExistConfig())
            {
                ConfigInitializer.CreateConfig();
            }
        }
Ejemplo n.º 3
0
        private static void InitializeConfigs(AzureSession session, string profilePath)
        {
            var fallbackList = new List <string>()
            {
                Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".Azure", "PSConfig.json"),
                Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), ".Azure", "PSConfig.json")
            };
            ConfigInitializer configInitializer = new ConfigInitializer(fallbackList);

            configInitializer.MigrateConfigs(profilePath);
            configInitializer.InitializeForAzureSession(session);
        }
Ejemplo n.º 4
0
 protected void uxOK_Click(object sender, EventArgs e)
 {
     if (uxProviders.SelectedValue == "sql")
     {
         ConfigInitializer.InitializeSql(uxConnectionStrings.SelectedValue);
     }
     else
     {
         ConfigInitializer.InitializeAccess(uxAccessFileName.Text);
     }
     Response.Redirect(JcoHttpHandler.HandlerPath + "?a=conf&p=2");
     //MultiView1.ActiveViewIndex = 1;
 }
Ejemplo n.º 5
0
        public void BatchInsertDialogCollections(ConfigInitializer.ChatlogTableEntity chatlogTable, MatchCollection chatlogCollections, int IncidentId, bool SKIP)
        {
            if (SKIP) return;

            Console.WriteLine("     [Sub-Chatlog] Inserting...");
            var queryText = chatlogTable.ToHeader();
            var chatlog = new DataNormalizer.DataEntity.ChatLog(chatlogTable);
            using (var transaction = this._connection.BeginTransaction())
            {
                int TOTAL_DIALOG_NUM = chatlogCollections.Count;
                int finished = 0;

                int BATCH_COUNT = 0;

                int LENGTH = chatlogCollections.Count;

                for (int i = 0; i < LENGTH; i++)
                {
                    var match = chatlogCollections[i];
                    if (BATCH_COUNT != 0)
                    {
                        // add head value with ","
                        queryText += ",";
                    }
                    queryText += chatlog.getParameterString(match, IncidentId);
                    BATCH_COUNT += 1;
                    // reach BATCH SIZE || last match
                    if (BATCH_COUNT >= 100 || i == LENGTH - 1)
                    {
                        // execute command and reset cmd text
                        _executeCMD(queryText, this._connection, transaction);
                        queryText = chatlogTable.ToHeader();
                        BATCH_COUNT = 0;
                        finished += 100;
                    }
                }

                //chatlog.clearState();
                transaction.Commit();
                Console.WriteLine($"     [Sub-Chatlog] Insert : Done! IncidentID = {IncidentId}, LENGTH={LENGTH}");
            }
        }
        public void NoFileExtension()
        {
            string configFile = Files.cr_noEnding;
            var    ci         = new ConfigInitializer(new string[] { }, configFile);

            ci.SetUp();

            string               expectedLogFile    = CombineWithDefaultLogFolder("StreamRedirection");
            string               expectedStreamFile = CombineWithDefaultLogFolder("Log");
            LogLevel             expectedLogLevel   = LogLevel.Error;
            TextDocumentSyncKind expectedSyncKind   = TextDocumentSyncKind.Incremental;

            Console.WriteLine(LanguageServerConfig.ToString());

            Assert.IsFalse(ci.Errors.HasErrors);
            Assert.AreEqual(expectedLogFile, LanguageServerConfig.LogFile);
            Assert.AreEqual(expectedStreamFile, LanguageServerConfig.RedirectedStreamFile);
            Assert.AreEqual(expectedSyncKind, LanguageServerConfig.SyncKind);
            Assert.AreEqual(expectedLogLevel, LanguageServerConfig.LogLevel);
        }
        public void GoodCustomValues()
        {
            string configFile = Files.cr_fine;
            var    ci         = new ConfigInitializer(new string[] { }, configFile);

            ci.SetUp();

            string               expectedLogFile    = CombineWithDefaultLogFolder("./b.txt");
            string               expectedStreamFile = CombineWithDefaultLogFolder("./a.txt");
            LogLevel             expectedLogLevel   = LogLevel.Trace;
            TextDocumentSyncKind expectedSyncKind   = TextDocumentSyncKind.Full;

            Console.WriteLine(LanguageServerConfig.ToString());

            Assert.IsFalse(ci.Errors.HasErrors);
            Assert.AreEqual(expectedLogFile, LanguageServerConfig.LogFile);
            Assert.AreEqual(expectedStreamFile, LanguageServerConfig.RedirectedStreamFile);
            Assert.AreEqual(expectedLogLevel, LanguageServerConfig.LogLevel);
            Assert.AreEqual(expectedSyncKind, LanguageServerConfig.SyncKind);
        }
        public void MissingFields()
        {
            string configFile = Files.cr_missingFields;
            var    ci         = new ConfigInitializer(new string[] { }, configFile);

            ci.SetUp();

            string               expectedLogFile    = defaultLog;
            string               expectedStreamFile = defaultStream;
            LogLevel             expectedLogLevel   = LogLevel.Error;
            TextDocumentSyncKind expectedSyncKind   = TextDocumentSyncKind.Incremental;

            Console.WriteLine(LanguageServerConfig.ToString());

            Assert.IsFalse(ci.Errors.HasErrors, "has error mismatch");
            Assert.AreEqual(expectedLogFile, LanguageServerConfig.LogFile);
            Assert.AreEqual(expectedStreamFile, LanguageServerConfig.RedirectedStreamFile);
            Assert.AreEqual(expectedSyncKind, LanguageServerConfig.SyncKind);
            Assert.AreEqual(expectedLogLevel, LanguageServerConfig.LogLevel);
        }
        public void WrongLogPathType()
        {
            string configFile = Files.cr_wrongLogPathType;
            var    ci         = new ConfigInitializer(new string[] { }, configFile);

            ci.SetUp();

            string               expectedLogFile    = CombineWithDefaultLogFolder("../2");
            string               expectedStreamFile = defaultStream;
            LogLevel             expectedLogLevel   = LogLevel.Error;
            TextDocumentSyncKind expectedSyncKind   = TextDocumentSyncKind.Incremental;

            Console.WriteLine(LanguageServerConfig.ToString());

            Assert.IsFalse(ci.Errors.HasErrors);
            Assert.AreEqual(expectedLogFile, LanguageServerConfig.LogFile);
            Assert.AreEqual(expectedStreamFile, LanguageServerConfig.RedirectedStreamFile);
            Assert.AreEqual(expectedSyncKind, LanguageServerConfig.SyncKind);
            Assert.AreEqual(expectedLogLevel, LanguageServerConfig.LogLevel);
        }
        public void SameFiles()
        {
            string configFile = Files.cr_sameFiles;
            var    ci         = new ConfigInitializer(new string[] { }, configFile);

            ci.SetUp();

            string               expectedLogFile    = defaultLog;
            string               expectedStreamFile = defaultStream;
            LogLevel             expectedLogLevel   = LogLevel.Error;
            TextDocumentSyncKind expectedSyncKind   = TextDocumentSyncKind.Incremental;

            Console.WriteLine(LanguageServerConfig.ToString());

            Assert.IsTrue(ci.Errors.HasErrors);
            Assert.IsTrue(ci.Errors.ErrorMessages.Contains("same files"));
            Assert.AreEqual(expectedLogFile, LanguageServerConfig.LogFile);
            Assert.AreEqual(expectedStreamFile, LanguageServerConfig.RedirectedStreamFile);
            Assert.AreEqual(expectedSyncKind, LanguageServerConfig.SyncKind);
            Assert.AreEqual(expectedLogLevel, LanguageServerConfig.LogLevel);
        }
        public void ExceedingLogLevelInArgs()
        {
            string configFile = Files.cr_default;

            var ci = new ConfigInitializer(new string[] { "/loglevel:55" }, configFile);

            ci.SetUp();

            string               expectedLogFile    = defaultLog;
            string               expectedStreamFile = defaultStream;
            LogLevel             expectedLogLevel   = LogLevel.Error;
            TextDocumentSyncKind expectedSyncKind   = TextDocumentSyncKind.Incremental;

            Console.WriteLine(LanguageServerConfig.ToString());

            Assert.IsTrue(ci.Errors.HasErrors, "Error Mismatch");
            Assert.AreEqual(expectedLogFile, LanguageServerConfig.LogFile);
            Assert.AreEqual(expectedStreamFile, LanguageServerConfig.RedirectedStreamFile);
            Assert.AreEqual(expectedSyncKind, LanguageServerConfig.SyncKind);
            Assert.AreEqual(expectedLogLevel, LanguageServerConfig.LogLevel);
        }
        public void MissingCfGFile()
        {
            string configFile = Files.cr_default;

            var ci = new ConfigInitializer(new string[] { "/log:./Logs/a.txt", "/stream:./Logs/b.txt", "/loglevel:0" }, configFile);

            ci.SetUp();

            string               expectedLogFile    = CombineWithDefaultLogFolder("a.txt");
            string               expectedStreamFile = CombineWithDefaultLogFolder("b.txt");
            LogLevel             expectedLogLevel   = LogLevel.Trace;
            TextDocumentSyncKind expectedSyncKind   = TextDocumentSyncKind.Incremental;

            Console.WriteLine(LanguageServerConfig.ToString());

            Assert.IsFalse(ci.Errors.HasErrors, "Error Mismatch");
            Assert.AreEqual(expectedLogFile, LanguageServerConfig.LogFile);
            Assert.AreEqual(expectedStreamFile, LanguageServerConfig.RedirectedStreamFile);
            Assert.AreEqual(expectedSyncKind, LanguageServerConfig.SyncKind);
            Assert.AreEqual(expectedLogLevel, LanguageServerConfig.LogLevel);
        }
        public void NoCfgFile()
        {
            string configFile = CombinePath("/", "abasdfasfdsa.json");
            var    ci         = new ConfigInitializer(new string[] { }, configFile);

            ci.SetUp();

            string               expectedLogFile    = defaultLog;
            string               expectedStreamFile = defaultStream;
            LogLevel             expectedLogLevel   = LogLevel.Error;
            TextDocumentSyncKind expectedSyncKind   = TextDocumentSyncKind.Incremental;

            Console.WriteLine(LanguageServerConfig.ToString());

            Assert.IsTrue(ci.Errors.HasErrors, "Error Mismatch");
            Assert.IsTrue(ci.Errors.ErrorMessages.Contains("not be located"), "Errormsg not contained");
            Assert.AreEqual(expectedLogFile, LanguageServerConfig.LogFile);
            Assert.AreEqual(expectedStreamFile, LanguageServerConfig.RedirectedStreamFile);
            Assert.AreEqual(expectedSyncKind, LanguageServerConfig.SyncKind);
            Assert.AreEqual(expectedLogLevel, LanguageServerConfig.LogLevel);
        }
        public void ExceedingLogLevel()
        {
            string configFile = Files.cr_wrongLogLevel;
            var    ci         = new ConfigInitializer(new string[] { }, configFile);

            ci.SetUp();

            string               expectedLogFile    = defaultLog;
            string               expectedStreamFile = defaultStream;
            LogLevel             expectedLogLevel   = LogLevel.Error;
            TextDocumentSyncKind expectedSyncKind   = TextDocumentSyncKind.Incremental;

            Console.WriteLine(LanguageServerConfig.ToString());

            Assert.IsTrue(ci.Errors.HasErrors, "error expectation mismatch");
            Assert.IsTrue(ci.Errors.ErrorMessages.Contains("Loglevel must be between"));
            Assert.AreEqual(expectedLogFile, LanguageServerConfig.LogFile);
            Assert.AreEqual(expectedStreamFile, LanguageServerConfig.RedirectedStreamFile);
            Assert.AreEqual(expectedSyncKind, LanguageServerConfig.SyncKind);
            Assert.AreEqual(expectedLogLevel, LanguageServerConfig.LogLevel);
        }
        public void IllegalArgument()
        {
            string configFile = Files.cr_default;

            var ci = new ConfigInitializer(new string[] { "/abc:ab" }, configFile);

            ci.SetUp();

            string               expectedLogFile    = defaultLog;
            string               expectedStreamFile = defaultStream;
            LogLevel             expectedLogLevel   = LogLevel.Error;
            TextDocumentSyncKind expectedSyncKind   = TextDocumentSyncKind.Incremental;

            Console.WriteLine(LanguageServerConfig.ToString());

            Assert.IsTrue(ci.Errors.HasErrors, "Error Mismatch");
            Assert.IsTrue(ci.Errors.ErrorMessages.Contains("Unknown switch"));

            Assert.AreEqual(expectedLogFile, LanguageServerConfig.LogFile);
            Assert.AreEqual(expectedStreamFile, LanguageServerConfig.RedirectedStreamFile);
            Assert.AreEqual(expectedSyncKind, LanguageServerConfig.SyncKind);
            Assert.AreEqual(expectedLogLevel, LanguageServerConfig.LogLevel);
        }
Ejemplo n.º 16
0
        private Engine()
        {
            // Read config file
            _configuration    = ConfigInitializer.InitConfig();
            _connectionString = _configuration.GetConnectionString("Default");

            _context = new ToDoContext();
            _context.Database.EnsureCreated();

            _userRepository = new UserRepository(_context);
            //ToDoListRepository toDoListRepository = new ToDoListRepository(_connectionStringEdit);

            _userService = new UserService(_userRepository);
            //_toDoListService = new ToDoListService(toDoListRepository);

            _reader = new ConsoleReader();
            _writer = new ConsoleWriter();

            _userController = new UserController(_userService, _writer, _reader);
            //_toDoListController = new ToDoListController(_toDoListService,_userService, _writer, _reader);

            _menu = new Menu(_writer, _reader, _userController);
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Initializes and returns an <see cref="IConfigManager"/> with the specified configs registered with initial state.
        /// </summary>
        /// <param name="configFileWriter">An action to set up the config file before config manager initializes.</param>
        /// <param name="envVarWriter">An action to set up the environments before config manager initializes.</param>
        /// <param name="config">Definitions of configs to be registered to the config manager.</param>
        /// <returns>A config manager with initial state, ready to use.</returns>
        internal IConfigManager GetConfigManager(InitSettings settings, params ConfigDefinition[] config)
        {
            var dataStore  = settings?.DataStore ?? new MockDataStore();
            var configPath = settings?.Path ?? Path.GetRandomFileName();
            var environmentVariableProvider = settings?.EnvironmentVariableProvider ?? new MockEnvironmentVariableProvider();

            ConfigInitializer ci = new ConfigInitializer(new List <string>()
            {
                configPath
            })
            {
                DataStore = dataStore,
                EnvironmentVariableProvider = environmentVariableProvider
            };
            IConfigManager icm = ci.GetConfigManager();

            foreach (var configDefinition in config)
            {
                icm.RegisterConfig(configDefinition);
            }
            icm.BuildConfig();
            return(icm);
        }
Ejemplo n.º 18
0
        private Engine()
        {
            // Read config file
            _configuration          = ConfigInitializer.InitConfig();
            _connectionStringCreate = _configuration.GetConnectionString("Create");
            _connectionStringEdit   = _configuration.GetConnectionString("Edit");

            InitializeDb(_connectionStringCreate, _connectionStringEdit);

            UserRepository     userRepositiry     = new UserRepository(_connectionStringEdit);
            ToDoListRepository toDoListRepository = new ToDoListRepository(_connectionStringEdit);

            _userService     = new UserService(userRepositiry);
            _toDoListService = new ToDoListService(toDoListRepository);

            _reader = new ConsoleReader();
            _writer = new ConsoleWriter();

            _userController     = new UserController(_userService, _writer, _reader);
            _toDoListController = new ToDoListController(_toDoListService, _userService, _writer, _reader);

            _menu = new Menu(_writer, _reader, _userController, _toDoListController);
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Initializes and returns an <see cref="IConfigManager"/> with the specified configs registered with initial state.
        /// </summary>
        /// <param name="configFileWriter">An action to set up the config file before config manager initializes.</param>
        /// <param name="envVarWriter">An action to set up the environments before config manager initializes.</param>
        /// <param name="config">Definitions of configs to be registered to the config manager.</param>
        /// <returns>A config manager with initial state, ready to use.</returns>
        protected IConfigManager GetConfigManagerWithInitState(Action <MockDataStore, string> configFileWriter, Action <MockEnvironmentVariableProvider> envVarWriter, params ConfigDefinition[] config)
        {
            if (configFileWriter == null)
            {
                configFileWriter = _noopFileWriter;
            }

            if (envVarWriter == null)
            {
                envVarWriter = _noopEnvVarWriter;
            }

            string configPath    = Path.GetRandomFileName();
            var    mockDataStore = new MockDataStore();

            configFileWriter(mockDataStore, configPath);
            var environmentVariables = new MockEnvironmentVariableProvider();

            envVarWriter(environmentVariables);
            ConfigInitializer ci = new ConfigInitializer(new List <string>()
            {
                configPath
            })
            {
                DataStore = mockDataStore,
                EnvironmentVariableProvider = environmentVariables
            };
            IConfigManager icm = ci.GetConfigManager();

            foreach (var configDefinition in config)
            {
                icm.RegisterConfig(configDefinition);
            }
            icm.BuildConfig();
            return(icm);
        }
Ejemplo n.º 20
0
 public Incident(ConfigInitializer.IncidentTableEntity tableEntity) { this.tableInfo = tableEntity; }
Ejemplo n.º 21
0
 public ChatLog(ConfigInitializer.ChatlogTableEntity tableEntity)
 {
     this.tableInfo = tableEntity;
 }
Ejemplo n.º 22
0
 public void InsertIncidentLevel(ConfigInitializer.LevelTableEntity levelTable, MatchCollection collections, int incidentId)
 {
     string qText = levelTable.ToString();
     var cmd = new SqlCommand(qText, this._connection);
     for (int i = 0; i < 5; i++)
     {
         string tag = collections[i].Groups[1].Value;
         cmd.Parameters.AddWithValue($"@{i + 1}", tag);
     }
     cmd.Parameters.AddWithValue($"@6", incidentId);
     try
     {
         cmd.ExecuteNonQuery();
         Console.WriteLine($" @InsertIncidentLevel : insert {incidentId}");
     }
     catch
     {
         Console.WriteLine("Error happend at @InsertIncidentLevel");
     }
 }