/// <summary> /// Load settings from registry or applies default values if registry values are either missing or /// this class was created without a connection to a team foundation server /// </summary> /// <param name="teamProjectCollectionUrl">Team project collection url</param> /// <returns>True if all keys were accessed successfully, false if at least on key could not be accessed</returns> public bool Load(string teamProjectCollectionUrl) { var successfulLoad = true; Logger.Instance().Log(TraceLevel.Verbose, "Loading settings from team foundation registry"); if (teamProjectCollectionUrl != null) { var tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(teamProjectCollectionUrl)); tfs.EnsureAuthenticated(); _registry = tfs.GetService <ITeamFoundationRegistry>(); } // Loads values from TFS registry foreach (var property in GetType().GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)) { var registryInfo = property.GetCustomAttribute <TfsRegistryEntryAttribute>(); // ReSharper disable InvertIf if (registryInfo != null) // ReSharper restore InvertIf { var key = string.Format("{0}/{1}", TfsRegistryFolder, registryInfo.RegistryKeyOverride ?? property.Name); try { // Apply default value and after that, try to load value from registry property.SetValue(this, registryInfo.DefaultValue); var value = _registry.GetValue(key); if (value == null) { // If we dont have read permission for security reasons null is returned which is the same for keys that don't exist Logger.Instance().Log(TraceLevel.Verbose, "Key not present in registry or access denied: {0}. Using default value", key); successfulLoad = false; } else { property.SetValue(this, Convert.ChangeType(value, property.PropertyType)); } } catch (Exception e) { Logger.Instance().Log(TraceLevel.Warning, "Failed to load value {0} from tfs registry: {1}", key, e.ToString()); } } } return(successfulLoad); }
private void ReadRegistry() { txtWorkflowActivitiesGlobalCollection.Text = tfsRegServiceConfiguration.GetValue(TfsRegistryPath.WorkflowActivitiesGlobalCollection, "").Trim(new char[] { '/' }); txtWorkflowActivitiesGlobalPath.Text = tfsRegServiceConfiguration.GetValue(TfsRegistryPath.WorkflowActivitiesGlobalPath, "").Trim(new char[] { '/' }); txtWorkflowsGlobalCollection.Text = tfsRegServiceConfiguration.GetValue(TfsRegistryPath.WorkflowsGlobalCollection, "").Trim(new char[] { '/' }); txtWorkflowsGlobalPath.Text = tfsRegServiceConfiguration.GetValue(TfsRegistryPath.WorkflowsGlobalPath, "").Trim(new char[] { '/' }); // WorkflowsCollectionPath.Text = tfsRegServiceConfiguration.GetValue(TfsRegistryPath.WorkflowsCollectionPath, "").Trim(new char[] { '/' }); txtWorkflowsProjectReleativePath.Text = tfsRegServiceConfiguration.GetValue(TfsRegistryPath.WorkflowsProjectReleativePath, "").Trim(new char[] { '/' }); txtWorkflowsConfigFileNameWebService.Text = tfsRegServiceConfiguration.GetValue(TfsRegistryPath.WorkflowsConfigFileNameWebService, "").Trim(new char[] { '/' }); txtWorkflowsConfigFileNameJobAgent.Text = tfsRegServiceConfiguration.GetValue(TfsRegistryPath.WorkflowsConfigFileNameJobAgent, "").Trim(new char[] { '/' }); cbCollection.ValueMember = ""; cbCollection.DisplayMember = ""; cbCollection.DataSource = null; dictWorkflowsCollectionPath = new Dictionary <string, string>(); ReadOnlyCollection <CatalogNode> collectionNodes = srvConfiguration.CatalogNode.QueryChildren( new[] { CatalogResourceTypes.ProjectCollection }, false, CatalogQueryOptions.None); foreach (Microsoft.TeamFoundation.Framework.Client.CatalogNode collectionNode in collectionNodes) { string strCollection = collectionNode.Resource.DisplayName; Guid quidCollection = new Guid(collectionNode.Resource.Properties["InstanceId"]); Microsoft.TeamFoundation.Client.TfsTeamProjectCollection collection = srvConfiguration.GetTeamProjectCollection(quidCollection); Microsoft.TeamFoundation.Framework.Client.ITeamFoundationRegistry tfsRegServiceCollection = collection.GetService <Microsoft.TeamFoundation.Framework.Client.ITeamFoundationRegistry>(); string strWorkflowsCollectionPath = tfsRegServiceCollection.GetValue(TfsRegistryPath.WorkflowsCollectionPath, "").Trim(new char[] { '/' }); dictWorkflowsCollectionPath.Add(strCollection, strWorkflowsCollectionPath); } cbCollection.DataSource = new BindingSource(dictWorkflowsCollectionPath, null); cbCollection.DisplayMember = "Key"; cbCollection.ValueMember = "Value"; }