Exemple #1
0
 private void _removeTemplateItem(TemplateItemBase item)
 {
     if (Items.Contains(item))
     {
         Items.Remove(item);
     }
 }
Exemple #2
0
 private void _deselectItem(TemplateItemBase item)
 {
     if (item.IsSelected)
     {
         item.IsSelected = false;
     }
     if (SelectedItems.Contains(item))
     {
         SelectedItems.Remove(item);
     }
 }
Exemple #3
0
 private void _selectItem(TemplateItemBase item)
 {
     if (!item.IsSelected)
     {
         item.IsSelected = true;
     }
     if (!SelectedItems.Contains(item))
     {
         SelectedItems.Add(item);
     }
 }
Exemple #4
0
 private void _addTemplateItem(TemplateItemBase item)
 {
     Items.Add(item);
 }
Exemple #5
0
        private ExtractionValue _getTemplateItemValue(
            TemplateItemBase item,
            Dictionary <string, ExtractionValue> nameDic,
            Dictionary <int, ExtractionValue> numberDic)
        {
            switch (item.Type)
            {
            case TemplateValueType.String:
                return(new ExtractionValue(item.As <TemplateItem <string> >().Value, ValueType.String));

            case TemplateValueType.Bool:
                return(new ExtractionValue(item.As <TemplateItem <bool> >().Value, ValueType.Bool));

            case TemplateValueType.Integer:
                return(new ExtractionValue(item.As <TemplateItem <int> >().Value, ValueType.Int));

            case TemplateValueType.Float:
                return(new ExtractionValue(item.As <TemplateItem <float> >().Value, ValueType.Float));

            case TemplateValueType.NumberRef:
                var refValInd = item.As <TemplateItem <(int, string)> >().Value;
                if (!numberDic.ContainsKey(refValInd.Item1))
                {
                    return(null);
                }
                return(_extractValueRef(numberDic[refValInd.Item1], refValInd.Item2));

            case TemplateValueType.NameRef:
                var refValName = item.As <TemplateItem <(string, string)> >().Value;
                if (!nameDic.ContainsKey(refValName.Item1))
                {
                    return(null);
                }
                return(_extractValueRef(nameDic[refValName.Item1], refValName.Item2));

            case TemplateValueType.List:
                var items   = item.As <TemplateItem <TemplateItemBase[]> >().Value;
                var resList = new List <ExtractionValue>();
                foreach (var itemBase in items)
                {
                    var resValue = _getTemplateItemValue(itemBase, nameDic, numberDic);
                    if (resValue == null)
                    {
                        continue;
                    }

                    if (resValue.Type == ValueType.List)
                    {
                        foreach (var insideValue in resValue.GetValue <List <ExtractionValue> >())
                        {
                            resList.Add(insideValue);
                        }
                    }
                    else
                    {
                        resList.Add(resValue);
                    }
                }

                return(new ExtractionValue(resList, ValueType.List));


            default:
                throw new NotImplementedException($"Unsopported type {item.Type}");
            }
        }
Exemple #6
0
 public void AddStaticVar(TemplateItemBase item)
 {
     _staticVars.Add(item);
 }
Exemple #7
0
 private static void _checkPropertyValue <T>(TemplateItemBase etProp, TemplateItemBase rezProp)
 {
     Assert.AreEqual(etProp.As <TemplateItem <T> >().Value,
                     rezProp.As <TemplateItem <T> >().Value,
                     "Wrong property value");
 }
Exemple #8
0
        private static void _checkTemplateItem(TemplateItemBase etItem, TemplateItemBase rezItem)
        {
            Assert.AreEqual(etItem.Name,
                            rezItem.Name,
                            "Wrong template item name");

            Assert.AreEqual(etItem.Type,
                            rezItem.Type,
                            "Wrong template item value type");

            Assert.AreEqual(etItem.GetType(),
                            rezItem.GetType(),
                            "Wrong value type");

            switch (etItem.Type)
            {
            case TemplateValueType.List:
                var etValueItem  = etItem.As <TemplateItem <TemplateItemBase[]> >();
                var rezValueItem = rezItem.As <TemplateItem <TemplateItemBase[]> >();
                Assert.AreEqual(etValueItem.Value.Length,
                                rezValueItem.Value.Length,
                                "Wrong template item list length");

                for (int i = 0; i < etValueItem.Value.Length; i++)
                {
                    _checkTemplateItem(etValueItem.Value[i], rezValueItem.Value[i]);
                }
                break;

            case TemplateValueType.NameRef:
                _checkPropertyValue <(string, string)>(etItem, rezItem);
                break;

            case TemplateValueType.String:
                _checkPropertyValue <string>(etItem, rezItem);
                break;

            case TemplateValueType.NumberRef:
                _checkPropertyValue <(int, string)>(etItem, rezItem);
                break;

            case TemplateValueType.Integer:
                _checkPropertyValue <int>(etItem, rezItem);
                break;

            case TemplateValueType.Float:
                Assert.AreEqual(
                    etItem.As <TemplateItem <float> >().Value,
                    rezItem.As <TemplateItem <float> >().Value,
                    0.0001,
                    "Wrong property value");
                break;

            case TemplateValueType.Bool:
                _checkPropertyValue <bool>(etItem, rezItem);
                break;

            default:
                throw new NotImplementedException();
            }
        }