private async Task CheckingUnknownFormControlType(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(); Dictionary <string, FormatTextTableHandler> dictUnknownControls = new Dictionary <string, FormatTextTableHandler>(StringComparer.InvariantCultureIgnoreCase); var descriptor = new SolutionComponentDescriptor(service); var handler = new FormDescriptionHandler(descriptor, new DependencyRepository(service)); var repositorySystemForm = new SystemFormRepository(service); var formList = await repositorySystemForm.GetListAsync(null, null, new ColumnSet(true)); foreach (var systemForm in formList .OrderBy(f => f.ObjectTypeCode) .ThenBy(f => f.Type?.Value) .ThenBy(f => f.Name) ) { string formXml = systemForm.FormXml; if (!string.IsNullOrEmpty(formXml)) { XElement doc = XElement.Parse(formXml); var tabs = handler.GetFormTabs(doc); var unknownControls = tabs.SelectMany(t => t.Sections).SelectMany(s => s.Controls).Where(c => c.GetControlType() == FormControl.FormControlType.UnknownControl); foreach (var control in unknownControls) { if (!dictUnknownControls.ContainsKey(control.ClassId)) { FormatTextTableHandler tableUnknownControls = new FormatTextTableHandler(); tableUnknownControls.SetHeader("Entity", "FormType", "Form", "State", "Attribute", "Form Url"); dictUnknownControls[control.ClassId] = tableUnknownControls; } dictUnknownControls[control.ClassId].AddLine( systemForm.ObjectTypeCode , systemForm.FormattedValues[SystemForm.Schema.Attributes.type] , systemForm.Name , systemForm.FormattedValues[SystemForm.Schema.Attributes.formactivationstate] , control.Attribute , service.UrlGenerator.GetSolutionComponentUrl(ComponentType.SystemForm, systemForm.Id) ); } } } if (dictUnknownControls.Count > 0) { content.AppendLine().AppendLine(); content.AppendFormat("Unknown Form Control Types: {0}", dictUnknownControls.Count); foreach (var classId in dictUnknownControls.Keys.OrderBy(s => s)) { content.AppendLine().AppendLine(); content.AppendLine(classId); var tableUnknownControls = dictUnknownControls[classId]; foreach (var str in tableUnknownControls.GetFormatedLines(false)) { content.AppendLine(_tabSpacer + str); } } commonConfig.CheckFolderForExportExists(this._iWriteToOutput); string fileName = string.Format("{0}.Checking Unknown Form Control Types 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, "Unknown Form Control Types were exported to {0}", filePath); this._iWriteToOutput.PerformAction(service.ConnectionData, filePath); } else { this._iWriteToOutput.WriteToOutput(connectionData, "No Unknown Form Control Types in CRM were founded."); this._iWriteToOutput.ActivateOutputWindow(connectionData); } }
private async Task <string> CreateFormsEventsFile(IOrganizationServiceExtented service, string fileFolder, string fileNameFormat, string connectionDataName, bool onlyWithFormLibraries) { this._iWriteToOutput.WriteToOutput(service.ConnectionData, "Start analyzing System Forms."); var repository = new SystemFormRepository(service); var allForms = (await repository.GetListAsync()) .OrderBy(ent => ent.ObjectTypeCode) .ThenBy(ent => ent.Type.Value) .ThenBy(ent => ent.Name) ; SolutionComponentDescriptor descriptor = new SolutionComponentDescriptor(service); var handler = new FormDescriptionHandler(descriptor, new DependencyRepository(service)); StringBuilder content = new StringBuilder(); foreach (var systemForm in allForms) { string entityName = systemForm.ObjectTypeCode; string name = systemForm.Name; string typeName = systemForm.FormattedValues[SystemForm.Schema.Attributes.type]; string formXml = systemForm.FormXml; if (!string.IsNullOrEmpty(formXml)) { XElement doc = XElement.Parse(formXml); string events = handler.GetEventsDescription(doc); if (!string.IsNullOrEmpty(events)) { string desc = handler.GetFormLibrariesDescription(doc); if (onlyWithFormLibraries && string.IsNullOrEmpty(desc)) { continue; } if (content.Length > 0) { content .AppendLine() .AppendLine(new string('-', 100)) .AppendLine() ; } content.AppendFormat("Entity: {0}", entityName).AppendLine(); content.AppendFormat("Form Type: {0}", typeName).AppendLine(); content.AppendFormat("Form Name: {0}", name).AppendLine(); if (!string.IsNullOrEmpty(desc)) { content.AppendLine("FormLibraries:"); content.Append(desc); } content.AppendLine("Events:"); content.AppendLine(events); } } } string filePath = string.Empty; if (content.Length > 0) { string fileName = string.Format("{0}{1} {2}.txt" , (!string.IsNullOrEmpty(connectionDataName) ? connectionDataName + "." : string.Empty) , fileNameFormat.Trim() , EntityFileNameFormatter.GetDateString() ); filePath = Path.Combine(fileFolder, FileOperations.RemoveWrongSymbols(fileName)); if (!Directory.Exists(fileFolder)) { Directory.CreateDirectory(fileFolder); } File.WriteAllText(filePath, content.ToString(), new UTF8Encoding(false)); this._iWriteToOutput.WriteToOutput(service.ConnectionData, "System Forms Events were exported to {0}", filePath); } else { this._iWriteToOutput.WriteToOutput(service.ConnectionData, "No Forms Events were founded."); } return(filePath); }