public void UpdatePackageAgent(PackageAgent agent, bool updateEnabled) { if (agent == null) { throw new ArgumentNullException(nameof(agent)); } var packageAgents = GetExistingSettingsLookup(); packageAgents.TryGetValue(agent.Name, out var agentToUpdate); if (agentToUpdate != null) { AddItem disabledAgentItem = null; if (updateEnabled) { // get list of disabled packages var disabledAgentsSection = Settings.GetSection(ConfigurationConstants2.DisabledPackageAgents); disabledAgentItem = disabledAgentsSection?.GetFirstItemWithAttribute <AddItem>(ConfigurationConstants.KeyAttribute, agentToUpdate.ElementName); } var oldPackageAgent = ReadPackageAgent(agentToUpdate, disabledAgentItem == null); var isDirty = false; UpdatePackageAgent( agent, oldPackageAgent, disabledAgentItem, updateEnabled, shouldSkipSave: false, isDirty: ref isDirty); } }
public void AddPackageAgent(PackageAgent agent) { if (agent == null) { throw new ArgumentNullException(nameof(agent)); } var isDirty = false; AddPackageAgent(agent, shouldSkipSave: false, isDirty: ref isDirty); }
PackageAgent ReadPackageAgent(AgentItem setting, bool isEnabled) { var name = setting.Key; var packageAgent = new PackageAgent(setting.GetValueAsPath(), name, isEnabled) { IsMachineWide = setting.Origin?.IsMachineWide ?? false, }; return(packageAgent); }
/// <summary> /// Saves the <paramref name="agent" /> as the active agent. /// </summary> /// <param name="agent"></param> public void SaveActivePackageAgent(PackageAgent agent) { try { var activePackageAgentSection = Settings.GetSection(ConfigurationConstants2.ActivePackageAgentSectionName); if (activePackageAgentSection != null) { foreach (var activePackageAgent in activePackageAgentSection.Items) { Settings.Remove(ConfigurationConstants2.ActivePackageAgentSectionName, activePackageAgent); } } Settings.AddOrUpdate(ConfigurationConstants2.ActivePackageAgentSectionName, new AddItem(agent.Name, agent.Agent)); Settings.SaveToDisk(); } // we want to ignore all errors here. catch (Exception) { } }
void UpdatePackageAgent( PackageAgent newAgent, PackageAgent existingAgent, AddItem existingDisabledAgentItem, bool updateEnabled, bool shouldSkipSave, ref bool isDirty) { if (string.Equals(newAgent.Name, existingAgent.Name, StringComparison.OrdinalIgnoreCase)) { if ((!string.Equals(newAgent.Agent, existingAgent.Agent, StringComparison.OrdinalIgnoreCase) || newAgent.ProtocolVersion != existingAgent.ProtocolVersion) && newAgent.IsPersistable) { Settings.AddOrUpdate(ConfigurationConstants2.PackageAgents, newAgent.AsAgentItem()); isDirty = true; } if (updateEnabled) { if (newAgent.IsEnabled && existingDisabledAgentItem != null) { Settings.Remove(ConfigurationConstants2.DisabledPackageAgents, existingDisabledAgentItem); isDirty = true; } if (!newAgent.IsEnabled && existingDisabledAgentItem == null) { AddDisabledAgent(newAgent.Name, shouldSkipSave: true, isDirty: ref isDirty); } } if (!shouldSkipSave && isDirty) { Settings.SaveToDisk(); OnPackageAgentsChanged(); isDirty = false; } } }
void AddPackageAgent(PackageAgent agent, bool shouldSkipSave, ref bool isDirty) { if (agent.IsPersistable) { Settings.AddOrUpdate(ConfigurationConstants2.PackageAgents, agent.AsAgentItem()); isDirty = true; } if (agent.IsEnabled) { RemoveDisabledAgent(agent.Name, shouldSkipSave: true, isDirty: ref isDirty); } else { AddDisabledAgent(agent.Name, shouldSkipSave: true, isDirty: ref isDirty); } if (!shouldSkipSave && isDirty) { Settings.SaveToDisk(); OnPackageAgentsChanged(); isDirty = false; } }
static int AddOrUpdateIndexedAgent(Dictionary <string, IndexedPackageAgent> packageAgentLookup, int packageIndex, PackageAgent packageAgent, string lookupKey) { if (!packageAgentLookup.TryGetValue(lookupKey, out var previouslyAddedAgent)) { packageAgentLookup[lookupKey] = new IndexedPackageAgent { PackageAgent = packageAgent, Index = packageIndex++ } } ; else if (previouslyAddedAgent.PackageAgent.ProtocolVersion < packageAgent.ProtocolVersion && packageAgent.ProtocolVersion <= MaxSupportedProtocolVersion) { // Pick the package agent with the highest supported protocol version previouslyAddedAgent.PackageAgent = packageAgent; } return(packageIndex); }