Exemplo n.º 1
0
        public async Task <bool> OpenUplinkWindowAsync(string title, BrowserWindow mainWindow = null, BrowserWindowOptions options = null)
        {
            // Checkout main window.
            mainWindow = mainWindow ?? Electron.WindowManager.BrowserWindows.First();
            // If there are no defined options, use default ones.
            if (options == null)
            {
                options = new ElectronNET.API.Entities.BrowserWindowOptions()
                {
                    Title = title,
                    Show  = false,
                };
            }

            // Start creating window.
            Task <BrowserWindow> createWindow = Electron.WindowManager.CreateWindowAsync(options);

            try
            {
                /* Check if wanted uplink was activated at runtime yet. */
                UplinkModel uplink = (UplinkModel)register.ProvideInstance("uplink", title);
                if (!register.InstanceExists(uplink.Type, title))
                {
                    // Init remote manager.
                    IProtocolManager protocolManager = new FtpsRemoteManager(uplink.Host, uplink.Host.UrlGetPort(), uplink.User, uplink.Password);
                    register.RegisterInstance(uplink.Type, title, protocolManager);
                    // Init root directory.
                    ManagedDirectory rootDirectory = protocolManager.GetWorkingDirectory();
                    register.RegisterInstance("rootDirectory", title, rootDirectory);
                }
            }
            catch (ArgumentNullException e) { ExceptionHandler.LogException("Instance and/or type is null.", e); }
            catch (ArgumentException e) { ExceptionHandler.LogException(e); }
            catch (InvalidOperationException e) { ExceptionHandler.LogException(e); }
            catch (KeyNotFoundException e) { ExceptionHandler.LogException("The property is retrieved and type does not exist in the collection.", e); }

            /* Create window. */
            BrowserWindow window = await createWindow;

            // End here if creation was not successful.
            if (createWindow.IsFaulted)
            {
                ExceptionHandler.LogException("The window could not be created.", createWindow.Exception);
                return(false);
            }
            window.LoadURL(@"/uplink/index/{title}?type={type}");
            window.OnReadyToShow += () => window.Show();
            window.SetParentWindow(mainWindow);

            return(true);
        }