Exemplo n.º 1
0
        /// <summary>
        /// 复制文件夹
        /// </summary>
        /// <param name="sourceFolder">待复制的文件夹</param>
        /// <param name="destFolder">复制到的文件夹</param>
        public static void CopyFolder(string sourceFolder, string destFolder)
        {
            if (!Directory.Exists(destFolder))
            {
                Directory.CreateDirectory(destFolder);
            }
            string[] files = Directory.GetFiles(sourceFolder);
            foreach (string file in files)
            {
                string name = Path.GetFileName(file);
                string dest = Path.Combine(destFolder, name);
                File.Copy(file, dest, true);
            }
            string[] folders = Directory.GetDirectories(sourceFolder);
            foreach (string folder in folders)
            {
                string name = Path.GetFileName(folder);
                string dest = Path.Combine(destFolder, name);
                CopyFolder(folder, dest);
            }

            var message = string.Format("copy to folder: [{0}] => done!", destFolder);

            UtilsLogger.LogMessage(message);
        }
Exemplo n.º 2
0
        public static string ReadFirstDisk()
        {
            UtilsLogger.LogMessage(string.Format("ReadFirstDisk()"));
            List <String> list = ReadAllDisk();
            string        code = SortListAndReadFirst(list);

            UtilsLogger.LogMessage(string.Format("ReadFirstDisk() => code: {0}", code));
            return(code);
        }
Exemplo n.º 3
0
        //cpu
        public static List <String> ReadAllCpu()
        {
            lock (_lock)
            {
                List <String> list = new List <string>();
                try
                {
                    using (ManagementObjectSearcher s = new ManagementObjectSearcher("SELECT * FROM Win32_PRocessor"))
                        foreach (ManagementObject mo in s.Get())
                        {
                            try
                            {
                                list.Add(mo.Properties["ProcessorId"].Value.ToString());
                            }
                            catch (Exception ex)
                            {
                                UtilsLogger.LogMessage(string.Format("ex in ReadAllCpu() =>{0}", ex.Message));
                            }
                        }

                    //using (ManagementClass mc = new ManagementClass("Win32_Processor"))
                    //{
                    //    ManagementObjectCollection moc = mc.GetInstances();
                    //    foreach (ManagementObject mo in moc)
                    //    {
                    //        try
                    //        {
                    //            list.Add(mo.Properties["ProcessorId"].Value.ToString());
                    //        }
                    //        catch (Exception ex)
                    //        {
                    //            UtilsLogger.LogMessage(string.Format("ex in ReadAllCpu() =>{0}", ex.Message));
                    //        }
                    //    }
                    //}
                    UtilsLogger.LogMessage(string.Format("ReadAllCpu()=>{0}", list.Count));
                    foreach (var item in list)
                    {
                        UtilsLogger.LogMessage(string.Format("cpu =>{0}", item));
                    }
                    UtilsLogger.LogMessage(string.Format("first cpu =>{0}", list[0]));
                }
                catch (Exception exAll)
                {
                    UtilsLogger.LogMessage(string.Format("exAll in ReadAllCpu() =>{0}", exAll.Message));
                }
                return(list);
            }
        }
Exemplo n.º 4
0
 private static void TraceMessage(string message)
 {
     UtilsLogger.LogMessage(message);
 }