Exemplo n.º 1
0
        private static List <IISAppPoolStateInfo> AppPoolStatesIIS6(string hostName)
        {
            List <IISAppPoolStateInfo> states = new List <IISAppPoolStateInfo>();

            try
            {
                DirectoryEntry root = new DirectoryEntry("IIS://" + hostName + "/W3SVC/AppPools");
                foreach (DirectoryEntry e in root.Children)
                {
                    if (e.SchemaClassName == "IIsApplicationPool")
                    {
                        IISAppPoolStateInfo appPool = new IISAppPoolStateInfo()
                        {
                            DisplayName = e.Name
                        };
                        appPool.Status = (AppPoolStatus)e.Properties["AppPoolState"].Value;
                    }
                }
            }
            catch (Exception ex)
            {
                if (ex.Message.Contains("Class not registered"))
                {
                    throw new Exception("Error querying IIS. On IIS 7+ please make sure IIS 6 Metabase Compatibility (Role Service) is installed/enabled");
                }
                else
                {
                    throw;
                }
            }
            return(states);
        }
Exemplo n.º 2
0
        public List <IISAppPoolStateInfo> GetIISAppPoolStates()
        {
            List <IISAppPoolStateInfo> sourceList = GetSourceIISAppPoolStates();
            List <IISAppPoolStateInfo> list       = new List <IISAppPoolStateInfo>();

            foreach (var checkEntry in SubItems)
            {
                IISAppPoolStateInfo monitorEntryState = new IISAppPoolStateInfo()
                {
                    DisplayName = checkEntry.Description
                };
                IISAppPoolStateInfo checkedEntryState = (from IISAppPoolStateInfo ap in sourceList
                                                         where checkEntry.Description == ap.DisplayName
                                                         select ap).FirstOrDefault();
                if (checkedEntryState != null)
                {
                    monitorEntryState.Status = checkedEntryState.Status;
                }
                else
                {
                    monitorEntryState.Status = AppPoolStatus.Unknown;
                }
                list.Add(monitorEntryState);
            }
            return(list);
        }
 public override void RefreshDisplayData()
 {
     try
     {
         System.Windows.Forms.Cursor.Current = Cursors.WaitCursor;
         lvwEntries.BeginUpdate();
         foreach (ListViewGroup lvgMachine in lvwEntries.Groups)
         {
             IISAppPoolMachine serviceDefinition = (IISAppPoolMachine)lvgMachine.Tag;
             try
             {
                 List <IISAppPoolStateInfo> sourceList = serviceDefinition.GetIISAppPoolStates();
                 foreach (ListViewItem lviAppPool in lvgMachine.Items)
                 {
                     IISAppPoolEntry     entry          = (IISAppPoolEntry)lviAppPool.Tag;
                     IISAppPoolStateInfo currentAppPool = (from ap in sourceList
                                                           where ap.DisplayName == entry.Description
                                                           select ap).FirstOrDefault();
                     if (currentAppPool == null || currentAppPool.Status == AppPoolStatus.Unknown)
                     {
                         lviAppPool.ImageIndex = 0;
                     }
                     else if (currentAppPool.Status == AppPoolStatus.Started)
                     {
                         lviAppPool.ImageIndex = 1;
                     }
                     else if (currentAppPool.Status == AppPoolStatus.Stopped)
                     {
                         lviAppPool.ImageIndex = 2;
                     }
                     else
                     {
                         lviAppPool.ImageIndex = 3;
                     }
                 }
             }
             catch (UnauthorizedAccessException unauthEx)
             {
                 MessageBox.Show(string.Format("Cannot update the application pool list for {0} due to 'Unauthorized Access' error. Please restart this application in 'Admin' mode.\r\nDetails: {1}", serviceDefinition.MachineName, unauthEx.Message), "Unauthorized Access", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
             }
             catch (Exception ex)
             {
                 MessageBox.Show(string.Format("Error updating application pool states of {0}\r\n{1}", serviceDefinition.MachineName, ex.ToString()), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     lvwEntries.EndUpdate();
     System.Windows.Forms.Cursor.Current = Cursors.Default;
     toolStripStatusLabelDetails.Text    = "Last updated " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
 }
Exemplo n.º 4
0
        private List <IISAppPoolStateInfo> AppPoolStatesIIS7Plus(string hostName)
        {
            List <IISAppPoolStateInfo> appPools = new List <IISAppPoolStateInfo>();

            try
            {
                if (UsePerfCounter && System.Diagnostics.PerformanceCounterCategory.Exists("APP_POOL_WAS", hostName))
                {
                    //Try performance counters
                    System.Diagnostics.PerformanceCounterCategory pcCat = new System.Diagnostics.PerformanceCounterCategory("APP_POOL_WAS", hostName);
                    //getting instance names
                    string[] instances = pcCat.GetInstanceNames();
                    foreach (string instanceName in instances)
                    {
                        if (instanceName != "_Total")
                        {
                            System.Diagnostics.PerformanceCounter pc = (from pcCacheEntry in pcCatCache
                                                                        where pcCacheEntry.InstanceName == instanceName
                                                                        select pcCacheEntry).FirstOrDefault();
                            if (pc == null)
                            {
                                pc = new System.Diagnostics.PerformanceCounter("APP_POOL_WAS", "Current Application Pool State", instanceName, hostName);
                                pcCatCache.Add(pc);
                            }
                            float value = pc.NextValue();
                            IISAppPoolStateInfo appPool = new IISAppPoolStateInfo()
                            {
                                DisplayName = instanceName
                            };
                            appPool.Status = ReadAppPoolStateFromPCValue(value);
                            appPools.Add(appPool);
                        }
                    }
                }
                else
                {
                    using (WebAdmin.ServerManager serverManager = WebAdmin.ServerManager.OpenRemote(hostName))
                    {
                        foreach (var pool in serverManager.ApplicationPools)
                        {
                            IISAppPoolStateInfo appPool = new IISAppPoolStateInfo()
                            {
                                DisplayName = pool.Name
                            };
                            appPool.Status = (AppPoolStatus)pool.State;
                            appPools.Add(appPool);
                        }
                    }
                }
            }
            //catch (UnauthorizedAccessException unauthEx)
            //{
            //    appPools = new List<IISAppPoolStateInfo>();
            //    //Try performance counters
            //    System.Diagnostics.PerformanceCounterCategory pcCat = new System.Diagnostics.PerformanceCounterCategory("APP_POOL_WAS", hostName);
            //    //getting instance names
            //    string[] instances = pcCat.GetInstanceNames();
            //    foreach (string instanceName in instances)
            //    {
            //        System.Diagnostics.PerformanceCounter pc = new System.Diagnostics.PerformanceCounter("APP_POOL_WAS", "Current Application Pool State", instanceName, hostName);
            //        float value = pc.NextValue();
            //        IISAppPoolStateInfo appPool = new IISAppPoolStateInfo() { DisplayName = instanceName };
            //        appPool.Status = ReadAppPoolStateFromPCValue(value);
            //        appPools.Add(appPool);
            //    }
            //}
            catch (Exception ex)
            {
                if (ex is UnauthorizedAccessException)
                {
                    throw new Exception("Using ServiceManager class on local machine requires elevated rights. Please run this collector in a process that runs in 'Admin mode'");
                }
                else if (ex.Message.Contains("80040154"))
                {
                    throw new Exception(string.Format("ServiceManager class not supported on {0}", hostName));
                }
                else if (ex.Message.Contains("800706ba"))
                {
                    throw new Exception("Firewall blocking ServiceManager call. Please add OAB exception");
                }
                else
                {
                    throw;
                }
            }
            return(appPools);
        }