Example #1
0
        /// <summary>
        /// Try to find the CMIS server associated to any URL.
        /// Users can provide the URL of the web interface, and we have to return the CMIS URL
        /// Returns the list of repositories as well.
        /// </summary>
        static public Tuple<CmisServer, Exception> GetRepositoriesFuzzy(ServerCredentials credentials)
        {
            Dictionary<string, string> repositories = null;
            Exception firstException = null;

            // Try the given URL, maybe user directly entered the CMIS AtomPub endpoint URL.
            try
            {
                repositories = GetRepositories(credentials);
            }
            catch (CmisRuntimeException e)
            {
                if (e.Message == "ConnectFailure")
                    return new Tuple<CmisServer, Exception>(new CmisServer(credentials.Address, null), new ServerNotFoundException(e.Message, e));
                firstException = e;
            }
            catch (Exception e)
            {
                // Save first Exception and try other possibilities.
                firstException = e;
            }
            if (repositories != null)
            {
                // Found!
                return new Tuple<CmisServer, Exception>(new CmisServer(credentials.Address, repositories), null);
            }

            // Extract protocol and server name or IP address
            string prefix = credentials.Address.GetLeftPart(UriPartial.Authority);

            // See https://github.com/aegif/CmisSync/wiki/What-address for the list of ECM products prefixes
            // Please send us requests to support more CMIS servers: https://github.com/aegif/CmisSync/issues
            string[] suffixes = {
                "/alfresco/api/-default-/public/cmis/versions/1.1/atom", // Alfresco 4.2 CMIS 1.1
                "/alfresco/api/-default-/public/cmis/versions/1.0/atom", // Alfresco 4.2 CMIS 1.0
                "/alfresco/cmisatom", // Alfresco 4.0 and 4.1
                "/alfresco/service/cmis", // Alfresco 3.x
                "/cmis/atom11", // OpenDataSpace
                "/rest/private/cmisatom/", // eXo Platform
                "/xcmis/rest/cmisatom", // xCMIS
                "/files/basic/cmis/my/servicedoc", // IBM Connections
                "/p8cmis/resources/Service", // IBM FileNet
                "/_vti_bin/cmis/rest?getRepositories", // Microsoft SharePoint
                "/nemakiware/atom/bedroom", // NemakiWare  TODO: different port, typically 8080 for Web UI and 3000 for CMIS
                "/nuxeo/atom/cmis", // Nuxeo
                "/cmis/atom",
                "/cmis/resources/", // EMC Documentum
                "/emc-cmis-ea/resources/", // EMC Documentum
                "/emc-cmis-weblogic/resources/", // EMC Documentum
                "/emc-cmis-wls/resources/", // EMC Documentum
                "/emc-cmis-was61/resources/", // EMC Documentum
                "/emc-cmis-wls1030/resources/", // EMC Documentum
                "/docushare/ds_mobile_connector/atom", // Xerox DocuShare
                "/documents/ds_mobile_connector/atom" // Xerox DocuShare  TODO: can be anything instead of "documents"
            };
            string bestUrl = null;
            // Try all suffixes
            for (int i=0; i < suffixes.Length; i++)
            {
                string fuzzyUrl = prefix + suffixes[i];
                Logger.Info("Sync | Trying with " + fuzzyUrl);
                try
                {
                    ServerCredentials cred = new ServerCredentials()
                    {
                        UserName = credentials.UserName,
                        Password = credentials.Password.ToString(),
                        Address = new Uri(fuzzyUrl)
                    };
                    repositories = GetRepositories(cred);
                }
                catch (CmisPermissionDeniedException e)
                {
                    firstException = new PermissionDeniedException(e.Message, e);
                    bestUrl = fuzzyUrl;
                }
                catch (Exception e)
                {
                    // Do nothing, try other possibilities.
                    Logger.Debug(e.Message);
                }
                if (repositories != null)
                {
                    // Found!
                    return new Tuple<CmisServer, Exception>( new CmisServer(new Uri(fuzzyUrl), repositories), null);
                }
            }

            // Not found. Return also the first exception to inform the user correctly
            return new Tuple<CmisServer,Exception>(new CmisServer(bestUrl==null?credentials.Address:new Uri(bestUrl), null), firstException);
        }
Example #2
0
        /// <summary>
        /// Load repositories information from a CMIS endpoint.
        /// </summary>
        static public Tuple<CmisServer, Exception> GetRepositoriesFuzzy(ServerCredentials credentials)
        {
            try
            {
                return CmisUtils.GetRepositoriesFuzzy(credentials);
            }
            catch (Exception e)
            {
                return new Tuple<CmisServer, Exception>(null, e);
            }

        }
Example #3
0
        /// <summary>
        /// Get the list of repositories of a CMIS server
        /// Each item contains id +
        /// </summary>
        /// <returns>The list of repositories. Each item contains the identifier and the human-readable name of the repository.</returns>
        static public Dictionary<string,string> GetRepositories(ServerCredentials credentials)
        {
            Dictionary<string,string> result = new Dictionary<string,string>();

            // If no URL was provided, return empty result.
            if (credentials.Address == null )
            {
                return result;
            }

            IList<IRepository> repositories;
            try
            {
                repositories = Auth.Auth.GetCmisRepositories(credentials.Address, credentials.UserName, credentials.Password.ToString());
            }
            catch (CmisPermissionDeniedException e)
            {
                Logger.Error("CMIS server found, but permission denied. Please check username/password. ", e);
                throw;
            }
            catch (CmisRuntimeException e)
            {
                Logger.Error("No CMIS server at this address, or no connection. ", e);
                throw;
            }
            catch (CmisObjectNotFoundException e)
            {
                Logger.Error("No CMIS server at this address, or no connection. ", e);
                throw;
            }
            catch (CmisConnectionException e)
            {
                Logger.Error("No CMIS server at this address, or no connection. ", e);
                throw;
            }
            catch (CmisInvalidArgumentException e)
            {
                Logger.Error("Invalid URL, maybe Alfresco Cloud? ", e);
                throw;
            }

            // Populate the result list with identifier and name of each repository.
            foreach (IRepository repo in repositories)
            {
                // Repo name is sometimes empty (ex: Alfresco), in such case show the repo id instead.
                string name = repo.Name.Length == 0 ? repo.Id : repo.Name;

                result.Add(repo.Id, name);
            }

            return result;
        }
Example #4
0
        private void ShowAdd1Page()
        {
            this.Present();
            Header = CmisSync.Properties_Resources.Where;

            VBox layout_vertical   = new VBox (false, 12);
            HBox layout_fields     = new HBox (true, 12);
            VBox layout_address    = new VBox (true, 0);
            HBox layout_address_help = new HBox(false, 3);
            VBox layout_user       = new VBox (true, 0);
            VBox layout_password   = new VBox (true, 0);

            // Address
            Label address_label = new Label()
            {
                UseMarkup = true,
                          Xalign = 0,
                          Markup = "<b>" + 
                              CmisSync.Properties_Resources.EnterWebAddress +
                              "</b>"
            };

            Entry address_entry = new Entry () {
                Text = (Controller.PreviousAddress == null || String.IsNullOrEmpty(Controller.PreviousAddress.ToString()))?"https://":Controller.PreviousAddress.ToString(),
                     ActivatesDefault = false
            };

            Label address_help_label = new Label()
            {
                Xalign = 0,
                       UseMarkup = true,
                       Markup = "<span foreground=\"#808080\" size=\"small\">" +
                           CmisSync.Properties_Resources.Help + ": " +
                           "</span>"
            };
            EventBox address_help_urlbox = new EventBox();
            Label address_help_urllabel = new Label()
            {
                Xalign = 0,
                       UseMarkup = true,
                       Markup = "<span foreground=\"blue\" underline=\"single\" size=\"small\">" +
                           CmisSync.Properties_Resources.WhereToFind +
                           "</span>"
            };
            address_help_urlbox.Add(address_help_urllabel);
            address_help_urlbox.ButtonPressEvent += delegate(object o, ButtonPressEventArgs args) {
                Process process = new Process();
                process.StartInfo.FileName  = "xdg-open";
                process.StartInfo.Arguments = "https://github.com/aegif/CmisSync/wiki/What-address";
                process.Start ();
            };
            address_help_urlbox.EnterNotifyEvent += delegate(object o, EnterNotifyEventArgs args) {
                address_help_urlbox.GdkWindow.Cursor = hand_cursor;
            };

            Label address_error_label = new Label()
            {
                Xalign = 0,
                UseMarkup = true,
                Markup = ""
            };
            address_error_label.Hide();

            // User
            Entry user_entry = new Entry () {
                Text = Controller.PreviousPath,
                     ActivatesDefault = false
            };

            if(String.IsNullOrEmpty(Controller.saved_user))
            {
                user_entry.Text = Environment.UserName;
            }
            else
            {
                user_entry.Text = Controller.saved_user;
            }

            // Password
            Entry password_entry = new Entry () {
                Visibility = false,
                ActivatesDefault = true
            };

            Controller.ChangeAddressFieldEvent += delegate (string text,
                    string example_text) {

                Application.Invoke (delegate {
                        address_entry.Text      = text;
                        });
            };

            Controller.ChangeUserFieldEvent += delegate (string text,
                    string example_text) {

                Application.Invoke (delegate {
                        user_entry.Text      = text;
                        });
            };

            Controller.ChangePasswordFieldEvent += delegate (string text,
                    string example_text) {

                Application.Invoke (delegate {
                        password_entry.Text      = text;
                        });
            };

            address_entry.Changed += delegate {
                string error = Controller.CheckAddPage(address_entry.Text);
                if (!String.IsNullOrEmpty(error)) {
                    address_error_label.Markup = "<span foreground=\"red\">" + CmisSync.Properties_Resources.ResourceManager.GetString(error, CultureInfo.CurrentCulture) + "</span>";
                    address_error_label.Show();
                } else {
                    address_error_label.Hide();
                }
            };

            // Address
            layout_address_help.PackStart(address_help_label, false, false, 0);
            layout_address_help.PackStart(address_help_urlbox, false, false, 0);
            layout_address.PackStart (address_label, true, true, 0);
            layout_address.PackStart (address_entry, true, true, 0);
            layout_address.PackStart (layout_address_help, true, true, 0);
//            layout_address.PackStart (address_error_label, true, true, 0);

            // User
            layout_user.PackStart (new Label () {
                    Markup = "<b>" + CmisSync.Properties_Resources.User + ":</b>",
                    Xalign = 0
                    }, true, true, 0);
            layout_user.PackStart (user_entry, false, false, 0);

            // Password
            layout_password.PackStart (new Label () {
                    Markup = "<b>" + CmisSync.Properties_Resources.Password + ":</b>",
                    Xalign = 0
                    }, true, true, 0);
            layout_password.PackStart (password_entry, false, false, 0);

            layout_fields.PackStart (layout_user);
            layout_fields.PackStart (layout_password);

//            layout_vertical.PackStart (new Label (""), false, false, 0);
            layout_vertical.PackStart (layout_address, false, false, 0);
            layout_vertical.PackStart (layout_fields, false, false, 0);
            layout_vertical.PackStart (address_error_label, true, true, 0);

            Add (layout_vertical);

            // Cancel button
            Button cancel_button = new Button (cancelText);

            cancel_button.Clicked += delegate {
                Controller.PageCancelled ();
            };

            // Continue button
            Button continue_button = new Button (continueText) {
                Sensitive = String.IsNullOrEmpty( Controller.CheckAddPage (address_entry.Text))
            };

            continue_button.Clicked += delegate {
                // Show wait cursor
                this.GdkWindow.Cursor = wait_cursor;

                // Try to find the CMIS server (asynchronous using a delegate)
                GetRepositoriesFuzzyDelegate dlgt =
                    new GetRepositoriesFuzzyDelegate(CmisUtils.GetRepositoriesFuzzy);
                ServerCredentials credentials = new ServerCredentials() {
                    UserName = user_entry.Text,
                    Password = password_entry.Text,
                    Address = new Uri(address_entry.Text)
                };
                IAsyncResult ar = dlgt.BeginInvoke(credentials, null, null);
                while (!ar.AsyncWaitHandle.WaitOne(100)) {
                    while (Application.EventsPending()) {
                        Application.RunIteration();
                    }
                }
                Tuple<CmisServer, Exception> result = dlgt.EndInvoke(ar);
                CmisServer cmisServer = result.Item1;
                if(cmisServer != null)
                {
                    Controller.repositories = cmisServer.Repositories;
                    address_entry.Text = cmisServer.Url.ToString();
                }
                else
                {
                    Controller.repositories = null;
                }
                // Hide wait cursor
                this.GdkWindow.Cursor = default_cursor;

                if (Controller.repositories == null)
                {
                    // Show warning
                    string warning = "";
                    string message = result.Item2.Message;
                    Exception e = result.Item2;
                    if (e is CmisPermissionDeniedException)
                    {
                        warning = Properties_Resources.LoginFailedForbidden;
                    }
//                    else if (e is CmisServerNotFoundException)
//                    {
//                        warning = Properties_Resources.ConnectFailure;
//                    }
                    else if (e.Message == "SendFailure" && cmisServer.Url.Scheme.StartsWith("https"))
                    {
                        warning = Properties_Resources.SendFailureHttps;
                    }
                    else if (e.Message == "TrustFailure")
                    {
                        warning = Properties_Resources.TrustFailure;
                    }
                    else
                    {
                        warning = message + Environment.NewLine + Properties_Resources.Sorry;
                    }
                    address_error_label.Markup = "<span foreground=\"red\">" + warning + "</span>";
                    address_error_label.Show();
                }
                else
                {
                    // Continue to folder selection
                    Controller.Add1PageCompleted(
                            new Uri(address_entry.Text), user_entry.Text, password_entry.Text);
                }
            };

            Controller.UpdateAddProjectButtonEvent += delegate (bool button_enabled) {
                Application.Invoke (delegate {
                    continue_button.Sensitive = button_enabled;
                    if(button_enabled) {
                        continue_button.SetFlag(Gtk.WidgetFlags.CanFocus);
                        continue_button.SetFlag(Gtk.WidgetFlags.CanDefault);
                        continue_button.GrabDefault();
                    }
                });
            };

            AddButton (cancel_button);
            AddButton (continue_button);

            Controller.CheckAddPage (address_entry.Text);
            address_entry.GrabFocus ();
        }
Example #5
0
        /// <summary>
        /// Constructor.
        /// </summary>
        public Setup()
        {
            Logger.Debug("Entering constructor.");

            // Defines how to show the setup window.
            Controller.ShowWindowEvent += delegate
            {
                Dispatcher.BeginInvoke((Action)delegate
                {
                    Logger.Debug("Entering ShowWindowEvent.");
                    Show();
                    Activate();
                    BringIntoView();
                    Logger.Debug("Exiting ShowWindowEvent.");
                });
            };

            // Defines how to hide the setup windows.
            Controller.HideWindowEvent += delegate
            {
                Dispatcher.BeginInvoke((Action)delegate
                {
                    Hide();
                });
            };

            // Defines what to do when changing page.
            // The remote folder addition wizard has several steps.
            Controller.ChangePageEvent += delegate(PageType type)
            {
                Dispatcher.BeginInvoke((Action)delegate
                {
                    Logger.Debug("Entering ChangePageEvent.");
                    Reset();

                    //Remove window activated event handler if one exists...
                    if (windowActivatedEventHandler != null)
                    {
                        Logger.Debug("Removing window activated event handler");
                        Activated -= windowActivatedEventHandler;
                        windowActivatedEventHandler = null;
                    }

                    // Show appropriate setup page.
                    switch (type)
                    {
                        // Welcome page that shows up at first run.
                        #region Page Setup
                        case PageType.Setup:
                            {
                                // GUI elements.

                                Header = Properties_Resources.Welcome;
                                Description = Properties_Resources.Intro;

                                Button cancel_button = new Button()
                                {
                                    Content = Properties_Resources.Cancel
                                };

                                Button continue_button = new Button()
                                {
                                    Content = Properties_Resources.Continue,
                                    IsEnabled = false
                                };

                                Buttons.Add(continue_button);
                                Buttons.Add(cancel_button);

                                continue_button.Focus();

                                // Actions.

                                Controller.UpdateSetupContinueButtonEvent += delegate(bool enabled)
                                {
                                    Dispatcher.BeginInvoke((Action)delegate
                                    {
                                        continue_button.IsEnabled = enabled;
                                    });
                                };

                                cancel_button.Click += delegate
                                {
                                    Dispatcher.BeginInvoke((Action)delegate
                                    {
                                        Program.UI.StatusIcon.Dispose();
                                        Controller.SetupPageCancelled();
                                    });
                                };

                                continue_button.Click += delegate
                                {
                                    Controller.SetupPageCompleted();
                                };

                                Controller.CheckSetupPage();

                                break;
                            }
                        #endregion

                        #region Page Tutorial
                        case PageType.Tutorial:
                            {
                                switch (Controller.TutorialCurrentPage)
                                {
                                    // First page of the tutorial.
                                    case 1:
                                        {
                                            // GUI elements.

                                            Header = Properties_Resources.WhatsNext;
                                            Description = Properties_Resources.CmisSyncCreates;

                                            WPF.Image slide_image = new WPF.Image()
                                            {
                                                Width = 350,
                                                Height = 200
                                            };

                                            slide_image.Source = UIHelpers.GetImageSource("tutorial-slide-1");

                                            Button skip_tutorial_button = new Button()
                                            {
                                                Content = Properties_Resources.SkipTutorial
                                            };

                                            Button continue_button = new Button()
                                            {
                                                Content = Properties_Resources.Continue
                                            };


                                            ContentCanvas.Children.Add(slide_image);
                                            Canvas.SetLeft(slide_image, 215);
                                            Canvas.SetTop(slide_image, 130);

                                            Buttons.Add(continue_button);
                                            Buttons.Add(skip_tutorial_button);

                                            // Actions.

                                            skip_tutorial_button.Click += delegate
                                            {
                                                Controller.TutorialSkipped();
                                            };

                                            continue_button.Click += delegate
                                            {
                                                Controller.TutorialPageCompleted();
                                            };

                                            break;
                                        }

                                    // Second page of the tutorial.
                                    case 2:
                                        {
                                            // GUI elements.

                                            Header = Properties_Resources.Synchronization;
                                            Description = Properties_Resources.DocumentsAre;


                                            Button continue_button = new Button()
                                            {
                                                Content = Properties_Resources.Continue
                                            };

                                            WPF.Image slide_image = new WPF.Image()
                                            {
                                                Width = 350,
                                                Height = 200
                                            };

                                            slide_image.Source = UIHelpers.GetImageSource("tutorial-slide-2");


                                            ContentCanvas.Children.Add(slide_image);
                                            Canvas.SetLeft(slide_image, 215);
                                            Canvas.SetTop(slide_image, 130);

                                            Buttons.Add(continue_button);

                                            // Actions.

                                            continue_button.Click += delegate
                                            {
                                                Controller.TutorialPageCompleted();
                                            };

                                            break;
                                        }

                                    // Third page of the tutorial.
                                    case 3:
                                        {
                                            // GUI elements.

                                            Header = Properties_Resources.StatusIcon;
                                            Description = Properties_Resources.StatusIconShows;


                                            Button continue_button = new Button()
                                            {
                                                Content = Properties_Resources.Continue
                                            };

                                            WPF.Image slide_image = new WPF.Image()
                                            {
                                                Width = 350,
                                                Height = 200
                                            };

                                            slide_image.Source = UIHelpers.GetImageSource("tutorial-slide-3");


                                            ContentCanvas.Children.Add(slide_image);
                                            Canvas.SetLeft(slide_image, 215);
                                            Canvas.SetTop(slide_image, 130);

                                            Buttons.Add(continue_button);

                                            // Actions.

                                            continue_button.Click += delegate
                                            {
                                                Controller.TutorialPageCompleted();
                                            };

                                            break;
                                        }

                                    // Fourth page of the tutorial.
                                    case 4:
                                        {
                                            // GUI elements.

                                            Header = Properties_Resources.AddFolders;
                                            Description = Properties_Resources.YouCan;


                                            Button finish_button = new Button()
                                            {
                                                Content = Properties_Resources.Finish
                                            };

                                            WPF.Image slide_image = new WPF.Image()
                                            {
                                                Width = 350,
                                                Height = 200
                                            };

                                            slide_image.Source = UIHelpers.GetImageSource("tutorial-slide-4");

                                            CheckBox check_box = new CheckBox()
                                            {
                                                Content = Properties_Resources.Startup,
                                                IsChecked = true
                                            };


                                            ContentCanvas.Children.Add(slide_image);
                                            Canvas.SetLeft(slide_image, 215);
                                            Canvas.SetTop(slide_image, 130);

                                            ContentCanvas.Children.Add(check_box);
                                            Canvas.SetLeft(check_box, 185);
                                            Canvas.SetBottom(check_box, 12);

                                            Buttons.Add(finish_button);

                                            // Actions.

                                            check_box.Click += delegate
                                            {
                                                Controller.StartupItemChanged(check_box.IsChecked.Value);
                                            };

                                            finish_button.Click += delegate
                                            {
                                                Controller.TutorialPageCompleted();
                                            };

                                            break;
                                        }
                                }
                                break;
                            }
                        #endregion

                        // First step of the remote folder addition dialog: Specifying the server.
                        #region Page Add1
                        case PageType.Add1:
                            {
                                // GUI elements.

                                Header = Properties_Resources.Where;

                                // Address input GUI.
                                TextBlock address_label = new TextBlock()
                                {
                                    Text = Properties_Resources.EnterWebAddress,
                                    FontWeight = FontWeights.Bold
                                };

                                TextBox address_box = new TextBox()
                                {
                                    Width = 420,
                                    Text = (Controller.PreviousAddress != null) ? Controller.PreviousAddress.ToString() : ""
                                };

                                TextBlock address_help_label = new TextBlock()
                                {
                                    Text = Properties_Resources.Help + ": ",
                                    FontSize = 11,
                                    Foreground = new SolidColorBrush(Color.FromRgb(128, 128, 128))
                                };
                                Run run = new Run(Properties_Resources.WhereToFind);
                                Hyperlink link = new Hyperlink(run);
                                link.NavigateUri = new Uri("https://github.com/aegif/CmisSync/wiki/What-address");
                                address_help_label.Inlines.Add(link);
                                link.RequestNavigate += (sender, e) =>
                                {
                                    System.Diagnostics.Process.Start(e.Uri.ToString());
                                };

                                // Rather than a TextBlock, we use a textBox so that users can copy/paste the error message and Google it.
                                TextBox address_error_label = new TextBox()
                                {
                                    FontSize = 11,
                                    Foreground = new SolidColorBrush(Color.FromRgb(255, 128, 128)),
                                    TextWrapping = TextWrapping.Wrap,
                                    Visibility = Visibility.Hidden,
                                    BorderThickness = new Thickness(0),
                                    IsReadOnly = true,
                                    Background = Brushes.Transparent,
                                    MaxWidth = 420
                                };


                                // User input GUI.
                                TextBlock user_label = new TextBlock()
                                {
                                    Text = Properties_Resources.User + ":",
                                    FontWeight = FontWeights.Bold,
                                    Width = 200
                                };

                                TextBox user_box = new TextBox()
                                {
                                    Width = 200
                                };
                                if (Controller.saved_user == String.Empty || Controller.saved_user == null)
                                {
                                    user_box.Text = Environment.UserName;
                                }
                                else
                                {
                                    user_box.Text = Controller.saved_user;
                                }

                                TextBlock user_help_label = new TextBlock()
                                {
                                    FontSize = 11,
                                    Width = 200,
                                    Foreground = new SolidColorBrush(Color.FromRgb(128, 128, 128))
                                };

                                // Password input GUI.
                                TextBlock password_label = new TextBlock()
                                {
                                    Text = Properties_Resources.Password + ":",
                                    FontWeight = FontWeights.Bold,
                                    Width = 200
                                };

                                PasswordBox password_box = new PasswordBox()
                                {
                                    Width = 200
                                };

                                TextBlock password_help_label = new TextBlock()
                                {
                                    FontSize = 11,
                                    Width = 200,
                                    Foreground = new SolidColorBrush(Color.FromRgb(128, 128, 128))
                                };

                                // Buttons.
                                Button cancel_button = new Button()
                                {
                                    Content = Properties_Resources.Cancel
                                };

                                Button continue_button = new Button()
                                {
                                    Content = Properties_Resources.Continue
                                };

                                Buttons.Add(continue_button);
                                Buttons.Add(cancel_button);

                                // Address
                                ContentCanvas.Children.Add(address_label);
                                Canvas.SetTop(address_label, 100);
                                Canvas.SetLeft(address_label, 185);

                                ContentCanvas.Children.Add(address_box);
                                Canvas.SetTop(address_box, 120);
                                Canvas.SetLeft(address_box, 185);

                                ContentCanvas.Children.Add(address_help_label);
                                Canvas.SetTop(address_help_label, 145);
                                Canvas.SetLeft(address_help_label, 185);

                                // User
                                ContentCanvas.Children.Add(user_label);
                                Canvas.SetTop(user_label, 160);
                                Canvas.SetLeft(user_label, 185);

                                ContentCanvas.Children.Add(user_box);
                                Canvas.SetTop(user_box, 180);
                                Canvas.SetLeft(user_box, 185);

                                ContentCanvas.Children.Add(user_help_label);
                                Canvas.SetTop(user_help_label, 215);
                                Canvas.SetLeft(user_help_label, 185);

                                // Password
                                ContentCanvas.Children.Add(password_label);
                                Canvas.SetTop(password_label, 160);
                                Canvas.SetRight(password_label, 30);

                                ContentCanvas.Children.Add(password_box);
                                Canvas.SetTop(password_box, 180);
                                Canvas.SetRight(password_box, 30);

                                ContentCanvas.Children.Add(password_help_label);
                                Canvas.SetTop(password_help_label, 215);
                                Canvas.SetRight(password_help_label, 30);

                                ContentCanvas.Children.Add(address_error_label);
                                Canvas.SetTop(address_error_label, 220);
                                Canvas.SetLeft(address_error_label, 185);

                                TaskbarItemInfo.ProgressValue = 0.0;
                                TaskbarItemInfo.ProgressState = TaskbarItemProgressState.None;

                                if (Controller.PreviousAddress == null || Controller.PreviousAddress.ToString() == String.Empty)
                                    address_box.Text = "https://";
                                else
                                    address_box.Text = Controller.PreviousAddress.ToString();
                                address_box.Focus();
                                address_box.Select(address_box.Text.Length, 0);

                                // Actions.

                                Controller.ChangeAddressFieldEvent += delegate(string text,
                                    string example_text)
                                {
                                    Dispatcher.BeginInvoke((Action)delegate
                                    {
                                        address_box.Text = text;
                                        address_help_label.Text = example_text;
                                    });
                                };

                                Controller.ChangeUserFieldEvent += delegate(string text,
                                    string example_text)
                                {
                                    Dispatcher.BeginInvoke((Action)delegate
                                    {
                                        user_box.Text = text;
                                        user_help_label.Text = example_text;
                                    });
                                };

                                Controller.ChangePasswordFieldEvent += delegate(string text,
                                    string example_text)
                                {
                                    Dispatcher.BeginInvoke((Action)delegate
                                    {
                                        password_box.Password = text;
                                        password_help_label.Text = example_text;
                                    });
                                };

                                Controller.UpdateAddProjectButtonEvent += delegate(bool button_enabled)
                                {
                                    Dispatcher.BeginInvoke((Action)delegate
                                    {
                                        continue_button.IsEnabled = button_enabled;
                                    });
                                };

                                Controller.CheckAddPage(address_box.Text);

                                address_box.TextChanged += delegate
                                {
                                    string error = Controller.CheckAddPage(address_box.Text);
                                    if (!String.IsNullOrEmpty(error))
                                    {
                                        address_error_label.Text = Properties_Resources.ResourceManager.GetString(error, CultureInfo.CurrentCulture);
                                        address_error_label.Visibility = Visibility.Visible;
                                    }
                                    else address_error_label.Visibility = Visibility.Hidden;
                                };

                                cancel_button.Click += delegate
                                {
                                    Controller.PageCancelled();
                                };

                                continue_button.Click += delegate
                                {
                                    // Show wait cursor
                                    System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor;

                                    // Try to find the CMIS server (asynchronously)
                                    GetRepositoriesFuzzyDelegate dlgt =
                                        new GetRepositoriesFuzzyDelegate(CmisUtils.GetRepositoriesFuzzy);
                                    ServerCredentials credentials = new ServerCredentials()
                                    {
                                        UserName = user_box.Text,
                                        Password = password_box.Password,
                                        Address = new Uri(address_box.Text)
                                    };
                                    IAsyncResult ar = dlgt.BeginInvoke(credentials, null, null);
                                    while (!ar.AsyncWaitHandle.WaitOne(100))
                                    {
                                        System.Windows.Forms.Application.DoEvents();
                                    }
                                    Tuple<CmisServer, Exception> result = dlgt.EndInvoke(ar);
                                    CmisServer cmisServer = result.Item1;

                                    Controller.repositories = cmisServer != null ? cmisServer.Repositories : null;

                                    address_box.Text = cmisServer.Url.ToString();

                                    // Hide wait cursor
                                    System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default;

                                    if (Controller.repositories == null)
                                    {
                                        // Could not retrieve repositories list from server, show warning.
                                        string warning = "";
                                        string message = result.Item2.Message;
                                        Exception e = result.Item2;
                                        if (e is PermissionDeniedException)
                                        {
                                            warning = Properties_Resources.LoginFailedForbidden;
                                        }
                                        else if (e is ServerNotFoundException)
                                        {
                                            warning = Properties_Resources.ConnectFailure;
                                        }
                                        else if (e.Message == "SendFailure" && cmisServer.Url.Scheme.StartsWith("https"))
                                        {
                                            warning = Properties_Resources.SendFailureHttps;
                                        }
                                        else if (e.Message == "TrustFailure")
                                        {
                                            warning = Properties_Resources.TrustFailure;
                                        }
                                        else
                                        {
                                            warning = message + Environment.NewLine + Properties_Resources.Sorry;
                                        }
                                        address_error_label.Text = warning;
                                        address_error_label.Visibility = Visibility.Visible;
                                    }
                                    else
                                    {
                                        // Continue to next step, which is choosing a particular folder.
                                        Controller.Add1PageCompleted(
                                            new Uri(address_box.Text), user_box.Text, password_box.Password);
                                    }
                                };
                                break;
                            }
                        #endregion

                        // Second step of the remote folder addition dialog: choosing the folder.
                        #region Page Add2
                        case PageType.Add2:
                            {
                                // GUI elements.

                                Header = Properties_Resources.Which;

                                // A tree allowing the user to browse CMIS repositories/folders.
                                /*if(TODO check if OpenDataSpace, and further separate code below)
                                {
                                    System.Uri resourceLocater = new System.Uri("/CmisSync;component/TreeView.xaml", System.UriKind.Relative);
                                    System.Windows.Controls.TreeView treeView = System.Windows.Application.LoadComponent(resourceLocater) as TreeView;
                                    ObservableCollection<CmisRepo> repos = new ObservableCollection<CmisRepo>();
                                */
                                System.Windows.Controls.TreeView treeView = new System.Windows.Controls.TreeView();
                                treeView.Width = 410;
                                treeView.Height = 267;

                                // Some CMIS servers hold several repositories (ex:Nuxeo). Show one root per repository.
                                foreach (KeyValuePair<String, String> repository in Controller.repositories)
                                {
                                    System.Windows.Controls.TreeViewItem item = new System.Windows.Controls.TreeViewItem();
                                    item.Tag = new SelectionTreeItem(repository.Key, "/");
                                    item.Header = repository.Value;
                                    treeView.Items.Add(item);
                                }

                                ContentCanvas.Children.Add(treeView);
                                Canvas.SetTop(treeView, 70);
                                Canvas.SetLeft(treeView, 185);

                                // Action: when an element in the tree is clicked, loads its children and show them.
                                treeView.SelectedItemChanged += delegate
                                {
                                    // Identify the selected remote path.
                                    TreeViewItem item = (TreeViewItem)treeView.SelectedItem;
                                    Controller.saved_remote_path = ((SelectionTreeItem)item.Tag).fullPath;

                                    // Identify the selected repository.
                                    object cursor = item;
                                    while (cursor is TreeViewItem)
                                    {
                                        TreeViewItem treeViewItem = (TreeViewItem)cursor;
                                        cursor = treeViewItem.Parent;
                                        if (!(cursor is TreeViewItem))
                                        {
                                            Controller.saved_repository = ((SelectionTreeItem)treeViewItem.Tag).repository;
                                        }
                                    }

                                    // Load sub-folders if it has not been done already.
                                    // We use each item's Tag to store metadata: whether this item's subfolders have been loaded or not.
                                    if (((SelectionTreeItem)item.Tag).childrenLoaded == false)
                                    {
                                        System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor;

                                        // Get list of subfolders (asynchronously)
                                        GetSubfoldersDelegate dlgt = new GetSubfoldersDelegate(CmisUtils.GetSubfolders);
                                        IAsyncResult ar = dlgt.BeginInvoke(Controller.saved_repository,
                                            Controller.saved_remote_path, Controller.saved_address.ToString(),
                                            Controller.saved_user, Controller.saved_password, null, null);
                                        while (!ar.AsyncWaitHandle.WaitOne(100))
                                        {
                                            System.Windows.Forms.Application.DoEvents();
                                        }
                                        string[] subfolders = dlgt.EndInvoke(ar);

                                        // Create a sub-item for each subfolder
                                        foreach (string subfolder in subfolders)
                                        {
                                            System.Windows.Controls.TreeViewItem subItem =
                                                new System.Windows.Controls.TreeViewItem();
                                            subItem.Tag = new SelectionTreeItem(null, subfolder);
                                            subItem.Header = Path.GetFileName(subfolder);
                                            item.Items.Add(subItem);
                                        }
                                        ((SelectionTreeItem)item.Tag).childrenLoaded = true;
                                        item.ExpandSubtree();
                                        System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default;
                                    }
                                };

                                Button cancel_button = new Button()
                                {
                                    Content = Properties_Resources.Cancel
                                };

                                Button continue_button = new Button()
                                {
                                    Content = CmisSync.Properties_Resources.ResourceManager.GetString("Continue", CultureInfo.CurrentCulture)
                                };

                                Button back_button = new Button()
                                {
                                    Content = Properties_Resources.Back,
                                    IsDefault = false
                                };

                                Buttons.Add(back_button);
                                Buttons.Add(continue_button);
                                Buttons.Add(cancel_button);

                                continue_button.Focus();

                                cancel_button.Click += delegate
                                {
                                    Controller.PageCancelled();
                                };

                                continue_button.Click += delegate
                                {
                                    Controller.Add2PageCompleted(
                                        Controller.saved_repository, Controller.saved_remote_path);
                                };

                                back_button.Click += delegate
                                {
                                    Controller.BackToPage1();
                                };
                                break;
                            }
                        #endregion

                        // Third step of the remote folder addition dialog: Customizing the local folder.
                        #region Page Customize
                        case PageType.Customize:
                            {
                                string parentFolder = Controller.DefaultRepoPath;

                                // GUI elements.

                                Header = Properties_Resources.Customize;

                                // Customize local folder name
                                TextBlock localfolder_label = new TextBlock()
                                {
                                    Text = Properties_Resources.EnterLocalFolderName,
                                    FontWeight = FontWeights.Bold,
                                    TextWrapping = TextWrapping.Wrap,
                                    Width = 420
                                };
                                string localfoldername = Controller.saved_address.Host.ToString();
                                foreach (KeyValuePair<String, String> repository in Controller.repositories)
                                {
                                    if (repository.Key == Controller.saved_repository)
                                    {
                                        localfoldername += "\\" + repository.Value;
                                        break;
                                    }
                                }
                                TextBox localfolder_box = new TextBox()
                                {
                                    Width = 420,
                                    Text = localfoldername
                                };

                                TextBlock localrepopath_label = new TextBlock()
                                {
                                    Text = Properties_Resources.ChangeRepoPath,
                                    FontWeight = FontWeights.Bold
                                };

                                TextBox localrepopath_box = new TextBox()
                                {
                                    Width = 375,
                                    Text = Path.Combine(parentFolder, localfolder_box.Text)
                                };

                                Button choose_folder_button = new Button()
                                {
                                    Width = 40,
                                    Content = "..."
                                };

                                TextBlock localfolder_error_label = new TextBlock()
                                {
                                    FontSize = 11,
                                    Foreground = new SolidColorBrush(Color.FromRgb(255, 128, 128)),
                                    Visibility = Visibility.Hidden,
                                    TextWrapping = TextWrapping.Wrap,
                                    MaxWidth = 420
                                };

                                Button cancel_button = new Button()
                                {
                                    Content = Properties_Resources.Cancel
                                };

                                Button add_button = new Button()
                                {
                                    Content = Properties_Resources.Add,
                                    IsDefault = true
                                };

                                Button back_button = new Button()
                                {
                                    Content = Properties_Resources.Back
                                };

                                Buttons.Add(back_button);
                                Buttons.Add(add_button);
                                Buttons.Add(cancel_button);

                                // Local Folder Name
                                ContentCanvas.Children.Add(localfolder_label);
                                Canvas.SetTop(localfolder_label, 160);
                                Canvas.SetLeft(localfolder_label, 185);

                                ContentCanvas.Children.Add(localfolder_box);
                                Canvas.SetTop(localfolder_box, 180);
                                Canvas.SetLeft(localfolder_box, 185);

                                ContentCanvas.Children.Add(localrepopath_label);
                                Canvas.SetTop(localrepopath_label, 200);
                                Canvas.SetLeft(localrepopath_label, 185);

                                ContentCanvas.Children.Add(localrepopath_box);
                                Canvas.SetTop(localrepopath_box, 220);
                                Canvas.SetLeft(localrepopath_box, 185);

                                ContentCanvas.Children.Add(choose_folder_button);
                                Canvas.SetTop(choose_folder_button, 220);
                                Canvas.SetLeft(choose_folder_button, 565);

                                ContentCanvas.Children.Add(localfolder_error_label);
                                Canvas.SetTop(localfolder_error_label, 275);
                                Canvas.SetLeft(localfolder_error_label, 185);

                                TaskbarItemInfo.ProgressValue = 0.0;
                                TaskbarItemInfo.ProgressState = TaskbarItemProgressState.None;

                                localfolder_box.Focus();
                                localfolder_box.Select(localfolder_box.Text.Length, 0);

                                // Repo path validity.

                                CheckCustomizeInput(localfolder_box, localrepopath_box, localfolder_error_label);

                                // Actions.

                                Controller.UpdateAddProjectButtonEvent += delegate(bool button_enabled)
                                {
                                    Dispatcher.BeginInvoke((Action)delegate
                                    {
                                        if (add_button.IsEnabled != button_enabled)
                                        {
                                            add_button.IsEnabled = button_enabled;
                                            if (button_enabled)
                                            {
                                                add_button.IsDefault = true;
                                                back_button.IsDefault = false;
                                            }
                                        }
                                    });
                                };

                                CheckRepoPathAndNameDelegate checkRepoPathAndNameDelegate = delegate()
                                {
                                    string error = Controller.CheckRepoPathAndName(localrepopath_box.Text, localfolder_box.Text);

                                    if (!String.IsNullOrEmpty(error))
                                    {
                                        localfolder_error_label.Text = Properties_Resources.ResourceManager.GetString(error, CultureInfo.CurrentCulture);
                                        localfolder_error_label.Visibility = Visibility.Visible;
                                    }
                                    else
                                    {
                                        localfolder_error_label.Visibility = Visibility.Hidden;
                                    }
                                };

                                //execute the check on first run...
                                checkRepoPathAndNameDelegate();

                                localfolder_box.TextChanged += delegate
                                {
                                    localrepopath_box.Text = Path.Combine(parentFolder, localfolder_box.Text);
                                };

                                localrepopath_box.TextChanged += delegate
                                {
                                    checkRepoPathAndNameDelegate();
                                };

                                windowActivatedEventHandler = new EventHandler(delegate(object sender, EventArgs e)
                                {
                                    checkRepoPathAndNameDelegate();
                                });

                                Activated += windowActivatedEventHandler;

                                // Choose a folder.
                                choose_folder_button.Click += delegate
                                {
                                    System.Windows.Forms.FolderBrowserDialog folderBrowserDialog1 = new System.Windows.Forms.FolderBrowserDialog();
                                    if (folderBrowserDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                                    {
                                        parentFolder = folderBrowserDialog1.SelectedPath;
                                        localrepopath_box.Text = Path.Combine(parentFolder, localfolder_box.Text);
                                    }
                                };

                                // Other actions.

                                cancel_button.Click += delegate
                                {
                                    Controller.PageCancelled();
                                };

                                back_button.Click += delegate
                                {
                                    Controller.BackToPage2();
                                };

                                add_button.Click += delegate
                                {
                                    Controller.CustomizePageCompleted(localfolder_box.Text, localrepopath_box.Text);
                                };

                                Controller.LocalPathExists += LocalPathExistsHandler;
                                break;
                            }
                        #endregion

                        // Final page of the remote folder addition dialog: end of the addition wizard.
                        #region Page Finished
                        case PageType.Finished:
                            {
                                // GUI elements.

                                Header = Properties_Resources.Ready;
                                Description = Properties_Resources.YouCanFind;

                                Button finish_button = new Button()
                                {
                                    Content = Properties_Resources.Finish
                                };

                                Button open_folder_button = new Button()
                                {
                                    Content = Properties_Resources.OpenFolder
                                };

                                TaskbarItemInfo.ProgressValue = 0.0;
                                TaskbarItemInfo.ProgressState = TaskbarItemProgressState.None;

                                Buttons.Add(open_folder_button);
                                Buttons.Add(finish_button);

                                // Actions.

                                finish_button.Click += delegate
                                {
                                    Controller.FinishPageCompleted();
                                };

                                open_folder_button.Click += delegate
                                {
                                    Controller.OpenFolderClicked();
                                };


                                SystemSounds.Exclamation.Play();

                                break;
                            }
                        #endregion

                        // Settings dialog.
                        #region Page Settings
                        case PageType.Settings:
                            {
                                // GUI elements.

                                Header = Properties_Resources.Settings;

                                // Address input GUI.
                                TextBlock address_label = new TextBlock()
                                {
                                    Text = Properties_Resources.WebAddress,
                                    FontWeight = FontWeights.Bold
                                };

                                TextBox address_box = new TextBox()
                                {
                                    Width = 420,
                                    Text = Controller.saved_address.ToString(),
                                    IsEnabled = false,
                                };

                                // User input GUI.
                                TextBlock user_label = new TextBlock()
                                {
                                    Text = Properties_Resources.User + ":",
                                    FontWeight = FontWeights.Bold,
                                    Width = 200
                                };

                                TextBox user_box = new TextBox()
                                {
                                    Width = 200,
                                    Text = Controller.saved_user,
                                    IsEnabled = false,
                                };

                                // Password input GUI.
                                TextBlock password_label = new TextBlock()
                                {
                                    Text = Properties_Resources.Password + ":",
                                    FontWeight = FontWeights.Bold,
                                    Width = 200
                                };

                                PasswordBox password_box = new PasswordBox()
                                {
                                    Width = 200
                                };

                                // Rather than a TextBlock, we use a textBox so that users can copy/paste the error message and Google it.
                                TextBox authentication_error_label = new TextBox()
                                {
                                    FontSize = 11,
                                    Foreground = new SolidColorBrush(Color.FromRgb(255, 128, 128)),
                                    Visibility = Visibility.Hidden,
                                    IsReadOnly = true,
                                    Background = Brushes.Transparent,
                                    BorderThickness = new Thickness(0),
                                    TextWrapping = TextWrapping.Wrap,
                                    MaxWidth = 420
                                };

                                // Sync at startup ?
                                CheckBox startup_checkbox = new CheckBox()
                                {
                                    Content = Properties_Resources.SyncAtStartup,
                                    IsChecked = Controller.saved_syncatstartup,
                                    FontWeight = FontWeights.Bold,
                                    Width = 400,
                                };

                                // Sync duration input GUI.
                                TextBlock slider_label = new TextBlock()
                                {
                                    Text = Properties_Resources.SyncInterval + ":",
                                    FontWeight = FontWeights.Bold,
                                    Width = 200,
                                };

                                PollIntervalSlider slider = new PollIntervalSlider()
                                {
                                    Width = 400,
                                    PollInterval = Controller.saved_sync_interval
                                };

                                TextBlock slider_min_label = new TextBlock()
                                {
                                    Text = slider.FormattedMinimum(),
                                    Width = 200,
                                };

                                TextBlock slider_max_label = new TextBlock()
                                {
                                    Text = slider.FormattedMaximum(),
                                    Width = 200,
                                    TextAlignment = TextAlignment.Right,
                                };

                                // Buttons.
                                Button cancel_button = new Button()
                                {
                                    Content = Properties_Resources.Cancel
                                };

                                Button save_button = new Button()
                                {
                                    Content = Properties_Resources.Save
                                };

                                Buttons.Add(save_button);
                                Buttons.Add(cancel_button);

                                // Address
                                ContentCanvas.Children.Add(address_label);
                                Canvas.SetTop(address_label, 50);
                                Canvas.SetLeft(address_label, 185);

                                ContentCanvas.Children.Add(address_box);
                                Canvas.SetTop(address_box, 70);
                                Canvas.SetLeft(address_box, 185);

                                // User
                                ContentCanvas.Children.Add(user_label);
                                Canvas.SetTop(user_label, 110);
                                Canvas.SetLeft(user_label, 185);

                                ContentCanvas.Children.Add(user_box);
                                Canvas.SetTop(user_box, 130);
                                Canvas.SetLeft(user_box, 185);

                                // Password
                                ContentCanvas.Children.Add(password_label);
                                Canvas.SetTop(password_label, 170);
                                Canvas.SetLeft(password_label, 185);

                                ContentCanvas.Children.Add(password_box);
                                Canvas.SetTop(password_box, 190);
                                Canvas.SetLeft(password_box, 185);

                                // Error label
                                ContentCanvas.Children.Add(authentication_error_label);
                                Canvas.SetTop(authentication_error_label, 215);
                                Canvas.SetLeft(authentication_error_label, 185);

                                // Sync at startup
                                ContentCanvas.Children.Add(startup_checkbox);
                                Canvas.SetTop(startup_checkbox, 220);
                                Canvas.SetLeft(startup_checkbox, 185);

                                // Sync Interval
                                ContentCanvas.Children.Add(slider_label);
                                Canvas.SetTop(slider_label, 250);
                                Canvas.SetLeft(slider_label, 185);

                                ContentCanvas.Children.Add(slider);
                                Canvas.SetTop(slider, 270);
                                Canvas.SetLeft(slider, 185);

                                ContentCanvas.Children.Add(slider_min_label);
                                Canvas.SetTop(slider_min_label, 300);
                                Canvas.SetLeft(slider_min_label, 185);

                                ContentCanvas.Children.Add(slider_max_label);
                                Canvas.SetTop(slider_max_label, 300);
                                Canvas.SetLeft(slider_max_label, 385);

                                TaskbarItemInfo.ProgressValue = 0.0;
                                TaskbarItemInfo.ProgressState = TaskbarItemProgressState.None;

                                user_box.Focus();


                                // Actions.
                                Controller.UpdateAddProjectButtonEvent += delegate(bool button_enabled)
                                {
                                    Dispatcher.BeginInvoke((Action)delegate
                                    {
                                        save_button.IsEnabled = button_enabled;
                                    });
                                };

                                cancel_button.Click += delegate
                                {
                                    Controller.PageCancelled();
                                };

                                save_button.Click += delegate
                                {
                                    if (!String.IsNullOrEmpty(password_box.Password))
                                    {
                                        // Show wait cursor
                                        System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor;

                                        // Try to find the CMIS server (asynchronously)
                                        GetRepositoriesFuzzyDelegate dlgt =
                                            new GetRepositoriesFuzzyDelegate(CmisUtils.GetRepositoriesFuzzy);
                                        IAsyncResult ar = dlgt.BeginInvoke(
                                            new ServerCredentials()
                                                {
                                                    UserName = Controller.saved_user,
                                                    Password = password_box.Password,
                                                    Address = Controller.saved_address
                                                },
                                            null, null);
                                        while (!ar.AsyncWaitHandle.WaitOne(100))
                                        {
                                            System.Windows.Forms.Application.DoEvents();
                                        }
                                        Tuple<CmisServer, Exception> result = dlgt.EndInvoke(ar);
                                        CmisServer cmisServer = result.Item1;

                                        Controller.repositories = cmisServer != null ? cmisServer.Repositories : null;

                                        // Hide wait cursor
                                        System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default;

                                        if (Controller.repositories == null)
                                        {
                                            // Could not retrieve repositories list from server, show warning.
                                            string warning = "";
                                            string message = result.Item2.Message;
                                            Exception e = result.Item2;
                                            if (e is PermissionDeniedException)
                                            {
                                                warning = Properties_Resources.LoginFailedForbidden;
                                            }
                                            else if (e is ServerNotFoundException)
                                            {
                                                warning = Properties_Resources.ConnectFailure;
                                            }
                                            else if (e.Message == "SendFailure" && cmisServer.Url.Scheme.StartsWith("https"))
                                            {
                                                warning = Properties_Resources.SendFailureHttps;
                                            }
                                            else if (e.Message == "TrustFailure")
                                            {
                                                warning = Properties_Resources.TrustFailure;
                                            }
                                            else
                                            {
                                                warning = message + Environment.NewLine + Properties_Resources.Sorry;
                                            }
                                            authentication_error_label.Text = warning;
                                            authentication_error_label.Visibility = Visibility.Visible;
                                        }
                                        else
                                        {
                                            // Continue to next step, which is choosing a particular folder.
                                            Controller.SettingsPageCompleted(password_box.Password, slider.PollInterval, (bool)startup_checkbox.IsChecked);
                                        }

                                    }
                                    else
                                    {
                                        Controller.SettingsPageCompleted(null, slider.PollInterval, (bool)startup_checkbox.IsChecked);
                                    }

                                };
                                break;
                            }
                        #endregion

                    }

                    ShowAll();
                    Logger.Debug("Exiting ChangePageEvent.");
                });
            };
            this.Closing += delegate
            {
                Controller.PageCancelled();
            };

            Controller.PageCancelled();
            Logger.Debug("Exiting constructor.");
        }
        partial void OnSave(NSObject sender)
        {
            if (!String.IsNullOrEmpty(PasswordText.StringValue))
            {
                // Try to find the CMIS server and Check credentials
                var credentials = new ServerCredentials()
                {
                    UserName = UserText.StringValue,
                    Password = PasswordText.StringValue,
                    Address = new Uri(AddressText.StringValue)
                };
                PasswordText.Enabled = false;
                CancelButton.Enabled = false;
                SaveButton.Enabled = false;

                Thread check = new Thread(() => {
                    var fuzzyResult = CmisUtils.GetRepositoriesFuzzy(credentials);
                    var cmisServer = fuzzyResult.Item1;
                    Controller.repositories = (cmisServer != null)? cmisServer.Repositories: null;

                    InvokeOnMainThread(() => {
                        if (Controller.repositories == null)
                        {
                            string warning = "";
                            string message = fuzzyResult.Item2.Message;
                            Exception e = fuzzyResult.Item2;
                            if (e is PermissionDeniedException)
                            {
                                warning = Properties_Resources.LoginFailedForbidden;
                            }
                            else if (e is ServerNotFoundException)
                            {
                                warning = Properties_Resources.ConnectFailure;
                            }
                            else if (e.Message == "SendFailure" && cmisServer.Url.Scheme.StartsWith("https"))
                            {
                                warning = Properties_Resources.SendFailureHttps;
                            }
                            else if (e.Message == "TrustFailure")
                            {
                                warning = Properties_Resources.TrustFailure;
                            }
                            else if (e.Message == "Unauthorized")
                            {
                                message = Properties_Resources.LoginFailedForbidden;
                            }
                            else
                            {
                                warning = Properties_Resources.Sorry;
                            }
                                
                            NSAlert alert = NSAlert.WithMessage(message, "OK", null, null, warning);
                            alert.Icon = new NSImage (System.IO.Path.Combine (NSBundle.MainBundle.ResourcePath, "Pixmaps", "process-syncing-error.icns"));
                            alert.Window.OrderFrontRegardless();
                            alert.RunModal();

                            PasswordText.Enabled = true;
                            CancelButton.Enabled = true;
                            SaveButton.Enabled = true;
                        }
                        else
                        {
                            RemoveEvent();
                            Controller.SettingsPageCompleted(PasswordText.StringValue, SliderIndexToPollingInterval(Slider.IntValue), (StartupCheckbox.State == NSCellStateValue.On));
                        }
                    });
                });
                check.Start();
            }
            else
            {
                Controller.SettingsPageCompleted(null, SliderIndexToPollingInterval(Slider.IntValue), (StartupCheckbox.State == NSCellStateValue.On));
            }
        }
Example #7
0
		public void ShowSettingsPage()
		{
			SetSizeRequest (680, 470);
			Header = CmisSync.Properties_Resources.Settings;
			string localfoldername = Controller.saved_address.ToString();
			string username = Controller.saved_user;

			Label url_label = new Label() {
				Xalign = 0,
				UseMarkup = true,
				Markup = "<b>"+CmisSync.Properties_Resources.WebAddress+"</b>"
			};

			Entry url_entry = new Entry() {
				Text = localfoldername,
				IsEditable = false,
				Sensitive=false
			};

			Label user_label = new Label() {
				Xalign = 0,
				UseMarkup = true,
				Markup = "<b>"+CmisSync.Properties_Resources.User+"</b>"
			};

			Entry user_entry = new Entry() {
				Text = username,
				IsEditable = false,
				Sensitive=false
			};

			Label password_label = new Label() {
				Xalign = 0,
				UseMarkup = true,
				Markup = "<b>"+CmisSync.Properties_Resources.Password+"</b>",
			};

			Label authentification_error_label = new Label() {
				Xalign = 0,
				UseMarkup = true,
				Visible = false
			};

			Entry password_entry = new Entry() {
				Text = "",
				ActivatesDefault = false
			};
			String password = "";
			password_entry.TextInserted+=delegate {
				password+=password_entry.Text[password_entry.Text.Length-1];
				password_entry.Text=password_entry.Text.Replace(password_entry.Text[password_entry.Text.Length-1],'*');
			};

			CheckButton launcAtStartup = new CheckButton (CmisSync.Properties_Resources.SyncAtStartup);
			if (Controller.saved_syncatstartup)
				launcAtStartup.Active = true;

			Label syncInterval_label = new Label() {
				Xalign = 0,
				UseMarkup = true,
				Markup = "<b>"+CmisSync.Properties_Resources.SyncInterval+"(Secondes)"+"</b>"
			};

			//sync interval is between 5s and 1day
			HScale syncInterval_hscale = new HScale(new Adjustment(0,5,86401,5,5,1));
			syncInterval_hscale.DrawValue = true;
			// syncinterval is converted in secondes
			syncInterval_hscale.Value=Controller.saved_sync_interval/1000;
			syncInterval_hscale.Digits = 0;
			syncInterval_hscale.ValueChanged += delegate {
				Application.Invoke (delegate {
					syncInterval_hscale.TooltipText=syncInterval_hscale.Value+" s";
				});
			};


			Button cancel_button = new Button(cancelText);
			cancel_button.Clicked += delegate {
				Controller.PageCancelled();
			};


			Button save_button = new Button(
				CmisSync.Properties_Resources.Save
				);

			VBox layout_vertical   = new VBox (false, 10);

			layout_vertical.PackStart (new Label(""), false, false, 0);
			layout_vertical.PackStart (url_label, false, false, 0);
			layout_vertical.PackStart (url_entry, false, false, 0);
			layout_vertical.PackStart (user_label, false, false, 0);
			layout_vertical.PackStart (user_entry, false, false, 0);
			layout_vertical.PackStart (password_label, false, false, 0);
			layout_vertical.PackStart (password_entry, false, false, 0);
			layout_vertical.PackStart (authentification_error_label, false, false, 0);
			layout_vertical.PackStart (launcAtStartup, false, false, 0);
			layout_vertical.PackStart (syncInterval_label, false, false, 0);
			layout_vertical.PackStart (syncInterval_hscale, false, false, 0);
			//layout_vertical.PackStart (scale2, false, false, 0);

			ScrolledWindow scrolledWindow = new ScrolledWindow();
			scrolledWindow.SetPolicy(PolicyType.Never, PolicyType.Automatic);

			scrolledWindow.AddWithViewport(layout_vertical);
			scrolledWindow.ShadowType=ShadowType.None;

			Add(scrolledWindow);
			AddButton(save_button);
			AddButton(cancel_button);

			save_button.Clicked += delegate {
				//save password not masked
				String verypassword="";

				for (int i=0;i<password.Length;i++){
					if (!password[i].Equals('*'))
						verypassword+=password[i];
				}
				//reset 
				password="";

				if (!String.IsNullOrEmpty(verypassword))
				{
					// Show wait cursor
					this.GdkWindow.Cursor = wait_cursor;

					// Try to find the CMIS server (asynchronous using a delegate)
					GetRepositoriesFuzzyDelegate dlgt =
						new GetRepositoriesFuzzyDelegate(CmisUtils.GetRepositoriesFuzzy);
					ServerCredentials credentials = new ServerCredentials() {
						UserName = user_entry.Text,
						Password = verypassword,
						Address = new Uri(url_entry.Text)
					};
					IAsyncResult ar = dlgt.BeginInvoke(credentials, null, null);
					while (!ar.AsyncWaitHandle.WaitOne(100)) {
						while (Application.EventsPending()) {
							Application.RunIteration();
						}
					}
					Tuple<CmisServer, Exception> result = dlgt.EndInvoke(ar);
					CmisServer cmisServer = result.Item1;
					if(cmisServer != null)
					{
						Controller.repositories = cmisServer.Repositories;
						url_entry.Text = cmisServer.Url.ToString();
					}
					else
					{
						Controller.repositories = null;
					}
					// Hide wait cursor
					this.GdkWindow.Cursor = default_cursor;

					if (Controller.repositories == null)
					{
						// Show warning
						string warning = "";
						string message = result.Item2.Message;
						Exception e = result.Item2;
						if (e is CmisPermissionDeniedException)
						{
							warning = Properties_Resources.LoginFailedForbidden;
						}

						else if (e.Message == "SendFailure" && cmisServer.Url.Scheme.StartsWith("https"))
						{
							warning = Properties_Resources.SendFailureHttps;
						}
						else if (e.Message == "TrustFailure")
						{
							warning = Properties_Resources.TrustFailure;
						}
						else
						{
							warning = message + Environment.NewLine + Properties_Resources.Sorry;
						}
						authentification_error_label.Markup = "<span foreground=\"red\">" + warning + "</span>";
						authentification_error_label.Show();
					}
					else
					{
						// update settings
						// syncinterval is converted in millisecondes
						Controller.SettingsPageCompleted(verypassword,(int)(syncInterval_hscale.Value*1000),launcAtStartup.Active);
					}
				}
				else
				{
					Controller.SettingsPageCompleted(null, (int)syncInterval_hscale.Value*1000, launcAtStartup.Active);
				}
			};

		}
Example #8
0
 public void GetRepositories(string canonical_name, string localPath, string remoteFolderPath,
     string url, string user, string password, string repositoryId)
 {
     ServerCredentials credentials = new ServerCredentials()
     {
         Address = new Uri(url),
         UserName = user,
         Password = password
     };
     Dictionary<string, string> repos = CmisUtils.GetRepositories(credentials);
     foreach (KeyValuePair<string, string> pair in repos)
     {
         Console.WriteLine(pair.Key + " : " + pair.Value);
     }
     Assert.NotNull(repos);
 }
Example #9
0
 public void GetRepositoriesFuzzy(string url, string user, string password)
 {
     ServerCredentials credentials = new ServerCredentials()
     {
         Address = new Uri(url),
         UserName = user,
         Password = password
     };
     Tuple<CmisServer, Exception> server = CmisUtils.GetRepositoriesFuzzy(credentials);
     Assert.NotNull(server.Item1);
 }
Example #10
0
        void ShowLoginPage()
        {
            Header = CmisSync.Properties_Resources.Where;
            Description = "";
            AddressLabel = new NSTextField() {
                Alignment = NSTextAlignment.Left,
                BackgroundColor = NSColor.WindowBackground,
                Bordered = false,
                Editable = false,
                Frame = new RectangleF(190, 320, 196 + 196 + 16, 17),
                StringValue = Properties_Resources.EnterWebAddress,
                Font = GUI.BoldFont
            };
            AddressTextField = new NSTextField() {
                Frame = new RectangleF(190, 290, 196 + 196 + 16, 22),
                Font = GUI.Font,
                Delegate = new TextFieldDelegate(),
                StringValue = (Controller.PreviousAddress == null || String.IsNullOrEmpty(Controller.PreviousAddress.ToString())) ? "https://" : Controller.PreviousAddress.ToString()
            };
            AddressTextField.Cell.LineBreakMode = NSLineBreakMode.TruncatingHead;
            AddressHelpLabel = new NSTextField() {
                BackgroundColor = NSColor.WindowBackground,
                Bordered = false,
                TextColor = NSColor.DisabledControlText,
                Editable = false,
                Frame = new RectangleF(190, 265, 196 + 196 + 16, 17),
                Font = NSFontManager.SharedFontManager.FontWithFamily("Lucida Grande", NSFontTraitMask.Condensed, 0, 11),
            };
            NSTextField UserLabel = new NSTextField() {
                Alignment = NSTextAlignment.Left,
                BackgroundColor = NSColor.WindowBackground,
                Font = GUI.BoldFont,
                Bordered = false,
                Editable = false,
                Frame = new RectangleF(190, 230, 196, 17),
                StringValue = Properties_Resources.User
            };
            NSTextField UserTextField = new NSTextField() {
                Font = GUI.Font,
                StringValue = String.IsNullOrEmpty(Controller.saved_user) ? Environment.UserName : Controller.saved_user,
                Frame = new RectangleF(190, 200, 196, 22)
            };
            UserTextField.Cell.LineBreakMode = NSLineBreakMode.TruncatingHead;
            PasswordLabel = new NSTextField() {
                Alignment = NSTextAlignment.Left,
                BackgroundColor = NSColor.WindowBackground,
                Bordered = false,
                Editable = false,
                Frame = new RectangleF(190 + 196 + 16, 230, 196, 17),
                StringValue = Properties_Resources.Password,
                Font = GUI.BoldFont
            };
            PasswordTextField = new NSSecureTextField() {
                Frame = new RectangleF(190 + 196 + 16, 200, 196, 22),
                Delegate = new TextFieldDelegate()
            };
            WarningTextField = new NSTextField() {
                BackgroundColor = NSColor.WindowBackground,
                Bordered = false,
                TextColor = NSColor.Red,
                Editable = false,
                Frame = new RectangleF(190, 30, 196 + 196 + 16, 160),
                Font = NSFontManager.SharedFontManager.FontWithFamily("Lucida Grande", NSFontTraitMask.Condensed, 0, 11),
            };
            WarningTextField.Cell.LineBreakMode = NSLineBreakMode.ByWordWrapping;
            ContinueButton = new NSButton() {
                Title = Properties_Resources.Continue,
                Enabled = false
            };
            CancelButton = new NSButton() {
                Title = Properties_Resources.Cancel
            };
            (AddressTextField.Delegate as TextFieldDelegate).StringValueChanged += CheckAddressTextField;
            ContinueButton.Activated += delegate
            {
                ServerCredentials credentials = null;
                InvokeOnMainThread(delegate {
                    credentials = new ServerCredentials() {
                        UserName = UserTextField.StringValue,
                        Password = PasswordTextField.StringValue,
                        Address = new Uri(AddressTextField.StringValue)
                    };
                    ContinueButton.Enabled = false;
                    CancelButton.Enabled = false;
                });
                Thread check = new Thread(() => {
                    Tuple<CmisServer, Exception> fuzzyResult = CmisUtils.GetRepositoriesFuzzy(credentials);
                    CmisServer cmisServer = fuzzyResult.Item1;
                    if (cmisServer != null)
                    {
                        Controller.repositories = cmisServer.Repositories;
                    }
                    else
                    {
                        Controller.repositories = null;
                    }
                    InvokeOnMainThread(delegate {
                        if (Controller.repositories == null)
                        {
                            // TODO fix
                            // WarningTextField.StringValue = Controller.getConnectionsProblemWarning(fuzzyResult.Item1, fuzzyResult.Item2);
                            WarningTextField.StringValue = "Controller.getConnectionsProblemWarning(fuzzyResult.Item1, fuzzyResult.Item2)";

                            ContinueButton.Enabled = true;
                            CancelButton.Enabled = true;
                        }
                        else
                        {
                            Controller.Add1PageCompleted(cmisServer.Url, credentials.UserName, credentials.Password.ToString());
                        }
                    });
                });
                check.Start();
            };
            CancelButton.Activated += delegate
            {
                Controller.PageCancelled();
            };
            ContentView.AddSubview(AddressLabel);
            ContentView.AddSubview(AddressTextField);
            ContentView.AddSubview(AddressHelpLabel);
            ContentView.AddSubview(UserLabel);
            ContentView.AddSubview(UserTextField);
            ContentView.AddSubview(PasswordLabel);
            ContentView.AddSubview(PasswordTextField);
            ContentView.AddSubview(WarningTextField);
            Buttons.Add(ContinueButton);
            Buttons.Add(CancelButton);
            Controller.CheckAddPage(AddressTextField.StringValue);
        }
Example #11
0
        /// <summary>
        /// Try to find the CMIS server associated to any URL.
        /// Users can provide the URL of the web interface, and we have to return the CMIS URL
        /// Returns the list of repositories as well.
        /// </summary>
        static public Tuple<CmisServer, Exception> GetRepositoriesFuzzy(ServerCredentials credentials)
        {
            Dictionary<string, string> repositories = null;
            Exception firstException = null;

            // Try the given URL, maybe user directly entered the CMIS AtomPub endpoint URL.
            try
            {
                repositories = GetRepositories(credentials);
            }
            catch (CmisRuntimeException e)
            {
                if (e.Message == "ConnectFailure")
                    return new Tuple<CmisServer, Exception>(new CmisServer(credentials.Address, null), new ServerNotFoundException(e.Message, e));
                firstException = e;
            }
            catch (Exception e)
            {
                // Save first Exception and try other possibilities.
                firstException = e;
            }
            if (repositories != null)
            {
                // Found!
                return new Tuple<CmisServer, Exception>(new CmisServer(credentials.Address, repositories), null);
            }

            // Extract protocol and server name or IP address
            string prefix = credentials.Address.GetLeftPart(UriPartial.Authority);

            // See https://github.com/nicolas-raoul/CmisSync/wiki/What-address for the list of ECM products prefixes
            // Please send us requests to support more CMIS servers: https://github.com/nicolas-raoul/CmisSync/issues
            string[] suffixes = {
                "/cmis/atom11",
                "/alfresco/cmisatom",
                "/alfresco/service/cmis",
                "/cmis/resources/",
                "/emc-cmis-ea/resources/",
                "/emc-cmis-weblogic/resources/",
                "/emc-cmis-wls/resources/",
                "/emc-cmis-was61/resources/",
                "/emc-cmis-wls1030/resources/",
                "/xcmis/rest/cmisatom",
                "/files/basic/cmis/my/servicedoc",
                "/p8cmis/resources/Service",
                "/_vti_bin/cmis/rest?getRepositories",
                "/nemakiware/atom/bedroom",
                "/nuxeo/atom/cmis",
                "/cmis/atom"
            };
            string bestUrl = null;
            // Try all suffixes
            for (int i=0; i < suffixes.Length; i++)
            {
                string fuzzyUrl = prefix + suffixes[i];
                Logger.Info("Sync | Trying with " + fuzzyUrl);
                try
                {
                    ServerCredentials cred = new ServerCredentials()
                    {
                        UserName = credentials.UserName,
                        Password = credentials.Password.ToString(),
                        Address = new Uri(fuzzyUrl)
                    };
                    repositories = GetRepositories(cred);
                }
                catch (CmisPermissionDeniedException e)
                {
                    firstException = new PermissionDeniedException(e.Message, e);
                    bestUrl = fuzzyUrl;
                }
                catch (Exception e)
                {
                    // Do nothing, try other possibilities.
                    Logger.Debug(e.Message);
                }
                if (repositories != null)
                {
                    // Found!
                    return new Tuple<CmisServer, Exception>( new CmisServer(new Uri(fuzzyUrl), repositories), null);
                }
            }

            // Not found. Return also the first exception to inform the user correctly
            return new Tuple<CmisServer,Exception>(new CmisServer(bestUrl==null?credentials.Address:new Uri(bestUrl), null), firstException);
        }
Example #12
0
        partial void OnContinue (MonoMac.Foundation.NSObject sender)
        {
            ServerCredentials credentials = new ServerCredentials() {
                UserName = UserText.StringValue,
                Password = PasswordText.StringValue,
                Address = new Uri(AddressText.StringValue)
            };
            AddressText.Enabled = false;
            UserText.Enabled = false;
            PasswordText.Enabled = false;
            ContinueButton.Enabled = false;
            CancelButton.Enabled = false;

            Thread check = new Thread(() => {
                Tuple<CmisServer, Exception> fuzzyResult = CmisUtils.GetRepositoriesFuzzy(credentials);
                CmisServer cmisServer = fuzzyResult.Item1;
                if (cmisServer != null)
                {
                    Controller.repositories = cmisServer.Repositories;
                }
                else
                {
                    Controller.repositories = null;
                    // Could not retrieve repositories list from server
                    string warning = "";
                }
                InvokeOnMainThread(delegate {
                    if (Controller.repositories == null)
                    {
                        // WarnText.StringValue = Controller.getConnectionsProblemWarning(fuzzyResult.Item1, fuzzyResult.Item2);
                        string message = fuzzyResult.Item2.Message;
                        string warning = "";
                        Exception e = fuzzyResult.Item2;
                        if (e is PermissionDeniedException)
                        {
                            warning = Properties_Resources.LoginFailedForbidden;
                        }
                        else if (e is ServerNotFoundException)
                        {
                            warning = Properties_Resources.ConnectFailure;
                        }
                        else if (e.Message == "SendFailure" && cmisServer.Url.Scheme.StartsWith("https"))
                        {
                            warning = Properties_Resources.SendFailureHttps;
                        }
                        else if (e.Message == "TrustFailure")
                        {
                            warning = Properties_Resources.TrustFailure;
                        }
                        else if (e.Message == "Unauthorized")
                        {
                            warning = Properties_Resources.LoginFailedForbidden;
                        }
                        else
                        {
                            warning = message + Environment.NewLine + Properties_Resources.Sorry;
                        }

                        WarnText.StringValue = warning;
                        AddressText.Enabled = true;
                        UserText.Enabled = true;
                        PasswordText.Enabled = true;
                        ContinueButton.Enabled = true;
                        CancelButton.Enabled = true;
                        // TODO remove  this line for debug

                    }
                    else
                    {
                        RemoveEvent();
                        Controller.Add1PageCompleted(cmisServer.Url, credentials.UserName, credentials.Password.ToString());
                    }
                });
            });
            check.Start();
        }