Ejemplo n.º 1
0
        public FredhopperProductCatalog(XElement configuration)
        {
            var binding = new BasicHttpBinding();

            binding.MaxReceivedMessageSize = 1000000; // Needs be configurable?
            this.maxItems         = Int32.Parse(configuration.Element(EclProvider.EcommerceEclNs + "MaxItems").Value);
            this.categoryMaxDepth = Int32.Parse(configuration.Element(EclProvider.EcommerceEclNs + "CategoryMaxDepth").Value);
            var usernameElement = configuration.Element(EclProvider.EcommerceEclNs + "UserName");
            var passwordElement = configuration.Element(EclProvider.EcommerceEclNs + "Password");

            if (usernameElement != null)
            {
                binding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
                binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
            }
            var endpointAddress = new EndpointAddress(configuration.Element(EclProvider.EcommerceEclNs + "EndpointAddress").Value);

            this.fhClient = new FASWebServiceClient(binding, endpointAddress);
            if (usernameElement != null)
            {
                this.fhClient.ClientCredentials.UserName.UserName = usernameElement.Value;
                this.fhClient.ClientCredentials.UserName.Password = passwordElement.Value;
            }

            // TODO: How to handle creation of new publications through SiteWizard? This will require some reconfig for each publication...
            // Use a fallback for those cases or???

            XElement publicationConfigurations = configuration.Element(EclProvider.EcommerceEclNs + "PublicationConfigurations");

            foreach (var config in publicationConfigurations.Elements(EclProvider.EcommerceEclNs + "PublicationConfiguration"))
            {
                var publicationIds    = config.Attribute("publicationIds").Value; // Format: 12,34,45,55
                var publicationConfig = new PublicationConfiguration();
                publicationConfig.Locale   = config.Element(EclProvider.EcommerceEclNs + "Locale").Value;
                publicationConfig.Universe = config.Element(EclProvider.EcommerceEclNs + "Universe").Value;
                var fallback = config.Attribute("fallback");
                if (fallback != null && fallback.Value.Equals("true"))
                {
                    publicationConfig.Fallback = true;
                }
                var modelMappings    = config.Element(EclProvider.EcommerceEclNs + "ModelMappings").Value;
                var modelMappingsMap = new Dictionary <string, string>();
                var tokens           = modelMappings.Split(new char[] { ' ', ';', '=' }, StringSplitOptions.RemoveEmptyEntries);
                int i = 0;
                while (i < tokens.Length)
                {
                    var name  = tokens[i];
                    var value = tokens[i + 1];
                    modelMappingsMap.Add(name, value);
                    i = i + 2;
                }
                publicationConfig.ModelMappings = modelMappingsMap;
                var ids = publicationIds.Split(new char[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries);
                foreach (var id in ids)
                {
                    this.publicationConfigurations.Add(Int32.Parse(id), publicationConfig);
                }
            }
        }
Ejemplo n.º 2
0
 public universe CallFredHopper(string fh_params)
 {
     page page = null;
     universe universe = null;
     FASWebServiceClient client = new FASWebServiceClient();
     if (client.State == CommunicationState.Faulted)
     {
         client.Abort();
     }
     try
     {
         if (client.Endpoint.Address != null)
         {
             page = client.getAll(fh_params);
             client.Close();
         }
         else
         {
             page = new page();
         }
         try
         {
             universe = page.universes.SingleOrDefault<universe>(u => u.type == universeType.selected);
         }
         catch (Exception)
         {
             universe = new universe();
         }
     }
     catch (Exception)
     {
         page = new page();
         client.Abort();
     }
     return universe;
 }