Exemplo n.º 1
0
        /// <summary>
        /// 初始读取文件并备份
        /// </summary>
        public void DefaultBackupFile(string path)
        {
            //读取本地文件夹中的所有文件列表
            List <string> files = FileTool.GetAllFile(path);

            if (ListTool.HasElements(files))
            {
                foreach (var file in files)
                {
                    try
                    {
                        string lastwritetime = DateTimeConvert.StandardString(File.GetLastWriteTime(file));
                        using (var db = new Muse())
                        {
                            BackupFiles backfile = db.Get <BackupFiles>(x => x.FullPath == file && x.LastWriteTime == lastwritetime, null);
                            if (backfile == null)
                            {
                                AddToBackupFiles(file);
                            }
                        }
                    }
                    catch (Exception e) { }
                }
            }
        }
Exemplo n.º 2
0
        void SetNetProcess()
        {
            // 清空已有连接数
            if (ListTool.HasElements(NetProcessInfoList))
            {
                NetProcessInfoList.ForEach(x =>
                {
                    x.ConnectCount = 0;
                });
            }

            // 统计TCP连接数
            if (ListTool.HasElements(TcpConnection))
            {
                foreach (var t in TcpConnection)
                {
                    SetNetProcessConnection(t.ProcessId);
                }
            }
            // 统计UDP连接数
            if (ListTool.HasElements(UdpConnection))
            {
                foreach (var u in UdpConnection)
                {
                    SetNetProcessConnection(u.ProcessId);
                }
            }
        }
Exemplo n.º 3
0
        public void Start()
        {
            #region 启动系统性能计数器统计
            try
            {
                NetFlow.Start();
                NetFlow.DataMonitorEvent += DataMonitorEvent;
                _IsNetFlowRun             = true;
            }
            catch { }
            #endregion

            #region 启动Socket包统计
            if (PermissionTool.IsAdmin())
            {
                List <IPAddress> hosts = NetCardInfoTool.GetIPv4Address();
                AllIPv4Address = NetCardInfoTool.GetAllIPv4Address();
                foreach (var host in hosts)
                {
                    try
                    {
                        NetPacketTool p = new NetPacketTool(host);
                        p.NewPacket += new NewPacketEventHandler(NewPacketEvent);
                        p.Start();
                        NetPacketList.Add(p);
                    }
                    catch { }
                }
                if (ListTool.HasElements(NetPacketList))
                {
                    _IsNetPacketRun = true;
                }
            }
            #endregion
        }
 public void Refresh()
 {
     if (LoadTask == null || LoadTask.IsCompleted)
     {
         Task.Factory.StartNew(() =>
         {
             var data = WakaAnalyzer.Recent7.LanguageCount();//获取所有语言统计信息
             if (ListTool.HasElements(data))
             {
                 Series = new SeriesCollection();
                 data.ForEach(x =>
                 {
                     App.Current.Dispatcher.Invoke((Action)(() =>
                     {
                         var p = new PieSeries
                         {
                             Values = new ChartValues <double> {
                                 x.Item2
                             },
                             Title = x.Item1
                         };
                         Series.Add(p);
                     }));
                 });
             }
         });
     }
 }
Exemplo n.º 5
0
        /// <summary>
        /// 获取全部USB设备列表
        /// </summary>
        /// <returns></returns>
        public static List <USBDeviceModel> All()
        {
            var list1 = AllByFind();
            var list2 = AllByStatus();

            if (ListTool.HasElements(list1) && ListTool.HasElements(list2))
            {
                foreach (var x in list1)
                {
                    foreach (var y in list2)
                    {
                        if (x.ID == y.ID && x.Origin == y.Origin)
                        {
                            x.Running = y.Running;
                        }
                    }
                }
                USBStorageTool.Bind(ref list1);
                return(list1);
            }
            if (ListTool.HasElements(list1))
            {
                USBStorageTool.Bind(ref list1);
                return(list1);
            }

            USBStorageTool.Bind(ref list2);
            return(list2);
        }
Exemplo n.º 6
0
        private void CalcNetProcessInfo()
        {
            if (ListTool.HasElements(NetProcessInfoList))
            {
                foreach (var p in NetProcessInfoList)
                {
                    p.UploadDataCount   += p.UploadData;
                    p.DownloadDataCount += p.DownloadData;
                }

                var allUpBag   = NetProcessInfoList.Sum(x => x.UploadBag);
                var allDownBag = NetProcessInfoList.Sum(x => x.DownloadBag);

                foreach (var p in NetProcessInfoList)
                {
                    if (allUpBag > 0 && NetFlow.UploadData > 0)
                    {
                        var uprate = Convert.ToSingle(p.UploadBag) / allUpBag;
                        p.UploadData = Convert.ToInt64(uprate * NetFlow.UploadData);
                    }
                    if (allDownBag > 0 && NetFlow.DownloadData > 0)
                    {
                        var downRate = Convert.ToSingle(p.DownloadBag) / allDownBag;
                        p.DownloadData = Convert.ToInt64(downRate * NetFlow.DownloadData);
                    }

                    p.UploadBag      = 0;
                    p.DownloadBag    = 0;
                    p.LastUpdateTime = DateTime.Now;
                }
            }
        }
Exemplo n.º 7
0
        void ShowFileDetails(int row)
        {
            if (row >= 0)
            {
                string path = R.Services.FBS.Paths[row].Path;
                UIEnableButton(false);
                DgvFile.Rows.Clear();
                Task.Factory.StartNew(() =>
                {
                    using (var db = new Muse())
                    {
                        //db.Context.Database.Log = (sql) =>
                        //{
                        //    R.Log.i(sql);
                        //};
                        try
                        {
                            var result = db.Do <BackupFiles>().
                                         Where(x => x.FullPath.Contains(path)).
                                         GroupBy(x => new { x.FullPath }).
                                         Select(x => new
                            {
                                Path     = x.Max(o => o.FullPath),
                                BackPath = x.Max(o => o.BackupFullPath),
                                Count    = x.Count(),
                                Time     = x.Max(o => o.LastWriteTime),
                            }).OrderByDescending(x => x.Time).ToList();

                            if (ListTool.HasElements(result))
                            {
                                foreach (var item in result)
                                {
                                    //BackupFiles bkfile = bkfiles.FirstOrDefault(x => x.FullPath == file);
                                    //int versioncount = bkfiles.Count(x => x.FullPath == file);
                                    //string lastwritetime = bkfile != null ? bkfile.LastWriteTime : "-";
                                    string versiondesc = "第 " + item.Count + " 版";
                                    UIDgvFileAdd(Path.GetFileName(item.Path), item.Path, FileTool.SizeFormat(item.BackPath), versiondesc, item.Time);
                                }
                            }
                        }
                        catch (Exception e) { }

                        //List<BackupFiles> bkfiles = db.Gets<BackupFiles>(x => x.FullPath.Contains(path), null).ToList();
                        //List<string> files = FileTool.GetAllFile(path);
                        //if (ListTool.HasElements(files))
                        //{
                        //    foreach (var file in files)
                        //    {
                        //        BackupFiles bkfile = bkfiles.FirstOrDefault(x => x.FullPath == file);
                        //        int versioncount = bkfiles.Count(x => x.FullPath == file);
                        //        string versiondesc = "第 " + versioncount + " 版";
                        //        string lastwritetime = bkfile != null ? bkfile.LastWriteTime : "-";
                        //        UIDgvFileAdd(Path.GetFileName(file), file, FileTool.SizeFormat(file), versiondesc, lastwritetime);
                        //    }
                        //}
                    }
                    UIEnableButton(true);
                });
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// 清空并重置当前所有程序的连接数
        /// </summary>
        void SetNetProcess()
        {
            // 清空已有连接数
            if (ListTool.HasElements(_NetProcessInfoList))
            {
                _NetProcessInfoList.ForEach(x =>
                {
                    x.NetConnectionInfoList = new List <NetConnectionInfo>();
                });
            }

            // 统计TCP连接数
            if (ListTool.HasElements(TcpConnection))
            {
                foreach (var t in TcpConnection)
                {
                    SetNetProcessConnection(t);
                }
            }
            // 统计UDP连接数
            if (ListTool.HasElements(UdpConnection))
            {
                foreach (var u in UdpConnection)
                {
                    SetNetProcessConnection(u);
                }
            }
        }
Exemplo n.º 9
0
        public static long CountLine(string file, string[] filter)
        {
            long count = 0;

            try
            {
                using (StreamReader sr = new StreamReader(file, Encoding.UTF8))
                {
                    string line;
                    while ((line = sr.ReadLine()) != null)
                    {
                        bool access = true;
                        if (ListTool.HasElements(filter))
                        {
                            foreach (var f in filter)
                            {
                                if (line.Trim() == f)
                                {
                                    access = false;
                                }
                            }
                        }
                        if (access)
                        {
                            count++;
                        }
                    }
                }
            }
            catch (Exception e) { }
            return(count);
        }
Exemplo n.º 10
0
        public static int GetDatas(string apiKey, DateTime date)
        {
            int count                          = 0;
            var durations                      = GetDurations(apiKey, date);
            var heartbeats                     = GetHeartbeats(apiKey, date);
            List <WakaTimeDatas> datas         = AssembleHeartbeats(durations, heartbeats);
            List <WakaTimeDatas> notExistDatas = new List <WakaTimeDatas>();

            if (ListTool.HasElements(datas))
            {
                using (Muse db = new Muse())
                {
                    foreach (var data in datas)
                    {
                        if (!db.Any <WakaTimeDatas>(x => x.ID == data.ID, null))
                        {
                            if (!notExistDatas.Any(x => x.ID == data.ID))
                            {
                                notExistDatas.Add(data);
                            }
                        }
                    }
                    if (ListTool.HasElements(notExistDatas))
                    {
                        count = db.Adds(notExistDatas);
                    }
                }
            }
            return(count);
        }
Exemplo n.º 11
0
        public void Start()
        {
            if (!IsStart)
            {
                IsStart = true;

                Watcher.EventHandler += WatcherChangedEvent;
                Watcher.Start();//启动文件变动监听

                Task.Factory.StartNew(() =>
                {
                    ReadBackupFileCount(); //读取备份文件总数
                    ReadBackupPaths();     //读取备份文件夹列表
                    StatusOfReadBackupPaths = true;

                    if (ListTool.HasElements(Paths))
                    {
                        foreach (var p in Paths)
                        {
                            DefaultBackupFile(p.Path);//常规检查备份
                        }
                    }

                    BackupFileTask();//开始定时备份任务
                });
            }
        }
Exemplo n.º 12
0
 public static void Search(string words)
 {
     Task.Factory.StartNew(() =>
     {
         R.MainUI.UI_DGV_Clear();
         if (Str.Ok(words))
         {
             List <ClipboardData> record = ClipboardDataList.Where(x => x.Text != null && x.Text.Contains(words)).ToList();
             if (ListTool.HasElements(record))
             {
                 foreach (var item in record)
                 {
                     R.MainUI.UI_DGV_Add(item);
                 }
             }
         }
         else
         {
             if (ListTool.HasElements(ClipboardDataList))
             {
                 foreach (var item in ClipboardDataList)
                 {
                     R.MainUI.UI_DGV_Add(item);
                 }
             }
         }
     });
 }
 /// <summary>
 /// 高亮文本内容(已弃用,后期可考虑做搜索功能)
 /// </summary>
 /// <param name="length"></param>
 private void UIConsoleHighlight(int length)
 {
     try
     {
         Invoke(new Action(() =>
         {
             //高亮关键字
             string[] keywords = null;
             if (ListTool.HasElements(keywords))
             {
                 foreach (var key in keywords)
                 {
                     if (!StringTool.Ok(key))
                     {
                         continue;                     //不正常关键字跳出
                     }
                     int start = ConsoleLength - length;
                     while ((start = RTBConsole.Text.IndexOf(key, start)) >= 0)
                     {
                         RTBConsole.Select(start, key.Length);
                         RTBConsole.SelectionBackColor = Color.Yellow;
                         start++;
                     }
                 }
             }
         }));
     }
     catch { }
 }
Exemplo n.º 14
0
        public static long GetPathSize(string path)
        {
            long size = 0, _s = 0;

            try
            {
                List <string> files = FileTool.GetAllFile(path);
                if (ListTool.HasElements(files))
                {
                    foreach (var f in files)
                    {
                        if (File.Exists(f))
                        {
                            _s = FileTool.Size(f);
                            if (_s >= 0)
                            {
                                size += _s;
                            }
                        }
                    }
                }
            }
            catch { }
            return(size);
        }
Exemplo n.º 15
0
        /// <summary>
        /// 清理过多的日志文件
        /// </summary>
        private void Cleaner(LogType type)
        {
            List <string> files = FileTool.GetFile(GetFilePath(type));

            if (ListTool.HasElements(files))
            {
                files.ForEach(f =>
                {
                    try
                    {
                        string filename = Path.GetFileNameWithoutExtension(f);
                        if (filename.Length == 10)
                        {
                            DateTime date = DateTime.Parse(filename);
                            if (date < DateTime.Now.AddDays(-CACHE_DAYS - 1))
                            {
                                FileTool.Delete(f);
                            }
                        }
                        else
                        {
                            FileTool.Delete(f);
                        }
                    }
                    catch { FileTool.Delete(f); }
                });
            }
        }
Exemplo n.º 16
0
            /// <summary>
            /// 获取所有年份
            /// </summary>
            /// <returns></returns>
            public static List<int> AllYears()
            {
                List<int> years = new List<int>();
                using (Muse db = new Muse())
                {
                    if (db.Any<WakaTimeDatas>(x => x.ID != null, null))
                    {
                        var data = db.Do<WakaTimeDatas>().
                              GroupBy(x => new { x.BeginDate.Year }).
                              Select(x => new
                              {
                                  Date = x.Max(y => y.BeginDate),
                              }).OrderByDescending(x => x.Date).ToList();

                        if (ListTool.HasElements(data))
                        {
                            data.ForEach(x =>
                            {
                                years.Add(x.Date.Year);
                            });
                        }
                    }
                }
                int year = DateTime.Now.Year;
                if (!years.Contains(year)) years.Add(year);
                return years;
            }
Exemplo n.º 17
0
        private void SetNetProcess()
        {
            // 清空已有连接数
            if (ListTool.HasElements(NetProcessInfoList))
            {
                foreach (var x in NetProcessInfoList)
                {
                    x.NetConnectionInfoList = new ThreadSafeCollection <NetConnectionInfo>();
                }
            }

            // 统计TCP连接数
            if (ListTool.HasElements(TcpConnection))
            {
                foreach (var t in TcpConnection)
                {
                    SetNetProcessConnection(t);
                }
            }
            // 统计UDP连接数
            if (ListTool.HasElements(UdpConnection))
            {
                foreach (var u in UdpConnection)
                {
                    SetNetProcessConnection(u);
                }
            }
        }
Exemplo n.º 18
0
        void Start()
        {
            return;

            if (!IsStart)
            {
                IsStart = true;
                Task.Factory.StartNew(() =>
                {
                    while (IsStart)
                    {
                        Thread.Sleep(500);

                        if (Queue.Any())
                        {
                            List <LogModel> list = new List <LogModel>();
                            for (int i = 0; i < Queue.Count; i++)
                            {
                                LogModel model = null;
                                if (Queue.TryDequeue(out model))
                                {
                                    list.Add(model);
                                }
                            }
                            if (ListTool.HasElements(list))
                            {
                                WriteFile(list);
                            }
                        }
                    }
                });
            }
        }
Exemplo n.º 19
0
        /// <summary>
        /// 更新后操作(启动或关闭进程)
        /// </summary>
        /// <param name="vm"></param>
        private void AfterUpdate()
        {
            List <string> kill  = new List <string>();
            List <string> start = new List <string>();

            VersionModelList?.ForEach(x =>
            {
                if (ListTool.HasElements(x.AfterUpdateKillProcess))
                {
                    foreach (var item in x.AfterUpdateKillProcess)
                    {
                        if (!kill.Contains(item))
                        {
                            kill.Add(item);
                        }
                    }
                }

                if (ListTool.HasElements(x.AfterUpdateStartProcess))
                {
                    foreach (var item in x.AfterUpdateStartProcess)
                    {
                        if (!start.Contains(item))
                        {
                            start.Add(item);
                        }
                    }
                }
            });
            ProcessHelper.AfterUpdate(kill, start);
        }
Exemplo n.º 20
0
        private void FileRestoreForm_Load(object sender, EventArgs e)
        {
            //读取该文件的备份记录
            using (var db = new Muse())
            {
                Files = db.Gets <BackupFiles>(x => x.FullPath == FilePath, null).OrderBy(x => x.Id).ToList();
            }
            if (ListTool.HasElements(Files))
            {
                //获取文件名及路径信息
                var first = Files.FirstOrDefault();
                LbFileName.Text = Path.GetFileName(first.FullPath);
                LbPath.Text     = first.FullPath;
                LbVersion.Text  = "共 " + Files.Count + " 版";

                TtLabel.SetToolTip(LbFileName, Path.GetFileName(first.FullPath));
                TtLabel.SetToolTip(LbPath, first.FullPath);

                //显示所有备份记录
                int index = 1;
                foreach (var file in Files)
                {
                    DgvFiles.Rows.Add(string.Format("第 {0} 版", index++), file.LastWriteTime, ByteConvertTool.Fmt(file.Size));
                }
            }
        }
Exemplo n.º 21
0
        /// <summary>
        /// 清理过多的状态信息文件
        /// </summary>
        private void Cleaner()
        {
            string        path  = DirTool.Combine(LogPath, "status");
            List <string> files = FileTool.GetFile(path);

            if (ListTool.HasElements(files))
            {
                files.ForEach(f =>
                {
                    try
                    {
                        string filename = Path.GetFileNameWithoutExtension(f);
                        if (filename.Length == 10)
                        {
                            DateTime date = DateTime.Parse(filename);
                            if (date < Time.AddDays(-CACHE_DAYS - 1))
                            {
                                FileTool.Delete(f);
                            }
                        }
                        else
                        {
                            FileTool.Delete(f);
                        }
                    }
                    catch { FileTool.Delete(f); }
                });
            }
        }
Exemplo n.º 22
0
 /// <summary>
 /// 连接多个string构成目录
 /// </summary>
 /// <param name="paths"></param>
 /// <returns></returns>
 public static string Combine(params string[] paths)
 {
     if (ListTool.HasElements(paths))
     {
         if (paths.Length > 1)
         {
             StringBuilder result = new StringBuilder(paths[0]);
             for (int i = 1; i < paths.Length; i++)
             {
                 result.Append("\\");
                 result.Append(paths[i]);
             }
             while (result.ToString().IndexOf("\\\\") >= 0)
             {
                 result.Replace("\\\\", "\\");
             }
             return(result.ToString());
         }
         else
         {
             return(paths[0]);
         }
     }
     return("");
 }
Exemplo n.º 23
0
        /// <summary>
        /// 启用USB设备
        /// </summary>
        /// <returns></returns>
        public static bool Enable(string id)
        {
            List <string> temp    = new List <string>();
            Process       process = ProcessStarter.NewProcess(DevconExeSelector.GetExe(), $" ENABLE \"USB\\{id}\"", R.Domain, R.Username, R.Password);

            ProcessTool.SleepKill(process, 5);
            ProcessStarter.Execute(process, new Action <string>((x) =>
            {
                temp.Add(x);
            }));

            if (ListTool.HasElements(temp))
            {
                foreach (var item in temp)
                {
                    if (Str.Ok(item) &&
                        item.ToUpper().StartsWith($"USB\\{id}") &&
                        item.ToUpper().Contains("ENABLE"))
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Exemplo n.º 24
0
            /// <summary>
            /// 统计最近七天编程语言使用占用情况
            /// </summary>
            /// <param name="userId"></param>
            /// <returns></returns>
            public static List <Tuple <string, double> > LanguageCount()
            {
                DateTime today                    = DateTime.Now;
                DateTime sevenDaysAgo             = new DateTime(today.AddDays(-6).Year, today.AddDays(-6).Month, today.AddDays(-6).Day, 0, 0, 0);
                List <Tuple <string, double> > rs = null;

                using (Muse db = new Muse())
                {
                    if (db.Any <WakaTimeDatas>(x => x.ID != null, null))
                    {
                        var languageGroup = db.Do <WakaTimeDatas>().Where(x => x.Language != null && x.BeginDate >= sevenDaysAgo).GroupBy(x => x.Language).
                                            Select(x => new
                        {
                            Language = x.Max(e => e.Language),
                            Duration = x.Sum(y => y.Duration),
                        }).OrderByDescending(x => x.Duration).Take(MAX_LANGUAGE).ToList();

                        if (ListTool.HasElements(languageGroup))
                        {
                            rs = new List <Tuple <string, double> >();
                            languageGroup.ForEach(x =>
                            {
                                Tuple <string, double> rec = new Tuple <string, double>(x.Language, x.Duration);
                                rs.Add(rec);
                            });
                        }
                    }
                }
                return(rs);
            }
Exemplo n.º 25
0
        /// <summary>
        /// 获取全部USB设备列表(带状态,根据STATUS命令)
        /// </summary>
        /// <returns></returns>
        public static List <USBDeviceModel> AllByStatus()
        {
            List <USBDeviceModel> list = null;
            List <string>         temp = new List <string>();

            Process process = ProcessStarter.NewProcess(DevconExeSelector.GetExe(), " STATUS USB*");

            ProcessTool.SleepKill(process, 5);
            ProcessStarter.Execute(process, new Action <string>((x) =>
            {
                temp.Add(x);
            }));

            if (ListTool.HasElements(temp))
            {
                string   inline  = string.Join("||||", temp);
                string[] inlines = inline.Split(new string[] { "USB\\" }, StringSplitOptions.RemoveEmptyEntries);
                if (ListTool.HasElements(inlines))
                {
                    list = new List <USBDeviceModel>();
                    foreach (var item in inlines)
                    {
                        var usb = USBDeviceModel.String2ModelByStatus(item);
                        if (usb != null)
                        {
                            list.Add(usb);
                        }
                    }
                }
            }
            return(list);
        }
Exemplo n.º 26
0
            /// <summary>
            /// 统计月度所有项目时间段情况(散点图)
            /// </summary>
            /// <param name="userId"></param>
            /// <param name="year"></param>
            /// <param name="month"></param>
            /// <returns></returns>
            public static List <Tuple <string, List <Tuple <DateTime, double> > > > BubbleReport(int year, int month)
            {
                List <Tuple <string, List <Tuple <DateTime, double> > > > rs = null;
                DateTime monthStart = new DateTime(year, month, 1);
                DateTime monthEnd   = monthStart.AddMonths(1);

                using (Muse db = new Muse())
                {
                    if (db.Any <WakaTimeDatas>(x => x.BeginDate >= monthStart && x.BeginDate < monthEnd, null))
                    {
                        var heartbeats = db.Do <WakaTimeDatas>().Where(x => x.BeginDate >= monthStart && x.BeginDate < monthEnd).OrderByDescending(x => x.Duration).Take(1000).ToList();
                        if (ListTool.HasElements(heartbeats))
                        {
                            rs = new List <Tuple <string, List <Tuple <DateTime, double> > > >();
                            heartbeats.ForEach(x =>
                            {
                                if (!rs.Any(y => y.Item1 == x.Project))
                                {
                                    rs.Add(new Tuple <string, List <Tuple <DateTime, double> > >(x.Project, new List <Tuple <DateTime, double> >()));
                                }
                                else
                                {
                                    var item = rs.FirstOrDefault(y => y.Item1 == x.Project);
                                    if (item != null)
                                    {
                                        item.Item2.Add(new Tuple <DateTime, double>(x.BeginDate, x.Duration));
                                    }
                                }
                            });
                        }
                    }
                }
                return(rs);
            }
Exemplo n.º 27
0
        void CalcNetProcessInfo()
        {
            if (ListTool.HasElements(NetProcessInfoList))
            {
                NetProcessInfoList.ForEach(p =>
                {
                    p.UploadDataCount   += p.UploadData;
                    p.DownloadDataCount += p.DownloadData;
                });

                int allupbag   = NetProcessInfoList.Sum(x => x.UploadBag);
                int alldownbag = NetProcessInfoList.Sum(x => x.DownloadBag);

                NetProcessInfoList.ForEach(p =>
                {
                    if (allupbag > 0 && NetFlow.UploadData > 0)
                    {
                        float uprate = (float)p.UploadBag / allupbag;
                        p.UploadData = (int)(uprate * NetFlow.UploadData);
                    }
                    if (alldownbag > 0 && NetFlow.DownloadData > 0)
                    {
                        float downrate = (float)p.DownloadBag / alldownbag;
                        p.DownloadData = (int)(downrate * NetFlow.DownloadData);
                    }

                    p.UploadBag      = 0;
                    p.DownloadBag    = 0;
                    p.LastUpdateTime = DateTime.Now;
                });
            }
        }
Exemplo n.º 28
0
        private bool Init()
        {
            _Instances = NetCardInfoTool.GetInstanceNames();
            if (ListTool.HasElements(_Instances))
            {
                UploadCounter   = new List <PerformanceCounter>();
                DownloadCounter = new List <PerformanceCounter>();
                for (int i = 0; i < _Instances.Count(); i++)
                {
                    try
                    {
                        // 添加 上行流量计数器
                        UploadCounter.Add(new PerformanceCounter("Network Interface", "Bytes Sent/sec", _Instances[i]));
                    }
                    catch { }
                    try
                    {
                        // 添加 下行流量计数器
                        DownloadCounter.Add(new PerformanceCounter("Network Interface", "Bytes Received/sec", _Instances[i]));
                    }
                    catch { }
                }
            }

            if (ListTool.HasElements(UploadCounter) && ListTool.HasElements(DownloadCounter))
            {
                return(true);
            }
            return(false);
        }
Exemplo n.º 29
0
        /// <summary>
        /// 获取文件(多个目录)
        /// </summary>
        /// <param name="paths">路径(支持多个路径)</param>
        /// <param name="patterns">通配符(支持多个通配符)</param>
        /// <returns></returns>
        public static List <string> GetAllFile(List <string> paths, string[] patterns = null)
        {
            List <string> result = new List <string>();

            if (!ListTool.IsNullOrEmpty(paths))
            {
                foreach (var path in paths)
                {
                    if (!ListTool.IsNullOrEmpty(patterns))
                    {
                        foreach (var pattern in patterns)
                        {
                            List <string> temp = GetFile(path, pattern);
                            if (ListTool.HasElements(temp))
                            {
                                result.AddRange(temp);
                            }
                        }
                    }
                    else
                    {
                        List <string> temp = GetFile(path);
                        if (!ListTool.IsNullOrEmpty(temp))
                        {
                            result.AddRange(temp);
                        }
                    }
                }
            }
            return(result);
        }
Exemplo n.º 30
0
            /// <summary>
            /// 统计所有编程语言使用占用情况
            /// </summary>
            /// <param name="userId"></param>
            /// <returns></returns>
            public static List <Tuple <string, double> > LanguageCount()
            {
                List <Tuple <string, double> > rs = null;

                using (Muse db = new Muse())
                {
                    if (db.Any <WakaTimeDatas>(x => x.ID != null, null))
                    {
                        var languageGroup = db.Do <WakaTimeDatas>().Where(x => x.Language != null).GroupBy(x => x.Language).
                                            Select(x => new
                        {
                            Language = x.Max(e => e.Language),
                            Duration = x.Sum(y => y.Duration),
                        }).OrderByDescending(x => x.Duration).Take(MAX_LANGUAGE).ToList();

                        if (ListTool.HasElements(languageGroup))
                        {
                            rs = new List <Tuple <string, double> >();
                            languageGroup.ForEach(x =>
                            {
                                Tuple <string, double> rec = new Tuple <string, double>(x.Language, x.Duration);
                                rs.Add(rec);
                            });
                        }
                    }
                }
                return(rs);
            }