public DriverUIState()
 {
     Driver = new RestDriver();
 }
Example #2
0
        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);
        }