public async Task <HttpResponseMessage> SaveDeviceRuleAsync(DeviceRule updatedRule) { return(await GetServiceResponseAsync <TableStorageResponse <DeviceRule> >(async() => { return await _deviceRulesLogic.SaveDeviceRuleAsync(updatedRule); })); }
//insert DATA FIELD,operators public async Task BootstrapDefaultRulesAsync(List <string> existingDeviceIds) { DeviceRule tempRule = await GetNewRuleAsync(existingDeviceIds[0]); tempRule.DataField = DeviceRuleDataFields.TEMP; tempRule.RuleOutput = "AlarmTEMP"; tempRule.Threshold = 38.0d; await SaveDeviceRuleAsync(tempRule); DeviceRule rearTPMRule = await GetNewRuleAsync(existingDeviceIds[0]); rearTPMRule.DataField = DeviceRuleDataFields.REAR_TPM; rearTPMRule.RuleOutput = "AlarmREAR_TPM"; rearTPMRule.Threshold = 48.0d; await SaveDeviceRuleAsync(rearTPMRule); DeviceRule frontTPMRule = await GetNewRuleAsync(existingDeviceIds[0]); frontTPMRule.DataField = DeviceRuleDataFields.FRONT_TPM; frontTPMRule.RuleOutput = "AlarmFRONT_TPM"; frontTPMRule.Threshold = 48.0d; await SaveDeviceRuleAsync(frontTPMRule); DeviceRule berreryVOLTRule = await GetNewRuleAsync(existingDeviceIds[0]); berreryVOLTRule.DataField = DeviceRuleDataFields.BETTERY_VOLT; berreryVOLTRule.RuleOutput = "AlarmBETTERY_VOLT"; berreryVOLTRule.Threshold = 48.0d; await SaveDeviceRuleAsync(berreryVOLTRule); }
public async Task <ActionResult> EditRuleProperties(string deviceId, string ruleId) { EditDeviceRuleModel editModel = null; //empty ruleId implies that we are creating new if (string.IsNullOrWhiteSpace(ruleId)) { bool canCreate = await _deviceRulesLogic.CanNewRuleBeCreatedForDeviceAsync(deviceId); if (!canCreate) { editModel = new EditDeviceRuleModel() { DeviceID = deviceId }; return(View("AllRulesAssigned", editModel)); } } DeviceRule ruleModel = await _deviceRulesLogic.GetDeviceRuleOrDefaultAsync(deviceId, ruleId); Dictionary <string, List <string> > availableFields = await _deviceRulesLogic.GetAvailableFieldsForDeviceRuleAsync(ruleModel.DeviceID, ruleModel.RuleId); List <SelectListItem> availableDataFields = this.ConvertStringListToSelectList(availableFields["availableDataFields"]); List <SelectListItem> availableOperators = this.ConvertStringListToSelectList(availableFields["availableOperators"]); List <SelectListItem> availableRuleOutputs = this.ConvertStringListToSelectList(availableFields["availableRuleOutputs"]); editModel = CreateEditModelFromDeviceRule(ruleModel); editModel.AvailableDataFields = availableDataFields; editModel.AvailableOperators = availableOperators; editModel.AvailableRuleOutputs = availableRuleOutputs; return(View("EditDeviceRuleProperties", editModel)); }
/// <summary> /// Save a Device Rule to the server. This may be either a new rule or an update to an existing rule. /// </summary> /// <param name="updateContainer"></param> /// <returns></returns> public async Task <TableStorageResponse <DeviceRule> > SaveDeviceRuleAsync(DeviceRule updatedRule) { DeviceRuleTableEntity incomingEntity = new DeviceRuleTableEntity(updatedRule.DeviceID, updatedRule.RuleId) { DataField = updatedRule.DataField, Threshold = (double)updatedRule.Threshold, Enabled = updatedRule.EnabledState, RuleOutput = updatedRule.RuleOutput }; if (!string.IsNullOrWhiteSpace(updatedRule.Etag)) { incomingEntity.ETag = updatedRule.Etag; } TableStorageResponse <DeviceRule> result = await AzureTableStorageHelper.DoTableInsertOrReplace <DeviceRule, DeviceRuleTableEntity>(incomingEntity, BuildRuleFromTableEntity, _storageAccountConnectionString, _deviceRulesNormalizedTableName); // Build up a new blob to push up List <DeviceRuleBlobEntity> blobList = await BuildBlobEntityListFromTableRows(); await PersistRulesToBlobStorageAsync(blobList); return(result); }
public async void SaveDeviceRuleAsyncTest() { var deviceId = fixture.Create <string>(); var rules = fixture.Create <List <DeviceRule> >(); rules.ForEach(x => x.DeviceID = deviceId); _deviceRulesRepositoryMock.Setup(x => x.GetAllRulesForDeviceAsync(deviceId)).ReturnsAsync(rules); _deviceRulesRepositoryMock.Setup(x => x.SaveDeviceRuleAsync(It.IsNotNull <DeviceRule>())) .ReturnsAsync(new TableStorageResponse <DeviceRule>()); var newRule = new DeviceRule(); newRule.InitializeNewRule(deviceId); newRule.DataField = rules[0].DataField; var ret = await deviceRulesLogic.SaveDeviceRuleAsync(newRule); Assert.NotNull(ret.Entity); Assert.Equal(TableStorageResponseStatus.DuplicateInsert, ret.Status); newRule.InitializeNewRule(deviceId); newRule.DataField = "New data in DataField"; ret = await deviceRulesLogic.SaveDeviceRuleAsync(newRule); Assert.NotNull(ret); }
public async Task <ActionResult> RemoveRule(string deviceId, string ruleId) { DeviceRule ruleModel = await _deviceRulesLogic.GetDeviceRuleOrDefaultAsync(deviceId, ruleId); EditDeviceRuleModel editModel = CreateEditModelFromDeviceRule(ruleModel); return(View("RemoveDeviceRule", editModel)); }
public async Task <ActionResult> GetRuleProperties(string deviceId, string ruleId) { DeviceRule rule = await _deviceRulesLogic.GetDeviceRuleAsync(deviceId, ruleId); EditDeviceRuleModel editModel = CreateEditModelFromDeviceRule(rule); return(PartialView("_DeviceRuleProperties", editModel)); }
internal static bool LoadRulesFromDB(int rulesetId, string deviceName, List <DeviceRule> rules) { DataTable rulesTable = GetRulesetRules(rulesetId); string[] propsList = { "RuleNumber", "TriggerLabel", "ActionLabel" }; if (rulesTable != null) { bool allOK = true; foreach (var prop in propsList) { if (!rulesTable.Columns.Contains(prop)) { Logger.AddLogEntry(LogCategory.ERROR, String.Format("LoadActiveRulesFromDB: {0} not found.", prop)); allOK = false; } } if (allOK) { foreach (DataRow dr in rulesTable.Rows) { string ruleNumberStr = dr["RuleNumber"].ToString(); string actionLabel = dr["ActionLabel"].ToString(); string triggerLabel = dr["TriggerLabel"].ToString(); if (Int32.TryParse(ruleNumberStr, out int ruleNumber)) { DeviceRule rule = new DeviceRule { RuleNumber = ruleNumber, DeviceName = deviceName }; if (triggerLabel != null) { rule.TriggerClip = AudioClipsMgr.GetAudioClip(triggerLabel); } if (rule.TriggerClip == null) // if null, it's a TimeTrigger { rule.TriggerClip = AudioClipsMgr.GetTimeTriggerClip(triggerLabel); } if (actionLabel != null) { rule.ActionClip = AudioClipsMgr.GetAudioClip(actionLabel); } rules.Add(rule); } else { Logger.AddLogEntry(LogCategory.ERROR, String.Format("LoadActiveRulesFromDB: Could not parse entry for ruleNumber {0}", ruleNumberStr)); } } Logger.AddLogEntry(LogCategory.INFO, "Active Rules Loaded"); return(true); } return(false); } return(false); }
/// <summary> /// Generate a new rule with bare-bones configuration. This new rule can then be conigured and sent /// back through the SaveDeviceRuleAsync method to persist. /// </summary> /// <param name="deviceId"></param> /// <returns></returns> public async Task <DeviceRule> GetNewRuleAsync(string deviceId) { return(await Task.Run(() => { var rule = new DeviceRule(); rule.InitializeNewRule(deviceId); return rule; })); }
private static String CreateDeviceRules(int temperature) { DeviceRule deviceRule = new DeviceRule(); deviceRule.SensorType = "thermometer"; deviceRule.TemperatureThreshold = temperature; List <DeviceRule> deviceRules = new List <DeviceRule>(); deviceRules.Add(deviceRule); return(JsonConvert.SerializeObject(deviceRules)); }
/// <summary> /// Retrieve a single rule from AzureTableStorage or default if none exists. /// A distinct rule is defined by the combination key deviceID/DataField /// </summary> /// <param name="deviceId"></param> /// <param name="dataField"></param> /// <returns></returns> public async Task <DeviceRule> GetDeviceRuleAsync(string deviceId, string ruleId) { TableOperation query = TableOperation.Retrieve <DeviceRuleTableEntity>(deviceId, ruleId); TableResult response = await Task.Run(() => _azureTableStorageClient.Execute(query) ); DeviceRule result = BuildRuleFromTableEntity((DeviceRuleTableEntity)response.Result); return(result); }
public async Task <ActionResult> UpdateRuleProperties(EditDeviceRuleModel model) { string errorMessage = model.CheckForErrorMessage(); if (!string.IsNullOrWhiteSpace(errorMessage)) { return(Json(new { error = errorMessage })); } DeviceRule rule = CreateDeviceRuleFromEditModel(model); TableStorageResponse <DeviceRule> response = await _deviceRulesLogic.SaveDeviceRuleAsync(rule); return(BuildRuleUpdateResponse(response)); }
/// <summary> /// Retrieve a single rule from AzureTableStorage or default if none exists. /// A distinct rule is defined by the combination key deviceID/DataField /// </summary> /// <param name="deviceId"></param> /// <param name="dataField"></param> /// <returns></returns> public async Task <DeviceRule> GetDeviceRuleAsync(string deviceId, string ruleId) { var deviceRulesTable = await AzureTableStorageHelper.GetTableAsync(_storageAccountConnectionString, _deviceRulesNormalizedTableName); TableOperation query = TableOperation.Retrieve <DeviceRuleTableEntity>(deviceId, ruleId); TableResult response = await Task.Run(() => deviceRulesTable.Execute(query) ); DeviceRule result = BuildRuleFromTableEntity((DeviceRuleTableEntity)response.Result); return(result); }
public async Task <TableStorageResponse <DeviceRule> > DeleteDeviceRuleAsync(string deviceId, string ruleId) { DeviceRule found = await _deviceRulesRepository.GetDeviceRuleAsync(deviceId, ruleId); if (found == null) { var response = new TableStorageResponse <DeviceRule>(); response.Entity = found; response.Status = TableStorageResponseStatus.NotFound; return(response); } return(await _deviceRulesRepository.DeleteDeviceRuleAsync(found)); }
public async Task BootstrapDefaultRulesAsync(List <string> existingDeviceIds) { DeviceRule temperatureRule = await GetNewRuleAsync(existingDeviceIds[0]); temperatureRule.DataField = DeviceRuleDataFields.Temperature; temperatureRule.RuleOutput = "AlarmTemp"; temperatureRule.Threshold = 38.0d; await SaveDeviceRuleAsync(temperatureRule); DeviceRule humidityRule = await GetNewRuleAsync(existingDeviceIds[0]); humidityRule.DataField = DeviceRuleDataFields.Humidity; humidityRule.RuleOutput = "AlarmHumidity"; humidityRule.Threshold = 48.0d; await SaveDeviceRuleAsync(humidityRule); }
public async Task <TableStorageResponse <DeviceRule> > DeleteDeviceRuleAsync(DeviceRule ruleToDelete) { DeviceRuleTableEntity incomingEntity = BuildTableEntityFromRule(ruleToDelete); TableStorageResponse <DeviceRule> result = await _azureTableStorageClient.DoDeleteAsync <DeviceRule, DeviceRuleTableEntity>(incomingEntity, BuildRuleFromTableEntity); if (result.Status == TableStorageResponseStatus.Successful) { // Build up a new blob to push up for ASA job ref data List <DeviceRuleBlobEntity> blobList = await BuildBlobEntityListFromTableRows(); await PersistRulesToBlobStorageAsync(blobList); } return(result); }
private DeviceRule CreateDeviceRuleFromEditModel(EditDeviceRuleModel editModel) { DeviceRule rule = new DeviceRule(editModel.RuleId); rule.DataField = editModel.DataField; rule.DeviceID = editModel.DeviceID; rule.EnabledState = editModel.EnabledState; rule.Etag = editModel.Etag; rule.Operator = editModel.Operator; rule.RuleOutput = editModel.RuleOutput; if (!string.IsNullOrWhiteSpace(editModel.Threshold)) { rule.Threshold = double.Parse(editModel.Threshold); } return(rule); }
public async Task <TableStorageResponse <DeviceRule> > DeleteDeviceRuleAsync(DeviceRule ruleToDelete) { DeviceRuleTableEntity incomingEntity = BuildTableEntityFromRule(ruleToDelete); TableStorageResponse <DeviceRule> result = await AzureTableStorageHelper.DoDeleteAsync <DeviceRule, DeviceRuleTableEntity>(incomingEntity, BuildRuleFromTableEntity, _storageAccountConnectionString, _deviceRulesNormalizedTableName); if (result.Status == TableStorageResponseStatus.Successful) { // Build up a new blob to push up for ASA job ref data List <DeviceRuleBlobEntity> blobList = await BuildBlobEntityListFromTableRows(); await PersistRulesToBlobStorageAsync(blobList); } return(result); }
/// <summary> /// Retrieve an existing rule for editing. If none is found then a default, bare-bones rule is returned for creating new /// A new rule is not persisted until it is saved. Distinct Rules are defined by the combination key of deviceID and ruleId /// /// Use this method if you are not sure the desired rule exists /// </summary> /// <param name="deviceId"></param> /// <param name="ruleId"></param> /// <returns></returns> public async Task <DeviceRule> GetDeviceRuleOrDefaultAsync(string deviceId, string ruleId) { List <DeviceRule> rulesForDevice = await _deviceRulesRepository.GetAllRulesForDeviceAsync(deviceId); foreach (DeviceRule rule in rulesForDevice) { if (rule.RuleId == ruleId) { return(rule); } } var createdRule = new DeviceRule(); createdRule.InitializeNewRule(deviceId); return(createdRule); }
private EditDeviceRuleModel CreateEditModelFromDeviceRule(DeviceRule rule) { EditDeviceRuleModel editModel = new EditDeviceRuleModel(); editModel.RuleId = rule.RuleId; editModel.DataField = rule.DataField; editModel.DeviceID = rule.DeviceID; editModel.EnabledState = rule.EnabledState; editModel.Etag = rule.Etag; editModel.Operator = rule.Operator; editModel.RuleOutput = rule.RuleOutput; if (rule.Threshold != null) { editModel.Threshold = rule.Threshold.ToString(); } return(editModel); }
/// <summary> /// Save a rule to the data store. This method should be used for new rules as well as updating existing rules /// </summary> /// <param name="updatedRule"></param> /// <returns></returns> public async Task <TableStorageResponse <DeviceRule> > SaveDeviceRuleAsync(DeviceRule updatedRule) { //Enforce single instance of a rule for a data field for a given device List <DeviceRule> foundForDevice = await _deviceRulesRepository.GetAllRulesForDeviceAsync(updatedRule.DeviceID); foreach (DeviceRule rule in foundForDevice) { if (rule.DataField == updatedRule.DataField && rule.RuleId != updatedRule.RuleId) { var response = new TableStorageResponse <DeviceRule>(); response.Entity = rule; response.Status = TableStorageResponseStatus.DuplicateInsert; return(response); } } return(await _deviceRulesRepository.SaveDeviceRuleAsync(updatedRule)); }
private DeviceRuleTableEntity BuildTableEntityFromRule(DeviceRule incomingRule) { DeviceRuleTableEntity tableEntity = new DeviceRuleTableEntity(incomingRule.DeviceID, incomingRule.RuleId) { DataField = incomingRule.DataField, Threshold = (double)incomingRule.Threshold, Enabled = incomingRule.EnabledState, RuleOutput = incomingRule.RuleOutput }; if (!string.IsNullOrWhiteSpace(incomingRule.Etag)) { tableEntity.ETag = incomingRule.Etag; } return(tableEntity); }
public async Task BootstrapDefaultRulesAsync(List <string> existingDeviceIds) { foreach (var deviceId in existingDeviceIds) { DeviceRule temperatureRule = await GetNewRuleAsync(deviceId); temperatureRule.DataField = DeviceRuleDataFields.Temperature; temperatureRule.RuleOutput = "AlarmTemp"; temperatureRule.Threshold = 60.0d; await SaveDeviceRuleAsync(temperatureRule); DeviceRule humidityRule = await GetNewRuleAsync(deviceId); humidityRule.DataField = DeviceRuleDataFields.WaterLevel; humidityRule.RuleOutput = "AlarmWaterLevel"; humidityRule.Threshold = 48.0d; await SaveDeviceRuleAsync(humidityRule); } }
private DeviceRule BuildRuleFromTableEntity(DeviceRuleTableEntity tableEntity) { if (tableEntity == null) { return(null); } var updatedRule = new DeviceRule(tableEntity.RuleId) { DeviceID = tableEntity.DeviceId, DataField = tableEntity.DataField, Threshold = tableEntity.Threshold, EnabledState = tableEntity.Enabled, Operator = ">", RuleOutput = tableEntity.RuleOutput, Etag = tableEntity.ETag }; return(updatedRule); }
public async Task BootstrapDefaultRulesAsync(List <string> existingDeviceIds) { DeviceRule temperatureRule = await GetNewRuleAsync(existingDeviceIds[0]); temperatureRule.DataField = DeviceRuleDataFields.Temperature; temperatureRule.RuleOutput = "AlarmTemp"; temperatureRule.Threshold = 38.0d; await SaveDeviceRuleAsync(temperatureRule); DeviceRule speedRule = await GetNewRuleAsync(existingDeviceIds[0]); speedRule.DataField = DeviceRuleDataFields.Speed; speedRule.RuleOutput = "AlarmSpeed"; speedRule.Threshold = 48.0d; await SaveDeviceRuleAsync(speedRule); DeviceRule obstacleRule = await GetNewRuleAsync(existingDeviceIds[0]); speedRule.DataField = DeviceRuleDataFields.IsObstacleDetected; speedRule.RuleOutput = "AlarmObstacle"; speedRule.Threshold = 0; await SaveDeviceRuleAsync(obstacleRule); }
internal static bool AddRule(int rulesetId, DeviceRule rule) { lock (DBAdmin.padlock) { int updatedRows = 0; using (SQLiteConnection dbConnection = DBAdmin.GetSQLConnection()) { dbConnection.Open(); using (SQLiteCommand cmd = new SQLiteCommand(dbConnection)) { SQLiteTransaction trans = dbConnection.BeginTransaction(); cmd.CommandText = "INSERT INTO [RULESET_RULES] ([RulesetId], [RuleNumber], " + "[DeviceName], [TriggerLabel], [ActionLabel]) " + "VALUES(@rulesetId, @ruleNumber, @deviceName, @triggerLabel, @actionLabel);"; cmd.Parameters.Add(new SQLiteParameter("@rulesetId", DbType.Int32) { Value = rulesetId }); cmd.Parameters.Add(new SQLiteParameter("@ruleNumber", DbType.Int32) { Value = rule.RuleNumber }); cmd.Parameters.Add(new SQLiteParameter("@deviceName", DbType.String) { Value = rule.DeviceName }); if (rule.TriggerClip != null) { cmd.Parameters.Add(new SQLiteParameter("@triggerLabel", DbType.String) { Value = rule.TriggerClip.Label }); } else { cmd.Parameters.Add(new SQLiteParameter("@triggerLabel", DbType.String) { Value = null }); } if (rule.ActionClip != null) { cmd.Parameters.Add(new SQLiteParameter("@actionLabel", DbType.String) { Value = rule.ActionClip.Label }); } else { cmd.Parameters.Add(new SQLiteParameter("@actionLabel", DbType.String) { Value = null }); } updatedRows = cmd.ExecuteNonQuery(); trans.Commit(); } } return(updatedRows == 1); } }
public async Task <ActionResult> GetNewRule(string deviceId) { DeviceRule rule = await _deviceRulesLogic.GetNewRuleAsync(deviceId); return(Json(rule)); }
protected override IEnumerable <RuleDescriptor> LoadDescriptors() { var language = _services.WorkContext.WorkingLanguage; var currencyCode = _services.StoreContext.CurrentStore.PrimaryStoreCurrency.CurrencyCode; var stores = _services.StoreService.GetAllStores() .Select(x => new RuleValueSelectListOption { Value = x.Id.ToString(), Text = x.Name }) .ToArray(); var cartItemQuantity = new CartRuleDescriptor { Name = "CartItemQuantity", DisplayName = T("Admin.Rules.FilterDescriptor.CartItemQuantity"), RuleType = RuleType.String, ProcessorType = typeof(CartItemQuantityRule), Operators = new[] { RuleOperator.IsEqualTo } }; cartItemQuantity.Metadata["ValueTemplateName"] = "ValueTemplates/CartItemQuantity"; cartItemQuantity.Metadata["ProductRuleDescriptor"] = new CartRuleDescriptor { Name = "CartItemQuantity-Product", RuleType = RuleType.Int, ProcessorType = typeof(CartItemQuantityRule), Operators = new[] { RuleOperator.IsEqualTo }, SelectList = new RemoteRuleValueSelectList("Product") }; var descriptors = new List <CartRuleDescriptor> { new CartRuleDescriptor { Name = "Currency", DisplayName = T("Admin.Rules.FilterDescriptor.Currency"), RuleType = RuleType.IntArray, ProcessorType = typeof(CurrencyRule), SelectList = new RemoteRuleValueSelectList("Currency") { Multiple = true } }, new CartRuleDescriptor { Name = "Language", DisplayName = T("Admin.Rules.FilterDescriptor.Language"), RuleType = RuleType.IntArray, ProcessorType = typeof(LanguageRule), SelectList = new RemoteRuleValueSelectList("Language") { Multiple = true } }, new CartRuleDescriptor { Name = "Store", DisplayName = T("Admin.Rules.FilterDescriptor.Store"), RuleType = RuleType.IntArray, ProcessorType = typeof(StoreRule), SelectList = new LocalRuleValueSelectList(stores) { Multiple = true } }, new CartRuleDescriptor { Name = "IPCountry", DisplayName = T("Admin.Rules.FilterDescriptor.IPCountry"), RuleType = RuleType.StringArray, ProcessorType = typeof(IPCountryRule), SelectList = new RemoteRuleValueSelectList("Country") { Multiple = true } }, new CartRuleDescriptor { Name = "Weekday", DisplayName = T("Admin.Rules.FilterDescriptor.Weekday"), RuleType = RuleType.IntArray, ProcessorType = typeof(WeekdayRule), SelectList = new LocalRuleValueSelectList(WeekdayRule.GetDefaultValues(language)) { Multiple = true } }, new CartRuleDescriptor { Name = "CustomerRole", DisplayName = T("Admin.Rules.FilterDescriptor.IsInCustomerRole"), RuleType = RuleType.IntArray, ProcessorType = typeof(CustomerRoleRule), SelectList = new RemoteRuleValueSelectList("CustomerRole") { Multiple = true }, IsComparingSequences = true }, new CartRuleDescriptor { Name = "CartBillingCountry", DisplayName = T("Admin.Rules.FilterDescriptor.BillingCountry"), RuleType = RuleType.IntArray, ProcessorType = typeof(BillingCountryRule), SelectList = new RemoteRuleValueSelectList("Country") { Multiple = true } }, new CartRuleDescriptor { Name = "CartShippingCountry", DisplayName = T("Admin.Rules.FilterDescriptor.ShippingCountry"), RuleType = RuleType.IntArray, ProcessorType = typeof(ShippingCountryRule), SelectList = new RemoteRuleValueSelectList("Country") { Multiple = true } }, new CartRuleDescriptor { Name = "CartShippingMethod", DisplayName = T("Admin.Rules.FilterDescriptor.ShippingMethod"), RuleType = RuleType.IntArray, ProcessorType = typeof(ShippingMethodRule), SelectList = new RemoteRuleValueSelectList("ShippingMethod") { Multiple = true } }, new CartRuleDescriptor { Name = "CartPaymentMethod", DisplayName = T("Admin.Rules.FilterDescriptor.PaymentMethod"), RuleType = RuleType.StringArray, ProcessorType = typeof(PaymentMethodRule), SelectList = new RemoteRuleValueSelectList("PaymentMethod") { Multiple = true } }, new CartRuleDescriptor { Name = "CartTotal", DisplayName = T("Admin.Rules.FilterDescriptor.CartTotal"), RuleType = RuleType.Money, ProcessorType = typeof(CartTotalRule) }, new CartRuleDescriptor { Name = "CartSubtotal", DisplayName = T("Admin.Rules.FilterDescriptor.CartSubtotal"), RuleType = RuleType.Money, ProcessorType = typeof(CartSubtotalRule) }, new CartRuleDescriptor { Name = "CartProductCount", DisplayName = T("Admin.Rules.FilterDescriptor.CartProductCount"), RuleType = RuleType.Int, ProcessorType = typeof(CartProductCountRule) }, cartItemQuantity, new CartRuleDescriptor { Name = "ProductInCart", DisplayName = T("Admin.Rules.FilterDescriptor.ProductInCart"), RuleType = RuleType.IntArray, ProcessorType = typeof(ProductInCartRule), SelectList = new RemoteRuleValueSelectList("Product") { Multiple = true }, IsComparingSequences = true }, new CartRuleDescriptor { Name = "ProductFromCategoryInCart", DisplayName = T("Admin.Rules.FilterDescriptor.ProductFromCategoryInCart"), RuleType = RuleType.IntArray, ProcessorType = typeof(ProductFromCategoryInCartRule), SelectList = new RemoteRuleValueSelectList("Category") { Multiple = true }, IsComparingSequences = true }, new CartRuleDescriptor { Name = "ProductFromManufacturerInCart", DisplayName = T("Admin.Rules.FilterDescriptor.ProductFromManufacturerInCart"), RuleType = RuleType.IntArray, ProcessorType = typeof(ProductFromManufacturerInCartRule), SelectList = new RemoteRuleValueSelectList("Manufacturer") { Multiple = true }, IsComparingSequences = true }, new CartRuleDescriptor { Name = "ProductInWishlist", DisplayName = T("Admin.Rules.FilterDescriptor.ProductOnWishlist"), RuleType = RuleType.IntArray, ProcessorType = typeof(ProductOnWishlistRule), SelectList = new RemoteRuleValueSelectList("Product") { Multiple = true }, IsComparingSequences = true }, new CartRuleDescriptor { Name = "ProductReviewCount", DisplayName = T("Admin.Rules.FilterDescriptor.ProductReviewCount"), RuleType = RuleType.Int, ProcessorType = typeof(ProductReviewCountRule) }, new CartRuleDescriptor { Name = "RewardPointsBalance", DisplayName = T("Admin.Rules.FilterDescriptor.RewardPointsBalance"), RuleType = RuleType.Int, ProcessorType = typeof(RewardPointsBalanceRule) }, new CartRuleDescriptor { Name = "RuleSet", DisplayName = T("Admin.Rules.FilterDescriptor.RuleSet"), RuleType = RuleType.Int, ProcessorType = typeof(RuleSetRule), Operators = new[] { RuleOperator.IsEqualTo, RuleOperator.IsNotEqualTo }, SelectList = new RemoteRuleValueSelectList("CartRule"), }, new CartRuleDescriptor { Name = "CartOrderCount", DisplayName = T("Admin.Rules.FilterDescriptor.OrderCount"), GroupKey = "Admin.Orders", RuleType = RuleType.Int, ProcessorType = typeof(OrderCountRule) }, new CartRuleDescriptor { Name = "CartSpentAmount", DisplayName = T("Admin.Rules.FilterDescriptor.SpentAmount"), GroupKey = "Admin.Orders", RuleType = RuleType.Money, ProcessorType = typeof(SpentAmountRule) }, new CartRuleDescriptor { Name = "CartPaidBy", DisplayName = T("Admin.Rules.FilterDescriptor.PaidBy"), GroupKey = "Admin.Orders", RuleType = RuleType.StringArray, ProcessorType = typeof(PaidByRule), SelectList = new RemoteRuleValueSelectList("PaymentMethod") { Multiple = true }, IsComparingSequences = true }, new CartRuleDescriptor { Name = "CartPurchasedProduct", DisplayName = T("Admin.Rules.FilterDescriptor.PurchasedProduct"), GroupKey = "Admin.Orders", RuleType = RuleType.IntArray, ProcessorType = typeof(PurchasedProductRule), SelectList = new RemoteRuleValueSelectList("Product") { Multiple = true }, IsComparingSequences = true }, new CartRuleDescriptor { Name = "CartPurchasedFromManufacturer", DisplayName = T("Admin.Rules.FilterDescriptor.PurchasedFromManufacturer"), GroupKey = "Admin.Orders", RuleType = RuleType.IntArray, ProcessorType = typeof(PurchasedFromManufacturerRule), SelectList = new RemoteRuleValueSelectList("Manufacturer") { Multiple = true }, IsComparingSequences = true }, new CartRuleDescriptor { Name = "UserAgent.IsMobile", DisplayName = T("Admin.Rules.FilterDescriptor.MobileDevice"), GroupKey = "Admin.Rules.FilterDescriptor.Group.BrowserUserAgent", RuleType = RuleType.Boolean, ProcessorType = typeof(IsMobileRule) }, new CartRuleDescriptor { Name = "UserAgent.Device", DisplayName = T("Admin.Rules.FilterDescriptor.DeviceFamily"), GroupKey = "Admin.Rules.FilterDescriptor.Group.BrowserUserAgent", RuleType = RuleType.StringArray, ProcessorType = typeof(DeviceRule), SelectList = new LocalRuleValueSelectList(DeviceRule.GetDefaultValues()) { Multiple = true, Tags = true } }, new CartRuleDescriptor { Name = "UserAgent.OS", DisplayName = T("Admin.Rules.FilterDescriptor.OperatingSystem"), GroupKey = "Admin.Rules.FilterDescriptor.Group.BrowserUserAgent", RuleType = RuleType.StringArray, ProcessorType = typeof(OSRule), SelectList = new LocalRuleValueSelectList(OSRule.GetDefaultValues()) { Multiple = true, Tags = true } }, new CartRuleDescriptor { Name = "UserAgent.Browser", DisplayName = T("Admin.Rules.FilterDescriptor.BrowserName"), GroupKey = "Admin.Rules.FilterDescriptor.Group.BrowserUserAgent", RuleType = RuleType.StringArray, ProcessorType = typeof(BrowserRule), SelectList = new LocalRuleValueSelectList(BrowserRule.GetDefaultValues()) { Multiple = true, Tags = true } }, new CartRuleDescriptor { Name = "UserAgent.BrowserMajorVersion", DisplayName = T("Admin.Rules.FilterDescriptor.BrowserMajorVersion"), GroupKey = "Admin.Rules.FilterDescriptor.Group.BrowserUserAgent", RuleType = RuleType.Int, ProcessorType = typeof(BrowserMajorVersionRule) }, new CartRuleDescriptor { Name = "UserAgent.BrowserMinorVersion", DisplayName = T("Admin.Rules.FilterDescriptor.BrowserMinorVersion"), GroupKey = "Admin.Rules.FilterDescriptor.Group.BrowserUserAgent", RuleType = RuleType.Int, ProcessorType = typeof(BrowserMinorVersionRule) }, }; descriptors .Where(x => x.RuleType == RuleType.Money) .Each(x => x.Metadata["postfix"] = currencyCode); return(descriptors); }