public override IPlugin ExecutePlugin()
        {
            ConfigItem.PluginRunContext = this;
            if (Plugins.ContainsKey(ConfigItem.Url))
            {
                _init[ConfigItem.Url] = false;
                IPlugin thePlugin = Plugins[ConfigItem.Url];
                ProcessParametricPlugin(thePlugin);
                thePlugin.InitPlugin(ConfigItem, Context);
                thePlugin.ShowPlugin(ConfigItem, Context);
                return(Plugins[ConfigItem.Url]);
            }
            else
            {
                AutoResetEvent theSignal = new AutoResetEvent(false);
                ThreadRun      runThread = new ThreadRun(ConfigItem, Context, theSignal, Plugins, this);
                ThreadStart    ts        = new ThreadStart(runThread.Run);
                Thread         td        = new Thread(ts);
                td.SetApartmentState(ApartmentState.STA);
                td.IsBackground = true;
                td.Name         = ConfigItem.Url;
                td.Start();
                _init[ConfigItem.Url] = true;
                theSignal.WaitOne();

                theSignal.Close();
                return(Plugins[ConfigItem.Url]);
            }
        }
        /// <summary>
        /// Load a plugin Assembly
        /// </summary>
        /// <typeparam name="T">Plugin type</typeparam>
        /// <param name="assemblyPath">Plugin assembly path</param>
        /// <exception cref="PluginNotRegisteredException"></exception>
        public void LoadPlugin <T>(string assemblyPath)
        {
            Type t = typeof(T);

            if (!Plugins.ContainsKey(t))
            {
                throw new PluginNotRegisteredException(t);
            }

            Assembly assembly = Assembly.LoadFile(assemblyPath);

            if (Plugins[t].ContainsKey(assembly))
            {
                throw new PluginAssemblyAlreadyLoadedException(assembly);
            }

            Type[] types = assembly.GetTypes();

            foreach (Type type in types)
            {
                if (t.IsAssignableFrom(type))
                {
                    object plugin = Activator.CreateInstance(type);

                    if (!Plugins[t].ContainsKey(assembly))
                    {
                        Plugins[t].Add(assembly, new List <object>());
                    }

                    Plugins[t][assembly].Add(plugin);
                }
            }
        }
Exemple #3
0
        public IDbConnection BuildConnection(string driver, string connectionString)
        {
            IDbConnection conn = null;

            switch (driver.ToUpper())
            {
            case esMetaDrivers.MySql:
                MySql.MySqlDatabases.LoadAssembly();
                conn = MySql.MySqlDatabases.CreateConnection(connectionString);
                break;

            case esMetaDrivers.PostgreSQL:
                PostgreSQL.PostgreSQLDatabases.LoadAssembly();
                conn = PostgreSQL.PostgreSQLDatabases.CreateConnection(connectionString);
                break;

            default:

                if (Plugins.ContainsKey(driver))
                {
                    conn = this.GetConnectionFromPlugin(driver, connectionString);
                }
                else
                {
                    conn = new OleDbConnection(connectionString);
                }
                break;
            }
            return(conn);
        }
Exemple #4
0
        private void ParseStartArgs()
        {
            var pluginStart = false;

            for (var i = 0; i < mStartArgs.Length; i++)
            {
                var plugName   = mStartArgs[i];
                var pluginArgs = new List <string>();
                if (plugName.Contains(";") == true)
                {
                    // Plugin-args are seperated by ;
                    pluginArgs.AddRange(plugName.Split(';'));
                    plugName = pluginArgs[0];
                    pluginArgs.RemoveAt(0);
                }

                if (Plugins.ContainsKey(plugName) == false)
                {
                    MsgHelper.Error("Fehler beim Plugin laden", "Das Plugin \"" + plugName + "\" existiert nicht!\nBitte achte auf die korrekte Groß- und Kleinschreibung.");
                    continue;
                }

                Logger.Info("start Plugin \"" + plugName + "\" from Parameterinfo");
                ((PluginBase)Plugins[plugName]).OnPluginAddPage(this, pluginArgs);
                pluginStart = true;
            }

            if (pluginStart == true)             // we start a Plugin, so minimize Client
            {
                WindowState = FormWindowState.Minimized;
            }
        }
Exemple #5
0
        public void UnloadPlugin(Guid key)
        {
            //Skip if the plugin doesn't exist
            if (!Plugins.ContainsKey(key))
            {
                return;
            }

            //Skip if the plugin is already unloaded
            if (!PluginStates.ContainsKey(key))
            {
                return;
            }

            LogManager.APILog.WriteLineAndConsole("Unloading plugin '" + key + "'");

            object plugin = Plugins[key];

            try
            {
                MethodInfo initMethod = plugin.GetType( ).GetMethod("Shutdown");
                initMethod.Invoke(plugin, new object[] { });
            }
            catch (Exception ex)
            {
                LogManager.ErrorLog.WriteLine(ex);
            }

            m_pluginAssemblies.Remove(key);
            PluginStates.Remove(key);
            Plugins.Remove(key);
        }
        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);

            EnsureWebConditionControls();
            var visible = webReportManager.Plugin != null && !IsSubscription;

            btnCreateReportRu.Visible       = false;
            btnCreateReportKz.Visible       = false;
            btnSubscriptionsJournal.Visible = false;
            var showOnlyCulture = Request.QueryString["culture"];

            if (visible)
            {
                var cultures       = webReportManager.Plugin.SupportCulture;
                var cultureCaption = webReportManager.Plugin.CultureCaption;
                for (var i = 0; i < cultures.Length; i++)
                {
                    if (cultures[i].StartsWith("ru") && (string.IsNullOrEmpty(showOnlyCulture) || showOnlyCulture == cultures[i]))
                    {
                        btnCreateReportRu.Visible = true;
                        btnCreateReportRu.Text    = cultureCaption[i];
                    }
                    else if (cultures[i].StartsWith("kz") && (string.IsNullOrEmpty(showOnlyCulture) || showOnlyCulture == cultures[i]))
                    {
                        btnCreateReportKz.Visible = true;
                        btnCreateReportKz.Text    = cultureCaption[i];
                    }
                }

                if (!(webReportManager.Plugin is CrossJournalReportPlugin) && !(webReportManager.Plugin is IReportAutoExport))
                {
                    btnSubscriptionsJournal.Visible = true;
                }
            }

            StiWebViewer1.Visible = StiWebViewer1.Report != null;
            if (!string.IsNullOrEmpty(CurrentPlugin) && Plugins.ContainsKey(CurrentPlugin))
            {
                lReport.Text = Plugins[CurrentPlugin].Description;
            }
            else
            {
                lReport.Text = string.Empty;
            }

            if (!WebReportManager.IsTreeViewControlVisible)
            {
                tdTreeView.Visible              = false;
                checkboxPanel.Visible           = false;
                btnSubscriptionsJournal.Visible = false;
                btnClearValueConditions.Visible = visible;
            }

            SetClearFormJavaScript();
        }
        public async Task <T> AuthWrapper <T>(string plugin, Func <IDownloadPlugin, ISession, Task <T> > function) where T : Response, new()
        {
            if (!Plugins.ContainsKey(plugin))
            {
                T t = new T();
                t.Status       = ResponseStatus.MissingPlugin;
                t.ErrorMessage = "Plugin '" + plugin + "' not found.";
                DoLogging(t);
                return(t);
            }
            IDownloadPlugin p     = Plugins[plugin];
            int             retry = 0;
            T r;

            do
            {
                if (!Settings.Instance.OpenSessionsDictionary.ContainsKey(plugin))
                {
                    if (!Settings.Instance.AuthorizationsMetadataDictionary.ContainsKey(plugin))
                    {
                        T t = new T();
                        t.Status       = ResponseStatus.MissingAuthenticationParameters;
                        t.ErrorMessage = "Authentication parameters for Plugin '" + plugin + "' are missing.";
                        DoLogging(t);
                        return(t);
                    }
                    ISession ses = await p.Authenticate(Settings.Instance.AuthorizationsMetadataDictionary[plugin]);

                    if (ses.Status != ResponseStatus.Ok)
                    {
                        T t = new T();
                        ses.PropagateError(t);
                        DoLogging(t);
                        return(t);
                    }
                    Settings.Instance.OpenSessionsDictionary.Add(plugin, ses);
                    DoChangeSettings();
                }
                ISession s = Settings.Instance.OpenSessionsDictionary[plugin];
                r = await function(p, s);

                if (r.Status != ResponseStatus.Ok)
                {
                    if (r.Status == ResponseStatus.LoginRequired)
                    {
                        Settings.Instance.OpenSessionsDictionary.Remove(plugin);
                        DoChangeSettings();
                    }
                    DoLogging(r);
                }
                retry++;
            } while (r.Status == ResponseStatus.LoginRequired && retry <= Settings.Instance.NumberOfRetries);
            return(r);
        }
 /// <summary>
 ///		Método para crear un plugin
 /// </summary>
 public void CreatePlugin(string projectExtension, Plugins.IPluginSourceEditor plugin)
 {
     if (!Plugins.ContainsKey(projectExtension))
     {
         Plugins.Add(projectExtension, plugin);
     }
     else
     {
         System.Diagnostics.Debug.WriteLine($"Ya existe un plugin con la extensión: {projectExtension}");
     }
 }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                string reportName = Request.QueryString["ClassName"];
                if (!string.IsNullOrEmpty(reportName) && Plugins.ContainsKey(reportName))
                {
                    if (!webReportManager.HierarchyReports.Plugins.ContainsKey(Plugins[reportName]))
                    {
                        System.Web.HttpContext.Current.Response.Redirect("/MainPage.aspx/NoPermit");
                    }
                    HierarchyReports <TreeNode, Panel> hierarchyReports;
                    hierarchyReports = webReportManager.HierarchyReports.Plugins[Plugins[reportName]];
                    if (TreeView1.SelectedNode != null)
                    {
                        TreeView1.SelectedNode.Selected = false;
                    }
                    if (hierarchyReports.TreeControl != null)
                    {
                        hierarchyReports.TreeControl.Selected = true;
                    }
                    Page.LoadComplete +=
                        delegate
                    {
                        WebConditionControlsCreated = false;
                        SetCurrentPlugin(Plugins[reportName],
                                         string.IsNullOrEmpty(Request.QueryString["setDefaultParams"]));
                    };

                    Page.PreRenderComplete += delegate //(object sender, EventArgs e)
                    {
                        var culture = Request.QueryString["culture"] ?? "ru";
                        if (string.IsNullOrEmpty(Request.QueryString["open"]) ||
                            Request.QueryString["open"].Equals("on"))
                        {
                            CreateReport(culture, false);
                        }
                    };
                }
            }
            EnsureWebConditionControls();
            if (reportCircle != null)
            {
                webReportManager.Plugin.CircleFillConditions = reportCircle.GetFillCircleConditions();
//                foreach (List<BaseReportCondition> filters in reportCircle.GetFillCircleConditions())
//                {
//                    webReportManager.Filters.AddRange(filters);
//                }
            }
        }
        /// <summary>
        /// Register a plugin
        /// </summary>
        /// <typeparam name="T">Plugin type</typeparam>
        /// <param name="dependenciesPaths">Plugin dependencies paths</param>
        /// <exception cref="PluginAlreadyRegisteredException"></exception>
        public void RegisterPlugin <T>(params string[] dependenciesPaths)
        {
            Type t = typeof(T);

            if (Plugins.ContainsKey(t))
            {
                throw new PluginAlreadyRegisteredException(t);
            }

            Plugins.Add(t, new Dictionary <Assembly, List <object> >());
            DependenciesPaths.Add(t, new List <string>());

            AddPluginsDependenciesPaths <T>(dependenciesPaths);
        }
 private void CreateWebConditionControls()
 {
     if (!string.IsNullOrEmpty(CurrentPlugin) && Plugins.ContainsKey(CurrentPlugin))
     {
         webReportManager.Plugin = Plugins[CurrentPlugin];
         webReportManager.Plugin.InitializeReportCulture(webReportManager.Plugin.SupportCulture[0]);
         ((IWebReportPlugin)webReportManager.Plugin).Page = Page;
         webReportManager.SessionWorker = swReport.SessionWorker;
         webReportManager.Session       = Session;
         webReportManager.CreateView();
     }
     if (webReportManager.Plugin != null)
     {
         int i = 0;
         foreach (BaseReportCondition condition in webReportManager.Filters)
         {
             if (!condition.Visible)
             {
                 continue;
             }
             Control columnFilter = (Control)condition.ColumnFilter;
             if (string.IsNullOrEmpty(columnFilter.ID))
             {
                 columnFilter.ID = string.Format("column_{0}", i);
             }
             ph.Controls.Add(columnFilter);
             i++;
         }
         //                rcc.SetReportCondition(webReportManager.Plugin.ModelFillConditions);
         if (webReportManager.Plugin.CreateModelFillConditions().Count > 0)
         {
             reportCircle    = new ReportConditionControls((IWebReportPlugin)webReportManager.Plugin);
             reportCircle.ID = "rcc";
             if (_countModelFillConditions != -1)
             {
                 reportCircle.CountRows = _countModelFillConditions;
             }
             phCircle.Controls.Add(reportCircle);
             //todo: кастыль, количество после постбака не востанавливается
             if (_countModelFillConditions != -1)
             {
                 reportCircle.CountRows = -1;
                 reportCircle.CountRows = _countModelFillConditions;
             }
         }
     }
 }
Exemple #12
0
        public bool Connect(string driverIn, string connectionString)
        {
            string driver = driverIn.ToUpper();

            if (driver == "POSTGRESQL8")
            {
                driver = "POSTGRESQL";
            }
            if (driver == "MYSQL2")
            {
                driver = "MYSQL";
            }
            if (driver == "VISTADB3X")
            {
                driver = "VISTADB";
            }

            switch (driver)
            {
            case esMetaDrivers.None:
                return(true);

            case esMetaDrivers.SQL:
            case esMetaDrivers.Oracle:
            case esMetaDrivers.Access:
            case esMetaDrivers.MySql:
            case esMetaDrivers.PostgreSQL:

                return(this.Connect(esMetaDrivers.GetDbDriverFromName(driver), driver, connectionString));

            default:

                if (Plugins.ContainsKey(driver))
                {
                    return(this.Connect(dbDriver.Plugin, driver, connectionString));
                }
                else
                {
                    return(false);
                }
            }
        }
Exemple #13
0
        private IDbConnection GetConnectionFromPlugin(string providerName, string pluginConnectionString, out IPlugin plugin)
        {
            PluginContext pluginContext = new PluginContext(providerName, pluginConnectionString);

            IDbConnection connection = null;

            if (!Plugins.ContainsKey(providerName))
            {
                throw new Exception("EntitySpaces.MetadataEngine Plugin \"" + providerName + "\" not registered.");
            }
            else
            {
                plugin = Plugins[providerName] as IPlugin;
                plugin.Initialize(pluginContext);

                connection = plugin.NewConnection;
            }

            return(connection);
        }
Exemple #14
0
 internal static bool HasPlugin(string plugin)
 {
     return(Plugins.ContainsKey(plugin));
 }
        public void LoadPlugins(bool forceLoad = false)
        {
            if (Loaded && !forceLoad)
            {
                return;
            }

            ApplicationLog.BaseLog.Info("Loading plugins ...");

            try
            {
                Loaded = true;
                //				m_initialized = false;   // THIS CAUSES all plugins to stop working

                string modsPath = Path.Combine(Server.Instance.Path, "Mods");
                ApplicationLog.BaseLog.Info("Scanning: {0}", modsPath);
                if (!Directory.Exists(modsPath))
                {
                    ApplicationLog.BaseLog.Error("Invalid directory");
                    return;
                }

                string[] files = Directory.GetFiles(modsPath, "*.dll", SearchOption.AllDirectories);
                if (files.Length == 0)
                {
                    ApplicationLog.BaseLog.Info("Found no dll files");
                }

                foreach (string file in files)
                {
                    try
                    {
                        ApplicationLog.BaseLog.Info($"Trying to load {file}");
                        // Load assembly from file into memory, so we can hotswap it if we want
                        byte[]   b = File.ReadAllBytes(file);
                        Assembly pluginAssembly = Assembly.Load(b);
                        if (IsOldPlugin(pluginAssembly))
                        {
                            if (IsValidPlugin(pluginAssembly))
                            {
                                pluginAssembly = Assembly.UnsafeLoadFrom(file);
                            }
                            else
                            {
                                continue;
                            }
                        }
                        ApplicationLog.BaseLog.Info($"Loaded assembly {pluginAssembly.FullName}");
                        //Get the assembly GUID
                        GuidAttribute guid      = (GuidAttribute)pluginAssembly.GetCustomAttributes(typeof(GuidAttribute), true)[0];
                        Guid          guidValue = new Guid(guid.Value);

                        if (_pluginPaths.ContainsKey(guidValue))
                        {
                            _pluginPaths[guidValue] = file;
                        }
                        else
                        {
                            _pluginPaths.Add(guidValue, file);
                        }

                        if (_pluginAssemblies.ContainsKey(guidValue))
                        {
                            _pluginAssemblies[guidValue] = pluginAssembly;
                        }
                        else
                        {
                            _pluginAssemblies.Add(guidValue, pluginAssembly);
                        }

                        //Look through the exported types to find the one that implements PluginBase
                        Type[] types = pluginAssembly.GetExportedTypes( );
                        foreach (Type type in types)
                        {
                            //Check that we don't have an entry already for this GUID
                            if (Plugins.ContainsKey(guidValue))
                            {
                                break;
                            }

                            //if (type.BaseType == null)
                            //                                    continue;

                            //Type[] filteredTypes = type.BaseType.GetInterfaces();
                            Type[] filteredTypes = type.GetInterfaces( );
                            foreach (Type interfaceType in filteredTypes)
                            {
                                if (interfaceType.Name == typeof(IPlugin).Name)
                                {
                                    try
                                    {
                                        //Create an instance of the plugin object
                                        IPlugin pluginObject = (IPlugin)Activator.CreateInstance(type);

                                        //And add it to the dictionary
                                        Plugins.Add(guidValue, pluginObject);

                                        break;
                                    }
                                    catch (Exception ex)
                                    {
                                        ApplicationLog.BaseLog.Error(ex);
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        ApplicationLog.BaseLog.Error(ex);
                    }
                }
            }
            catch (Exception ex)
            {
                ApplicationLog.BaseLog.Error(ex);
            }

            ApplicationLog.BaseLog.Info("Finished loading plugins");
        }
Exemple #16
0
        public void LoadPlugins(bool forceLoad = false)
        {
            if (Loaded && !forceLoad)
            {
                return;
            }

            Console.WriteLine("Loading plugins ...");

            try
            {
                Loaded = true;
                //				m_initialized = false;   // THIS CAUSES all plugins to stop working

                string modsPath = Path.Combine(Server.Instance.Path, "Mods");
                Console.WriteLine("Scanning: {0}", modsPath);
                if (!Directory.Exists(modsPath))
                {
                    return;
                }

                string[] subDirectories = Directory.GetDirectories(modsPath);
                foreach (string path in subDirectories)
                {
                    string[] files = Directory.GetFiles(path);
                    foreach (string file in files)
                    {
                        try
                        {
                            FileInfo fileInfo = new FileInfo(file);
                            if (!fileInfo.Extension.ToLower( ).Equals(".dll"))
                            {
                                continue;
                            }

                            // Load assembly from file into memory, so we can hotswap it if we want
                            byte[]   b = File.ReadAllBytes(file);
                            Assembly pluginAssembly = Assembly.Load(b);
                            if (IsOldPlugin(pluginAssembly))
                            {
                                if (IsValidPlugin(pluginAssembly))
                                {
                                    pluginAssembly = Assembly.UnsafeLoadFrom(file);
                                }
                                else
                                {
                                    continue;
                                }
                            }

                            //Get the assembly GUID
                            GuidAttribute guid      = (GuidAttribute)pluginAssembly.GetCustomAttributes(typeof(GuidAttribute), true)[0];
                            Guid          guidValue = new Guid(guid.Value);

                            if (m_pluginPaths.ContainsKey(guidValue))
                            {
                                m_pluginPaths[guidValue] = file;
                            }
                            else
                            {
                                m_pluginPaths.Add(guidValue, file);
                            }

                            if (m_pluginAssemblies.ContainsKey(guidValue))
                            {
                                m_pluginAssemblies[guidValue] = pluginAssembly;
                            }
                            else
                            {
                                m_pluginAssemblies.Add(guidValue, pluginAssembly);
                            }

                            //Look through the exported types to find the one that implements PluginBase
                            Type[] types = pluginAssembly.GetExportedTypes( );
                            foreach (Type type in types)
                            {
                                //Check that we don't have an entry already for this GUID
                                if (Plugins.ContainsKey(guidValue))
                                {
                                    break;
                                }

                                //if (type.BaseType == null)
                                //                                    continue;

                                //Type[] filteredTypes = type.BaseType.GetInterfaces();
                                Type[] filteredTypes = type.GetInterfaces( );
                                foreach (Type interfaceType in filteredTypes)
                                {
                                    if (interfaceType.FullName == typeof(IPlugin).FullName)
                                    {
                                        try
                                        {
                                            //Create an instance of the plugin object
                                            object pluginObject = Activator.CreateInstance(type);

                                            //And add it to the dictionary
                                            Plugins.Add(guidValue, pluginObject);

                                            break;
                                        }
                                        catch (Exception ex)
                                        {
                                            LogManager.ErrorLog.WriteLine(ex);
                                        }
                                    }
                                }
                            }

                            break;
                        }
                        catch (Exception ex)
                        {
                            LogManager.ErrorLog.WriteLine(ex);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LogManager.ErrorLog.WriteLine(ex);
            }

            Console.WriteLine("Finished loading plugins");
        }
Exemple #17
0
 public bool Contains(Type type)
 {
     ValidateType(type);
     return(Plugins.ContainsKey(type));
 }
Exemple #18
0
        internal static void LoadAll()
        {
            if (Plugins.Count != 0)
            {
                return;
            }

            try
            {
                if (!Directory.Exists("plugins"))
                {
                    Directory.CreateDirectory("plugins");
                    return;
                }
            }
            catch
            {
                return;
            }

            string[] files = Directory.GetFiles("plugins", "*.dll");

            if (files.Length != 0)
            {
                foreach (string file in files)
                {
                    try
                    {
                        Assembly assembly = Assembly.LoadFrom(Path.GetFullPath(file));
                        foreach (Type type in assembly.GetTypes())
                        {
                            if (!type.IsClass || type.IsNotPublic)
                            {
                                continue;
                            }

                            if (type.BaseType == typeof(Plugin))
                            {
                                try
                                {
                                    Plugin obj = (Plugin)Activator.CreateInstance(type);
                                    obj.ClassName = type.ToString();
                                    if (obj.RequiredCoreVersion > World.Version)
                                    {
                                        throw new Exception("Newer version of core is needed! (" + obj.RequiredCoreVersion + ")");
                                    }
                                    if (string.IsNullOrEmpty(obj.Keyword.Trim()) || string.IsNullOrEmpty(obj.Name.Trim()))
                                    {
                                        throw new Exception("Plugin has invalid parameters!");
                                    }
                                    if (Plugins.ContainsKey(obj.Keyword.ToLower().Trim()))
                                    {
                                        Plugin prev = Plugins[obj.Keyword.ToLower().Trim()];
                                        if (prev.Version >= obj.Version)
                                        {
                                            throw new Exception("A newer version of this plugin was already loaded!");
                                        }
                                    }
                                    if (obj.Keyword.ToLower().Trim() == "core" || obj.Keyword.ToLower().Trim() == "server")
                                    {
                                        throw new Exception("Plugin has invalid keyword!");
                                    }

                                    if (obj.Config != null)
                                    {
                                        obj.Config.Load(obj.Keyword.ToLower().Trim());
                                        obj.OnLoadedConfig(obj.Config.DidLoad);
                                    }
                                    Plugins[obj.Keyword.ToLower().Trim()] = obj;
                                    Log.Write("Loaded: [" + obj.Keyword.ToLower().Trim() + "] " + obj.Name + ", version " + obj.Version.ToString() + ".");
                                }
                                catch (Exception e)
                                {
                                    Log.Write("Failed: [" + type.ToString() + "] in " + file + "!");
                                    Log.Write("        " + e.Message);
                                    continue;
                                }
                            }
                        }
                    }
                    catch
                    {
                        continue;
                    }
                }
            }

            Log.Write("Done.");
        }