コード例 #1
0
ファイル: IISHelper.cs プロジェクト: xtinker/MyGit
        public static Dictionary <string, SiteObj> GetSiteNames()
        {
            Dictionary <string, SiteObj> dictionary = new Dictionary <string, SiteObj>();
            int iISMajorVersion = IISHelper.GetIISMajorVersion();

            if (iISMajorVersion == 6)
            {
                ManagementObjectSearcher managementObjectSearcher = new ManagementObjectSearcher("root\\MicrosoftIISv2", "SELECT * FROM IIsWebServerSetting");
                using (ManagementObjectCollection.ManagementObjectEnumerator enumerator = managementObjectSearcher.Get().GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        ManagementObject managementObject = (ManagementObject)enumerator.Current;
                        SiteObj          siteObj          = new SiteObj();
                        siteObj.SiteName        = managementObject["ServerComment"].ToString();
                        siteObj.SiteNameQuanPin = PinyinHelper.GetPinyin(siteObj.SiteName).ToUpper();
                        siteObj.SiteNameDuanPin = PinyinHelper.GetFirstPinyin(siteObj.SiteName).ToUpper();
                        siteObj.PoolName        = managementObject["AppPoolId"].ToString();
                        ManagementBaseObject[] array = (ManagementBaseObject[])managementObject["ServerBindings"];
                        siteObj.Port = array[0]["Port"].ToString();
                        int num = 0;
                        while (dictionary.ContainsKey(siteObj.SiteName))
                        {
                            num++;
                            siteObj.SiteName = managementObject["ServerComment"].ToString() + "_" + num.ToString();
                        }
                        dictionary.Add(siteObj.SiteName, siteObj);
                    }
                }
            }
            else
            {
                ServerManager serverManager = new ServerManager();
                foreach (Site current in serverManager.Sites)
                {
                    SiteObj siteObj = new SiteObj();
                    siteObj.SiteName        = current.Name;
                    siteObj.SiteNameQuanPin = PinyinHelper.GetPinyin(siteObj.SiteName).ToUpper();
                    siteObj.SiteNameDuanPin = PinyinHelper.GetFirstPinyin(siteObj.SiteName).ToUpper();
                    siteObj.PoolName        = ((current.Applications.Count > 0) ? current.Applications[0].ApplicationPoolName : "");
                    siteObj.Port            = current.Bindings[0].EndPoint.Port.ToString();
                    siteObj.SitePath        = ((current.Applications.Count > 0) ? current.Applications[0].VirtualDirectories[0].PhysicalPath : "");
                    int num = 0;
                    while (dictionary.ContainsKey(siteObj.SiteName))
                    {
                        num++;
                        siteObj.SiteName = current.Name + "_" + num.ToString();
                    }
                    dictionary.Add(siteObj.SiteName, siteObj);
                }
            }
            return(dictionary);
        }
コード例 #2
0
ファイル: IISHelper.cs プロジェクト: xtinker/MyGit
        public static List <string> GetSiteNames(string strKeyWord)
        {
            List <string> list            = new List <string>();
            int           iISMajorVersion = IISHelper.GetIISMajorVersion();

            if (iISMajorVersion == 6)
            {
                ManagementObjectSearcher managementObjectSearcher = new ManagementObjectSearcher("root\\MicrosoftIISv2", "SELECT * FROM IIsWebServerSetting");
                using (ManagementObjectCollection.ManagementObjectEnumerator enumerator = managementObjectSearcher.Get().GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        ManagementObject managementObject = (ManagementObject)enumerator.Current;
                        list.Add(managementObject["ServerComment"].ToString());
                    }
                }
            }
            else
            {
                ServerManager serverManager = new ServerManager();
                foreach (Site current in serverManager.Sites)
                {
                    if (current.Name.ToUpper().Contains(strKeyWord.ToUpper()) || PinyinHelper.GetPinyin(current.Name).ToUpper().Contains(strKeyWord.ToUpper()) || PinyinHelper.GetFirstPinyin(current.Name).ToUpper().Contains(strKeyWord.ToUpper()))
                    {
                        list.Add(current.Name);
                    }
                }
            }
            return(list);
        }
コード例 #3
0
        /// <summary>
        /// 递归
        /// </summary>
        /// <param name="menu"></param>
        /// <returns></returns>
        private MenuInfo Builder(SysMenuDto menu)
        {
            //如果是顶级菜单,并且没有子集,需要单独构造,把当前菜单写在 Children 里面
            if (menu.FatherID == 0 && (menu.Children == null || menu.Children.Count == 0))
            {
                return(new MenuInfo
                {
                    Path = GetRoutePath(menu.Url),
                    Component = "Layout",
                    Redirect = string.Empty,
                    Children = new List <MenuInfo>
                    {
                        new MenuInfo
                        {
                            Path = PinyinHelper.GetFirstPinyin(menu.Name),
                            Name = menu.Name,
                            Component = menu.Url,
                            Meta = new Meta
                            {
                                Icon = menu.Icon,
                                Title = menu.Name,
                                MenuID = menu.ID,
                            },
                        }
                    }
                });
            }

            MenuInfo result = new MenuInfo
            {
                Component = menu.Url,
                Name      = menu.Name,
                Redirect  = string.Empty,
                Meta      = new Meta
                {
                    Icon   = menu.Icon,
                    Title  = menu.Name,
                    MenuID = menu.ID,
                },
                Path = menu.Path
            };

            List <MenuInfo> childrenList = new List <MenuInfo>();

            if (menu.Children.CheckNotEmpty() == true)
            {
                foreach (SysMenuDto menuChild in menu.Children)
                {
                    childrenList.Add(Builder(menuChild));
                }
            }
            result.Children = childrenList;

            //if (result.Children.Count == 0)
            //{
            //    result.Path = PinyinHelper.GetFirstPinyin(result.Name);
            //}
            //else
            //{
            //    result.Component = "Layout";
            //    result.Path = GetRoutePath(menu.Url);
            //}


            if (result.Children.Count > 0)
            {
                result.Component = "Layout";
                result.Path      = GetRoutePath(menu.Url);
            }
            return(result);
        }