private async void mIOpenDependentComponentsInWeb_Click(object sender, RoutedEventArgs e) { var entity = GetSelectedEntity(); if (entity == null) { return; } var service = await GetService(); var descriptor = GetDescriptor(service); var solutionComponents = await descriptor.GetSolutionComponentsListAsync(new[] { entity }); if (!solutionComponents.Any()) { _iWriteToOutput.WriteToOutput(service.ConnectionData, Properties.OutputStrings.SolutionComponentNotFoundInConnectionFormat1, service.ConnectionData.Name); _iWriteToOutput.ActivateOutputWindow(service.ConnectionData); return; } foreach (var item in solutionComponents) { service.ConnectionData.OpenSolutionComponentDependentComponentsInWeb((ComponentType)item.ComponentType.Value, item.ObjectId.Value); } }
private async void btnSaveEntity_Click(object sender, RoutedEventArgs e) { var updateEntity = new Entity(_entityName); var list = _listAttributeControls.OfType <IAttributeMetadataControl <AttributeMetadata> >().ToList(); foreach (var item in list) { item.AddChangedAttribute(updateEntity); } if (!updateEntity.Attributes.Any()) { _iWriteToOutput.WriteToOutput(_service.ConnectionData, Properties.OutputStrings.NoChangesInEntityFormat1, _entityName); _iWriteToOutput.ActivateOutputWindow(_service.ConnectionData); return; } if (_entityId != Guid.Empty) { updateEntity.Id = _entityId; } ToggleControls(false, Properties.WindowStatusStrings.SavingEntityFormat1, _entityName); if (_entityInstance != null) { _iWriteToOutput.WriteToOutputEntityInstance(_service.ConnectionData, _entityInstance); } try { var saver = new EntitySaverFactory().GetEntitySaver(_entityName, _service); var tempEntityId = await saver.UpsertAsync(updateEntity, (s) => UpdateStatus(s)); _iWriteToOutput.WriteToOutputEntityInstance(_service.ConnectionData, _entityName, tempEntityId); ToggleControls(true, Properties.WindowStatusStrings.SavingEntityCompletedFormat1, _entityName); this.Close(); } catch (Exception ex) { ToggleControls(true, Properties.WindowStatusStrings.SavingEntityFailedFormat1, _entityName); _iWriteToOutput.WriteErrorToOutput(_service.ConnectionData, ex); } }
private async Task PerformDeleteEntity(string folder, Guid idPluginType, string name) { string message = string.Format(Properties.MessageBoxStrings.AreYouSureDeleteSdkObjectFormat2, PluginType.EntityLogicalName, name); if (MessageBox.Show(message, Properties.MessageBoxStrings.QuestionTitle, MessageBoxButton.OKCancel, MessageBoxImage.Question) == MessageBoxResult.OK) { var service = await GetService(); ToggleControls(service.ConnectionData, false, Properties.WindowStatusStrings.DeletingEntitiesFormat2, service.ConnectionData.Name, PluginType.EntityLogicalName); try { _iWriteToOutput.WriteToOutput(service.ConnectionData, Properties.OutputStrings.DeletingEntity); _iWriteToOutput.WriteToOutputEntityInstance(service.ConnectionData, PluginType.EntityLogicalName, idPluginType); await service.DeleteAsync(PluginType.EntityLogicalName, idPluginType); } catch (Exception ex) { _iWriteToOutput.WriteErrorToOutput(service.ConnectionData, ex); _iWriteToOutput.ActivateOutputWindow(service.ConnectionData); } ToggleControls(service.ConnectionData, true, Properties.WindowStatusStrings.DeletingEntitiesCompletedFormat2, service.ConnectionData.Name, PluginType.EntityLogicalName); ShowExistingPluginTypes(); } }
private async Task PerformSaveClick() { var imageType = GetImageType(); this.Image.Name = txtBName.Text.Trim(); this.Image.EntityAlias = txtBEntityAlias.Text.Trim(); this.Image.MessagePropertyName = cmBMessagePropertyName.Text?.Trim() ?? string.Empty; this.Image.RelatedAttributeName = txtBRelatedAttributeName.Text.Trim(); this.Image.Description = txtBDescription.Text.Trim(); this.Image.Attributes1 = txtBAttributes.Text.Trim(); this.Image.ImageType = new OptionSetValue(imageType); ToggleControls(false, Properties.WindowStatusStrings.UpdatingSdkMessageProcessingStepImageFormat1, _service.ConnectionData.Name); try { this.Image.Id = await _service.UpsertAsync(this.Image); ToggleControls(true, Properties.WindowStatusStrings.UpdatingSdkMessageProcessingStepImageCompletedFormat1, _service.ConnectionData.Name); this.DialogResult = true; this.Close(); } catch (Exception ex) { ToggleControls(true, Properties.WindowStatusStrings.UpdatingSdkMessageProcessingStepImageFailedFormat1, _service.ConnectionData.Name); _iWriteToOutput.WriteErrorToOutput(_service.ConnectionData, ex); _iWriteToOutput.ActivateOutputWindow(_service.ConnectionData); } }
private static async Task <bool> TestConnect(ConnectionData connectionData, IWriteToOutput iWriteToOutput) { iWriteToOutput.ActivateOutputWindow(connectionData); iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.ConnectingToCRM); iWriteToOutput.WriteToOutput(connectionData, connectionData.GetConnectionDescription()); try { var service = ConnectInternal( connectionData , true , out OrganizationDetail organizationDetail ); if (service != null) { { WhoAmIResponse whoresponse = (WhoAmIResponse)service.Execute(new WhoAmIRequest()); iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.WhoAmIRequestExecutedSuccessfully); iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.QuickConnectionOrganizationIdFormat1, whoresponse.OrganizationId); iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.QuickConnectionBusinessUnitIdFormat1, whoresponse.BusinessUnitId); iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.QuickConnectionUserIdFormat1, whoresponse.UserId); } var result = new OrganizationServiceExtentedProxy(service, connectionData); await LoadOrganizationDataAsync(result, organizationDetail); iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.CurrentServiceEndpointFormat1, result.CurrentServiceEndpoint); iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.SuccessfullyConnectedFormat1, connectionData.Name); return(true); } else { iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.ConnectionFailedFormat1, connectionData.Name); return(false); } } catch (Exception ex) { iWriteToOutput.WriteErrorToOutput(connectionData, ex); iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.ConnectionFailedFormat1, connectionData.Name); return(false); } }
private static async Task <bool> TestConnect(ConnectionData connectionData, IWriteToOutput iWriteToOutput, System.Windows.Window window) { iWriteToOutput.ActivateOutputWindow(connectionData, window); iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.ConnectingToCRM); iWriteToOutput.WriteToOutput(connectionData, connectionData.GetConnectionDescription()); try { var connectionResult = await ConnectInternal(connectionData, true); OrganizationServiceProxy serviceProxy = connectionResult.Item1; OrganizationDetail organizationDetail = connectionResult.Item2; string currentServiceEndpoint = GetServiceManagementEndpoint(connectionData.ConnectionId); if (serviceProxy != null) { using (var serviceProxyExt = new OrganizationServiceExtentedProxy(serviceProxy, connectionData, currentServiceEndpoint)) { var whoAmIResponse = await serviceProxyExt.ExecuteAsync <WhoAmIResponse>(new WhoAmIRequest()); iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.WhoAmIRequestExecutedSuccessfully); iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.QuickConnectionOrganizationIdFormat1, whoAmIResponse.OrganizationId); iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.QuickConnectionBusinessUnitIdFormat1, whoAmIResponse.BusinessUnitId); iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.QuickConnectionUserIdFormat1, whoAmIResponse.UserId); await LoadOrganizationDataAsync(serviceProxyExt, organizationDetail, whoAmIResponse); iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.CurrentServiceEndpointFormat1, serviceProxyExt.CurrentServiceEndpoint); } iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.SuccessfullyConnectedFormat1, connectionData.Name); return(true); } else { iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.ConnectionFailedFormat1, connectionData.Name); return(false); } } catch (Exception ex) { iWriteToOutput.WriteErrorToOutput(connectionData, ex); iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.ConnectionFailedFormat1, connectionData.Name); return(false); } }
private static bool ValidateXmlDocument(ConnectionData connectionData, IWriteToOutput iWriteToOutput, XDocument doc) { ContentComparerHelper.ClearRoot(doc); XmlSchemaSet schemas = new XmlSchemaSet(); { var schemasResources = AbstractDynamicCommandXsdSchemas.GetXsdSchemas(AbstractDynamicCommandXsdSchemas.WebResourceDependencyXmlSchema); if (schemasResources != null) { foreach (var fileName in schemasResources) { Uri uri = FileOperations.GetSchemaResourceUri(fileName); StreamResourceInfo info = Application.GetResourceStream(uri); using (StreamReader reader = new StreamReader(info.Stream)) { schemas.Add(string.Empty, XmlReader.Create(reader)); } } } } List <ValidationEventArgs> errors = new List <ValidationEventArgs>(); doc.Validate(schemas, (o, e) => { errors.Add(e); }); if (errors.Count > 0) { iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.TextIsNotValidForFieldFormat1, AbstractDynamicCommandXsdSchemas.WebResourceDependencyXmlSchema); foreach (var item in errors) { iWriteToOutput.WriteToOutput(connectionData, string.Empty); iWriteToOutput.WriteToOutput(connectionData, string.Empty); iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.XmlValidationMessageFormat2, item.Severity, item.Message); iWriteToOutput.WriteErrorToOutput(connectionData, item.Exception); } iWriteToOutput.ActivateOutputWindow(connectionData); } return(errors.Count == 0); }
private async Task PerformExportApplicationRibbonDiffXml() { if (!this.IsControlsEnabled) { return; } var service = await GetService(); this._iWriteToOutput.WriteToOutputStartOperation(service.ConnectionData, Properties.OperationNames.ExportingApplicationRibbonDiffXmlFormat1, service.ConnectionData.Name); ToggleControls(service.ConnectionData, false, Properties.WindowStatusStrings.ExportingApplicationRibbonDiffXml); var repositoryPublisher = new PublisherRepository(service); var publisherDefault = await repositoryPublisher.GetDefaultPublisherAsync(); if (publisherDefault == null) { ToggleControls(service.ConnectionData, true, Properties.WindowStatusStrings.NotFoundedDefaultPublisher); _iWriteToOutput.ActivateOutputWindow(service.ConnectionData); return; } var repositoryRibbonCustomization = new RibbonCustomizationRepository(service); var ribbonCustomization = await repositoryRibbonCustomization.FindApplicationRibbonCustomizationAsync(); if (ribbonCustomization == null) { ToggleControls(service.ConnectionData, true, Properties.WindowStatusStrings.NotFoundedApplicationRibbonRibbonCustomization); _iWriteToOutput.ActivateOutputWindow(service.ConnectionData); return; } try { string ribbonDiffXml = await repositoryRibbonCustomization.GetRibbonDiffXmlAsync(_iWriteToOutput, null, ribbonCustomization); if (string.IsNullOrEmpty(ribbonDiffXml)) { ToggleControls(service.ConnectionData, true, Properties.WindowStatusStrings.ExportingApplicationRibbonDiffXmlFailed); return; } ribbonDiffXml = ContentCoparerHelper.FormatXmlByConfiguration(ribbonDiffXml, _commonConfig, _xmlOptions , schemaName: AbstractDynamicCommandXsdSchemas.SchemaRibbonXml , ribbonEntityName: string.Empty ); { string fileName = EntityFileNameFormatter.GetApplicationRibbonDiffXmlFileName(service.ConnectionData.Name); string filePath = Path.Combine(_commonConfig.FolderForExport, FileOperations.RemoveWrongSymbols(fileName)); File.WriteAllText(filePath, ribbonDiffXml, new UTF8Encoding(false)); this._iWriteToOutput.WriteToOutput(service.ConnectionData, Properties.OutputStrings.ExportedAppliationRibbonDiffXmlForConnectionFormat2, service.ConnectionData.Name, filePath); this._iWriteToOutput.PerformAction(service.ConnectionData, filePath); } ToggleControls(service.ConnectionData, true, Properties.WindowStatusStrings.ExportingApplicationRibbonDiffXmlCompleted); } catch (Exception ex) { this._iWriteToOutput.WriteErrorToOutput(service.ConnectionData, ex); ToggleControls(service.ConnectionData, true, Properties.WindowStatusStrings.ExportingApplicationRibbonDiffXmlFailed); } this._iWriteToOutput.WriteToOutputEndOperation(service.ConnectionData, Properties.OperationNames.ExportingApplicationRibbonDiffXmlFormat1, service.ConnectionData.Name); }
private void tSBLoadFromFile_Click(object sender, RoutedEventArgs e) { if (!IsControlsEnabled) { return; } string selectedPath = string.Empty; var t = new Thread(() => { try { var openFileDialog1 = new Microsoft.Win32.OpenFileDialog { Filter = "ConnectionData (.xml)|*.xml", FilterIndex = 1, RestoreDirectory = true }; if (openFileDialog1.ShowDialog().GetValueOrDefault()) { selectedPath = openFileDialog1.FileName; } } catch (Exception ex) { _iWriteToOutput.WriteErrorToOutput(null, ex); _iWriteToOutput.ActivateOutputWindow(null, this); } }); t.SetApartmentState(ApartmentState.STA); t.Start(); t.Join(); if (string.IsNullOrEmpty(selectedPath)) { return; } ConnectionData connectionData = null; try { connectionData = ConnectionData.GetFromPath(selectedPath); } catch (Exception ex) { _iWriteToOutput.WriteErrorToOutput(null, ex); _iWriteToOutput.ActivateOutputWindow(null, this); connectionData = null; } if (connectionData == null) { return; } connectionData.User = this._crmConfig.Users.FirstOrDefault(u => u.UserId == connectionData.UserId); if (this._crmConfig.Connections.Any(c => c.ConnectionId == connectionData.ConnectionId) || this._crmConfig.ArchiveConnections.Any(c => c.ConnectionId == connectionData.ConnectionId) || connectionData.ConnectionId == Guid.Empty ) { connectionData.ConnectionId = Guid.NewGuid(); } var form = new WindowCrmConnectionCard(_iWriteToOutput, connectionData, _crmConfig.Users); if (form.ShowDialog().GetValueOrDefault()) { this.Dispatcher.Invoke(() => { connectionData.Save(); connectionData.ConnectionConfiguration = this._crmConfig; connectionData.LoadIntellisenseAsync(); connectionData.StartWatchFile(); this._crmConfig.Connections.Add(connectionData); }); } UpdateCurrentConnectionInfo(); this._crmConfig.Save(); }
public async Task <string> GetRibbonDiffXmlAsync(IWriteToOutput iWriteToOutput, EntityMetadata entityMetadata, RibbonCustomization ribbonCustomization) { if (entityMetadata == null && ribbonCustomization == null) { throw new ArgumentException("entityMetadata or ribbonCustomization"); } Publisher publisherDefault = null; { var repositoryPublisher = new PublisherRepository(_service); publisherDefault = await repositoryPublisher.GetDefaultPublisherAsync(); if (publisherDefault == null) { iWriteToOutput.WriteToOutput(_service.ConnectionData, Properties.OutputStrings.NotFoundedDefaultPublisher); iWriteToOutput.ActivateOutputWindow(_service.ConnectionData); return(null); } } var idSolution = Guid.NewGuid(); var solutionUniqueName = string.Format("RibbonDiffXml_{0}", idSolution); solutionUniqueName = solutionUniqueName.Replace("-", "_"); var solution = new Solution() { UniqueName = solutionUniqueName, FriendlyName = solutionUniqueName, SolutionId = idSolution, Description = "Temporary solution for exporting RibbonDiffXml.", PublisherId = publisherDefault.ToEntityReference(), Version = "1.0.0.0", }; iWriteToOutput.WriteToOutput(_service.ConnectionData, Properties.OutputStrings.CreatingNewSolutionFormat1, solutionUniqueName); solution.Id = await _service.CreateAsync(solution); iWriteToOutput.WriteToOutputSolutionUri(_service.ConnectionData, solution.UniqueName, solution.Id); try { var repositorySolutionComponent = new SolutionComponentRepository(_service); if (entityMetadata != null) { iWriteToOutput.WriteToOutput(_service.ConnectionData, Properties.OutputStrings.InConnectionAddingInSolutionEntityFormat3, _service.ConnectionData.Name, solutionUniqueName, entityMetadata.LogicalName); await repositorySolutionComponent.AddSolutionComponentsAsync(solutionUniqueName, new[] { new SolutionComponent() { ComponentType = new OptionSetValue((int)ComponentType.Entity), ObjectId = entityMetadata.MetadataId.Value, RootComponentBehaviorEnum = SolutionComponent.Schema.OptionSets.rootcomponentbehavior.Include_Subcomponents_0, } }); iWriteToOutput.WriteToOutput(_service.ConnectionData, Properties.OutputStrings.ExportingSolutionAndExtractingRibbonDiffXmlForEntityFormat2, solutionUniqueName, entityMetadata.LogicalName); } else if (ribbonCustomization != null) { iWriteToOutput.WriteToOutput(_service.ConnectionData, Properties.OutputStrings.InConnectionAddingInSolutionApplicationRibbonFormat2, _service.ConnectionData.Name, solutionUniqueName); await repositorySolutionComponent.AddSolutionComponentsAsync(solutionUniqueName, new[] { new SolutionComponent() { ComponentType = new OptionSetValue((int)ComponentType.RibbonCustomization), ObjectId = ribbonCustomization.Id, RootComponentBehaviorEnum = SolutionComponent.Schema.OptionSets.rootcomponentbehavior.Include_Subcomponents_0, } }); iWriteToOutput.WriteToOutput(_service.ConnectionData, Properties.OutputStrings.ExportingSolutionAndExtractingApplicationRibbonDiffXmlFormat1, solutionUniqueName); } var repositoryExportSolution = new ExportSolutionHelper(_service); var solutionBodyBinary = await repositoryExportSolution.ExportSolutionAndGetBodyBinaryAsync(solutionUniqueName); string ribbonDiffXml = null; if (entityMetadata != null) { ribbonDiffXml = ExportSolutionHelper.GetRibbonDiffXmlForEntityFromSolutionBody(entityMetadata.LogicalName, solutionBodyBinary); } else if (ribbonCustomization != null) { ribbonDiffXml = ExportSolutionHelper.GetApplicationRibbonDiffXmlFromSolutionBody(solutionBodyBinary); } return(ribbonDiffXml); } finally { var task = DeleteSolution(iWriteToOutput, solution); } }
public async Task PerformUpdateRibbonDiffXml(IWriteToOutput iWriteToOutput, CommonConfiguration commonConfig, XDocument doc, EntityMetadata entityMetadata, RibbonCustomization ribbonCustomization) { if (entityMetadata == null && ribbonCustomization == null) { throw new ArgumentException("entityMetadata or ribbonCustomization"); } ContentComparerHelper.ClearRoot(doc); Publisher publisherDefault = null; { var repositoryPublisher = new PublisherRepository(_service); publisherDefault = await repositoryPublisher.GetDefaultPublisherAsync(); if (publisherDefault == null) { iWriteToOutput.WriteToOutput(_service.ConnectionData, Properties.OutputStrings.NotFoundedDefaultPublisher); iWriteToOutput.ActivateOutputWindow(_service.ConnectionData); return; } } var idSolution = Guid.NewGuid(); var solutionUniqueName = string.Format("RibbonDiffXml_{0}", idSolution); solutionUniqueName = solutionUniqueName.Replace("-", "_"); var solution = new Solution() { UniqueName = solutionUniqueName, FriendlyName = solutionUniqueName, SolutionId = idSolution, Description = "Temporary solution for exporting RibbonDiffXml.", PublisherId = publisherDefault.ToEntityReference(), Version = "1.0.0.0", }; iWriteToOutput.WriteToOutput(_service.ConnectionData, Properties.OutputStrings.CreatingNewSolutionFormat1, solutionUniqueName); solution.Id = await _service.CreateAsync(solution); iWriteToOutput.WriteToOutputSolutionUri(_service.ConnectionData, solution.UniqueName, solution.Id); try { if (entityMetadata != null) { iWriteToOutput.WriteToOutput(_service.ConnectionData, Properties.OutputStrings.InConnectionAddingInSolutionEntityFormat3, _service.ConnectionData.Name, solutionUniqueName, entityMetadata.LogicalName); { var repositorySolutionComponent = new SolutionComponentRepository(_service); await repositorySolutionComponent.AddSolutionComponentsAsync(solutionUniqueName, new[] { new SolutionComponent() { ComponentType = new OptionSetValue((int)ComponentType.Entity), ObjectId = entityMetadata.MetadataId.Value, RootComponentBehaviorEnum = SolutionComponent.Schema.OptionSets.rootcomponentbehavior.Include_Subcomponents_0, } }); } iWriteToOutput.WriteToOutput(_service.ConnectionData, Properties.OutputStrings.ExportingSolutionAndExtractingRibbonDiffXmlForEntityFormat2, solutionUniqueName, entityMetadata.LogicalName); } else if (ribbonCustomization != null) { iWriteToOutput.WriteToOutput(_service.ConnectionData, Properties.OutputStrings.InConnectionAddingInSolutionApplicationRibbonFormat2, _service.ConnectionData.Name, solutionUniqueName); { var repositorySolutionComponent = new SolutionComponentRepository(_service); await repositorySolutionComponent.AddSolutionComponentsAsync(solutionUniqueName, new[] { new SolutionComponent() { ComponentType = new OptionSetValue((int)ComponentType.RibbonCustomization), ObjectId = ribbonCustomization.Id, RootComponentBehaviorEnum = SolutionComponent.Schema.OptionSets.rootcomponentbehavior.Include_Subcomponents_0, } }); } iWriteToOutput.WriteToOutput(_service.ConnectionData, Properties.OutputStrings.ExportingSolutionAndExtractingApplicationRibbonDiffXmlFormat1, solutionUniqueName); } string header = (entityMetadata != null) ? entityMetadata.LogicalName : "ApplicationRibbon"; var repository = new ExportSolutionHelper(_service); var solutionBodyBinary = await repository.ExportSolutionAndGetBodyBinaryAsync(solutionUniqueName); { string fileName = EntityFileNameFormatter.GetSolutionFileName(_service.ConnectionData.Name, solution.UniqueName, $"{header} Solution Backup", FileExtension.zip); string filePath = Path.Combine(commonConfig.FolderForExport, FileOperations.RemoveWrongSymbols(fileName)); File.WriteAllBytes(filePath, solutionBodyBinary); iWriteToOutput.WriteToOutput(_service.ConnectionData, "Solution {0} Backup exported to {1}", solution.UniqueName, filePath); iWriteToOutput.WriteToOutputFilePathUri(_service.ConnectionData, filePath); } string ribbonDiffXml = string.Empty; if (entityMetadata != null) { ribbonDiffXml = ExportSolutionHelper.GetRibbonDiffXmlForEntityFromSolutionBody(entityMetadata.LogicalName, solutionBodyBinary); } else if (ribbonCustomization != null) { ribbonDiffXml = ExportSolutionHelper.GetApplicationRibbonDiffXmlFromSolutionBody(solutionBodyBinary); } ribbonDiffXml = ContentComparerHelper.FormatXmlByConfiguration( ribbonDiffXml , commonConfig , XmlOptionsControls.RibbonXmlOptions , schemaName: AbstractDynamicCommandXsdSchemas.RibbonSchema , entityName: entityMetadata?.LogicalName ?? string.Empty ); { string filePath = string.Empty; if (entityMetadata != null) { string fileName = EntityFileNameFormatter.GetEntityRibbonDiffXmlFileName(_service.ConnectionData.Name, entityMetadata.LogicalName, "BackUp", FileExtension.xml); filePath = Path.Combine(commonConfig.FolderForExport, FileOperations.RemoveWrongSymbols(fileName)); iWriteToOutput.WriteToOutput(_service.ConnectionData, "{0} RibbonDiffXml BackUp exported to {1}", entityMetadata.LogicalName, filePath); } else if (ribbonCustomization != null) { string fileName = EntityFileNameFormatter.GetApplicationRibbonDiffXmlFileName(_service.ConnectionData.Name, "BackUp", FileExtension.xml); filePath = Path.Combine(commonConfig.FolderForExport, FileOperations.RemoveWrongSymbols(fileName)); iWriteToOutput.WriteToOutput(_service.ConnectionData, "Application RibbonDiffXml BackUp exported to {0}", filePath); } File.WriteAllText(filePath, ribbonDiffXml, new UTF8Encoding(false)); iWriteToOutput.WriteToOutputFilePathUri(_service.ConnectionData, filePath); } if (entityMetadata != null) { solutionBodyBinary = ExportSolutionHelper.ReplaceRibbonDiffXmlForEntityInSolutionBody(entityMetadata.LogicalName, solutionBodyBinary, doc.Root); } else if (ribbonCustomization != null) { solutionBodyBinary = ExportSolutionHelper.ReplaceApplicationRibbonDiffXmlInSolutionBody(solutionBodyBinary, doc.Root); } { string fileName = EntityFileNameFormatter.GetSolutionFileName(_service.ConnectionData.Name, solution.UniqueName, $"{header} Changed Solution Backup", FileExtension.zip); string filePath = Path.Combine(commonConfig.FolderForExport, FileOperations.RemoveWrongSymbols(fileName)); File.WriteAllBytes(filePath, solutionBodyBinary); iWriteToOutput.WriteToOutput(_service.ConnectionData, "Changed Solution {0} Backup exported to {1}", solution.UniqueName, filePath); iWriteToOutput.WriteToOutputFilePathUri(_service.ConnectionData, filePath); } iWriteToOutput.WriteToOutput(_service.ConnectionData, Properties.OutputStrings.ImportingSolutionFormat1, solutionUniqueName); await repository.ImportSolutionAsync(solutionBodyBinary); await DeleteSolution(iWriteToOutput, solution); { var repositoryPublish = new PublishActionsRepository(_service); if (entityMetadata != null) { iWriteToOutput.WriteToOutput(_service.ConnectionData, Properties.OutputStrings.InConnectionPublishingEntitiesFormat2, _service.ConnectionData.Name, entityMetadata.LogicalName); await repositoryPublish.PublishEntitiesAsync(new[] { entityMetadata.LogicalName }); } else if (ribbonCustomization != null) { iWriteToOutput.WriteToOutput(_service.ConnectionData, Properties.OutputStrings.InConnectionPublishingApplicationRibbonFormat1, _service.ConnectionData.Name); await repositoryPublish.PublishApplicationRibbonAsync(); } } } finally { var task = DeleteSolution(iWriteToOutput, solution); } }
private async Task PerformUpdateEntityField(string folder, Guid idCustomControl, string name, string fieldName, string fieldTitle, string extension) { if (!this.IsControlsEnabled) { return; } var service = await GetService(); ToggleControls(service.ConnectionData, false, Properties.WindowStatusStrings.UpdatingFieldFormat2, service.ConnectionData.Name, fieldName); try { var repository = new CustomControlRepository(service); var customControl = await repository.GetByIdAsync(idCustomControl, new ColumnSet(fieldName)); string xmlContent = customControl.GetAttributeValue <string>(fieldName); if (string.Equals(fieldName, CustomControl.Schema.Attributes.manifest, StringComparison.InvariantCultureIgnoreCase)) { if (ContentCoparerHelper.TryParseXml(xmlContent, out var tempDoc)) { xmlContent = tempDoc.ToString(); } } else if (string.Equals(fieldName, CustomControl.Schema.Attributes.clientjson, StringComparison.InvariantCultureIgnoreCase)) { xmlContent = ContentCoparerHelper.FormatJson(xmlContent); } { string backUpXmlContent = xmlContent; if (string.Equals(fieldName, CustomControl.Schema.Attributes.manifest, StringComparison.InvariantCultureIgnoreCase)) { backUpXmlContent = ContentCoparerHelper.FormatXmlByConfiguration(backUpXmlContent, _commonConfig, _xmlOptions , schemaName: AbstractDynamicCommandXsdSchemas.SchemaManifest , customControlId: idCustomControl ); } else if (string.Equals(fieldName, CustomControl.Schema.Attributes.clientjson, StringComparison.InvariantCultureIgnoreCase)) { backUpXmlContent = ContentCoparerHelper.FormatJson(backUpXmlContent); } await CreateFileAsync(folder, idCustomControl, name, fieldTitle + " BackUp", extension, backUpXmlContent); } var newText = string.Empty; bool?dialogResult = false; this.Dispatcher.Invoke(() => { var form = new WindowTextField("Enter " + fieldTitle, fieldTitle, xmlContent); dialogResult = form.ShowDialog(); newText = form.FieldText; }); if (dialogResult.GetValueOrDefault() == false) { ToggleControls(service.ConnectionData, true, Properties.WindowStatusStrings.UpdatingFieldCanceledFormat2, service.ConnectionData.Name, fieldName); return; } newText = ContentCoparerHelper.RemoveAllCustomXmlAttributesAndNamespaces(newText); UpdateStatus(service.ConnectionData, Properties.WindowStatusStrings.ValidatingXmlForFieldFormat1, fieldName); if (!ContentCoparerHelper.TryParseXmlDocument(newText, out var doc)) { ToggleControls(service.ConnectionData, true, Properties.WindowStatusStrings.TextIsNotValidXml); _iWriteToOutput.ActivateOutputWindow(service.ConnectionData); return; } newText = doc.ToString(SaveOptions.DisableFormatting); var updateEntity = new CustomControl { Id = idCustomControl }; updateEntity.Attributes[fieldName] = newText; await service.UpdateAsync(updateEntity); ToggleControls(service.ConnectionData, true, Properties.WindowStatusStrings.UpdatingFieldCompletedFormat2, service.ConnectionData.Name, fieldName); } catch (Exception ex) { _iWriteToOutput.WriteErrorToOutput(service.ConnectionData, ex); ToggleControls(service.ConnectionData, true, Properties.WindowStatusStrings.UpdatingFieldFailedFormat2, service.ConnectionData.Name, fieldName); } }
private async Task PerformSaveClick() { if (_assemblyLoad == null) { return; } if (_listMissingCrm.Count > 0) { return; } string workflowActivityGroupName = txtBWorkflowActivityGroupName.Text.Trim(); var updateAssembly = new PluginAssembly(); if (PluginAssembly.PluginAssemblyId.HasValue) { updateAssembly.Id = PluginAssembly.PluginAssemblyId.Value; updateAssembly.PluginAssemblyId = PluginAssembly.PluginAssemblyId; } else { updateAssembly.Name = _assemblyLoad.Name; } updateAssembly.Description = txtBDescription.Text.Trim(); var isolationMode = GetIsolationMode(); var sourceType = GetSourceType(); updateAssembly.IsolationMode = new Microsoft.Xrm.Sdk.OptionSetValue(isolationMode); updateAssembly.SourceType = new Microsoft.Xrm.Sdk.OptionSetValue(sourceType); updateAssembly.Version = _assemblyLoad.Version; updateAssembly.Culture = _assemblyLoad.Culture; updateAssembly.PublicKeyToken = _assemblyLoad.PublicKeyToken; if (sourceType == (int)PluginAssembly.Schema.OptionSets.sourcetype.Database_0 && _assemblyLoad.Content != null && _assemblyLoad.Content.Length > 0 ) { updateAssembly.Content = Convert.ToBase64String(_assemblyLoad.Content); } if (sourceType == (int)PluginAssembly.Schema.OptionSets.sourcetype.Disk_1) { updateAssembly.Path = txtBFileNameOnServer.Text.Trim(); } else { updateAssembly.Path = string.Empty; } var listToRegister = _listLocalAssembly.Where(p => p.IsChecked).ToList(); _service.ConnectionData.AddAssemblyMapping(_assemblyLoad.Name, _assemblyLoad.FilePath); _service.ConnectionData.Save(); ToggleControls(false, Properties.WindowStatusStrings.UpdatingPluginAssemblyFormat1, _service.ConnectionData.Name); try { this.PluginAssembly.Id = await _service.UpsertAsync(updateAssembly); if (listToRegister.Any()) { var assemblyRef = this.PluginAssembly.ToEntityReference(); ToggleControls(false, Properties.WindowStatusStrings.RegisteringNewPluginTypesFormat2, _service.ConnectionData.Name, listToRegister.Count); foreach (var pluginType in listToRegister) { var pluginTypeEntity = new PluginType() { Name = pluginType.Name, TypeName = pluginType.Name, FriendlyName = pluginType.Name, PluginAssemblyId = assemblyRef, }; if (pluginType.IsWorkflowActivity) { pluginTypeEntity.WorkflowActivityGroupName = workflowActivityGroupName; } ToggleControls(false, Properties.WindowStatusStrings.RegisteringPluginTypeFormat2, _service.ConnectionData.Name, pluginType); try { pluginTypeEntity.Id = await _service.CreateAsync(pluginTypeEntity); ToggleControls(true, Properties.WindowStatusStrings.RegisteringPluginTypeCompletedFormat2, _service.ConnectionData.Name, pluginType); } catch (Exception ex) { ToggleControls(true, Properties.WindowStatusStrings.RegisteringPluginTypeFailedFormat2, _service.ConnectionData.Name, pluginType); _iWriteToOutput.WriteErrorToOutput(_service.ConnectionData, ex); _iWriteToOutput.ActivateOutputWindow(_service.ConnectionData); } } ToggleControls(true, Properties.WindowStatusStrings.RegisteringNewPluginTypesCompletedFormat2, _service.ConnectionData.Name, listToRegister.Count); } ToggleControls(true, Properties.WindowStatusStrings.UpdatingPluginAssemblyCompletedFormat1, _service.ConnectionData.Name); this.DialogResult = true; this.Close(); } catch (Exception ex) { ToggleControls(true, Properties.WindowStatusStrings.UpdatingPluginAssemblyFailedFormat1, _service.ConnectionData.Name); _iWriteToOutput.WriteErrorToOutput(_service.ConnectionData, ex); _iWriteToOutput.ActivateOutputWindow(_service.ConnectionData); } }
private async Task PerformSaveClick() { string messageName = cmBMessageName.Text?.Trim(); string primaryEntity = cmBPrimaryEntity.Text?.Trim(); string secondaryEntity = cmBSecondaryEntity.Text?.Trim(); if (string.IsNullOrEmpty(messageName)) { MessageBox.Show(Properties.MessageBoxStrings.MessageNameIsEmpty, Properties.MessageBoxStrings.ErrorTitle, MessageBoxButton.OK, MessageBoxImage.Error); return; } if (!int.TryParse(txtBExecutionOrder.Text.Trim(), out int rank)) { string text = string.Format(Properties.MessageBoxStrings.TextCannotBeParsedToIntFormat1, txtBExecutionOrder.Text); MessageBox.Show(text, Properties.MessageBoxStrings.ErrorTitle, MessageBoxButton.OK, MessageBoxImage.Error); return; } if (string.IsNullOrEmpty(primaryEntity)) { primaryEntity = "none"; } if (string.IsNullOrEmpty(secondaryEntity)) { secondaryEntity = "none"; } var messageFilterCount = _filters.Count(f => string.Equals(f.SdkMessageId.Name, messageName, StringComparison.InvariantCultureIgnoreCase) && string.Equals(f.PrimaryObjectTypeCode, primaryEntity, StringComparison.InvariantCultureIgnoreCase) && string.Equals(f.SecondaryObjectTypeCode, secondaryEntity, StringComparison.InvariantCultureIgnoreCase) ); if (messageFilterCount != 1) { string text = string.Format(Properties.MessageBoxStrings.MessageFilterNotFindedForMessageNameAndEntitiesFormat3, messageName, primaryEntity, secondaryEntity); MessageBox.Show(text, Properties.MessageBoxStrings.ErrorTitle, MessageBoxButton.OK, MessageBoxImage.Error); return; } var messageFilter = _filters.Single(f => string.Equals(f.SdkMessageId.Name, messageName, StringComparison.InvariantCultureIgnoreCase) && string.Equals(f.PrimaryObjectTypeCode, primaryEntity, StringComparison.InvariantCultureIgnoreCase) && string.Equals(f.SecondaryObjectTypeCode, secondaryEntity, StringComparison.InvariantCultureIgnoreCase) ); this.Step.Name = txtBName.Text.Trim(); this.Step.Description = txtBDescription.Text.Trim(); this.Step.SdkMessageFilterId = messageFilter.ToEntityReference(); this.Step.SdkMessageId = messageFilter.SdkMessageId; this.Step.Rank = rank; this.Step.Configuration = txtBUnSecureConfiguration.Text.Trim(); var stage = GetStage(); var invocationsource = GetInvocationSource(); this.Step.Stage = new OptionSetValue(stage); if (stage == (int)SdkMessageProcessingStep.Schema.OptionSets.stage.Post_operation_40) { var mode = GetMode(); this.Step.Mode = new OptionSetValue(mode); if (mode == (int)SdkMessageProcessingStep.Schema.OptionSets.mode.Asynchronous_1) { this.Step.AsyncAutoDelete = chBDeleteAsyncOperationIfSuccessful.IsChecked.GetValueOrDefault(); } else { this.Step.AsyncAutoDelete = false; } } else { this.Step.Mode = new OptionSetValue((int)SdkMessageProcessingStep.Schema.OptionSets.mode.Synchronous_0); this.Step.AsyncAutoDelete = false; } if (!messageFilter.Availability.HasValue || messageFilter.Availability == (int)SdkMessageFilter.Schema.OptionSets.availability.Both) { var supporteddeployment = GetDeployment(); this.Step.SupportedDeployment = new OptionSetValue(supporteddeployment); } else if (messageFilter.Availability == (int)SdkMessageFilter.Schema.OptionSets.availability.Server) { this.Step.SupportedDeployment = new OptionSetValue((int)SdkMessageProcessingStep.Schema.OptionSets.supporteddeployment.Server_Only_0); } else if (messageFilter.Availability == (int)SdkMessageFilter.Schema.OptionSets.availability.Client) { this.Step.SupportedDeployment = new OptionSetValue((int)SdkMessageProcessingStep.Schema.OptionSets.supporteddeployment.Microsoft_Dynamics_365_Client_for_Outlook_Only_1); } #pragma warning disable CS0612 // Type or member is obsolete this.Step.InvocationSource = new OptionSetValue(invocationsource); #pragma warning restore CS0612 // Type or member is obsolete if (string.Equals(messageFilter.SdkMessageId.Name, "Update", StringComparison.InvariantCultureIgnoreCase)) { this.Step.FilteringAttributes = txtBFilteringBAttributes.Text.Trim(); } else { this.Step.FilteringAttributes = string.Empty; } this.Step.ImpersonatingUserId = _impersonatingUser; string secureConfig = txtBSecureConfiguration.Text.Trim(); EntityReference configToDelete = null; if (string.IsNullOrEmpty(secureConfig)) { if (this.Step.SdkMessageProcessingStepSecureConfigId != null) { configToDelete = this.Step.SdkMessageProcessingStepSecureConfigId; this.Step.SdkMessageProcessingStepSecureConfigId = null; } } else { SdkMessageProcessingStepSecureConfig config = new SdkMessageProcessingStepSecureConfig() { SecureConfig = secureConfig, }; if (this.Step.SdkMessageProcessingStepSecureConfigId != null) { config.Id = this.Step.SdkMessageProcessingStepSecureConfigId.Id; } ToggleControls(false, Properties.WindowStatusStrings.UpdatingSdkMessageProcessingStepSecureConfigFormat1, _service.ConnectionData.Name); try { config.Id = await _service.UpsertAsync(config); ToggleControls(true, Properties.WindowStatusStrings.UpdatingSdkMessageProcessingStepSecureConfigCompletedFormat1, _service.ConnectionData.Name); } catch (Exception ex) { ToggleControls(true, Properties.WindowStatusStrings.UpdatingSdkMessageProcessingStepSecureConfigFailedFormat1, _service.ConnectionData.Name); _iWriteToOutput.WriteErrorToOutput(_service.ConnectionData, ex); _iWriteToOutput.ActivateOutputWindow(_service.ConnectionData); } if (config.Id != Guid.Empty) { this.Step.SdkMessageProcessingStepSecureConfigId = config.ToEntityReference(); } } ToggleControls(false, Properties.WindowStatusStrings.UpdatingSdkMessageProcessingStepFormat1, _service.ConnectionData.Name); try { this.Step.Id = await _service.UpsertAsync(this.Step); if (configToDelete != null) { ToggleControls(false, Properties.WindowStatusStrings.DeletingSdkMessageProcessingStepSecureConfigFormat1, _service.ConnectionData.Name); try { await _service.DeleteAsync(configToDelete.LogicalName, configToDelete.Id); ToggleControls(true, Properties.WindowStatusStrings.DeletingSdkMessageProcessingStepSecureConfigCompletedFormat1, _service.ConnectionData.Name); } catch (Exception ex) { ToggleControls(true, Properties.WindowStatusStrings.DeletingSdkMessageProcessingStepSecureConfigFailedFormat1, _service.ConnectionData.Name); _iWriteToOutput.WriteErrorToOutput(_service.ConnectionData, ex); _iWriteToOutput.ActivateOutputWindow(_service.ConnectionData); } } ToggleControls(true, Properties.WindowStatusStrings.UpdatingSdkMessageProcessingStepCompletedFormat1, _service.ConnectionData.Name); this.DialogResult = true; this.Close(); } catch (Exception ex) { ToggleControls(true, Properties.WindowStatusStrings.UpdatingSdkMessageProcessingStepFailedFormat1, _service.ConnectionData.Name); _iWriteToOutput.WriteErrorToOutput(_service.ConnectionData, ex); _iWriteToOutput.ActivateOutputWindow(_service.ConnectionData); } }
private async void btnSaveEntity_Click(object sender, RoutedEventArgs e) { if (!_entityIds.Any()) { return; } var list = _listAttributeControls.OfType <IAttributeMetadataControl <AttributeMetadata> >().ToList(); { var testEntity = new Entity(_entityName); foreach (var item in list) { item.AddChangedAttribute(testEntity); } if (!testEntity.Attributes.Any()) { _iWriteToOutput.WriteToOutput(_service.ConnectionData, Properties.OutputStrings.NoChangesInEntityFormat1, _entityName); _iWriteToOutput.ActivateOutputWindow(_service.ConnectionData); return; } } ToggleControls(false, Properties.WindowStatusStrings.SavingEntitiesFormat1, _entityName); bool hasError = false; var saver = new EntitySaverFactory().GetEntitySaver(_entityName, _service); foreach (var id in _entityIds) { var updateEntity = new Entity(_entityName) { Id = id, }; foreach (var item in list) { item.AddChangedAttribute(updateEntity); } try { _iWriteToOutput.WriteToOutput(_service.ConnectionData, Properties.WindowStatusStrings.SavingEntityInstanceFormat2, _entityName, id); _iWriteToOutput.WriteToOutputEntityInstance(_service.ConnectionData, updateEntity); await saver.UpsertAsync(updateEntity, (s) => UpdateStatus(s)); } catch (Exception ex) { hasError = true; _iWriteToOutput.WriteErrorToOutput(_service.ConnectionData, ex, Properties.WindowStatusStrings.SavingEntityInstanceFailedFormat2, _entityName, id); } } ToggleControls(true, Properties.WindowStatusStrings.SavingEntitiesCompletedFormat1, _entityName); if (!hasError) { this.Close(); } }
private async Task PerformUpdateEntityField(string folder, Guid idSiteMap, string name, string nameUnique, string fieldName, string fieldTitle) { if (!this.IsControlsEnabled) { return; } var service = await GetService(); ToggleControls(service.ConnectionData, false, Properties.WindowStatusStrings.UpdatingFieldFormat2, service.ConnectionData.Name, fieldName); try { var repository = new SitemapRepository(service); var sitemap = await repository.GetByIdAsync(idSiteMap, new ColumnSet(fieldName)); string xmlContent = sitemap.GetAttributeValue <string>(fieldName); await CreateFileAsync(folder, name, nameUnique, idSiteMap, fieldTitle + " BackUp", xmlContent); var newText = string.Empty; { bool?dialogResult = false; this.Dispatcher.Invoke(() => { var form = new WindowTextField("Enter " + fieldTitle, fieldTitle, xmlContent); dialogResult = form.ShowDialog(); newText = form.FieldText; }); if (dialogResult.GetValueOrDefault() == false) { ToggleControls(service.ConnectionData, true, Properties.WindowStatusStrings.UpdatingFieldCanceledFormat2, service.ConnectionData.Name, fieldName); return; } } newText = ContentCoparerHelper.RemoveAllCustomXmlAttributesAndNamespaces(newText); UpdateStatus(service.ConnectionData, Properties.WindowStatusStrings.ValidatingXmlForFieldFormat1, fieldName); if (!ContentCoparerHelper.TryParseXmlDocument(newText, out var doc)) { ToggleControls(service.ConnectionData, true, Properties.WindowStatusStrings.TextIsNotValidXml); _iWriteToOutput.ActivateOutputWindow(service.ConnectionData); return; } bool validateResult = await SitemapRepository.ValidateXmlDocumentAsync(service.ConnectionData, _iWriteToOutput, doc); if (!validateResult) { var dialogResult = MessageBoxResult.Cancel; this.Dispatcher.Invoke(() => { dialogResult = MessageBox.Show(Properties.MessageBoxStrings.ContinueOperation, Properties.MessageBoxStrings.QuestionTitle, MessageBoxButton.OKCancel, MessageBoxImage.Question); }); if (dialogResult != MessageBoxResult.OK) { ToggleControls(service.ConnectionData, true, Properties.WindowStatusStrings.ValidatingXmlForFieldFailedFormat1, fieldName); _iWriteToOutput.ActivateOutputWindow(service.ConnectionData); return; } } newText = doc.ToString(SaveOptions.DisableFormatting); var updateEntity = new SiteMap { Id = idSiteMap }; updateEntity.Attributes[fieldName] = newText; await service.UpdateAsync(updateEntity); UpdateStatus(service.ConnectionData, Properties.WindowStatusStrings.PublishingSiteMapFormat3, service.ConnectionData.Name, name, idSiteMap.ToString()); { var repositoryPublish = new PublishActionsRepository(service); await repositoryPublish.PublishSiteMapsAsync(new[] { idSiteMap }); } ToggleControls(service.ConnectionData, true, Properties.WindowStatusStrings.UpdatingFieldCompletedFormat2, service.ConnectionData.Name, fieldName); } catch (Exception ex) { _iWriteToOutput.WriteErrorToOutput(service.ConnectionData, ex); ToggleControls(service.ConnectionData, true, Properties.WindowStatusStrings.UpdatingFieldFailedFormat2, service.ConnectionData.Name, fieldName); } }