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;
        }
Esempio n. 2
0
        public string GetXml(string type)
        {
            try
            {
                XmlDocument doc = null;

                string inputString = Server.HtmlEncode(type);
                if (String.IsNullOrEmpty(inputString))
                {
                    inputString = string.Empty;
                }

                var      ep         = new SampleRuleExtensionPoint();
                object[] extensions = ep.CreateExtensions();

                foreach (ISampleRule extension in extensions)
                {
                    if (extension.Name.Equals(inputString))
                    {
                        doc = extension.Rule;
                        break;
                    }
                }

                if (doc == null)
                {
                    doc = new XmlDocument();
                    XmlNode node = doc.CreateElement("rule");
                    doc.AppendChild(node);
                    XmlElement conditionNode = doc.CreateElement("condition");
                    node.AppendChild(conditionNode);
                    conditionNode.SetAttribute("expressionLanguage", "dicom");
                    XmlNode actionNode = doc.CreateElement("action");
                    node.AppendChild(actionNode);
                }

                var sw = new StringWriter();

                var xmlSettings = new XmlWriterSettings
                {
                    Encoding            = Encoding.UTF8,
                    ConformanceLevel    = ConformanceLevel.Fragment,
                    Indent              = true,
                    NewLineOnAttributes = false,
                    CheckCharacters     = true,
                    IndentChars         = "  "
                };

                XmlWriter tw = XmlWriter.Create(sw, xmlSettings);

                if (tw != null)
                {
                    doc.WriteTo(tw);
                    tw.Close();
                }

                return(sw.ToString());
            }
            catch (Exception e)
            {
                Platform.Log(LogLevel.Error, e, "Unexpected exception processing server rule of type: {0}", type);
                throw;
            }
        }
        /// <summary>
        /// Displays the add/edit device dialog box.
        /// </summary>
        public void Show()
        {
            //If the validation failed, keep everything as is, and
            //make sure the dialog stays visible.
            if (!Page.IsValid)
            {
                ModalDialog.Show();
                return;
            }

            if (_partition != null)
            {
                AuthorityGroupCheckBoxList.Items.Clear();

                var adapter = new ServerPartitionDataAdapter();
                IList <AuthorityGroupDetail> accessAllStudiesList;
                IList <AuthorityGroupDetail> groups = adapter.GetAuthorityGroupsForPartition(_partition.Key, true, out accessAllStudiesList);

                IList <ListItem> items = CollectionUtils.Map(
                    groups,
                    delegate(AuthorityGroupDetail group)
                {
                    var item = new ListItem(@group.Name,
                                            @group.AuthorityGroupRef.ToString(false, false));
                    item.Attributes["title"] = @group.Description;
                    return(item);
                });

                AuthorityGroupCheckBoxList.Items.AddRange(CollectionUtils.ToArray(items));
            }

            var ep = new SampleRuleExtensionPoint();

            object[] extensions = ep.CreateExtensions();

            if (Mode == AddEditDataRuleDialogMode.Edit)
            {
                ModalDialog.Title    = SR.DialogEditDataRuleTitle;
                OKButton.Visible     = false;
                UpdateButton.Visible = true;

                DefaultCheckBox.Checked    = _rule.DefaultRule;
                EnabledCheckBox.Checked    = _rule.Enabled;
                ExemptRuleCheckBox.Checked = _rule.ExemptRule;


                RuleNameTextBox.Text = _rule.RuleName;

                SampleRuleDropDownList.Visible = false;
                SelectSampleRuleLabel.Visible  = false;


                // Fill in the Rule XML
                var sw = new StringWriter();

                var xmlSettings = new XmlWriterSettings
                {
                    Encoding            = Encoding.UTF8,
                    ConformanceLevel    = ConformanceLevel.Fragment,
                    Indent              = true,
                    NewLineOnAttributes = false,
                    CheckCharacters     = true,
                    IndentChars         = "  "
                };

                XmlWriter tw = XmlWriter.Create(sw, xmlSettings);

                XmlNode node2 = _rule.RuleXml.SelectSingleNode("/rule/condition");

                node2.WriteTo(tw);

                tw.Close();

                RuleXmlTextBox.Text = sw.ToString();

                DataRuleValidator.RuleTypeControl = ServerRuleTypeEnum.DataAccess.Lookup;

                AuthorityGroupCheckBoxList.ClearSelection();

                foreach (XmlNode node in _rule.RuleXml.SelectNodes("/rule/action/grant-access"))
                {
                    string   oid  = node.Attributes["authorityGroupOid"].Value;
                    ListItem item = AuthorityGroupCheckBoxList.Items.FindByValue(oid);
                    if (item != null)
                    {
                        item.Selected = true;
                    }
                }
            }
            else if (Mode == AddEditDataRuleDialogMode.New)
            {
                ModalDialog.Title    = SR.DialogAddDataRuleTitle;
                OKButton.Visible     = true;
                UpdateButton.Visible = false;

                DefaultCheckBox.Checked    = false;
                EnabledCheckBox.Checked    = true;
                ExemptRuleCheckBox.Checked = false;

                RuleNameTextBox.Text = string.Empty;
                RuleXmlTextBox.Text  = string.Empty;

                SampleRuleDropDownList.Visible = true;
                SelectSampleRuleLabel.Visible  = true;

                // Do the drop down lists
                SampleRuleDropDownList.Items.Clear();
                SampleRuleDropDownList.Items.Add(new ListItem(string.Empty, string.Empty));
                foreach (ISampleRule extension in extensions)
                {
                    if (extension.Type.Equals(ServerRuleTypeEnum.DataAccess))
                    {
                        SampleRuleDropDownList.Items.Add(new ListItem(extension.Description, extension.Name));
                    }
                }

                DataRuleValidator.RuleTypeControl = ServerRuleTypeEnum.DataAccess.Lookup;
            }
            else
            {
                ModalDialog.Title    = SR.DialogAddDataRuleTitle;
                OKButton.Visible     = true;
                UpdateButton.Visible = false;

                DefaultCheckBox.Checked    = _rule.DefaultRule;
                EnabledCheckBox.Checked    = _rule.Enabled;
                ExemptRuleCheckBox.Checked = _rule.ExemptRule;


                RuleNameTextBox.Text = _rule.RuleName;

                SampleRuleDropDownList.Visible = false;
                SelectSampleRuleLabel.Visible  = false;


                // Fill in the Rule XML
                var sw = new StringWriter();

                var xmlSettings = new XmlWriterSettings
                {
                    Encoding            = Encoding.UTF8,
                    ConformanceLevel    = ConformanceLevel.Fragment,
                    Indent              = true,
                    NewLineOnAttributes = false,
                    CheckCharacters     = true,
                    IndentChars         = "  "
                };

                XmlWriter tw = XmlWriter.Create(sw, xmlSettings);

                XmlNode node2 = _rule.RuleXml.SelectSingleNode("/rule/condition");

                node2.WriteTo(tw);

                tw.Close();

                RuleXmlTextBox.Text = sw.ToString();

                DataRuleValidator.RuleTypeControl = ServerRuleTypeEnum.DataAccess.Lookup;

                AuthorityGroupCheckBoxList.ClearSelection();

                foreach (XmlNode node in _rule.RuleXml.SelectNodes("/rule/action/grant-access"))
                {
                    string   oid  = node.Attributes["authorityGroupOid"].Value;
                    ListItem item = AuthorityGroupCheckBoxList.Items.FindByValue(oid);
                    if (item != null)
                    {
                        item.Selected = true;
                    }
                }
            }

            ModalDialog.Show();
            return;
        }
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            var ep         = new SampleRuleExtensionPoint();
            var extensions = ep.CreateExtensions();

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


            SampleRuleDropDownList.Attributes.Add("onchange", "webServiceScript(this, this.SelectedIndex);");

            string javascript =
                @"<script type='text/javascript'>
            function ValidationServerRuleParams()
            {
                control = document.getElementById('" +
                RuleXmlTextBox.ClientID +
                @"');
                params = new Array();
                params.serverRule=escape(CodeMirrorEditor.getCode());
				params.ruleType = '"                 + ServerRuleTypeEnum.DataAccess.Lookup + @"';
                return params;
            }

            function selectRuleType(oList, selectedIndex)
            {                         
                var val = oList.value; 
                var sampleList = document.getElementById('" +
                SampleRuleDropDownList.ClientID +
                @"');
                
                for (var q=sampleList.options.length; q>=0; q--) sampleList.options[q]=null;
				"                ;

            javascript += GetJavascriptForSampleRule(ServerRuleTypeEnum.DataAccess, extensions);

            javascript +=
                @"}

            // This function calls the Web Service method.  
            function webServiceScript(oList)
            {
                var type = oList.value;
             
                Macro.ImageServer.Web.Application.Pages.Admin.Configure.DataRules.DataRuleSamples.GetXml(type,
                    OnSucess, OnError);
            }
            function OnError(result)
            {
                alert('Error: ' + result.get_message());
            }

            // This is the callback function that
            // processes the Web Service return value.
            function OnSucess(result)
            {
                var oList = document.getElementById('" +
                SampleRuleDropDownList.ClientID +
                @"');
                var sValue = oList.options[oList.selectedIndex].value;
             
                RsltElem = document.getElementById('" +
                RuleXmlTextBox.ClientID +
                @"');

                //Set the value on the TextArea and then set the value in the Editor.
                //CodeMirror doesn't monitor changes to the textarea.
                RsltElem.value = result;
                CodeMirrorEditor.setCode(RsltElem.value);
            }
           
            function pageLoad(){
                $find('" +
                ModalDialog.PopupExtenderID +
                @"').add_shown(HighlightXML);
            }

            function HighlightXML() {
                CodeMirrorEditor = CodeMirror.fromTextArea('" +
                RuleXmlTextBox.ClientID +
                @"', {parserfile: 'parsexml.js',path: '../../../../Scripts/CodeMirror/js/', stylesheet: '../../../../Scripts/CodeMirror/css/xmlcolors.css'});
            }

	        function UpdateRuleXML() {
                RsltElem = document.getElementById('" +
                RuleXmlTextBox.ClientID +
                @"');	            

                RsltElem.value = CodeMirrorEditor.getCode();    
	        }
  
            var CodeMirrorEditor = null;
            </script>";

            Page.ClientScript.RegisterClientScriptBlock(GetType(), ClientID, javascript);

            Page.ClientScript.RegisterClientScriptInclude(GetType(), "CodeMirrorLibrary",
                                                          "../../../../Scripts/CodeMirror/js/codemirror.js");

            EditDataRuleValidationSummary.HeaderText = ErrorMessages.EditServerRuleValidationError;
        }
Esempio n. 5
0
        public string GetXml(string type)
        {
            try
            {
                XmlDocument doc = null;

                string inputString = Server.HtmlEncode(type);
                if (String.IsNullOrEmpty(inputString))
                    inputString = string.Empty;

                var ep = new SampleRuleExtensionPoint();
                object[] extensions = ep.CreateExtensions();

                foreach (ISampleRule extension in extensions)
                {
                    if (extension.Name.Equals(inputString))
                    {
                        doc = extension.Rule;
                        break;
                    }
                }

                if (doc == null)
                {
                    doc = new XmlDocument();
                    XmlNode node = doc.CreateElement("rule");
                    doc.AppendChild(node);
                    XmlElement conditionNode = doc.CreateElement("condition");
                    node.AppendChild(conditionNode);
                    conditionNode.SetAttribute("expressionLanguage", "dicom");
                    XmlNode actionNode = doc.CreateElement("action");
                    node.AppendChild(actionNode);
                }

                var sw = new StringWriter();

                var xmlSettings = new XmlWriterSettings
                                      {
                                          Encoding = Encoding.UTF8,
                                          ConformanceLevel = ConformanceLevel.Fragment,
                                          Indent = true,
                                          NewLineOnAttributes = false,
                                          CheckCharacters = true,
                                          IndentChars = "  "
                                      };

                XmlWriter tw = XmlWriter.Create(sw, xmlSettings);

                if (tw != null)
                {
                    doc.WriteTo(tw);
                    tw.Close();
                }

                return sw.ToString();
            }
            catch (Exception e)
            {
                Platform.Log(LogLevel.Error, e, "Unexpected exception processing server rule of type: {0}", type);
                throw;
            }
        }
        /// <summary>
        /// Displays the add/edit device dialog box.
        /// </summary>
        public void Show()
        {
            //If the validation failed, keep everything as is, and 
            //make sure the dialog stays visible.
            if (!Page.IsValid)
            {
                RuleXmlTabPanel.TabIndex = 0;
                ModalDialog.Show();
                return;
            }

            // update the dropdown list
            RuleApplyTimeDropDownList.Items.Clear();
            RuleTypeDropDownList.Items.Clear();
            RuleXmlTabPanel.TabIndex = 0;
            ServerPartitionTabContainer.ActiveTabIndex = 0;

            var ep = new SampleRuleExtensionPoint();
            object[] extensions = ep.CreateExtensions();

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

            if (EditMode)
            {
                ModalDialog.Title = SR.DialogEditServerRuleTitle;
                OKButton.Visible = false;
                UpdateButton.Visible = true;

                DefaultCheckBox.Checked = _rule.DefaultRule;
                EnabledCheckBox.Checked = _rule.Enabled;
                ExemptRuleCheckBox.Checked = _rule.ExemptRule;

                //if (_rule.DefaultRule)
                //	DefaultCheckBox.Enabled = false;

                RuleNameTextBox.Text = _rule.RuleName;

                SampleRuleDropDownList.Visible = false;
                SelectSampleRuleLabel.Visible = false;

                // Fill in the drop down menus
                RuleTypeDropDownList.Items.Add(new ListItem(
                                                   ServerEnumDescription.GetLocalizedDescription(_rule.ServerRuleTypeEnum),
                                                   _rule.ServerRuleTypeEnum.Lookup));

                IList<ServerRuleApplyTimeEnum> list = new List<ServerRuleApplyTimeEnum>();


                if (ruleTypeList.ContainsKey(_rule.ServerRuleTypeEnum))
                    list = ruleTypeList[_rule.ServerRuleTypeEnum];

                foreach (ServerRuleApplyTimeEnum applyTime in list)
                    RuleApplyTimeDropDownList.Items.Add(new ListItem(
                                                            ServerEnumDescription.GetLocalizedDescription(applyTime),
                                                            applyTime.Lookup));


                if (RuleApplyTimeDropDownList.Items.FindByValue(_rule.ServerRuleApplyTimeEnum.Lookup) != null)
                    RuleApplyTimeDropDownList.SelectedValue = _rule.ServerRuleApplyTimeEnum.Lookup;

                RuleTypeDropDownList.SelectedValue = _rule.ServerRuleTypeEnum.Lookup;


                // Fill in the Rule XML
                var sw = new StringWriter();

                var xmlSettings = new XmlWriterSettings();

                xmlSettings.Encoding = Encoding.UTF8;
                xmlSettings.ConformanceLevel = ConformanceLevel.Fragment;
                xmlSettings.Indent = true;
                xmlSettings.NewLineOnAttributes = false;
                xmlSettings.CheckCharacters = true;
                xmlSettings.IndentChars = "  ";

                XmlWriter tw = XmlWriter.Create(sw, xmlSettings);

                _rule.RuleXml.WriteTo(tw);

                tw.Close();

                RuleXmlTextBox.Text = sw.ToString();

                ServerRuleValidator.RuleTypeControl = RuleTypeDropDownList.SelectedValue;
            }
            else
            {
                ModalDialog.Title = SR.DialogAddServerRuleTitle;
                OKButton.Visible = false;
                UpdateButton.Visible = true;

                DefaultCheckBox.Checked = false;
                EnabledCheckBox.Checked = true;
                ExemptRuleCheckBox.Checked = false;

                RuleNameTextBox.Text = string.Empty;
                RuleXmlTextBox.Text = string.Empty;

                SampleRuleDropDownList.Visible = true;
                SelectSampleRuleLabel.Visible = true;

                // Do the drop down lists
                bool first = true;
                var list = new List<ServerRuleTypeEnum>();
                list.AddRange(ruleTypeList.Keys);

                // Sort the list by description
                list.Sort(
                    new Comparison<ServerRuleTypeEnum>(
                        delegate(ServerRuleTypeEnum type1, ServerRuleTypeEnum type2) { return type1.Description.CompareTo(type2.Description); }));

                foreach (ServerRuleTypeEnum type in list)
                {
                    if (first)
                    {
                        first = false;
                        SampleRuleDropDownList.Items.Clear();
                        SampleRuleDropDownList.Items.Add(new ListItem(string.Empty, string.Empty));

                        foreach (ISampleRule extension in extensions)
                        {
                            if (extension.Type.Equals(type))
                            {
                                SampleRuleDropDownList.Items.Add(new ListItem(extension.Description, extension.Name));
                            }
                        }

                        foreach (ServerRuleApplyTimeEnum applyTime in ruleTypeList[type])
                            RuleApplyTimeDropDownList.Items.Add(new ListItem(
                                                                    ServerEnumDescription.GetLocalizedDescription(applyTime),
                                                                    applyTime.Lookup));
                    }

                    RuleTypeDropDownList.Items.Add(new ListItem(
                                                       ServerEnumDescription.GetLocalizedDescription(type), type.Lookup));
                }

                ServerRuleValidator.RuleTypeControl = RuleTypeDropDownList.SelectedValue;
            }

            ModalDialog.Show();
            return;
        }
        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;
        }
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            var ep = new SampleRuleExtensionPoint();
            object[] extensions = ep.CreateExtensions();

            ServerPartitionTabContainer.ActiveTabIndex = 0;

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


            SampleRuleDropDownList.Attributes.Add("onchange", "webServiceScript(this, this.SelectedIndex);");
            RuleTypeDropDownList.Attributes.Add("onchange", "selectRuleType(this);");

            RuleTypeDropDownList.TextChanged += delegate
                                                    {
                                                        ServerRuleValidator.RuleTypeControl = RuleTypeDropDownList.SelectedValue;
                                                    };

            string javascript =
                @"<script type='text/javascript'>
            function ValidationServerRuleParams()
            {
                control = document.getElementById('" +RuleXmlTextBox.ClientID +@"');
                params = new Array();
                params.serverRule=escape(CodeMirrorEditor.getCode());
				var oList = document.getElementById('" +RuleTypeDropDownList.ClientID +@"');
				params.ruleType = oList.options[oList.selectedIndex].value;
                return params;
            }

            function selectRuleType(oList, selectedIndex)
            {                         
                var val = oList.value; 
                var sampleList = document.getElementById('" +SampleRuleDropDownList.ClientID +@"');
                var applyTimeList = document.getElementById('" +RuleApplyTimeDropDownList.ClientID +@"');
                
                for (var q=sampleList.options.length; q>=0; q--) sampleList.options[q]=null;
                for (var q=applyTimeList.options.length; q>=0; q--) applyTimeList.options[q]=null;
				";

            bool first = true;
            foreach (ServerRuleTypeEnum type in ruleTypeList.Keys)
            {
                if (!first)
                {
                    javascript += "else ";
                }
                else
                    first = false;

                javascript += GetJavascriptForSampleRule(type, extensions);
            }

            javascript +=
            @"}

            // This function calls the Web Service method.  
            function webServiceScript(oList)
            {
                var type = oList.value;
             
                ClearCanvas.ImageServer.Web.Application.Pages.Admin.Configure.ServerRules.ServerRuleSamples.GetXml(type,
                    OnSucess, OnError);
            }
            function OnError(result)
            {
                alert('Error: ' + result.get_message());
            }

            // This is the callback function that
            // processes the Web Service return value.
            function OnSucess(result)
            {
                var oList = document.getElementById('" +SampleRuleDropDownList.ClientID +@"');
                var sValue = oList.options[oList.selectedIndex].value;
             
                RsltElem = document.getElementById('" +RuleXmlTextBox.ClientID +@"');

                //Set the value on the TextArea and then set the value in the Editor.
                //CodeMirror doesn't monitor changes to the textarea.
                RsltElem.value = result;
                CodeMirrorEditor.setCode(RsltElem.value);
            }
           
            function pageLoad(){
                $find('" + ModalDialog.PopupExtenderID + @"').add_shown(HighlightXML);
            }

            function HighlightXML() {
                CodeMirrorEditor = CodeMirror.fromTextArea('" + RuleXmlTextBox.ClientID + @"', {parserfile: 'parsexml.js',path: '../../../../Scripts/CodeMirror/js/', stylesheet: '../../../../Scripts/CodeMirror/css/xmlcolors.css'});
            }

	        function UpdateRuleXML() {
                RsltElem = document.getElementById('" + RuleXmlTextBox.ClientID + @"');	
                RsltElem.value = CodeMirrorEditor.getCode();    
	        }
  
            var CodeMirrorEditor = null;
            </script>";

            Page.ClientScript.RegisterClientScriptBlock(GetType(), ClientID, javascript);

            Page.ClientScript.RegisterClientScriptInclude(GetType(), "CodeMirrorLibrary",
                                                          "../../../../Scripts/CodeMirror/js/codemirror.js");

            EditServerRuleValidationSummary.HeaderText = ErrorMessages.EditServerRuleValidationError;
        }
Esempio n. 9
0
        /// <summary>
        /// Displays the add/edit device dialog box.
        /// </summary>
        public void Show()
        {
            //If the validation failed, keep everything as is, and 
            //make sure the dialog stays visible.
            if (!Page.IsValid)
            {
                ModalDialog.Show();
                return;
            }

            if (_partition != null)
            {
                AuthorityGroupCheckBoxList.Items.Clear();

                var adapter = new ServerPartitionDataAdapter();
                IList<AuthorityGroupDetail> accessAllStudiesList;
                IList<AuthorityGroupDetail> groups = adapter.GetAuthorityGroupsForPartition(_partition.Key, true, out accessAllStudiesList);

                IList<ListItem> items = CollectionUtils.Map(
                    groups,
                    delegate(AuthorityGroupDetail group)
                    {
                        var item = new ListItem(@group.Name,
                                                   @group.AuthorityGroupRef.ToString(false, false));
                        item.Attributes["title"] = @group.Description;
                        return item;
                    });   

                AuthorityGroupCheckBoxList.Items.AddRange(CollectionUtils.ToArray(items));
            }

            var ep = new SampleRuleExtensionPoint();
            object[] extensions = ep.CreateExtensions();

            if (Mode == AddEditDataRuleDialogMode.Edit)
            {
                ModalDialog.Title = SR.DialogEditDataRuleTitle;
                OKButton.Visible = false;
                UpdateButton.Visible = true;

                DefaultCheckBox.Checked = _rule.DefaultRule;
                EnabledCheckBox.Checked = _rule.Enabled;
                ExemptRuleCheckBox.Checked = _rule.ExemptRule;


                RuleNameTextBox.Text = _rule.RuleName;

                SampleRuleDropDownList.Visible = false;
                SelectSampleRuleLabel.Visible = false;


                // Fill in the Rule XML
                var sw = new StringWriter();

                var xmlSettings = new XmlWriterSettings
                                      {
                                          Encoding = Encoding.UTF8,
                                          ConformanceLevel = ConformanceLevel.Fragment,
                                          Indent = true,
                                          NewLineOnAttributes = false,
                                          CheckCharacters = true,
                                          IndentChars = "  "
                                      };

                XmlWriter tw = XmlWriter.Create(sw, xmlSettings);

                XmlNode node2 = _rule.RuleXml.SelectSingleNode("/rule/condition");
                
                node2.WriteTo(tw);

                tw.Close();

                RuleXmlTextBox.Text = sw.ToString();

                DataRuleValidator.RuleTypeControl = ServerRuleTypeEnum.DataAccess.Lookup;

                AuthorityGroupCheckBoxList.ClearSelection();

                foreach (XmlNode node in _rule.RuleXml.SelectNodes("/rule/action/grant-access"))
                {
                    string oid = node.Attributes["authorityGroupOid"].Value;
                    ListItem item = AuthorityGroupCheckBoxList.Items.FindByValue(oid);
                    if (item != null) item.Selected = true;
                }
            }
            else if (Mode == AddEditDataRuleDialogMode.New)
            {
                ModalDialog.Title = SR.DialogAddDataRuleTitle;
                OKButton.Visible = true;
                UpdateButton.Visible = false;

                DefaultCheckBox.Checked = false;
                EnabledCheckBox.Checked = true;
                ExemptRuleCheckBox.Checked = false;

                RuleNameTextBox.Text = string.Empty;
                RuleXmlTextBox.Text = string.Empty;

                SampleRuleDropDownList.Visible = true;
                SelectSampleRuleLabel.Visible = true;

                // Do the drop down lists
                SampleRuleDropDownList.Items.Clear();
                SampleRuleDropDownList.Items.Add(new ListItem(string.Empty, string.Empty));
                foreach (ISampleRule extension in extensions)
                {
                    if (extension.Type.Equals(ServerRuleTypeEnum.DataAccess))
                    {
                        SampleRuleDropDownList.Items.Add(new ListItem(extension.Description, extension.Name));
                    }
                }

                DataRuleValidator.RuleTypeControl = ServerRuleTypeEnum.DataAccess.Lookup;
            }
            else
            {
                ModalDialog.Title = SR.DialogAddDataRuleTitle;
                OKButton.Visible = true;
                UpdateButton.Visible = false;

                DefaultCheckBox.Checked = _rule.DefaultRule;
                EnabledCheckBox.Checked = _rule.Enabled;
                ExemptRuleCheckBox.Checked = _rule.ExemptRule;


                RuleNameTextBox.Text = _rule.RuleName;

                SampleRuleDropDownList.Visible = false;
                SelectSampleRuleLabel.Visible = false;


                // Fill in the Rule XML
                var sw = new StringWriter();

                var xmlSettings = new XmlWriterSettings
                {
                    Encoding = Encoding.UTF8,
                    ConformanceLevel = ConformanceLevel.Fragment,
                    Indent = true,
                    NewLineOnAttributes = false,
                    CheckCharacters = true,
                    IndentChars = "  "
                };

                XmlWriter tw = XmlWriter.Create(sw, xmlSettings);

                XmlNode node2 = _rule.RuleXml.SelectSingleNode("/rule/condition");

                node2.WriteTo(tw);

                tw.Close();

                RuleXmlTextBox.Text = sw.ToString();

                DataRuleValidator.RuleTypeControl = ServerRuleTypeEnum.DataAccess.Lookup;

                AuthorityGroupCheckBoxList.ClearSelection();

                foreach (XmlNode node in _rule.RuleXml.SelectNodes("/rule/action/grant-access"))
                {
                    string oid = node.Attributes["authorityGroupOid"].Value;
                    ListItem item = AuthorityGroupCheckBoxList.Items.FindByValue(oid);
                    if (item != null) item.Selected = true;
                }
            }

            ModalDialog.Show();
            return;
        }
        /// <summary>
        /// Displays the add/edit device dialog box.
        /// </summary>
        public void Show()
        {
            //If the validation failed, keep everything as is, and
            //make sure the dialog stays visible.
            if (!Page.IsValid)
            {
                RuleXmlTabPanel.TabIndex = 0;
                ModalDialog.Show();
                return;
            }

            // update the dropdown list
            RuleApplyTimeDropDownList.Items.Clear();
            RuleTypeDropDownList.Items.Clear();
            RuleXmlTabPanel.TabIndex = 0;
            ServerPartitionTabContainer.ActiveTabIndex = 0;

            var ep = new SampleRuleExtensionPoint();

            object[] extensions = ep.CreateExtensions();

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

            if (EditMode)
            {
                ModalDialog.Title    = SR.DialogEditServerRuleTitle;
                OKButton.Visible     = false;
                UpdateButton.Visible = true;

                DefaultCheckBox.Checked    = _rule.DefaultRule;
                EnabledCheckBox.Checked    = _rule.Enabled;
                ExemptRuleCheckBox.Checked = _rule.ExemptRule;

                //if (_rule.DefaultRule)
                //	DefaultCheckBox.Enabled = false;

                RuleNameTextBox.Text = _rule.RuleName;

                SampleRuleDropDownList.Visible = false;
                SelectSampleRuleLabel.Visible  = false;

                // Fill in the drop down menus
                RuleTypeDropDownList.Items.Add(new ListItem(
                                                   ServerEnumDescription.GetLocalizedDescription(_rule.ServerRuleTypeEnum),
                                                   _rule.ServerRuleTypeEnum.Lookup));

                IList <ServerRuleApplyTimeEnum> list = new List <ServerRuleApplyTimeEnum>();


                if (ruleTypeList.ContainsKey(_rule.ServerRuleTypeEnum))
                {
                    list = ruleTypeList[_rule.ServerRuleTypeEnum];
                }

                foreach (ServerRuleApplyTimeEnum applyTime in list)
                {
                    RuleApplyTimeDropDownList.Items.Add(new ListItem(
                                                            ServerEnumDescription.GetLocalizedDescription(applyTime),
                                                            applyTime.Lookup));
                }


                if (RuleApplyTimeDropDownList.Items.FindByValue(_rule.ServerRuleApplyTimeEnum.Lookup) != null)
                {
                    RuleApplyTimeDropDownList.SelectedValue = _rule.ServerRuleApplyTimeEnum.Lookup;
                }

                RuleTypeDropDownList.SelectedValue = _rule.ServerRuleTypeEnum.Lookup;


                // Fill in the Rule XML
                var sw = new StringWriter();

                var xmlSettings = new XmlWriterSettings();

                xmlSettings.Encoding            = Encoding.UTF8;
                xmlSettings.ConformanceLevel    = ConformanceLevel.Fragment;
                xmlSettings.Indent              = true;
                xmlSettings.NewLineOnAttributes = false;
                xmlSettings.CheckCharacters     = true;
                xmlSettings.IndentChars         = "  ";

                XmlWriter tw = XmlWriter.Create(sw, xmlSettings);

                _rule.RuleXml.WriteTo(tw);

                tw.Close();

                RuleXmlTextBox.Text = sw.ToString();

                ServerRuleValidator.RuleTypeControl = RuleTypeDropDownList.SelectedValue;
            }
            else
            {
                ModalDialog.Title    = SR.DialogAddServerRuleTitle;
                OKButton.Visible     = false;
                UpdateButton.Visible = true;

                DefaultCheckBox.Checked    = false;
                EnabledCheckBox.Checked    = true;
                ExemptRuleCheckBox.Checked = false;

                RuleNameTextBox.Text = string.Empty;
                RuleXmlTextBox.Text  = string.Empty;

                SampleRuleDropDownList.Visible = true;
                SelectSampleRuleLabel.Visible  = true;

                // Do the drop down lists
                bool first = true;
                var  list  = new List <ServerRuleTypeEnum>();
                list.AddRange(ruleTypeList.Keys);

                // Sort the list by description
                list.Sort(
                    new Comparison <ServerRuleTypeEnum>(
                        delegate(ServerRuleTypeEnum type1, ServerRuleTypeEnum type2) { return(type1.Description.CompareTo(type2.Description)); }));

                foreach (ServerRuleTypeEnum type in list)
                {
                    if (first)
                    {
                        first = false;
                        SampleRuleDropDownList.Items.Clear();
                        SampleRuleDropDownList.Items.Add(new ListItem(string.Empty, string.Empty));

                        foreach (ISampleRule extension in extensions)
                        {
                            if (extension.Type.Equals(type))
                            {
                                SampleRuleDropDownList.Items.Add(new ListItem(extension.Description, extension.Name));
                            }
                        }

                        foreach (ServerRuleApplyTimeEnum applyTime in ruleTypeList[type])
                        {
                            RuleApplyTimeDropDownList.Items.Add(new ListItem(
                                                                    ServerEnumDescription.GetLocalizedDescription(applyTime),
                                                                    applyTime.Lookup));
                        }
                    }

                    RuleTypeDropDownList.Items.Add(new ListItem(
                                                       ServerEnumDescription.GetLocalizedDescription(type), type.Lookup));
                }

                ServerRuleValidator.RuleTypeControl = RuleTypeDropDownList.SelectedValue;
            }

            ModalDialog.Show();
            return;
        }
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            var ep = new SampleRuleExtensionPoint();
            var extensions = ep.CreateExtensions();
        
            Dictionary<ServerRuleTypeEnum, IList<ServerRuleApplyTimeEnum>> ruleTypeList = LoadRuleTypes(extensions);


            SampleRuleDropDownList.Attributes.Add("onchange", "webServiceScript(this, this.SelectedIndex);");

            string javascript =
                @"<script type='text/javascript'>
            function ValidationServerRuleParams()
            {
                control = document.getElementById('" +
                RuleXmlTextBox.ClientID +
                @"');
                params = new Array();
                params.serverRule=escape(CodeMirrorEditor.doc.getValue());
				params.ruleType = '" + ServerRuleTypeEnum.DataAccess.Lookup + @"';
                return params;
            }

            function selectRuleType(oList, selectedIndex)
            {                         
                var val = oList.value; 
                var sampleList = document.getElementById('" +
                SampleRuleDropDownList.ClientID +
                @"');
                
                for (var q=sampleList.options.length; q>=0; q--) sampleList.options[q]=null;
				";

            javascript += GetJavascriptForSampleRule(ServerRuleTypeEnum.DataAccess, extensions);

            javascript +=
                @"}

            // This function calls the Web Service method.  
            function webServiceScript(oList)
            {
                var type = oList.value;
             
                ClearCanvas.ImageServer.Web.Application.Pages.Admin.Configure.DataRules.DataRuleSamples.GetXml(type,
                    OnSucess, OnError);
            }
            function OnError(result)
            {
                alert('Error: ' + result.get_message());
            }

            // This is the callback function that
            // processes the Web Service return value.
            function OnSucess(result)
            {
                var oList = document.getElementById('" +
                SampleRuleDropDownList.ClientID +
                @"');
                var sValue = oList.options[oList.selectedIndex].value;
             
                RsltElem = document.getElementById('" +
                RuleXmlTextBox.ClientID +
                @"');

                //Set the value on the TextArea and then set the value in the Editor.
                //CodeMirror doesn't monitor changes to the textarea.
                RsltElem.value = result;
                CodeMirrorEditor.doc.setValue(RsltElem.value);
            }
           
            function pageLoad(){
                $find('" +
                ModalDialog.PopupExtenderID +
                @"').add_shown(HighlightXML);
            }

            

	        function UpdateRuleXML() {
                RsltElem = document.getElementById('" +
                RuleXmlTextBox.ClientID +
                @"');	            

                RsltElem.value = CodeMirrorEditor.doc.getValue();    
	        }
  
            var CodeMirrorEditor = null;
            </script>";

            Page.ClientScript.RegisterClientScriptBlock(GetType(), ClientID, javascript);

            EditDataRuleValidationSummary.HeaderText = ErrorMessages.EditServerRuleValidationError;
        }
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            var ep = new SampleRuleExtensionPoint();

            object[] extensions = ep.CreateExtensions();

            ServerPartitionTabContainer.ActiveTabIndex = 0;

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


            SampleRuleDropDownList.Attributes.Add("onchange", "webServiceScript(this, this.SelectedIndex);");
            RuleTypeDropDownList.Attributes.Add("onchange", "selectRuleType(this);");

            RuleTypeDropDownList.TextChanged += delegate
            {
                ServerRuleValidator.RuleTypeControl = RuleTypeDropDownList.SelectedValue;
            };

            string javascript =
                @"<script type='text/javascript'>
            function ValidationServerRuleParams()
            {
                control = document.getElementById('" + RuleXmlTextBox.ClientID + @"');
                params = new Array();
                params.serverRule=escape(CodeMirrorEditor.doc.getValue());
				var oList = document.getElementById('"                 + RuleTypeDropDownList.ClientID + @"');
				params.ruleType = oList.options[oList.selectedIndex].value;
                return params;
            }

            function selectRuleType(oList, selectedIndex)
            {                         
                var val = oList.value; 
                var sampleList = document.getElementById('" + SampleRuleDropDownList.ClientID + @"');
                var applyTimeList = document.getElementById('" + RuleApplyTimeDropDownList.ClientID + @"');
                
                for (var q=sampleList.options.length; q>=0; q--) sampleList.options[q]=null;
                for (var q=applyTimeList.options.length; q>=0; q--) applyTimeList.options[q]=null;
				"                ;

            bool first = true;

            foreach (ServerRuleTypeEnum type in ruleTypeList.Keys)
            {
                if (!first)
                {
                    javascript += "else ";
                }
                else
                {
                    first = false;
                }

                javascript += GetJavascriptForSampleRule(type, extensions);
            }

            javascript +=
                @"}

            // This function calls the Web Service method.  
            function webServiceScript(oList)
            {
                var type = oList.value;
             
                MatrixPACS.ImageServer.Web.Application.Pages.Admin.Configure.ServerRules.ServerRuleSamples.GetXml(type,
                    OnSucess, OnError);
            }
            function OnError(result)
            {
                alert('Error: ' + result.get_message());
            }

            // This is the callback function that
            // processes the Web Service return value.
            function OnSucess(result)
            {
                var oList = document.getElementById('" + SampleRuleDropDownList.ClientID + @"');
                var sValue = oList.options[oList.selectedIndex].value;
             
                RsltElem = document.getElementById('" + RuleXmlTextBox.ClientID + @"');

                //Set the value on the TextArea and then set the value in the Editor.
                //CodeMirror doesn't monitor changes to the textarea.
                RsltElem.value = result;
                CodeMirrorEditor.doc.setValue(RsltElem.value);
            }
           
            function pageLoad(){
                $find('" + ModalDialog.PopupExtenderID + @"').add_shown(HighlightXML);
            }


	        function UpdateRuleXML() {
                RsltElem = document.getElementById('" + RuleXmlTextBox.ClientID + @"');	
                RsltElem.value = CodeMirrorEditor.doc.getValue();    
	        }
  
            var CodeMirrorEditor = null;
            </script>";

            Page.ClientScript.RegisterClientScriptBlock(GetType(), ClientID, javascript);

            EditServerRuleValidationSummary.HeaderText = ErrorMessages.EditServerRuleValidationError;
        }