public void LoadRules()
        {
            var criteria = new ServerRuleSelectCriteria();

            // only query for device in this partition
            criteria.ServerPartitionKey.EqualTo(ServerPartition.GetKey());

            if (!String.IsNullOrEmpty(RuleApplyTimeDropDownList.Text))
            {
                if (!RuleApplyTimeDropDownList.SelectedValue.Equals("ALL"))
                {
                    ServerRuleApplyTimeEnum en =
                        ServerRuleApplyTimeEnum.GetEnum(RuleApplyTimeDropDownList.SelectedItem.Value);
                    criteria.ServerRuleApplyTimeEnum.EqualTo(en);
                }
            }
            if (!String.IsNullOrEmpty(RuleTypeDropDownList.Text))
            {
                if (!RuleTypeDropDownList.SelectedValue.Equals("ALL"))
                {
                    ServerRuleTypeEnum en = ServerRuleTypeEnum.GetEnum(RuleTypeDropDownList.SelectedItem.Value);
                    criteria.ServerRuleTypeEnum.EqualTo(en);
                }
                else
                {
                    criteria.ServerRuleTypeEnum.NotEqualTo(ServerRuleTypeEnum.DataAccess);
                }
            }
            else
            {
                criteria.ServerRuleTypeEnum.NotEqualTo(ServerRuleTypeEnum.DataAccess);
            }

            if (StatusFilter.SelectedIndex != 0)
            {
                criteria.Enabled.EqualTo(StatusFilter.SelectedIndex == 1);
            }

            if (DefaultFilter.SelectedIndex != 0)
            {
                criteria.DefaultRule.EqualTo(DefaultFilter.SelectedIndex == 1);
            }

            ServerRuleGridViewControl.ServerRules = _controller.GetServerRules(criteria);
            ServerRuleGridViewControl.DataBind();
        }
        private void SaveData()
        {
            if (_rule == null)
            {
                _rule = new ServerRule();
            }


            if (RuleXmlTextBox.Text.Length > 0)
            {
                _rule.RuleXml = new XmlDocument();
                _rule.RuleXml.Load(new StringReader(RuleXmlTextBox.Text));
            }

            _rule.RuleName = RuleNameTextBox.Text;

            _rule.ServerRuleTypeEnum = ServerRuleTypeEnum.GetEnum(RuleTypeDropDownList.SelectedItem.Value);

            var ep = new SampleRuleExtensionPoint();

            object[] extensions = ep.CreateExtensions();

            Dictionary <ServerRuleTypeEnum, IList <ServerRuleApplyTimeEnum> > ruleTypeList = LoadRuleTypes(extensions);

            if (ruleTypeList.ContainsKey(_rule.ServerRuleTypeEnum))
            {
                string val = Request[RuleApplyTimeDropDownList.UniqueID];
                foreach (ServerRuleApplyTimeEnum applyTime in ruleTypeList[_rule.ServerRuleTypeEnum])
                {
                    _rule.ServerRuleApplyTimeEnum = applyTime;
                    if (val.Equals(applyTime.Lookup))
                    {
                        _rule.ServerRuleApplyTimeEnum = applyTime;
                        break;
                    }
                }
            }

            _rule.Enabled            = EnabledCheckBox.Checked;
            _rule.DefaultRule        = DefaultCheckBox.Checked;
            _rule.ServerPartitionKey = Partition.GetKey();
            _rule.ExemptRule         = ExemptRuleCheckBox.Checked;
        }
Пример #3
0
        protected override bool OnServerSideEvaluate()
        {
            String ruleXml = GetControlValidationValue(ControlToValidate);

            if (String.IsNullOrEmpty(ruleXml))
            {
                ErrorMessage = ValidationErrors.ServerRuleXMLIsMissing;
                return(false);
            }

            if (RuleTypeControl.Equals(ServerRuleTypeEnum.DataAccess.Lookup))
            {
                // Validated DataAccess rules only have the condition.  Make a fake
                // rule that includes a non-op action
                ruleXml = String.Format("<rule>{0}<action><no-op/></action></rule>", ruleXml);
            }

            var theDoc = new XmlDocument();

            try
            {
                theDoc.LoadXml(ruleXml);
            }
            catch (Exception e)
            {
                ErrorMessage = String.Format(ValidationErrors.UnableToParseServerRuleXML, e.Message);
                return(false);
            }

            string error;

            if (false == Rule <ServerActionContext> .ValidateRule(
                    theDoc,
                    ServerRulesEngine.GetSpecificationCompiler(),
                    ServerRulesEngine.GetActionCompiler(ServerRuleTypeEnum.GetEnum(RuleTypeControl)),
                    out error))
            {
                ErrorMessage = error;
                return(false);
            }

            return(true);
        }
Пример #4
0
        public ValidationResult ValidateServerRule(string serverRule, string ruleType)
        {
            ValidationResult result = new ValidationResult();

            if (String.IsNullOrEmpty(serverRule))
            {
                result.ErrorText = ValidationErrors.ServerRuleXMLIsMissing;
                result.Success   = false;
                result.ErrorCode = -5000;
                return(result);
            }

            ServerRuleTypeEnum type;

            try
            {
                type = ServerRuleTypeEnum.GetEnum(ruleType);
            }
            catch (Exception e)
            {
                result.ErrorText = String.Format(ValidationErrors.UnableToParseServerRuleXML, e.Message);
                result.Success   = false;
                result.ErrorCode = -5000;
                return(result);
            }

            XmlDocument theDoc = new XmlDocument();

            try
            {
                string xml = Microsoft.JScript.GlobalObject.unescape(serverRule);

                if (type.Equals(ServerRuleTypeEnum.DataAccess))
                {
                    // Validated DataAccess rules only have the condition.  Make a fake
                    // rule that includes a non-op action
                    xml = String.Format("<rule>{0}<action><no-op/></action></rule>", xml);
                }

                theDoc.LoadXml(xml);
            }
            catch (Exception e)
            {
                result.ErrorText = String.Format(ValidationErrors.UnableToParseServerRuleXML, e.Message);
                result.Success   = false;
                result.ErrorCode = -5000;
                return(result);
            }

            string error;

            if (false == Rule <ServerActionContext, ServerRuleTypeEnum> .ValidateRule(type, theDoc, out error))
            {
                result.ErrorText = error;
                result.Success   = false;
                result.ErrorCode = -5000;
            }
            else
            {
                result.Success = true;
            }

            return(result);
        }