/// <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;
        }
        public string GetServiceStatus(string strServiceNames, BMCMonitoring.ServiceTypes serviceStatus)
        {
            CheckSecurity();

            string strSiteName = string.Empty;
            try
            {
                var dtServiceStatus = new DataTable("Services");

                var objMonitoring = new BMCMonitoring();
                switch (serviceStatus)
                {
                    case BMCMonitoring.ServiceTypes.All:
                        dtServiceStatus = objMonitoring.GetServiceStatus(strServiceNames, BMCMonitoring.ServiceTypes.All);
                        break;
                    case BMCMonitoring.ServiceTypes.Running:
                        dtServiceStatus = objMonitoring.GetServiceStatus(strServiceNames, BMCMonitoring.ServiceTypes.Running);
                        break;
                    case BMCMonitoring.ServiceTypes.NotRunning:
                        dtServiceStatus = objMonitoring.GetServiceStatus(strServiceNames, BMCMonitoring.ServiceTypes.NotRunning);
                        break;
                }
                var objWriter = new StringWriter();
                dtServiceStatus.WriteXml(objWriter);
                return objWriter.ToString();
            }
            catch
            {
                LogManager.WriteLog("Error in getting status from site " + strSiteName, LogManager.enumLogLevel.Error);
                return "<OutputXML><ErrorMessage>no records found </ErrorMessage></OutputXML> ";
            }
        }
        /// <summary>
        /// To get the status of a particular service
        /// <Author>Vineetha Mathew</Author>       
        /// <param name="strServiceName">string</param>
        /// <returns></returns>
        /// </summary>       
        private string GetServiceStatus(string strServiceName)
        {
            BMCMonitoring objBMCMonitoring = new BMCMonitoring();
            DataTable dtServicesStatus = new DataTable();
            StringBuilder strServicelist = new StringBuilder();
            try
            {
                dtServicesStatus = objBMCMonitoring.GetServiceStatus(strServiceName, BMCMonitoring.ServiceTypes.All);
                Application.DoEvents();
                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].ToString() == strServiceName && dtServicesStatus.Rows[i][j + 1].ToString() == "Stopped")
                                {
                                    strServiceStatus = "STOP";
                                }
                                else if (dtServicesStatus.Rows[i][j].ToString() == strServiceName && dtServicesStatus.Rows[i][j + 1].ToString() == "Running")
                                {
                                    strServiceStatus = "RUN";

                                }
                                else if (dtServicesStatus.Rows[i][j].ToString() == strServiceName && dtServicesStatus.Rows[i][j + 1].ToString() == "Pending")
                                {
                                    strServiceStatus = "PEND";
                                }
                                else if (dtServicesStatus.Rows[i][j].ToString() == strServiceName && dtServicesStatus.Rows[i][j + 1].ToString() == "Service not found")
                                {
                                    strServiceStatus = "NOSERVICE";
                                }
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                }

            }
            catch (IndexOutOfRangeException iex)
            {
                LogManager.WriteLog("GetServiceStatus" + iex.Message.ToString() + iex.Source.ToString(), LogManager.enumLogLevel.Error);
                ExceptionManager.Publish(iex);
            }
            catch (Exception ex)
            {
                LogManager.WriteLog("GetServiceStatus" + ex.Message.ToString() + ex.Source.ToString(), LogManager.enumLogLevel.Error);
                ExceptionManager.Publish(ex);
            }
            finally
            {
                dtServicesStatus.Dispose();
            }
            return strServiceStatus;
        }
        /// <summary>
        /// To get all the status of the services on form load
        /// <Author>Vineetha Mathew</Author>      
        /// <param name=""></param>
        /// <returns></returns>
        /// </summary>      
        private void GetServiceStatusToListView()
        {
            BMCMonitoring objBMCMonitoring = new BMCMonitoring();
            DataTable dtServicesStatus = new DataTable();
            StringBuilder strServicelist = new StringBuilder();           
            try
            {
                lvServiceslist.BeginUpdate();

                for (int i = 0; i < lvServiceslist.Items.Count; i++)
                {                                     
                    strServicelist.Append(lvServiceslist.Items[i].Text + ",");
                }
                dtServicesStatus = objBMCMonitoring.GetServiceStatus(strServicelist.ToString(), BMCMonitoring.ServiceTypes.All);
                Application.DoEvents();
                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].ToString() == lvServiceslist.Items[i].Text.ToString() && dtServicesStatus.Rows[i][j + 1].ToString() == "Stopped")
                                {   
                                    lvServiceslist.Items[i].ForeColor = Color.Red;
                                    lvServiceslist.Items[i].SubItems[1].Text = "Stopped";                                    
                                }
                                else if (dtServicesStatus.Rows[i][j].ToString() == lvServiceslist.Items[i].Text.ToString() && dtServicesStatus.Rows[i][j + 1].ToString() == "Running")
                                {                                   
                                    lvServiceslist.Items[i].ForeColor = Color.Blue;                                   
                                    lvServiceslist.Items[i].SubItems[1].Text = "Running";                                    

                                }
                                else if (dtServicesStatus.Rows[i][j].ToString() == lvServiceslist.Items[i].Text.ToString() && dtServicesStatus.Rows[i][j + 1].ToString() == "Pending")
                                {   
                                    lvServiceslist.Items[i].ForeColor = Color.MediumSeaGreen;                                   
                                    lvServiceslist.Items[i].SubItems[1].Text = "Pending";                                    
                                }
                                else if (dtServicesStatus.Rows[i][j].ToString() == lvServiceslist.Items[i].Text.ToString() && dtServicesStatus.Rows[i][j + 1].ToString() == "Service not found")
                                {
                                    lvServiceslist.Items[i].ForeColor = Color.Green;
                                    lvServiceslist.Items[i].SubItems[1].Text = "Service not found";                                    
                                }
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                }
               
            }
            catch (IndexOutOfRangeException iex)
            {
                LogManager.WriteLog("GetServiceStatus" + iex.Message.ToString() + iex.Source.ToString(), LogManager.enumLogLevel.Error);
                ExceptionManager.Publish(iex);
            }
            catch (Exception ex)
            {
                LogManager.WriteLog("GetServiceStatus" + ex.Message.ToString() + ex.Source.ToString(), LogManager.enumLogLevel.Error);
                ExceptionManager.Publish(ex);
            }
            finally
            {
                lvServiceslist.EndUpdate();
            }
        }
예제 #5
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);
            }
        }
        /// <summary>
        /// Display the Ticketing server details.
        /// <param name="CMPServerEntries"></param>
        /// <returns></returns>
        /// </summary>        
        //private void GetTicketingServerSettings(Dictionary<string, string> TicketingServerSettings)
        //{
        //    try
        //    {
        //        if (TicketingServerSettings != null)
        //        {
        //            foreach (KeyValuePair<string, string> objKeyValue in TicketingServerSettings)
        //            {
        //                if (objKeyValue.Key.ToUpper() == "SERVER")
        //                {
        //                    txtticketserver.Text = objKeyValue.Value;
        //                }
        //                else if (objKeyValue.Key.ToUpper() == "UID")
        //                {
        //                    txtticketusername.Text = objKeyValue.Value;
        //                }
        //                else if (objKeyValue.Key.ToUpper() == "PASSWORD")
        //                {
        //                    txtticketPassword.Password = objKeyValue.Value;
        //                }
        //                else if (objKeyValue.Key.ToUpper() == "DATABASE")
        //                {
        //                    lblticketDBname.Text = objKeyValue.Value;
        //                }
        //                else if (objKeyValue.Key.ToUpper() == "TIMEOUT")
        //                {
        //                    txtticketTimeout.Text = objKeyValue.Value;
        //                }
        //                else if (objKeyValue.Key.ToUpper() == "INSTANCE")
        //                {
        //                    txticketInstance.Text = objKeyValue.Value;
        //                }

        //            }
        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        LogManager.WriteLog("GetTicketingServerSettings" + ex.Message.ToString() + ex.Source.ToString(), LogManager.enumLogLevel.Error);
        //        ExceptionManager.Publish(ex);
        //        MessageBox.ShowBox("MessageID74", BMC_Icon.Error);
        //    }
        //}

        /// <summary>
        /// Load Services information to lisview
        /// </summary>
        /// <param name="strListarray"></param>
        private void LoadServicesToListView(string[] strListarray)
        {
            BMCMonitoring objBMCMonitoring = new BMCMonitoring();
            DataTable dtServicesStatus = new DataTable();
            StringBuilder strServicelist = new StringBuilder();

            for (int i = 0; i < strListarray.Length; i++)
            {
                strServicelist.Append(strListarray[i] + ",");
            }

            dtServicesStatus = objBMCMonitoring.GetServiceStatus(strServicelist.ToString(), BMCMonitoring.ServiceTypes.All);

            if (_LoadListViewCollection.Count > 0) { _LoadListViewCollection.Clear(); }

            foreach (DataRow dataRow in dtServicesStatus.Rows)
            {
                _LoadListViewCollection.Add(new LoadListView { Check = 0, ServiceName = dataRow[0].ToString(), ServiceStatus = dataRow[1].ToString() });
            }

            lvServiceslist.ItemsSource = LoadListViewCollection;
        }