Example #1
0
 public void LoadPrefs()
 {
     _registredServers.Clear();
     if (!File.Exists(ConfigFile))
     {
         return;
     }
     try
     {
         using (var file = File.OpenRead(ConfigFile))
         {
             XDocument doc = XDocument.Load(file);
             foreach (var serverElement in doc.Root.Element("Servers").Elements("Server"))
             {
                 var isPasswordSavedInXml = serverElement.Attribute("Password") != null;
                 var password             = isPasswordSavedInXml ? serverElement.Attribute("Password").Value : CredentialsManager.GetPassword(new Uri(serverElement.Attribute("Url").Value));
                 if (password == null)
                 {
                     throw new Exception("TFS Addin: No Password found for TFS server: " + serverElement.Attribute("Name").Value);
                 }
                 var server = TeamFoundationServerFactory.Create(serverElement, password, isPasswordSavedInXml);
                 if (server != null)
                 {
                     _registredServers.Add(server);
                 }
             }
             foreach (var workspace in doc.Root.Element("Workspaces").Elements("Workspace"))
             {
                 _activeWorkspaces.Add(workspace.Attribute("Id").Value, workspace.Attribute("Name").Value);
             }
             var mergeToolElement = doc.Root.Element("MergeTool");
             if (mergeToolElement != null)
             {
                 this.MergeToolInfo = new MergeToolInfo
                 {
                     CommandName = mergeToolElement.Attribute("Command").Value,
                     Arguments   = mergeToolElement.Attribute("Arguments").Value,
                 };
             }
             checkOutLockLevel = doc.Root.Element("CheckOutLockLevel") == null ? CheckOutLockLevel.Unchanged : (CheckOutLockLevel)Convert.ToInt32(doc.Root.Element("CheckOutLockLevel").Value);
             isDebugMode       = doc.Root.Element("DebugMode") != null && Convert.ToBoolean(doc.Root.Element("DebugMode").Value);
             this.Servers.ForEach(s => s.IsDebuMode = isDebugMode);
             file.Close();
         }
     }
     catch (Exception e)
     {
         MessageService.ShowException(e);
         return;
     }
     if (_registredServers.Any())
     {
         RaiseServersChange();
     }
 }
 void OnAddServer(object sender, EventArgs e)
 {
     using (var dialog = new AddServerDialog())
     {
         if (dialog.Run(this) == Command.Ok && dialog.ServerInfo != null)
         {
             if (TFSVersionControlService.Instance.HasServer(dialog.ServerInfo.Name))
             {
                 MessageService.ShowError("Server with same name already exists!");
                 return;
             }
             using (var credentialsDialog = new CredentialsDialog(dialog.ServerType))
             {
                 if (credentialsDialog.Run(this) == Command.Ok && credentialsDialog.Authentication != null)
                 {
                     CredentialsManager.StoreCredential(dialog.ServerInfo.Uri, credentialsDialog.Authentication.Password);
                     var  password             = CredentialsManager.GetPassword(dialog.ServerInfo.Uri); //Try Get Password
                     bool isPasswordSavedInXml = false;
                     if (password == null)
                     {
                         MessageService.ShowWarning("No keyring service found!\nPassword will be saved as plain text.");
                         isPasswordSavedInXml = true;
                     }
                     var server = TeamFoundationServerFactory.Create(dialog.ServerType, dialog.ServerInfo,
                                                                     credentialsDialog.Authentication, isPasswordSavedInXml);
                     using (var projectsDialog = new ChooseProjectsDialog(server))
                     {
                         if (projectsDialog.Run(this) == Command.Ok && projectsDialog.SelectedProjects.Any())
                         {
                             var selectedProjects = projectsDialog.SelectedProjects;
                             server.ProjectCollections = new List <ProjectCollection>(selectedProjects.Select(x => x.Collection).Distinct());
                             server.ProjectCollections.ForEach(pc => pc.Projects = new List <ProjectInfo>(selectedProjects.Where(pi => pi.Collection == pc)));
                             TFSVersionControlService.Instance.AddServer(server);
                             UpdateServersList();
                         }
                     }
                 }
             }
         }
     }
 }