zoukankan      html  css  js  c++  java
  • 代码片段

    经常会写一些测试用的片段 丢了又可惜 决定记下来

    值类型检查

                     var list = new List<Type>()
                     {
                         typeof(Object),
                         typeof(DBNull),
                         typeof(Boolean),
                         typeof(Char),
                         typeof(SByte),
                         typeof(Byte),
                         typeof(Int16),
                         typeof(UInt16),
                         typeof(Int32),
                         typeof(UInt32),
                         typeof(Int64),
                         typeof(UInt64),
                         typeof(Single),
                         typeof(Double),
                         typeof(Decimal),
                         typeof(DateTime),
                         typeof(String),
                     };
                     foreach(var item in list)
                     {
                         WL("Type: {0}, IsValueType: {1}", item.Name, item.IsValueType);
                     }
    

     IIS 管理  C:\Windows\System32\inetsrv\Microsoft.Web.Administration.dll

    创建 删除 修改 虚拟目录

            static void UpdateIIS(string[] args)
            {
                using (var serverManager = new ServerManager())
                {
    #if !DEBUG
                    if (args.Length != 3)
                    {
                        Console.Write("参数不正确!");
                        return;
                    }
    #endif
    
                    Configuration config = serverManager.GetApplicationHostConfiguration();
                    ConfigurationSection sitesSection = config.GetSection("system.applicationHost/sites");
                    ConfigurationElementCollection sitesCollection = sitesSection.GetCollection();
    #if !DEBUG
                    ConfigurationElement siteElement = FindElement(sitesCollection, "site", "name", args[0]);
    #else
                    ConfigurationElement siteElement = FindElement(sitesCollection, "site", "name", "LXT");
    #endif
                    if (siteElement == null)
                    {
                        Console.WriteLine("IIS 未找到名为 {0} 的站点", args[0]);
                        return;
                    }
    
    
                    ConfigurationElementCollection siteCollection = siteElement.GetCollection();
    
    #if !DEBUG
                    Delete(siteCollection, args[1]);
                    Create(siteCollection, args[1], args[2]);
    #else
                    Delete(siteCollection, "/HeadImages");
                    Create(siteCollection, "/HeadImages", @"D:\Dev\IIS7");
    #endif
    
                    serverManager.CommitChanges();
    
                }
                Console.WriteLine("IIS 更新完成");
            }
    
    
            static ConfigurationElement FindElement(ConfigurationElementCollection collection, string elementTagName, params string[] keyValues)
            {
                foreach (ConfigurationElement element in collection)
                {
                    if (String.Equals(element.ElementTagName, elementTagName, StringComparison.OrdinalIgnoreCase))
                    {
                        bool matches = true;
                        for (int i = 0; i < keyValues.Length; i += 2)
                        {
                            object o = element.GetAttributeValue(keyValues[i]);
                            string value = null;
                            if (o != null)
                            {
                                value = o.ToString();
                            }
                            if (!String.Equals(value, keyValues[i + 1], StringComparison.OrdinalIgnoreCase))
                            {
                                matches = false;
                                break;
                            }
                        }
                        if (matches)
                        {
                            return element;
                        }
                    }
                }
                return null;
            }
    
            static void Delete(ConfigurationElementCollection collection, string virtualDirectoryPath)
            {
                var oldApplication = collection.SingleOrDefault(e => e.Attributes["path"].Value.ToString() == "/");
                if (oldApplication == null) return;
                var virtualDirectorys = oldApplication.GetCollection();
                if (virtualDirectorys.Count == 1) return;
                var virtualDirectory = virtualDirectorys.SingleOrDefault(e => e.Attributes["path"].Value.ToString() == virtualDirectoryPath);
                if (virtualDirectory == null) return;
                virtualDirectorys.Remove(virtualDirectory);
                Console.WriteLine("IIS 删除 虚拟目录");
            }
    
            static void Create(ConfigurationElementCollection collection, string virtualDirectoryPath, string physicalPath)
            {
    
                var application = collection.SingleOrDefault(e => e.Attributes["path"].Value.ToString() == virtualDirectoryPath);
                if (application == null)
                {
                    application = collection.CreateElement("application");
                    application["path"] = virtualDirectoryPath;
                    collection.Add(application);
                }
                application["applicationPool"] = "LXT";
    
                ConfigurationElementCollection virtualDirectorys = application.GetCollection();
                var virtualDirectory = virtualDirectorys.SingleOrDefault(e => e.Attributes["path"].Value.ToString() == "/");
                if (virtualDirectory == null)
                {
                    virtualDirectory = virtualDirectorys.CreateElement("virtualDirectory");
                    virtualDirectory["path"] = @"/";
                    virtualDirectorys.Add(virtualDirectory);
                    Console.WriteLine("IIS 创建 应用程序");
                }
                else
                    Console.WriteLine("IIS 修改 应用程序");
                virtualDirectory["physicalPath"] = physicalPath;
            }
    
  • 相关阅读:
    要使用springtest来进行单元测试 否则将无法注入 applicationContext.xml
    关键词的重要性
    发卡可以以交叉方式佩戴来增强可爱性
    红毛类型
    oracle学习总结4
    对springMVC的简单理解
    理解RESTful架构
    项目移植过程中报:“Project facet Java version 1.7 is not supported.” 错误
    svn服务器的搭建
    oracle学习总结3
  • 原文地址:https://www.cnblogs.com/slightboy/p/1963686.html
Copyright © 2011-2022 走看看