Exemple #1
0
        public void AddProxies(string fileName, ProxyType type, List <string> lines)
        {
            List <string> fromFile = new List <string>();
            List <string> fromBox  = new List <string>();

            // Load proxies from file
            if (fileName != "")
            {
                Globals.LogInfo(Components.ProxyManager, $"Trying to load from file {fileName}");

                fromFile.AddRange(File.ReadAllLines(fileName).ToList());
            }
            else
            {
                Globals.LogInfo(Components.ProxyManager, "No file specified, skipping the import from file");
            }

            // Load proxies from textbox lines
            fromBox.AddRange(lines);

            Globals.LogInfo(Components.ProxyManager, $"Adding {fromFile.Count + fromBox.Count} proxies to the database");

            // Check if they're valid
            using (var db = new LiteDatabase(Globals.dataBaseFile))
            {
                foreach (var p in fromFile.Where(p => !string.IsNullOrEmpty(p)).Distinct().ToList())
                {
                    try
                    {
                        CProxy proxy = new CProxy(p, type);
                        if (!proxy.IsNumeric || proxy.IsValidNumeric)
                        {
                            vm.ProxyList.Add(proxy);
                            db.GetCollection <CProxy>("proxies").Insert(proxy);
                        }
                    }
                    catch { }
                }

                foreach (var p in fromBox.Where(p => !string.IsNullOrEmpty(p)).Distinct().ToList())
                {
                    try
                    {
                        CProxy proxy = new CProxy();
                        proxy.Parse(p, type);
                        if (!proxy.IsNumeric || proxy.IsValidNumeric)
                        {
                            vm.ProxyList.Add(proxy);
                            db.GetCollection <CProxy>("proxies").Insert(proxy);
                        }
                    }
                    catch { }
                }
            }

            // Refresh
            vm.UpdateProperties();
        }