private void frmMain_Load(object sender, EventArgs e) { //ставим черную иконку (загрузка программы) TrayIcons.TrayIcon(TrayIconType.Off, niMain, false); niMain.Text = "IP informer loading..."; this.Hide(); //прячем главное окно //читаем настройки settings = new appSettings(CommonFunctions.SettingsPath + CommonFunctions.AppSettingsFile); if (!settings.LoadConfig()) { //ошибка при загрузке конфигурации TrayIcons.TrayIcon(TrayIconType.Panic, niMain, false); niMain.Text = "Config Error!"; niMain.ShowBalloonTip(5000, "Config Error!", settings.ConfigError, ToolTipIcon.Error); return; } //подключаем события и запускаем следилку WatchIP.Connecting += new Informer.OnConnecting(WatchIP_Connecting); WatchIP.CountryAlarm += new Informer.OnCountryAlarm(WatchIP_CountryAlarm); WatchIP.IPOK += new Informer.OnIPOK(WatchIP_IPOK); WatchIP.NetError += new Informer.OnNetError(WatchIP_NetError); WatchIP.ScriptWarnings += new Informer.OnScriptWarnings(WatchIP_ScriptWarnings); WatchIP.FatalError += new Informer.OnFatalError(WatchIP_FatalError); WatchIP.NewIP += new Informer.OnNewIP(WatchIP_NewIP); WatchIP.StartWatch(); }
void WatchIP_Connecting(object sender) { ScriptWarnings = false; CurrentIcon = TrayIconType.Connecting; BeginInvoke((MethodInvoker) delegate { TrayIcons.TrayIcon(CurrentIcon, niMain, ScriptWarnings); niMain.Text = CommonFunctions.CutTipText(("Connecting...\n" + niMain.Text)); }); }
void WatchIP_IPOK(object sender) { CurrentIcon = TrayIconType.OK; prevNetError = string.Empty; prevPanic = false; PlayAlarm = true; BeginInvoke((MethodInvoker) delegate { TrayIcons.TrayIcon(CurrentIcon, niMain, ScriptWarnings); niMain.Text = CommonFunctions.CutTipText(WatchIP.IPShortInfo); }); }
void WatchIP_ScriptWarnings(object sender, ScriptWarningsEventArgs e) { ScriptWarnings = true; BeginInvoke((MethodInvoker) delegate { TrayIcons.TrayIcon(CurrentIcon, niMain, ScriptWarnings); niMain.Text = CommonFunctions.CutTipText("Script warning: " + e.IP + " " + e.ScriptMessage); niMain.ShowBalloonTip(5000, "Script warning!", e.ScriptMessage, ToolTipIcon.Warning); }); }
//остановка отслеживания пользователем void UserStop(bool FromMenu) { WatchIP.StopWatch(); niMain.ShowBalloonTip(5000, "Внимание!", "Отслеживание IP остановлено пользователем!", ToolTipIcon.Warning); if (FromMenu) //из меню (меняем иконку и подсказку) { TrayIcons.TrayIcon(TrayIconType.Warning, niMain, false); niMain.Text = "IP не отслеживается. Приостановлено пользователем."; } //иначе ничего не меняем, пусть //остаются безмолвным напоминанием mnuStopWatching.Text = "Возобновить"; }
void WatchIP_NetError(object sender) { prevPanic = false; //в любом случае устанавливаем серую иконку, текст подсказки //и отключаем пункты меню с информацией об IP CurrentIcon = TrayIconType.NoNetwork; BeginInvoke((MethodInvoker) delegate { mnuMyIP.Enabled = false; mnuOthIP.Enabled = false; TrayIcons.TrayIcon(CurrentIcon, niMain, ScriptWarnings); niMain.Text = CommonFunctions.CutTipText(WatchIP.ErrorMessage); }); //ошибка уже была и была такая же, уходим if (prevNetError == WatchIP.ErrorMessage) { return; } else { prevNetError = WatchIP.ErrorMessage; } //другая ошибка или первый раз //показываем balloon BeginInvoke((MethodInvoker) delegate { niMain.ShowBalloonTip(5000, "Network Error!", WatchIP.ErrorMessage, ToolTipIcon.Warning); }); //если надо - покажем окошко if (settings.ComNetErr == NetErrorMessage.Window) { BeginInvoke((MethodInvoker) delegate { if (fPanicNet == null) { fPanicNet = new frmPanicNet(); fPanicNet.ErrorMessage = WatchIP.ErrorMessage; fPanicNet.FormPanicNetClosed += new frmPanicNet.OnFormPanicNetClosed(fPanicNet_FormPanicNetClosed); fPanicNet.Show(); } }); } }
void WatchIP_FatalError(object sender) { CurrentIcon = TrayIconType.Panic; BeginInvoke((MethodInvoker) delegate { mnuMyIP.Enabled = false; mnuOthIP.Enabled = false; TrayIcons.TrayIcon(CurrentIcon, niMain, ScriptWarnings); niMain.Text = "Fatal error"; niMain.ShowBalloonTip(5000, "Fatal Error", WatchIP.ErrorMessage, ToolTipIcon.Error); CommonFunctions.ErrMessage(WatchIP.ErrorMessage); WatchIP.StopWatch(); }); }
void ResetWatch() { prevNetError = string.Empty; PlayAlarm = true; prevPanic = false; WatchIP.StopWatch(); System.Threading.Thread.Sleep(1000); if (!settings.LoadConfig()) { //ошибка при загрузке конфигурации TrayIcons.TrayIcon(TrayIconType.Panic, niMain, false); niMain.Text = "Config Error!"; niMain.ShowBalloonTip(5000, "Config Error!", settings.ConfigError, ToolTipIcon.Error); return; } WatchIP.StartWatch(); mnuStopWatching.Text = "Остановить"; }
void CountryWarning(string IP, string Country, string ISOCode) { string msg = "Обнаружен IP нежелательной страны: " + IP + " " + Country + " (" + ISOCode + ")"; CurrentIcon = TrayIconType.Panic; BeginInvoke((MethodInvoker) delegate { TrayIcons.TrayIcon(CurrentIcon, niMain, ScriptWarnings); niMain.Text = CommonFunctions.CutTipText(msg); if (PlayAlarm) { niMain.ShowBalloonTip(5000, "Нежелательный IP", msg, ToolTipIcon.Error); } }); CommonFunctions.PlayAlarmSound(settings.ComAlarmSoundPath, Properties.Resources.panicsound, settings.ComAlarmSound && PlayAlarm); PlayAlarm = false; }