예제 #1
0
        private void SetStateAndLastCheck()
        {
            ServiceActivity activity = ActivityDAO.GetActivityData();

            if (!activity.IsSucceeded)
            {
                lblLastCheck.Text    = "n/a";
                lblCurrentState.Text = "n/a";

                progressBar1.ProgressText = "";
                progressBar1.Value        = 0;
                if (!isLastConnectionFailed)
                {
                    isLastConnectionFailed = true;
                    Program.ShowMessageBox("Unable to establish DB connection. Check Database settings.");
                    listView1.Items[2].Selected = true;
                    listView1.Items[2].Focused  = true;
                    listView1.Select();
                }

                return;
            }

            isLastConnectionFailed = false;
            lblLastCheck.Text      = activity.LastCheck.ToString(@"M/d/yyyy hh:mm:ss tt");
            lastCheckDate          = activity.LastCheck;

            bool bWorkingState = (activity.WorkingState &&
                                  (lblCurrentStatus.Text == ServiceControllerStatus.Running.ToString()));

            lblCurrentState.Text = bWorkingState ? "Working" : "Idle";

            if (bWorkingState)
            {
                if (progressBar1.Maximum != activity.TotalProgress)
                {
                    progressBar1.Maximum = activity.TotalProgress;
                    progressBar1.Value   = 0;
                }

                progressBar1.ProgressText = activity.PassedProgress + " out of " + activity.TotalProgress + "...";
                progressBar1.Value        = activity.PassedProgress;
            }
            else
            {
                progressBar1.ProgressText = "";
                progressBar1.Value        = 0;
            }
        }
예제 #2
0
        private static ServiceActivity GetActivityData(string connStr)
        {
            ServiceActivity activity = new ServiceActivity();

            try
            {
                using (DbConnection connection = new OracleConnection(Connect.DecryptMaster(connStr)))
                {
                    connection.Open();

                    const string strQuery =
                        "WITH STAT AS (SELECT FINISHED, COUNT(1) AS CNT FROM (SELECT  DECODE(STATUS, 'SUCCEEDED', 1, 'FAILED', 1, 'AWAITING', DECODE(ATTEMPTS, (SELECT MAX_ATTEMPTS FROM " +
                        Program.SchemaName + ".ILC_INSTANCE), 1, 0), 0) AS FINISHED FROM " + Program.SchemaName + ".SERVICE_VERIFICATION INNER JOIN " +
                        Program.SchemaName + ".SERVICE_VERIFICATION_SESSION ON SERVICE_VERIFICATION.REPORT_ID=SERVICE_VERIFICATION_SESSION.REPORT_ID AND SERVICE_VERIFICATION_SESSION.IS_REPORTED=0) S GROUP BY FINISHED) " +
                        "SELECT START_TIME, IS_REPORTED, NVL((SELECT CNT FROM STAT WHERE FINISHED=0), 0) AS REMAINING, NVL((SELECT CNT FROM STAT WHERE FINISHED=1), 0) AS FINISHED FROM " +
                        Program.SchemaName + ".SERVICE_VERIFICATION_SESSION";

                    using (DbCommand cmd = connection.CreateCommand())
                    {
                        cmd.CommandType = CommandType.Text;
                        cmd.CommandText = strQuery;

                        int remained = 0;

                        using (DbDataReader reader = cmd.ExecuteReader())
                        {
                            if (reader.Read())
                            {
                                activity.LastCheck    = (DateTime)reader[0];
                                activity.WorkingState = Convert.ToInt32(reader[1]) == 0;
                                remained = Convert.ToInt32(reader[2]);
                                activity.PassedProgress = Convert.ToInt32(reader[3]);

                                activity.IsSucceeded = true;
                            }
                        }

                        activity.TotalProgress = remained + activity.PassedProgress;
                    }
                }
            }
            catch (Exception)
            {
                activity.IsSucceeded = false;
            }

            return(activity);
        }
예제 #3
0
        private static void ShowBalloon(object sender, MouseEventArgs e)
        {
            if (!isBalloonShown && !notifyIcon.ContextMenuStrip.Visible)
            {
                StringBuilder strBalloon = new StringBuilder();
                strBalloon.AppendLine("Current service status  " + serviceController.Status);
                ServiceActivity activity = ActivityDAO.GetActivityData();

                strBalloon.AppendLine("Time when service ran the last check  " +
                                      (activity.IsSucceeded ? activity.LastCheck.ToString(@"M/d/yyyy hh:mm:ss tt") : "n/a"));
                if (!activity.IsSucceeded)
                {
                    strBalloon.AppendLine("Current state  n/a");
                }
                else
                {
                    if ((activity.WorkingState &&
                         (serviceController.Status == ServiceControllerStatus.Running)))
                    {
                        strBalloon.AppendLine("Current state  Working: " +
                                              activity.PassedProgress + " out of " + activity.TotalProgress + "...");
                    }
                    else
                    {
                        strBalloon.AppendLine("Current state  Idle");
                    }
                }

                string        path   = Utils.ServiceInfo.GetServicePath();
                Configuration config = Utils.ServiceInfo.GetServiceConfig(path);
                if (config.AppSettings.Settings["EmailServerName"] != null)
                {
                    strBalloon.AppendLine("SMTP/Exchange server name/IP  " + config.AppSettings.Settings["EmailServerName"].Value);
                }

                string sBalloon = strBalloon.ToString();

                balloonPosition = Cursor.Position;
                notifyIcon.ShowBalloonTip(5000, "Service information",
                                          sBalloon,
                                          ToolTipIcon.Info);

                isBalloonShown = true;
            }
        }