Esempio n. 1
0
 protected AzusaContext GetContext()
 {
     if (context == null)
     {
         context = AzusaContext.GetInstance();
     }
     return(context);
 }
Esempio n. 2
0
        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();
        }
Esempio n. 3
0
        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();
        }
Esempio n. 4
0
        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);
            }
        }
Esempio n. 5
0
        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);
                };
            }
        }
Esempio n. 6
0
 public MainForm()
 {
     InitializeComponent();
     context = AzusaContext.GetInstance();
 }
Esempio n. 7
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);
        }