Beispiel #1
0
        public NotificationIcon()
        {
            Config.Load();
            alarmStatus = AlarmEnum.None;

            notificationMenu = new ContextMenu(
                new MenuItem[]
            {
                new MenuItem("Setting", MenuSetting),
                new MenuItem("Exit", MenuExitClick)
            });

            notifyIcon = new NotifyIcon
            {
                ContextMenu = notificationMenu,
                Visible     = true
            };

            SFXConnectionLost = new SoundPlayer();
            SFXTimeOut        = new SoundPlayer();
            SFXResumed        = new SoundPlayer();

            var apppath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);

            originalImage = Image.FromFile(System.IO.Path.Combine(apppath, "Resources\\none.png"));
            drawable      = Properties.Resources.none;
            hiconOriginal = Properties.Resources.none.GetHicon();
            noneIcon      = Icon.FromHandle(hiconOriginal);
            g             = Graphics.FromImage(drawable);
            font          = new Font("Consolas", 9f, FontStyle.Bold);
            font100       = new Font("Consolas", 7f, FontStyle.Bold);;
            SetIcon();
        }
Beispiel #2
0
        public NotificationIcon()
        {
            Config.Load();
            alarmStatus = AlarmEnum.None;

            notificationMenu = new ContextMenu(
                new MenuItem[]
            {
                new MenuItem("Setting", MenuSetting),
                new MenuItem("Exit", MenuExitClick)
            });

            notifyIcon = new NotifyIcon
            {
                ContextMenu = notificationMenu,
                Visible     = true
            };

            originalImage = Image.FromFile("Resources\\none.png");
            drawable      = Properties.Resources.none;
            hiconOriginal = Properties.Resources.none.GetHicon();
            noneIcon      = Icon.FromHandle(hiconOriginal);
            g             = Graphics.FromImage(drawable);
            font          = new Font("Consolas", 9f, FontStyle.Bold);
            SetIcon();
        }
Beispiel #3
0
        protected AlarmTypeModel GenerateAlarmTypeModel(AlarmEnum type)
        {
            AlarmTypeModel output = new AlarmTypeModel()
            {
                AlarmType     = type,
                AlarmTypeName = AlarmTypeNameObtainer.GetAlarmName(type),
                AddThisAlarm  = true,
                ActivateAlarm = true,
            };

            return(output);
        }
        public static string GetAlarmName(AlarmEnum type)
        {
            switch (type)
            {
            case AlarmEnum.Bin: return("Binary alarm");

            case AlarmEnum.ElecProt: return("Electrical protection activation");

            case AlarmEnum.Contactor: return("Contactor failure");

            case AlarmEnum.Overload: return("Overload protection");

            case AlarmEnum.Isolator: return("Isolator activation");

            case AlarmEnum.Inverter: return("Inverter failure");

            case AlarmEnum.Run: return("Inverter not running");

            case AlarmEnum.Position: return("Wrong position");

            case AlarmEnum.Maintenance: return("Maintenance");

            case AlarmEnum.Break: return("Sensor break");

            case AlarmEnum.HHDeviation: return("High deviation");

            case AlarmEnum.LLDeviation: return("Low d eviation");

            case AlarmEnum.HighHigh: return("High high");

            case AlarmEnum.High: return("High");

            case AlarmEnum.LowLow: return("Low low");

            case AlarmEnum.Low: return("Low");

            default: return("Default alarm");
            }
        }
Beispiel #5
0
        // Ping on thread pool
        private void PingPool(object _)
        {
            Thread.Sleep(999);

            try
            {
                var    p      = new Ping();
                byte[] buffer = new byte[4];

                // I have so much bad Internet that the timeout alarm goes out all the time. So, check twice.
                bool timeOutAgain = false;

                for (; ;)
                {
                    try
                    {
                        PingReply reply = p.Send(Config.TheIPAddress, 5000, buffer);

                        switch (reply.Status)
                        {
                        case IPStatus.TimedOut:
                            DrawGraph(-1L);

                            if (timeOutAgain)
                            {
                                notifyIcon.Text = "Status: Time out";
                                if (alarmStatus == AlarmEnum.OK)
                                {
                                    if (Config.AlarmTimeOut)
                                    {
                                        notifyIcon.ShowBalloonTip(BALLOON_TIP_TIME_OUT, "PingoMeter", "Ping time out", ToolTipIcon.Warning);
                                    }

                                    PlaySound(SFXTimeOut, Config.SFXTimeOut);
                                }

                                alarmStatus = AlarmEnum.TimeOut;
                            }
                            else
                            {
                                notifyIcon.Text = "Status: Time out?";
                                timeOutAgain    = true;
                            }
                            break;

                        case IPStatus.Success:
                            DrawGraph(reply.RoundtripTime);

                            if (alarmStatus != AlarmEnum.None && alarmStatus != AlarmEnum.OK)
                            {
                                PlaySound(SFXResumed, Config.SFXResumed);

                                if (Config.AlarmResumed)
                                {
                                    notifyIcon.ShowBalloonTip(BALLOON_TIP_TIME_OUT, "PingoMeter", "Ping resumed", ToolTipIcon.Info);
                                }
                            }

                            alarmStatus  = AlarmEnum.OK;
                            timeOutAgain = false;
                            break;

                        default:

                            DrawGraph(-1L);
                            var statusName = GetIPStatusName(reply.Status);
                            notifyIcon.Text = "Status: " + statusName;



                            if (alarmStatus != AlarmEnum.ConnectionLost)
                            {
                                PlaySound(SFXConnectionLost, Config.SFXConnectionLost);

                                if (Config.AlarmConnectionLost)
                                {
                                    notifyIcon.ShowBalloonTip(BALLOON_TIP_TIME_OUT, "PingoMeter", statusName, ToolTipIcon.Error);
                                }
                            }

                            alarmStatus = AlarmEnum.ConnectionLost;
                            break;
                        }
                    }
                    catch (PingException)
                    {
                        DrawGraph(-1L);
                        notifyIcon.Text = "Status: Connection lost.";

                        if (alarmStatus != AlarmEnum.ConnectionLost)
                        {
                            PlaySound(SFXConnectionLost, Config.SFXConnectionLost);

                            if (Config.AlarmConnectionLost)
                            {
                                notifyIcon.ShowBalloonTip(BALLOON_TIP_TIME_OUT, "PingoMeter", "Connection lost", ToolTipIcon.Error);
                            }
                        }

                        alarmStatus = AlarmEnum.ConnectionLost;
                    }
                    catch (Exception ex)
                    {
                        DrawGraph(-1L);
                        notifyIcon.Text = ex.Message;
                        notifyIcon.Text = "Status: Error.";

                        notifyIcon.ShowBalloonTip(BALLOON_TIP_TIME_OUT, "PingoMeter", "Error: " + ex.Message, ToolTipIcon.Error);
                        alarmStatus = AlarmEnum.None;
                    }

                    Thread.Sleep(Config.Delay);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "PingoMeter crash log");
                alarmStatus = AlarmEnum.None;
            }
        }
Beispiel #6
0
        // Ping on thread pool
        private void PingPool(object _)
        {
            Thread.Sleep(999);

            try
            {
                var    p      = new Ping();
                byte[] buffer = new byte[4];

                // У меня на столько хреновый интернет, что timeout вылазиет постоянно.
                // Так что нужно проверять дважды. (for bad internet)
                bool timeOutAgain = false;

                for (; ;)
                {
                    try
                    {
                        PingReply reply = p.Send(Config.TheIPAddress, 5000, buffer);

                        switch (reply.Status)
                        {
                        case IPStatus.TimedOut:
                            DrawGraph(-1L);

                            if (timeOutAgain)
                            {
                                notifyIcon.Text = "Status: Time out";
                                if (alarmStatus == AlarmEnum.OK && Config.AlarmTimeOut)
                                {
                                    notifyIcon.ShowBalloonTip(BALLOON_TIP_TIME_OUT, "PingoMeter", "Ping time out", ToolTipIcon.Warning);
                                }

                                alarmStatus = AlarmEnum.TimeOut;
                            }
                            else
                            {
                                notifyIcon.Text = "Status: Time out?";
                                timeOutAgain    = true;
                            }
                            break;

                        case IPStatus.Success:
                            DrawGraph(reply.RoundtripTime);

                            if (alarmStatus != AlarmEnum.None && alarmStatus != AlarmEnum.OK && Config.AlarmResumed)
                            {
                                notifyIcon.ShowBalloonTip(BALLOON_TIP_TIME_OUT, "PingoMeter", "Ping resumed", ToolTipIcon.Info);
                            }

                            alarmStatus  = AlarmEnum.OK;
                            timeOutAgain = false;
                            break;

                        default:
                            DrawGraph(-1L);
                            var statusName = GetIPStatusName(reply.Status);
                            notifyIcon.Text = "Status: " + statusName;

                            if (alarmStatus != AlarmEnum.ConnectionLost && Config.AlarmConnectionLost)
                            {
                                notifyIcon.ShowBalloonTip(BALLOON_TIP_TIME_OUT, "PingoMeter", statusName, ToolTipIcon.Error);
                            }

                            alarmStatus = AlarmEnum.ConnectionLost;
                            break;
                        }
                    }
                    catch (PingException)
                    {
                        DrawGraph(-1L);
                        notifyIcon.Text = "Status: Connection lost.";

                        if (alarmStatus != AlarmEnum.ConnectionLost && Config.AlarmConnectionLost)
                        {
                            notifyIcon.ShowBalloonTip(BALLOON_TIP_TIME_OUT, "PingoMeter", "Connection lost", ToolTipIcon.Error);
                        }

                        alarmStatus = AlarmEnum.ConnectionLost;
                    }
                    catch (Exception ex)
                    {
                        DrawGraph(-1L);
                        notifyIcon.Text = ex.Message;
                        notifyIcon.Text = "Status: Error.";

                        notifyIcon.ShowBalloonTip(BALLOON_TIP_TIME_OUT, "PingoMeter", "Error: " + ex.Message, ToolTipIcon.Error);

                        alarmStatus = AlarmEnum.None;
                    }

                    Thread.Sleep(Config.Delay);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "PingoMeter crash log");
                alarmStatus = AlarmEnum.None;
            }
        }
Beispiel #7
0
 protected abstract byte GenerateBitForAckTag(int startByte, AlarmEnum alarmType);
Beispiel #8
0
 protected abstract int GenerateByteForAckTag(int startByte, AlarmEnum alarmType);