Ejemplo n.º 1
0
        public CommandHistoryModel LoadCommandHistory()
        {
            CommandHistoryModel retVal = null;
            string path         = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            string fullFileName = string.Format("{0}\\{1}", path, "sugarHistory.json");

            try
            {
                String json = "";
                using (StreamReader sr = new StreamReader(fullFileName))
                {
                    json = sr.ReadToEnd();
                }

                retVal = JsonConvert.DeserializeObject <CommandHistoryModel>(json);
            }
            catch (Exception e)
            {
                retVal = new CommandHistoryModel();
                retVal.CommandHistory = new List <string>();

                SaveCommandHistory(retVal);
            }

            return(retVal);
        }
Ejemplo n.º 2
0
        private void SaveCommandHistory(CommandHistoryModel data)
        {
            string json         = JsonConvert.SerializeObject(data, new IsoDateTimeConverter());
            string path         = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            string fullFileName = string.Format("{0}\\{1}", path, "sugarHistory.json");

            json.SaveAsTextFile(fullFileName);
        }
Ejemplo n.º 3
0
        public CommandForm()
        {
            InitializeComponent();
            SetForStartUp();
            InitHotKey();

            commandManager.InitCommands();
            history      = commandManager.LoadCommandHistory();
            historyIndex = history.CommandHistory.Count;

            EventManager.Instance.HideEvent            += Instance_hideEvent;
            EventManager.Instance.ShowEvent            += Instance_ShowEvent;
            EventManager.Instance.MoveEvent            += Instance_MoveEvent;
            EventManager.Instance.SettingsChangedEvent += Instance_SettingsChangedEvent;
            notifyIcon.Text = Application.ProductName + " - MLH Software";
            //this.BackColor = Color.White;
            //this.TransparencyKey = Color.White;
        }
Ejemplo n.º 4
0
        private void ProcessCommand()
        {
            //Save the command in history.
            history      = commandManager.SaveCommandHistory(CommandText);
            historyIndex = history.CommandHistory.Count;

            List <string> command = new List <string>();
            List <string> tmp     = CommandText.Split('▶').ToList <string>();

            foreach (var item in tmp)
            {
                command.Add(item.Trim());
            }

            bool foundCommand = commandManager.ExecuteCommand(command.FirstOrDefault(), command.ToArray());

            if (!foundCommand)
            {
                commandManager.ExecuteCommand(suggestedCommand, command.ToArray());
            }

            commandTextBox.Focus();
        }
Ejemplo n.º 5
0
        public CommandHistoryModel SaveCommandHistory(string command)
        {
            CommandHistoryModel history = LoadCommandHistory();

            if (history == null)
            {
                history = new CommandHistoryModel();
                history.CommandHistory = new List <string>();
            }

            if (!string.IsNullOrEmpty(command) && !history.CommandHistory.Contains(command))
            {
                history.CommandHistory.Add(command);
            }

            if (history.CommandHistory.Count >= 10)
            {
                history.CommandHistory = history.CommandHistory.Skip(Math.Max(0, history.CommandHistory.Count() - 10)).ToList();
            }

            SaveCommandHistory(history);
            return(history);
        }