示例#1
0
        static MainController()
        {
            StructureMapBootstrapper.Bootstrap();
            PreferencesFactory.set(new ApplicationPreferences());
            ProtocolFactory.get().register(new FTPProtocol(), new FTPTLSProtocol(), new SFTPProtocol(), new DAVProtocol(),
                                           new DAVSSLProtocol(), new SwiftProtocol(), new S3Protocol(), new GoogleStorageProtocol(),
                                           new AzureProtocol(), new IRODSProtocol(), new SpectraProtocol(), new B2Protocol(), new DriveProtocol(),
                                           new DropboxProtocol(), new HubicProtocol(), new LocalProtocol(), new OneDriveProtocol(),
                                           new MantaProtocol(),
                                           new SDSProtocol());

            if (!Debugger.IsAttached)
            {
                // Add the event handler for handling UI thread exceptions to the event.
                System.Windows.Forms.Application.ThreadException += ExceptionHandler;

                // Set the unhandled exception mode to force all Windows Forms errors to go through
                // our handler.
                System.Windows.Forms.Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);

                // Add the event handler for handling non-UI thread exceptions to the event.
                AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionHandler;
            }
            //make sure that a language change takes effect after a restart only
            StartupLanguage = PreferencesFactory.get().getProperty("application.language");
        }
示例#2
0
        static void Main(string[] args)
        {
            bool  newInstance;
            Mutex mutex = new Mutex(true, "iterate/cyberduck.io", out newInstance);

            var preferences = new ApplicationPreferences();

            PreferencesFactory.set(preferences);
            var argsTask = Task.Run(async() =>
            {
                using (var channel = new ChannelFactory <ICyberduck>(new NetNamedPipeBinding(), new EndpointAddress("net.pipe://localhost/iterate/cyberduck.io")))
                {
                    ICyberduck proxy = null;

                    // Connect to pipe
                    int retries    = 0;
                    bool connected = false;
                    while (!connected && retries < 7) // Timeout after 127 seconds
                    {
                        try
                        {
                            proxy = channel.CreateChannel();
                            proxy.Connect();
                            connected = true;
                        }
                        catch (Exception e)
                        {
                            await Task.Delay(TimeSpan.FromSeconds(Math.Pow(2, retries++)));
                        }
                    }
                    if (!connected)
                    {
                        throw new TimeoutException();
                    }

                    if (!newInstance)
                    {
                        proxy.NewInstance();
                    }

                    foreach (var item in args)
                    {
                        Uri result;
                        if (Uri.TryCreate(item, UriKind.Absolute, out result))
                        {
                            switch (result.Scheme.ToLowerInvariant())
                            {
                            case var scheme when scheme == preferences.getProperty("oauth.handler.scheme"):
                                if (result.AbsolutePath == "oauth")
                                {
                                    var query = HttpUtility.ParseQueryString(result.Query);
                                    var state = query.Get("state");
                                    var code  = query.Get("code");
                                    proxy.OAuth(state, code);
                                }
                                break;

                            case "file":
                                var localPath = result.LocalPath;
                                if (result.IsFile)
                                {
                                    if (File.Exists(localPath))
                                    {
                                        switch (Path.GetExtension(localPath).ToLowerInvariant())
                                        {
                                        case ".cyberducklicense":
                                            proxy.RegisterRegistration(localPath);
                                            break;

                                        case ".cyberduckprofile":
                                            proxy.RegisterProfile(localPath);
                                            break;

                                        case ".duck":
                                            proxy.RegisterBookmark(localPath);
                                            break;
                                        }
                                    }
                                }
                                else
                                {
                                    proxy.QuickConnect(item);
                                }

                                break;
                            }
                        }
                    }
                }
            });

            if (newInstance)
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);

                Application.Run(MainController.Application);
            }
            else
            {
                try
                {
                    argsTask.Wait();
                }
                catch (AggregateException aggregateException)
                {
                    aggregateException.Handle(x =>
                    {
                        if (x is CommunicationObjectFaultedException)
                        {
                            // silent catch this error.
                            return(true);
                        }
                        return(false);
                    });
                }
            }
            mutex.Close();
        }