private static string GetJavascriptForSampleRule(ServerRuleTypeEnum typeEnum, object[] extensions)
        {
            string sampleList = string.Empty;

            foreach (ISampleRule extension in extensions)
            {
                sampleList +=
                    String.Format(
                        @"        myEle = document.createElement('option') ;
                    myEle.value = '{0}';
                    myEle.text = '{1}' ;
                    if(navigator.appName == 'Microsoft Internet Explorer') sampleList.add(myEle);
                    else sampleList.add(myEle, null);",
                        extension.Name, extension.Description);
            }

            return
                (String.Format(
                     @"if (val == '{0}')
                {{
                    myEle = document.createElement('option') ;
                    myEle.value = '';
                    myEle.text = '' ;
                    if(navigator.appName == 'Microsoft Internet Explorer') sampleList.add(myEle);
                    else sampleList.add(myEle, null);
                    {1}
                }}",
                     typeEnum.Lookup, sampleList));
        }
Пример #2
0
 /// <summary>
 /// Creates an instance of <see cref="SampleRuleBase"/>
 /// </summary>
 /// <param name="name">Name of the sample rule</param>
 /// <param name="description">Description of the sample rule</param>
 /// <param name="type">Type of the sample rule</param>
 /// <param name="embeddedXmlName">Name of the resource file containing the sample rule xml</param>
 public SampleRuleBase(string name, string description, ServerRuleTypeEnum type, string embeddedXmlName)
 {
     _name            = name;
     _description     = description;
     _type            = type;
     _embeddedXmlName = embeddedXmlName;
 }
        private static string GetJavascriptForSampleRule(ServerRuleTypeEnum typeEnum, object[] extensions)
        {
            string sampleList = string.Empty;

            foreach (ISampleRule extension in extensions)
            {
                if (extension.Type.Equals(typeEnum))
                {
                    sampleList +=
                        String.Format(
                            @"        myEle = document.createElement('option') ;
                    myEle.value = '{0}';
                    myEle.text = '{1}' ;
                    if(navigator.appName == 'Microsoft Internet Explorer') sampleList.add(myEle);
                    else sampleList.add(myEle, null);",
                            extension.Name, extension.Description);
                }
            }
            string enumList = string.Empty;

            foreach (ISampleRule extension in extensions)
            {
                if (extension.Type.Equals(typeEnum))
                {
                    foreach (ServerRuleApplyTimeEnum applyTimeEnum in extension.ApplyTimeList)
                    {
                        enumList +=
                            String.Format(
                                @"myEle = document.createElement('option') ;
                    myEle.value = '{0}';
                    myEle.text = '{1}';
                    if(navigator.appName == 'Microsoft Internet Explorer') applyTimeList.add(myEle);
                    else applyTimeList.add(myEle, null);",
                                applyTimeEnum.Lookup, ServerEnumDescription.GetLocalizedDescription(applyTimeEnum));
                    }
                    break;
                }
            }

            return
                (String.Format(
                     @"if (val == '{0}')
                {{
					{1}
                    myEle = document.createElement('option') ;
                    myEle.value = '';
                    myEle.text = '' ;
                    if(navigator.appName == 'Microsoft Internet Explorer') sampleList.add(myEle);
                    else sampleList.add(myEle, null);
                    {2}
                }}",
                     typeEnum.Lookup, enumList, sampleList));
        }
        public void Insert(Guid Guid, short EnumX, string Lookup, string Description, string LongDescription)
        {
            var item = new ServerRuleTypeEnum();

            item.Guid = Guid;

            item.EnumX = EnumX;

            item.Lookup = Lookup;

            item.Description = Description;

            item.LongDescription = LongDescription;


            item.Save(UserName);
        }
        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;
        }
Пример #7
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);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            ServerRuleGridViewControl.ServerRulePanel = this;

            // setup child controls
            GridPagerTop.InitializeGridPager(SR.GridPagerServerRulesSingleItem,
                                             SR.GridPagerServerRulesMultipleItems,
                                             ServerRuleGridViewControl.TheGrid,
                                             () => ServerRuleGridViewControl.ServerRules == null
                                                       ? 0
                                                       : ServerRuleGridViewControl.ServerRules.Count,
                                             ImageServerConstants.GridViewPagerPosition.Top);
            ServerRuleGridViewControl.Pager = GridPagerTop;
            GridPagerTop.Reset();


            int prevSelectIndex = RuleApplyTimeDropDownList.SelectedIndex;

            RuleApplyTimeDropDownList.Items.Clear();
            RuleApplyTimeDropDownList.Items.Add(new ListItem(SR.All, "ALL"));
            foreach (ServerRuleApplyTimeEnum applyTimeEnum in ServerRuleApplyTimeEnum.GetAll())
            {
                RuleApplyTimeDropDownList.Items.Add(
                    new ListItem(ServerEnumDescription.GetLocalizedDescription(applyTimeEnum), applyTimeEnum.Lookup));
            }
            RuleApplyTimeDropDownList.SelectedIndex = prevSelectIndex;


            prevSelectIndex = RuleTypeDropDownList.SelectedIndex;
            RuleTypeDropDownList.Items.Clear();
            RuleTypeDropDownList.Items.Add(new ListItem(SR.All, "ALL"));
            foreach (ServerRuleTypeEnum typeEnum in ServerRuleTypeEnum.GetAll())
            {
                RuleTypeDropDownList.Items.Add(new ListItem(ServerEnumDescription.GetLocalizedDescription(typeEnum), typeEnum.Lookup));
            }
            RuleTypeDropDownList.SelectedIndex = prevSelectIndex;

            if (Page.IsPostBack)
            {
                DataBind();
            }
        }
        public void Update(Guid Guid, short EnumX, string Lookup, string Description, string LongDescription)
        {
            var item = new ServerRuleTypeEnum();
            item.MarkOld();
            item.IsLoaded = true;

            item.Guid = Guid;

            item.EnumX = EnumX;

            item.Lookup = Lookup;

            item.Description = Description;

            item.LongDescription = LongDescription;

            item.Save(UserName);
        }
Пример #10
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);
        }