public async Task <bool> CreateFileWithDependentComponentsAsync(DependencyRepository dependencyRepository, string connectionInfo, string filePath, ComponentType componentType, Guid idComponent, string componentName) { var coll = await dependencyRepository.GetDependentComponentsAsync((int)componentType, idComponent); string description = await this.GetDescriptionDependentAsync(coll); if (string.IsNullOrEmpty(description)) { return(false); } StringBuilder content = new StringBuilder(); content.AppendLine(connectionInfo).AppendLine(); content.AppendFormat("Dependent Components for {0} '{1}' at {2}", componentType.ToString(), componentName, DateTime.Now.ToString("G", System.Globalization.CultureInfo.CurrentCulture)).AppendLine(); content.Append(description); File.WriteAllText(filePath, content.ToString(), new UTF8Encoding(false)); return(true); }
private async Task CheckingGlobalOptionSetDuplicates(ConnectionData connectionData, CommonConfiguration commonConfig) { var service = await ConnectAndWriteToOutputAsync(connectionData); if (service == null) { return; } StringBuilder content = new StringBuilder(); content.AppendLine(Properties.OutputStrings.ConnectingToCRM); content.AppendLine(connectionData.GetConnectionDescription()); content.AppendFormat(Properties.OutputStrings.CurrentServiceEndpointFormat1, service.CurrentServiceEndpoint).AppendLine(); var entityMetadataSource = new SolutionComponentMetadataSource(service); var descriptor = new SolutionComponentDescriptor(service); descriptor.WithUrls = true; descriptor.WithManagedInfo = true; descriptor.WithSolutionsInfo = true; var dependencyRepository = new DependencyRepository(service); var descriptorHandler = new DependencyDescriptionHandler(descriptor); RetrieveAllOptionSetsRequest request = new RetrieveAllOptionSetsRequest(); RetrieveAllOptionSetsResponse response = (RetrieveAllOptionSetsResponse)service.Execute(request); bool hasInfo = false; foreach (var optionSet in response.OptionSetMetadata.OfType <OptionSetMetadata>().OrderBy(e => e.Name)) { var coll = await dependencyRepository.GetDependentComponentsAsync((int)ComponentType.OptionSet, optionSet.MetadataId.Value); if (coll.Any()) { var filter = coll .Where(c => c.DependentComponentType.Value == (int)ComponentType.Attribute) .Select(c => new { Dependency = c, Attribute = entityMetadataSource.GetAttributeMetadata(c.DependentComponentObjectId.Value) }) .Where(c => c.Attribute != null) .GroupBy(c => c.Attribute.EntityLogicalName) .Where(gr => gr.Count() > 1) .SelectMany(gr => gr.Select(c => c.Dependency)) .ToList() ; if (filter.Any()) { var desc = await descriptorHandler.GetDescriptionDependentAsync(filter); if (!string.IsNullOrEmpty(desc)) { if (content.Length > 0) { content .AppendLine(new string('-', 150)) .AppendLine(); } hasInfo = true; content.AppendFormat("Global OptionSet Name {0} IsCustomOptionSet {1} IsManaged {2}", optionSet.Name, optionSet.IsCustomOptionSet, optionSet.IsManaged).AppendLine(); content.AppendLine(desc); } } } } if (!hasInfo) { content.AppendLine("No duplicates were found."); } commonConfig.CheckFolderForExportExists(this._iWriteToOutput); string fileName = string.Format("{0}.Checking Global OptionSet Duplicates on Entity at {1}.txt", connectionData.Name, DateTime.Now.ToString("yyyy.MM.dd HH-mm-ss")); string filePath = Path.Combine(commonConfig.FolderForExport, FileOperations.RemoveWrongSymbols(fileName)); File.WriteAllText(filePath, content.ToString(), new UTF8Encoding(false)); this._iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.CreatedFileWithCheckingGlobalOptionSetDuplicatesOnEntityFormat1, filePath); this._iWriteToOutput.PerformAction(service.ConnectionData, filePath); }
private async Task ShowingWebResourcesDependentComponents(ConnectionData connectionData, CommonConfiguration commonConfig, List <SelectedFile> selectedFiles) { var service = await ConnectAndWriteToOutputAsync(connectionData); if (service == null) { return; } StringBuilder content = new StringBuilder(); content.AppendLine(Properties.OutputStrings.ConnectingToCRM); content.AppendLine(connectionData.GetConnectionDescription()); content.AppendFormat(Properties.OutputStrings.CurrentServiceEndpointFormat1, service.CurrentServiceEndpoint).AppendLine(); var descriptor = new SolutionComponentDescriptor(service); descriptor.WithUrls = true; descriptor.WithManagedInfo = true; descriptor.WithSolutionsInfo = true; var descriptorHandler = new DependencyDescriptionHandler(descriptor); var dependencyRepository = new DependencyRepository(service); bool isconnectionDataDirty = false; List <string> listNotExistsOnDisk = new List <string>(); List <string> listNotFoundedInCRMNoLink = new List <string>(); List <string> listLastLinkEqualByContent = new List <string>(); List <SolutionComponent> webResourceNames = new List <SolutionComponent>(); Dictionary <SolutionComponent, string> webResourceDescriptions = new Dictionary <SolutionComponent, string>(); WebResourceRepository repositoryWebResource = new WebResourceRepository(service); FormatTextTableHandler tableWithoutDependenComponents = new FormatTextTableHandler(); tableWithoutDependenComponents.SetHeader("FilePath", "Web Resource Name", "Web Resource Type"); var groups = selectedFiles.GroupBy(sel => sel.Extension); foreach (var gr in groups) { var names = gr.Select(sel => sel.FriendlyFilePath).ToArray(); var dict = repositoryWebResource.FindMultiple(gr.Key, names); foreach (var selectedFile in gr) { if (File.Exists(selectedFile.FilePath)) { string name = selectedFile.FriendlyFilePath.ToLower(); var webresource = WebResourceRepository.FindWebResourceInDictionary(dict, name, gr.Key); if (webresource == null) { Guid?webId = connectionData.GetLastLinkForFile(selectedFile.FriendlyFilePath); if (webId.HasValue) { webresource = await repositoryWebResource.GetByIdAsync(webId.Value); if (webresource != null) { listLastLinkEqualByContent.Add(selectedFile.FriendlyFilePath); } } } if (webresource != null) { // Запоминается файл isconnectionDataDirty = true; connectionData.AddMapping(webresource.Id, selectedFile.FriendlyFilePath); var coll = await dependencyRepository.GetDependentComponentsAsync((int)ComponentType.WebResource, webresource.Id); var desc = await descriptorHandler.GetDescriptionDependentAsync(coll); if (!string.IsNullOrEmpty(desc)) { var component = new SolutionComponent() { ComponentType = new OptionSetValue((int)ComponentType.WebResource), ObjectId = webresource.Id, }; webResourceNames.Add(component); webResourceDescriptions.Add(component, desc); } else { tableWithoutDependenComponents.AddLine(selectedFile.FriendlyFilePath, webresource.Name, "'" + webresource.FormattedValues[WebResource.Schema.Attributes.webresourcetype] + "'"); } } else { connectionData.RemoveMapping(selectedFile.FriendlyFilePath); listNotFoundedInCRMNoLink.Add(selectedFile.FriendlyFilePath); } } else { listNotExistsOnDisk.Add(selectedFile.FilePath); } } } if (isconnectionDataDirty) { //Сохранение настроек после публикации connectionData.Save(); } FindsController.WriteToContentList(listNotFoundedInCRMNoLink, content, "File NOT FOUNDED in CRM: {0}"); FindsController.WriteToContentList(listLastLinkEqualByContent, content, "Files NOT FOUNDED in CRM, but has Last Link: {0}"); FindsController.WriteToContentList(listNotExistsOnDisk, content, Properties.OutputStrings.FileNotExistsFormat1); FindsController.WriteToContentList(tableWithoutDependenComponents.GetFormatedLines(true), content, "Files without dependent components: {0}"); FindsController.WriteToContentDictionary(descriptor, content, webResourceNames, webResourceDescriptions, "WebResource dependent components: {0}"); commonConfig.CheckFolderForExportExists(this._iWriteToOutput); string fileName = string.Format("{0}.WebResourceDependent at {1}.txt", connectionData.Name, DateTime.Now.ToString("yyyy.MM.dd HH-mm-ss")); string filePath = Path.Combine(commonConfig.FolderForExport, FileOperations.RemoveWrongSymbols(fileName)); File.WriteAllText(filePath, content.ToString(), new UTF8Encoding(false)); this._iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.CreatedFileWithWebResourcesDependentComponentsFormat1, filePath); this._iWriteToOutput.PerformAction(service.ConnectionData, filePath); }
private async Task GenerateOptionSetEnums(string tempNamespace, OptionSetMetadata optionSet) { var dependent = await _dependencyRepository.GetDependentComponentsAsync((int)ComponentType.OptionSet, optionSet.MetadataId.Value); string entityname = null; string attributename = null; List <StringMap> listStringmap = null; if (dependent.Any(e => e.DependentComponentType.Value == (int)ComponentType.Attribute)) { var attr = dependent.FirstOrDefault(e => e.DependentComponentType.Value == (int)ComponentType.Attribute); var attributeMetadata = _descriptor.MetadataSource.GetAttributeMetadata(attr.DependentComponentObjectId.Value); if (attributeMetadata != null) { entityname = attributeMetadata.EntityLogicalName; attributename = attributeMetadata.LogicalName; listStringmap = await _repositoryStringMap.GetListAsync(entityname); } } var options = CreateFileHandler.GetOptionItems(entityname, attributename, optionSet, listStringmap); if (!options.Any()) { return; } WriteLine(); if (this._withDependentComponents) { var desc = await _descriptorHandler.GetDescriptionDependentAsync(dependent); var split = desc.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); foreach (var item in split) { WriteLine("// {0}", item); } } string objectName = string.Format("{0}{1}Enum", tempNamespace, optionSet.Name); if (CreateFileHandler.IgnoreGlobalOptionSet(optionSet.Name)) { WriteLine("// {0}", objectName); return; } WriteLine(string.Format("{0} =", objectName) + " {"); WriteLine(); // Формируем значения foreach (var item in options) { WriteLine(item.MakeStringJS()); } WriteLine("};"); }
private async Task <string> CreateFile(string entityName, string filePath, bool allComponents) { StringBuilder content = new StringBuilder(); var metedata = _descriptor.MetadataSource.GetEntityMetadata(entityName); foreach (var currentAttribute in metedata.Attributes.OrderBy(attr => attr.LogicalName)) { if (currentAttribute.AttributeOf == null) { string name = string.Format("{0}.{1}", entityName, currentAttribute.LogicalName); var coll = await _dependencyRepository.GetDependentComponentsAsync((int)ComponentType.Attribute, currentAttribute.MetadataId.Value); if (!allComponents) { coll = coll.Where(ent => { var val = ent.DependentComponentType.Value; return(val == (int)ComponentType.Workflow || val == (int)ComponentType.SdkMessageProcessingStep || val == (int)ComponentType.SdkMessageProcessingStepImage ); //return val == (int)ComponentType.SDKMessageProcessingStepImage // ; } ).ToList(); } var desc = await _descriptorHandler.GetDescriptionDependentAsync(coll); if (!string.IsNullOrEmpty(desc)) { if (content.Length > 0) { content .AppendLine() .AppendLine() .AppendLine(new string('-', 100)) .AppendLine() .AppendLine(); } content.AppendFormat("Attribute {0} Dependent Components:", name).AppendLine(); content.Append(desc); } } } string message = string.Empty; if (content.Length > 0) { File.WriteAllText(filePath, content.ToString(), new UTF8Encoding(false)); message = string.Format("For entity '{0}' created file with attributes dependent components: {1}", entityName, filePath); } else { message = string.Format("No information about attributes dependent components for entity '{0}'.", entityName); } return(message); }
private async Task GenerateOptionSetEnums(IEnumerable <AttributeMetadata> attributeList, OptionSetMetadata optionSet) { var options = CreateFileHandler.GetOptionItems(attributeList.First().EntityLogicalName, attributeList.First().LogicalName, optionSet, this._listStringMap); if (!options.Any()) { return; } WriteLine(); WriteLine("// Attribute:"); foreach (var attr in attributeList.OrderBy(a => a.LogicalName)) { WriteLine("// " + _tabSpacer + attr.LogicalName); } if (optionSet.IsGlobal.GetValueOrDefault() && this._config.WithDependentComponents) { var coll = await _dependencyRepository.GetDependentComponentsAsync((int)ComponentType.OptionSet, optionSet.MetadataId.Value); var desc = await _descriptorHandler.GetDescriptionDependentAsync(coll); var split = desc.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); if (split.Any()) { WriteSummaryStrings(split); } } bool ignore = attributeList.Any(a => IgnoreAttribute(_entityMetadata.LogicalName, a.LogicalName)); if (ignore) { foreach (var attr in attributeList.OrderBy(a => a.LogicalName)) { WriteLine("//var {0}Enum", attr.LogicalName); } return; } var enumName = string.Empty; if (optionSet.IsGlobal.GetValueOrDefault()) { enumName = optionSet.Name; } else { enumName = attributeList.First().LogicalName; } WriteLine(string.Format("'{0}Enum':", enumName) + " {"); WriteLine(); // Формируем значения foreach (var item in options) { WriteLine(item.MakeStringJS()); } WriteLine("},"); }
private async Task GenerateOptionSetEnums(OptionSetMetadata optionSet) { var dependent = await _dependencyRepository.GetDependentComponentsAsync((int)ComponentType.OptionSet, optionSet.MetadataId.Value); string entityname = null; string attributename = null; List <StringMap> listStringmap = null; if (dependent.Any(e => e.DependentComponentType.Value == (int)ComponentType.Attribute)) { var attr = dependent.FirstOrDefault(e => e.DependentComponentType.Value == (int)ComponentType.Attribute); var attributeMetadata = _descriptor.MetadataSource.GetAttributeMetadata(attr.DependentComponentObjectId.Value); if (attributeMetadata != null) { entityname = attributeMetadata.EntityLogicalName; attributename = attributeMetadata.LogicalName; listStringmap = await _repositoryStringMap.GetListAsync(entityname); } } WriteLine(); List <string> headers = new List <string>(); string temp = string.Format("OptionSet Name: {0} IsCustomOptionSet: {1}", optionSet.Name, optionSet.IsCustomOptionSet); if (this._config.WithManagedInfo) { temp += string.Format(" IsManaged: {0}", optionSet.IsManaged); } headers.Add(temp); if (this._config.WithDependentComponents) { var desc = await _descriptorHandler.GetDescriptionDependentAsync(dependent); var split = desc.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); if (split.Any()) { headers.Add(string.Empty); foreach (var item in split) { headers.Add(item); } } } WriteSummary(optionSet.DisplayName, optionSet.Description, null, headers); var options = CreateFileHandler.GetOptionItems(entityname, attributename, optionSet, listStringmap); { bool ignore = CreateFileHandler.IgnoreGlobalOptionSet(optionSet.Name) || !options.Any(); if (!ignore) { if (this._config.AddDescriptionAttribute) { string description = CreateFileHandler.GetLocalizedLabel(optionSet.DisplayName); if (string.IsNullOrEmpty(description)) { description = CreateFileHandler.GetLocalizedLabel(optionSet.Description); } if (!string.IsNullOrEmpty(description)) { WriteLine("[System.ComponentModel.DescriptionAttribute(\"{0}\")]", description); } } if (this._config.OptionSetExportType == OptionSetExportType.Enums && _config.AddTypeConverterAttributeForEnums && !string.IsNullOrEmpty(_config.TypeConverterName)) { WriteLine("[System.ComponentModel.TypeConverterAttribute(\"{0}\")]", _config.TypeConverterName); } } StringBuilder str = new StringBuilder(); if (ignore) { str.Append("// "); } if (this._config.OptionSetExportType == OptionSetExportType.Enums) { str.AppendFormat("public enum {0}", optionSet.Name); } else { str.AppendFormat("public static partial class {0}", optionSet.Name); } WriteLine(str.ToString()); if (ignore) { return; } } WriteLine("{"); bool first = true; // Формируем значения foreach (var item in options) { if (first) { first = false; } else { WriteLine(); } List <string> header = new List <string>() { item.Value.ToString() }; if (item.DisplayOrder.HasValue) { header.Add(string.Format("DisplayOrder: {0}", item.DisplayOrder.Value)); } WriteSummary(item.Label, item.Description, header, null); if (this._config.AddDescriptionAttribute) { string description = CreateFileHandler.GetLocalizedLabel(item.Label); if (string.IsNullOrEmpty(description)) { description = CreateFileHandler.GetLocalizedLabel(item.Description); } if (!string.IsNullOrEmpty(description)) { WriteLine("[System.ComponentModel.DescriptionAttribute(\"{0}\")]", description); } } var str = item.MakeStrings(); if (this._config.OptionSetExportType == OptionSetExportType.Enums) { WriteLine("[System.Runtime.Serialization.EnumMemberAttribute()]"); WriteLine(str + ","); } else { WriteLine("public {0} int {1};", _fieldHeader, str); } } WriteLine("}"); }
private async Task GenerateOptionSetEnums(string tempNamespace, OptionSetMetadata optionSet) { var dependent = await _dependencyRepository.GetDependentComponentsAsync((int)ComponentType.OptionSet, optionSet.MetadataId.Value); string entityname = null; string attributename = null; List <StringMap> listStringmap = null; if (dependent.Any(e => e.DependentComponentType.Value == (int)ComponentType.Attribute)) { var attr = dependent.FirstOrDefault(e => e.DependentComponentType.Value == (int)ComponentType.Attribute); var attributeMetadata = _descriptor.MetadataSource.GetAttributeMetadata(attr.DependentComponentObjectId.Value); if (attributeMetadata != null) { entityname = attributeMetadata.EntityLogicalName; attributename = attributeMetadata.LogicalName; listStringmap = await _repositoryStringMap.GetListAsync(entityname); } } var options = GetOptionItems(entityname, attributename, optionSet, listStringmap); if (!options.Any()) { return; } WriteLine(); WriteLine(); List <string> headers = new List <string>(); string temp = string.Format("OptionSet Name: {0} IsCustomOptionSet: {1}", optionSet.Name, optionSet.IsCustomOptionSet); headers.Add(temp); if (this._withDependentComponents) { var desc = await _descriptorHandler.GetDescriptionDependentAsync(dependent); var split = desc.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); if (split.Any()) { headers.Add(string.Empty); foreach (var item in split) { headers.Add(item); } } } WriteSummary(optionSet.DisplayName, optionSet.Description, null, headers); string objectName = string.Format("{0}{1}Enum", tempNamespace, optionSet.Name); if (IgnoreGlobalOptionSet(optionSet.Name)) { WriteLine("// {0}", objectName); return; } WriteLine(string.Format("{0} =", objectName) + " {"); WriteLine(); bool first = true; // Формируем значения foreach (var item in options.OrderBy(o => o.Value)) { WriteCommaIfNotFirstLine(ref first); Write(item.MakeStringJS()); } WriteLine(); Write("};"); }