Пример #1
0
        private static void WriteIntoTheStorage(ILog log, CentralinoConfiguration centralinoConfiguration, CentralinoLines allLines)
        {
            log.Info($"Starting to write all lines on storage {centralinoConfiguration.DbConfiguration.ConnectionString}");

            (IEnumerable <Seq <Error> > errors, IEnumerable <ICentralinoLine> lines) = allLines.Lines.Partition();

            DbSerializer dbSerializer = DbSerializer.From(centralinoConfiguration);

            dbSerializer.WriteAll(lines);

            foreach (Seq <Error> error in errors)
            {
                log.Warn(ErrorToString(error));
            }
            log.Info($"End of writing to the storage {centralinoConfiguration.DbConfiguration.ConnectionString}");
        }
Пример #2
0
 public static void Main(string[] args)
 {
     if (args.Length > 0)
     {
         var log = ConfigureLogging();
         log.Info("Starting ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
         try
         {
             FromConfigReadCentralinoAndWriteInStorage(args, log);
         }
         catch (Exception e)
         {
             log.Error($"Unexpected error: {e.Message}", e);
         }
         log.Info("Ending ####################################################################");
     }
     else
     {
         CentralinoConfiguration.FromCommanLine(new[] { "--help" });
     }
 }
Пример #3
0
        public static DbSerializer From(CentralinoConfiguration configuration)
        {
            CentralinoDbContext db;

            switch (configuration.DbConfiguration.Db)
            {
            case DbEnum.SqlServer:
                db = new SqlServerDbContext(configuration.DbConfiguration);
                break;

            case DbEnum.MySql:
                db = new MySqlDbContext(configuration.DbConfiguration);
                break;


            default:
                db = new SqlServerDbContext(configuration.DbConfiguration);
                break;
            }

            return(new DbSerializer(db, configuration.Sede));
        }
Пример #4
0
        private static CentralinoLines ReadFromCentralino(CentralinoReader centralinoReader, ILog log, CentralinoConfiguration centralinoConfiguration)
        {
            log.Info($"Starting to read lines from centralino {centralinoConfiguration.Host}:{centralinoConfiguration.Port}");
            var task = centralinoReader.ReadAllLines();

            task.Wait();
            CentralinoLines allLines = task.Result;

            log.Info($"Read {allLines.Lines.Length} lines from centralino {centralinoConfiguration.Host}:{centralinoConfiguration.Port}");
            return(allLines);
        }
Пример #5
0
        private static Unit ReadFromCentralinoAndWrite(CentralinoReader centralinoReader, ILog log, CentralinoConfiguration centralinoConfiguration)
        {
            try
            {
                log.Info($"Configuration: {centralinoConfiguration}");

                var allLines = ReadFromCentralino(centralinoReader, log, centralinoConfiguration);
                WriteIntoTheStorage(log, centralinoConfiguration, allLines);
            }
            catch (Exception e)
            {
                log.Error($"Unexpected error: {e.Message}", e);
            }

            return(Unit.Default);
        }
Пример #6
0
 private static void FromConfigReadCentralinoAndWriteInStorage(string[] args, ILog log)
 {
     CentralinoConfiguration
     .FromCommanLine(args)
     .Map(configuration => ReadFromCentralinoAndWrite(new CentralinoReader(configuration), log, configuration));
 }