private void MyPluginControl_Load(object sender, EventArgs e) { pluginViewModel.ActiveConnection = ConnectionDetail != null; var organization = ConnectionDetail?.Organization ?? ""; // Loads or creates the settings for the plugin if (!SettingsManager.Instance.TryLoad(GetType(), out options)) { options = new Options { CurrentOrganizationOptions = new OrganizationOptions() { Key = organization } }; options.OrganizationOptions.Add(options.CurrentOrganizationOptions.Key, options.CurrentOrganizationOptions); options.PropertyChanged += Options_PropertyChanged; LogWarning("Settings not found => a new settings file has been created!"); } else { if (!options.OrganizationOptions.TryGetValue(organization, out OrganizationOptions current)) { current = new OrganizationOptions() { Key = organization }; options.OrganizationOptions.Add(current.Key, current); } options.CurrentOrganizationOptions = current; LogInfo("Settings found and loaded"); } optionsGrid.SelectedObject = options; }
/// <summary> /// This event occurs when the connection has been updated in XrmToolBox /// </summary> public override void UpdateConnection(IOrganizationService newService, ConnectionDetail detail, string actionName, object parameter) { base.UpdateConnection(newService, detail, actionName, parameter); if (options != null && detail != null) { var organization = detail.Organization; LogInfo("Connection has changed to: {0}", detail.WebApplicationUrl); if (!options.OrganizationOptions.TryGetValue(organization, out OrganizationOptions current)) { current = new OrganizationOptions() { Key = organization }; options.OrganizationOptions.Add(current.Key, current); } options.CurrentOrganizationOptions = current; } pluginViewModel.ActiveConnection = detail != null; }