/** * Check if current DatafeedResult contains "Keyword" * @params: keyword: Search keyword * @return: True: if it contains, False: if it doesn't contain * */ public bool Find(string keyword) { if ((DatafeedID.Contains(keyword) && CheckStatus.Check_DatafeedID) || (Guid.Contains(keyword) && CheckStatus.Check_Guid) || (DatafeedName.Contains(keyword) && CheckStatus.Check_DatafeedName) || (SecurityUsername.Contains(keyword) && CheckStatus.Check_SecurityUsername) || (SecurityPassword.Contains(keyword) && CheckStatus.Check_SecurityPassword) || (TransportUsername.Contains(keyword) && CheckStatus.Check_TransportUsername) || (TransportPassword.Contains(keyword) && CheckStatus.Check_TransportPassword) || (TransportURL.Contains(keyword) && CheckStatus.Check_TransportURL) || (TransportInstance.Contains(keyword) && CheckStatus.Check_TransportInstance) || (SecurityDomain.Contains(keyword) && CheckStatus.Check_SecurityDomain) || (TransportDomain.Contains(keyword) && CheckStatus.Check_TransportDomain) || (ProxyOption.Contains(keyword) && CheckStatus.Check_ProxyOption) || (ProxyName.Contains(keyword) && CheckStatus.Check_ProxyName) || (ProxyPort.Contains(keyword) && CheckStatus.Check_ProxyPort) || (ProxyDomain.Contains(keyword) && CheckStatus.Check_ProxyDomain) || (ProxyUserName.Contains(keyword) && CheckStatus.Check_ProxyUserName) || (ProxyPassword.Contains(keyword) && CheckStatus.Check_ProxyPassword) || (TransportPath.Contains(keyword) && CheckStatus.Check_TransportPath) || (ConnectionString.Contains(keyword) && CheckStatus.Check_ConnectionString) || (SQLQueryUsername.Contains(keyword) && CheckStatus.Check_SQLQueryUsername) || (SQLQueryPassword.Contains(keyword) && CheckStatus.Check_SQLQueryPassword) ) { return(true); } return(false); }
/// <summary> /// FillHierarchy method implementation /// </summary> public ProxyDomain FillHierarchy(string hierarchyNodeID, int numberOfLevels) { ProxyDomain results = null; ExecuteOnChannel("FillHierarchy", ExecuteOptions.AsProcess, channel => results = channel.FillHierarchy(hierarchyNodeID, numberOfLevels)); return(results); }
/// <summary> /// 验证Ip可用性 /// </summary> /// <param name="maxThreadNum">启用多少线程验证</param> public void ValidateCanUse(int maxThreadNum = 1) { var tasks = new Task[maxThreadNum]; for (var i = 0; i < maxThreadNum; i++) { tasks[i] = new Task(() => { for (var j = 0; j < MaxValue; j++) { ProxyDomain proxyDomain = new ProxyDomain(); var id = new Random().Next(1, proxyDomain.GetMaxId()); var proxyEntity = proxyDomain.GetById(id); if (proxyEntity.Id == 0) { continue; } if (ThreadValidate.Doit(proxyEntity)) { break; } } Console.WriteLine("完成"); }); tasks[i].Start(); } Task.WaitAll(tasks); }
private Assembly OnCurrentDomainAssemblyResolve(object sender, ResolveEventArgs e) { if (e.RequestingAssembly == null) { return(null); } AssemblyName assemblyName = new AssemblyName(e.Name); if (assemblyName.Name.EndsWith(".resources", StringComparison.InvariantCultureIgnoreCase) && !assemblyName.CultureName.EndsWith("neutral", StringComparison.InvariantCultureIgnoreCase)) { return(null); } // Try to load the dependencies located to the temp directory... string tmpPath = Path.Combine(Path.GetTempPath(), "LayerCake Generator", this.Context.ProjectName); FileInfo[] files = new DirectoryInfo(tmpPath).GetFiles(string.Format("{0}.*.dll", assemblyName.Name)); FileInfo file = files.First(i => i.CreationTimeUtc == files.Max(j => j.CreationTimeUtc)); string requiredAssemblyPath = Path.Combine(tmpPath, file.Name); ProxyDomain proxyDomain = new ProxyDomain(); Assembly assembly = proxyDomain.LoadAssembly(requiredAssemblyPath, withPdbSymbols: true); return(assembly); }
/// <summary> /// Gets a type /// </summary> /// <param name="typeName">Type name in the format "type" or "type@path", where "type" is the name of the type /// and "path" is the path to the assembly on disk. Type must have a single parameterless constructor.</param> /// <param name="assembly">Assembly to get type from</param> /// <returns>Type</returns> public static Type GetType(string typeName, Assembly assembly = null) { string[] typeParts = typeName.Split('@'); if (typeParts.Length > 1 && assembly != null) { throw new Exception("Cannot both pass an assembly and include its path in the type name"); } if (assembly == null) { if (typeParts.Length == 1) { int lastPlus = typeParts[0].LastIndexOf('+'); if (!_externalTypeAssembly.TryGetValue(typeParts[0], out assembly) && (lastPlus == -1 || !_externalTypeAssembly.TryGetValue(typeParts[0].Substring(0, lastPlus), out assembly))) { assembly = Assembly.GetExecutingAssembly(); } } else if (typeParts.Length == 2) { assembly = new ProxyDomain().LoadAssemblyFrom(typeParts[1].Trim()); if (!_externalTypeAssembly.ContainsKey(typeParts[0])) { _externalTypeAssembly.Add(typeParts[0], assembly); } } else { throw new Exception("Invalid type: " + typeName); } } Type type; try { if (typeParts.Length == 1 || typeParts.Length == 2) { type = assembly.GetType(typeParts[0].Trim(), true, false); } else { throw new Exception("Invalid type: " + typeName); } } catch (Exception ex) { throw new Exception("Failed to get type: " + ex); } return(type); }
/// <summary> /// 直接采集IP并更新到数据库 /// </summary> /// <param name="countNum">采集IP总数</param> /// <param name="getNum">每次提取数量</param> /// <param name="isValidate">是否对代理验证</param> public void ProxySave(int countNum = 100, int getNum = 5, bool isValidate = false) { new Thread(() => { while (true) { if (countNum == 0) { break; } var ipLists = GetProxyByHttp(getNum).Split(Environment.NewLine.ToCharArray()).ExceptNull().ToList(); foreach (var ipList in ipLists) { var ipAndPort = ipList.Split(':'); if (string.IsNullOrWhiteSpace(ipList) || ipAndPort.Length < 2) { continue; } Console.WriteLine("获取到代理:" + ipList); var model = new ProxyEntity(); model.IpAddress = ipAndPort[0]; model.Port = Conv.ToInt(ipAndPort[1]); model.Usage = 0; model.CreateTime = DateTime.Now; ProxyDomain proxyDomain = new ProxyDomain(); if (isValidate) { if (ThreadValidate.VerificationIp(model.IpAddress, model.Port)) { if (!proxyDomain.IsExist(model)) { proxyDomain.Add(model); } countNum--; } } if (!proxyDomain.IsExist(model)) { proxyDomain.Add(model); } countNum--; } } Console.WriteLine("IP采集完毕"); }) { IsBackground = false }.Start(); }
/// <summary> /// Open a scraper config. We get the scraper information about the config form from the service, then use /// reflection to load the neccessary dll files. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void miOpenConfig_Click(object sender, RoutedEventArgs e) { try { WebScraper scraper = (WebScraper)lvScrapers.SelectedItem; if (scraper != null) { System.Windows.Forms.Application.EnableVisualStyles(); WebConfigResult scraperDll = Proxy.GetConfig(scraper.ScraperId); if (File.Exists(scraperDll.DllPath)) { ProxyDomain pd = new ProxyDomain(); Assembly assembly = pd.GetAssembly(scraperDll.DllPath); String assemblyName = scraperDll.PluginAssemblyName; IScraperPlugin plugin = (IScraperPlugin)assembly.CreateInstance(assemblyName); NativeAssemblyLoader.SetSearchDirectory(Path.GetFullPath(Path.GetDirectoryName(scraperDll.DllPath))); Form config = plugin.CreateConfig(); WebScraperState before = Proxy.GetScraperState(scraper.ScraperId).ScraperState; if (before == WebScraperState.Running) { bool result = Proxy.PauseScraper(scraper.ScraperId); } config.ShowDialog(); if (before == WebScraperState.Running) { bool result = Proxy.ResumeScraper(scraper.ScraperId); } } else { Log.Warn("Couldn't load scraper config, {0} doesn't exist", scraperDll.DllPath); } } } catch (Exception ex) { Log.Error("Error starting scraper config", ex); } }
static string GetEndpointName(string path) { var assemblyFiles = new DirectoryInfo(path).GetFiles("*.dll", SearchOption.AllDirectories) .Union(new DirectoryInfo(path).GetFiles("*.exe", SearchOption.AllDirectories)); assemblyFiles = assemblyFiles.Where(f => !defaultAssemblyExclusions.Any(exclusion => f.Name.ToLower().StartsWith(exclusion))); var results = new List<Assembly>(); foreach (var assemblyFile in assemblyFiles) { try { var pd = new ProxyDomain(); var assembly = pd.GetAssembly(assemblyFile.FullName); assembly.GetTypes(); results.Add(assembly); } catch(Exception e) { } } var endPointType = ScanAssembliesForEndpoints(results).FirstOrDefault(); if (endPointType == null) { throw new Exception(string.Format("No implementation of IConfigureThisEndpoint found in {0}", path)); } //Stolen from https://github.com/NServiceBus/NServiceBus/blob/master/src/hosting/NServiceBus.Hosting.Windows/Program.cs var endpointConfiguration = Activator.CreateInstance(endPointType); var endpointName = endpointConfiguration.GetType().Namespace; var arr = endpointConfiguration.GetType().GetCustomAttributes(typeof(EndpointNameAttribute), false); if (arr.Length == 1) endpointName = (arr[0] as EndpointNameAttribute).Name; if (endpointConfiguration is INameThisEndpoint) endpointName = (endpointConfiguration as INameThisEndpoint).GetName(); return endpointName; }
protected override void BeginProcessing() { base.BeginProcessing(); if (path.StartsWith(@".\")) { path = System.IO.Path.Combine(this.CurrentProviderLocation("FileSystem").ProviderPath, path.Substring(2)); } else { path = System.IO.Path.Combine(this.CurrentProviderLocation("FileSystem").ProviderPath, path); } path = System.IO.Path.GetFullPath(path); if (!System.IO.File.Exists(path)) { ThrowTerminatingError(new ErrorRecord(new FileNotFoundException(string.Format("File {0} not found", path)), "100", ErrorCategory.OpenError, path)); } string domainName = "GetSelfHostedPSDomain-" + Guid.NewGuid().ToString().GetHashCode().ToString("x"); Evidence domainEvidence = new Evidence(AppDomain.CurrentDomain.Evidence); AppDomainSetup domainInfo = new AppDomainSetup(); domainInfo.ApplicationName = domainName; domainInfo.ApplicationBase = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); AppDomain subDomain = AppDomain.CreateDomain(domainName, domainEvidence, domainInfo); Type type = typeof(ProxyDomain); ProxyDomain proxyDomain = (ProxyDomain)subDomain.CreateInstanceAndUnwrap(type.Assembly.FullName, type.FullName); proxyDomain.LoadAssembly(GetDLLLocation("System")); proxyDomain.LoadAssembly(GetDLLLocation("System.Management")); proxyDomain.LoadAssembly(GetDLLLocation("System.Management.Automation")); proxyDomain.LoadAssembly(Assembly.GetExecutingAssembly().Location); WriteObject(proxyDomain.GetAssembly(path)); AppDomain.Unload(subDomain); subDomain = null; }
/// <summary> /// Gets a type /// </summary> /// <param name="typeName">Type name in the format "type" or "type@path", where "type" is the name of the type /// and "path" is the path to the assembly on disk. Type must have a single parameterless constructor.</param> /// <param name="assembly">Assembly to get type from</param> /// <returns>Type</returns> public static Type GetType(string typeName, Assembly assembly = null) { string[] typeParts = typeName.Split('@'); if (typeParts.Length > 1 && assembly != null) throw new Exception("Cannot both pass an assembly and include its path in the type name"); if (assembly == null) if (typeParts.Length == 1) { int lastPlus = typeParts[0].LastIndexOf('+'); if (!_externalTypeAssembly.TryGetValue(typeParts[0], out assembly) && (lastPlus == -1 || !_externalTypeAssembly.TryGetValue(typeParts[0].Substring(0, lastPlus), out assembly))) assembly = Assembly.GetExecutingAssembly(); } else if (typeParts.Length == 2) { assembly = new ProxyDomain().LoadAssemblyFrom(typeParts[1].Trim()); if (!_externalTypeAssembly.ContainsKey(typeParts[0])) _externalTypeAssembly.Add(typeParts[0], assembly); } else { throw new Exception("Invalid type: " + typeName); } Type type; try { if (typeParts.Length == 1 || typeParts.Length == 2) type = assembly.GetType(typeParts[0].Trim(), true, false); else throw new Exception("Invalid type: " + typeName); } catch (Exception ex) { throw new Exception("Failed to get type: " + ex); } return type; }
/// <summary> /// 通过在线代理直接获取未验证的IP代理 /// 主要用于本地IP代理库存不足,临时获取 /// </summary> /// <returns></returns> public ProxyEntity GetHttProxyEntity() { var ipList = GetProxyByHttp(); var ipAndPort = ipList.Split(':'); var model = new ProxyEntity(); model.IpAddress = ipAndPort[0]; model.Port = Conv.ToInt(ipAndPort[1]); model.Usage = 1; model.CanUse = true; model.CreateTime = DateTime.Now; model.LastUseTime = DateTime.Now; ProxyDomain proxyDomain = new ProxyDomain(); if (!proxyDomain.IsExist(model)) { proxyDomain.Add(model); } return(model); }
public void Initialize() { string executablePath = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); ProxyDomain pd = new ProxyDomain(); Assembly assembly = pd.GetAssembly(System.IO.Path.Combine(executablePath, "MaterialDesignThemes.Wpf.dll")); Assembly assembly1 = pd.GetAssembly(Path.Combine(executablePath, "MaterialDesignColors.dll")); if (assembly != null | assembly1 != null) { Active.Editor.WriteMessage("style dlls not load"); } StandartCopier standartCopier = new StandartCopier(); if (!File.Exists(standartCopier.Pc3Location) & !File.Exists(standartCopier.PmpLocation)) { bool isCopied = standartCopier.CopyParamsFiles(); if (isCopied) { Active.Editor.WriteMessage("Файлы {0}, {1} скопированы", standartCopier.Pc3Location, standartCopier.PmpLocation); } else { Active.Editor.WriteMessage( "Не удалось скопировать файлы настройки, скопируйте с сервера \\\\uz-fs\\install\\CAD\\Blocks файлы {0} в {1} и {2} ", standartCopier.Pc3Dest, standartCopier.Pc3Location, standartCopier.PmpLocation); } } else { Active.Editor.WriteMessage("Файлы настройки присутствуют, для перевода в pdf наберите CreateTranspdf"); } Active.Editor.WriteMessage("Файлы настройки присутствуют, для перевода в pdf наберите CreateTranspdf"); }
public ASOptionsResponse GetOptions() { if (server == null) { throw new InvalidDataException("ASOptionsRequest not initialized because server was not specified."); } if ((useCertificateAuthentication == false && credential == null) || server == null) { throw new InvalidDataException("ASOptionsRequest not initialized. User credentials or certificate authentication need to be specified."); } string strURI = string.Format("{0}//{1}/Microsoft-Server-ActiveSync", UseSSL ? "https:" : "http:", Server); Uri serverUri = new Uri(strURI); HttpWebRequest httpReq = (HttpWebRequest)WebRequest.Create(strURI); if (useCertificateAuthentication == true) { try { httpReq.UseDefaultCredentials = false; X509Certificate oX509Certificate = null; oX509Certificate = new X509Certificate(certificateFile, certificatePassword); httpReq.ClientCertificates.Add(oX509Certificate); } catch (Exception ex) { MessageBox.Show("Exception: \r\n" + ex.ToString(), "Error setting certificate authentication."); return(null); } } else { try { CredentialCache creds = new CredentialCache(); creds.Add(serverUri, "Basic", Credentials); // Using Basic authentication httpReq.Credentials = creds; } catch (Exception ex) { MessageBox.Show("Exception: \r\n" + ex.ToString(), "Error setting specified credentials."); return(null); } } httpReq.Method = "OPTIONS"; if (SpecifyProxySettings == true) { WebProxy oWebProxy = null; oWebProxy = new WebProxy(ProxyServer, ProxyPort); //oWebProxy.BypassProxyOnLocal = BypassProxyForLocalAddress; if (OverrideProxyCredntials == true) { if (ProxyUser.Trim().Length == 0) { oWebProxy.UseDefaultCredentials = true; } else { if (ProxyDomain.Trim().Length == 0) { oWebProxy.Credentials = new NetworkCredential(ProxyUser, ProxyPassword); } else { oWebProxy.Credentials = new NetworkCredential(ProxyUser, ProxyPassword, ProxyDomain); } } } else { oWebProxy.UseDefaultCredentials = true; } httpReq.Proxy = oWebProxy; } if (UserAgent.Trim().Length != 0) { httpReq.UserAgent = UserAgent; } try { HttpWebResponse httpResp = (HttpWebResponse)httpReq.GetResponse(); ASOptionsResponse response = new ASOptionsResponse(httpResp); httpResp.Close(); return(response); } catch (Exception ex) { System.Windows.Forms.MessageBox.Show(ex.Message, "Error calling GetOptions"); //VSError.ReportException(ex); return(null); } }
public void Execute(IProcessorBehavior behavior, ProcessorParameters parameters) { if (this.IsRunning) { ThrowException.Throw("The processor is already running"); } do { #region [ Begin ] this.IsRunning = true; _stopwatch = new Stopwatch(); _stopwatch.Start(); if (this.CancelToken != null) { this.CancelToken.Dispose(); } this.CancelToken = new CancellationTokenSource(); this.GeneratedServices = new List <string>(); this.HasErrors = false; this.PublishProcessMessage("Running Process ({0} mode)...", parameters.CompilationMode); #endregion #region [ Checking Assemblies Dependencies ] if (this.CancelToken.IsCancellationRequested) { break; } this.PublishProcessMessage("Checking Assemblies Dependencies..."); bool bOk = true; string modelAssemblyPath = Path.Combine(this.Context.SrcDirectory, string.Format(@"{0}.Models", this.Context.ProjectName), string.Format(@"bin\{0}", parameters.CompilationMode), string.Format(@"{0}.Models.dll", this.Context.ProjectName)); if (!File.Exists(modelAssemblyPath)) { bOk = false; } if (bOk) { string businessAssemblyPath = Path.Combine(this.Context.SrcDirectory, string.Format(@"{0}.Business", this.Context.ProjectName), string.Format(@"bin\{0}", parameters.CompilationMode), string.Format(@"{0}.Business.dll", this.Context.ProjectName)); if (!File.Exists(businessAssemblyPath)) { bOk = false; } } if (!bOk) { this.PublishErrorMessage( "The whole solution must be compiled ({0} mode) before running the proccess.", parameters.CompilationMode); break; } #endregion #region [ Checking and Loading Culture Context ] if (this.CancelToken.IsCancellationRequested) { break; } this.PublishProcessMessage("Checking and Loading Culture Context..."); string[] supportedCultures = DatabaseHelper.GetCultures(this.SmoContext); this.Context.Culture.SupportedCultures = supportedCultures; if (this.Context.Culture.SupportedCultures.Length == 0) { this.PublishErrorMessage("The 'Translation' table must define at least one culture!"); break; } foreach (string culture in supportedCultures.Where(c => c.Length != 2)) { this.PublishErrorMessage( "The '{0}' culture column from the 'Translation' table is not correct! Culture columns must be 2 characters long.", culture); break; } if (!supportedCultures.Contains(this.Context.Culture.Default)) { this.PublishErrorMessage( "The default culture '{0}' is not supported ({1}).", this.Context.Culture.Default, string.Join(", ", supportedCultures)); break; } #endregion #region [ Checking and Loading Database Structure ] if (this.CancelToken.IsCancellationRequested) { break; } this.PublishProcessMessage("Checking and Loading Database Structure..."); this.ModelDescriptor = new ModelDescriptor(this.SmoContext, this.Context); string mdFile = null; try { mdFile = this.ModelDescriptor.Load(this.CancelToken.Token); } catch (Exception x) { this.PublishErrorMessage( "Failed while loading Database Structure (Table: '{1}' - Column: '{2}') -> {0}", x, this.ModelDescriptor.CurrentTable.Name, this.ModelDescriptor.CurrentColumn.Name); break; } if (this.CancelToken.IsCancellationRequested) { break; } if (this.ModelDescriptor.Errors.Count != 0) { foreach (var error in this.ModelDescriptor.Errors) { this.PublishErrorMessage(error.GetError()); } break; } #endregion #region [ Checking Authentication Support ] if (this.CancelToken.IsCancellationRequested) { break; } var userTable = this.ModelDescriptor.Schema.Tables.FirstOrDefault(t => t.Name == this.Context.AuthenticationSupport.UserTableName); if (userTable == null) { this.PublishErrorMessage( "The '{0}' table declared in Context.AuthenticationSupport.UserTableName cannot be found in the database!", this.Context.AuthenticationSupport.UserTableName); break; } else { if (userTable.Columns.Count(c => c.Name == this.Context.AuthenticationSupport.UserTableIdentifiedColumnName) == 0) { this.PublishErrorMessage( "The '{0}' table must have a column named '{1}'!", this.Context.AuthenticationSupport.UserTableName, this.Context.AuthenticationSupport.UserTableIdentifiedColumnName); break; } // UserTableIdentifiedColumnName must have an UNIQUE constraint... if (userTable.Constraints == null || userTable.Constraints.Count(c => c.Columns.Any(i => i.Name == this.Context.AuthenticationSupport.UserTableIdentifiedColumnName)) == 0) { this.PublishErrorMessage( "The '{0}' column from the '{1}' table must have an UNIQUE constraint in order to be used as identifier column!", this.Context.AuthenticationSupport.UserTableIdentifiedColumnName, this.Context.AuthenticationSupport.UserTableName); break; } // UserTableName must define Password & Culture columns if (userTable.Columns.Count(c => c.CSharpPropertyName == "Password") == 0 || userTable.Columns.Count(c => c.CSharpPropertyName == "Culture") == 0) { this.PublishErrorMessage( "The '{0}' table must have '{0}_Password' and '{0}_Culture' columns!", this.Context.AuthenticationSupport.UserTableName); break; } } #endregion #region [ Loading Assemblies Dependencies ] if (this.CancelToken.IsCancellationRequested) { break; } this.PublishProcessMessage("Loading Assemblies Dependencies..."); Assembly businessAssembly = null; try { string tmpDir = Path.Combine(Path.GetTempPath(), "LayerCake Generator", this.Context.ProjectName); if (!Directory.Exists(tmpDir)) { Directory.CreateDirectory(tmpDir); } foreach (FileInfo file in new DirectoryInfo(tmpDir).GetFiles()) { string extension = file.Extension.ToLowerInvariant(); if (extension == ".dll" || extension == ".pdb") { try { file.Delete(); } catch (UnauthorizedAccessException) { // Occurred when the assembly is already loaded in the AppDomain.CurrentDomain } catch (Exception) { } } } string guid = Guid.NewGuid().ToString(); string assemblyPath = Path.GetDirectoryName( this.Context.GetAssemblyPath("Business", parameters.CompilationMode)); if (!Directory.Exists(assemblyPath)) { this.PublishErrorMessage("Cannot locate the path {0}", assemblyPath); break; } string businessAssemblyPath = null; ProxyDomain proxyDomain = new ProxyDomain(); // Copy all DLL/PDB files from the Business\bin\Debug to the Temp... foreach (FileInfo file in new DirectoryInfo(assemblyPath).GetFiles()) { string extension = file.Extension.ToLowerInvariant(); if (extension == ".dll" || extension == ".pdb") { string copiedDllPath = Path.Combine(tmpDir, string.Format("{0}.{1}{2}", Path.GetFileNameWithoutExtension(file.Name), guid, extension)); File.Copy(file.FullName, copiedDllPath); if (copiedDllPath.Contains(".Business") && Path.GetExtension(copiedDllPath).ToLowerInvariant() == ".dll") { businessAssemblyPath = copiedDllPath; } } } // Must be at the end once all the DLLs have been copied. // (cf. AppDomain Assembly Resolving (Program.cs, CurrentDomain_AssemblyResolve))... businessAssembly = proxyDomain.LoadAssembly(businessAssemblyPath); } catch (Exception x) { this.PublishErrorMessage( "Cannot load Assemblies Dependencies -> {0}", x.GetFullMessage(withExceptionType: true)); break; } #endregion #region [ Loading Business Context ] if (this.CancelToken.IsCancellationRequested) { break; } this.PublishProcessMessage("Loading Business Context..."); IList <string> errors; this.BusinessContext = new BusinessContext(businessAssembly); try { this.BusinessContext.Load(out errors); } catch (Exception x) { this.PublishErrorMessage("Cannot load the Business Context -> {0}", x.Message); break; } if (errors.Count != 0) { foreach (string error in errors) { this.PublishErrorMessage(error); } break; } #endregion #region [ Creating TextTemplating TextTemplatingEngine ] if (this.CancelToken.IsCancellationRequested) { break; } this.PublishProcessMessage("Creating TextTemplating Engine..."); this.TextTemplatingEngine = new TextTemplatingEngine( this.Context.SolutionDirectory, this.Context.TemplateDirectory); this.TextTemplatingEngine.OnGeneratedFile += OnFileGenerated; #endregion #region [ Executing... ] behavior.Execute(this, parameters); #endregion }while (false); #region [ End ] _stopwatch.Stop(); int nbFiles = this.TextTemplatingEngine != null?this.TextTemplatingEngine.GeneratedFiles.Count() : 0; string summary = string.Format("Process Duration -> {0}secs ({1} files)", (int)_stopwatch.Elapsed.TotalSeconds, nbFiles); if (this.HasErrors) { this.PublishErrorMessage("Undo code modifications"); this.PublishErrorMessage(summary); } else { if (this.CancelToken.IsCancellationRequested) // the process has been stopped -> do not commit (-> do not call LinkGeneratedFiles()) { this.PublishErrorMessage("Undo code modifications"); // cancel user action } else { this.LinkGeneratedFiles(); } this.PublishProcessMessage(summary); } this.Clear(); this.IsRunning = false; #endregion }
/// <summary> /// 单个查询 /// </summary> /// <param name="companyName"></param> public void SingelSearch(string companyName) { var httpClient = new HttpClient(); httpClient.Setting.Timeout = 1000 * 5; httpClient.Create <string>(HttpMethod.Post, firsturl).Send(); while (true) { var targetModel = new CrawlerEntity { 搜索名称 = companyName, 操作人姓名 = TaskEntity.OperatorName, 入爬行库时间 = TaskEntity.CreateTime, TaskGuid = TaskEntity.Unique }; try { //IP处理 var proxyEntity = new ProxyDomain().GetByRandom(); //代理IP if (proxyEntity == null) { Console.WriteLine("在线代理临时获取策略启动。"); proxyEntity = Proxy.Proxy.GetInstance().GetHttProxyEntity(); Console.WriteLine("线上获取到了代理:{0}:{1}", proxyEntity.IpAddress, proxyEntity.Port); } httpClient.Setting.Proxy = new WebProxy(proxyEntity.IpAddress, proxyEntity.Port); var resultBody = httpClient.Create <string>(HttpMethod.Post, targetUrl, data: new { queryStr = targetModel.搜索名称, module = "", idFlag = "qyxy" }).Send(); if (!resultBody.IsValid()) { RemoveOldIp(proxyEntity); continue; } if (ValidText(resultBody.Result)) { RemoveOldIp(proxyEntity); continue; } //提取二级连接 var parser = new JumonyParser(); var urls = parser.Parse(resultBody.Result).Find("li a").ToList(); var nextUrl = ""; if (urls.Count < 1) { AddNull(targetModel); break; } foreach (var htmlElement in urls) { targetModel.称 = htmlElement.InnerText(); nextUrl = url + htmlElement.Attribute("href").AttributeValue; } //提取目标正文 var resultsecondBody = httpClient.Create <string>(HttpMethod.Get, zhuUrl + new Uri(firsturl + nextUrl).Query).Send(); var nameValueCollection = new NameValueCollection(URL.GetQueryString(new Uri(firsturl + nextUrl).Query)); if (!resultsecondBody.IsValid()) { RemoveOldIp(proxyEntity); continue; } if (ValidText(resultsecondBody.Result)) { RemoveOldIp(proxyEntity); continue; } //正文处理 var sorceIhtml = new JumonyParser().Parse(resultsecondBody.Result.Replace("<th", "<td")); var tableLists = sorceIhtml.Find("table[class='f-lbiao']").ToList(); var listall = new List <string>(); foreach (var tableList in tableLists) { tableList.Find("tr td") .ForEach(t => listall.Add(t.InnerText().TrimEnd(':').TrimEnd(':').Trim())); } var fillModel = FillModel(listall); fillModel.全局唯一编号 = nameValueCollection["reg_bus_ent_id"].ToUpper(); new CrawlerDomain().Add(StrategyNo1(fillModel, targetModel)); //后续其他处理 包括了IP使用状态,以查询列表状态 proxyEntity.Usage = proxyEntity.Usage + 1; new ProxyDomain().Update(proxyEntity); Console.WriteLine("{0} 抓取到:{1}", Task.CurrentId, targetModel.搜索名称); } catch (Exception e) { new LogDomain().Add(new LogEntity { LogType = "error", TaskName = TaskEntity.TaskName, ErrorDetails = Task.CurrentId + "线程: " + e.Message, Details = e.ToString(), TriggerTime = DateTime.Now }); continue; } break; } }
public ASCommandResponse GetResponse() { string StatusCode = string.Empty; string Meaning = string.Empty; string Cause = string.Empty; string Resolution = string.Empty; EASTester.EasHelp oHelp = new EASTester.EasHelp(); GenerateXMLPayload(); //if (ProtocolVersion == null) // throw new InvalidDataException("ASCommandRequest not initialized - Protocol version not specified."); //if (ProtocolVersion == null) // throw new InvalidDataException("ASCommandRequest not initialized - EAS Protocol version must be set"); //if (WbxmlBytes == null) // throw new InvalidDataException("ASCommandRequest not initialized - Request is empty."); //if (Server == null) // throw new InvalidDataException("ASCommandRequest not initialized - Server must be specified."); //if (Credentials == null && useCertificateAuthentication == false) // throw new InvalidDataException("ASCommandRequest not initialized for authentication."); //if (useCertificateAuthentication == true && certificateFile.Length == 0) // throw new InvalidDataException("ASCommandRequest not initialized - Certificate file must be specified."); string uriString = string.Format("{0}//{1}/Microsoft-Server-ActiveSync?{2}", useSSL ? "https:" : "http:", server, RequestLine); Uri serverUri = new Uri(uriString); HttpWebRequest httpReq = (HttpWebRequest)WebRequest.Create(uriString); //httpReq.ClientCertificates. httpReq.Method = "POST"; httpReq.ContentType = "application/vnd.ms-sync.wbxml"; // Handle any certificate errors on the certificate from the server. //ServicePointManager.CertificatePolicy = new CertPolicy(); //bool bSettingCredsWasOK = false; if (useCertificateAuthentication == true) { // https://support.microsoft.com/en-us/kb/895971 try { httpReq.UseDefaultCredentials = false; X509Certificate oX509Certificate = null; //oX509Certificate = new X509Certificate.CreateFromCertFile(certificateFile); oX509Certificate = new X509Certificate(certificateFile, certificatePassword); httpReq.ClientCertificates.Add(oX509Certificate); } catch (Exception ex) { MessageBox.Show("Exception: \r\n" + ex.ToString(), "Error setting certificate authentication."); return(null); } } else { try { CredentialCache creds = new CredentialCache(); creds.Add(serverUri, "Basic", credential); // Using Basic authentication httpReq.Credentials = creds; } catch (Exception ex) { MessageBox.Show("Exception: \r\n" + ex.ToString(), "Error setting specified credentials."); return(null); } } if (SpecifyProxySettings == true) { WebProxy oWebProxy = null; oWebProxy = new WebProxy(ProxyServer, ProxyPort); //oWebProxy.BypassProxyOnLocal = BypassProxyForLocalAddress; if (OverrideProxyCredntials == true) { if (ProxyUser.Trim().Length == 0) { oWebProxy.UseDefaultCredentials = true; } else { if (ProxyDomain.Trim().Length == 0) { oWebProxy.Credentials = new NetworkCredential(ProxyUser, ProxyPassword); } else { oWebProxy.Credentials = new NetworkCredential(ProxyUser, ProxyPassword, ProxyDomain); } } } else { oWebProxy.UseDefaultCredentials = true; } httpReq.Proxy = oWebProxy; } if (UserAgent.Trim().Length != 0) { httpReq.UserAgent = UserAgent; } if (!UseEncodedRequestLine) { httpReq.Headers.Add("MS-ASProtocolVersion", ProtocolVersion); httpReq.Headers.Add("X-MS-PolicyKey", PolicyKey.ToString()); } try { Stream requestStream = httpReq.GetRequestStream(); requestStream.Write(WbxmlBytes, 0, WbxmlBytes.Length); requestStream.Close(); HttpWebResponse httpResp = (HttpWebResponse)httpReq.GetResponse(); //float iisStatusCode = (float)httpResp.StatusCode; ASCommandResponse response = WrapHttpResponse(httpResp); httpResp.Close(); //StatusCode = iisStatusCode.ToString(); //Meaning = string.Empty; //Cause = string.Empty; //Resolution = string.Empty; //oHelp.GetHttpStatusInfo(StatusCode, ref Meaning, ref Cause, ref Resolution); //MessageBox.Show("IIS Resposne Code: " + StatusCode + "\r\nDescription: " + Meaning); return(response); } catch (WebException wex) { MessageBox.Show("Exception: \r\n" + wex.ToString(), "Error"); return(null); } catch (Exception ex) { MessageBox.Show("Exception: \r\n" + ex.ToString(), "Error"); return(null); } }
/** * Replace DatafeedResult with keyword. * @params: keyword: Search Keyword, replaceText: Text for Replace * @return: Replace keyword count * */ public int Replace(string keyword, string replaceText) { int replaceCount = 0; if (DatafeedID.Contains(keyword) && CheckStatus.Check_DatafeedID) { DatafeedID = DatafeedID.Replace(keyword, replaceText); replaceCount += 1; } if (Guid.Contains(keyword) && CheckStatus.Check_Guid) { Guid = Guid.Replace(keyword, replaceText); replaceCount += 1; } if (DatafeedName.Contains(keyword) && CheckStatus.Check_DatafeedName) { DatafeedName = DatafeedName.Replace(keyword, replaceText); replaceCount += 1; } if (SecurityUsername.Contains(keyword) && CheckStatus.Check_SecurityUsername) { SecurityUsername = SecurityUsername.Replace(keyword, replaceText); replaceCount += 1; } if (SecurityPassword.Contains(keyword) && CheckStatus.Check_SecurityPassword) { SecurityPassword = SecurityPassword.Replace(keyword, replaceText); replaceCount += 1; } if (TransportUsername.Contains(keyword) && CheckStatus.Check_TransportUsername) { TransportUsername = TransportUsername.Replace(keyword, replaceText); replaceCount += 1; } if (TransportPassword.Contains(keyword) && CheckStatus.Check_TransportPassword) { TransportPassword = TransportPassword.Replace(keyword, replaceText); replaceCount += 1; } if (TransportURL.Contains(keyword) && CheckStatus.Check_TransportURL) { TransportURL = TransportURL.Replace(keyword, replaceText); replaceCount += 1; } if (TransportInstance.Contains(keyword) && CheckStatus.Check_TransportInstance) { TransportInstance = TransportInstance.Replace(keyword, replaceText); replaceCount += 1; } if (SecurityDomain.Contains(keyword) && CheckStatus.Check_SecurityDomain) { SecurityDomain = SecurityDomain.Replace(keyword, replaceText); replaceCount += 1; } if (TransportDomain.Contains(keyword) && CheckStatus.Check_TransportDomain) { TransportDomain = TransportDomain.Replace(keyword, replaceText); replaceCount += 1; } if (ProxyOption.Contains(keyword) && CheckStatus.Check_ProxyOption) { ProxyOption = ProxyOption.Replace(keyword, replaceText); replaceCount += 1; } if (ProxyName.Contains(keyword) && CheckStatus.Check_ProxyName) { ProxyName = ProxyName.Replace(keyword, replaceText); replaceCount += 1; } if (ProxyPort.Contains(keyword) && CheckStatus.Check_ProxyPort) { ProxyPort = ProxyPort.Replace(keyword, replaceText); replaceCount += 1; } if (ProxyDomain.Contains(keyword) && CheckStatus.Check_ProxyDomain) { ProxyDomain = ProxyDomain.Replace(keyword, replaceText); replaceCount += 1; } if (ProxyUserName.Contains(keyword) && CheckStatus.Check_ProxyUserName) { ProxyUserName = ProxyUserName.Replace(keyword, replaceText); replaceCount += 1; } if (ProxyPassword.Contains(keyword) && CheckStatus.Check_ProxyPassword) { ProxyPassword = ProxyPassword.Replace(keyword, replaceText); replaceCount += 1; } if (TransportPath.Contains(keyword) && CheckStatus.Check_TransportPath) { TransportPath = TransportPath.Replace(keyword, replaceText); replaceCount += 1; } if (ConnectionString.Contains(keyword) && CheckStatus.Check_ConnectionString) { ConnectionString = ConnectionString.Replace(keyword, replaceText); replaceCount += 1; } if (SQLQueryUsername.Contains(keyword) && CheckStatus.Check_SQLQueryUsername) { SQLQueryUsername = SQLQueryUsername.Replace(keyword, replaceText); replaceCount += 1; } if (SQLQueryPassword.Contains(keyword) && CheckStatus.Check_SQLQueryPassword) { SQLQueryPassword = SQLQueryPassword.Replace(keyword, replaceText); replaceCount += 1; } return(replaceCount); }