/// <summary> /// Compares the current context to the passed parameters to see if the security requirements are met /// </summary> /// <param name="credentials"></param> /// <param name="approvedIps"></param> public bool VerifyCredentials(AuthCredentials credentials, List<string> approvedIps = null) { //get the current request object var context = OperationContext.Current; if (context == null) return false; var messageProperties = context.IncomingMessageProperties; if (messageProperties == null) return false; if (credentials.RequireSsl) if (!messageProperties.Via.OriginalString.StartsWith("https")) return false; var request = messageProperties["httpRequest"] as HttpRequestMessageProperty; if (request == null) return false; //Check for IP restrictions if (approvedIps != null && approvedIps.Count > 0) { string ip = null; #if GOGRID ip = request.Headers["X-Forwarded-For"]; #else var endpointProperty = messageProperties[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty; if (endpointProperty != null) ip = endpointProperty.Address; #endif if (!string.IsNullOrEmpty(ip)) if (approvedIps.FindIndex(x => x.Equals(ip)) < 0) return false; } //Confirm Credentials switch (credentials.Type) { case AuthCredentials.AuthType.BasicAuth: var authHeader = request.Headers["Authorization"]; if (string.IsNullOrEmpty(authHeader)) { authHeader = request.Headers["Authentication"]; if (string.IsNullOrEmpty(authHeader)) break; } if (!authHeader.StartsWith("Basic ")) break; //var encodedAsBytes = Convert.FromBase64String(authHeader.Substring(6)); //var unencoded = System.Text.Encoding.ASCII.GetString(encodedAsBytes); var unencoded = Input.Base64Decode(authHeader.Substring(6)); var index = unencoded.IndexOf(":", StringComparison.Ordinal); if (index < 1) break; var usr = unencoded.Substring(0, index); if (!usr.Equals(credentials.UserName)) break; var pwd = unencoded.Substring(index + 1); if (!pwd.Equals(credentials.Password)) break; return true; case AuthCredentials.AuthType.None: return true; default: if (BoostLog.Instance != null) BoostLog.Instance.WriteEntry(EventLogEntryType.Error, "Unknown AuthType requested: " + credentials.Type.ToString()); return false; } return false; }
public AuthCredentials(AuthCredentials source) { Type = source.Type; UserName = source.UserName; Password = source.Password; UserNameParam = source.UserNameParam; PasswordParam = source.PasswordParam; RequireSsl = source.RequireSsl; }
public static string CreateAuthHeader(AuthCredentials credentials) { switch (credentials.Type) { case AuthCredentials.AuthType.BasicAuth: var toEncode = string.Format("{0}:{1}", credentials.UserName, credentials.Password); //var toEncodeAsBytes = System.Text.Encoding.ASCII.GetBytes(toEncode); //var encoded = System.Convert.ToBase64String(toEncodeAsBytes); var encoded = Input.Base64Encode(toEncode); return "Basic " + encoded; case AuthCredentials.AuthType.None: return ""; default: throw new ArgumentOutOfRangeException("Unknown AuthType: " + credentials.Type.ToString()); } }
/// <summary> /// initialize the fieldNames array /// needed as a separate call so that it can be updated after the defaults are set /// names should be accessed as FieldNames[(int)SiteRules.FieldName] /// </summary> //public void InitFieldNames() //{ // for (var i = 0; i < NumFieldNames; i++) // FieldNames[i] = GetFieldName((FieldName) i); //} //public void SetFieldHeaderIndices(DataGroup group, List<string> header) //{ // foreach (var field in _fieldNames.Where(x => x.Value.Group.Equals(group))) // { // field.Value.SetIndex(header); // } //} /// <summary> /// Set default values that are cart specific /// If init flag is true then some extra defaults will also be set /// such as ApiUrl and Exclusions /// </summary> /// <param name="init"></param> /// <param name="level"></param> protected void SetCartDefaults(bool init = true, string level = "") { //our preferred method is to gather sales realtime //this can be overriden by the platform-specific CartExtractor ExtractSalesUpdate = false; ExtractSalesFull = true; ExtractSalesFromXmlFile = false; ExtractCatalogFromXmlFile = false; InvalidatePricesOnExtract = false; InvalidatePricesOnExtractComplete = false; ExtractAtt2Names = false; ExtractCustomerData = false; RequireEmailOptIn = false; TrackShopperActivity = false; AllowLowerCatalogCount = false; AllowLowerSalesCount = false; AllowLowerCustomerCount = false; AllowManualUpload = true; AllowUserExtraction = true; ApiCountEnabled = true; ApiCustomerDateRangeEnabled = true; ApiSalesDateRangeEnabled = true; //ApiResponseTimeout = DefaultApiResponseTimeout; //ApiSessionTimeout = DefaultApiSessionTimeout; //ApiMaxTries = DefaultApiMaxTries; EnableServiceCallDetailLog = false; ExportDepartmentNames = false; //Att1Enabled = true; //Att2Enabled = true; CartName = CartType.ToString(); switch (CartType) { //platform specific feed types case CartType.AspDotNetStorefront: if (init) { ApiUrl = "https://" + StoreShortUrl + "/skins/4Tell/FourTellVortxExport.aspx"; ExtractCustomerData = true; ExtractorCredentials = new AuthCredentials { Type = AuthCredentials.AuthType.AuthParams, RequireSsl = true, UserName = Alias, UserNameParam = "ClientAlias", Password = ClientData.Instance.GetServiceKey(Alias), PasswordParam = "ServiceKey" }; } ExportDepartmentNames = true; goto case CartType.JsonFeed; case CartType.BigCommerce: if (init) { ApiKey = ""; //clear auto-calculated key --must get it from the cart ScrapeCategoryThumbnails = true; ExclusionsOn = true; ExclusionRules = new List<Condition>(); ExclusionRules.Add(new Condition("Out Of Stock", "lt", "1", "inventory_level")); ExclusionRules.Add(new Condition("Free", "lt", ".01", "price")); ImageLinkBaseUrl = "/product_images/"; OrderDateReversed = true; //default to day/month/year instead of month/day/year --this is not always true } CartExtractorExists = true; PluginHandlesExclusions = false; PluginHandlesFilters = false; PluginHandlesCategoryOptimization = false; PluginHandlesReplacements = false; ScrapeCategoryThumbnails = false; break; case CartType.CommerceV3: goto case CartType.JsonFeed; case CartType.Magento: if (init) { ApiUrl = "https://" + StoreShortUrl + "/index.php/recommend/api"; ApiVersion = 3.5F; PluginVersion = 3.5F; ExtractCustomerData = true; ExtractAtt2Names = true; ExtractorCredentials = new AuthCredentials { Type = AuthCredentials.AuthType.AuthParams, RequireSsl = true, UserName = Alias, UserNameParam = "ClientAlias", Password = ClientData.Instance.GetServiceKey(Alias), PasswordParam = "ServiceKey" }; ApiForceAllRowRanges = 1000; ExclusionRules = new List<Condition>(); ExclusionRules.Add(new Condition("Out Of Stock", "Eq", "Out of Stock", "StockAvailability")); ExclusionRules.Add(new Condition("Free", "lt", ".01", "Price")); } if (PluginVersion > 3) goto case CartType.JsonFeed; goto case CartType.Other; case CartType.MivaMerchant: if (init) { ApiUrl = "https://" + StoreShortUrl + "/mm5/"; ExtractorCredentials = new AuthCredentials { Type = AuthCredentials.AuthType.AuthParams, RequireSsl = true, UserName = Alias, UserNameParam = "ClientAlias", Password = ClientData.Instance.GetServiceKey(Alias), PasswordParam = "ServiceKey" }; ApiVersion = 3.5F; ExtractCustomerData = false; ExtractSalesUpdate = true; ExclusionsOn = true; ExclusionRules = new List<Condition>(); ExclusionRules.Add(new Condition("Out Of Stock", "lt", "1", "StockLevel")); ExclusionRules.Add(new Condition("Free", "lt", ".01", "Price")); init = false; } goto case CartType.JsonFeed; case CartType.NetSuite: if (init) { ApiKey = ""; //clear auto-calculated key --must get it from the cart ScrapeCategoryThumbnails = true; ExclusionsOn = true; ExclusionRules = new List<Condition>(); ExclusionRules.Add(new Condition("Out Of Stock", "lt", "1", "inventory_level")); ExclusionRules.Add(new Condition("Free", "lt", ".01", "price")); } CartExtractorExists = true; PluginHandlesExclusions = false; PluginHandlesFilters = false; PluginHandlesCategoryOptimization = false; PluginHandlesReplacements = false; ScrapeCategoryThumbnails = false; ExtractCustomerData = true; break; case CartType.Shopify: if (init) { ApiKey = ""; //clear auto-calculated key --must get it from the cart ScrapeCategoryThumbnails = true; ExclusionsOn = true; ExclusionRules = new List<Condition>(); ExclusionRules.Add(new Condition("Out Of Stock", "lt", "1", "inventory_level")); ExclusionRules.Add(new Condition("Free", "lt", ".01", "price")); } CartExtractorExists = true; PluginHandlesExclusions = false; PluginHandlesFilters = false; PluginHandlesCategoryOptimization = false; PluginHandlesReplacements = false; ScrapeCategoryThumbnails = false; ExtractCustomerData = true; break; case CartType.ThreeDCart: if (init) { ApiKey = ""; //clear auto-calculated key --must get it from the cart ApiUrl = StoreShortUrl; ExclusionsOn = true; ExtractCustomerData = true; ExtractSalesUpdate = true; ExclusionsOn = true; ExclusionRules = new List<Condition>(); ExclusionRules.Add(new Condition("Not For Sale", "eq", "1", "notforsale")); ExclusionRules.Add(new Condition("Non-Searchable", "eq", "1", "nonsearchable"));// ExclusionRules.Add(new Condition("Hidden", "eq", "1", "hide")); ExclusionRules.Add(new Condition("Out Of Stock", "lt", "1", "stock")); ExclusionRules.Add(new Condition("Free", "lt", ".01", "price")); } CartExtractorExists = true; PluginHandlesExclusions = false; PluginHandlesFilters = false; PluginHandlesCategoryOptimization = false; PluginHandlesReplacements = false; ThreeDCartLevel tLevel; CartLevel = Enum.TryParse(level, true, out tLevel) ? (int) tLevel : (int) ThreeDCartLevel.Standard; break; case CartType.Volusion: if (init) { ApiKey = ""; //clear auto-calculated key --must get it from the cart ExclusionsOn = true; ExtractCustomerData = true; ExtractSalesUpdate = false; ExtractSalesFromXmlFile = false; ExtractCatalogFromXmlFile = false; //TODO: set (detect?) Volusion CartLevel and use to set XmlFile's true if < gold ExclusionRules = new List<Condition>(); ExclusionRules.Add(new Condition("Free", "lt", ".01", "pe.ProductPrice")); ExclusionRules.Add(new Condition("No Price", "eq", "null", "pe.ProductPrice")); } CartExtractorExists = true; PluginHandlesExclusions = false; PluginHandlesFilters = false; PluginHandlesCategoryOptimization = false; PluginHandlesReplacements = false; ExtrapolateThumbnailPath = true; break; case CartType.WebsitePipeline: //generic feed types case CartType.JsonFeed: CartExtractorExists = true; PluginHandlesExclusions = false; PluginHandlesFilters = false; PluginHandlesCategoryOptimization = false; PluginHandlesReplacements = false; if (DataFormatRowEnds == null || !DataFormatRowEnds.Any()) DataFormatRowEnds = new[] {"],[", "], [", "],\n[","],\r\n["}; //default to Json row endings if (DataFormatRowTrims == null || DataFormatRowTrims.Count() < 1) DataFormatRowTrims = new[] {' ', '[', ']', ','}; //quotes must be left for the SplitRow logic if (init) { ApiVersion = 3.5F; ExtractCustomerData = true; ExtractSalesUpdate = false; ExclusionsOn = true; if (ExclusionRules == null) { ExclusionRules = new List<Condition>(); ExclusionRules.Add(new Condition("Out Of Stock", "lt", "1", "Inventory")); ExclusionRules.Add(new Condition("Free", "lt", ".01", "Price")); } } break; case CartType.TabbedFeed: //TabbedFeedRules.xml maps tabbed feed to json format //just need to remove the header row if (init) { ApiExtraHeaders = 1; } goto case CartType.JsonFeed; case CartType.XmlFeed: CartExtractorExists = true; PluginHandlesExclusions = false; PluginHandlesFilters = false; PluginHandlesCategoryOptimization = false; PluginHandlesReplacements = false; break; default: case CartType.osCommerce: case CartType.PrestaShop: case CartType.Other: CartExtractorExists = false; PluginHandlesExclusions = true; PluginHandlesFilters = true; PluginHandlesCategoryOptimization = true; PluginHandlesReplacements = true; AllowUserExtraction = false; ApiCountEnabled = false; ApiCustomerDateRangeEnabled = false; ApiSalesDateRangeEnabled = false; break; case CartType.Test: CartExtractorExists = true; PluginHandlesExclusions = false; PluginHandlesFilters = false; PluginHandlesCategoryOptimization = false; PluginHandlesReplacements = false; break; } }
protected void ParseSettings(XElement settings) { //site definition StoreShortUrl = CleanUpUrl(Input.GetValue(settings, "storeUrl")); EnableServiceCallDetailLog = Input.GetValue(settings, "enableServiceCallDetailLog").Equals("true", StringComparison.OrdinalIgnoreCase); var zone = Input.GetValue(settings, "siteTimeZone"); if (!string.IsNullOrEmpty(zone)) { try { SiteTimeZone = TimeZoneInfo.FindSystemTimeZoneById(zone); } catch {} } //Security Rules RequireSecureBoost = Input.GetValue(settings, "requireSecureBoost").Equals("true"); RequireSecureUpload = Input.GetValue(settings, "requireSecureUpload").Equals("true"); UploadAddresses = null; var ipList = settings.Elements("approvedUploadIP"); if (ipList.Any()) UploadAddresses = ipList.Select(ip => ip.Value).ToList(); AllowManualUpload = !Input.GetValue(settings, "allowManualUpload").Equals("false"); //default is true AllowUserExtraction = !Input.GetValue(settings, "allowUserExtraction").Equals("false"); //default is true //track last extraction/generation var extract = Input.GetValue(settings, "lastExtractionType"); CartExtractor.ExtractType lastExtractType; if (Enum.TryParse(extract, true, out lastExtractType)) LastExtractionType = lastExtractType; extract = Input.GetValue(settings, "lastDynamicUpdateType"); if (Enum.TryParse(extract, true, out lastExtractType)) LastDynamicUpdateType = lastExtractType; var lastDate = Input.GetValue(settings, "lastExtractionTime"); LastExtractionTime = Input.SafeDateConvert(lastDate, DateTime.MinValue); lastDate = Input.GetValue(settings, "lastDynamicUpdateTime"); LastDynamicUpdateTime = Input.SafeDateConvert(lastDate, DateTime.MinValue); lastDate = Input.GetValue(settings, "lastGeneratorTime"); LastGeneratorTime = Input.SafeDateConvert(lastDate, DateTime.MinValue); lastDate = Input.GetValue(settings, "lastRuleChange"); LastRuleChangeTime = Input.SafeDateConvert(lastDate, DateTime.MinValue); LastExtractorDuration = Input.SafeIntConvert(Input.GetValue(settings, "lastExtractorDuration")); if (LastExtractorDuration.Equals(0)) LastExtractorDuration = Input.SafeIntConvert(Input.GetValue(settings, "lastExtractionDuration")); //legacy LastGeneratorDuration = Input.SafeIntConvert(Input.GetValue(settings, "lastGeneratorDuration")); var lockout = Input.SafeIntConvert(Input.GetValue(settings, "extractorLockoutMinutes"), -1); ExtractorLockoutMinutes = lockout > -1 ? lockout : DefaultExtractorLockoutMinutes; //contact info UserContact poc = ParseLegacySettings(settings); var userElement = settings.Element("users"); if (userElement != null) { var users = userElement.Descendants("user"); if (users.Any()) { foreach (var u in users) { Users.Add(new User(u)); } if (poc == null) { var pocUser = Users.First(x => x.ContactRole.Equals(UserContactRole.Technical)); if (pocUser != null) poc = new UserContact { Email = pocUser.Email, Name = pocUser.Name }; } //else // DataLogProxy.Instance.AddSite(Alias, poc); //add client to the log } } #region Data Source Rules //Migration rulescatalogMigration var migration = settings.Element("catalogMigration"); if (migration != null) { var startDate = Input.SafeDateConvert(Input.GetAttribute(migration, "startDate"), DateTime.MinValue); var fromField = Input.GetAttribute(migration, "mapFromField"); var toField = Input.GetAttribute(migration, "mapToField"); var enabled = !Input.GetAttribute(migration, "enabled").Equals("false"); var use4TellCatalog = Input.GetAttribute(migration, "use4TellCatalog").Equals("true"); var use4TellSales = Input.GetAttribute(migration, "use4TellSales").Equals("true"); MigrationRules = new CatalogMigration(Alias, (int)Tier, startDate, fromField, toField, enabled, true, SalesMonthsToExport, use4TellCatalog, use4TellSales); } //set cart extraction defaults try { CartName = Input.GetValue(settings, "cartType"); PluginVersion = Input.SafeFloatConvert(Input.GetValue(settings, "pluginVersion")); CartType cartType; CartType = Enum.TryParse(CartName, true, out cartType) ? cartType : CartType.Other; var level = Input.GetValue(settings, "cartLevel"); CartLevel = 0; SetCartDefaults(false, level); } catch (Exception ex) { CartType = CartType.Other; SetCartDefaults(); } //Onboarding Credentials (not used by service but sometimes needed for onboarding) AdminUser = Input.GetValue(settings, "adminUser"); AdminPassword = Input.GetValue(settings, "adminPassword"); FtpType = Input.GetValue(settings, "ftpType"); FtpUrl = Input.GetValue(settings, "ftpUrl"); FtpUser = Input.GetValue(settings, "ftpUser"); FtpPassword = Input.GetValue(settings, "ftpPassword"); //API access ApiUrl = Input.GetValue(settings, "apiUrl"); float apiVersion; ApiVersion = Input.GetValue(out apiVersion, settings, "apiVersion") ? apiVersion : 0F; //default zero means no API ApiCountEnabled = !Input.GetValue(settings, "apiCountEnabled").Equals("false", StringComparison.OrdinalIgnoreCase); //default true ApiCustomerDateRangeEnabled = !Input.GetValue(settings, "apiCustomerDateRangeEnabled").Equals("false", StringComparison.OrdinalIgnoreCase); //default true ApiSalesDateRangeEnabled = !Input.GetValue(settings, "apiSalesDateRangeEnabled").Equals("false", StringComparison.OrdinalIgnoreCase); //default true ApiHeaderIsOnlyOnFirstRow = Input.GetValue(settings, "apiHeaderIsOnlyOnFirstRow").Equals("true", StringComparison.OrdinalIgnoreCase); //default false ApiRowEnd = Input.GetCsvStringList(settings, "apiRowEnd"); ApiTrimChars = Input.GetCsvCharList(settings, "apiTrimChars"); ApiMinimumCatalogSize = Input.SafeIntConvert(Input.GetValue(settings, "apiMinimumCatalogSize"), 0); ApiForceAllRowRanges = Input.SafeIntConvert(Input.GetValue(settings, "apiForceAllRowRanges"), 0); if (ApiForceAllRowRanges < 1) ApiForceAllRowRanges = Input.SafeIntConvert(Input.GetValue(settings, "apiForceRowRange"), 0); //depricated ApiForceCatalogRowRange = Input.SafeIntConvert(Input.GetValue(settings, "apiForceCatalogRowRange"), 0); ApiForceCategoryRowRange = Input.SafeIntConvert(Input.GetValue(settings, "apiForceCategoryRowRange"), 0); ApiForceSalesRowRange = Input.SafeIntConvert(Input.GetValue(settings, "apiForceSalesRowRange"), 0); ApiForceCustomerRowRange = Input.SafeIntConvert(Input.GetValue(settings, "apiForceCustomerRowRange"), 0); ApiForceInventoryRowRange = Input.SafeIntConvert(Input.GetValue(settings, "apiForceInventoryRowRange"), 0); ApiAllowExtraRows = Input.GetValue(settings, "apiAllowExtraRows").Equals("true", StringComparison.OrdinalIgnoreCase); ApiMaxDaysPerRequest = Input.SafeIntConvert(Input.GetValue(settings, "apiMaxDaysPerRequest"), 0); ApiUserName = Input.GetValue(settings, "apiUserName"); ApiKey = Input.GetValue(settings, "apiKey"); ApiSecret = Input.GetValue(settings, "apiSecret"); ApiAliasParam = Input.GetValue(settings, "apiAliasParam"); ApiUserParam = Input.GetValue(settings, "apiUserParam"); ApiKeyParam = Input.GetValue(settings, "apiKeyParam"); ApiFieldParam = Input.GetValue(settings, "apiFieldParam"); ApiIdRangeParam = Input.GetValue(settings, "apiIdRangeParam"); ApiRowRangeParam = Input.GetValue(settings, "apiRowRangeParam"); ApiDateRangeParam = Input.GetValue(settings, "apiDateRangeParam"); ApiYearParam = Input.GetValue(settings, "apiYearParam"); ApiMonthParam = Input.GetValue(settings, "apiMonthParam"); ApiModeParam = Input.GetValue(settings, "apiModeParam"); ApiResponseFormat = Input.GetValue(settings, "apiResponseFormat"); ApiAcceptHeader = Input.GetValue(settings, "apiAcceptHeader"); ApiExtraHeaders = Input.SafeIntConvert(Input.GetValue(settings, "apiExtraHeaders")); var additionalQueries = settings.Element("apiAddQueries"); if (additionalQueries != null) { var queries = additionalQueries.Descendants("addQuery"); if (queries.Any()) { ApiAddQueries = new Dictionary<DataGroup, NameValueCollection>(); foreach (var q in queries) { //parse query details var queryGroup = Input.GetAttribute(q, "group"); if (string.IsNullOrEmpty(queryGroup)) continue; DataGroup dataGroup; if (!Enum.TryParse(queryGroup, true, out dataGroup)) continue; var name = Input.GetAttribute(q, "name"); if (string.IsNullOrEmpty(name)) continue; var value = Input.GetAttribute(q, "value"); if (string.IsNullOrEmpty(value)) continue; NameValueCollection queryList; if (!ApiAddQueries.TryGetValue(dataGroup, out queryList)) { ApiAddQueries.Add(dataGroup, new NameValueCollection {{name, value}}); } else ApiAddQueries[dataGroup].Add(name, value); } } } var charMapXml = settings.Element("titleCharMap"); TitleCharMap = GetCharMapPairs(charMapXml, Alias); WebClientConfig = new CartWebClientConfig(settings); //cart extraction settings CombinedFeedUrl = Input.GetValue(settings, "combinedFeedUrl"); if (string.IsNullOrEmpty(CombinedFeedUrl)) CombinedFeedUrl = Input.GetValue(settings, "combinedFeed"); //old name CatalogFeedUrl = Input.GetValue(settings, "catalogFeedUrl"); if (string.IsNullOrEmpty(CatalogFeedUrl)) CatalogFeedUrl = Input.GetValue(settings, "catalogFeed"); //old name SalesFeedUrl = Input.GetValue(settings, "salesFeedUrl"); if (string.IsNullOrEmpty(SalesFeedUrl)) SalesFeedUrl = Input.GetValue(settings, "salesFeed"); //old name CustomerFeedUrl = Input.GetValue(settings, "customerFeedUrl"); Att1NameFeedUrl = Input.GetValue(settings, "att1NameFeedUrl"); if (string.IsNullOrEmpty(Att1NameFeedUrl)) Att1NameFeedUrl = Input.GetValue(settings, "att1NameFeed"); //old name Att2NameFeedUrl = Input.GetValue(settings, "att2NameFeedUrl"); if (string.IsNullOrEmpty(Att2NameFeedUrl)) Att2NameFeedUrl = Input.GetValue(settings, "att2NameFeed"); //old name DepartmentNameFeedUrl = Input.GetValue(settings, "departmentNameFeedUrl"); InventoryFeedUrl = Input.GetValue(settings, "inventoryFeedUrl"); //Access Rules var accessCreds = settings.Element("accessCredentials"); if (accessCreds != null) AccessCredentials = new AuthCredentials(accessCreds); var extractorCreds = settings.Element("extractorCredentials"); if (extractorCreds != null) ExtractorCredentials = new AuthCredentials(extractorCreds); else if (AccessCredentials != null) //if no extractor creds provided, make them match the access creds ExtractorCredentials = new AuthCredentials(AccessCredentials); var loginUrl = Input.GetValue(settings, "extractorLoginUrl"); if (loginUrl != null) ExtractorLoginUrl = loginUrl; var loginCreds = settings.Element("extractorLoginCredentials"); if (loginCreds != null) ExtractorLoginCredentials = new AuthCredentials(loginCreds); //Extractor Flags -- only override defaults if a value is set in siterules //general (timeframes are set in legacy settings) var flag = Input.GetValue(settings, "unescapeFeedData"); if (!string.IsNullOrEmpty(flag)) UnescapeFeedData = flag.Equals("true", StringComparison.OrdinalIgnoreCase); flag = Input.GetValue(settings, "reduceXmlFeed"); if (!string.IsNullOrEmpty(flag)) ReduceXmlFeed = flag.Equals("true", StringComparison.OrdinalIgnoreCase); flag = Input.GetValue(settings, "omitExtraFields"); if (!string.IsNullOrEmpty(flag)) OmitExtraFields = flag.Equals("true", StringComparison.OrdinalIgnoreCase); UseLargeCatalogHandling = Input.GetValue(settings, "useLargeCatalogHandling").Equals("true", StringComparison.OrdinalIgnoreCase); //sales flag = Input.GetValue(settings, "extractSalesUpdate"); if (!string.IsNullOrEmpty(flag)) ExtractSalesUpdate = flag.Equals("true", StringComparison.OrdinalIgnoreCase); flag = Input.GetValue(settings, "extractSalesFull"); if (!string.IsNullOrEmpty(flag)) ExtractSalesFull = !flag.Equals("false", StringComparison.OrdinalIgnoreCase); //default true flag = Input.GetValue(settings, "extractSalesFromXmlFile"); if (!string.IsNullOrEmpty(flag)) ExtractSalesFromXmlFile = flag.Equals("true", StringComparison.OrdinalIgnoreCase); flag = Input.GetValue(settings, "orderDateReversed"); if (!string.IsNullOrEmpty(flag)) OrderDateReversed = flag.Equals("true", StringComparison.OrdinalIgnoreCase); //customers flag = Input.GetValue(settings, "extractCustomerData"); if (!string.IsNullOrEmpty(flag)) ExtractCustomerData = flag.Equals("true", StringComparison.OrdinalIgnoreCase); flag = Input.GetValue(settings, "requireEmailOptIn"); if (!string.IsNullOrEmpty(flag)) RequireEmailOptIn = flag.Equals("true", StringComparison.OrdinalIgnoreCase); flag = Input.GetValue(settings, "trackShopperActivity"); if (!string.IsNullOrEmpty(flag)) TrackShopperActivity = flag.Equals("true", StringComparison.OrdinalIgnoreCase); PersonaMappingFields = Input.GetValue(settings, "personaMappingFields"); //catalog flag = Input.GetValue(settings, "invalidatePricesOnExtract"); if (!string.IsNullOrEmpty(flag)) InvalidatePricesOnExtract = flag.Equals("true", StringComparison.OrdinalIgnoreCase); flag = Input.GetValue(settings, "invalidatePricesOnExtractComplete"); if (!string.IsNullOrEmpty(flag)) InvalidatePricesOnExtractComplete = flag.Equals("true", StringComparison.OrdinalIgnoreCase); flag = Input.GetValue(settings, "extractCatalogFromXmlFile"); if (!string.IsNullOrEmpty(flag)) ExtractCatalogFromXmlFile = flag.Equals("true", StringComparison.OrdinalIgnoreCase); flag = Input.GetValue(settings, "extractAtt2Names"); if (string.IsNullOrEmpty(flag)) flag = Input.GetValue(settings, "exportAtt2Names"); //legacy name if (!string.IsNullOrEmpty(flag)) ExtractAtt2Names = flag.Equals("true", StringComparison.OrdinalIgnoreCase); flag = Input.GetValue(settings, "allowLowerCatalogCount"); if (!string.IsNullOrEmpty(flag)) AllowLowerCatalogCount = flag.Equals("true", StringComparison.OrdinalIgnoreCase); flag = Input.GetValue(settings, "allowLowerSalesCount"); if (!string.IsNullOrEmpty(flag)) AllowLowerSalesCount = flag.Equals("true", StringComparison.OrdinalIgnoreCase); flag = Input.GetValue(settings, "allowLowerCustomerCount"); if (!string.IsNullOrEmpty(flag)) AllowLowerCustomerCount = flag.Equals("true", StringComparison.OrdinalIgnoreCase); flag = Input.GetValue(settings, "mapStockToVisibility"); if (!string.IsNullOrEmpty(flag)) MapStockToVisibility = flag.Equals("true", StringComparison.OrdinalIgnoreCase); flag = Input.GetValue(settings, "reverseVisibleFlag"); if (!string.IsNullOrEmpty(flag)) ReverseVisibleFlag = flag.Equals("true", StringComparison.OrdinalIgnoreCase); flag = Input.GetValue(settings, "ignoreStockUseFlag"); if (!string.IsNullOrEmpty(flag)) IgnoreStockUseFlag = flag.Equals("true", StringComparison.OrdinalIgnoreCase); flag = Input.GetValue(settings, "ignoreStockInPriceRange"); if (!string.IsNullOrEmpty(flag)) IgnoreStockInPriceRange = flag.Equals("true", StringComparison.OrdinalIgnoreCase); flag = Input.GetValue(settings, "includeChildrenInCatalog"); if (!string.IsNullOrEmpty(flag)) IncludeChildrenInCatalog = flag.Equals("true", StringComparison.OrdinalIgnoreCase); flag = Input.GetValue(settings, "useAverageChildRating"); if (!string.IsNullOrEmpty(flag)) UseAverageChildRating = flag.Equals("true", StringComparison.OrdinalIgnoreCase); HiddenSalePriceText = Input.GetValue(settings, "hiddenSalePriceText"); //categories MapCategoriesToFilters = Input.GetValue(settings, "mapCategoriesToFilters") .Equals("true", StringComparison.OrdinalIgnoreCase); IncludeCategoryParents = Input.GetValue(settings, "includeCategoryParents") .Equals("true", StringComparison.OrdinalIgnoreCase); flag = Input.GetValue(settings, "exportDepartmentNames"); if (!string.IsNullOrEmpty(flag)) ExportDepartmentNames = flag.Equals("true", StringComparison.OrdinalIgnoreCase); flag = Input.GetValue(settings, "useDepartmentsAsCategories"); if (!string.IsNullOrEmpty(flag)) UseDepartmentsAsCategories = flag.Equals("true", StringComparison.OrdinalIgnoreCase); var catSep = Input.GetValue(settings, "categorySeparator"); if (!string.IsNullOrEmpty(catSep)) { char charTest; if (Input.TryConvert(catSep, out charTest)) CategorySeparator = charTest.ToString(); else CategorySeparator = catSep; } //images AllowMissingPhotos = false; var amp = settings.Element("allowMissingPhotos"); if (amp != null) { if (amp.Value != null && amp.Value.Equals("true")) AllowMissingPhotos = true; else AllowMissingPhotos = Input.GetAttribute(amp, "enabled").Equals("true"); } var imageThreshold = Input.SafeIntConvert(Input.GetValue(settings, "missingImageThreshold"), -1); if (imageThreshold > -1) MissingImageThreshold = imageThreshold; flag = Input.GetValue(settings, "extrapolateThumbnailPath"); if (!string.IsNullOrEmpty(flag)) ExtrapolateThumbnailPath = flag.Equals("true"); flag = Input.GetValue(settings, "scrapeCategoryThumbnails"); if (string.IsNullOrEmpty(flag)) flag = Input.GetValue(settings, "useCacheThumb"); //depricated if (!string.IsNullOrEmpty(flag)) ScrapeCategoryThumbnails = !flag.Equals("false"); //default true flag = Input.GetValue(settings, "forceCategoryTreeScrape"); if (!string.IsNullOrEmpty(flag)) ForceCategoryTreeScrape = flag.Equals("true"); flag = Input.GetValue(settings, "imageLinkBaseUrl"); if (string.IsNullOrEmpty(flag)) flag = Input.GetValue(settings, "photoBaseUrl"); //legacy name if (!string.IsNullOrEmpty(flag)) ImageLinkBaseUrl = flag; flag = Input.GetValue(settings, "imageLinkFormat"); //a string.Format parameter that the product id gets plugged into if (!string.IsNullOrEmpty(flag)) { if (flag.IndexOf("{0}") >= 0) ImageLinkFormat = flag; else if (string.IsNullOrEmpty(ImageLinkBaseUrl)) //missing locator for the id so use it as a baseUrl instead ImageLinkBaseUrl = flag; } if (!string.IsNullOrEmpty(ImageLinkBaseUrl)) { if (!ImageLinkBaseUrl.StartsWith("/") && !ImageLinkBaseUrl.StartsWith("http")) ImageLinkBaseUrl = "/" + ImageLinkBaseUrl; //add initial slash if (ImageLinkBaseUrl.EndsWith("/")) ImageLinkBaseUrl = ImageLinkBaseUrl.Substring(0, ImageLinkBaseUrl.Length - 1); //remove final slash } flag = Input.GetValue(settings, "pageLinkFormat"); //a string.Format parameter that the product id gets plugged into if (!string.IsNullOrEmpty(flag) && flag.Contains("{0}")) PageLinkFormat = flag; ProductNodeSelector = Input.GetValue(settings, "productNodeSelector"); ImageUrlSelector = Input.GetValue(settings, "imageUrlSelector"); ImageUrlPrefix = Input.GetValue(settings, "imageUrlPrefix"); ImageUrlSuffix = Input.GetValue(settings, "imageUrlSuffix"); PidSelector = Input.GetValue(settings, "pidSelector"); PidPrefix = Input.GetValue(settings, "pidPrefix"); PidSuffix = Input.GetValue(settings, "pidSuffix"); CommentParseKey = Input.GetValue(settings, "commentParseKey"); if (string.IsNullOrEmpty(ProductNodeSelector)) ProductNodeSelector = Input.GetValue(settings, "imageNodeSelector"); //depricated if (string.IsNullOrEmpty(ImageUrlPrefix)) ImageUrlPrefix = Input.GetValue(settings, "imageSrcSelector"); //depricated //First check CartRules for defaults var cartRules = ReadCartRules(CartType); Fields.InitializeFields(cartRules, true); Fields.InitializeFields(settings, false); //conditional rules ExclusionRules = new List<Condition>(); var exConditions = settings.Element("exclusionConditions"); if (exConditions != null) { foreach (var ec in exConditions.Elements("condition")) { var name = Input.GetAttribute(ec, "name"); var comparison = Input.GetAttribute(ec, "comparison"); var value = Input.GetAttribute(ec, "value"); var fieldName = Input.GetAttribute(ec, "fieldName"); var conditionType = Input.GetAttribute(ec, "type"); //var resultField = FieldsIncludeTablePrefix ? StripTablePrefix(fieldName) : fieldName; try { ExclusionRules.Add(new Condition(name, comparison, value, fieldName)); //, resultField)); } catch (Exception ex) { if (BoostLog.Instance != null) BoostLog.Instance.WriteEntry(EventLogEntryType.Error, "Error creating exclusion rule", ex, Alias); } } } var exSet = settings.Element("exclusionSet"); if (exSet != null) { ExclusionSet = new LogicSet(Alias, exSet); } FilterParsingRules = null; var filterParsing = settings.Element("filterParsingRules"); if (filterParsing != null) { FilterParsingRules = new List<ParseGroup>(); var parseGroups = filterParsing.Elements("parseGroup"); if (parseGroups != null) { var tempVal = ""; foreach (var g in parseGroups) { var newGroup = new ParseGroup { Delimiter = Input.GetAttribute(g, "delimiter") }; var parseRules = g.Elements("parseRule"); if (parseRules == null) continue; newGroup.ParseRules = new List<ParseRule>(); foreach (var pr in parseRules) { newGroup.ParseRules.Add(new ParseRule { FromField = Input.GetAttribute(pr, "fromField"), ToField = Input.GetAttribute(pr, "toField"), RegexMatch = Input.GetAttribute(pr, "regexMatch"), RegexGroup = Input.SafeIntConvert(Input.GetAttribute(pr, "regexGroup")), Expand = Input.GetAttribute(pr, "expand").Equals("true"), Modulo = Input.SafeIntConvert(Input.GetAttribute(pr, "modulo")), Delimiter = Input.GetAttribute(pr, "delimiter"), Format = Input.GetAttribute(pr, "format") }); } FilterParsingRules.Add(newGroup); } } } FilterRules = new List<Condition>(); var filterConditions = settings.Element("filterConditions"); if (filterConditions != null) { foreach (var f in filterConditions.Elements("condition")) { var name = Input.GetAttribute(f, "name"); var comparison = Input.GetAttribute(f, "comparison"); var value = Input.GetAttribute(f, "value"); var fieldName = Input.GetAttribute(f, "fieldName"); //var resultField = FieldsIncludeTablePrefix ? StripTablePrefix(fieldName) : fieldName; try { FilterRules.Add(new Condition(name, comparison, value, fieldName)); //, resultField)); } catch (Exception ex) { if (BoostLog.Instance != null) BoostLog.Instance.WriteEntry(EventLogEntryType.Error, "Error creating filter rule", ex, Alias); } } } UniversalFilterName = Input.GetValue(settings, "universalFilterName"); if (UniversalFilterName.Length < 1) UniversalFilterName = "Universal"; FilterTopSellers = Input.GetValue(settings, "filterTopSellers").Equals("true", StringComparison.CurrentCultureIgnoreCase); ReplacementRules = new List<ReplacementCondition>(); var repConditions = settings.Element("replacementConditions"); if (repConditions != null) { foreach (var rep in repConditions.Elements("condition")) { var name = Input.GetAttribute(rep, "name"); var type = Input.GetAttribute(rep, "type"); var oldName = Input.GetAttribute(rep, "oldFieldName"); var newName = Input.GetAttribute(rep, "newFieldName"); var oldResultField = oldName; //FieldsIncludeTablePrefix ? StripTablePrefix(oldName) : oldName; var newResultField = newName; //FieldsIncludeTablePrefix ? StripTablePrefix(newName) : newName; ReplacementRules.Add(new ReplacementCondition(name, type, oldName, newName, oldResultField, newResultField)); } } var catConditions = settings.Element("categoryConditions"); if (catConditions != null) { foreach (var cat in catConditions.Elements("condition")) { var groupId = Input.GetAttribute(cat, "groupId"); var type = Input.GetAttribute(cat, "type"); var value = Input.GetAttribute(cat, "value"); CategoryRules.AddCat(type, value, groupId); } } //Featured selections var featuredConditions = settings.Element("featuredConditions") ?? settings.Element("manualTopSellConditions"); //depricated if (featuredConditions != null) { FeaturedRules = new List<FeaturedRecCondition>(); foreach (var cat in featuredConditions.Elements("condition")) { var queryField = Input.GetAttribute(cat, "fieldName"); var resultField = queryField; //FieldsIncludeTablePrefix ? StripTablePrefix(queryField) : queryField; var include = Input.GetAttribute(cat, "type").Equals("include", StringComparison.OrdinalIgnoreCase); var enabled = !Input.GetAttribute(cat, "enabled").Equals("false", StringComparison.OrdinalIgnoreCase); FeaturedRules.Add(new FeaturedRecCondition(queryField, resultField, include, enabled)); } } var featuredCrossSellConditions = settings.Element("featuredCrossSellConditions") ?? settings.Element("manualCrossSellConditions"); //depricated if (featuredCrossSellConditions != null) { FeaturedCrossSellRules = new List<FeaturedRecCondition>(); foreach (var cat in featuredCrossSellConditions.Elements("condition")) { var queryField = Input.GetAttribute(cat, "fieldName"); var resultField = queryField; //FieldsIncludeTablePrefix ? StripTablePrefix(queryField) : queryField; var include = Input.GetAttribute(cat, "type").Equals("include", StringComparison.OrdinalIgnoreCase); var enabled = !Input.GetAttribute(cat, "enabled").Equals("false", StringComparison.OrdinalIgnoreCase); FeaturedCrossSellRules.Add(new FeaturedRecCondition(queryField, resultField, include, enabled)); } } var featuredUpSellConditions = settings.Element("featuredUpSellConditions") ?? settings.Element("manualUpSellConditions"); //depricated if (featuredUpSellConditions != null) { FeaturedUpSellRules = new List<FeaturedRecCondition>(); foreach (var cat in featuredUpSellConditions.Elements("condition")) { var queryField = Input.GetAttribute(cat, "fieldName"); var resultField = queryField; //FieldsIncludeTablePrefix ? StripTablePrefix(queryField) : queryField; var include = Input.GetAttribute(cat, "type").Equals("include", StringComparison.OrdinalIgnoreCase); var enabled = !Input.GetAttribute(cat, "enabled").Equals("false", StringComparison.OrdinalIgnoreCase); FeaturedUpSellRules.Add(new FeaturedRecCondition(queryField, resultField, include, enabled)); } } //timers var upTimers = settings.Elements("updateTimer"); if (!upTimers.Any()) upTimers = settings.Elements("uploadTimer"); //depricated if (upTimers.Any()) { ExtractorSchedules = new List<ExtractorSchedule>(); foreach (var ut in upTimers) { ExtractorSchedules.Add(new ExtractorSchedule(ut)); } } //Exclusion Stats var exclusionStats = settings.Elements("exclusionStats"); if (exclusionStats.Any()) { var stats = exclusionStats.Elements("stat"); if (stats != null && stats.Any()) { ExclusionStats = new Dictionary<string, int>(); foreach (var s in stats) { var key = Input.GetAttribute(s, "name"); var value = Input.SafeIntConvert(Input.GetAttribute(s, "value")); ExclusionStats.Add(key, value); } } } #endregion }