public static bool ImportSolution(CrmServiceClient client, string path) { byte[] solutionBytes = CrmDeveloperExtensions2.Core.FileSystem.GetFileBytes(path); if (solutionBytes == null) { return(false); } try { ImportSolutionRequest request = new ImportSolutionRequest { //TODO: make configurable CustomizationFile = solutionBytes, OverwriteUnmanagedCustomizations = true, PublishWorkflows = true, ImportJobId = Guid.NewGuid() }; ImportSolutionResponse response = (ImportSolutionResponse)client.Execute(request); return(true); } catch (FaultException <OrganizationServiceFault> crmEx) { OutputLogger.WriteToOutputWindow("Error Importing Solution To CRM: " + crmEx.Message + Environment.NewLine + crmEx.StackTrace, MessageType.Error); return(false); } catch (Exception ex) { OutputLogger.WriteToOutputWindow("Error Importing Solution To CRM: " + ex.Message + Environment.NewLine + ex.StackTrace, MessageType.Error); return(false); } }
public static void AddFileFromTemplate(Project project, string templatePartialPath, string filename) { try { var codebase = Assembly.GetExecutingAssembly().CodeBase; var uri = new Uri(codebase, UriKind.Absolute); var path = Path.GetDirectoryName(uri.LocalPath); if (string.IsNullOrEmpty(path)) { OutputLogger.WriteToOutputWindow($"{Resource.ErrorMessage_FindTemplateDirectory}: {path}", MessageType.Error); return; } //TODO: update path for localization var templatePath = Path.Combine(path, $@"ItemTemplates\CSharp\D365 DevEx\1033\{templatePartialPath}.vstemplate"); project.ProjectItems.AddFromTemplate(templatePath, filename); } catch (Exception ex) { ExceptionHandler.LogException(Logger, $"{Resource.ErrorMessage_CreateFileFromTemplate}: {filename}", ex); MessageBox.Show($"{Resource.ErrorMessage_CreateFileFromTemplate}: {filename}"); } }
public static bool AddAssemblyToSolution(CrmServiceClient client, Guid assemblyId, string uniqueName) { try { var scRequest = new AddSolutionComponentRequest { ComponentType = 91, SolutionUniqueName = uniqueName, ComponentId = assemblyId }; client.Execute(scRequest); ExLogger.LogToFile(Logger, $"{Resource.Message_AssemblyAddedSolution}: {uniqueName} - {assemblyId}", LogLevel.Info); OutputLogger.WriteToOutputWindow($"{Resource.Message_AssemblyAddedSolution}: {uniqueName} - {assemblyId}", MessageType.Info); return(true); } catch (Exception ex) { ExceptionHandler.LogException(Logger, Resource.ErrorMessage_ErrorAddingAssemblySolution, ex); return(false); } }
public static bool Uninstall(DTE dte, Project project) { try { var componentModel = (IComponentModel)Package.GetGlobalService(typeof(SComponentModel)); if (componentModel == null) { return(false); } var uninstaller = componentModel.GetService <IVsPackageUninstaller>(); NuGetProcessor.UnInstallPackage(uninstaller, project, ExtensionConstants.IlMergeNuGet); OutputLogger.WriteToOutputWindow(Resource.Message_ILMergeUninstalled, MessageType.Info); return(true); } catch (Exception ex) { ExceptionHandler.LogException(Logger, Resource.ErrorMessage_ErrorUninstallingILMerge, ex); return(false); } }
public static bool AddWebResourceToSolution(CrmServiceClient client, string uniqueName, Guid webResourceId) { try { AddSolutionComponentRequest scRequest = new AddSolutionComponentRequest { ComponentType = 61, SolutionUniqueName = uniqueName, ComponentId = webResourceId }; AddSolutionComponentResponse response = (AddSolutionComponentResponse)client.Execute(scRequest); OutputLogger.WriteToOutputWindow("New Web Resource Added To Solution: " + response.id, MessageType.Info); return(true); } catch (FaultException <OrganizationServiceFault> crmEx) { OutputLogger.WriteToOutputWindow( "Error adding web resource to solution: " + crmEx.Message + Environment.NewLine + crmEx.StackTrace, MessageType.Error); return(false); } catch (Exception ex) { OutputLogger.WriteToOutputWindow( "Error adding web resource to solution: " + ex.Message + Environment.NewLine + ex.StackTrace, MessageType.Error); return(false); } }
public static string CreateToolPath() { var spPath = UserOptionsHelper.GetOption <string>(UserOptionProperties.SolutionPackagerToolPath); if (string.IsNullOrEmpty(spPath)) { OutputLogger.WriteToOutputWindow(Resource.ErrorMessage_SetSolutionPackagerPath, MessageType.Error); return(null); } if (!spPath.EndsWith("\\", StringComparison.CurrentCultureIgnoreCase)) { spPath += "\\"; } var toolPath = @"""" + spPath + "SolutionPackager.exe" + @""""; if (File.Exists(spPath + "SolutionPackager.exe")) { return(toolPath); } OutputLogger.WriteToOutputWindow($"S{Resource.ErrorMessage_SolutionPackagerNotFound}: {spPath}", MessageType.Error); return(null); }
private static void ProcessMetadata(RetrieveAllEntitiesResponse metaDataResponse) { ExLogger.LogToFile(Logger, Resource.Message_ProcessingMetadata, LogLevel.Info); OutputLogger.WriteToOutputWindow(Resource.Message_ProcessingMetadata, MessageType.Info); var entities = metaDataResponse.EntityMetadata; Metadata = new List <CompletionValue>(); var entityTriggerCharacter = UserOptionsHelper.GetOption <string>(UserOptionProperties.IntellisenseEntityTriggerCharacter); var entityFieldCharacter = UserOptionsHelper.GetOption <string>(UserOptionProperties.IntellisenseFieldTriggerCharacter); foreach (var entityMetadata in entities) { Metadata.Add(new CompletionValue($"{entityTriggerCharacter}{entityMetadata.LogicalName}", entityMetadata.LogicalName, GetDisplayName(entityMetadata.DisplayName), MetadataType.Entity)); Metadata.Add(new CompletionValue($"{entityTriggerCharacter}{entityMetadata.LogicalName}{entityFieldCharacter}?field?", $"{entityTriggerCharacter}{entityMetadata.LogicalName}", GetDisplayName(entityMetadata.DisplayName), MetadataType.None)); foreach (var attribute in entityMetadata.Attributes.Where(attribute => attribute.IsValidForCreate.GetValueOrDefault() || attribute.IsValidForUpdate.GetValueOrDefault() || attribute.IsValidForRead.GetValueOrDefault())) { Metadata.Add(new CompletionValue($"{entityTriggerCharacter}{entityMetadata.LogicalName}_{attribute.LogicalName}", attribute.LogicalName, $"{GetDisplayName(attribute.DisplayName)}: {attribute.AttributeType.GetValueOrDefault()}", MetadataType.Attribute)); } } Metadata = Metadata.OrderBy(m => m.Name).ToList(); }
public static string CreateToolPath(DTE dte) { CrmDeveloperExtensions2.Core.UserOptionsGrid.GetSolutionPackagerToolPath(dte); string spPath = CrmDeveloperExtensions2.Core.UserOptionsGrid.GetSolutionPackagerToolPath(dte); if (string.IsNullOrEmpty(spPath)) { OutputLogger.WriteToOutputWindow("Please set the Solution Packager path in options", MessageType.Error); return(null); } if (!spPath.EndsWith("\\")) { spPath += "\\"; } string toolPath = @"""" + spPath + "SolutionPackager.exe" + @""""; if (!File.Exists(spPath + "SolutionPackager.exe")) { OutputLogger.WriteToOutputWindow($"SolutionPackager.exe not found at: {spPath}", MessageType.Error); return(null); } return(toolPath); }
public static bool AddWebResourceToSolution(CrmServiceClient client, string uniqueName, Guid webResourceId) { try { var scRequest = new AddSolutionComponentRequest { ComponentType = 61, SolutionUniqueName = uniqueName, ComponentId = webResourceId }; client.Execute(scRequest); ExLogger.LogToFile(Logger, Resource.Message_NewWebResourceAddedSolution, LogLevel.Info); OutputLogger.WriteToOutputWindow(Resource.Message_NewWebResourceAddedSolution, MessageType.Info); return(true); } catch (Exception ex) { ExceptionHandler.LogException(Logger, Resource.ErrorMessage_ErrorAddingWebResourceSolution, ex); return(false); } }
public static bool UpdateCrmAssembly(CrmServiceClient client, CrmAssembly crmAssembly, string assebmlyPath) { try { Entity assembly = new Entity("pluginassembly") { Id = crmAssembly.AssemblyId, ["content"] = Convert.ToBase64String(CrmDeveloperExtensions2.Core.FileSystem.GetFileBytes(assebmlyPath)) }; client.Update(assembly); return(true); } catch (FaultException <OrganizationServiceFault> crmEx) { OutputLogger.WriteToOutputWindow( "Error Updating Assembly In CRM: " + crmEx.Message + Environment.NewLine + crmEx.StackTrace, MessageType.Error); return(false); } catch (Exception ex) { OutputLogger.WriteToOutputWindow( "Error Updating Assembly In CRM: " + ex.Message + Environment.NewLine + ex.StackTrace, MessageType.Error); return(false); } }
public static string EncodedImage(string filePath, FileExtensionType extension) { try { switch (extension) { case FileExtensionType.Ico: return(ImageEncoding.EncodeIco(filePath)); case FileExtensionType.Gif: case FileExtensionType.Jpg: case FileExtensionType.Png: return(ImageEncoding.EncodeImage(filePath, extension)); case FileExtensionType.Svg: return(ImageEncoding.EncodeSvg(filePath)); default: return(null); } } catch (Exception ex) { OutputLogger.WriteToOutputWindow(Resource.Error_ErrorEncodingImage, MessageType.Error); ExceptionHandler.LogException(Logger, Resource.Error_ErrorEncodingImage, ex); return(null); } }
public static void GetMetadata(CrmServiceClient client) { try { using (client) { RetrieveAllEntitiesRequest metaDataRequest = new RetrieveAllEntitiesRequest { EntityFilters = EntityFilters.Entity | EntityFilters.Attributes }; RetrieveAllEntitiesResponse metaDataResponse = (RetrieveAllEntitiesResponse)client.Execute(metaDataRequest); ProcessMetadata(metaDataResponse); } } catch (FaultException <OrganizationServiceFault> crmEx) { OutputLogger.WriteToOutputWindow( "Error Retrieving Metadata From CRM: " + crmEx.Message + Environment.NewLine + crmEx.StackTrace, MessageType.Error); } catch (Exception ex) { OutputLogger.WriteToOutputWindow( "Error Retrieving Metadata From CRM: " + ex.Message + Environment.NewLine + ex.StackTrace, MessageType.Error); } }
public static bool UpdateAndPublishSingle(CrmServiceClient client, List <Entity> webResources) { //CRM 2011 < UR12 try { OrganizationRequestCollection requests = CreateUpdateRequests(webResources); foreach (OrganizationRequest request in requests) { client.Execute(request); OutputLogger.WriteToOutputWindow(Resource.Message_UploadedWebResource, MessageType.Info); } string publishXml = CreatePublishXml(webResources); PublishXmlRequest publishRequest = CreatePublishRequest(publishXml); client.Execute(publishRequest); OutputLogger.WriteToOutputWindow(Resource.Message_PublishedWebResources, MessageType.Info); return(true); } catch (Exception ex) { ExceptionHandler.LogException(Logger, Resource.ErrorMessage_ErrorUpdatingPublishingWebResources, ex); return(false); } }
public static bool UpdateAndPublishSingle(CrmServiceClient client, List <Entity> webResources) { //CRM 2011 < UR12 try { OrganizationRequestCollection requests = CreateUpdateRequests(webResources); foreach (OrganizationRequest request in requests) { client.Execute(request); OutputLogger.WriteToOutputWindow("Uploaded Web Resource", MessageType.Info); } string publishXml = CreatePublishXml(webResources); PublishXmlRequest publishRequest = CreatePublishRequest(publishXml); client.Execute(publishRequest); OutputLogger.WriteToOutputWindow("Published Web Resource(s)", MessageType.Info); return(true); } catch (FaultException <OrganizationServiceFault> crmEx) { OutputLogger.WriteToOutputWindow("Error Updating And Publishing Web Resource(s) To CRM: " + crmEx.Message + Environment.NewLine + crmEx.StackTrace, MessageType.Error); return(false); } catch (Exception ex) { OutputLogger.WriteToOutputWindow("Error Updating And Publishing Web Resource(s) To CRM: " + ex.Message + Environment.NewLine + ex.StackTrace, MessageType.Error); return(false); } }
public static bool SetSolutionXmlVersion(Project project, Version newVersion) { try { bool isValid = ValidateSolutionXml(project); if (!isValid) { return(false); } Version oldVersion = GetSolutionXmlVersion(project); if (newVersion < oldVersion) { OutputLogger.WriteToOutputWindow("Unexpected error setting Solution.xml version: new version cannot be lower than old version", MessageType.Error); return(false); } string solutionXmlPath = GetSolutionXmlPath(project); XmlDocument doc = new XmlDocument(); doc.Load(solutionXmlPath); XmlNodeList versionNodes = doc.GetElementsByTagName("Version"); versionNodes[0].InnerText = newVersion.ToString(); doc.Save(solutionXmlPath); return(true); } catch (Exception ex) { OutputLogger.WriteToOutputWindow("Unexpected error setting Solution.xml version: " + ex.Message + Environment.NewLine + ex.StackTrace, MessageType.Error); return(false); } }
public void SolutionEventsOnBeforeClosing() { try { if (!(GetGlobalService(typeof(DTE)) is DTE dte)) { throw new ArgumentNullException(Core.Resources.Resource.ErrorMessage_ErrorAccessingDTE); } SharedGlobals.SetGlobal("UseCrmIntellisense", null, dte); if (SharedGlobals.GetGlobal("CrmService", dte) != null) { SharedGlobals.SetGlobal("CrmService", null, dte); } if (SharedGlobals.GetGlobal("CrmMetadata", dte) != null) { SharedGlobals.SetGlobal("CrmMetadata", null, dte); OutputLogger.WriteToOutputWindow("Clearing metadata", MessageType.Info); } } catch (Exception ex) { ExceptionHandler.LogException(Logger, null, ex); throw; } }
public static bool ImportSolution(CrmServiceClient client, string path) { var solutionBytes = FileSystem.GetFileBytes(path); if (solutionBytes == null) { return(false); } try { var request = new ImportSolutionRequest { CustomizationFile = solutionBytes, OverwriteUnmanagedCustomizations = true, PublishWorkflows = true, ImportJobId = Guid.NewGuid() }; client.Execute(request); ExLogger.LogToFile(Logger, $"{Resource.Message_ImportedSolution}: {path}", LogLevel.Info); OutputLogger.WriteToOutputWindow($"{Resource.Message_ImportedSolution}: {path}", MessageType.Info); return(true); } catch (Exception ex) { ExceptionHandler.LogException(Logger, Resource.ErrorMessage_ErrorImportingSolution, ex); return(false); } }
public static bool UpdateAndPublishMultiple(CrmServiceClient client, List <Entity> webResources) { //CRM 2011 UR12+ try { ExecuteMultipleRequest emRequest = new ExecuteMultipleRequest { Requests = new OrganizationRequestCollection(), Settings = new ExecuteMultipleSettings { ContinueOnError = false, ReturnResponses = true } }; emRequest.Requests = CreateUpdateRequests(webResources); string publishXml = CreatePublishXml(webResources); emRequest.Requests.Add(CreatePublishRequest(publishXml)); bool wasError = false; ExecuteMultipleResponse emResponse = (ExecuteMultipleResponse)client.Execute(emRequest); foreach (var responseItem in emResponse.Responses) { if (responseItem.Fault == null) { continue; } OutputLogger.WriteToOutputWindow( "Error Updating And Publishing Web Resource(s) To CRM: " + responseItem.Fault.Message + Environment.NewLine + responseItem.Fault.TraceText, MessageType.Error); wasError = true; } if (wasError) { return(false); } OutputLogger.WriteToOutputWindow("Updated And Published Web Resource(s)", MessageType.Info); return(true); } catch (FaultException <OrganizationServiceFault> crmEx) { OutputLogger.WriteToOutputWindow("Error Updating And Publishing Web Resource(s) To CRM: " + crmEx.Message + Environment.NewLine + crmEx.StackTrace, MessageType.Error); return(false); } catch (Exception ex) { OutputLogger.WriteToOutputWindow("Error Updating And Publishing Web Resource(s) To CRM: " + ex.Message + Environment.NewLine + ex.StackTrace, MessageType.Error); return(false); } }
public static void LogProcessError(Logger logger, string message, string errorDataReceived) { string output = FormatProcessErrorOutput(message, errorDataReceived); ExtensionLogger.LogToFile(logger, output, LogLevel.Error); OutputLogger.WriteToOutputWindow(output, MessageType.Error); }
public static void LogCrmConnectionError(Logger logger, string message, CrmConnectionManager crmConnectionManager) { string output = FormatCrmConnectionErrorOutput(crmConnectionManager); ExtensionLogger.LogToFile(logger, output, LogLevel.Error); OutputLogger.WriteToOutputWindow(output, MessageType.Error); }
public static void LogException(Logger logger, string message, Exception ex) { string output = FormatExceptionOutput(message, ex); ExtensionLogger.LogToFile(logger, output, LogLevel.Error); OutputLogger.WriteToOutputWindow(output, MessageType.Error); }
public void WriteLine(string format, params object[] args) { if (format == null) { return; } OutputLogger.WriteToOutputWindow(string.Format(format, args), MessageType.Info); }
public static List <Guid> DeletePluginTracesFromCrm(CrmServiceClient client, Guid[] pluginTraceLogIds) { List <Guid> deletedPluginTraceLogIds = new List <Guid>(); try { ExecuteMultipleRequest executeMultipleRequest = new ExecuteMultipleRequest { Requests = new OrganizationRequestCollection(), Settings = new ExecuteMultipleSettings { ContinueOnError = true, ReturnResponses = true } }; foreach (Guid pluginTraceLogId in pluginTraceLogIds) { DeleteRequest request = new DeleteRequest { Target = new EntityReference("plugintracelog", pluginTraceLogId) }; executeMultipleRequest.Requests.Add(request); } ExecuteMultipleResponse executeMultipleResponse = (ExecuteMultipleResponse)client.Execute(executeMultipleRequest); foreach (var responseItem in executeMultipleResponse.Responses) { if (responseItem.Response != null) { deletedPluginTraceLogIds.Add(pluginTraceLogIds[responseItem.RequestIndex]); continue; } if (responseItem.Fault != null) { OutputLogger.WriteToOutputWindow( "Error Deleting Plug-in Trace Log From CRM: " + responseItem.Fault, MessageType.Error); } } } catch (FaultException <OrganizationServiceFault> crmEx) { OutputLogger.WriteToOutputWindow( "Error Deleting Plug-in Trace Log(s) From CRM: " + crmEx.Message + Environment.NewLine + crmEx.StackTrace, MessageType.Error); } catch (Exception ex) { OutputLogger.WriteToOutputWindow( "Error Deleting Plug-in Trace Log(s) From CRM: " + ex.Message + Environment.NewLine + ex.StackTrace, MessageType.Error); } return(deletedPluginTraceLogIds); }
public static EntityCollection RetrieveSolutionsFromCrm(CrmServiceClient client) { try { QueryExpression query = new QueryExpression { EntityName = "solution", ColumnSet = new ColumnSet("friendlyname", "solutionid", "uniquename"), Criteria = new FilterExpression { Conditions = { new ConditionExpression { AttributeName = "isvisible", Operator = ConditionOperator.Equal, Values = { true } }, new ConditionExpression { AttributeName = "ismanaged", Operator = ConditionOperator.Equal, Values = { false } } } }, Orders = { new OrderExpression { AttributeName = "friendlyname", OrderType = OrderType.Ascending } } }; EntityCollection solutions = client.RetrieveMultiple(query); return(solutions); } catch (FaultException <OrganizationServiceFault> crmEx) { OutputLogger.WriteToOutputWindow( "Error Retrieving Solutions From CRM: " + crmEx.Message + Environment.NewLine + crmEx.StackTrace, MessageType.Error); return(null); } catch (Exception ex) { OutputLogger.WriteToOutputWindow( "Error Retrieving Solutions From CRM: " + ex.Message + Environment.NewLine + ex.StackTrace, MessageType.Error); return(null); } }
public static bool UpdateAndPublishMultiple(CrmServiceClient client, List <Entity> webResources) { //CRM 2011 UR12+ try { var emRequest = new ExecuteMultipleRequest { Requests = new OrganizationRequestCollection(), Settings = new ExecuteMultipleSettings { ContinueOnError = false, ReturnResponses = true } }; emRequest.Requests = CreateUpdateRequests(webResources); var publishXml = CreatePublishXml(webResources); emRequest.Requests.Add(CreatePublishRequest(publishXml)); var wasError = false; var emResponse = (ExecuteMultipleResponse)client.Execute(emRequest); foreach (var responseItem in emResponse.Responses) { if (responseItem.Fault == null) { continue; } ExLogger.LogToFile(Logger, Resource.ErrorMessage_ErrorUpdatingPublishingWebResources, LogLevel.Info); OutputLogger.WriteToOutputWindow(Resource.ErrorMessage_ErrorUpdatingPublishingWebResources, MessageType.Error); wasError = true; } if (wasError) { return(false); } ExLogger.LogToFile(Logger, Resource.Message_UpdatedPublishedWebResources, LogLevel.Info); OutputLogger.WriteToOutputWindow(Resource.Message_UpdatedPublishedWebResources, MessageType.Info); return(true); } catch (Exception ex) { ExceptionHandler.LogException(Logger, Resource.ErrorMessage_ErrorUpdatingPublishingWebResources, ex); return(false); } }
public static void RenameFile(string path) { try { File.Move(path, $"{path}.{DateTime.Now:MMddyyyyHHmmss}"); } catch (Exception ex) { ExceptionHandler.LogException(Logger, $"{Resource.ErrorMessage_UnableRenameFile}: {path}", ex); OutputLogger.WriteToOutputWindow(Resource.ErrorMessage_UnableRenameFile, MessageType.Error); throw; } }
public static string GetFileText(string path) { try { return(File.ReadAllText(path)); } catch (Exception ex) { ExceptionHandler.LogException(Logger, $"{Resource.ErrorMessage_ReadFile}: {path}", ex); OutputLogger.WriteToOutputWindow(Resource.ErrorMessage_ReadFile, MessageType.Error); return(null); } }
private static void ToggleCrmIntellisense(object sender, EventArgs e, DTE dte) { bool isEnabled; var value = SharedGlobals.GetGlobal("UseCrmIntellisense", dte); if (value == null) { isEnabled = false; SharedGlobals.SetGlobal("UseCrmIntellisense", true, dte); } else { isEnabled = (bool)value; SharedGlobals.SetGlobal("UseCrmIntellisense", !isEnabled, dte); } ExLogger.LogToFile(Logger, $"{Resource.Message_CRMIntellisenseEnabled}: {!isEnabled}", LogLevel.Info); if (!isEnabled) //On { if (HostWindow.IsCrmDexWindowOpen(dte) && SharedGlobals.GetGlobal("CrmService", dte) != null) { return; } } else { if (!HostWindow.IsCrmDexWindowOpen(dte) && SharedGlobals.GetGlobal("CrmService", dte) != null) { SharedGlobals.SetGlobal("CrmService", null, dte); } CrmMetadata.Metadata = null; SharedGlobals.SetGlobal("CrmMetadata", null, dte); ExLogger.LogToFile(Logger, Resource.Message_ClearingMetadata, LogLevel.Info); OutputLogger.WriteToOutputWindow(Resource.Message_ClearingMetadata, MessageType.Info); return; } var result = MessageBox.Show(Resource.MessageBox_ConnectToCrm, Resource.MessageBox_ConnectToCrm_Title, MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.Yes); if (result != MessageBoxResult.Yes) { return; } ConnectToCrm(); }
public static string GetProjectPath(Project project) { string path = project.FullName; path = Path.GetDirectoryName(path); if (!string.IsNullOrEmpty(path)) { return(path); } OutputLogger.WriteToOutputWindow(Resource.ErrorMessage_ErrorGetProjectPath, MessageType.Error); return(null); }
public static string GetProjectPath(Project project) { string path = project.FullName; path = Path.GetDirectoryName(path); if (string.IsNullOrEmpty(path)) { OutputLogger.WriteToOutputWindow("Unable to get path from project", MessageType.Error); return(null); } return(path); }