コード例 #1
0
 /// <summary>
 /// 根据端口号获取进程ID
 /// </summary>
 /// <param name="port"></param>
 /// <returns></returns>
 public static int GetPidByPort(int port)
 {
     try
     {
         TcpRow[] list = GetTcps();
         if (Ls.Ok(list))
         {
             foreach (var item in list)
             {
                 if (item.LocalPort == port)
                 {
                     return(item.ProcessId);
                 }
             }
         }
     }
     catch { }
     try
     {
         UdpRow[] list = GetUdps();
         if (Ls.Ok(list))
         {
             foreach (var item in list)
             {
                 if (item.LocalPort == port)
                 {
                     return(item.ProcessId);
                 }
             }
         }
     }
     catch { }
     return(-1);
 }
コード例 #2
0
        /// <summary>
        /// 清理日志文件
        /// </summary>
        public static void CleanLogFile()
        {
            Task.Factory.StartNew(() =>
            {
                if (IsCleaning == false)
                {
                    IsCleaning = true;

                    List <string> all_log    = GetAllLogFile();
                    List <string> expire_log = GetExpireLogFile(all_log, out long allSize, out long expireSize);

                    if (Ls.Ok(expire_log))
                    {
                        foreach (var file in expire_log)
                        {
                            FileTool.Delete(file);
                        }

                        R.SystemStatus.DriveTotal = DriveTool.GetDriveTotalSize(R.Paths.App);
                        R.SystemStatus.DriveAvail = DriveTool.GetDriveAvailableSize(R.Paths.App);
                        LogCleaner.LogFileAnalyse();
                    }

                    IsCleaning = false;
                }
            });
        }
コード例 #3
0
        /// <summary>
        /// 查询过期的日志文件(15天前)
        /// </summary>
        /// <returns></returns>
        private static List <string> GetExpireLogFile(List <string> list, out long allSize, out long expireSize)
        {
            List <string> result = new List <string>();

            allSize    = 0;
            expireSize = 0;
            if (Ls.Ok(list))
            {
                foreach (var file in list)
                {
                    try
                    {
                        FileInfo file_info = new FileInfo(file);
                        if (file_info.LastWriteTime.AddDays(15) < DateTime.Now)
                        {
                            result.Add(file);
                            expireSize += file_info.Length;
                        }
                        allSize += file_info.Length;
                    }
                    catch { }
                }
            }
            return(result);
        }
コード例 #4
0
        private void Form1_Load(object sender, EventArgs e)
        {
            Azylee.YeahWeb.ExtWebAPI.BingWebAPI.WallpaperUtils.WallpaperTool.GetLast10Days();

            List <string> file_list = new List <string>();
            var           md        = Azylee.YeahWeb.ExtWebAPI.BingWebAPI.WallpaperUtils.WallpaperTool.GetToday();
            var           md2       = Azylee.YeahWeb.ExtWebAPI.BingWebAPI.WallpaperUtils.WallpaperTool.GetYesterday();

            if (md != null && Ls.Ok(md.images))
            {
                foreach (var item in md.images)
                {
                    string image_url   = item.GetImageUrl();
                    string file_path   = DirTool.Combine(@"F:\imgs", item.hsh + ".jpg");
                    bool   down_result = HttpTool.Download(image_url, file_path);
                    if (down_result)
                    {
                        file_list.Add(file_path);
                    }
                }
            }
            //string a = WallpaperTool.Get();

            //bool b = WallpaperTool.Set(@"C:\Users\yuzhengyang\Pictures\\cc.jpg");

            //Bitmap b1 = new Bitmap(@"F:\图片压缩测试\未标题-1.jpg");
            //byte[] b1_byte = IMG.Compression(b1, 30);
            //File.WriteAllBytes(@"F:\图片压缩测试\未标题-1(Compression).jpg", b1_byte);
        }
コード例 #5
0
 public static List <NetworkInterface> GetNetworkInterfaces()
 {
     try
     {
         NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces();
         if (Ls.Ok(adapters))
         {
             foreach (var item in adapters)
             {
                 try
                 {
                     if (NetworkInterfaces.Any(x => x.Id == item.Id))
                     {
                     }
                     else
                     {
                         NetworkInterfaces.Add(item);
                     }
                 }
                 catch { }
             }
         }
     }
     catch { }
     return(NetworkInterfaces);
 }
コード例 #6
0
        public static List <USBStorageModel> GetAll()
        {
            List <USBStorageModel> result = new List <USBStorageModel>();

            try
            {
                var idList = GetStorageID();
                if (Ls.Ok(idList))
                {
                    foreach (var id in idList)
                    {
                        var volumeList = GetVolumeID(id);
                        if (Ls.Ok(volumeList))
                        {
                            foreach (var volume in volumeList)
                            {
                                var storageList = GetStorage(id, volume);
                                if (Ls.Ok(storageList))
                                {
                                    result.AddRange(storageList);
                                }
                            }
                        }
                    }
                }
            }
            catch { }
            return(result);
        }
コード例 #7
0
        private void Do()
        {
            Task.Factory.StartNew(() =>
            {
                List <int> ports = CMDNetstatTool.GetAvailablePorts(10, 52810);
                if (Ls.Ok(ports))
                {
                    foreach (var p in ports)
                    {
                        try
                        {
                            R.Tx.TcppPort   = p;
                            R.Tx.TcppServer = new TcppServer(R.Tx.TcppPort, TcppEvent.ReceiveMessage,
                                                             TcppEvent.OnConnect, TcppEvent.OnDisconnect);
                            R.Tx.TcppServer.Start();//启动 Socket Tcp 通信机制
                            IniTool.Set(R.Files.Settings, "Tx", "TcppPort", R.Tx.TcppPort);
                            IniTool.Set(R.Files.Settings, "Tx", "StartTime", DateTime.Now.ToString());
                            break;
                        }
                        catch { }
                    }
                }

                R.USBListener.Start();        // 启动USB监控
                R.USBStorageListener.Start(); // 启动U盘监控
            });
        }
コード例 #8
0
        public static void Bind(ref List <USBDeviceModel> list)
        {
            var ids = GetStorageID();

            if (Ls.Ok(ids) && Ls.Ok(list))
            {
                foreach (var l in list)
                {
                    foreach (var i in ids)
                    {
                        if (l.VID.Contains(i.VID) && l.PID.Contains(i.PID))
                        {
                            l.IsStorage = true;
                        }
                    }
                }
            }

            var vols = GetAll();

            if (Ls.Ok(vols) && Ls.Ok(list))
            {
                foreach (var l in list)
                {
                    foreach (var v in vols)
                    {
                        if (l.VID.Contains(v.VID) && l.PID.Contains(v.PID))
                        {
                            l.Volume += v.Symbol + ",";
                        }
                    }
                }
            }
        }
コード例 #9
0
 internal static void Bind(ref List <USBStorageModel> list)
 {
     if (Ls.Ok(list) && Ls.Ok(__USBIDS))
     {
         foreach (var item in list)
         {
             string vid = item.VID.Substring(4, 4);
             string pid = item.PID.Substring(4, 4);
             //查询厂商信息
             var vendor = __USBIDS.FirstOrDefault(x => x.VendorID == vid);
             if (vendor != null)
             {
                 item.VendorName = vendor.VendorName;//设置厂商信息
                 if (Ls.Ok(vendor.USBProducts))
                 {
                     //查询产品信息
                     var product = vendor.USBProducts.FirstOrDefault(x => x.ProductID.Contains(pid));
                     if (product != null)
                     {
                         item.ProductName = product.ProductName;                 //设置产品信息
                     }
                 }
             }
         }
     }
 }
コード例 #10
0
        public static List <USBStorageIDModel> GetStorageID()
        {
            List <USBStorageIDModel> result = null;

            try
            {
                RegistryKey usbsKey = Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Services\USBSTOR\Enum", false);
                if (usbsKey != null)
                {
                    string[] usbs = usbsKey.GetValueNames();
                    if (Ls.Ok(usbs))
                    {
                        result = new List <USBStorageIDModel>();
                        foreach (var usb in usbs)
                        {
                            object valueObj = usbsKey.GetValue(usb);
                            string value    = valueObj.ToString();
                            if (int.TryParse(usb, out int index) && value.Contains("USB"))
                            {
                                result.Add(USBStorageIDModel.String2Model(value));
                            }
                        }
                    }
                }
            }
            catch { }
            return(result);
        }
コード例 #11
0
ファイル: FileFinder.cs プロジェクト: zyj0021/Fork
        /// <summary>
        /// 获取所有目录中的所有文件
        /// </summary>
        /// <param name="path"></param>
        /// <param name="action"></param>
        /// <param name="patterns"></param>
        public static void GetAllFile(string path, Action <List <string> > action, string[] patterns = null)
        {
            List <string> allpath = DirFinder.GetAllPath(path);

            if (allpath == null)
            {
                allpath = new List <string>();
            }
            allpath.Add(path);

            foreach (var p in allpath)
            {
                if (Ls.Ok(patterns))
                {
                    foreach (var pattern in patterns)
                    {
                        List <string> files = GetFile(p, pattern);
                        if (Ls.Ok(files))
                        {
                            action?.Invoke(files);
                        }
                    }
                }
                else
                {
                    List <string> files = GetFile(p);
                    if (Ls.Ok(files))
                    {
                        action?.Invoke(files);
                    }
                }
            }
        }
コード例 #12
0
        // GET: Report
        public ActionResult Index()
        {
            using (Muse db = new Muse())
            {
                IEnumerable <ReportDataSourceModel> sources = db.GetAll <ReportDataSourceModel>(new string[] { "ReportDataSetModels" }, false);

                if (Ls.Ok(sources))
                {
                    var    source = sources.First();
                    string cs     = source.ConnectionString;
                    string sql    = source.ReportDataSets.First().Sql;

                    MySqlHelper msHelper = new MySqlHelper(cs);
                    DataTable   a        = msHelper.Select(sql, out int recordsAffected);
                    ReportModel ri       = new ReportModel()
                    {
                        DataTable    = a,
                        ReportOption = new ReportOptionModel()
                        {
                            Title      = "标题XXXXXX",
                            Type       = "ECharts.BasicLineChart",
                            Dimensions = "continent,cts,rgs",
                            SeriesType = "bar,bar",
                            Height     = 400,
                        }
                    };
                    ViewBag.Report = ri;
                }
            }
            return(View());
        }
コード例 #13
0
 public bool IsExistByHost(string host)
 {
     if (Ls.Ok(TcpClientList))
     {
         return(TcpClientList.Any(x => x.Host == host));
     }
     return(false);
 }
コード例 #14
0
 public bool IsExistByNumber(int number)
 {
     if (Ls.Ok(TcpClientList))
     {
         return(TcpClientList.Any(x => x.Number == number));
     }
     return(false);
 }
コード例 #15
0
        private bool CheckCurrentAuth(HttpContextBase httpContext, List <AuthorizeModel> list, string controller, string action)
        {
            bool result = false;

            if (Ls.Ok(list))
            {
                var userManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(new ApplicationDbContext()));
                var currentUser = userManager.FindById(httpContext.User.Identity.GetUserId());

                foreach (var item in list)
                {
                    //通配符验证方式
                    if (item.Controller == controller && item.Action == "*")
                    {
                        if (item.IsEnable)
                        {
                            if (item.AllowAnonymous)
                            {
                                result = true;
                            }
                            else
                            {
                                if (currentUser != null && userManager.IsInRole(currentUser.Id, item.Role))
                                {
                                    result = true;
                                }
                            }
                        }
                    }

                    //标准验证方式
                    if (item.Controller == controller && item.Action == action)
                    {
                        if (item.IsEnable)
                        {
                            if (item.AllowAnonymous)
                            {
                                result = true;
                            }
                            else
                            {
                                if (currentUser != null && userManager.IsInRole(currentUser.Id, item.Role))
                                {
                                    result = true;
                                }
                            }
                        }
                    }
                    if (result)
                    {
                        break;        //如果已验证通过,直接跳过其他验证
                    }
                }
            }
            return(result);
        }
コード例 #16
0
ファイル: DeviceFun.cs プロジェクト: xiaohszx/USBManager
        /// <summary>
        /// 禁用设备列表
        /// </summary>
        /// <param name="host"></param>
        /// <param name="model"></param>
        public static void Disable(TcpDataModel model)
        {
            List <USBDeviceModel> list = Json.Byte2Object <List <USBDeviceModel> >(model.Data);

            if (Ls.Ok(list))
            {
                int count = list.Count(x => x.Running == false);
                R.Toast.Show("启用设备", $"已禁用{count}个设备");
            }
        }
コード例 #17
0
        internal static List <USBVendorModel> GetByFile()
        {
            string s = TxtTool.Read(R.Files.USBIds);
            List <USBVendorModel> list = Json.String2Object <List <USBVendorModel> >(s);

            if (Ls.Ok(list))
            {
                return(list);
            }
            return(null);
        }
コード例 #18
0
 public void NIMainText()
 {
     if (Ls.Ok(R.Hosts))
     {
         NIMain.Text = R.AppNameCHShort + $" [{R.Hosts.Count()}C]";
     }
     else
     {
         NIMain.Text = R.AppNameCHShort;
     }
 }
コード例 #19
0
 /// <summary>
 /// 检查 Administrator 密码是否正确
 /// </summary>
 /// <param name="pwds"></param>
 /// <returns></returns>
 public static string CheckPasswords(List <string> pwds)
 {
     if (Ls.Ok(pwds))
     {
         foreach (var item in pwds)
         {
             if (CheckPassword(item))
             {
                 return(item);
             }
         }
     }
     return(null);
 }
コード例 #20
0
        /// <summary>
        /// 禁用设备列表
        /// </summary>
        /// <param name="host"></param>
        /// <param name="model"></param>
        public static void Disable(string host, TcpDataModel model)
        {
            List <USBStorageModel> list = Json.Byte2Object <List <USBStorageModel> >(model.Data);

            if (Ls.Ok(list))
            {
                foreach (var item in list)
                {
                    //if (DevconUSBTool.Disable(item.ID))
                    //    item.Running = false;
                }
            }
            R.Tx.TcppServer.Write(host, 30003001, Json.Object2Byte(list));
        }
コード例 #21
0
        private void BtnUpdate_Click(object sender, EventArgs e)
        {
            R.AppointFile = textBox1.Text;
            string filename = Path.GetFileName(R.AppointFile);
            string filemd5  = FileTool.GetMD5(R.AppointFile);

            if (Ls.Ok(R.Tx.Hosts))
            {
                foreach (var item in R.Tx.Hosts)
                {
                    R.Tx.TcppServer.Write(item, 90001000, Json.Object2Byte(new Tuple <string, string>(filename, filemd5)));
                }
            }
        }
コード例 #22
0
        private void BtnLoad_Click(object sender, EventArgs e)
        {
            List <string> list111 = NetcardControlTool.GetList();

            MacList = NetCardInfoTool.GetNetworkCardInfo();
            if (Ls.Ok(MacList))
            {
                LbxNetworkList.Items.Clear();
                foreach (var item in MacList)
                {
                    LbxNetworkList.Items.Add(item.Item2);
                }
            }
        }
コード例 #23
0
 public static void Start()
 {
     Task.Factory.StartNew(() =>
     {
         while (!R.MainUI.IsDisposed)
         {
             if (Ls.Ok(R.Tx.Hosts))
             {
                 R.Store.Persistence();
             }
             Sleep.S(10);
         }
     });
 }
コード例 #24
0
 /// <summary>
 /// 安装服务(安装、运行、设置自启,一条龙服务)
 /// </summary>
 /// <param name="name">服务名</param>
 /// <param name="path">应用程序路径</param>
 /// <param name="account">运行账户信息</param>
 /// <returns></returns>
 public static bool Install(string name, string path, WindowsAccountModel account = null)
 {
     try
     {
         List <string> createResult = CMDProcessTool.Execute($"sc create {name} binPath= \"{path}\"", account);
         List <string> startResult  = CMDProcessTool.Execute($"net start {name}", account);
         List <string> configResult = CMDProcessTool.Execute($"sc config {name} start= AUTO", account);
         if (Ls.Ok(createResult))
         {
             return(createResult.Any(x => x.Contains("成功") || x.Contains("服务已存在")));
         }
         return(false);
     }
     catch { return(false); }
 }
コード例 #25
0
        /// <summary>
        /// 日志文件分析
        /// </summary>
        public static void LogFileAnalyse()
        {
            List <string> all_log          = GetAllLogFile();
            List <string> expire_log       = GetExpireLogFile(all_log, out long allSize, out long expireSize);
            int           all_log_count    = Ls.Ok(all_log) ? all_log.Count : 0;
            int           expire_log_count = Ls.Ok(expire_log) ? expire_log.Count : 0;

            R.SystemStatus.AllLogCount    = all_log_count;
            R.SystemStatus.AllLogSize     = (long)ByteConvertTool.Cvt(allSize, "KB");
            R.SystemStatus.ExpireLogCount = expire_log_count;
            R.SystemStatus.ExpireLogSize  = (long)ByteConvertTool.Cvt(expireSize, "KB");

            //R.Log.I($"全部日志文件:{all_log_count} 个, 共计:{ByteConvertTool.Cvt(allSize, "GB")} GB");
            //R.Log.I($"过期日志文件:{expire_log_count} 个, 共计:{ByteConvertTool.Cvt(expireSize, "GB")} GB");
        }
コード例 #26
0
 /// <summary>
 /// 卸载服务(关闭、删除,一条龙服务)
 /// </summary>
 /// <param name="name"></param>
 /// <param name="account">运行账户信息</param>
 public static bool Uninstall(string name, WindowsAccountModel account = null)
 {
     try
     {
         List <string> stopResult   = CMDProcessTool.Execute($"sc stop {name}", account);
         List <string> deleteResult = CMDProcessTool.Execute($"sc delete {name}", account);
         List <string> queryResult  = CMDProcessTool.Execute($"sc query {name}");
         if (Ls.Ok(queryResult))
         {
             return(queryResult.Any(x => x.Contains("失败") || x.Contains("1060") || x.Contains("服务未安装")));
         }
         return(false);
     }
     catch { return(false); }
 }
コード例 #27
0
        internal static List <USBVendorModel> GetByWeb()
        {
            try
            {
                string   s     = HttpTool.Get("http://www.linux-usb.org/usb.ids");
                string[] lines = s.Split('\n');
                if (Ls.Ok(lines))
                {
                    List <USBVendorModel> list         = new List <USBVendorModel>();
                    List <string>         vendor_lines = new List <string>();

                    foreach (var l in lines)
                    {
                        if (l.StartsWith("#"))
                        {
                            continue;
                        }
                        if (!Str.Ok(l.Trim()))
                        {
                            continue;
                        }

                        if (!l.StartsWith("\t") && vendor_lines.Count() > 0)
                        {
                            var model = USBVendorModel.String2Model(vendor_lines);
                            if (model != null)
                            {
                                list.Add(model);
                                if (model.VendorID == "FFEE")
                                {
                                    break;
                                }
                                vendor_lines = new List <string>();
                            }
                        }

                        vendor_lines.Add(l);
                    }

                    if (Ls.Ok(list))
                    {
                        return(list);
                    }
                }
            }
            catch { }
            return(null);
        }
コード例 #28
0
ファイル: DeviceFun.cs プロジェクト: xiaohszx/USBManager
        /// <summary>
        /// 启用设备列表
        /// </summary>
        /// <param name="host"></param>
        /// <param name="model"></param>
        public static void Enable(string host, TcpDataModel model)
        {
            List <USBDeviceModel> list = Json.Byte2Object <List <USBDeviceModel> >(model.Data);

            if (Ls.Ok(list))
            {
                foreach (var item in list)
                {
                    if (USBTool.Enable(item.ID))
                    {
                        item.Running = true;
                    }
                }
            }
            R.Tx.TcppServer.Write(host, 20003000, Json.Object2Byte(list));
        }
コード例 #29
0
        public static bool Eject(string[] volumes)
        {
            bool flag = true;

            if (Ls.Ok(volumes))
            {
                foreach (var item in volumes)
                {
                    if (Str.Ok(item))
                    {
                        flag = flag && Eject(item);
                    }
                }
            }
            return(flag);
        }
コード例 #30
0
        private void ConnectTask(TcpClient client)
        {
            Task.Factory.StartNew(() =>
            {
                OnConnectAction?.Invoke();//委托:已连接
                while (client.Connected)
                {
                    try
                    {
                        TcpDataModel model = TcpStreamHelper.Read(client);
                        if (model != null)
                        {
                            if (model.Type == int.MaxValue)
                            {
                                //返回心跳
                                Write(new TcpDataModel(int.MaxValue));
                            }
                            else
                            {
                                //优先调用默认接收消息方法Action
                                OnReceiveAction?.Invoke(model);

                                //调用同步处理委托方法
                                if (Ls.Ok(SyncFunction))
                                {
                                    for (var i = 0; i < SyncFunction.Count; i++)
                                    {
                                        bool flag = SyncFunction.TryDequeue(out Tuple <int, Action <TcpDataModel> > fun);
                                        if (flag)
                                        {
                                            Task.Factory.StartNew(() => { fun.Item2?.Invoke(model); });
                                        }
                                    }
                                }
                            }
                        }
                    }
                    catch { }
                    //Sleep.S(1);
                }
                client.Close();
                OnDisconnectAction?.Invoke();//委托:断开连接
            });
            //lstn.BeginAcceptTcpClient(new AsyncCallback(acceptCallback), lstn);
        }