public override void FromXml(XmlElement xmlElement)
        {
            FieldDropdown dropdown = mBlock.GetField("MENU") as FieldDropdown;

            if (dropdown == null)
            {
                throw new Exception("FieldDropDown \"MENU\" not found.");
            }

            if (xmlElement.HasAttribute("options"))
            {
                string   optionText = xmlElement.GetAttribute("options");
                string[] options    = optionText.Split(new[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries);
                if (options.Length % 2 != 0)
                {
                    throw new Exception(string.Format("Xml serialization for mutation {0} is damaged", MutatorId));
                }

                FieldDropdownMenu[] menu = new FieldDropdownMenu[options.Length / 2];
                for (int i = 0; i < menu.Length; i++)
                {
                    menu[i].Text  = options[i * 2];
                    menu[i].Value = options[i * 2 + 1];
                }
                dropdown.SetOptions(menu);
            }
        }
Exemple #2
0
        private static FieldDropdown CreateFromJson(JObject json)
        {
            string        fieldName = json["name"].IsString() ? json["name"].ToString() : "FIELDNAME_DEFAULT";
            FieldDropdown field     = new FieldDropdown(fieldName);

            if (json.JsonDataContainsKey("options"))
            {
                field.SetOptions(json["options"] as JArray);
            }

            field.IsImage = json.JsonDataContainsKey("image") && (bool)json["image"];
            return(field);
        }
        protected override void OnAttached()
        {
            mDropdown = mBlock.GetField("PROPERTY") as FieldDropdown;
            if (mDropdown == null)
            {
                throw new Exception("FieldDropDown \"PROPERTY\" not found.");
            }

            UpdateInternal(mDropdown.GetValue().Equals(DIVISIBLE_BY));

            //register observer
            mObserver = new MemorySafeMutatorObserver(this);
            mDropdown.AddObserver(mObserver);
        }
        protected override void OnAttached()
        {
            if (mBlock.GetField("WHERE") != null)
            {
                AtData data = new AtData();
                data.whereDropdown = mBlock.GetField("WHERE") as FieldDropdown;
                data.atInputIndex  = mBlock.InputList.FindIndex(input => "AT".Equals(input.Name));
                data.xmlAttr       = "at";
                data.inputName     = "AT";
                mAtDatas.Add(data);

                mIsOnly = true;
            }
            else if (mBlock.GetField("WHERE1") != null)
            {
                int i = 1;
                while (true)
                {
                    FieldDropdown dropdown = mBlock.GetField("WHERE" + i) as FieldDropdown;
                    if (dropdown == null)
                    {
                        break;
                    }
                    AtData data = new AtData();
                    data.whereDropdown = dropdown;
                    data.atInputIndex  = mBlock.InputList.FindIndex(input => ("AT" + i).Equals(input.Name));
                    data.xmlAttr       = "at" + i;
                    data.inputName     = "AT" + i;
                    mAtDatas.Add(data);
                    i++;
                }

                mIsOnly = false;
            }
            else
            {
                throw new Exception("FieldDropDown \"WHERE\" not found.");
            }

            UpdateInternal();

            //register observer
            mObserver = new MemorySafeMutatorObserver(this);
            foreach (AtData atData in mAtDatas)
            {
                atData.whereDropdown.AddObserver(mObserver);
            }
        }
        public override XmlElement ToXml()
        {
            FieldDropdown dropdown = mBlock.GetField("MENU") as FieldDropdown;

            if (dropdown == null)
            {
                throw new Exception("FieldDropDown \"MENU\" not found.");
            }

            StringBuilder sb = new StringBuilder();

            foreach (FieldDropdownMenu option in dropdown.GetOptions())
            {
                sb.AppendFormat("{0},{1};", option.Text, option.Value);
            }

            XmlElement xmlElement = XmlUtil.CreateDom("mutation");

            xmlElement.SetAttribute("options", sb.ToString());

            return(xmlElement);
        }