public List getScrubRules()

in CosmosClone/CosmicCloneUI/DataAnonymizationPage.xaml.cs [306:384]


        public List<ScrubRule> getScrubRules()
        {
            //List<ScrubRule> sb = new List<ScrubRule>();
            TextBox filterCondition = (TextBox) this.FindName("FilterCondition");
            //sb.filterQuery = filterCondition.Text;
            List<ScrubRule> srList = new List<ScrubRule>();

            WrapPanel wrapPanel = (WrapPanel) this.FindName("WrapPanel");
            foreach (UIElement SPUI in wrapPanel.Children)
            {
                Expander exp = (Expander) SPUI;
                StackPanel lrsp = (StackPanel) exp.Content;
                UIElementCollection uiElementsSP = lrsp.Children;

                ScrubRule sr = new ScrubRule();

                foreach (UIElement uiElementSP in uiElementsSP)
                {
                    StackPanel tempSP = (StackPanel) uiElementSP;
                    UIElementCollection uiElements = tempSP.Children;

                    foreach (UIElement uiElement in uiElements)
                    {
                        if (uiElement.GetType().Name == "Label")
                        {
                            var ruleIdLabel = (Label) uiElement;
                            int ruleId;
                            if (int.TryParse(ruleIdLabel.Content.ToString(), out ruleId))
                            {
                                sr.RuleId = ruleId;
                            }
                            else sr.RuleId = 0;
                        }

                        if (uiElement.GetType().Name == "TextBox")
                        {
                            TextBox tb = (TextBox) uiElement;

                            if (tb.Name.StartsWith("Filter"))
                            {
                                sr.FilterCondition = tb.Text.Trim();
                            }
                            else if (tb.Name.StartsWith("ScrubAttribute"))
                            {
                                sr.PropertyName = tb.Text.Trim();
                            }
                            else if (tb.Name.StartsWith("ScrubValue"))
                            {
                                sr.UpdateValue = tb.Text.Trim();
                            }
                        }

                        if (uiElement.GetType().Name == "ComboBox")
                        {
                            ComboBox cb = (ComboBox) uiElement;
                            if (cb.Name.StartsWith("ScrubType"))
                            {
                                //sr.Type = (RuleType) Enum.Parse(typeof(RuleType), cb.Text);
                                RuleType rType;

                                if (Enum.TryParse<RuleType>(cb.Text, out rType))
                                {
                                    sr.Type = rType;
                                }
                                else
                                {
                                    sr.Type = null;
                                }
                            }
                        }
                    }

                }

                srList.Add(sr);
            }

            return srList;
        }