Beispiel #1
0
        /// <summary>
        ///  Prints help for an fieldAttribute
        /// </summary>
        /// <param name="namespaceAttribute">The fieldAttribute to print help for</param>
        /// <param name="interpreter">The interpreter to use</param>
        /// <param name="showGenericConfigurationInfo"></param>
        public static void PrintConfigurationContextHelp(CmdConfigurationNamespaceAttribute namespaceAttribute,
                                                         BaseInterpreter interpreter,
                                                         bool showGenericConfigurationInfo = false)
        {
            if (showGenericConfigurationInfo)
            {
                ConfigurationGenericHelp(interpreter, Console.WindowWidth, interpreter.TopInterpreter.Options.DefaultIndent);
            }

            ConfigurationNamespaceHelp(namespaceAttribute, Console.WindowWidth, interpreter.TopInterpreter.Options.DefaultIndent);
        }
Beispiel #2
0
        /// <summary>
        ///  Prints generic help about the configuration
        /// </summary>
        /// <param name="interpreter">The current interpreter</param>
        /// <param name="width">The width of the console</param>
        /// <param name="indent">The indent to use</param>
        /// <param name="tw">The Textwriter to write the help to</param>
        public static void ConfigurationGenericHelp(BaseInterpreter interpreter, int width, int indent = 3, TextWriter tw = null)
        {
            tw = tw ?? Console.Out;
            string indentString = new string(' ', indent);

            tw.Write(CommandlineMethods.PadCentered($"Usage of {interpreter.Name}", width));
            string interpreterStringPath = string.Join(" --", interpreter.Path.Select(x => x.Name));     //TODO Clean up this hacky line

            tw.WriteLine($"{interpreterStringPath} NameOfValue help");
            tw.WriteLine(indentString + "Prints help for the field");
            tw.WriteLine($"{interpreterStringPath} NameOfValue get");
            tw.WriteLine(indentString + "Reads the field");
            tw.WriteLine($"{interpreterStringPath} NameOfValue set NewValue");
            tw.WriteLine(indentString + "Sets the field to the value provided");
            //TODO Add add&remove when implemented
        }
Beispiel #3
0
        private GameConsole(Game game, Dungeon dungeon, IEnumerable <ICommandFactory <ConsoleContext <Dungeon> > > thirdPartyFactories) : base(game)
        {
            In = new KeyboardStreamReader(input = new KeyboardStream());
            var s = new StreamWriter(output = new ScreenStream())
            {
                AutoFlush = true
            };

            Out         = s;
            interpreter = new BaseInterpreter(defaultFactories.Concat(thirdPartyFactories), In, Out, input)
            {
                ConsoleContext = new ConsoleContext <Dungeon>(defaultFactories.Concat(thirdPartyFactories), dungeon)
            };
            new Action(async() => await interpreter.Run())();

            LoadResources();
            game.Components.Add(this);
        }
Beispiel #4
0
        public COMMONService()
        {
            InitializeComponent();

            logging.EventLog.GlobalSource = "COMMONService";

            try
            {
                LogManager.InitializeConfigurator("common_log_config.json");
            }
            catch (Exception)
            {
            }

            m_daily_file_writer = new Writer();
            m_shutdown          = new ManualResetEvent(false);

            m_last_configuration_update = DateTimeOffset.MinValue;
            m_system_device             = null;
            m_days_to_keep       = 180;
            m_daily_file_cleaner = new dailyfiles.Cleaner(m_days_to_keep);
            m_db_cleaner         = new db.Cleaner();

            m_responders = new List <Responder>(new Responder[] {
                new EventLogResponder(),
                new DatabaseInfoResponder(),
                new AttributeResponder(),
                new IPAddressResponder(),
                new COMMONDBSizeResponder(),
                new MonitoredDrivesResponder(),
                //new SMARTFailureResponder(),
            });

            m_interpreters = BaseInterpreter.AllInterpreters();

            m_host_configuration = new HostConfiguration()
            {
                UrlReservations = new UrlReservations()
                {
                    CreateAutomatically = true
                }
            };
            m_host = new NancyHost(new Uri("http://localhost:8080"), new COMMONDatabaseBootstrapper(), m_host_configuration);
        }
Beispiel #5
0
        static void Main(string[] args)
        {
            string config_file = null;

            for (int i = 0; i < args.Length; ++i)
            {
                if (args[i] == "-i")
                {
                    if (++i < args.Length)
                    {
                        config_file = args[i];
                    }
                }
            }

            Database db = new Database();

            Console.WriteLine("Initializing Database");
            Initializer initializer = new Initializer(new Initializer.EOptions[] { Initializer.EOptions.SkipSystemCreation });

            initializer.Initialize(db);

            SystemConfiguration config = null;

            using (SQLiteConnection conn = db.Connection)
            {
                conn.Open();

                if (config_file != null)
                {
                    try
                    {
                        Console.WriteLine("Reading config file: " + config_file);
                        FileInfo            fi   = new FileInfo(config_file);
                        string              text = File.ReadAllText(fi.FullName);
                        SystemConfiguration c    = JsonConvert.DeserializeObject <SystemConfiguration>(text);
                        if (c != null)
                        {
                            // There's no timestamp in the file, so about all we can do is use the timestamp
                            // of the file itself.
                            SetSystemConfiguration(c, fi.CreationTime, db);
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Error reading config file");
                        Console.WriteLine(ex.Message);
                    }
                }

                // Get the current configuration from the database, then when we read in a new
                // configuration from the files we'll update the DB.
                config = GetSystemConfiguration(conn);
            }

            Console.WriteLine("Reading Daily Files");

            FileInformationResponder responder = new FileInformationResponder();

            RequestBus.Instance.Subscribe(responder);

            string here   = AppDomain.CurrentDomain.BaseDirectory;
            Reader reader = new Reader(here);
            List <Reader.DailyFileInfo> reports = reader.DoRead();

            // Put the reports in order by day so we process the configuration changes properly.
            reports.Sort((a, b) => a.Day.CompareTo(b.Day));

            // If there's nothing to speak of in the database, such as when we just initialized it,
            // scan through the daily files until we get a SystemConfiguration. That's about the best we can
            // hope for.
            if (config == null ||
                config.devices.Count < 2)
            {
                config = FindConfigInDailyFiles(reports);
            }

            Dictionary <string, DataCollectorContext> collector_id_cache = GetCollectorIDCache(config);

            DataStorage data_storage = new DataStorage();

            BaseInterpreter.AllInterpreters().ForEach(i => data_storage.AddInterpreter(i));

            using (SQLiteConnection conn = db.Connection)
            {
                conn.Open();
                foreach (Reader.DailyFileInfo report in reports)
                {
                    Console.WriteLine($"Loading {report.Info.Name}");

                    Stopwatch watch = Stopwatch.StartNew();
                    int       count = 0;
                    using (SQLiteTransaction t = conn.BeginTransaction())
                    {
                        foreach (DailyReport.Record record in report.Report.records)
                        {
                            if (record.type == ECollectorType.Configuration)
                            {
                                // Deserialize to a SystemConfiguration object, then store that in the DB, and reload the
                                // config from the DB
                                config = JsonConvert.DeserializeObject <SystemConfiguration>(record.value);
                                SetSystemConfiguration(config, record.timestamp, db);
                                collector_id_cache = GetCollectorIDCache(GetSystemConfiguration(conn));
                            }
                            else
                            {
                                if (collector_id_cache.TryGetValue(record.collector, out DataCollectorContext dc_context))
                                {
                                    DataStorage.DataRecord r = new DataStorage.DataRecord(dc_context, record.value, record.timestamp);
                                    r.D.CollectedAt = record.timestamp;
                                    data_storage.Insert(r, conn);
                                    count++;
                                }
                                else
                                {
                                    Console.WriteLine($"Unable to find {record.collector}");
                                }
                            }
                        }
                        t.Commit();
                    }
                    long ms            = watch.ElapsedMilliseconds;
                    long ms_per_record = count == 0 ? ms : ms / count;

                    Console.WriteLine($"Inserting {count} records took {ms} ms, at {ms_per_record} ms per record");
                }
            }
        }
 /// <summary>
 ///  Prints help for a context
 /// </summary>
 /// <param name="context">The context to print help</param>
 /// <param name="interpreter">The interpreter to use</param>
 public static void PrintContextHelp(CmdContextAttribute context, BaseInterpreter interpreter) =>
 ContextHelp(context, Console.WindowWidth, interpreter.TopInterpreter.Options.DefaultIndent);
 /// <summary>
 ///  Prints help for an action
 /// </summary>
 /// <param name="action">The action to print help for</param>
 /// <param name="interpreter">The interpreter to use</param>
 public static void PrintActionHelp(CmdActionAttribute action, BaseInterpreter interpreter) =>
 ActionHelp(action, Console.WindowWidth, interpreter.TopInterpreter.Options.DefaultIndent);