Exemple #1
0
        public AddToDate(IElementCreationContext context) 
            : base(context, context.Owner.GetVplTypeOrThrow(VplTypeId.DateTime))
        {
            DateParameter = context.Owner.CreateParameter("date", context.Owner.GetVplTypeOrThrow(VplTypeId.DateTime),
                "Date");

            DateParameter.Postfix = " + ";

            AmountParameter = context.Owner.CreateParameter("amount", context.Owner.GetFloatType());

            Parameters.Add(DateParameter);
            Parameters.Add(AmountParameter);

            _services = new OperationService[]
            {
                new OperationService(OperationType.Seconds, "Seconds", TimeSpan.FromSeconds),
                new OperationService(OperationType.Minutes, "Minutes", TimeSpan.FromMinutes),
                new OperationService(OperationType.Hours, "Hours", TimeSpan.FromHours),
                new OperationService(OperationType.Days, "Days", TimeSpan.FromDays),
            };

            Operation = OperationType.Seconds;

            if (!string.IsNullOrWhiteSpace(context.Data))
            {
                var data = JsonConvert.DeserializeObject<OperatorData>(context.Data);

                Operation = data.Operation;
            }

            foreach (var service in _services)
            {
                AddAction(new ElementAction(service.Text, () => Operation = service.Operation, () => Operation != service.Operation));
            }
        }
Exemple #2
0
        public NotOperator(IElementCreationContext context) 
            : base(context, context.Owner.GetBooleanType())
        {
            ParameterA = context.Owner.CreateParameter("a", context.Owner.GetVplTypeOrThrow(VplTypeId.Boolean), "Not");

            Parameters.Add(ParameterA);
        }
Exemple #3
0
        public Block(IElementCreationContext context, string id) 
            : base(context)
        {
            _id = id;

            _elements = new Elements(context.Owner);
        }
        public BinaryLogicalOperator(IElementCreationContext context, BinaryLogicalOperatorType defaultType) 
            : base(context, context.Owner.GetBooleanType())
        {
            ParameterA = context.Owner.CreateParameter("a", context.Owner.GetBooleanType());
            ParameterB = context.Owner.CreateParameter("b", context.Owner.GetBooleanType());

            Parameters.Add(ParameterA);
            Parameters.Add(ParameterB);

            var services = new[]
            {
                new BinaryLogicalOperatorService(BinaryLogicalOperatorType.And, "And", (a, b) => a && b),
                new BinaryLogicalOperatorService(BinaryLogicalOperatorType.Or, "Or", (a, b) => a || b),
            };

            foreach (var service in services)
            {
                AddAction(new ElementAction(service.Text, () => OperatorType = service.Type));
            }

            _services = services.ToDictionary(s => s.Type, s => s);

            OperatorType = defaultType;

            if (!string.IsNullOrWhiteSpace(context.Data))
            {
                var data = JsonConvert.DeserializeObject<BinaryLogicalOperatorData>(context.Data);

                OperatorType = data.OperatorType;
            }
        }
Exemple #5
0
        public WaitStatement(IElementCreationContext context) 
            : base(context)
        {
            SecondsParameter = Owner.CreateParameter("seconds", Owner.GetFloatType(), "Wait", "Seconds");

            SecondsParameter.SetValue(5.0);

            Parameters.Add(SecondsParameter);
        }
Exemple #6
0
        public VariableGetter(IElementCreationContext context, Guid variableId)
            : base(context)
        {
            if (variableId == Guid.Empty)
                throw new ArgumentException("variableId was default value.", nameof(variableId));

            _id = variableId;

            _variable = new Lazy<IVariable>(GetVariable);
        }
Exemple #7
0
        public VariableSetter(IElementCreationContext context, Guid variableId) 
            : base(context)
        {
            if (variableId == Guid.Empty)
                throw new ArgumentException("variableId was default value.", nameof(variableId));

            _variable = context.Owner.GetVariableOrThrow(variableId);
            _variable.NameChanged += VariableNameChanged;
            _parameter = AddParameter(_variable);
        }
        public EvaluateFunctionOperator(IElementCreationContext context) 
            : base(context, context.Owner.GetAnyType())
        {
            _behavior = new CommonFunctionBehavior(context, Parameters, "Evaluate", this);

            AddActions(_behavior.Actions);

            ForegroundColor = Colors.MediumSeaGreen;
            ForegroundColor = Colors.Black;
        }
Exemple #9
0
        public RepeatStatement(IElementCreationContext context) 
            : base(context)
        {
            Condition = Owner.CreateParameter("condition", Owner.GetFloatType());

            Block = Owner.CreateBlock("block", "Repeat");

            Block.Parameters.Add(Condition);
            Blocks.Add(Block);
        }
        public CallFunctionStatement(IElementCreationContext context) 
            : base(context)
        {
            _behavior = new CommonFunctionBehavior(context, Parameters, "Call", this);

            AddActions(_behavior.Actions);

            BackgroundColor = Colors.Lavender;
            ForegroundColor = Colors.Black;
        }
Exemple #11
0
        public WhileStatement(IElementCreationContext context) 
            : base(context)
        {
            Condition = Owner.CreateParameter("condition", Owner.GetBooleanType());

            Block = Owner.CreateBlock("block", "While");

            Block.Parameters.Add(Condition);
            Blocks.Add(Block);
        }
Exemple #12
0
        public Parameter(IElementCreationContext context, string id, IVplType type) 
            : base(context)
        {
            if (type == null) throw new ArgumentNullException(nameof(type));
            _id = id;
            _type = type;

            Value = type.DefaultValue;

            _editor = new Lazy<Visual>(type.CreateVisual);
        }
Exemple #13
0
        internal UnaryFloatOperator(IElementCreationContext context, Func<double, double> func, string label) 
            : base(context, context.Owner.GetFloatType())
        {
            if (func == null) throw new ArgumentNullException(nameof(func));

            _func = func;
            _label = label;

            Parameter = context.Owner.CreateParameter("a", context.Owner.GetFloatType());
            Parameters.Add(Parameter);
        }
Exemple #14
0
        public VariableGetter(IElementCreationContext context)
            : base(context)
        {
            if (string.IsNullOrWhiteSpace(context.Data))
                throw new ArgumentNullException($"Custom serialization data missing for {GetType().Name}");

            var data = JsonConvert.DeserializeObject<VariableGetterData>(context.Data);

            _id = data.VariableId;

            _variable = new Lazy<IVariable>(GetVariable);
        }
Exemple #15
0
        public VariableSetter(IElementCreationContext context) 
            : base(context)
        {
            if (string.IsNullOrWhiteSpace(context.Data))
                throw new ArgumentNullException($"Custom serialization data missing for {GetType().Name}");

            var data = JsonConvert.DeserializeObject<VariableSetterData>(context.Data);

            _variable = context.Owner.GetVariableOrThrow(data.VariableId);
            _variable.NameChanged += VariableNameChanged;
            _parameter = AddParameter(_variable);
        }
Exemple #16
0
        public CommentStatement(IElementCreationContext context)
            : base(context)
        {
            Comment = context.Data;

            ForegroundColor = Colors.Black;
            BackgroundColor = Colors.Yellow;

            _commentView = new CommentView()
            {
                DataContext = this
            };
        }
Exemple #17
0
        protected Element(IElementCreationContext context)
        {
            if (context == null) throw new ArgumentNullException(nameof(context));

            _owner = context.Owner;
            _factory = context.Factory;

            DeleteCommand = new RelayCommand(DeleteSelected, CanDelete);
            CopyCommand = new RelayCommand(Copy);
            CutCommand = new RelayCommand(Cut, CanDelete);
            PasteCommand = new RelayCommand(Paste, CanPaste);

            BackgroundColor = Colors.Plum;
            ForegroundColor = Colors.Black;
        }
        internal CommonFunctionBehavior(IElementCreationContext context, Parameters parameters, string text, IElement parent)
        {
            if (context == null) throw new ArgumentNullException(nameof(context));
            if (parameters == null) throw new ArgumentNullException(nameof(parameters));
            if (parent == null) throw new ArgumentNullException(nameof(parent));

            _owner = context.Owner;
            _parameters = parameters;
            _text = text;
            _parent = parent;

            _labelView = new CallFunctionView()
            {
                DataContext = this
            };

            if (string.IsNullOrWhiteSpace(context.Data))
            {
                _model = new CallFunctionData();
            }
            else
            {
                _model = JsonConvert.DeserializeObject<CallFunctionData>(context.Data);

                var functionService = context.Owner.GetService<IFunctionService>();

                if (functionService == null)
                {
                    MessageBox.Show("No function service was provided.");
                    return;
                }

                //Get the function
                SelectFunction(functionService.GetFunction(_model.FunctionId));
            }

            _actions = new IElementAction[]
            {
                new ElementAction("Select function...", SelectFunction)
            };
        }
Exemple #19
0
        public BinaryOperator(IElementCreationContext context, BinaryOperatorType defaultOperatorType) 
            : base(context, context.Owner.GetFloatType())
        {
            var services = new []
            {
                new BinaryOperatorService(BinaryOperatorType.Addition, "+", (a, b) => a + b),
                new BinaryOperatorService(BinaryOperatorType.Subtraction, "-", (a, b) => a - b),
                new BinaryOperatorService(BinaryOperatorType.Multiplication, "*", (a, b) => a * b),
                new BinaryOperatorService(BinaryOperatorType.Division, "/", (a, b) => a / b),
                new BinaryOperatorService(BinaryOperatorType.ShiftLeft, "<<", (a, b) => a << b), 
                new BinaryOperatorService(BinaryOperatorType.ShiftRight, ">>", (a, b) => a >> b), 
                new BinaryOperatorService(BinaryOperatorType.BitwiseAnd, "&", (a , b) => a & b),
                new BinaryOperatorService(BinaryOperatorType.BitwiseOr, "|", (a , b) => a | b),
                new BinaryOperatorService(BinaryOperatorType.Modulus, "%", (a , b) => a % b),
            };

            foreach (var service in services)
            {
                AddAction(new ElementAction(service.Text, () => OperatorType = service.Type));
            }

            _services = services.ToDictionary(s => s.Type, s => s);

            ParameterA = context.Owner.CreateParameter("a", context.Owner.GetFloatType());
            ParameterB = context.Owner.CreateParameter("b", context.Owner.GetFloatType());

            Parameters.Add(ParameterA);
            Parameters.Add(ParameterB);

            Service = _services[BinaryOperatorType.Addition];

            OperatorType = defaultOperatorType;

            if (!string.IsNullOrWhiteSpace(context.Data))
            {
                var data = JsonConvert.DeserializeObject<BinaryOperatorData>(context.Data);

                OperatorType = data.OperatorType;
            }
        }
Exemple #20
0
        public IfElseStatement(IElementCreationContext context) 
            : base(context)
        {
            _data = new IfElseData();

            try
            {
                if (!string.IsNullOrWhiteSpace(context.Data))
                {
                    _data = JsonConvert.DeserializeObject<IfElseData>(context.Data);
                }

                if (_data.NumberOfIfs == 0)
                {
                    _data.NumberOfIfs = 1;
                }
            }
            catch (Exception ex)
            {
                //TODO: Add this to the IElementCreationContext error/warning interface that we have yet to add.
                Console.WriteLine(ex);
            }

            for (var index = 0; index < _data.NumberOfIfs; index++)
            {
                AddIfClause(index);
            }

            if (_data.IncludeElse)
            {
               AddElse();
            }

            //Add actions for adding / removing else clauses.
            this.AddAction("Add 'Else If'", AddIfClause);
            this.AddAction("Remove last 'Else If'", RemoveLastIf, CanRemoveLastIf);
            this.AddAction("Add 'Else'", AddElse, CanAddElse);
            this.AddAction("Remove 'Else'", RemoveElse, CanRemoveElse);
        }
Exemple #21
0
        public ComparisonOperator(IElementCreationContext context, ComparisonOperatorType comparisonType) 
            : base(context, context.Owner.GetBooleanType())
        {
            ParameterA = Owner.CreateParameter("a", context.Owner.GetFloatType());
            ParameterB = Owner.CreateParameter("b", context.Owner.GetFloatType());

            Parameters.Add(ParameterA);
            Parameters.Add(ParameterB);

            _services = new[]
            {
                new ComparisonOperatorService(ComparisonOperatorType.LessThan, "<", (a, b) => a < b),
                new ComparisonOperatorService(ComparisonOperatorType.LessThanOrEqual, "<=", (a, b) => a <= b),
                new ComparisonOperatorService(ComparisonOperatorType.Equal, "=", (a, b) => a == b),
                new ComparisonOperatorService(ComparisonOperatorType.NotEqual, "<>", (a, b) => a != b),
                new ComparisonOperatorService(ComparisonOperatorType.GreaterThan, ">", (a, b) => a > b),
                new ComparisonOperatorService(ComparisonOperatorType.GreaterThanOrEqual, ">=", (a, b) => a >= b),
            };

            //Add actions so we can just change the type instead of having to recreate it.
            foreach (var service in _services)
            {
                AddAction(new ElementAction(service.Text, () => ComparisonType = service.ComparisonType, () => ComparisonType != service.ComparisonType));
            }

            ComparisonType = ComparisonOperatorType.Equal;

            if (!string.IsNullOrWhiteSpace(context.Data))
            {
                var data = JsonConvert.DeserializeObject<ComparisonOperatorData>(context.Data);

                ComparisonType = data.ComparisonType;
            }
            else
            {
                ComparisonType = comparisonType;
            }

        }
Exemple #22
0
        public Cast(IElementCreationContext context)
            : base(context)
        {
            TypeSelected(VplTypeId.Any);

            //Add the action.
            AddAction(new ElementAction("Select Type...", SelectType));

            try
            {
                if (!string.IsNullOrWhiteSpace(context.Data))
                {
                    var data = JsonConvert.DeserializeObject<OperatorData>(context.Data);

                    TypeSelected(data.VplTypeId);
                }
            }
            catch (Exception ex)
            {
                //TODO: Add something to IElementCreationContext to log this to
                Console.WriteLine(ex);
            }
        }
Exemple #23
0
        public Alert(IElementCreationContext context) : base(context)
        {
            _messageParameter = context.Owner.CreateParameter("message", context.Owner.GetStringType());

            Parameters.Add(_messageParameter);
        }
Exemple #24
0
 protected OperatorBase(IElementCreationContext context)
     : base(context)
 {
 }
Exemple #25
0
 public CommentViewModel(IElementCreationContext context)
     : base(context)
 {
     Comment = context.Data;
 }
Exemple #26
0
 protected Operator(IElementCreationContext context, IVplType type)
     : base(context)
 {
     if (type == null) throw new ArgumentNullException(nameof(type));
     _type = type;
 }
Exemple #27
0
 protected Statement(IElementCreationContext context) 
     : base(context)
 {
     BackgroundColor = Colors.CornflowerBlue;
     ForegroundColor = Colors.White;
 }
Exemple #28
0
 protected CompoundStatement(IElementCreationContext context)
     : base(context)
 {
 }
Exemple #29
0
 public IElement Create(IElementCreationContext context)
 {
     return _factory(context);
 }
Exemple #30
0
 public UtcNow(IElementCreationContext context)
     : base(context, context.Owner.GetVplTypeOrThrow(VplTypeId.DateTime))
 {
 }