/// <summary> /// Add or update a cache item /// </summary> public void Add(string key, object val, DateTime itemTime) { Proxy.Add( getServerEndPoint(_serverId), new TCacheItem(key, val, itemTime), 0, false); }
public static void Add(string key, object val, DateTime absExpirationTime) { int expirationSecond = 0; if (absExpirationTime > DateTime.MinValue) { if (absExpirationTime < DateTime.Now) { return; } double totalSeconds = (absExpirationTime - DateTime.Now).TotalSeconds; if (totalSeconds > int.MaxValue) { expirationSecond = int.MaxValue; } else { expirationSecond = (int)totalSeconds; } } Proxy.Add( NonPersistentNodesList.GetServerEndPoint(key), new TCacheItem(key, val, TCacheNP.NoItemTime), expirationSecond, true); }
/// <summary> /// Add or update a cache item /// </summary> public static void Add(string key, object val, TimeSpan expirationTime) { Proxy.Add( NonPersistentNodesList.GetServerEndPoint(key), new TCacheItem(key, val, TCacheNP.NoItemTime), (int)expirationTime.TotalSeconds, false); }
public void UpdatingAToxicShouldWorks() { // Add a toxics to a proxy. // After update all the toxic's properties // Reload the toxic again and check that all the properties // are correctly updated var client = _connection.Client(); var proxy = new Proxy { Name = "testingProxy", Enabled = true, Listen = "127.0.0.1:9090", Upstream = "google.com" }; proxy = client.Add(proxy); var toxic = new SlicerToxic { Name = "SlicerToxicTest", Stream = ToxicDirection.UpStream }; toxic.Attributes.AverageSize = 10; toxic.Attributes.Delay = 5; toxic.Attributes.SizeVariation = 1; toxic = proxy.Add(toxic); // Reload the toxic and update the properties var toxicInProxy = (SlicerToxic)proxy.GetToxicByName(toxic.Name); // Update the toxic's property toxicInProxy.Name = "NewName"; toxicInProxy.Stream = ToxicDirection.DownStream; toxicInProxy.Attributes.AverageSize = 20; toxicInProxy.Attributes.Delay = 10; toxicInProxy.Attributes.SizeVariation = 2; proxy.UpdateToxic(toxic.Name, toxicInProxy); // Reload again (we must use the initial name because the toxic update // cannot update the toxic name var updatedToxic = proxy.GetToxicByName(toxic.Name); // Assert // WARNING: By design it's not possible to update the name and the stream properties of the proxy. Assert.NotEqual(toxicInProxy.Name, updatedToxic.Name); Assert.NotEqual(toxicInProxy.Stream, updatedToxic.Stream); Assert.IsType <SlicerToxic>(toxicInProxy); var specificToxicInProxy = (SlicerToxic)toxicInProxy; Assert.Equal(toxicInProxy.Attributes.AverageSize, specificToxicInProxy.Attributes.AverageSize); Assert.Equal(toxicInProxy.Attributes.Delay, specificToxicInProxy.Attributes.Delay); Assert.Equal(toxicInProxy.Attributes.SizeVariation, specificToxicInProxy.Attributes.SizeVariation); }
public virtual void SetImportValue(string value) { Proxy list = GetList(); list.Clear(); foreach (TType newValue in StringToList <TType> .StaticConvert(value, ConvertFromString)) { list.Add(newValue); } }
public ApiGatewayConfig() { Balancer.Add(new BalancerOption { Enable = false, Host = "localhost:64516", Nodes = new Node[] { new Node { Host = "google.com", Port = 443, Scheme = "https", Enable = true }, new Node { Host = "amazon.com", Port = 443, Scheme = "https", Enable = true } }, Path = "^(.*)$", Policy = "RoundRobin", Port = 64516, Scheme = "http" }); Proxy.Add(new ProxyOption { Enable = false, Host = "localhost:64516", Node = new Node { Host = "google.com", Port = 443, Scheme = "https" }, Path = "^(.*)$", Port = 64516, Scheme = "http" }); Cache = new CacheOption { Enable = false, Duration = 600, MaximumBodySize = 100 * 1024 * 1024, SizeLimit = 64 * 1024 * 1024, UseCaseSensitivePaths = false }; Logging = new LoggingOption { Enable = false }; }
protected virtual void PrivatePerform(IEnumerable <Item> results) { Proxy list = GetList(); foreach (Item item in results) { if (list.Contains(item.Value)) { list.Remove(item.Value); } else { list.Add(item.Value); } } }
public string getProxy() { string itemProxy = null; try { if (!Proxy.Contains(null)) { Proxy.Add(null); new Thread(new ThreadStart(start)).Start(); } Random random = new Random(); int index = random.Next(0, Proxy.Count); itemProxy = Proxy[index]; } catch (Exception e) { Log2Txt.logError(Log2Txt.GetMethodInfo() + e.Message); } return(itemProxy); }
public void GetAnExistingToxicFromAProxyShouldWork() { // Add a toxics to a proxy. // After reload the toxic again and check that all the properties // are correctly saved var client = _connection.Client(); var proxy = new Proxy { Name = "testingProxy", Enabled = true, Listen = "127.0.0.1:9090", Upstream = "google.com" }; proxy = client.Add(proxy); var toxic = new SlicerToxic { Name = "SlicerToxicTest", Stream = ToxicDirection.UpStream }; toxic.Attributes.AverageSize = 10; toxic.Attributes.Delay = 5; toxic.Attributes.SizeVariation = 1; toxic = proxy.Add(toxic); // Reload the toxic and update the properties var toxicInProxy = proxy.GetToxicByName(toxic.Name); // Assert Assert.Equal(toxicInProxy.Name, toxic.Name); Assert.Equal(toxicInProxy.Stream, toxic.Stream); Assert.IsType <SlicerToxic>(toxicInProxy); var specificToxicInProxy = (SlicerToxic)toxicInProxy; Assert.Equal(specificToxicInProxy.Attributes.AverageSize, toxic.Attributes.AverageSize); Assert.Equal(specificToxicInProxy.Attributes.Delay, toxic.Attributes.Delay); Assert.Equal(specificToxicInProxy.Attributes.SizeVariation, toxic.Attributes.SizeVariation); }
private void crawlProxy() { HtmlDocument html = new HtmlDocument(); List <string> ipList = new List <string>(); List <string> portList = new List <string>(); int maxPageNum = 0; string page = string.Empty; int pageIndex = 1; string itemUrl = string.Empty; string itemProxy = string.Empty; try { for (int i = 0; i < proxySites.Length; i++) { pageIndex = 1; itemUrl = proxySites[i]; itemProxy = getProxy(); page = getPage(itemUrl); if (string.IsNullOrEmpty(page)) { continue; } html.LoadHtml(page); string item = getValueByXPathAndAttribute(html, maxPagNumXPath); maxPageNum = Convert.ToInt32(item); while (maxPageNum >= pageIndex) { do { itemProxy = getProxy(); Log2Txt.logInfo(Log2Txt.GetMethodInfo() + "page(" + pageIndex + "/" + maxPageNum + "):" + "currentUrl:" + itemUrl + " currentProxy:" + itemProxy + "\r\n"); page = getPage(itemUrl, itemProxy); html.LoadHtml(page); ipList = getValuesByXPathAndAttribute(html, ipXPath); portList = getValuesByXPathAndAttribute(html, portXPath); for (int j = 0; j < ipList.Count; j++) { string str = ipList[j].ToString() + ":" + portList[j].ToString(); if (!isVaildProxy(str)) { continue; } if (Proxy.Contains(str)) { continue; } Proxy.Add(str); Log2Txt.logInfo("Find a proxy:" + str); } if (ipList.Count > 0) { pageIndex++; itemUrl = proxySites[i].Replace("1", pageIndex.ToString()); } else { removeProxy(itemProxy); } Thread.Sleep(1000); } while (ipList.Count == 0); } if (Proxy.Count > 1) { setProxysToFile(); } } } catch (Exception e) { Log2Txt.logError(Log2Txt.GetMethodInfo() + e.Message); } }