private void InitActions(bool isClearCache = false) { service?.Dispose(); CheckContext(isClearCache); crmAssembly.Clear(); try { ShowBusy("Checking assembly registration ..."); IsRegistered = CrmAssemblyHelper.IsAssemblyRegistered(context); } catch { IsRegistered = false; } if (!IsRegistered) { settings.Id = crmAssembly.Id = assemblyRegistration.Id = Guid.Empty; return; } ShowBusy("Getting assembly ID ..."); settings.Id = crmAssembly.Id = assemblyRegistration.Id = CrmAssemblyHelper.GetAssemblyId(context); UpdateStatus("Updating assembly info ...", true); crmAssembly.UpdateInfo(context); }
private void DeletePlugin() { var dte2 = GetService(typeof(SDTE)) as DTE2; var project = dte2.GetSelectedProject(); if (string.IsNullOrWhiteSpace(project?.FullName)) { throw new UserException("Please select a project first!"); } var settingsArray = Configuration.LoadConfigs(); var settings = settingsArray.GetSelectedSettings(); // if an ID does not exist and no connection info, then it's a new run if (settings.Id == Guid.Empty && (string.IsNullOrEmpty(settings.ServerName) || string.IsNullOrEmpty(settings.Username))) { RegisterModifyPlugin(project); } else { using (var service = ConnectionHelper.GetConnection(settings.GetOrganizationCrmConnectionString())) { var context = new XrmServiceContext(service); var registration = new AssemblyRegistration(context, service); // if the assembly is registered, get ID and delete if (CrmAssemblyHelper.IsAssemblyRegistered(context)) { var id = settings.Id == Guid.Empty ? CrmAssemblyHelper.GetAssemblyId(context) : settings.Id; registration.DeleteAssembly(id); } else { Status.Update("Assembly already deleted!"); // else, reset ID settings.Id = Guid.Empty; Configuration.SaveConfigs(settingsArray); } } } }
private void UpdatePlugin(Project project) { DteHelper.SetCurrentProject(project); var settingsArray = Configuration.LoadConfigs(); var settings = settingsArray.GetSelectedSettings(); // if an ID does not exist and no connection info, then it's a new run if (settings.Id == Guid.Empty && (string.IsNullOrEmpty(settings.ServerName) || string.IsNullOrEmpty(settings.Username))) { CopySettings(); RegisterModifyPlugin(project); } else { using (var service = ConnectionHelper.GetConnection(settings.GetOrganizationCrmConnectionString())) { var context = new XrmServiceContext(service); var registration = new AssemblyRegistration(context, service); registration.PropertyChanged += (o, args) => { try { switch (args.PropertyName) { case "LogMessage": lock (registration.LoggingLock) { Status.Update(registration.LogMessage); } break; } } catch { // ignored } }; // if the assembly is registered, get ID and update if (CrmAssemblyHelper.IsAssemblyRegistered(context)) { var id = settings.Id == Guid.Empty ? CrmAssemblyHelper.GetAssemblyId(context) : settings.Id; registration.UpdateAssembly(id, null); Status.Update($"Ran update on: {settings.ServerName} - {settings.CrmOrg} - {settings.Username}."); Status.Update($"For project: {DteHelper.GetProjectName(project)}."); } else { // else, reset and open dialogue // reset ID settings.Id = Guid.Empty; Configuration.SaveConfigs(settingsArray); RegisterModifyPlugin(project); } } } }