Example #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);
        }
Example #2
0
        /// <summary>
        /// Creates a new client and saves it to the configuration. (No exception handling!)
        /// </summary>
        /// <param name="type">Type of the new client instance.</param>
        /// <param name="title">Unique title of the new client instance.</param>
        /// <param name="host">Address of the remote server for the client instance.</param>
        /// <param name="port">Port of the remote server for the client instance.</param>
        /// <param name="user">User on the remote server for the client instance.</param>
        /// <param name="password">Password of user on the remote server for the client instance.</param>
        /// <returns>True if client was created.</returns>
        public bool CreateClientInstance(InstanceType type, string title, string host, int port, string user, string password)
        {
            if (type != InstanceType.Unknown)
            {
                IProtocolManager manager;
                switch (type)
                {
                case InstanceType.FtpsClient:
                    manager = new FtpsRemoteManager(host, port, user, password);
                    break;

                default:
                    return(false);
                }
                register.RegisterInstance(type, title, manager);
                return(true);
            }
            return(false);
        }