Beispiel #1
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)
            {
                Assert.That(string.IsNullOrEmpty(pair.Key), Is.False);
                Assert.That(string.IsNullOrEmpty(pair.Value), Is.False);
            }

            Assert.NotNull(repos);
        }
Beispiel #2
0
            /// <summary>
            /// Apply: Added files.
            /// </summary>
            public bool ApplyAddedFiles(ref List <string> addedFiles)
            {
                bool success = true;

                foreach (string addedFile in addedFiles)
                {
                    string   destinationFolderPath = Path.GetDirectoryName(addedFile);
                    SyncItem folderItem            = SyncItemFactory.CreateFromLocalPath(destinationFolderPath, true, repoInfo, database);
                    SyncItem fileItem = SyncItemFactory.CreateFromLocalPath(addedFile, false, repoInfo, database);
                    try
                    {
                        IFolder destinationFolder = (IFolder)session.GetObjectByPath(folderItem.RemotePath);

                        // Fill documents list, needed by the crawl method.
                        IList <string> remoteFiles = new List <string>();

                        if (CmisUtils.DocumentExists(session, fileItem.RemotePath))
                        {
                            remoteFiles.Add(fileItem.RemoteLeafname);
                        }

                        // Crawl this particular file.
                        CheckLocalFile(fileItem.LocalPath, destinationFolder, remoteFiles);
                    }
                    catch (Exception e)
                    {
                        Logger.Error("Error applying local file addition to the server: " + addedFile, e);
                        success = false;
                    }
                }
                return(success);
            }
        public void GetRepositoriesTroughProxy(
            string cmisServerUrl,
            string cmisUser,
            string cmisPassword,
            string proxyUrl,
            string proxyUser,
            string proxyPassword)
        {
            if (string.IsNullOrEmpty(proxyUrl))
            {
                Assert.Ignore();
            }

            ServerCredentials credentials = new ServerCredentials
            {
                Address  = new Uri(cmisServerUrl),
                UserName = cmisUser,
                Password = cmisPassword
            };

            ProxySettings proxySettings = new ProxySettings();

            proxySettings.Selection     = string.IsNullOrEmpty(cmisServerUrl) ? ProxySelection.NOPROXY : ProxySelection.CUSTOM;
            proxySettings.Server        = new Uri(proxyUrl);
            proxySettings.LoginRequired = !string.IsNullOrEmpty(proxyUser);
            if (proxySettings.LoginRequired)
            {
                proxySettings.Username           = proxyUser;
                proxySettings.ObfuscatedPassword = Crypto.Obfuscate(proxyPassword);
            }

            HttpProxyUtils.SetDefaultProxy(proxySettings, true);

            Assert.That(CmisUtils.GetRepositories(credentials), Is.Not.Empty);
        }
Beispiel #4
0
            /// <summary>
            /// Perform a crawl sync (check all folders and file checksums).
            /// If successful, update the local ChangeLog token.
            /// </summary>
            private void CrawlSyncAndUpdateChangeLogToken(IFolder remoteFolder, string remotePath, string localFolder)
            {
                var sw = new System.Diagnostics.Stopwatch();

                Logger.Info("Remote Full Crawl Started");
                try
                {
                    // Get ChangeLog token.
                    string token = CmisUtils.GetChangeLogToken(session);

                    // Sync.
                    bool success = CrawlSync(remoteFolder, remotePath, localFolder);

                    // Update ChangeLog token if sync has been successful.
                    if (success)
                    {
                        database.SetChangeLogToken(token);
                    }
                    else
                    {
                        Logger.Info("ChangeLog token not updated as an error occurred during sync.");
                    }
                }
                finally
                {
                    Logger.InfoFormat("Remote Full Crawl Finished : {0} min", sw.Elapsed);
                }
            }
            private bool HasFolderChanged(IFolder deletedIFolder)
            {
                // TODO Does not work if newly-created.

                // ChangeLog
                string lastTokenOnClient = database.GetChangeLogToken();
                string lastTokenOnServer = CmisUtils.GetChangeLogToken(session);

                if (lastTokenOnClient == lastTokenOnServer || lastTokenOnClient == null)
                {
                    return(false);
                }

                // TODO: Extract static code, because same code was writtern in SynchronizedFolder
                Config.Feature features = null;
                if (ConfigManager.CurrentConfig.GetFolder(repoInfo.Name) != null)
                {
                    features = ConfigManager.CurrentConfig.GetFolder(repoInfo.Name).SupportedFeatures;
                }
                int maxNumItems = (features != null && features.MaxNumberOfContentChanges != null) ?  // TODO if there are more items, either loop or force CrawlSync
                                  (int)features.MaxNumberOfContentChanges : 500;

                var changes = session.GetContentChanges(lastTokenOnClient, IsPropertyChangesSupported, maxNumItems);

                return(CheckInsideChange(deletedIFolder, changes));
            }
Beispiel #6
0
        public void GetRepositories(string canonical_name, string localPath, string remoteFolderPath,
                                    string url, string user, string password, string repositoryId)
        {
            Dictionary <string, string> repos = CmisUtils.GetRepositories(url, user, password);

            Assert.NotNull(repos);
        }
            /// <summary>
            /// Apply: Added folders.
            /// </summary>
            public bool ApplyAddedFolders(ref List <string> addedFolders)
            {
                bool success = true;

                foreach (string addedFolder in addedFolders)
                {
                    string   destinationFolderPath = Path.GetDirectoryName(addedFolder);
                    SyncItem destinationFolderItem = SyncItemFactory.CreateFromLocalPath(destinationFolderPath, true, repoInfo, database);
                    SyncItem addedFolderItem       = SyncItemFactory.CreateFromLocalPath(addedFolder, true, repoInfo, database);
                    try
                    {
                        IFolder destinationFolder = (IFolder)session.GetObjectByPath(destinationFolderItem.RemotePath, true);

                        IList <string> remoteFolders = new List <string>();

                        if (CmisUtils.FolderExists(session, addedFolderItem.RemotePath))
                        {
                            remoteFolders.Add(addedFolderItem.RemoteLeafname);
                        }

                        // TODO more efficient: first create said folder, then call CrawlSync in it.
                        CrawlSync(destinationFolder, destinationFolderItem.RemotePath, destinationFolderItem.LocalPath);
                    }
                    catch (Exception e)
                    {
                        Logger.Error("Error applying local folder addition to the server: " + addedFolder, e);
                        success = false;
                    }
                }
                return(success);
            }
            public ClientBrand(ServerCredentials credentials, string repositoryId, string remoteFolderPath)
            {
                Dictionary <string, string> parameters = CmisUtils.GetCmisParameters(credentials);
                ISessionFactory             factory    = SessionFactory.NewInstance();
                IList <IRepository>         repos      = factory.GetRepositories(parameters);

                foreach (IRepository repo in repos)
                {
                    if (repo.Id == repositoryId)
                    {
                        this.repository = repo;
                        this.repoName   = repo.Name;
                    }
                }

                if (this.repository == null)
                {
                    throw new ArgumentException("No such repository for " + repositoryId);
                }

                this.session = this.repository.CreateSession();
                this.folder  = this.session.GetObjectByPath(remoteFolderPath) as IFolder;
                if (this.folder == null)
                {
                    throw new ArgumentException("No such folder for " + remoteFolderPath);
                }

                foreach (string name in this.nameList)
                {
                    this.pathList.Add((remoteFolderPath + "/" + name).Replace("//", "/"));
                }

                this.DeleteFiles();
                this.CreateFiles();
            }
Beispiel #9
0
 /// <summary>
 /// Get the list of subfolders contained in a CMIS folder.
 /// </summary>
 static public string[] GetSubfolders(
     string repositoryId,
     string path,
     string address,
     string user,
     string password)
 {
     return(CmisUtils.GetSubfolders(repositoryId, path, address, user, password));
 }
            /// <summary>
            /// Synchronize changes made to a particular CMIS object.
            /// </summary>
            private bool CrawlCmisObject(ICmisObject cmisObject)
            {
                bool success = true;

                if (cmisObject is DotCMIS.Client.Impl.Folder)
                {
                    var remoteSubFolder = cmisObject as IFolder;

                    // Look for the local equivalent.
                    var localFolderItem = database.GetFolderSyncItemFromRemotePath(remoteSubFolder.Path);
                    while (true)
                    {
                        // If other local folders have the same id, they are obsolete and must be deteled.
                        var foldersToDelete = database.GetAllFoldersWithCmisId(cmisObject.Id).Where(p => p.RemotePath != remoteSubFolder.Path);
                        foreach (var folderToDelete in foldersToDelete)
                        {
                            success &= RemoveFolderLocally(folderToDelete.LocalPath);
                        }
                        ;

                        if (localFolderItem != null || remoteSubFolder.IsRootFolder)
                        {
                            break;
                        }

                        // Go up one level before performing the same thing.
                        remoteSubFolder = remoteSubFolder.Parents[0]; //TODO: Fix Parents[0] for multi-parent repositories
                        localFolderItem = database.GetFolderSyncItemFromRemotePath(remoteSubFolder.Path);
                    }
                    ;

                    success &= CrawlSync(remoteSubFolder, remoteSubFolder.Path, localFolderItem.LocalPath);
                }
                else if (cmisObject is DotCMIS.Client.Impl.Document)
                {
                    var remoteDocument = cmisObject as IDocument;

                    // Apply the change on all paths via which it is applicable.
                    foreach (IFolder remoteIFolder in remoteDocument.Parents)
                    {
                        if (PathIsApplicable(remoteIFolder.Path))
                        {
                            Logger.Debug("Document change is applicable:" + remoteIFolder);

                            var localFolderItem = database.GetFolderSyncItemFromRemotePath(remoteIFolder.Path);
                            var localFolder     = localFolderItem.LocalPath;

                            var remoteDocumentPath = CmisUtils.PathCombine(remoteIFolder.Path, repoInfo.CmisProfile.localFilename(remoteDocument));
                            var documentItem       = SyncItemFactory.CreateFromRemoteDocument(remoteDocumentPath, remoteDocument, repoInfo, database);

                            success &= CrawlRemoteDocument(remoteDocument, documentItem.RemotePath, localFolder, null);
                        }
                    }
                }
                return(success);
            }
Beispiel #11
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));
     }
 }
Beispiel #12
0
        /// <summary>
        /// Loads a tree of remote sub folder with the depth of 2
        /// </summary>
        /// <param name="credentials"></param>
        /// <param name="root"></param>
        /// <returns></returns>
        public static List <Node> LoadSubFolderDelegate(CmisRepoCredentials credentials, Node root)
        {
            CmisUtils.FolderTree tree     = CmisUtils.GetSubfolderTree(credentials, root.Path, 2);
            List <Node>          children = CreateSubTrees(tree.Children, null);

            foreach (Node child in children)
            {
                child.Parent = root;
            }
            return(children);
        }
Beispiel #13
0
        public void GetRepositories(string canonical_name, string localPath, string remoteFolderPath,
                                    string url, string user, string password, string repositoryId)
        {
            Dictionary <string, string> repos = CmisUtils.GetRepositories(new Uri(url), user, password);

            foreach (KeyValuePair <string, string> pair in repos)
            {
                Console.WriteLine(pair.Key + " : " + pair.Value);
            }
            Assert.NotNull(repos);
        }
Beispiel #14
0
        /// <summary>
        /// Check whether the filename is worth syncing or not.
        /// Files that are not worth syncing include temp files, locks, etc.
        /// </summary>
        private static bool IsFilenameWorthSyncing(string localDirectory, string filename)
        {
            if (null == filename)
            {
                return(false);
            }

            filename = filename.ToLower();

            if (ignoredFilenames.Contains(filename) ||
                ignoredFilenamesRegex.IsMatch(filename))
            {
                Logger.DebugFormat("Skipping {0}: ignored file", filename);
                return(false);
            }

            // Check filename extension if there is one.
            if (filename.Contains('.'))
            {
                string extension = filename.Split('.').Last();

                if (ignoredExtensions.Contains(extension))
                {
                    Logger.DebugFormat("Skipping {0}: ignored file extension", filename);
                    return(false);
                }
            }

            // Check resulting file path length
            string fullPath = CmisUtils.PathCombine(localDirectory, filename);

            #if __COCOA__ || __MonoCS__
            // TODO Check filename length for OS X
            // * Max "FileName" length: 255 charactors.
            // * FileName encoding is UTF-16 (Modified NFD).
            #else
            // Get Path.MaxPath
            // It is not a public field so reflection is necessary.

            FieldInfo maxPathField = typeof(Path).GetField("MaxPath",
                                                           BindingFlags.Static |
                                                           BindingFlags.GetField |
                                                           BindingFlags.NonPublic);

            if (fullPath.Length > (int)maxPathField.GetValue(null))
            {
                Logger.WarnFormat("Skipping {0}: path too long", fullPath);
                return(false);
            }
            #endif

            return(true);
        }
Beispiel #15
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);
        }
Beispiel #16
0
            private void SubFolderWork(object sender, DoWorkEventArgs e)
            {
                BackgroundWorker worker = sender as BackgroundWorker;
                Folder           f      = queue.Dequeue();

                currentWorkingObject        = f;
                currentWorkingObject.Status = LoadingStatus.LOADING;
                e.Result = CmisUtils.GetSubfolders(Id, f.Path, address, username, password);
                if (worker.CancellationPending)
                {
                    e.Cancel = true;
                }
            }
Beispiel #17
0
 public void OpenRemoteFolder(string name)
 {
     Config.SyncConfig.Folder f = ConfigManager.CurrentConfig.getFolder(name);
     if (f != null)
     {
         RepoInfo repo = f.GetRepoInfo();
         Process.Start(CmisUtils.GetBrowsableURL(repo));
     }
     else
     {
         Logger.Warn("Repo not found: " + name);
     }
 }
Beispiel #18
0
 /// <summary>
 /// With the default web browser, open the remote folder of a CmisSync synchronized folder.
 /// </summary>
 /// <param name="name">Name of the synchronized folder</param>
 public void OpenRemoteFolder(string name)
 {
     Config.SyncConfig.Folder folder = ConfigManager.CurrentConfig.getFolder(name);
     if (folder != null)
     {
         RepoInfo repo = folder.GetRepoInfo();
         Process.Start(CmisUtils.GetBrowsableURL(repo));
     }
     else
     {
         Logger.Warn("Could not find requested config for \"" + name + "\"");
     }
 }
Beispiel #19
0
        /// <summary>
        /// Load repositories information from a CMIS endpoint.
        /// </summary>
        static public Tuple <CmisServer, Exception> GetRepositoriesFuzzy(string url, string user, string password)
        {
            Uri uri;

            try
            {
                uri = new Uri(url);
                return(CmisUtils.GetRepositoriesFuzzy(uri, user, password));
            }
            catch (Exception e)
            {
                return(new Tuple <CmisServer, Exception>(null, e));
            }
        }
Beispiel #20
0
        partial void OnPasswordChanged(NSObject sender)
        {
            this.LoginStatusLabel.StringValue = "logging in...";
            this.LoginStatusLabel.Hidden      = false;
            //  monomac bug: animation GUI effect will cause GUI to hang, when backend thread is busy
//            this.LoginStatusProgress.StartAnimation(this);
            ServerCredentials cred = new ServerCredentials()
            {
                Address  = Credentials.Address,
                UserName = Credentials.UserName,
                Password = PasswordText.StringValue
            };

            PasswordText.Enabled = false;
            new TaskFactory().StartNew(() => {
                try{
                    CmisUtils.GetRepositories(cred);
                    InvokeOnMainThread(() => {
                        lock (loginLock)
                        {
                            if (!isClosed)
                            {
                                this.LoginStatusLabel.StringValue = "login successful";
                            }
                        }
                    });
                }catch (Exception e) {
                    InvokeOnMainThread(() => {
                        lock (loginLock)
                        {
                            if (!isClosed)
                            {
                                this.LoginStatusLabel.StringValue = "login failed: " + e.Message;
                            }
                        }
                    });
                }
                InvokeOnMainThread(() => {
                    lock (loginLock)
                    {
                        PasswordText.Enabled = true;
                        if (!isClosed)
                        {
                            this.LoginStatusProgress.StopAnimation(this);
                        }
                    }
                });
            });
        }
Beispiel #21
0
        partial void OnContinue(MonoMac.Foundation.NSObject sender)
        {
            ServerCredentials credentials = new ServerCredentials()
            {
                UserName = UserText.StringValue,
                Password = PasswordText.StringValue,
                Address  = new Uri(AddressText.StringValue)
            };

            WarnText.StringValue   = String.Empty;
            AddressText.Enabled    = false;
            UserText.Enabled       = false;
            PasswordText.Enabled   = false;
            ContinueButton.Enabled = false;
            CancelButton.Enabled   = false;
            //  monomac bug: animation GUI effect will cause GUI to hang, when backend thread is busy
//            LoginProgress.StartAnimation(this);
            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)
                    {
                        WarnText.StringValue   = Controller.GetConnectionsProblemWarning(fuzzyResult.Item1, fuzzyResult.Item2);
                        AddressText.Enabled    = true;
                        UserText.Enabled       = true;
                        PasswordText.Enabled   = true;
                        ContinueButton.Enabled = true;
                        CancelButton.Enabled   = true;
                    }
                    else
                    {
                        RemoveEvent();
                        Controller.Add1PageCompleted(cmisServer.Url, credentials.UserName, credentials.Password.ToString());
                    }
                    LoginProgress.StopAnimation(this);
                });
            });

            check.Start();
        }
Beispiel #22
0
            private void DoWork(object sender, DoWorkEventArgs e)
            {
                BackgroundWorker worker = sender as BackgroundWorker;

                try
                {
                    e.Result = CmisUtils.GetSubfolderTree(Id, Path, address, username, password, -1);
                }
                catch (Exception)
                {
                    e.Result = CmisUtils.GetSubfolders(Id, Path, address, username, password);
                }
                if (worker.CancellationPending)
                {
                    e.Cancel = true;
                }
            }
Beispiel #23
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;
                }
                InvokeOnMainThread(delegate {
                    if (Controller.repositories == null)
                    {
                        WarnText.StringValue   = Controller.getConnectionsProblemWarning(fuzzyResult.Item1, fuzzyResult.Item2);
                        AddressText.Enabled    = true;
                        UserText.Enabled       = true;
                        PasswordText.Enabled   = true;
                        ContinueButton.Enabled = true;
                        CancelButton.Enabled   = true;
                    }
                    else
                    {
                        RemoveEvent();
                        Controller.Add1PageCompleted(cmisServer.Url, credentials.UserName, credentials.Password.ToString());
                    }
                });
            });

            check.Start();
        }
Beispiel #24
0
        /// <summary></summary>
        /// <param name="localFolder"></param>
        /// <param name="remoteRelativePath"></param>
        /// <param name="repoInfo"></param>
        public LocalPathSyncItem(string localFolder, string remoteRelativePath, RepoInfo repoInfo)
        {
            this.localRoot  = repoInfo.TargetDirectory;
            this.remoteRoot = repoInfo.RemotePath;

            this.localPath = Path.Combine(localFolder, PathRepresentationConverter.RemoteToLocal(remoteRelativePath));
            if (localPath.StartsWith(this.localRoot))
            {
                this.localPath = localPath.Substring(localRoot.Length).TrimStart(Path.DirectorySeparatorChar);
            }
            string localRootRelative = localFolder;

            if (localFolder.StartsWith(this.localRoot))
            {
                localRootRelative = localFolder.Substring(localRoot.Length).TrimStart(CmisUtils.CMIS_FILE_SEPARATOR);
            }
            this.remotePath = CmisUtils.PathCombine(PathRepresentationConverter.LocalToRemote(localRootRelative), remoteRelativePath);
        }
            private void CrawlSyncAndUpdateChangeLogToken(IFolder remoteFolder, string remotePath, string localFolder)
            {
                // Get ChangeLog token.
                string token = CmisUtils.GetChangeLogToken(session);

                // Sync.
                bool success = CrawlSync(remoteFolder, remotePath, localFolder);

                // Update ChangeLog token if sync has been successful.
                if (success)
                {
                    database.SetChangeLogToken(token);
                }
                else
                {
                    Logger.Info("ChangeLog token not updated as an error occurred during sync.");
                }
            }
Beispiel #26
0
        private static bool IsAlfresco42OrLater(CmisSync.Lib.Config.SyncConfig.Folder folder, string newUrl)
        {
            try
            {
                CmisUtils.GetSubfolders(
                    folder.RepositoryId,
                    folder.RemotePath,
                    newUrl,
                    folder.UserName,
                    Crypto.Deobfuscate(folder.ObfuscatedPassword));

                return(true);
            }
            catch (Exception e)
            {
                return(false);
            }
        }
Beispiel #27
0
        /// <summary>
        /// Create from the path of a remote file, and the local filename to use.
        /// </summary>
        /// <param name="remoteRelativePath">Example: adir/a<file</param>
        /// <param name="localFilename">Example: afile.txt</param>
        public RemotePathSyncItem(string remoteRelativePath, string localFilename, RepoInfo repoInfo, Database.Database database)
        {
            this.isFolder   = false;
            this.database   = database;
            this.localRoot  = repoInfo.TargetDirectory;
            this.remoteRoot = repoInfo.RemotePath;

            this.remoteRelativePath = remoteRelativePath;
            if (remoteRelativePath.StartsWith(this.remoteRoot))
            {
                this.remoteRelativePath = this.remoteRelativePath.Substring(localRoot.Length).TrimStart(CmisUtils.CMIS_FILE_SEPARATOR);
            }

            int    lastSeparator        = remoteRelativePath.LastIndexOf(CmisUtils.CMIS_FILE_SEPARATOR);
            string remoteRelativeFolder = lastSeparator >= 0 ?
                                          remoteRelativePath.Substring(0, lastSeparator)
                : String.Empty;
            string remoteRelativePathWithCorrectLeafname = CmisUtils.PathCombine(remoteRelativeFolder, localFilename);

            localRelativePath = database.RemoteToLocal(remoteRelativePathWithCorrectLeafname, isFolder);
        }
        private IRepository GetRepo(ServerCredentials credentials)
        {
            Dictionary <string, string> parameters = CmisUtils.GetCmisParameters(credentials);

            try {
                ISessionFactory     factory = SessionFactory.NewInstance();
                IList <IRepository> repos   = factory.GetRepositories(parameters);
                foreach (IRepository repo in repos)
                {
                    if (repo.Name == this.RepoName)
                    {
                        return(repo);
                    }
                }

                return(null);
            } catch (Exception e) {
                Logger.Debug(e.Message);
                return(null);
            }
        }
Beispiel #29
0
        private void CheckPassword(object sender, DoWorkEventArgs args)
        {
            if (!passwordChanged)
            {
                return;
            }

            Dispatcher.BeginInvoke((Action) delegate
            {
                passwordHelp.Text           = Properties_Resources.LoginCheck;
                passwordBox.IsEnabled       = false;
                passwordProgress.Visibility = Visibility.Visible;
            });

            ServerCredentials cred = new ServerCredentials()
            {
                Address  = Credentials.Address,
                UserName = Credentials.UserName,
                Password = passwordBox.Password
            };

            CmisUtils.GetRepositories(cred);
        }
Beispiel #30
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);
        }