private void LoadPlugins(AzusaContext context) { while (context.PluginLoadQueue.Count > 0) { LoadPlugin(context.PluginLoadQueue.Dequeue()); } ScanPluginAssembly(context, this.GetType().Assembly); if (!context.Ini.ContainsKey("plugins")) { return; } IniSection pluginSection = context.Ini["plugins"]; foreach (KeyValuePair <string, string> keyValuePair in pluginSection) { if (!File.Exists(keyValuePair.Value)) { context.Splash.SetLabel(String.Format("Datei nicht gefunden: " + keyValuePair.Value)); continue; } string path = new FileInfo(keyValuePair.Value).FullName; Assembly assembly = Assembly.LoadFile(path); ScanPluginAssembly(context, assembly); } }
protected AzusaContext GetContext() { if (context == null) { context = AzusaContext.GetInstance(); } return(context); }
public WebServer() { context = AzusaContext.GetInstance(); handlers = new List <IAzusaWebHandler>(); int port = AzusaContext.FindFreePort(); Prefix = String.Format("http://localhost:{0}/", port); httpListener = new HttpListener(); httpListener.Prefixes.Add(Prefix); httpListener.Start(); thread = new Thread(ListenerThread); thread.Priority = ThreadPriority.Lowest; thread.Name = "Internal Webserver"; thread.Start(); }
internal static AzusaContext GetInstance() { if (instance == null) { instance = new AzusaContext(); instance.CultureInfo = CultureInfo.CurrentUICulture; instance.RandomNumberGenerator = new Random(); instance.Plugins = new List <AzusaPlugin>(); instance.PluginLoadQueue = new Queue <AzusaPlugin>(); instance.ImageAcquisitionPlugins = new List <IImageAcquisitionPlugin>(); instance.SidecarDisplayControls = new Dictionary <Guid, Type>(); } instance.NumOperations++; return(instance); }
private void ScanPluginAssembly(AzusaContext context, Assembly assembly) { Type[] exportedTypes = assembly.GetExportedTypes(); Array.Sort(exportedTypes, new TypeComparer()); Type pluginType = typeof(AzusaPlugin); Type imageAcquisitionPluginType = typeof(IImageAcquisitionPlugin); Type sidecarViewerPluginType = typeof(ISidecarDisplayControl); foreach (Type exportedType in exportedTypes) { if (exportedType.IsAbstract) { continue; } if (exportedType.IsInterface) { continue; } if (pluginType.IsAssignableFrom(exportedType)) { try { AzusaPlugin instance = (AzusaPlugin)Activator.CreateInstance(exportedType); LoadPlugin(instance); } catch (Exception e) { context.Splash.SetLabel(String.Format("Konnte Plug-In {0} nicht starten: {1}", exportedType.Name, e)); } } else if (imageAcquisitionPluginType.IsAssignableFrom(exportedType)) { IImageAcquisitionPlugin instance = (IImageAcquisitionPlugin)Activator.CreateInstance(exportedType); context.ImageAcquisitionPlugins.Add(instance); } else if (sidecarViewerPluginType.IsAssignableFrom(exportedType)) { ISidecarDisplayControl instance = (ISidecarDisplayControl)Activator.CreateInstance(exportedType); Guid guid = instance.DisplayControlUuid; context.SidecarDisplayControls.Add(guid, exportedType); } } }
public static void Main(string[] args) { AzusaContext context = AzusaContext.GetInstance(); if (args.Length != 0) { switch (args[0]) { case "--launcher": context.TabletMode = true; break; case "--setup": break; case "--makelicense": CreateLicenseFile(); return; default: return; } } Program program = new Program(); try { program.Run(args); } catch (StartupFailedException e) { context.Splash.InvokeClose(); DialogResult dialogResult = MessageBox.Show( "Die Azusa-Applikation konnte nicht gestartet werden. Soll das Setup-Werkzeug ausgeführt werden?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); if (dialogResult == DialogResult.Yes) { SetupForm setupForm = new SetupForm(e); dialogResult = setupForm.ShowDialog(); } } context.DestroyContext(); }
public Splash() { InitializeComponent(); bool hasImage = false; Random random = AzusaContext.GetInstance().RandomNumberGenerator; if (Directory.Exists("splashes")) { DirectoryInfo di = new DirectoryInfo("splashes"); FileInfo[] fileInfos = di.GetFiles("*.jpg"); int id = random.Next(fileInfos.GetLowerBound(0), fileInfos.GetUpperBound(0)); SetSplashImage(fileInfos[id].FullName); hasImage = true; } if (File.Exists("splash.jpg") && !hasImage) { string fname = "splash.jpg"; SetSplashImage(fname); } }
internal void ModuleScan() { AzusaContext context = AzusaContext.GetInstance(); Assembly azusaExe = Assembly.GetCallingAssembly(); Type[] classes = azusaExe.GetTypes(); Type moduleType = typeof(IAzusaModule); List <Type> foundModules = new List <Type>(); foreach (Type type in classes) { Type[] interfaces = type.GetInterfaces(); foreach (Type iface in interfaces) { if (iface.Equals(moduleType)) { foundModules.Add(type); } } } foreach (Type loadedModule in foundModules) { ToolStripButton tsb = new ToolStripButton(loadedModule.Name); tsb.Click += delegate(object sender, EventArgs args) { IAzusaModule instance = (IAzusaModule)Activator.CreateInstance(loadedModule); instance.OnLoad(); Form subform = new Form(); System.Windows.Forms.Control control = instance.GetSelf(); control.Dock = DockStyle.Fill; subform.Controls.Add(control); subform.Text = instance.Title; subform.Show(this); }; } }
public MainForm() { InitializeComponent(); context = AzusaContext.GetInstance(); }
private bool AttemptSshPortForward() { context.Splash.SetLabel("Überprüfe Verfügbarkeit des SSH-Proxy..."); string hostname = context.Ini["sshProxy"]["host"]; ushort port = Convert.ToUInt16(context.Ini["sshProxy"]["port"]); bool tcpProbe = TcpProbe(hostname, port); if (!tcpProbe) { return(false); } context.Splash.SetLabel("Versuche über SSH-Proxy mit Datenbank zu verbinden..."); string sshHost = context.Ini["sshProxy"]["host"]; int sshPort = Convert.ToInt32(context.Ini["sshProxy"]["port"]); string sshUser = context.Ini["sshProxy"]["username"]; string sshPassword = null; if (context.Ini["sshProxy"].ContainsKey("password")) { sshPassword = context.Ini["sshProxy"]["password"]; } List <AuthenticationMethod> authenticationMethods = new List <AuthenticationMethod>(); authenticationMethods.Add(new NoneAuthenticationMethod(sshUser)); if (File.Exists("ssh.key")) { authenticationMethods.Add( new PrivateKeyAuthenticationMethod(sshUser, new PrivateKeyFile[] { new PrivateKeyFile("ssh.key") })); } if (string.IsNullOrEmpty(sshPassword) && authenticationMethods.Count == 1) { context.Splash.Invoke((MethodInvoker) delegate { sshPassword = TextInputForm.PromptPassword(String.Format("Passwort für {0} auf {1}?", sshUser, sshHost), context.Splash); }); } if (!string.IsNullOrEmpty(sshPassword) && authenticationMethods.Count == 1) { authenticationMethods.Add(new PasswordAuthenticationMethod(sshUser, sshPassword)); } if (authenticationMethods.Count > 1) { context.Splash.SetLabel("Verbinde mit SSH Server..."); ConnectionInfo sshConnectionInfo = new ConnectionInfo(sshHost, sshPort, sshUser, authenticationMethods.ToArray()); context.SSH = new SshClient(sshConnectionInfo); if (!context.SSH.IsConnected) { context.SSH.Connect(); } context.Splash.SetLabel("Starte Port-Forwarding..."); uint localPort = (uint)AzusaContext.FindFreePort(); ForwardedPort sqlPort = new ForwardedPortLocal("127.0.0.1", localPort, context.Ini["postgresql"]["server"], Convert.ToUInt16(context.Ini["postgresql"]["port"])); context.SSH.AddForwardedPort(sqlPort); sqlPort.Start(); bool worksWithForward = TcpProbe("127.0.0.1", (int)localPort); if (worksWithForward) { context.Ini["postgresql"]["server"] = "127.0.0.1"; context.Ini["postgresql"]["port"] = localPort.ToString(); return(true); } else { context.SSH.Disconnect(); context.SSH = null; } } return(false); }
private bool PrepareRun() { //Lade Konfigurationsdatei context = AzusaContext.GetInstance(); FileInfo exePath = new FileInfo(Assembly.GetEntryAssembly().Location); FileInfo iniPath = new FileInfo(Path.Combine(exePath.Directory.FullName, "azusa.ini")); if (!iniPath.Exists) { throw new StartupFailedException(StartupFailReason.AzusaIniNotFound); } context.Ini = new Ini("azusa.ini"); IniSection azusaIniSection = context.Ini["azusa"]; if (azusaIniSection.ContainsKey("chdir")) { if (!string.IsNullOrEmpty(azusaIniSection["chdir"])) { if (Directory.Exists(azusaIniSection["chdir"])) { Environment.CurrentDirectory = azusaIniSection["chdir"]; } else { Console.WriteLine("Der Ordner {0} konnte nicht gefunden werden!", azusaIniSection["chdir"]); } } } CreateSplashThread(); context.Splash.SetLabel("Lade Lizenzdatei..."); LoadLicense(); context.Splash.SetLabel("Lade Icon..."); string procFileName = Process.GetCurrentProcess().MainModule.FileName; Icon icon = Icon.ExtractAssociatedIcon(procFileName); context.Icon = icon; context.Splash.SetLabel("Starte Webserver..."); context.WebServer = new WebServer(); bool connected = false; int useRest = context.ReadIniKey("rest", "use", 0); if (useRest > 0) { try { Console.WriteLine("Überprüfe die Verfügbarkeit der REST-Schnittstelle..."); RestDriver restDriver = new RestDriver(); if (restDriver.ConnectionIsValid()) { connected = true; context.DatabaseDriver = restDriver; } else { Console.WriteLine("REST-Schnittstelle sagt: " + restDriver.RestDriverErrorState); } } catch (Exception e) { Console.WriteLine("Failed to use the REST Client: " + e.Message); } } if (!connected) { bool onlineAvailable = false; context.Splash.SetLabel("Überprüfe Verfügbarkeit der Online-Datenbank..."); try { if (Convert.ToInt32(azusaIniSection["forceOffline"]) == 0) { Ping ping = new Ping(); PingReply pong = ping.Send(context.Ini["postgresql"]["server"]); if (pong.Status == IPStatus.Success) { onlineAvailable = TcpProbe(context.Ini["postgresql"]["server"], Convert.ToInt16(context.Ini["postgresql"]["port"])); } if (!onlineAvailable) { if (context.Ini.ContainsKey("sshProxy")) { if (Convert.ToInt32(context.Ini["sshProxy"]["allow"]) > 0) { onlineAvailable = AttemptSshPortForward(); } } } } } catch { onlineAvailable = false; } if (onlineAvailable) { try { ConnectOnline(); connected = true; } catch (DatabaseConnectionException e) { context.Splash.SetLabel(""); DialogResult askOffline = MessageBox.Show( String.Format( "Die Verbindung zur Datenbank ist fehlgeschlagen. Soll offline gearbeitet werden?\n{0}", e), "Azusa", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation); if (askOffline == DialogResult.Yes) { ConnectOffline(); connected = true; } else { context.Splash.InvokeClose(); return(true); } } } } if (!connected) { ConnectOffline(); } if (context.DatabaseDriver == null) { throw new StartupFailedException(StartupFailReason.NoDatabaseAvailable); } context.Splash.SetLabel("Erstelle Hauptfenster..."); context.MainForm = new MainForm(); context.Splash.SetLabel("Lade Module..."); context.MainForm.BootMediaLibrary(); context.MainForm.ModuleScan(); context.MainForm.Icon = icon; context.Splash.SetLabel("Lade Plug-Ins..."); LoadPlugins(context); context.Splash.InvokeClose(); return(false); }