Example #1
0
        public MainHiddenForm()
        {
            InitializeComponent();

            button = new CanFocusButton();
            button.State = ButtonState.Red;
            button.AutoManageButton = false;

            button.ConnectedChanged += button_ConnectedChanged;
            button.ButtonPress += button_ButtonPress;

            SetNotifyIcon();

            using (var regKey = Registry.CurrentUser.CreateSubKey(registryKey, RegistryKeyPermissionCheck.ReadWriteSubTree))
            {

                var tmp = regKey.GetValue("StartDate", DateTime.MinValue.ToBinary());

                if (tmp != null)
                {
                    var start = DateTime.FromBinary((long)tmp);
                    var action = (string)regKey.GetValue("ActionState", "");
                    var info = (string)regKey.GetValue("ActionInfo", "");

                    if (start.Date == DateTime.Now.Date)
                    {
                        var result = MessageBox.Show("Would you like to continue the " + action + " that you started at " + start + "?", "Resume task", MessageBoxButtons.YesNo);

                        if (result == System.Windows.Forms.DialogResult.Yes)
                        {
                            startDate = start;
                            startInfo = info;
                            currentState = (ActionState)Enum.Parse(typeof(ActionState), action);
                        }

                    }
                }

                SetNotifyIcon();

                var ctx = (string)regKey.GetValue("UserContext", null);
                if (ctx != null)
                {
                    userContext = new UserContext(ctx);

                    //validate that the context is still good
                    currentUser = User.GetCurrentUser(userContext);
                    if (currentUser == null) //nope
                        userContext = null;
                }

                if(userContext == null)
                {
                    using (var dlg = new Genome.LoginForm())
                    {
                        var result = dlg.ShowDialog();

                        if (result == System.Windows.Forms.DialogResult.OK)
                        {
                            userContext = dlg.UserContext;
                            regKey.SetValue("UserContext", userContext.ToString());
                        }

                    }
                }

            }

            button.State = ButtonState.Green;
            SetNotifyIcon();
        }
Example #2
0
 private void quitToolStripMenuItem_Click(object sender, EventArgs e)
 {
     closing = true;
     button.Dispose();
     button = null;
     Application.Exit();
 }