Search in sources :

Example 1 with ProxyController

use of ch.cyberduck.binding.ProxyController in project cyberduck by iterate-ch.

the class ProxyControllerTest method testInvokeWait.

@Test
public void testInvokeWait() throws Exception {
    final CountDownLatch entry = new CountDownLatch(1);
    final AtomicBoolean c = new AtomicBoolean();
    final ProxyController controller = new ProxyController() {

        @Override
        public void invoke(final MainAction runnable, final boolean wait) {
            assertTrue(wait);
            super.invoke(runnable, wait);
            entry.countDown();
        }
    };
    new Thread(() -> controller.invoke(new DefaultMainAction() {

        @Override
        public void run() {
            c.set(true);
        }
    }, true)).start();
    entry.await(1, TimeUnit.SECONDS);
    assertTrue(c.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DefaultMainAction(ch.cyberduck.core.threading.DefaultMainAction) ProxyController(ch.cyberduck.binding.ProxyController) CountDownLatch(java.util.concurrent.CountDownLatch) DefaultMainAction(ch.cyberduck.core.threading.DefaultMainAction) MainAction(ch.cyberduck.core.threading.MainAction) Test(org.junit.Test)

Example 2 with ProxyController

use of ch.cyberduck.binding.ProxyController in project cyberduck by iterate-ch.

the class MainController method application_openFile.

@Override
public boolean application_openFile(final NSApplication app, final String filename) {
    if (log.isDebugEnabled()) {
        log.debug(String.format("Open file %s", filename));
    }
    final Local f = LocalFactory.get(filename);
    if (f.exists()) {
        if ("duck".equals(f.getExtension())) {
            final Host bookmark;
            try {
                newDocument().mount(HostReaderFactory.get().read(f));
                return true;
            } catch (AccessDeniedException e) {
                log.error(String.format("Failure reading bookmark from %s. %s", f, e.getMessage()));
                return false;
            }
        } else if ("cyberducklicense".equals(f.getExtension())) {
            final License l = LicenseFactory.get(f);
            if (l.verify(new DisabledLicenseVerifierCallback())) {
                try {
                    f.copy(LocalFactory.get(SupportDirectoryFinderFactory.get().find(), f.getName()));
                    final NSAlert alert = NSAlert.alert(l.toString(), LocaleFactory.localizedString("Thanks for your support! Your contribution helps to further advance development to make Cyberduck even better.", "License") + "\n\n" + LocaleFactory.localizedString("Your donation key has been copied to the Application Support folder.", "License"), // default
                    LocaleFactory.localizedString("Continue", "License"), // other
                    null, null);
                    alert.setAlertStyle(NSAlert.NSInformationalAlertStyle);
                    if (new AlertSheetReturnCodeMapper().getOption(alert.runModal()) == SheetCallback.DEFAULT_OPTION) {
                        for (BrowserController c : MainController.getBrowsers()) {
                            c.removeDonateWindowTitle();
                        }
                        this.updateLicenseMenu();
                    }
                } catch (AccessDeniedException e) {
                    log.error(e.getMessage());
                    return false;
                }
            } else {
                final NSAlert alert = NSAlert.alert(LocaleFactory.localizedString("Not a valid registration key", "License"), LocaleFactory.localizedString("This donation key does not appear to be valid.", "License"), // default
                LocaleFactory.localizedString("Continue", "License"), // other
                null, null);
                alert.setAlertStyle(NSAlert.NSWarningAlertStyle);
                alert.setShowsHelp(true);
                alert.setDelegate(new ProxyController() {

                    @Action
                    public boolean alertShowHelp(NSAlert alert) {
                        BrowserLauncherFactory.get().open(ProviderHelpServiceFactory.get().help());
                        return true;
                    }
                }.id());
                alert.runModal();
            }
            return true;
        } else if ("cyberduckprofile".equals(f.getExtension())) {
            try {
                final Profile profile = ProfileReaderFactory.get().read(f);
                if (profile.isEnabled()) {
                    if (log.isDebugEnabled()) {
                        log.debug(String.format("Register profile %s", profile));
                    }
                    final ProtocolFactory protocols = ProtocolFactory.get();
                    protocols.register(profile);
                    final Host host = new Host(profile, profile.getDefaultHostname(), profile.getDefaultPort());
                    newDocument().addBookmark(host);
                    // Register in application support
                    final Local profiles = LocalFactory.get(SupportDirectoryFinderFactory.get().find(), preferences.getProperty("profiles.folder.name"));
                    if (!profiles.exists()) {
                        new DefaultLocalDirectoryFeature().mkdir(profiles);
                    }
                    f.copy(LocalFactory.get(profiles, f.getName()));
                }
            } catch (AccessDeniedException e) {
                log.error(String.format("Failure reading profile from %s. %s", f, e));
                return false;
            }
        } else {
            // Upload file
            this.background(new AbstractBackgroundAction<Void>() {

                @Override
                public Void run() {
                    // Wait until bookmarks are loaded
                    Uninterruptibles.awaitUninterruptibly(bookmarksSemaphore);
                    return null;
                }

                @Override
                public void cleanup() {
                    upload(f);
                }

                @Override
                public String getActivity() {
                    return "Open File";
                }
            });
            return true;
        }
    }
    return false;
}
Also used : AccessDeniedException(ch.cyberduck.core.exception.AccessDeniedException) AbstractBackgroundAction(ch.cyberduck.core.threading.AbstractBackgroundAction) Action(ch.cyberduck.binding.Action) License(ch.cyberduck.core.aquaticprime.License) DisabledLicenseVerifierCallback(ch.cyberduck.core.aquaticprime.DisabledLicenseVerifierCallback) NSAttributedString(ch.cyberduck.binding.foundation.NSAttributedString) DefaultLocalDirectoryFeature(ch.cyberduck.core.local.DefaultLocalDirectoryFeature) NSAlert(ch.cyberduck.binding.application.NSAlert) ProxyController(ch.cyberduck.binding.ProxyController) AlertSheetReturnCodeMapper(ch.cyberduck.binding.application.AlertSheetReturnCodeMapper)

Example 3 with ProxyController

use of ch.cyberduck.binding.ProxyController in project cyberduck by iterate-ch.

the class ProxyControllerTest method testInvokeNoWait.

@Test
public void testInvokeNoWait() throws Exception {
    final CountDownLatch entry = new CountDownLatch(1);
    final CountDownLatch invoked = new CountDownLatch(1);
    final AtomicBoolean c = new AtomicBoolean();
    final ProxyController controller = new ProxyController() {

        @Override
        public void invoke(final MainAction runnable, final boolean wait) {
            assertFalse(wait);
            super.invoke(runnable, wait);
            assertFalse(c.get());
            entry.countDown();
        }
    };
    new Thread(() -> controller.invoke(new DefaultMainAction() {

        @Override
        public void run() {
            c.set(true);
            invoked.countDown();
        }
    }, false)).start();
    entry.await(1, TimeUnit.SECONDS);
    invoked.await(1, TimeUnit.SECONDS);
    assertTrue(c.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DefaultMainAction(ch.cyberduck.core.threading.DefaultMainAction) ProxyController(ch.cyberduck.binding.ProxyController) CountDownLatch(java.util.concurrent.CountDownLatch) DefaultMainAction(ch.cyberduck.core.threading.DefaultMainAction) MainAction(ch.cyberduck.core.threading.MainAction) Test(org.junit.Test)

Example 4 with ProxyController

use of ch.cyberduck.binding.ProxyController in project cyberduck by iterate-ch.

the class ProxyControllerTest method testBackground.

@Test
public void testBackground() throws Exception {
    final AbstractController controller = new ProxyController();
    final CountDownLatch entry = new CountDownLatch(1);
    final CountDownLatch exit = new CountDownLatch(1);
    final AbstractBackgroundAction<Object> action = new AbstractBackgroundAction<Object>() {

        @Override
        public void init() {
            assertEquals("main", Thread.currentThread().getName());
        }

        @Override
        public Object run() {
            assertEquals("background-1", Thread.currentThread().getName());
            return null;
        }

        @Override
        public void cleanup() {
            assertEquals("main", Thread.currentThread().getName());
            assertFalse(controller.getRegistry().contains(this));
        }
    };
    controller.background(action).get();
}
Also used : AbstractBackgroundAction(ch.cyberduck.core.threading.AbstractBackgroundAction) ProxyController(ch.cyberduck.binding.ProxyController) CountDownLatch(java.util.concurrent.CountDownLatch) AbstractController(ch.cyberduck.core.AbstractController) Test(org.junit.Test)

Example 5 with ProxyController

use of ch.cyberduck.binding.ProxyController in project cyberduck by iterate-ch.

the class SparklePeriodicUpdateCheckerTest method testCheck.

@Test
public void testCheck() {
    final SparklePeriodicUpdateChecker updater = new SparklePeriodicUpdateChecker(new ProxyController());
    updater.check(false);
}
Also used : ProxyController(ch.cyberduck.binding.ProxyController) Test(org.junit.Test)

Aggregations

ProxyController (ch.cyberduck.binding.ProxyController)5 Test (org.junit.Test)4 CountDownLatch (java.util.concurrent.CountDownLatch)3 AbstractBackgroundAction (ch.cyberduck.core.threading.AbstractBackgroundAction)2 DefaultMainAction (ch.cyberduck.core.threading.DefaultMainAction)2 MainAction (ch.cyberduck.core.threading.MainAction)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 Action (ch.cyberduck.binding.Action)1 AlertSheetReturnCodeMapper (ch.cyberduck.binding.application.AlertSheetReturnCodeMapper)1 NSAlert (ch.cyberduck.binding.application.NSAlert)1 NSAttributedString (ch.cyberduck.binding.foundation.NSAttributedString)1 AbstractController (ch.cyberduck.core.AbstractController)1 DisabledLicenseVerifierCallback (ch.cyberduck.core.aquaticprime.DisabledLicenseVerifierCallback)1 License (ch.cyberduck.core.aquaticprime.License)1 AccessDeniedException (ch.cyberduck.core.exception.AccessDeniedException)1 DefaultLocalDirectoryFeature (ch.cyberduck.core.local.DefaultLocalDirectoryFeature)1