Example #1
0
        public static void LoadPlugins(IOpenRPAClient client)
        {
            var sw = new System.Diagnostics.Stopwatch();

            sw.Start();

            IEnumerable <System.Reflection.Assembly> assemblies = AppDomain.CurrentDomain.GetAssemblies().OrderBy(a => a.GetName().Name);
            ICollection <Type> alltypes             = new List <Type>();
            ICollection <Type> pluginTypes          = new List <Type>();
            ICollection <Type> snippetTypes         = new List <Type>();
            ICollection <Type> runPluginTypes       = new List <Type>();
            ICollection <Type> IDetectorPluginTypes = new List <Type>();

            Log.Information("LoadPlugins::Get types " + string.Format("{0:mm\\:ss\\.fff}", sw.Elapsed));
            foreach (var a in assemblies)
            {
                try
                {
                    foreach (var s in a.GetTypes())
                    {
                        alltypes.Add(s);
                    }
                }
                catch (Exception) { }
            }

            Log.Information("LoadPlugins::Get all IRecordPlugins " + string.Format("{0:mm\\:ss\\.fff}", sw.Elapsed));
            var IRecordPlugintype = typeof(IRecordPlugin);

            foreach (var p in alltypes)
            {
                try
                {
                    if (IRecordPlugintype.IsAssignableFrom(p) && p.IsInterface == false)
                    {
                        pluginTypes.Add(p);
                    }
                }
                catch (Exception) { }
            }
            Log.Information("LoadPlugins::Get all IDetectorPlugin " + string.Format("{0:mm\\:ss\\.fff}", sw.Elapsed));
            var IDetectorPlugintype = typeof(IDetectorPlugin);

            foreach (var p in alltypes)
            {
                try
                {
                    if (IDetectorPlugintype.IsAssignableFrom(p) && p.IsInterface == false)
                    {
                        IDetectorPluginTypes.Add(p);
                    }
                }
                catch (Exception) { }
            }

            Log.Information("LoadPlugins::Get all ISnippet " + string.Format("{0:mm\\:ss\\.fff}", sw.Elapsed));
            var ISnippettype = typeof(ISnippet);

            foreach (var p in alltypes)
            {
                try
                {
                    if (ISnippettype.IsAssignableFrom(p) && p.IsInterface == false)
                    {
                        snippetTypes.Add(p);
                    }
                }
                catch (Exception) { }
            }

            Log.Information("LoadPlugins::Get all IRunPlugin " + string.Format("{0:mm\\:ss\\.fff}", sw.Elapsed));
            var IRunPlugintype = typeof(IRunPlugin);

            foreach (var p in alltypes)
            {
                try
                {
                    if (IRunPlugintype.IsAssignableFrom(p) && p.IsInterface == false)
                    {
                        runPluginTypes.Add(p);
                    }
                }
                catch (Exception) { }
            }
            Log.Information("LoadPlugins::Get all ICustomWorkflowExtension " + string.Format("{0:mm\\:ss\\.fff}", sw.Elapsed));
            var WorkflowExtensiontype = typeof(ICustomWorkflowExtension);

            foreach (var p in alltypes)
            {
                try
                {
                    if (WorkflowExtensiontype.IsAssignableFrom(p) && p.IsInterface == false)
                    {
                        if (!WorkflowExtensionsTypes.Contains(p))
                        {
                            WorkflowExtensionsTypes.Add(p);
                        }
                    }
                }
                catch (Exception) { }
            }


            foreach (var type in IDetectorPluginTypes)
            {
                if (!detectorPluginTypes.ContainsKey(type.FullName))
                {
                    detectorPluginTypes.Add(type.FullName, type);
                }
            }
            foreach (Type type in pluginTypes)
            {
                try
                {
                    IRecordPlugin plugin = null;
                    foreach (var p in recordPlugins)
                    {
                        if (p.GetType() == type)
                        {
                            plugin = p;
                            break;
                        }
                    }
                    if (plugin == null)
                    {
                        plugin = (IRecordPlugin)Activator.CreateInstance(type);
                        Log.Information("LoadPlugins::Initialize plugin " + plugin.Name + " " + string.Format("{0:mm\\:ss\\.fff}", sw.Elapsed));
                        // SetStatus("Initialize plugin " + plugin.Name);
                        plugin.Initialize(client);
                        GenericTools.RunUI(() => recordPlugins.Add(plugin));
                    }
                }
                catch (Exception ex)
                {
                    Log.Error(ex.ToString());
                }
            }
            foreach (Type type in snippetTypes)
            {
                try
                {
                    ISnippet plugin = null;
                    foreach (var p in Snippets)
                    {
                        if (p.GetType() == type)
                        {
                            plugin = p;
                            break;
                        }
                    }
                    if (plugin == null)
                    {
                        plugin = (ISnippet)Activator.CreateInstance(type);
                        Log.Information("LoadPlugins::Initialize snippet " + plugin.Name + string.Format("{0:mm\\:ss\\.fff}", sw.Elapsed));
                        Snippets.Add(plugin);
                    }
                }
                catch (Exception ex)
                {
                    Log.Error(ex.ToString());
                }
            }
            foreach (Type type in runPluginTypes)
            {
                try
                {
                    IRunPlugin plugin = null;
                    foreach (var p in runPlugins)
                    {
                        if (p.GetType() == type)
                        {
                            plugin = p;
                            break;
                        }
                    }

                    if (plugin == null)
                    {
                        plugin = (IRunPlugin)Activator.CreateInstance(type);
                        Log.Information("LoadPlugins::Initialize RunPlugin " + plugin.Name + string.Format("{0:mm\\:ss\\.fff}", sw.Elapsed));
                        plugin.Initialize(client);
                        GenericTools.RunUI(() => runPlugins.Add(plugin));
                    }
                }
                catch (Exception ex)
                {
                    Log.Error(ex.ToString());
                }
            }
            Log.Information("LoadPlugins::end " + string.Format("{0:mm\\:ss\\.fff}", sw.Elapsed));
        }
Example #2
0
 public static void restore(IntPtr hWnd)
 {
     GenericTools.ShowWindow(hWnd, GenericTools.SW_RESTORE);
     GenericTools.SetForegroundWindow(hWnd);
 }
Example #3
0
        public static void LoadPlugins(IOpenRPAClient client, string projectsDirectory)
        {
            var sw = new System.Diagnostics.Stopwatch();

            sw.Start();
            Log.Information("LoadPlugins::begin " + string.Format("{0:mm\\:ss\\.fff}", sw.Elapsed));
            ICollection <Type> alltypes             = new List <Type>();
            ICollection <Type> pluginTypes          = new List <Type>();
            ICollection <Type> snippetTypes         = new List <Type>();
            ICollection <Type> runPluginTypes       = new List <Type>();
            ICollection <Type> IDetectorPluginTypes = new List <Type>();

            List <string> dllFileNames = new List <string>();

            foreach (var path in System.IO.Directory.GetFiles(projectsDirectory, "*.dll"))
            {
                dllFileNames.Add(path);
            }
            ICollection <Assembly> assemblies = new List <Assembly>();

            foreach (string dllFile in dllFileNames)
            {
                try
                {
                    // if (dllFile.Contains("OpenRPA.Interfaces.")) continue;
                    if (dllFile.Contains("DotNetProjects."))
                    {
                        continue;
                    }
                    if (dllFile.Contains("Emgu."))
                    {
                        continue;
                    }
                    if (dllFile.Contains("Microsoft.CodeAnalysis."))
                    {
                        continue;
                    }
                    if (dllFile.Contains("Microsoft.Office."))
                    {
                        continue;
                    }
                    if (dllFile.Contains("NuGet."))
                    {
                        continue;
                    }
                    if (dllFile.Contains("System.Collections."))
                    {
                        continue;
                    }
                    if (dllFile.Contains("System.ComponentModel."))
                    {
                        continue;
                    }
                    if (dllFile.Contains("System.Composition."))
                    {
                        continue;
                    }
                    if (dllFile.Contains("System.Data."))
                    {
                        continue;
                    }
                    if (dllFile.Contains("System.Diagnostics."))
                    {
                        continue;
                    }
                    if (dllFile.Contains("System.Globalization."))
                    {
                        continue;
                    }
                    if (dllFile.Contains("System.IO."))
                    {
                        continue;
                    }
                    if (dllFile.Contains("System.Linq."))
                    {
                        continue;
                    }
                    if (dllFile.Contains("System.Net."))
                    {
                        continue;
                    }
                    if (dllFile.Contains("System.Reflection."))
                    {
                        continue;
                    }
                    if (dllFile.Contains("System.Resources."))
                    {
                        continue;
                    }
                    if (dllFile.Contains("System.Runtime."))
                    {
                        continue;
                    }
                    if (dllFile.Contains("System.Security."))
                    {
                        continue;
                    }
                    if (dllFile.Contains("System.Text."))
                    {
                        continue;
                    }
                    if (dllFile.Contains("System.Threading."))
                    {
                        continue;
                    }
                    if (dllFile.Contains("System.Xml."))
                    {
                        continue;
                    }
                    if (dllFile.Contains("System.Windows."))
                    {
                        continue;
                    }
                    if (dllFile.Contains("ToastNotifications."))
                    {
                        continue;
                    }
                    if (dllFile.Contains("Xceed.Wpf."))
                    {
                        continue;
                    }
                    if (dllFile.Contains("ControlzEx."))
                    {
                        continue;
                    }
                    if (dllFile.Contains("MahApps."))
                    {
                        continue;
                    }
                    if (dllFile.Contains("Interop.SAPFEWSELib"))
                    {
                        continue;
                    }
                    if (dllFile.Contains("Interop.SapROTWr"))
                    {
                        continue;
                    }
                    AssemblyName an       = AssemblyName.GetAssemblyName(dllFile);
                    Assembly     assembly = Assembly.Load(an);
                    assemblies.Add(assembly);
                }
                catch (Exception ex)
                {
                    Log.Error(ex, "");
                }
            }
            Log.Information("LoadPlugins::Get types " + string.Format("{0:mm\\:ss\\.fff}", sw.Elapsed));
            foreach (var a in assemblies)
            {
                try
                {
                    foreach (var s in a.GetTypes())
                    {
                        alltypes.Add(s);
                    }
                }
                catch (Exception) { }
            }

            Log.Information("LoadPlugins::Get all IRecordPlugins " + string.Format("{0:mm\\:ss\\.fff}", sw.Elapsed));
            var IRecordPlugintype = typeof(IRecordPlugin);

            foreach (var p in alltypes)
            {
                try
                {
                    if (IRecordPlugintype.IsAssignableFrom(p) && p.IsInterface == false)
                    {
                        pluginTypes.Add(p);
                    }
                }
                catch (Exception) { }
            }
            Log.Information("LoadPlugins::Get all IDetectorPlugin " + string.Format("{0:mm\\:ss\\.fff}", sw.Elapsed));
            var IDetectorPlugintype = typeof(IDetectorPlugin);

            foreach (var p in alltypes)
            {
                try
                {
                    if (IDetectorPlugintype.IsAssignableFrom(p) && p.IsInterface == false)
                    {
                        IDetectorPluginTypes.Add(p);
                    }
                }
                catch (Exception) { }
            }

            Log.Information("LoadPlugins::Get all ISnippet " + string.Format("{0:mm\\:ss\\.fff}", sw.Elapsed));
            var ISnippettype = typeof(ISnippet);

            foreach (var p in alltypes)
            {
                try
                {
                    if (ISnippettype.IsAssignableFrom(p) && p.IsInterface == false)
                    {
                        snippetTypes.Add(p);
                    }
                }
                catch (Exception) { }
            }

            Log.Information("LoadPlugins::Get all IRunPlugin " + string.Format("{0:mm\\:ss\\.fff}", sw.Elapsed));
            var IRunPlugintype = typeof(IRunPlugin);

            foreach (var p in alltypes)
            {
                try
                {
                    if (IRunPlugintype.IsAssignableFrom(p) && p.IsInterface == false)
                    {
                        runPluginTypes.Add(p);
                    }
                }
                catch (Exception) { }
            }

            foreach (var type in IDetectorPluginTypes)
            {
                Plugins.detectorPluginTypes.Add(type.FullName, type);
            }
            foreach (Type type in pluginTypes)
            {
                try
                {
                    IRecordPlugin plugin = (IRecordPlugin)Activator.CreateInstance(type);
                    Log.Information("LoadPlugins::Initialize plugin " + plugin.Name + " " + string.Format("{0:mm\\:ss\\.fff}", sw.Elapsed));
                    // SetStatus("Initialize plugin " + plugin.Name);
                    plugin.Initialize(client);
                    GenericTools.RunUI(() => recordPlugins.Add(plugin));
                }
                catch (Exception ex)
                {
                    Log.Error(ex.ToString());
                }
            }
            foreach (Type type in snippetTypes)
            {
                try
                {
                    ISnippet plugin = (ISnippet)Activator.CreateInstance(type);
                    Log.Information("LoadPlugins::Initialize snippet " + plugin.Name + string.Format("{0:mm\\:ss\\.fff}", sw.Elapsed));
                    Snippets.Add(plugin);
                }
                catch (Exception ex)
                {
                    Log.Error(ex.ToString());
                }
            }
            foreach (Type type in runPluginTypes)
            {
                try
                {
                    IRunPlugin plugin = (IRunPlugin)Activator.CreateInstance(type);
                    Log.Information("LoadPlugins::Initialize RunPlugin " + plugin.Name + string.Format("{0:mm\\:ss\\.fff}", sw.Elapsed));
                    plugin.Initialize(client);
                    GenericTools.RunUI(() => runPlugins.Add(plugin));
                }
                catch (Exception ex)
                {
                    Log.Error(ex.ToString());
                }
            }
            Log.Information("LoadPlugins::end " + string.Format("{0:mm\\:ss\\.fff}", sw.Elapsed));
        }
Example #4
0
 public static void minimize(IntPtr hWnd)
 {
     GenericTools.ShowWindow(hWnd, GenericTools.SW_MINIMIZE);
 }
Example #5
0
        void OnBaseCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            var collection = Items;

            if (collection != null)
            {
                // Check the NewItems
                List <T> newlist = new List <T>();
                if (e.NewItems != null)
                {
                    foreach (T item in e.NewItems)
                    {
                        if (_filter(item) == true)
                        {
                            newlist.Add(item);
                        }
                    }
                }

                // Check the OldItems
                List <T> oldlist = new List <T>();
                //if (e.OldItems != null)
                //    foreach (T item in e.OldItems)
                //        if (_filter(item) == true)
                //            oldlist.Add(item);
                if (e.OldItems != null)
                {
                    foreach (T item in e.OldItems)
                    {
                        oldlist.Add(item);
                    }
                }

                // Create the Add/Remove/Replace lists
                List <T> addlist     = new List <T>();
                List <T> removelist  = new List <T>();
                List <T> replacelist = new List <T>();

                // Fill the Add/Remove/Replace lists
                foreach (T item in newlist)
                {
                    if (oldlist.Contains(item))
                    {
                        replacelist.Add(item);
                    }
                    else
                    {
                        addlist.Add(item);
                    }
                }
                foreach (T item in oldlist)
                {
                    if (newlist.Contains(item))
                    {
                        continue;
                    }
                    else
                    {
                        removelist.Add(item);
                    }
                }


                if (e.NewItems != null && e.Action == NotifyCollectionChangedAction.Replace)
                {
                    foreach (var item in e.NewItems)
                    {
                        bool shouldbehere = false;
                        bool ishere       = false;
                        var  titem        = (T)item;
                        if (!shouldbehere)
                        {
                            shouldbehere = _filter(titem);
                        }
                        if (!ishere)
                        {
                            ishere = Items.Contains(titem);
                        }
                        if (shouldbehere && !ishere && !addlist.Contains(titem))
                        {
                            addlist.Add(titem);
                        }
                        if (!shouldbehere && ishere && !removelist.Contains(titem))
                        {
                            removelist.Add(titem);
                        }
                    }
                }


                foreach (T item in addlist)
                {
                    Items.Add(item);
                }
                foreach (T item in removelist)
                {
                    Items.Remove(item);
                }
                // Send the corrected event
                GenericTools.RunUI(() =>
                {
                    switch (e.Action)
                    {
                    case NotifyCollectionChangedAction.Add:
                    case NotifyCollectionChangedAction.Move:
                    case NotifyCollectionChangedAction.Remove:
                    case NotifyCollectionChangedAction.Replace:
                        if (addlist.Count > 0)
                        {
                            OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, addlist));
                        }
                        if (replacelist.Count > 0)
                        {
                            // OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Replace, replacelist, replacelist, 0));
                        }
                        if (removelist.Count > 0)
                        {
                            OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, removelist));
                        }
                        break;

                    case NotifyCollectionChangedAction.Reset:
                        OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
                        break;
                    }
                });
            }
        }