Exemple #1
0
        /// <summary>
        /// Invoke plugin initPlugin Method
        /// </summary>
        public void InitPlugin()
        {
            //  Button b = sender as Button;

            //....Dev Plugin...toolstrip code.
            string dkey = pluginName;

            if (PluginUtility._StandardIOPlugins.ContainsKey(dkey))
            {
                StandardIO dplugin = PluginUtility._StandardIOPlugins[dkey];
                //dplugin.Start();

                dynamic devType = dplugin.GetType();
                dynamic dev     = Activator.CreateInstance(devType);


                dynamic methodStart = devType.GetMethod("Init");
                methodStart.Invoke(dev, new object[] { });


                dynamic actionProperty = devType.GetProperty("command");
                if (actionProperty != null)
                {
                    Dictionary <string, Action <string> > actionVal = actionProperty.GetValue(dev);
                    foreach (var action in actionVal)
                    {
                        //action.Value.DynamicInvoke("");
                        char[]   separator   = { ' ' };
                        string[] actionArray = action.Key.Split(separator, StringSplitOptions.RemoveEmptyEntries);
                        if (actionArray[0] == "create")
                        {
                            if (actionArray[1] == "menu")
                            {
                                ToolStripMenuItem topStripMenuItem = new ToolStripMenuItem();

                                topStripMenuItem.Name = "topToolStripMenuItem";
                                //newToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.N)));
                                topStripMenuItem.Text = actionArray[2];
                                topStripMenuItem.Name = actionArray[3];
                                topStripMenuItem.Tag  = pluginName;

                                topStripMenuItem.Click += new EventHandler(TopMenuItem_click);

                                menuStrip.Items.AddRange(new ToolStripItem[] {
                                    topStripMenuItem
                                });
                                //Console.WriteLine(actionArray[2]);
                            }
                        }
                    }
                }

                //MessageBox.Show(eventval);
            }
            //...End dev...
        }
        //start
        public static ICollection <StandardIO> LoadDevPlugins(string path)
        {
            string[] dllFileNames = null;

            if (Directory.Exists(path))
            {
                dllFileNames = Directory.GetFiles(path, "*.dll");

                ICollection <Assembly> assemblies = new List <Assembly>(dllFileNames.Length);
                foreach (string dllFile in dllFileNames)
                {
                    AssemblyName an       = AssemblyName.GetAssemblyName(dllFile);
                    Assembly     assembly = Assembly.Load(an);
                    assemblies.Add(assembly);
                }

                Type pluginType = typeof(StandardIO);
                ICollection <Type> pluginTypes = new List <Type>();
                foreach (Assembly assembly in assemblies)
                {
                    if (assembly != null)
                    {
                        Type[] types = assembly.GetTypes();

                        foreach (Type type in types)
                        {
                            if (type.IsInterface || type.IsAbstract)
                            {
                                continue;
                            }
                            else
                            {
                                if (type.GetInterface(pluginType.FullName) != null)
                                {
                                    pluginTypes.Add(type);
                                }
                            }
                        }
                    }
                }

                ICollection <StandardIO> plugins = new List <StandardIO>(pluginTypes.Count);
                foreach (Type type in pluginTypes)
                {
                    StandardIO plugin = (StandardIO)Activator.CreateInstance(type);
                    plugins.Add(plugin);
                }

                return(plugins);
            }

            return(null);
        }
Exemple #3
0
    } //constructor

    /// <summary>
    /// Starts the process and creates  output worker threads.
    /// Returns the underlying process object which can also be obtained by
    /// BaseProcess property.
    /// </summary>
    /// <returns></returns>
    public System.Diagnostics.Process Start()
    {
        m_StdOutWaitHandle = new ManualResetEvent(false);
        m_StdErrWaitHandle = new ManualResetEvent(false);

        //Create objects for worker threads.
        //These will call back on the this pointer to return the output.
        m_StdOutWorker = new StandardIO(m_Process, IOType.Output, m_StdOutWaitHandle, this);
        m_StdErrWorker = new StandardIO(m_Process, IOType.Error, m_StdErrWaitHandle, this);
        m_Process.Start();

        ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(m_StdOutWorker.GetOutput));
        ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(m_StdErrWorker.GetOutput));

        m_Started = true;
        return(m_Process);
    } //Execute()
    static public void Main()
    {
        ICache  _cache  = new Redis();
        IHttp   _http   = new Http();
        ILogger _logger = new  StandardIO();

        var exchange = new ExchangeService(_cache, _http, _logger);

        var newValue = exchange.ConvertTo(13.5, "USD", "COP");

        System.Console.WriteLine(newValue);

        newValue = exchange.ConvertTo(5, "USD", "COP");
        System.Console.WriteLine(newValue);

        newValue = exchange.ConvertTo(13.5, "USD", "BRL");
        System.Console.WriteLine(newValue);
    }
        /**
         * Get Plugin Version
         */
        public static dynamic getPlugin_Property(StandardIO item, string plugin_property)
        {
            dynamic version = null;
            dynamic devType = item.GetType();
            dynamic dev     = Activator.CreateInstance(devType);

            dynamic property = devType.GetProperty(plugin_property);

            if (property != null)
            {
                version = property.GetValue(dev);
                return(version);
            }
            else
            {
                version = null;
                return(version);
            }
        }
Exemple #6
0
        /// <summary>
        /// Set language specific syntax
        /// </summary>
        public void SetKeywordWithExt()
        {
            if (PluginUtility._StandardIOPlugins.ContainsKey(pluginName))
            {
                StandardIO item = PluginUtility._StandardIOPlugins[pluginName];
                if (PluginUtility.getPlugin_Property(item, "SetExt") != null)
                {
                    var extProperty = PluginUtility.getPlugin_Property(item, "SetExt");

                    //spliting string with separator
                    char[]   separatorExtSet = { '|' };
                    string[] allExt          = extProperty.Split(separatorExtSet, StringSplitOptions.RemoveEmptyEntries);

                    foreach (var ext in allExt)
                    {
                        char[]   separatorExt = { '@' };
                        string[] ExtSet       = ext.Split(separatorExt, StringSplitOptions.RemoveEmptyEntries);
                        KeywordWithExt.Add(ExtSet[0], ExtSet[1]);
                    }
                }
            }
        }
        /**
         * Get plugin property by key and return version
         */
        public static dynamic getPlugin_PropertyByKey(string key, string plugin_property)
        {
            dynamic version = null;

            PluginUtility._StandardIOPlugins.ContainsKey(key);
            StandardIO plugin = PluginUtility._StandardIOPlugins[key];

            dynamic devType = plugin.GetType();
            dynamic dev     = Activator.CreateInstance(devType);

            dynamic property = devType.GetProperty(plugin_property);

            if (property != null)
            {
                version = property.GetValue(dev);
                return(version);
            }
            else
            {
                version = null;
                return(version);
            }
        }
Exemple #8
0
        /// <summary>
        /// Plugin Common Code
        /// </summary>
        public void Plugin_Common(string dkey, PluginComponent component)
        {
            if (PluginUtility._StandardIOPlugins.ContainsKey(dkey))
            {
                //get GetRichTextBox() value
                string editorValue = GetRichTextBox().Text;

                StandardIO dplugin = PluginUtility._StandardIOPlugins[dkey];
                //dplugin.Start();

                dynamic devType = dplugin.GetType();
                dynamic dev     = Activator.CreateInstance(devType);

                dynamic property = devType.GetProperty("GetEditorText");
                if (property != null)
                {
                    property.SetValue(dev, editorValue);
                }


                dynamic eventProperty = devType.GetProperty("GetEditorText");
                if (eventProperty != null)
                {
                    dynamic eventval = eventProperty.GetValue(dev);
                }


                //setting file extension
                dynamic extension = devType.GetProperty("FileExtension");
                if (extension != null)
                {
                    extension.SetValue(dev, FileExtension);
                }

                //dynamic ext = extension.GetValue(dev);
                //setting file address
                if (String.IsNullOrEmpty(FileAddress))
                {
                }
                else
                {
                    try
                    {
                        string  getileurl = FileAddress.ToString();
                        dynamic fileurl   = devType.GetProperty("FileAddress");

                        if (fileurl != null)
                        {
                            fileurl.SetValue(dev, getileurl);
                        }
                        //dynamic Getfileurl = fileurl.GetValue(dev);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }


                if (component == PluginComponent.TopToolStripMenu)
                {
                    // invoke custom method
                    dynamic actionProperty = devType.GetProperty("command");
                    if (actionProperty != null)
                    {
                        Dictionary <string, Action <string> > actionVal = actionProperty.GetValue(dev);
                        foreach (var action in actionVal)
                        {
                            action.Value.DynamicInvoke("");
                        }
                    }
                }
                else
                {
                    dynamic methodStart = devType.GetMethod("Start");
                    methodStart.Invoke(dev, new object[] { });
                }

                //MessageBox.Show(eventval);
            }
        }
Exemple #9
0
        public void TopMenuItem_click(object sender, EventArgs args)
        {
            // Custom menu created in plugin
            ToolStripMenuItem toolstripbtn = sender as ToolStripMenuItem;
            // custom method key
            string subdkey = toolstripbtn.Name.ToString();


            string dkey = toolstripbtn.Tag.ToString();

            if (PluginUtility._StandardIOPlugins.ContainsKey(dkey))
            {
                string editorValue = GetRichTextBox().Text;

                StandardIO dplugin = PluginUtility._StandardIOPlugins[dkey];
                //dplugin.Start();

                dynamic devType = dplugin.GetType();
                dynamic dev     = Activator.CreateInstance(devType);


                //dynamic methodStart = devType.GetMethod("Init");
                //methodStart.Invoke(dev, new object[] { });

                dynamic property = devType.GetProperty("GetEditorText");
                if (property != null)
                {
                    property.SetValue(dev, editorValue);
                }


                dynamic eventProperty = devType.GetProperty("GetEditorText");
                if (eventProperty != null)
                {
                    dynamic eventval = eventProperty.GetValue(dev);
                }


                //setting file extension
                dynamic extension = devType.GetProperty("FileExtension");
                if (extension != null)
                {
                    extension.SetValue(dev, FileExtension);
                }

                if (String.IsNullOrEmpty(FileAddress))
                {
                }
                else
                {
                    try
                    {
                        string  getileurl = FileAddress.ToString();
                        dynamic fileurl   = devType.GetProperty("FileAddress");

                        if (fileurl != null)
                        {
                            fileurl.SetValue(dev, getileurl);
                        }
                        //dynamic Getfileurl = fileurl.GetValue(dev);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }


                dynamic actionProperty = devType.GetProperty("command");
                if (actionProperty != null)
                {
                    Dictionary <string, Action <string> > actionVal = actionProperty.GetValue(dev);
                    foreach (var action in actionVal)
                    {
                        //action.Value.DynamicInvoke("");
                        char[]   separator   = { ' ' };
                        string[] actionArray = action.Key.Split(separator, StringSplitOptions.RemoveEmptyEntries);
                        if (actionArray[0] == "create")
                        {
                            if (actionArray[1] == "menu")
                            {
                                if (subdkey == actionArray[3])
                                {
                                    action.Value.DynamicInvoke("");
                                    //MessageBox.Show(actionArray[3]);
                                }
                            }
                        }
                    }
                }

                //MessageBox.Show(eventval);
            }



            //Plugin_Event(sender,args, PluginComponent.TopToolStripMenu);

            /*       dynamic actionProperty = devType.GetProperty("command");
             *     if (actionProperty != null)
             *     {
             *         Dictionary<string, Action<string>> actionVal = actionProperty.GetValue(dev);
             *         foreach (var action in actionVal)
             *         {
             *             //action.Value.DynamicInvoke("");
             *             char[] separator = { ' ' };
             *             string[] actionArray = action.Key.Split(separator, StringSplitOptions.RemoveEmptyEntries);
             *             MessageBox.Show("Hello WOrld");
             *         }
             *     } */
        }
Exemple #10
0
    } //constructor

    /// <summary>
    /// Starts the process and creates  output worker threads.
    /// Returns the underlying process object which can also be obtained by
    /// BaseProcess property.
    /// </summary>
    /// <returns></returns>
    public System.Diagnostics.Process Start()
    {
        m_StdOutWaitHandle = new ManualResetEvent(false);
        m_StdErrWaitHandle = new ManualResetEvent(false);
    
        //Create objects for worker threads.  
        //These will call back on the this pointer to return the output.
        m_StdOutWorker = new StandardIO(m_Process, IOType.Output, m_StdOutWaitHandle, this);
        m_StdErrWorker = new StandardIO(m_Process, IOType.Error, m_StdErrWaitHandle, this);
        m_Process.Start();
    
        ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(m_StdOutWorker.GetOutput));
        ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(m_StdErrWorker.GetOutput));
    
        m_Started = true;
        return m_Process;

    } //Execute()
Exemple #11
0
    static void Main(string[] args)
    {
        var io = new StandardIO();

        new Process(io).Run();
    }