public void GivenThatSectionRelatesToASpecificTransformation() { var connectionSectionData = ConnectionSection.GetConnectionSection_NameAndType(_currentSectionName, (int)_currentExtractType); if (connectionSectionData == null) { throw new InvalidDataException(String.Format("Connection Section Data doesn't have any entry for Name='{0}' and Type='{1}'", _currentSectionName, _currentExtractType)); } var sectionData = connectionSectionData.FirstOrDefault(); if (sectionData == null) { throw new InvalidDataException(String.Format("Section Data doesn't have any entry for Name='{0}' and Type='{1}'", _currentSectionName, _currentExtractType)); } var patternData = ConnectionPattern.GetConnectionPattern_Section(sectionData.ConnectionSectionId).FirstOrDefault(); if (patternData == null) { throw new InvalidDataException(String.Format("Pattern Data doesn't have any entry for SectionId='{2}'. Name='{0}'. Type='{1}'", _currentSectionName, _currentExtractType, sectionData.ConnectionSectionId)); } if (!patternData.TransformId.HasValue) { throw new InvalidDataException(String.Format("Pattern Data doens't have a TransformId for PatternId='{3}'. SectionId='{2}'. Name='{0}'. Type='{1}'", _currentSectionName, _currentExtractType, sectionData.ConnectionSectionId, patternData.ConnectionPatternId)); } _currentCommunicationType = Type.GetType(sectionData.CommunicationType); _currentTransformId = patternData.TransformId.Value; }
/// <summary> /// 获取数据库连接 /// </summary> /// <param name="connName">连接串名称</param> /// <returns></returns> public IDbConnection CreateConnection(String connName) { if (String.IsNullOrEmpty(connName)) { throw new Exception("数据库连接串名称不能为空."); } ConcurrentDictionary <String, ConnectionSection> DicConnectionSection = QueryConnectionSection(); if (DicConnectionSection == null || DicConnectionSection.Count == 0) { throw new Exception("数据库连接串配置不能为空."); } ConnectionSection connectionSection = null; DicConnectionSection.TryGetValue(connName, out connectionSection); if (connectionSection == null) { throw new Exception(String.Format("未能找到{0}数据库连接串.", connName)); } var connection = ConnectionFactory.CreateConnection(connectionSection); connection.Open(); return(connection); }
public void TestAdvancedAuthenticationUrl() { var config = ConnectionSection.GetSection(); Clock.StubValue = 1370000000000; var parameters = new NameValueCollection() { {"format", "json"} }; string passwordParameter = ( config.Authentication.Prefix + Clock.StubValue + config.Authentication.Password.ToMD5() + config.Authentication.Postfix ).ToMD5(); var expectedUri = new Uri( @"http://demoshop.fact-finder.de:80/FACT-Finder/Search.ff?" + @"channel=de&format=json×tamp=" + Clock.StubValue + @"&username="******"&password=" + passwordParameter ); Uri actualUri = UrlBuilder.GetUrlWithAdvancedAuthentication(RequestType.Search, parameters); Assert.IsTrue(expectedUri.EqualsWithQueryString(actualUri)); }
/// <summary> /// Creates a copy of this object. /// </summary> /// <returns></returns> public ConnectionSection Clone() { ConnectionSection cs = this.MemberwiseClone() as ConnectionSection; cs.Password = this.Password.Clone(); return(cs); }
private void EnsureChannelParameter(NameValueCollection result) { if (string.IsNullOrEmpty(result["channel"])) { result["channel"] = ConnectionSection.GetSection().Channel; } }
public SearchParameters(NameValueCollection parameters) { Query = parameters["query"] ?? ""; SeoPath = parameters["seoPath"] ?? ""; ProductsPerPage = Int32.Parse(parameters["productsPerPage"] ?? "-1"); CurrentPage = Int32.Parse(parameters["page"] ?? "1"); FollowSearch = Int32.Parse(parameters["followSearch"] ?? "0"); IsNavigation = parameters["catalog"] == "true"; Filters = new Dictionary <string, string>(); Sortings = new Dictionary <string, string>(); foreach (string key in parameters) { string value = parameters[key]; if (key.StartsWith("filter")) { Filters[key.Substring("filter".Length)] = value; } else if (key.StartsWith("sort") && (value == "asc" || value == "desc")) { Sortings[key.Substring("sort".Length)] = value; } } var config = ConnectionSection.GetSection(); Channel = config.Channel; }
/// <summary> /// 创建一个打开的数据库连接 /// </summary> /// <param name="connectionSection"></param> /// <returns></returns> public static IDbConnection CreateOpenConnection(ConnectionSection connectionSection) { var dbConnection = CreateConnection(connectionSection); dbConnection.Open(); return(dbConnection); }
public Uri GetUrlWithAdvancedAuthentication(RequestType action, NameValueCollection parameters) { EnsureChannelParameter(parameters); var config = ConnectionSection.GetSection(); string timestamp = Clock.Now().ToString(); parameters["timestamp"] = timestamp; parameters["username"] = config.Authentication.UserName; parameters["password"] = ( config.Authentication.Prefix + timestamp + config.Authentication.Password.ToMD5() + config.Authentication.Postfix ).ToMD5(); return(new Uri(String.Format( "{0}://{1}:{2}/{3}/{4}?{5}", config.Protocol, config.ServerAddress, config.Port, config.Context, action, parameters.ToUriQueryString() ))); }
private Response RetrieveResponse(ConnectionData connectionData, Uri url) { HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url); webRequest.KeepAlive = false; webRequest.Method = "GET"; webRequest.AutomaticDecompression = DecompressionMethods.GZip; webRequest.Headers.Add(connectionData.HttpHeaderFields); var config = ConnectionSection.GetSection(); if (config.Language != "") { webRequest.Headers.Add(HttpRequestHeader.AcceptLanguage, config.Language); } log.InfoFormat("Sending request to URL: {0}", url); HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse(); var statusCode = webResponse.StatusCode; StreamReader responseStream = new StreamReader(webResponse.GetResponseStream(), true); string responseText = responseStream.ReadToEnd(); responseStream.Close(); webResponse.Close(); return(new Response( responseText, statusCode )); }
public void EnsureChannelParameter(NameValueCollection parameters) { var config = ConnectionSection.GetSection(); if (String.IsNullOrEmpty(parameters["channel"]) && config.Channel != "") { parameters["channel"] = config.Channel; } }
private static List <Element> GetSection() { List <Element> list = new List <Element>(); var section = ConnectionSection.GetSection(); for (int i = 0; i < section.MasterServices.Count; i++) { list.Add(section.MasterServices[i]); } return(list); }
/// <summary> /// 获取数据库连接 /// </summary> /// <returns></returns> public static IDbConnection CreateConnection(ConnectionSection connectionSection) { var factory = DbProviderFactories.GetFactory(connectionSection.ProviderName); if (factory == null) { throw new InvalidOperationException(String.Format("Can't find provider={0}.", connectionSection.ProviderName)); } else { var dbConnection = factory.CreateConnection(); dbConnection.ConnectionString = connectionSection.ConnectionString; return(dbConnection); } }
public Uri GetUrlWithoutAuthentication(RequestType action, NameValueCollection parameters) { EnsureChannelParameter(parameters); var config = ConnectionSection.GetSection(); return(new Uri(String.Format( "{0}://{1}:{2}/{3}/{4}?{5}", config.Protocol, config.ServerAddress, config.Port, config.Context, action, parameters.ToUriQueryString() ))); }
public void TestConnectionSection() { var section = ConnectionSection.GetSection(); Assert.IsNotNull(section); Assert.AreEqual(ConnectionProtocol.Http, section.Protocol); Assert.AreEqual(@"demoshop.fact-finder.de", section.ServerAddress); Assert.AreEqual(80, section.Port); Assert.AreEqual(@"FACT-Finder", section.Context); Assert.AreEqual(@"de", section.Channel); Assert.AreEqual(@"de", section.Language); Assert.AreEqual(@"user", section.Authentication.UserName); Assert.AreEqual(@"userpw", section.Authentication.Password); Assert.AreEqual(AuthenticationType.Advanced, section.Authentication.Type); Assert.AreEqual(@"FACT-FINDER", section.Authentication.Prefix); Assert.AreEqual(@"FACT-FINDER", section.Authentication.Postfix); }
public Uri GetUrlWithAuthentication(RequestType action, NameValueCollection parameters) { var config = ConnectionSection.GetSection(); switch (config.Authentication.Type) { case AuthenticationType.Http: return(GetUrlWithHttpAuthentication(action, parameters)); case AuthenticationType.Basic: return(GetUrlWithSimpleAuthentication(action, parameters)); case AuthenticationType.Advanced: return(GetUrlWithAdvancedAuthentication(action, parameters)); default: throw new Exception("Invalid authentication type configured."); } }
public static void Load() { Slaves = Slaves ?? new List <ISlave>(); var section = ConnectionSection.GetSection(); var servers = GetSection(); if (ReferenceEquals(servers, null)) { throw new ArgumentNullException(); } Slaves = new List <ISlave>(); for (int i = 0; i < servers.Count; i++) { AppDomain domain = AppDomain.CreateDomain(servers[i].ServiceType + i); var type = typeof(DomainLoader); var loader = (DomainLoader)domain.CreateInstanceAndUnwrap(Assembly.GetAssembly(type).FullName, type.FullName); var element = new ElementHelper { IpEndPoint = new IPEndPoint(IPAddress.Parse(servers[i].IpAddress), servers[i].Port), ServerType = servers[i].ServiceType }; var service = loader.LoadService(element); if (servers[i].ServiceType == "slave") { Slaves.Add(service as ISlave); } else if (servers[i].ServiceType == "master") { Master = service as MasterUserService; } else { throw new ArgumentException("Incorrect server type"); } } InitializeServices(); }