public HttpStatusCode UpdateProxies() { var serviceProviders = _proxyProviderService.GetProxyProviders(); var testServers = _proxyTestServerService.GetTestProxies(); Parallel.ForEach(serviceProviders, provider => { try { IList <Proxy> proxyList = ProxyHelper.StartCrawler(provider); provider.LastFetchOn = DateTime.Now; provider.LastFetchProxyCount = proxyList.Count; provider.Exception = ""; if (proxyList.Count > 0) { _proxyService.BatchCreateOrUpdate(proxyList); IList <ProxyTest> proxyTestResults = ProxyHelper.TestProxies(proxyList.ToList(), testServers); if (proxyTestResults.Count > 0) { _proxyTestService.BatchCreateOrUpdate(proxyTestResults); } } } catch (Exception ex) { provider.LastFetchProxyCount = -1; provider.Exception = ex.InnerException?.Message; } _proxyProviderService.Update(provider); }); try { _proxyProviderService.SaveChanges(); return(HttpStatusCode.OK); } catch { return(HttpStatusCode.InternalServerError); } }
public HttpStatusCode Insert([FromForm] ProxyProvider proxy) { try { if (proxy.Id > 0) { _proxyProviderService.Update(proxy); } else { _proxyProviderService.Create(proxy); } return(HttpStatusCode.OK); } catch { return(HttpStatusCode.InternalServerError); } }