static void RunSetup(MessageContainer messages, string appDir) { Assembly setupAssembly = PluginLoader.LoadPlugin ("SetupPlugin"); if (setupAssembly == null) { messages.Add ("Init: failed to load setup plugin assembly."); return; } Type[] types = setupAssembly.GetTypes (); ISetupPlugin setupPlugin; foreach (Type t in types) { if (!typeof (ISetupPlugin).IsAssignableFrom (t)) continue; try { setupPlugin = Activator.CreateInstance (t) as ISetupPlugin; setupPlugin.Initialize (); messages.Add ("Init: setup type '{0}' v{1} loaded", t.FullName, setupPlugin.Version); } catch (Exception ex) { messages.Add ("Init: failed to create instance of type '{0}' - cannot perform setup with this type. Exception '{1}' was caught, with message: {2}", t.FullName, ex.GetType (), ex.Message); continue; } try { if (!setupPlugin.PerformSetupSteps (appDir)) { messages.Add ("Init: setup failed."); continue; } messages.Add ("Init: setup successful."); } catch (Exception ex) { messages.Add ("Init: setup failed. Exception '{0}' caught: {1}", ex.GetType (), ex.Message); } } }
void CreateDirectory(string name, string dataDir, MessageContainer messages) { string newDir = Path.Combine (dataDir, name); if (!Directory.Exists (newDir)) { Directory.CreateDirectory (newDir); messages.Add (1, false, "* directory {0} created", newDir); } }
static void LoadPluginResources(Assembly pluginAssembly, MessageContainer messages) { Type [] types = pluginAssembly.GetTypes (); IPlugin plugin; foreach (Type t in types) { if (!typeof (IPlugin).IsAssignableFrom (t)) continue; try { plugin = Activator.CreateInstance (t) as IPlugin; plugin.Initialize (); messages.Add ("Init: plugin type '{0}' v{1} loaded", t.FullName, plugin.Version); } catch (Exception ex) { messages.Add ("Init: failed to create instance of type '{0}'. Exception '{1}' was caught, with message: {2}", t.FullName, ex.GetType (), ex.Message); continue; } } }