Exemplo n.º 1
0
        public static IElement[] CreateElements(this IElementOwner owner, IElementClipboardData data)
        {
            if (owner == null)
            {
                throw new ArgumentNullException(nameof(owner));
            }
            if (data == null)
            {
                throw new ArgumentNullException(nameof(data));
            }

            //Create the elements
            return(data.Items
                   .Select(item =>
            {
                if (item.ElementMetadata != null)
                {
                    return owner.Context.ElementBuilder.CreateElement(owner, item.ElementMetadata);
                }

                if (item.Factory != null)
                {
                    return owner.CreateElement(item.Factory);
                }

                //This shouldn't happen
                return null;
            })
                   .ToArray());
        }
 public DefaultFunctionSelector(IElementOwner owner)
 {
     if (owner == null)
     {
         throw new ArgumentNullException(nameof(owner));
     }
     _owner = owner;
 }
Exemplo n.º 3
0
        /// <summary>
        /// Creates an instance of IElementCreationContext
        /// </summary>
        /// <param name="owner">The owner.</param>
        /// <param name="elementTypeId">The type of element.</param>
        /// <param name="data">Optional data.</param>
        /// <returns></returns>
        public static IElementCreationContext CreateElementCreationContext(this IElementOwner owner, Guid elementTypeId, string data = null)
        {
            var factory = owner.Context.ElementFactoryManager.GetFactory(elementTypeId);

            var context = new ElementCreationContext(owner, data, factory);

            return(context);
        }
Exemplo n.º 4
0
        public ArgumentVariable(IElementOwner owner, IVplType type, IArgument argument)
            : base(owner, type, argument.Id)
        {
            if (argument == null) throw new ArgumentNullException(nameof(argument));

            _argument = argument;

            argument.PropertyChanged += Argument_PropertyChanged;
        }
Exemplo n.º 5
0
        public Elements(IElementOwner owner)
        {
            if (owner == null)
            {
                throw new ArgumentNullException(nameof(owner));
            }

            _owner = owner;
        }
Exemplo n.º 6
0
        public ElementCreationContext(IElementOwner owner, string data, IElementFactory factory)
        {
            if (owner == null) throw new ArgumentNullException(nameof(owner));
            if (factory == null) throw new ArgumentNullException(nameof(factory));

            _owner = owner;
            _data = data;
            _factory = factory;
        }
Exemplo n.º 7
0
 public Argument(IElementOwner owner, ArgumentMetadata metadata)
 {
     if (owner == null)
     {
         throw new ArgumentNullException(nameof(owner));
     }
     _owner    = owner;
     _metadata = metadata;
 }
Exemplo n.º 8
0
        /// <summary>
        /// Gets the specified VplType or throws an exception.
        /// </summary>
        /// <param name="owner"></param>
        /// <param name="vplTypeId"></param>
        /// <returns></returns>
        public static IVplType GetVplTypeOrThrow(this IElementOwner owner, Guid vplTypeId)
        {
            var type = owner.GetVplType(vplTypeId);

            if (type == null)
            {
                throw new TypeAccessException($"Unable to find the VplType with id {vplTypeId}.");
            }

            return(type);
        }
Exemplo n.º 9
0
        public static IElement CreateElement(this IElementOwner owner, IElementFactory factory)
        {
            if (factory == null)
            {
                throw new ArgumentNullException(nameof(factory));
            }

            var context = new ElementCreationContext(owner, null, factory);

            return(factory.Create(context));
        }
Exemplo n.º 10
0
        /// <summary>
        /// Attempts to get the variable with the specified id. If the variable isn't found, an exception is thrown.
        /// </summary>
        /// <param name="owner">Owner.</param>
        /// <param name="variableId">The id of the variable.</param>
        /// <returns></returns>
        public static IVariable GetVariableOrThrow(this IElementOwner owner, Guid variableId)
        {
            var variable = owner.GetVariable(variableId);

            if (variable == null)
            {
                throw new KeyNotFoundException($"Unable to find variable with id '{variableId}'");
            }

            return(variable);
        }
Exemplo n.º 11
0
        public ArgumentVariable(IElementOwner owner, IVplType type, IArgument argument)
            : base(owner, type, argument.Id)
        {
            if (argument == null)
            {
                throw new ArgumentNullException(nameof(argument));
            }

            _argument = argument;

            argument.PropertyChanged += Argument_PropertyChanged;
        }
Exemplo n.º 12
0
        /// <summary>
        /// Creates a parameter.
        /// </summary>
        /// <param name="owner">Owner.</param>
        /// <param name="id">The id of the parameter.</param>
        /// <param name="type">The type of parameter.</param>
        /// <param name="prefix">Optional prefix</param>
        /// <param name="postfix">Optionl postfix</param>
        /// <returns></returns>
        public static IParameter CreateParameter(this IElementOwner owner, string id, IVplType type, string prefix = null, string postfix = null)
        {
            var context = CreateElementCreationContext(owner, SystemElementIds.Parameter);

            var parameter = new Parameter(context, id, type)
            {
                Prefix  = prefix,
                Postfix = postfix
            };

            return(parameter);
        }
Exemplo n.º 13
0
        /// <summary>
        /// Creates a block.
        /// </summary>
        /// <param name="owner">Owner.</param>
        /// <param name="id">The id of the block.</param>
        /// <param name="label">An optional label.</param>
        /// <returns></returns>
        public static IBlock CreateBlock(this IElementOwner owner, string id, object label = null)
        {
            //Create the context
            var context = CreateElementCreationContext(owner, SystemElementIds.Block);

            //Create the block
            var block = new Block(context, id)
            {
                Label = label
            };

            return(block);
        }
Exemplo n.º 14
0
        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),
            };
        }
Exemplo n.º 15
0
        public ElementCreationContext(IElementOwner owner, string data, IElementFactory factory)
        {
            if (owner == null)
            {
                throw new ArgumentNullException(nameof(owner));
            }
            if (factory == null)
            {
                throw new ArgumentNullException(nameof(factory));
            }

            _owner   = owner;
            _data    = data;
            _factory = factory;
        }
Exemplo n.º 16
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;
        }
Exemplo n.º 17
0
        public Variable(IElementOwner owner, IVplType type, Guid id)
        {
            if (owner == null) throw new ArgumentNullException(nameof(owner));
            if (type == null) throw new ArgumentNullException(nameof(type));

            _owner = owner;
            _type = type;
            _id = id;

            RenameCommand = new RelayCommand(Rename, CanRename);
            DeleteCommand = new RelayCommand(() => Delete(), CanDelete);

            _editor = new Lazy<Visual>(type.CreateVisual);
            _value = type.DefaultValue;
        }
Exemplo n.º 18
0
        public IElement CreateElement(IElementOwner owner, ElementMetadata elementMetadata)
        {
            if (owner == null)
            {
                throw new ArgumentNullException(nameof(owner));
            }
            if (elementMetadata == null)
            {
                throw new ArgumentNullException(nameof(elementMetadata));
            }

            //Find the factory
            var factory = _factoryManager.GetFactory(elementMetadata.ElementTypeId);

            //Create the context
            var context = new ElementCreationContext(owner, elementMetadata.Data, factory);

            //Create the element
            var element = factory.Create(context);

            SetElementProperties(element, elementMetadata);

            //Blocks
            if (elementMetadata.Blocks != null)
            {
                foreach (var blockMetadata in elementMetadata.Blocks)
                {
                    var block = element.Blocks.FirstOrDefault(b => b.Id == blockMetadata.Id);

                    if (block == null)
                    {
                        Console.WriteLine("Whoa - didn't find a block");
                    }
                    else
                    {
                        SetElementProperties(block, blockMetadata);

                        if (blockMetadata.Elements != null)
                        {
                            //Add the block children
                            block.Elements.AddRange(blockMetadata.Elements.Select(e => CreateElement(owner, e)).ToArray());
                        }
                    }
                }
            }

            return(element);
        }
Exemplo n.º 19
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;
        }
Exemplo n.º 20
0
        public void AddToOwner(IElementOwner owner, IEnumerable <ElementMetadata> rootElements)
        {
            if (rootElements == null)
            {
                throw new ArgumentNullException(nameof(rootElements));
            }
            if (owner == null)
            {
                throw new ArgumentNullException(nameof(owner));
            }

            foreach (var elementMetadata in rootElements)
            {
                var element = CreateElement(owner, elementMetadata);

                owner.Add(element);
            }
        }
Exemplo n.º 21
0
        public IElement CreateElement(IElementOwner owner, ElementMetadata elementMetadata)
        {
            if (owner == null) throw new ArgumentNullException(nameof(owner));
            if (elementMetadata == null) throw new ArgumentNullException(nameof(elementMetadata));

            //Find the factory
            var factory = _factoryManager.GetFactory(elementMetadata.ElementTypeId);

            //Create the context
            var context = new ElementCreationContext(owner, elementMetadata.Data, factory);

            //Create the element
            var element = factory.Create(context);

            SetElementProperties(element, elementMetadata);

            //Blocks
            if (elementMetadata.Blocks != null)
            {
                foreach (var blockMetadata in elementMetadata.Blocks)
                {
                    var block = element.Blocks.FirstOrDefault(b => b.Id == blockMetadata.Id);

                    if (block == null)
                    {
                        Console.WriteLine("Whoa - didn't find a block");
                    }
                    else
                    {
                        SetElementProperties(block, blockMetadata);

                        if (blockMetadata.Elements != null)
                        {
                            //Add the block children
                            block.Elements.AddRange(blockMetadata.Elements.Select(e => CreateElement(owner, e)).ToArray());
                        }
                    }
                }
            }

            return element;
        }
Exemplo n.º 22
0
        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)
            };
        }
Exemplo n.º 23
0
        public Variable(IElementOwner owner, IVplType type, Guid id)
        {
            if (owner == null)
            {
                throw new ArgumentNullException(nameof(owner));
            }
            if (type == null)
            {
                throw new ArgumentNullException(nameof(type));
            }

            _owner = owner;
            _type  = type;
            _id    = id;

            RenameCommand = new RelayCommand(Rename, CanRename);
            DeleteCommand = new RelayCommand(() => Delete(), CanDelete);

            _editor = new Lazy <Visual>(type.CreateVisual);
            _value  = type.DefaultValue;
        }
Exemplo n.º 24
0
        private void AddToOwner(IElementOwner owner, IEnumerable <VariableMetadata> variableMetadatas)
        {
            if (owner == null)
            {
                throw new ArgumentNullException(nameof(owner));
            }
            if (variableMetadatas == null)
            {
                throw new ArgumentNullException(nameof(variableMetadatas));
            }

            foreach (var variableMetadata in variableMetadatas)
            {
                var variableType = owner.GetVplTypeOrThrow(variableMetadata.TypeId);

                var variable = new Variable(owner, variableType, variableMetadata.Id)
                {
                    Name = variableMetadata.Name
                };

                owner.AddVariable(variable);
            }
        }
Exemplo n.º 25
0
        public static bool AreAllItemsStatements(this IElementOwner owner, IElementClipboardData data)
        {
            if (owner == null)
            {
                throw new ArgumentNullException(nameof(owner));
            }
            if (data == null)
            {
                throw new ArgumentNullException(nameof(data));
            }

            return(data.Items.Any() &&
                   data.Items.All(i =>
            {
                IElementFactory factory;

                if (i.Factory != null)
                {
                    //First try to use the factory
                    factory = i.Factory;
                }
                else if (i.ElementMetadata != null)
                {
                    //Get the factory for this element type
                    factory = owner.Context.ElementFactoryManager.GetFactory(i.ElementMetadata.ElementTypeId);
                }
                else
                {
                    //This shouldn't happen
                    return false;
                }

                //Determine if this is a statement
                return factory.ElementType.IsStatement();
            }));
        }
Exemplo n.º 26
0
 /// <summary>
 /// Gets the Float VplType (.net type is double).
 /// </summary>
 /// <param name="owner"></param>
 /// <returns></returns>
 public static IVplType GetFloatType(this IElementOwner owner)
 {
     return(owner.GetVplTypeOrThrow(VplTypeId.Float));
 }
Exemplo n.º 27
0
 public ReturnValueVariable(IElementOwner owner, IVplType type)
     : base(owner, type, ReturnVariableId)
 {
 }
Exemplo n.º 28
0
 public Argument(IElementOwner owner, ArgumentMetadata metadata)
 {
     if (owner == null) throw new ArgumentNullException(nameof(owner));
     _owner = owner;
     _metadata = metadata;
 }
Exemplo n.º 29
0
 /// <summary>
 /// Gets the specified VplType or throws an exception.
 /// </summary>
 /// <param name="owner"></param>
 /// <param name="vplTypeId"></param>
 /// <returns></returns>
 public static IVplType GetVplType(this IElementOwner owner, Guid vplTypeId)
 {
     return(owner.Context.Types.FirstOrDefault(t => t.Id == vplTypeId));
 }
Exemplo n.º 30
0
 /// <summary>
 /// Gets the Boolean VplType.
 /// </summary>
 /// <param name="owner"></param>
 /// <returns></returns>
 public static IVplType GetBooleanType(this IElementOwner owner)
 {
     return(owner.GetVplTypeOrThrow(VplTypeId.Boolean));
 }
Exemplo n.º 31
0
 /// <summary>
 /// Gets a variable. If it is not found, null is returned.
 /// </summary>
 /// <param name="owner"></param>
 /// <param name="variableId">The id of the variable.</param>
 /// <returns></returns>
 public static IVariable GetVariable(this IElementOwner owner, Guid variableId)
 {
     return(owner.Variables.FirstOrDefault(v => v.Id == variableId));
 }
Exemplo n.º 32
0
 /// <summary>
 /// Gets the 'Any' type.
 /// </summary>
 /// <param name="owner"></param>
 /// <returns></returns>
 public static IVplType GetAnyType(this IElementOwner owner)
 {
     return(owner.GetVplTypeOrThrow(VplTypeId.Any));
 }
 public ReturnValueVariable(IElementOwner owner, IVplType type)
     : base(owner, type, ReturnVariableId)
 {
 }
Exemplo n.º 34
0
        private void AddToOwner(IElementOwner owner,  IEnumerable<VariableMetadata> variableMetadatas)
        {
            if (owner == null) throw new ArgumentNullException(nameof(owner));
            if (variableMetadatas == null) throw new ArgumentNullException(nameof(variableMetadatas));

            foreach (var variableMetadata in variableMetadatas)
            {
                var variableType = owner.GetVplTypeOrThrow(variableMetadata.TypeId);

                var variable = new Variable(owner, variableType, variableMetadata.Id)
                {
                    Name = variableMetadata.Name
                };

                owner.AddVariable(variable);
            }
        }
Exemplo n.º 35
0
        public void AddToOwner(IElementOwner owner, IEnumerable<ElementMetadata> rootElements)
        {
            if (rootElements == null) throw new ArgumentNullException(nameof(rootElements));
            if (owner == null) throw new ArgumentNullException(nameof(owner));

            foreach (var elementMetadata in rootElements)
            {
                var element = CreateElement(owner, elementMetadata);

                owner.Add(element);
            }
        }       
Exemplo n.º 36
0
 /// <summary>
 /// Gets the string VplType.
 /// </summary>
 /// <param name="owner"></param>
 /// <returns></returns>
 public static IVplType GetStringType(this IElementOwner owner)
 {
     return(owner.GetVplTypeOrThrow(VplTypeId.String));
 }
Exemplo n.º 37
0
 public DefaultFunctionSelector(IElementOwner owner)
 {
     if (owner == null) throw new ArgumentNullException(nameof(owner));
     _owner = owner;
 }
Exemplo n.º 38
0
 /// <summary>
 /// Gets the service of the specified type.
 /// </summary>
 /// <typeparam name="TService"></typeparam>
 /// <param name="owner"></param>
 /// <returns></returns>
 public static TService GetService <TService>(this IElementOwner owner)
 {
     return(owner.Context.Services
            .OfType <TService>()
            .FirstOrDefault());
 }