Ejemplo n.º 1
0
 public CalculationSettings(IEditorService edSvc, ClassDefinition cls, IFeatureSource parent, ICalculatedProperty calc)
     : this()
 {
     _edSvc = edSvc;
     _cls = cls;
     _parent = parent;
     TextBoxBinder.BindText(txtExpression, calc, "Expression"); //NOXLATE
     TextBoxBinder.BindText(txtName, calc, "Name"); //NOXLATE
 }
Ejemplo n.º 2
0
        void IFeatureSourceExtension.RemoveCalculatedProperty(ICalculatedProperty prop)
        {
            var calc = prop as CalculatedPropertyType;

            if (calc != null)
            {
                this.CalculatedProperty.Remove(calc);
            }
        }
Ejemplo n.º 3
0
        public MainViewModel()
        {
            this.text = ObservablePropertyFactory.Instance.CreateProperty(string.Empty);

            Random r = new Random();
            this.calculated = ObservablePropertyFactory.Instance.CreateCancellableAsyncCalculatedPropertyWithContext(
                r,
                this.text,
                TimeSpan.FromSeconds(0.1),
                async (helper, context, text) =>
                {
                    int millisecondsToWait = context.Next(5000);
                    await Task.Delay(millisecondsToWait, helper.Token).ConfigureAwait(false);
                    await helper.CheckCancellationTokenAndYield().ConfigureAwait(false);
                    return Tuple.Create(text + " [CALCULATED]", millisecondsToWait);
                });

            this.calculatedText = ObservablePropertyFactory.Instance.CreateCalculatedProperty(
                this.calculated, calculated => calculated.Switch(v => v == null ? null : v.Item1, e => "[ERROR]"));

            this.calculatedTime = ObservablePropertyFactory.Instance.CreateCalculatedProperty(
                this.calculated, calculated => calculated.Switch(v => v == null ? 0 : v.Item2, e => -1));
        }
Ejemplo n.º 4
0
 public CalculationSettings(IEditorService edSvc, ClassDefinition cls, IFeatureSource parent, ICalculatedProperty calc)
     : this()
 {
     _edSvc  = edSvc;
     _cls    = cls;
     _parent = parent;
     TextBoxBinder.BindText(txtExpression, calc, nameof(calc.Expression));
     TextBoxBinder.BindText(txtName, calc, nameof(calc.Name));
 }
Ejemplo n.º 5
0
        public CalculatorViewModel(bool supportsAsync)
        {
            this.updateInRealTimeItems =
                ObservablePropertyFactory.Instance.CreateReadOnlyProperty(
                    ObservableCollectionFactory.Instance.CreateObservableCollection(new[] { true, false }));
            this.updateInRealTimeSelection = ObservablePropertyFactory.Instance.CreateProperty<bool?>(true);
            this.updateInRealTime =
                ObservablePropertyFactory.Instance.CreateCalculatedProperty(
                    this.updateInRealTimeSelection,
                    updateInRealTimeSelection => updateInRealTimeSelection.HasValue && updateInRealTimeSelection.Value);
            this.supportsAsync = ObservablePropertyFactory.Instance.CreateReadOnlyProperty(supportsAsync);
            this.simulateLatencyItems =
                ObservablePropertyFactory.Instance.CreateReadOnlyProperty(
                    ObservableCollectionFactory.Instance.CreateObservableCollection(new[] { true, false }));
            this.simulateLatencySelection = ObservablePropertyFactory.Instance.CreateProperty<bool?>(true);
            this.simulateLatency =
                ObservablePropertyFactory.Instance.CreateCalculatedProperty(
                    this.simulateLatencySelection,
                    simulateLatencySelection => simulateLatencySelection.HasValue && simulateLatencySelection.Value);
            this.operators =
                ObservablePropertyFactory.Instance.CreateReadOnlyProperty(
                    ObservableCollectionFactory.Instance.CreateObservableCollection(
                        new[] { Operator.Add, Operator.Subtract, Operator.Multiply, Operator.Divide }));
            this.showMultiply =
                ObservablePropertyFactory.Instance.CreateCalculatedProperty(
                    this.operators.MergeCollectionPropertyWithChanges(this.operators),
                    c => c.Collection.Contains(Operator.Multiply));
            this.showDivide =
                ObservablePropertyFactory.Instance.CreateCalculatedProperty(
                    this.operators.MergeCollectionPropertyWithChanges(this.operators),
                    c => c.Collection.Contains(Operator.Divide));
            this.operand1 = ObservablePropertyFactory.Instance.CreateProperty<string>(null);
            this.selectedOperator = ObservablePropertyFactory.Instance.CreateProperty(Operator.Add);
            this.selectedOperatorString =
                ObservablePropertyFactory.Instance.CreateCalculatedProperty(
                    this.selectedOperator,
                    selectedOperator =>
                        {
                            switch (selectedOperator)
                            {
                                case Operator.Add:
                                    return "+";
                                case Operator.Subtract:
                                    return "-";
                                case Operator.Multiply:
                                    return "*";
                                case Operator.Divide:
                                    return "/";
                                default:
                                    throw new NotSupportedException(
                                        "Unknown enumeration value " + selectedOperator + ".");
                            }
                        });
            this.operand2 = ObservablePropertyFactory.Instance.CreateProperty<string>(null);
            this.result = ObservablePropertyFactory.Instance.CreateCalculatedProperty(
                this.Operand1,
                this.Operand2,
                this.SelectedOperator,
                (operand1, operand2, selectedOperator) =>
                    {
                        Func<double?, double?, double?> function;
                        switch (selectedOperator)
                        {
                            case Operator.Add:
                                function = (x, y) => x + y;
                                break;
                            case Operator.Subtract:
                                function = (x, y) => x - y;
                                break;
                            case Operator.Multiply:
                                function = (x, y) => x * y;
                                break;
                            case Operator.Divide:
                                function = (x, y) => x / y;
                                break;
                            default:
                                throw new NotSupportedException("Unknown enumeration value " + selectedOperator + ".");
                        }

                        double operand1Value;
                        double.TryParse(operand1, out operand1Value);
                        double operand2Value;
                        double.TryParse(operand2, out operand2Value);
                        double? r = function(operand1Value, operand2Value);
                        return r == null ? null : r.ToString();
                    });
        }
 public void AddProperty(string name, ICalculatedProperty property)
 {
     _definitions.Add(name, property);
 }
Ejemplo n.º 7
0
 public Employee()
 {
     this.fullName = ObservablePropertyFactory.Instance.CreateCalculatedProperty(this.firstName, this.lastName, (firstName, lastName) => firstName + " " + lastName);
 }
Ejemplo n.º 8
0
 void IFeatureSourceExtension.RemoveCalculatedProperty(ICalculatedProperty prop)
 {
     var calc = prop as CalculatedPropertyType;
     if (calc != null)
         this.CalculatedProperty.Remove(calc);
 }