/// <summary>
        /// Check Message Queue for Exchange if not there and check the MSMQ service is running
        /// if not running start it and create queue.else if service is already running create the queue simply.
        /// <Author>Vineetha Mathew</Author>
        /// <DateCreated>Date Created 11-Dec-2008</DateCreated>
        /// <param name=strMSMQExchangepath>string</param>
        /// <returns>true</returns>
        /// </summary>
        /// Method Revision History
        ///
        /// Author             Date              Description
        /// ---------------------------------------------------
        ///Vineetha Mathew      11-12-2008      Created
        public static bool CreateMSMQ(string strMSMQExchangepath)
        {
            bool          bMSMQServiceStatus   = false;
            DataTable     dtMSMQServicesStatus = new DataTable();
            BMCMonitoring objBMCMonitoring     = new BMCMonitoring();
            bool          bReturn = false;

            try
            {
                dtMSMQServicesStatus = objBMCMonitoring.GetServiceStatus("MSMQ", BMCMonitoring.ServiceTypes.All);

                if (dtMSMQServicesStatus.Rows.Count > 0)
                {
                    for (int i = 0; i < dtMSMQServicesStatus.Rows.Count; i++)
                    {
                        if (dtMSMQServicesStatus.Rows[i][0].ToString() == "MSMQ" && dtMSMQServicesStatus.Rows[i][1].ToString() == "Stopped")
                        {
                            bMSMQServiceStatus = objBMCMonitoring.StartService("MSMQ");
                            if (bMSMQServiceStatus == true)
                            {
                                System.Threading.Thread.Sleep(5000);
                                MessageQueue.Create(strMSMQExchangepath, true);
                                MessageQueue objMessagqQueue = new MessageQueue(strMSMQExchangepath);
                                objMessagqQueue.SetPermissions("Everyone", MessageQueueAccessRights.FullControl);
                                bReturn = true;
                                break;
                            }
                        }
                        else if (dtMSMQServicesStatus.Rows[i][0].ToString() == "MSMQ" && dtMSMQServicesStatus.Rows[i][1].ToString() == "Running")
                        {
                            MessageQueue.Create(strMSMQExchangepath, true);
                            MessageQueue objMessagqQueue = new MessageQueue(strMSMQExchangepath);
                            objMessagqQueue.SetPermissions("Everyone", MessageQueueAccessRights.FullControl);
                            bReturn = true;
                            break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LogManager.WriteLog("CreateMSMQ" + ex.Message.ToString() + ex.Source.ToString(), LogManager.enumLogLevel.Error);
                ExceptionManager.Publish(ex);
                bReturn = false;
            }
            return(bReturn);
        }
Exemple #2
0
        private void GetServiceStatus()
        {
            BMCMonitoring objBMCMonitoring = new BMCMonitoring();
            DataTable     dtServicesStatus = new DataTable();
            StringBuilder strServicelist   = new StringBuilder();
            //Rectangle itemBoundRectangle = new Rectangle(0, 0, 0, 0);
            ListViewItem itemListview = new ListViewItem();

            string[] strListarray = null;
            try
            {
                strListarray = ConfigManager.Read("ServicesList").ToString().Split(',');
                if (strListarray != null)
                {
                    for (int i = 0; i < strListarray.Length; i++)
                    {
                        strServicelist.Append(strListarray[i].ToString() + ",");
                    }
                }
                dtServicesStatus = objBMCMonitoring.GetServiceStatus(strServicelist.ToString(), BMCMonitoring.ServiceTypes.All);
                string strServiceStatus   = string.Empty;
                string strServiceStatus1  = string.Empty;
                bool   blnFoundNotRunning = false;
                int    ServiceCount       = dtServicesStatus.Rows.Count / 2;
                int    RowCount           = 0;
                if (dtServicesStatus.Rows.Count > 0)
                {
                    SetListviewItemStyle("Services", 0);
                    foreach (DataRow dr in dtServicesStatus.Rows)
                    {
                        if (!blnFoundNotRunning && dr["Status"].ToString().ToUpper().Trim() != "RUNNING")
                        {
                            SetListviewItemStyle("Services", 1);
                            SetListviewItemStyle("Services1", -1);
                            blnFoundNotRunning = true;
                        }
                        if (RowCount > ServiceCount)
                        {
                            strServiceStatus1 += dr["ServiceName"].ToString() + ":" + dr["Status"].ToString() + "; ";
                        }
                        else
                        {
                            strServiceStatus += dr["ServiceName"].ToString() + ":" + dr["Status"].ToString() + "; ";
                        }
                        RowCount++;
                    }

                    if (lvGoLive.Items["Services"].SubItems.Count > 2)
                    {
                        lvGoLive.Items["Services"].SubItems[2].Text = strServiceStatus;
                    }
                    else
                    {
                        lvGoLive.Items["Services"].SubItems.Add(strServiceStatus);
                    }
                    if (!string.IsNullOrEmpty(strServiceStatus1))
                    {
                        if (lvGoLive.Items["Services1"].SubItems.Count > 2)
                        {
                            lvGoLive.Items["Services1"].SubItems[2].Text = strServiceStatus1;
                        }
                        else
                        {
                            lvGoLive.Items["Services1"].SubItems.Add(strServiceStatus1);
                        }
                    }
                    else
                    {
                        lvGoLive.Items["Services1"].Remove();
                    }
                }
                #region unused code
                //if (dtServicesStatus.Rows.Count > 0)
                //{
                //    for (int j = 0; j < dtServicesStatus.Columns.Count; j++)
                //    {
                //        for (int i = 0; i < dtServicesStatus.Rows.Count; i++)
                //        {
                //            if (j != dtServicesStatus.Columns.Count - 1)
                //            {
                //                if (dtServicesStatus.Rows[i][j + 1].ToString() == "Stopped")
                //                {
                //                    lvGoLive.Items["Services"].ImageIndex = 1;

                //                    if (lvGoLive.Items["Services"].SubItems.Count > 2)
                //                    {
                //                        lvGoLive.Items["Services"].SubItems[2].Text = lvGoLive.Items["Services"].SubItems[2].Text + ";" + dtServicesStatus.Rows[i][j].ToString() +" Service is in Stopped State";
                //                    }
                //                    else
                //                    {
                //                        lvGoLive.Items["Services"].SubItems.Add(dtServicesStatus.Rows[i][j].ToString() + " Service is in Stopped State");

                //                    }
                //                }
                //                 else if (dtServicesStatus.Rows[i][j + 1].ToString() == "Pending")
                //                {
                //                    lvGoLive.Items["Services"].ImageIndex = 1;

                //                    if (lvGoLive.Items["Services"].SubItems.Count > 2)
                //                    {
                //                        lvGoLive.Items["Services"].SubItems[2].Text = lvGoLive.Items["Services"].SubItems[2].Text + ";" + dtServicesStatus.Rows[i][j].ToString() + " Service is in Pending State";
                //                    }
                //                    else
                //                    {
                //                        lvGoLive.Items["Services"].SubItems.Add(dtServicesStatus.Rows[i][j].ToString() + " Service is in Pending State");

                //                    }

                //                }

                //                else if (dtServicesStatus.Rows[i][j + 1].ToString().ToUpper() == "Service not found".ToUpper())
                //                {
                //                    lvGoLive.Items["Services"].ImageIndex = 1;
                //                    if (lvGoLive.Items["Services"].SubItems.Count > 2)
                //                    {
                //                        lvGoLive.Items["Services"].SubItems[2].Text = lvGoLive.Items["Services"].SubItems[2].Text + ";" + dtServicesStatus.Rows[i][j].ToString() + " Service not found.";
                //                    }
                //                    else
                //                    {
                //                        lvGoLive.Items["Services"].SubItems.Add(dtServicesStatus.Rows[i][j].ToString() + " Service not found");

                //                    }


                //                }

                //            }
                //            else
                //            {
                //                break;
                //            }
                //        }
                //    }
                //}

                //lvGoLive.AutoResizeColumn(2, ColumnHeaderAutoResizeStyle.ColumnContent);
                //if (lvGoLive.Items["Services"].ImageIndex != 1)
                //{
                //    lvGoLive.Items["Services"].ImageIndex = 0;
                //    lvGoLive.Items["Services"].BackColor = Color.White;
                //    lvGoLive.Items["Services"].ForeColor = Color.Black;

                //}
                //else
                //{
                //    lvGoLive.Items["Services"].BackColor = Color.Red;
                //    lvGoLive.Items["Services"].ForeColor = Color.White;
                //}
                #endregion
            }
            catch (Exception ex)
            {
                ExceptionManager.Publish(ex);


                SetListviewItemStyle("Services", 1);
            }
        }