Exemple #1
0
 public static string GetPathDifference(string rootPath, string path)
 {
     if (!string.IsNullOrEmpty(path) && CommHelper.StartsWithIgnoreCase(path, rootPath))
     {
         var retVal = path.Substring(rootPath.Length, path.Length - rootPath.Length);
         return(retVal.Trim('/', '\\'));
     }
     return(string.Empty);
 }
Exemple #2
0
        public static bool IsFileExtensionAllowed(string sAllowedExt, string sExt)
        {
            if (sExt != null && sExt.StartsWith("."))
            {
                sExt = sExt.Substring(1, sExt.Length - 1);
            }
            sAllowedExt = sAllowedExt.Replace("|", ",");
            var aExt = sAllowedExt.Split(',');

            return(aExt.Any(t => CommHelper.EqualsIgnoreCase(sExt, t)));
        }
        /// <summary>
        /// 获取硬盘容量
        /// </summary>
        public ComputerInfo GetDiskSize()
        {
            ComputerInfo computer = null;

            try
            {
                computer = new ComputerInfo();
                var  diskcon = Directory.GetLogicalDrives();
                long total   = 0;
                long free    = 0;
                foreach (string diskname in diskcon)
                {
                    try
                    {
                        DriveInfo di = new DriveInfo(diskname);
                        if (di.IsReady)
                        {
                            total += di.TotalSize;
                            free  += di.AvailableFreeSpace;
                            computer.DiskCount++;
                        }
                    }
                    catch
                    {
                    }
                }

                computer.DiskCount = diskcon.Length;
                computer.RAMTotal  = CommHelper.ToGB(total, 1000);
                computer.RAMFree   = CommHelper.ToGB(free, 1000);
                computer.RAMUsed   = CommHelper.ToGB(total - free, 1000);
                computer.UsedRate  = (100 - Math.Ceiling((decimal)free * 100 / total)).ToString() + "%";
            }catch (Exception ex)
            {
                LoggerHelper.Exception(ex);
            }

            return(computer);
        }
        /// <summary>
        /// 获取硬盘容量
        /// </summary>
        private string GetDiskSize1()
        {
            string        result = string.Empty;
            StringBuilder sb     = new StringBuilder();

            try
            {
                string                     hdId      = string.Empty;
                ManagementClass            hardDisk  = new ManagementClass("win32_DiskDrive");
                ManagementObjectCollection hardDiskC = hardDisk.GetInstances();
                foreach (ManagementObject m in hardDiskC)
                {
                    long capacity = Convert.ToInt64(m["Size"].ToString());
                    sb.Append(CommHelper.ToGB(capacity, 1000.0) + "+");
                }
                result = sb.ToString().TrimEnd('+');
            }
            finally
            {
            }
            return(result);
        }
Exemple #5
0
 public static FileType GetType(string typeStr)
 {
     return(CommHelper.ToEnum(CommHelper.UpperFirst(typeStr), FileType.Unknown));
 }
Exemple #6
0
 public static bool IsZip(string typeStr)
 {
     return(CommHelper.EqualsIgnoreCase(".zip", typeStr));
 }
Exemple #7
0
 public static bool IsExtension(string ext, params string[] extensions)
 {
     return(extensions.Any(extension => CommHelper.EqualsIgnoreCase(ext, extension)));
 }