Esempio n. 1
0
        public void Initialize()
        {
            m_Notify = new NotifyIcon();
            m_Notify.Visible = true;
            m_Notify.Icon = SystemIcons.Application;
            m_Notify.ContextMenu = new ContextMenu(new MenuItem[] { new MenuItem("Exit", tsmiQuit_Click) });
            m_Notify.MouseDoubleClick += NotifyIcon_MouseDoubleClick;

            try
            {
                string folderPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), SETTINGS_FOLDER_NAME);
                if (!Directory.Exists(folderPath))
                {
                    Directory.CreateDirectory(folderPath);
                    WriteSettings(new ConnectionSettings());
                }

                m_Settings = LoadSettings();
            }
            catch (IOException ex)
            {
                MessageBox.Show(ex.Message);
            }
            catch (JsonSerializationException ex)
            {
                MessageBox.Show("Error interpreting settings. Clearing.");
                WriteSettings(new ConnectionSettings());
                m_Settings = new ConnectionSettings();
            }

            btnStart.Enabled = !(m_Settings == null || !m_Settings.IsValid);
            btnStop.Enabled = false;
        }
        public ConnectionForm(ConnectionSettings settings)
        {
            m_Settings = settings ?? new ConnectionSettings();
            InitializeComponent();

            tbSlackKey.Text = m_Settings.SlackKey ?? "";
            tbAddress.Text = m_Settings.Address != null ? m_Settings.Address.ToString() : "";
            tbPort.Text = m_Settings.Port.ToString();
        }
Esempio n. 3
0
        private void WriteSettings(ConnectionSettings settings)
        {
            try
            {
                string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Arma Slack Bot", "settings.json");
                string data = JsonConvert.SerializeObject(settings);

                FileStream fStream = new FileStream(path, File.Exists(path) ? FileMode.Truncate : FileMode.Create);
                StreamWriter writer = new StreamWriter(fStream);
                writer.Write(data);
                writer.Flush();
                writer.Close();
                fStream.Close();
            }
            catch (IOException ex)
            {
                MessageBox.Show(ex.Message);
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Esempio n. 4
0
 void connectionForm_FormClosed(object sender, FormClosedEventArgs e)
 {
     ConnectionForm form = (ConnectionForm)sender;
     if (form.Accepted)
     {
         m_Settings = form.Settings;
         WriteSettings(m_Settings);
         if(m_Settings.Address != null && !string.IsNullOrEmpty(m_Settings.SlackKey) && (m_Bot == null || !m_Bot.IsConnected))
             btnStart.Enabled = true;
     }
 }