Ejemplo n.º 1
0
		public static void LoadAllPlugins(Form host) {
			//No need to check RemotingRole; no call to db.
			PluginList=new List<PluginContainer>();
			if(RemotingClient.RemotingRole==RemotingRole.ClientWeb) {
				return;//no plugins will load.  So from now on, we can assume a direct connection.
			}
			for(int i=0;i<ProgramC.Listt.Count;i++) {
				if(!ProgramC.Listt[i].Enabled) {
					continue;
				}
				if(ProgramC.Listt[i].PluginDllName=="") {
					continue;
				}
				string dllPath=ODFileUtils.CombinePaths(Application.StartupPath,ProgramC.Listt[i].PluginDllName);
				if(dllPath.Contains("[VersionMajMin]")) {
					Version vers=new Version(Application.ProductVersion);
					string dllPathWithVersion=dllPath.Replace("[VersionMajMin]",vers.Major.ToString()+"."+vers.Minor.ToString());
					dllPath=dllPath.Replace("[VersionMajMin]","");//now stripped clean
					if(File.Exists(dllPathWithVersion)){
						File.Copy(dllPathWithVersion,dllPath,true);
					}
				}
				if(!File.Exists(dllPath)) {
					continue;
				}
				PluginBase plugin=null;
				try {
					Assembly ass=Assembly.LoadFile(dllPath);
					string typeName=Path.GetFileNameWithoutExtension(dllPath)+".Plugin";
					Type type=ass.GetType(typeName);
					plugin=(PluginBase)Activator.CreateInstance(type);
					plugin.Host=host;
				}
				catch(Exception ex) {
					MessageBox.Show(ex.Message);
					continue;//don't add it to plugin list.
				}
				PluginContainer container=new PluginContainer();
				container.Plugin=plugin;
				container.ProgramNum=ProgramC.Listt[i].ProgramNum;
				PluginList.Add(container);
				//Active=true;
			}
		}
Ejemplo n.º 2
0
Archivo: Plugins.cs Proyecto: mnisl/OD
		///<summary>If this is middle tier, pass in null.</summary>
		public static void LoadAllPlugins(Form host) {
			//No need to check RemotingRole; no call to db.
			PluginList=new List<PluginContainer>();
			//if(RemotingClient.RemotingRole==RemotingRole.ClientWeb) {
			//  js 6/20/14 Don't do this.  We will now support plugins for middle tier.
			//	return;//no plugins will load.  So from now on, we can assume a direct connection.
			//}
			List<Program> listPrograms=ProgramC.GetListt();
			for(int i=0;i<listPrograms.Count;i++) {
				if(!listPrograms[i].Enabled) {
					continue;
				}
				if(listPrograms[i].PluginDllName=="") {
					continue;
				}
				string dllPath=ODFileUtils.CombinePaths(Application.StartupPath,listPrograms[i].PluginDllName);
				if(RemotingClient.RemotingRole==RemotingRole.ServerWeb) {
					dllPath=ODFileUtils.CombinePaths(System.Web.HttpContext.Current.Server.MapPath(null),listPrograms[i].PluginDllName);
				}
				if(dllPath.Contains("[VersionMajMin]")) {
					Version vers=new Version(Application.ProductVersion);
					string dllPathWithVersion=dllPath.Replace("[VersionMajMin]",vers.Major.ToString()+"."+vers.Minor.ToString());
					dllPath=dllPath.Replace("[VersionMajMin]","");//now stripped clean
					if(File.Exists(dllPathWithVersion)) {
						File.Copy(dllPathWithVersion,dllPath,true);
					}
					else{
						//try the Plugins folder
						#if !DEBUG
						if(PrefC.AtoZfolderUsed) {//must be using AtoZ folder
							string dllPathVersionCentral=ODFileUtils.CombinePaths(ImageStore.GetPreferredAtoZpath(),"Plugins",
								listPrograms[i].PluginDllName.Replace("[VersionMajMin]",vers.Major.ToString()+"."+vers.Minor.ToString()));
							if(File.Exists(dllPathVersionCentral)) {
								File.Copy(dllPathVersionCentral,dllPath,true);
							}
						}
						#endif
					}
				}
				if(!File.Exists(dllPath)) {
					continue;
				}
				PluginBase plugin=null;
				Assembly ass=null;
				string assName="";
				try {
					ass=Assembly.LoadFile(dllPath);
					assName=Path.GetFileNameWithoutExtension(dllPath);
					string typeName=assName+".Plugin";
					Type type=ass.GetType(typeName);
					plugin=(PluginBase)Activator.CreateInstance(type);
					plugin.Host=host;
				}
				catch(Exception ex) {
					//how to handle this for RemotingRole.ServerWeb?:
					MessageBox.Show("Error loading Plugin:"+listPrograms[i].PluginDllName+"\r\n"
						+ex.Message);
					continue;//don't add it to plugin list.
				}
				PluginContainer container=new PluginContainer();
				container.Plugin=plugin;
				container.ProgramNum=listPrograms[i].ProgramNum;
				container.Assemb=ass;
				container.Name=assName;
				PluginList.Add(container);
			}
		}
Ejemplo n.º 3
0
        ///<summary>If this is middle tier, pass in null.</summary>
        public static void LoadAllPlugins(Form host)
        {
            //No need to check RemotingRole; no call to db.
            if (ODBuild.IsWeb())
            {
                return;                //plugins not allowed in cloud mode
            }
            List <PluginContainer> listPlugins = new List <PluginContainer>();

            //Loop through all programs that are enabled with a plug-in dll name set.
            foreach (Program program in Programs.GetWhere(x => x.Enabled && !string.IsNullOrEmpty(x.PluginDllName)))
            {
                string dllPath = ODFileUtils.CombinePaths(Application.StartupPath, program.PluginDllName);
                if (RemotingClient.RemotingRole == RemotingRole.ServerWeb)
                {
                    dllPath = ODFileUtils.CombinePaths(System.Web.HttpContext.Current.Server.MapPath(null), program.PluginDllName);
                }
                //Check for the versioning trigger.
                //For example, the plug-in might be entered as MyPlugin[VersionMajMin].dll. The bracketed section will be removed when loading the dll.
                //So it will look for MyPlugin.dll as the dll to load. However, before it loads, it will look for a similar dll with a version number.
                //For example, if using version 14.3.23, it would look for MyPlugin14.3.dll.
                //If that file is found, it would replace MyPlugin.dll with the contents of MyPlugin14.3.dll, and then it would load MyPlugin.dll as normal.
                if (dllPath.Contains("[VersionMajMin]"))
                {
                    Version vers = Assembly.GetAssembly(typeof(Db)).GetName().Version;
                    string  dllPathWithVersion = dllPath.Replace("[VersionMajMin]", vers.Major.ToString() + "." + vers.Minor.ToString());
                    dllPath = dllPath.Replace("[VersionMajMin]", "");                 //now stripped clean
                    if (File.Exists(dllPathWithVersion))
                    {
                        File.Copy(dllPathWithVersion, dllPath, true);
                    }
                    else
                    {
                        //try the Plugins folder
                        if (PrefC.AtoZfolderUsed != DataStorageType.InDatabase)                       //must have an AtoZ folder to check
                        {
                            string dllPathVersionCentral = FileAtoZ.CombinePaths(ImageStore.GetPreferredAtoZpath(), "Plugins",
                                                                                 program.PluginDllName.Replace("[VersionMajMin]", vers.Major.ToString() + "." + vers.Minor.ToString()));
                            if (FileAtoZ.Exists(dllPathVersionCentral))
                            {
                                FileAtoZ.Copy(dllPathVersionCentral, dllPath, FileAtoZSourceDestination.AtoZToLocal, doOverwrite: true);
                            }
                        }
                    }
                }
                //We now know the exact name of the dll for the plug-in.  Check to see if it is present.
                if (!File.Exists(dllPath))
                {
                    continue;                    //Nothing to do.
                }
                //The dll was found, try and load it in.
                PluginBase plugin  = null;
                Assembly   ass     = null;
                string     assName = "";
                try {
                    ass     = Assembly.LoadFile(dllPath);
                    assName = Path.GetFileNameWithoutExtension(dllPath);
                    string typeName = assName + ".Plugin";
                    Type   type     = ass.GetType(typeName);
                    plugin      = (PluginBase)Activator.CreateInstance(type);
                    plugin.Host = host;
                }
                catch (Exception ex) {
                    //Never try and show message boxes when on the middle tier, there is no UI.  We should instead log to a file or the event viewer.
                    if (RemotingClient.RemotingRole != RemotingRole.ServerWeb)
                    {
                        //Notify the user that their plug-in is not loaded.
                        MessageBox.Show("Error loading Plugin:" + program.PluginDllName + "\r\n" + ex.Message);
                    }
                    continue;                    //Don't add it to plugin list.
                }
                //The plug-in was successfully loaded and will start getting hook notifications.  Add it to the list of loaded plug-ins.
                PluginContainer container = new PluginContainer();
                container.Plugin     = plugin;
                container.ProgramNum = program.ProgramNum;
                container.Assemb     = ass;
                container.Name       = assName;
                listPlugins.Add(container);
            }
            ListPlugins = listPlugins;
        }