Esempio n. 1
0
        public Form1(string arg)
        {
            InitializeComponent();
            dataTable = new DataTable();
            dataTable.Columns.Add("用户名");
            dataTable.Columns.Add("论坛");
            dataTable.Columns.Add("当前状态");
            dataTable.Columns.Add("上次连接时间");
            userDataGridView.DataSource              = dataTable;
            userDataGridView.AllowUserToAddRows      = false;
            userDataGridView.AllowUserToDeleteRows   = false;
            userDataGridView.AllowUserToOrderColumns = true;
            userDataGridView.ReadOnly            = true;
            userDataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
            userDataGridView.ColumnHeadersDefaultCellStyle.WrapMode = DataGridViewTriState.False;
            userDataGridView.RowHeadersVisible = false;
            userDataGridView.MultiSelect       = false;
            userDataGridView.SelectionMode     = DataGridViewSelectionMode.FullRowSelect;
            notifyIcon1.Visible = false;
            stopButton.Enabled  = false;

            _core = new KeeperCore();

            _users = UserManager.GetUsersFromDb();
            _users.ForEach(p =>
            {
                var model       = _core.AddKeeper(p.KeeperKey, p.KeeperInitKey);
                p.KeeperModel   = model;
                p.KeeperKey     = model.Key;
                p.KeeperInitKey = model.InitKey;
                p.KeeperName    = _core.LoadedKeepers.Find(q => q.Key == model.Key)?.Name;
            });
            //todo users to keepers

            RefreshUserDataGridView();

            FormClosed += delegate
            {
                System.Environment.Exit(0);
            };

            if (arg?.ToLower() == "run")
            {
                Start();
            }
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            Parser.Default.ParseArguments <Options>(args).WithParsed(o =>
            {
                if (o.PluginDirecotry != null)
                {
                    var path = Path.GetFullPath(o.PluginDirecotry);
                    if (!Directory.Exists(path))
                    {
                        throw new DirectoryNotFoundException("Plugins folder is not found");
                    }
                    Configurations.PluginsPath = path;
                }
            });

            Console.WriteLine("Loading Plugins");
            var keeperCore = new KeeperCore();

            Console.WriteLine("Plugins Loaded");

            var command = "";

            command = Console.ReadLine();
            var lowerCommand = command?.ToLower();

            while (lowerCommand != "exit" || lowerCommand != "quit")
            {
                try
                {
                    var subCommands = command.Split(' ');
                    var mainCommand = subCommands[0].ToLower();
                    if (mainCommand == "add")
                    {
                        if (subCommands.Length < 3)
                        {
                            throw new ArgumentException("add [key] [initKey]");
                        }

                        var key     = subCommands[1];
                        var initKey = new StringBuilder();
                        for (var i = 2; i < subCommands.Length; i++)
                        {
                            initKey.Append(subCommands[i]);
                        }

                        keeperCore.AddKeeper(key, initKey.ToString());
                    }
                    else if (mainCommand == "start")
                    {
                        keeperCore.Start();
                    }
                    else if (mainCommand == "stop")
                    {
                        keeperCore.Stop();
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
                finally
                {
                    command      = Console.ReadLine();
                    lowerCommand = command?.ToLower();
                }
            }
        }