Need hook in OpenDentBusiness > Plugins

This forum is for programmers who have questions about the source code.
Post Reply
User avatar
wjstarck
Posts: 936
Joined: Tue Jul 31, 2007 7:18 am
Location: Keller, TX
Contact:

Need hook in OpenDentBusiness > Plugins

Post by wjstarck » Wed Jun 09, 2010 9:55 am

Jordan-

I need a hook at the top of OpenDentBusiness > Plugins as I need to manipulate the plugin filename before it loads. So the effect of what I want to do would be like so:

public static void LoadAllPlugins(Form host) {

Code: Select all

Version MainAppVersion = new Version(System.Windows.Forms.Application.ProductVersion);
Version MainAppMajMin = new Version(MainAppVersion.Major, MainAppVersion.Minor);
string fileName = "Anesthesia" + POut.String(MainAppMajMin.ToString()) + ".dll";
File.Copy(fileName, "Anesthesia.dll", true);

//No need to check RemotingRole; no call to db.
PluginList=new List<PluginContainer>();

so that the hook would insert what I have delineated in the code box. Hope thats clear. :oops:
Cheers,

Bill Starck, DDS
Big Idea Software, LLC
Developer, EASy(Electronic Anesthesia System) for Open Dental
817-807-1709
TX, USA

User avatar
jordansparks
Site Admin
Posts: 5742
Joined: Sun Jun 17, 2007 3:59 pm
Location: Salem, Oregon
Contact:

Re: Need hook in OpenDentBusiness > Plugins

Post by jordansparks » Wed Jun 09, 2010 12:22 pm

Well I don't really see how you could have a hook do anything before the plugins were even loaded. However, we could allow a plugin filename that looked like this:
"Anesthesia[VersionMajMin].dll"
Just like we already do for [PatNum] and [ChartNumber] in the command line arguments.
Jordan Sparks, DMD
http://www.opendental.com

User avatar
wjstarck
Posts: 936
Joined: Tue Jul 31, 2007 7:18 am
Location: Keller, TX
Contact:

Re: Need hook in OpenDentBusiness > Plugins

Post by wjstarck » Wed Jun 09, 2010 1:15 pm

Arrgh... Good point. Reconciling the office checking account in QuickBooks has fried my brain.

I need to vary the plugin name, because I have an automatic updater control that will download multiple versions of the plugin, so I need to match the correct version of the plugin with the corresponding version of OD.

Where would you make the change (so I know where to look for it)?
Cheers,

Bill Starck, DDS
Big Idea Software, LLC
Developer, EASy(Electronic Anesthesia System) for Open Dental
817-807-1709
TX, USA

User avatar
jordansparks
Site Admin
Posts: 5742
Joined: Sun Jun 17, 2007 3:59 pm
Location: Salem, Oregon
Contact:

Re: Need hook in OpenDentBusiness > Plugins

Post by jordansparks » Sat Jun 26, 2010 8:54 pm

Added to 7.2 in the area of code you recommended. Documented on Plugin page.
Jordan Sparks, DMD
http://www.opendental.com

User avatar
wjstarck
Posts: 936
Joined: Tue Jul 31, 2007 7:18 am
Location: Keller, TX
Contact:

Re: Need hook in OpenDentBusiness > Plugins

Post by wjstarck » Sun Jun 27, 2010 8:10 am

Almost there.

I had to add this to FormProgramLinkEdit or it won't find the plugin name in the OD folder when I try to save:

private void butOK_Click(object sender, System.EventArgs e) {
if(checkEnabled.Checked && textPluginDllName.Text!=""){
string dllPath=ODFileUtils.CombinePaths(Application.StartupPath,textPluginDllName.Text);

Code: Select all

if (textPluginDllName.Text.Contains("[VersionMajMin]"))
				{
					Version vers = new Version(Application.ProductVersion);
					dllPath = dllPath.Replace("[VersionMajMin]", vers.Major.ToString() + "." + vers.Minor.ToString());
				}
if(!File.Exists(dllPath)) {
MessageBox.Show(Lan.g(this,"Dll file not found:")+" "+dllPath);
return;
}
}

Which allows me to save the name of the plugin without getting a 'plugin not found error' but now I get a 'Value cannot be null. Parameter name: type' after the plugin name has been saved and I try to restart OD.

I was coding a different workaround and was getting this initially and resolved it, so I'll play with it and see why I'm getting that error - unless you can see an obvious line or two that needs to be added somewhere.
Cheers,

Bill Starck, DDS
Big Idea Software, LLC
Developer, EASy(Electronic Anesthesia System) for Open Dental
817-807-1709
TX, USA

User avatar
wjstarck
Posts: 936
Joined: Tue Jul 31, 2007 7:18 am
Location: Keller, TX
Contact:

Re: Need hook in OpenDentBusiness > Plugins

Post by wjstarck » Sun Jun 27, 2010 8:17 am

OK, it's dying right here on Plugins.cs:

Code: Select all

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;
				}
Parameter 'type' is null, I think because the saved assembly name in OD (in my case Anesthesia[VersionMajMin].dll does not match what's found in the OpenDental folder (in my case Anesthesia7.2.dll). Does that sound right?

Not sure how to resolve that...
Cheers,

Bill Starck, DDS
Big Idea Software, LLC
Developer, EASy(Electronic Anesthesia System) for Open Dental
817-807-1709
TX, USA

User avatar
jordansparks
Site Admin
Posts: 5742
Joined: Sun Jun 17, 2007 3:59 pm
Location: Salem, Oregon
Contact:

Re: Need hook in OpenDentBusiness > Plugins

Post by jordansparks » Sun Jun 27, 2010 11:23 am

Made the first change. I think the second problem is because your assembly name must now have numbers in it. I hope decimals are allowed. You'll have to change it with each version.
Jordan Sparks, DMD
http://www.opendental.com

User avatar
wjstarck
Posts: 936
Joined: Tue Jul 31, 2007 7:18 am
Location: Keller, TX
Contact:

Re: Need hook in OpenDentBusiness > Plugins

Post by wjstarck » Sun Jun 27, 2010 12:39 pm

jordansparks wrote:I think the second problem is because your assembly name must now have numbers in it. I hope decimals are allowed. You'll have to change it with each version.
Mmmm...OK I'll check. I came up with this:

Code: Select all

public static void LoadAllPlugins(Form host) {
	//No need to check RemotingRole; no call to db.
	//for external plugins that need multiple versions in the OD folder
	string[] fileEntries = Directory.GetFiles(Application.StartupPath);
	foreach (string fileName in fileEntries){	
		string pluginName = Path.GetFileNameWithoutExtension(fileName);
		string pluginFileName = pluginName;
		string isDll = Path.GetExtension(fileName);
		if (isDll == ".dll")//because this only works with .dlls, and there will be other extensions in this folder{
			AssemblyName assemblyName = AssemblyName.GetAssemblyName(Path.GetFileName(fileName));
			string aName = assemblyName.Name.ToString() + ".dll";
			Version MainAppVersion = new Version(System.Windows.Forms.Application.ProductVersion);//eg. 6.8.0.0
			Version MainAppMajMin = new Version(MainAppVersion.Major, MainAppVersion.Minor);//eg. 6.a
			string version = MainAppMajMin.ToString();
			Regex regex = new Regex(version);
			if (regex.IsMatch(pluginFileName)){
				File.Replace(pluginFileName + ".dll", aName, aName + POut.String(".old"));
				}
			}			
}
Which works just fine. The snippet above matches the corresponding version of the plugin with the current running version of OD, then just renames the correct plugin version to Anesthesia.dll and the older version to Anesthesia.dll.old

But I'll check to see if I can get your changes to work.
Cheers,

Bill Starck, DDS
Big Idea Software, LLC
Developer, EASy(Electronic Anesthesia System) for Open Dental
817-807-1709
TX, USA

User avatar
jordansparks
Site Admin
Posts: 5742
Joined: Sun Jun 17, 2007 3:59 pm
Location: Salem, Oregon
Contact:

Re: Need hook in OpenDentBusiness > Plugins

Post by jordansparks » Mon Jun 28, 2010 6:16 am

The idea might be ok, but the way the code was implemented is difficult for me to follow, would slow down startup, and would put other files at risk. I'm thinking more like this:

Code: Select all

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);
	}
}
I just posted it. I also had to change FormProgramLinkEdit again. I documented it at the bottom of the plugins page in the manual. Let me know how it goes.

(a few hours later) Sorry, I thought I posted it. Now it's really posted.
Jordan Sparks, DMD
http://www.opendental.com

User avatar
wjstarck
Posts: 936
Joined: Tue Jul 31, 2007 7:18 am
Location: Keller, TX
Contact:

Re: Need hook in OpenDentBusiness > Plugins

Post by wjstarck » Mon Jun 28, 2010 8:38 pm

That works brilliantly.

Thank you very much :P

Can we backport it to 7.1 branch if it's not too much trouble?
Cheers,

Bill Starck, DDS
Big Idea Software, LLC
Developer, EASy(Electronic Anesthesia System) for Open Dental
817-807-1709
TX, USA

Post Reply