public bool Save() { bool SaveOK = false; if (_IsNew) { IReportPlugin plugin = CreateInstance(); if (plugin != null) { ReportPluginInfo plugininfo = plugin.GetPluginInfo(); GUID = plugininfo.GUID; Description = plugininfo.Description; ReportName = plugininfo.ReportName; TopLevelMenuKey = plugininfo.TopLevelMenuKey; SecondLevelMenuKey = plugininfo.SecondLevelMenuKey; plugin.Dispose(); } } if (!Directory.Exists(_Folder)) { Directory.CreateDirectory(_Folder); } if (GUID.Length > 0) { Serializer <ReportPluginInfo> .Save(this, _Folder + GUID + ".xml"); OnChanged(this); _IsNew = false; SaveOK = true; } return(SaveOK); }
/// <summary> /// Occurs when the class is Changed /// </summary> protected static void OnChanged(ReportPluginInfo plugin) { if (Changed != null) { Changed(plugin, new EventArgs()); } }
/// <summary> /// Loads a Plug-in based on the specified file name. /// </summary> public static ReportPluginInfo Load(string fileName) { if (!File.Exists(fileName)) { return(null); } try { ReportPluginInfo info = Serializer <ReportPluginInfo> .Load(fileName); info.GUID = new FileInfo(fileName).Name.Replace(".xml", string.Empty); info._IsNew = false; return(info); } catch (InvalidOperationException) { return(null); } }
public static Collection <ReportPluginInfo> LoadAll() { Collection <ReportPluginInfo> infos = new Collection <ReportPluginInfo>(); if (!Directory.Exists(_Folder)) { Directory.CreateDirectory(_Folder); } else { foreach (string filename in Directory.GetFiles(_Folder, "*.xml")) { ReportPluginInfo info = Load(filename); if (info != null) { infos.Add(info); } } } return(infos); }
/// <summary> /// Discover Plugins implemented in an assembly and creates corresponding XML file definitions for faster loading in the future. /// </summary> public static List <ReportPluginInfo> DiscoverPlugins(string fileName, ILogger logger) { if (!File.Exists(fileName)) { return(null); } try { List <ReportPluginInfo> plugins = new List <ReportPluginInfo>(); if (!Directory.Exists(_Folder)) { Directory.CreateDirectory(_Folder); } Assembly _assembly = Assembly.LoadFile(fileName); foreach (Type t in _assembly.GetTypes()) { if (t.GetInterfaces().Contains(typeof(IReportPlugin))) { IReportPlugin plugin = Activator.CreateInstance(t) as IReportPlugin; ReportPluginInfo _plugininfo = plugin.GetPluginInfo(); _plugininfo.FileName = fileName; if ((_plugininfo.GUID.Length > 0) && (_plugininfo.ReportName.Length > 0)) { plugins.Add(_plugininfo); string XMLFileName = _Folder + _plugininfo.GUID + ".xml"; if (File.Exists(XMLFileName)) { File.Delete(XMLFileName); } Serializer <ReportPluginInfo> .Save(_plugininfo, XMLFileName); _plugininfo._IsNew = false; } } } if (plugins.Count > 0) { return(plugins); } else { return(null); } } catch (InvalidOperationException) { return(null); } catch (Exception ex) { logger.LogException(ex); return(null); } }