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; } }
public NotOperator(IElementCreationContext context) : base(context, context.Owner.GetBooleanType()) { ParameterA = context.Owner.CreateParameter("a", context.Owner.GetVplTypeOrThrow(VplTypeId.Boolean), "Not"); Parameters.Add(ParameterA); }
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)); } }
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)); } }
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; } }
public Block(IElementCreationContext context, string id) : base(context) { _id = id; _elements = new Elements(context.Owner); }
public WaitStatement(IElementCreationContext context) : base(context) { SecondsParameter = Owner.CreateParameter("seconds", Owner.GetFloatType(), "Wait", "Seconds"); SecondsParameter.SetValue(5.0); Parameters.Add(SecondsParameter); }
protected Operator(IElementCreationContext context, IVplType type) : base(context) { if (type == null) { throw new ArgumentNullException(nameof(type)); } _type = type; }
public WhileStatement(IElementCreationContext context) : base(context) { Condition = Owner.CreateParameter("condition", Owner.GetBooleanType()); Block = Owner.CreateBlock("block", "While"); 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; }
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; }
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 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 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); }
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); }
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); }
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 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); }
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); }
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); }
public CommentStatement(IElementCreationContext context) : base(context) { Comment = context.Data; ForegroundColor = Colors.Black; BackgroundColor = Colors.Yellow; _commentView = new CommentView() { DataContext = this }; }
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), new ElementAction("Go to definition...", GoToDefinition, CanGoToDefinition), }; }
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); }
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); }
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); }
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); }
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; }
public ForStatement(IElementCreationContext context) : base(context) { From = Owner.CreateParameter("from", Owner.GetFloatType(), null, " : "); To = Owner.CreateParameter("to", Owner.GetFloatType(), null, " ; "); Step = Owner.CreateParameter("step", Owner.GetFloatType(), "step : "); Block = Owner.CreateBlock("block", "For"); Block.Parameters.Add(From); Block.Parameters.Add(To); Block.Parameters.Add(Step); Blocks.Add(Block); }
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) }; }
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; } }
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; } }
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; } }
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); }
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); }
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; } }
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); } }
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); } }
protected Statement(IElementCreationContext context) : base(context) { BackgroundColor = Colors.CornflowerBlue; ForegroundColor = Colors.White; }
public IElement Create(IElementCreationContext context) { return _factory(context); }
public UtcNow(IElementCreationContext context) : base(context, context.Owner.GetVplTypeOrThrow(VplTypeId.DateTime)) { }
public Now(IElementCreationContext context) : base(context, context.Owner.GetVplTypeOrThrow(VplTypeId.DateTime)) { }
protected CompoundStatement(IElementCreationContext context) : base(context) { }
protected Operator(IElementCreationContext context, IVplType type) : base(context) { if (type == null) throw new ArgumentNullException(nameof(type)); _type = type; }
protected OperatorBase(IElementCreationContext context) : base(context) { }
public CommentViewModel(IElementCreationContext context) : base(context) { Comment = context.Data; }
public Annotation(IElementCreationContext context) : base(context) { }
public Alert(IElementCreationContext context) : base(context) { _messageParameter = context.Owner.CreateParameter("message", context.Owner.GetStringType()); Parameters.Add(_messageParameter); }