Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ComponentVM"/> class.
        /// </summary>
        /// <param name="info">The information.</param>
        /// <param name="context">The context.</param>
        internal ComponentVM(SerializationInfo info, StreamingContext context)
        {
            this.node = (IDisplayableNode)info.GetValue(nameof(this.Node), typeof(IDisplayableNode));

            this.XCoord    = (double)info.GetValue(nameof(this.XCoord), typeof(double));
            this.YCoord    = (double)info.GetValue(nameof(this.YCoord), typeof(double));
            this.IsInField = (bool)info.GetValue(nameof(this.IsInField), typeof(bool));

            this.uniqueName = (string)info.GetValue(nameof(this.Name), typeof(string));

            this.removeCommand = (Command)info.GetValue(nameof(this.RemoveComponentCommand), typeof(Command));
        }
Ejemplo n.º 2
0
        // all nodes in components folder user to choose from
        public List <IDisplayableNode> GetNodes(string filePath)
        {
            List <IDisplayableNode> nodes = new List <IDisplayableNode>();

            if (Directory.Exists(filePath))
            {
                DirectoryInfo   dI    = new DirectoryInfo(filePath);
                DirectoryInfo[] dirs  = dI.GetDirectories();
                List <FileInfo> files = dI.GetFiles().ToList();

                foreach (var dir in dirs)
                {
                    foreach (var f in dir.GetFiles())
                    {
                        files.Add(f);
                    }
                }


                foreach (var file in files)
                {
                    try
                    {
                        Assembly ass = Assembly.LoadFrom(file.FullName);

                        foreach (var type in ass.GetExportedTypes())
                        {
                            foreach (var interfc in type.GetInterfaces())
                            {
                                if ((interfc) == typeof(IDisplayableNode))
                                {
                                    try
                                    {
                                        IDisplayableNode node = (IDisplayableNode)Activator.CreateInstance(type);
                                        nodes.Add(node);
                                    }
                                    catch (Exception e)
                                    {
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception)
                    {
                    }
                }
            }

            return(nodes);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Loads the single assembly.
        /// </summary>
        /// <param name="filePath">The file path.</param>
        /// <param name="configPath">The configuration path.</param>
        /// <returns>Returns list of node tuples with relative path to assembly.</returns>
        public static List <Tuple <IDisplayableNode, string> > LoadSingleAssembly(string filePath, string configPath)
        {
            List <Tuple <IDisplayableNode, string> > nodes = new List <Tuple <IDisplayableNode, string> >();
            var fullConf = Path.GetFullPath(configPath);

            var combinedConf = fullConf + filePath;

            if (File.Exists(combinedConf) && (Path.GetExtension(combinedConf) == ".dll" || Path.GetExtension(combinedConf) == ".exe"))
            {
                try
                {
                    Assembly ass = Assembly.LoadFrom(@combinedConf);

                    // Assembly ass = Assembly.Load(file.FullName);
                    foreach (var type in ass.GetExportedTypes())
                    {
                        foreach (var interfc in type.GetInterfaces())
                        {
                            if (interfc == typeof(IDisplayableNode))
                            {
                                try
                                {
                                    IDisplayableNode node = (IDisplayableNode)Activator.CreateInstance(type);

                                    if (ValidateNode(node))
                                    {
                                        nodes.Add(new Tuple <IDisplayableNode, string>(node, combinedConf));
                                    }
                                }
                                catch (Exception)
                                {
                                }
                            }
                        }
                    }
                }
                catch (Exception)
                {
                }
            }

            return(nodes);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ComponentVM" /> class.
        /// </summary>
        /// <param name="realComponent">The real component.</param>
        /// <param name="uniqueName">The unique name of the component.</param>
        /// <param name="pindIdAtion">The pin identifier action.</param>
        /// <param name="setPinCommand">The set pin command.</param>
        /// <param name="removeCommand">The remove command.</param>
        /// <param name="configurationLogic">The configuration logic.</param>
        public ComponentVM(
            IDisplayableNode realComponent,
            string uniqueName,
            IEnumerator <int> pindIdAtion,
            Command setPinCommand,
            Command removeCommand,
            ConfigurationLogic configurationLogic)
        {
            this.node          = realComponent;
            this.uniqueName    = uniqueName;
            this.removeCommand = removeCommand;
            this.config        = configurationLogic;

            this.node.PictureChanged += this.OnPictureChanged;

            this.OutputPinsVM = new ObservableCollection <PinVM>();
            this.InputPinsVM  = new ObservableCollection <PinVM>();

            foreach (var pin in this.node.Outputs)
            {
                if (pin != null)
                {
                    pindIdAtion.MoveNext();
                    this.OutputPinsVM.Add(new PinVM(pin, pindIdAtion.Current, false, setPinCommand, this, this.config.PinActiveColor, this.config.PinPassiveColor));

                    // this.OutputPinsVM.Add(new PinVM(pin, false, setPinCommand));
                }
            }

            foreach (var pin in this.node.Inputs)
            {
                if (pin != null)
                {
                    pindIdAtion.MoveNext();
                    this.InputPinsVM.Add(new PinVM(pin, pindIdAtion.Current, true, setPinCommand, this, this.config.PinActiveColor, this.config.PinPassiveColor));

                    // this.InputPinsVM.Add(new PinVM(pin, true, setPinCommand));
                }
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Validates the node content and checks for missing necessary properties.
        /// </summary>
        /// <param name="node">The node that contains the data of a electric component.</param>
        /// <returns>Returns true if the node is valid or returns false if not.</returns>
        private static bool ValidateNode(IDisplayableNode node)
        {
            if (node.Description == null || node.Description == string.Empty)
            {
                return(false);
            }

            if (node.Inputs == null || node.Outputs == null)
            {
                return(false);
            }

            if (node.Picture == null || node.Picture.Width <= 0 || node.Picture.Height <= 0)
            {
                return(false);
            }

            if (node.Label == null || node.Label == string.Empty)
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ComponentRepresentationVM"/> class.
 /// </summary>
 /// <param name="addCommand">The add command for adding real components to the designer field.</param>
 /// <param name="node">The node that will be added then.</param>
 /// <param name="assemblyPath">The assembly path.</param>
 public ComponentRepresentationVM(Command addCommand, IDisplayableNode node, string assemblyPath)
 {
     this.AddComponentCommand = addCommand;
     this.node         = node;
     this.AssemblyPath = assemblyPath;
 }
Ejemplo n.º 7
0
 public NodeVM(IDisplayableNode node)
 {
     this.node = node;
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Gets the nodes.
        /// </summary>
        /// <param name="filePath">The file path.</param>
        /// <param name="configPath">The configuration path.</param>
        /// <returns>Returns a list with tuples node and path.</returns>
        public List <Tuple <IDisplayableNode, string> > GetNodes(string filePath, string configPath)
        {
            List <Tuple <IDisplayableNode, string> > nodes = new List <Tuple <IDisplayableNode, string> >();

            if (Directory.Exists(filePath))
            {
                DirectoryInfo        dI   = new DirectoryInfo(filePath);
                List <DirectoryInfo> dirs = dI.GetDirectories().ToList();
                dirs.Add(dI);
                List <FileInfo> files = new List <FileInfo>();

                foreach (var dir in dirs)
                {
                    foreach (var f in dir.GetFiles("*.dll"))
                    {
                        files.Add(f);
                    }

                    foreach (var f in dir.GetFiles("*.exe"))
                    {
                        files.Add(f);
                    }
                }

                foreach (var file in files)
                {
                    try
                    {
                        string fullpath  = Path.GetFullPath(file.FullName);
                        var    splitPath = fullpath.Replace(Path.GetFullPath(configPath), string.Empty);
                        var    fullConf  = Path.GetFullPath(configPath);

                        var combinedConf = fullConf + splitPath;

                        Assembly ass = Assembly.LoadFrom(@combinedConf);

                        // Assembly ass = Assembly.Load(file.FullName);
                        foreach (var type in ass.GetExportedTypes())
                        {
                            foreach (var interfc in type.GetInterfaces())
                            {
                                if (interfc == typeof(IDisplayableNode))
                                {
                                    try
                                    {
                                        IDisplayableNode node = (IDisplayableNode)Activator.CreateInstance(type);

                                        if (ValidateNode(node))
                                        {
                                            nodes.Add(new Tuple <IDisplayableNode, string>(node, splitPath));
                                        }
                                    }
                                    catch (Exception)
                                    {
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception)
                    {
                    }
                }
            }
            else
            {
                Directory.CreateDirectory(filePath);
            }

            return(nodes);
        }