Hi,
I am trying to register plug-ins via a custom action and a registration.xml file that's an embedded resource. All the code is being called properly but it seems to have no effect and the plug-in is not registered. Using debug code I can verify that the custom action and all associated method calls are occuring. I am a little stumped. It's as if ApplicationContext.RegisterApplication() is just not doing anything.
public static void RegisterAddIns()
{
// We have to unregister the add-in before registering it
RegisterMediaCenterAddIn(LibraryAddIns.TVLibrary, true);
RegisterMediaCenterAddIn(LibraryAddIns.TVLibrary, false);
RegisterMediaCenterAddIn(LibraryAddIns.DVDExtender, true);
RegisterMediaCenterAddIn(LibraryAddIns.DVDExtender, false);
RegisterMediaCenterAddIn(LibraryAddIns.PodcastLibrary, true);
RegisterMediaCenterAddIn(LibraryAddIns.PodcastLibrary, false);
}
public static void UnRegisterAddIns()
{
RegisterMediaCenterAddIn(LibraryAddIns.TVLibrary, true);
RegisterMediaCenterAddIn(LibraryAddIns.DVDExtender, true);
RegisterMediaCenterAddIn(LibraryAddIns.PodcastLibrary, true);
}
private static void RegisterMediaCenterAddIn(LibraryAddIns addIn, bool unRegister)
{
WriteEntry("RegisterMediaCenterAddIn({0}, {1})", addIn, unRegister);
try
{
// Get registration xml from resource
string registrationXml = string.Empty;
switch (addIn)
{
case LibraryAddIns.TVLibrary:
registrationXml = TVLibrary.Resources.Registration_TVLibrary;
break;
case LibraryAddIns.DVDExtender:
registrationXml = TVLibrary.Resources.Registration_DVDExtender;
break;
case LibraryAddIns.PodcastLibrary:
registrationXml = TVLibrary.Resources.Registration_PodcastLibrary;
break;
}
// Load xml into a string reader inorder to pass to RegisterApplication()
WriteEntry("xml = {0}", registrationXml);
string basePath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
WriteEntry("basePath = {0}", basePath);
using (XmlTextReader xmlReader = new XmlTextReader(new StringReader(registrationXml)))
{
ApplicationContext.RegisterApplication(xmlReader, unRegister, true, basePath);
}
WriteEntry("RegisterMediaCenterAddIn({0}, {1}): Successful", addIn, unRegister);
}
catch (Microsoft.MediaCenter.ApplicationAlreadyRegisteredException regEx)
{
WriteEntry("RegisterMediaCenterAddIn({0}, {1}): Already registered", addIn, unRegister);
}
catch (Microsoft.MediaCenter.ApplicationNotRegisteredException notRegEx)
{
WriteEntry("RegisterMediaCenterAddIn({0}, {1}): Not registered", addIn, unRegister);
}
catch (Exception ex)
{
WriteEntry("RegisterMediaCenterAddIn({0}, {1}): Unhandled exception", ex, addIn, unRegister);
if (unRegister)
{
throw new InstallException(string.Format("Could not un-register Media Center Add In '{0}'", addIn), ex);
}
else
{
throw new InstallException(string.Format("Could not register Media Center Add In '{0}'", addIn), ex);
}
}
}