/// <summary> /// Запускает приложение. /// </summary> /// <exception cref="System.Exception"> /// </exception> public void RunApp() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); receiver = new MsgReceiver(); notifier = new Notifier(); brain = new Brain(); unreadMessagesForm = new AllMessagesForm(); if (!notifier.InitNotifier()) throw new Exception(); if (brain.LoadSettings()) if(!string.IsNullOrEmpty(brain.Login)) receiver.LogInVk(brain.Login, brain.Password); if (!receiver.IsLogged()) { ShowLoginWindow(); // Случай, когда пользователь просто закрыл окно входа if (!receiver.IsLogged()) { notifier.ShowAuthError(); brain.Login = ""; brain.Password = ""; } } else notifier.ShowDefault(); SetupNotifyIconMenus(); if (!notifier.SetContextMenu(contextMenu)) throw new Exception(); if (!notifier.SetLaunchCallback(LaunchCallback)) throw new Exception(); if (!brain.InitBrain(receiver, notifier, unreadMessagesForm)) throw new Exception(); appTimer = new System.Timers.Timer(5000); appTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent); appTimer.Enabled = true; Application.ApplicationExit += AppExitEvent; Application.Run(); }
/// <summary> /// Initializes a new instance of the <see cref="Form1"/> class. /// </summary> /// <exception cref="System.Exception"> /// </exception> public Form1() { InitializeComponent(); this.FormClosing += Form1_FormClosing; receiver = new MsgReceiver(); notifier = new Notifier(); brain = new Brain(); unreadMessagesForm = new AllMessagesForm(); if (!notifier.InitNotifier()) throw new Exception(); if (brain.LoadSettings()) if (!string.IsNullOrEmpty(brain.Login)) receiver.LogInVk(brain.Login, brain.Password); if (!receiver.IsLogged()) { ShowLoginWindow(); // Случай, когда пользователь просто закрыл окно входа if (!receiver.IsLogged()) { notifier.ShowAuthError(); brain.Login = ""; brain.Password = ""; } } else notifier.ShowDefault(); SetupNotifyIconMenus(); if (!notifier.SetContextMenu(contextMenu)) throw new Exception(); if (!notifier.SetLaunchCallback(LaunchCallback)) throw new Exception(); if (!brain.InitBrain(receiver, notifier, unreadMessagesForm)) throw new Exception(); }