自个儿的WCF学习与深化一体系文章

5.WCF会话(Session)与实例(Instance)管理

越多IT相关资讯与技术小说,欢迎光临作者的私有网站:http://www.zuowenjun.cn/

前面会继续更新…

List<Dictionary<string, string>> diskInfoDic = new List<Dictionary<string, string>>();
ManagementClass diskClass = new ManagementClass("Win32_LogicalDisk");
            ManagementObjectCollection disks = diskClass.GetInstances();
            foreach(ManagementObject disk in disks)
            {
                Dictionary<string, string> diskInfo = new Dictionary<string, string>();
                try
                {
                    // 磁盘名称
                    diskInfo["Name"] =disk["Name"].ToString();
                    // 磁盘描述
                    diskInfo["Description"]=disk["Description"].ToString();
                    // 磁盘总容量,可用空间,已用空间
                    if (System.Convert.ToInt64(disk["Size"]) > 0)
                    {
                        long totalSpace = System.Convert.ToInt64(disk["Size"]) / MB;
                        long freeSpace = System.Convert.ToInt64(disk["FreeSpace"]) / MB;
                        long usedSpace = totalSpace - freeSpace;
                                    diskInfo["totalSpace"]=totalSpace.ToString();
                        diskInfo["usedSpace"]=usedSpace.ToString();
                        diskInfo["freeSpace"]=freeSpace.ToString();
                    }
                    diskInfoDic.Add(diskInfo);
                }
                catch(Exception ex)
                {
                    Throw ex;
                }
            }

1.资讯,WCF服务创制与行使(请求应对形式)

措施一:利用System.IO.DriveInfo.GetDrives方法来拿到

2.WCF服务创制与运用(双工情势)

方法二:利用ManagementClass(“Win32_LogicalDisk”)来获取

3.WCF序列化

///   
        /// 获取指定驱动器的空间总大小(单位为B) 
        ///   
        ///  只需输入代表驱动器的字母即可 (大写) 
        ///    
        public static long GetHardDiskSpace(string str_HardDiskName) 
        { 
            long totalSize= new long(); 
            str_HardDiskName=str_HardDiskName +":\\"; 
            System.IO.DriveInfo[] drives = System.IO.DriveInfo.GetDrives(); 
            foreach (System.IO.DriveInfo drive in drives) 
            { 
                if (drive.Name == str_HardDiskName) 
                {
                    totalSize = drive.TotalSize / (1024 * 1024 * 1024); 
                } 
            } 
            return totalSize; 
        }

        ///   
        /// 获取指定驱动器的剩余空间总大小(单位为B) 
        ///   
        ///  只需输入代表驱动器的字母即可  
        ///    
        public static long GetHardDiskFreeSpace(string str_HardDiskName) 
        { 
            long freeSpace = new long(); 
            str_HardDiskName = str_HardDiskName + ":\\"; 
            System.IO.DriveInfo[] drives = System.IO.DriveInfo.GetDrives(); 
            foreach (System.IO.DriveInfo drive in drives) 
            { 
                if (drive.Name == str_HardDiskName) 
                {
                    freeSpace = drive.TotalFreeSpace / (1024 * 1024 * 1024); 
                } 
            } 
            return freeSpace; 
        }

更加多IT相关技术小说与谍报,欢迎光临小编的私房网站:http://www.zuowenjun.cn

4.WCF落成格局重载

Post Author: admin

发表评论

电子邮件地址不会被公开。 必填项已用*标注