private async Task <string> GetDescriptionGroupByRequiredComponents(List <Dependency> list)
        {
            StringBuilder builder = new StringBuilder();
            string        format  = "Dependent components:";

            var groupsComponent = list
                                  .GroupBy(d => d.RequiredComponentType)
                                  .OrderBy(gr => gr.Key?.Value);

            foreach (var grComp in groupsComponent)
            {
                var groupsObject = grComp
                                   .GroupBy(d => new { RequiredComponentType = d.RequiredComponentType.Value, RequiredComponentObjectId = d.RequiredComponentObjectId.Value });

                Dictionary <string, string> dict = new Dictionary <string, string>(StringComparer.InvariantCultureIgnoreCase);

                foreach (var grObj in groupsObject)
                {
                    try
                    {
                        var entityDesc = _descriptor.GetComponentDescription(grObj.Key.RequiredComponentType, grObj.Key.RequiredComponentObjectId);

                        var grList = grObj.Select(d => d.DependentToSolutionComponent()).ToList();

                        var collectionDesc = await _descriptor.GetSolutionComponentsDescriptionAsync(grList);

                        if (!string.IsNullOrEmpty(collectionDesc))
                        {
                            dict.Add(entityDesc, collectionDesc);
                        }
                    }
                    catch (Exception ex)
                    {
                        builder.AppendLine().AppendLine("Exception");
                        builder.AppendLine().AppendLine(DTEHelper.GetExceptionDescription(ex)).AppendLine();

                        DTEHelper.WriteExceptionToOutput(_descriptor.ConnectionData, ex);

#if DEBUG
                        if (System.Diagnostics.Debugger.IsAttached)
                        {
                            System.Diagnostics.Debugger.Break();
                        }
#endif
                    }
                }

                foreach (var entityDesc in dict.Keys.OrderBy(s => s))
                {
                    if (builder.Length > 0)
                    {
                        builder
                        .AppendLine()
                        .AppendLine(new string('-', 100))
                        .AppendLine();
                    }

                    builder.AppendLine(entityDesc);
                    builder.AppendLine(format);
                    builder.AppendLine(dict[entityDesc]);
                }
            }

            return(builder.ToString());
        }
예제 #2
0
        private static void ReplaceXsdSchemaInTextView(IWpfTextView wpfTextView, string schemas)
        {
            try
            {
                using (var edit = wpfTextView.TextBuffer.CreateEdit())
                {
                    var hasModifed = false;

                    string text = edit.Snapshot.GetText();

                    {
                        var match = Regex.Match(text, patternXsi);
                        if (match.Success)
                        {
                            string quoteSymbol = match.Groups[groupNameQuote].Value;
                            string replacement = string.Format(replaceXsiNamespaceFormat3, quoteSymbol, Intellisense.Model.IntellisenseContext.NamespaceXMLSchemaInstance.NamespaceName, quoteSymbol);

                            if (match.Value != replacement)
                            {
                                hasModifed = true;
                                edit.Replace(match.Index, match.Length, replacement);
                            }
                        }
                        else
                        {
                            int?   indexInsert = FindIndexToInsert(text);
                            string quoteSymbol = FindQuoteSymbol(text);

                            string replacement = string.Format(replaceXsiNamespaceFormat3, quoteSymbol, Intellisense.Model.IntellisenseContext.NamespaceXMLSchemaInstance.NamespaceName, quoteSymbol);

                            if (indexInsert.HasValue)
                            {
                                hasModifed = true;
                                edit.Insert(indexInsert.Value, replacement);
                            }
                        }
                    }

                    {
                        var match = Regex.Match(text, patternXsiSchemaLocation);
                        if (match.Success)
                        {
                            string quoteSymbol = match.Groups[groupNameQuote].Value;
                            var    newLocation = string.Format(replaceXsiSchemaLocationFormat3, quoteSymbol, schemas, quoteSymbol);

                            if (match.Value != newLocation)
                            {
                                hasModifed = true;
                                edit.Replace(match.Index, match.Length, newLocation);
                            }
                        }
                        else
                        {
                            int?   indexInsert = FindIndexToInsert(text);
                            string quoteSymbol = FindQuoteSymbol(text);

                            var newLocation = string.Format(replaceXsiSchemaLocationFormat3, quoteSymbol, schemas, quoteSymbol);

                            if (indexInsert.HasValue)
                            {
                                hasModifed = true;
                                edit.Insert(indexInsert.Value, newLocation);
                            }
                        }
                    }

                    if (hasModifed)
                    {
                        edit.Apply();
                    }
                }
            }
            catch (Exception ex)
            {
                DTEHelper.WriteExceptionToOutput(null, ex);
            }
        }
예제 #3
0
        public void HandleXsdSchemaExport(string[] fileNamesColl)
        {
            CommonConfiguration commonConfig = CommonConfiguration.Get();

            if (commonConfig != null)
            {
                var thread = new System.Threading.Thread(() =>
                {
                    try
                    {
                        var form = new WindowSelectFolderForExport(null, commonConfig.FolderForExport, commonConfig.DefaultFileAction);

                        if (form.ShowDialog().GetValueOrDefault())
                        {
                            commonConfig.FolderForExport   = form.SelectedFolder;
                            commonConfig.DefaultFileAction = form.GetFileAction();

                            commonConfig.Save();

                            ActivateOutputWindow(null);
                            WriteToOutputEmptyLines(null, commonConfig);

                            try
                            {
                                foreach (var fileName in fileNamesColl)
                                {
                                    Uri uri = FileOperations.GetSchemaResourceUri(fileName);
                                    StreamResourceInfo info = Application.GetResourceStream(uri);

                                    var doc = XDocument.Load(info.Stream);
                                    info.Stream.Dispose();

                                    var filePath = Path.Combine(commonConfig.FolderForExport, fileName);

                                    doc.Save(filePath, SaveOptions.OmitDuplicateNamespaces);

                                    this.WriteToOutput(null, string.Empty);
                                    this.WriteToOutput(null, string.Empty);
                                    this.WriteToOutput(null, string.Empty);

                                    this.WriteToOutput(null, "{0} exported.", fileName);

                                    this.WriteToOutput(null, string.Empty);

                                    this.WriteToOutputFilePathUri(null, filePath);

                                    PerformAction(null, filePath, true);
                                }
                            }
                            catch (Exception ex)
                            {
                                WriteErrorToOutput(null, ex);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        DTEHelper.WriteExceptionToOutput(null, ex);
                    }
                });

                thread.SetApartmentState(System.Threading.ApartmentState.STA);

                thread.Start();
            }
        }
예제 #4
0
        public void HandleConnectionOpenFetchXmlFile(ConnectionData connectionData)
        {
            CommonConfiguration commonConfig = CommonConfiguration.Get();

            if (connectionData == null)
            {
                if (!HasCurrentCrmConnection(out ConnectionConfiguration crmConfig))
                {
                    return;
                }

                connectionData = crmConfig.CurrentConnectionData;
            }

            if (connectionData != null)
            {
                CheckWishToChangeCurrentConnection(connectionData);

                string selection = GetSelectedText();

                var thread = new System.Threading.Thread(() =>
                {
                    try
                    {
                        var dialog = new WindowSelectEntityName(connectionData, "EntityName", selection);

                        if (dialog.ShowDialog().GetValueOrDefault())
                        {
                            string entityName  = dialog.EntityTypeName;
                            int?entityTypeCode = dialog.EntityTypeCode;

                            connectionData = dialog.GetConnectionData();

                            CheckWishToChangeCurrentConnection(connectionData);

                            var idEntityMetadata = connectionData.GetEntityMetadataId(entityName);

                            if (idEntityMetadata.HasValue)
                            {
                                this.OpenFetchXmlFile(connectionData, commonConfig, entityName);
                            }
                            else
                            {
                                ActivateOutputWindow(connectionData);
                                WriteToOutputEmptyLines(connectionData, commonConfig);

                                try
                                {
                                    Controller.StartOpeningEntityFetchXmlFile(connectionData, commonConfig, entityName, entityTypeCode);
                                }
                                catch (Exception ex)
                                {
                                    WriteErrorToOutput(connectionData, ex);
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        DTEHelper.WriteExceptionToOutput(connectionData, ex);
                    }
                });

                thread.SetApartmentState(System.Threading.ApartmentState.STA);

                thread.Start();
            }
        }
        public void HandleCheckingWorkflowsUsedEntities(ConnectionData connectionData, bool openExplorer)
        {
            CommonConfiguration commonConfig = CommonConfiguration.Get();

            if (connectionData == null)
            {
                if (!HasCurrentCrmConnection(out ConnectionConfiguration crmConfig))
                {
                    return;
                }

                connectionData = crmConfig.CurrentConnectionData;
            }

            if (connectionData != null && commonConfig != null)
            {
                CheckWishToChangeCurrentConnection(connectionData);

                var thread = new System.Threading.Thread(() =>
                {
                    try
                    {
                        var form = new WindowSelectFolderForExport(connectionData, commonConfig.FolderForExport, commonConfig.DefaultFileAction);

                        if (form.ShowDialog().GetValueOrDefault())
                        {
                            commonConfig.FolderForExport   = form.SelectedFolder;
                            commonConfig.DefaultFileAction = form.GetFileAction();

                            connectionData = form.GetConnectionData();

                            if (connectionData != null)
                            {
                                commonConfig.Save();

                                ActivateOutputWindow(connectionData);
                                WriteToOutputEmptyLines(connectionData, commonConfig);

                                CheckWishToChangeCurrentConnection(connectionData);

                                try
                                {
                                    Controller.StartCheckingWorkflowsUsedEntities(connectionData, commonConfig, openExplorer);
                                }
                                catch (Exception ex)
                                {
                                    WriteErrorToOutput(connectionData, ex);
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        DTEHelper.WriteExceptionToOutput(connectionData, ex);
                    }
                });

                thread.SetApartmentState(System.Threading.ApartmentState.STA);

                thread.Start();
            }
        }
        public static void GetFileTypeFullNameInAppDomain()
        {
            try
            {
                var filePath = (string)AppDomain.CurrentDomain.GetData(configFilePath);

                var assembliesProjects = (string[])AppDomain.CurrentDomain.GetData(configAssembliesProjects);
                var assemblies         = (string[])AppDomain.CurrentDomain.GetData(configAssemblies);

                AppDomain.CurrentDomain.SetData(configResult, string.Empty);

                HashSet <string> list = new HashSet <string>(assembliesProjects, StringComparer.InvariantCultureIgnoreCase);

                var resolver = new AssemblyResolver(assembliesProjects.Select(e => Path.GetDirectoryName(e)).ToArray());

                AppDomain.CurrentDomain.ReflectionOnlyAssemblyResolve -= resolver.Domain_ReflectionOnlyAssemblyResolve;
                AppDomain.CurrentDomain.ReflectionOnlyAssemblyResolve -= resolver.Domain_ReflectionOnlyAssemblyResolve;
                AppDomain.CurrentDomain.ReflectionOnlyAssemblyResolve += resolver.Domain_ReflectionOnlyAssemblyResolve;
                AppDomain.CurrentDomain.AssemblyResolve -= resolver.Domain_AssemblyResolve;
                AppDomain.CurrentDomain.AssemblyResolve -= resolver.Domain_AssemblyResolve;
                AppDomain.CurrentDomain.AssemblyResolve += resolver.Domain_AssemblyResolve;

                var hash = new HashSet <string>(StringComparer.InvariantCultureIgnoreCase);

                foreach (var item in assemblies)
                {
                    Assembly assembly = Assembly.ReflectionOnlyLoadFrom(item);

                    if (hash.Add(Path.GetFileName(item)))
                    {
                        list.Add(item);
                    }
                }

                foreach (var item in assemblies)
                {
                    Assembly assembly = Assembly.ReflectionOnlyLoadFrom(item);

                    var files = assembly.GetReferencedAssemblies();

                    foreach (var reference in files)
                    {
                        if (reference.Name != "mscorlib")
                        {
                            var temp = Assembly.ReflectionOnlyLoad(reference.FullName);

                            if (!string.IsNullOrEmpty(temp.CodeBase))
                            {
                                var uri = new Uri(temp.CodeBase);

                                if (hash.Add(Path.GetFileName(uri.LocalPath)))
                                {
                                    list.Add(uri.LocalPath);
                                }
                            }
                        }
                    }
                }

                foreach (var item in assembliesProjects)
                {
                    Assembly assembly = Assembly.ReflectionOnlyLoadFrom(item);

                    if (hash.Add(Path.GetFileName(item)))
                    {
                        list.Add(item);
                    }
                }

                foreach (var item in assembliesProjects)
                {
                    Assembly assembly = Assembly.ReflectionOnlyLoadFrom(item);

                    var files = assembly.GetReferencedAssemblies();

                    foreach (var reference in files)
                    {
                        if (reference.Name != "mscorlib")
                        {
                            var temp = Assembly.ReflectionOnlyLoad(reference.FullName);

                            if (!string.IsNullOrEmpty(temp.CodeBase))
                            {
                                var uri = new Uri(temp.CodeBase);

                                if (hash.Add(Path.GetFileName(uri.LocalPath)))
                                {
                                    list.Add(uri.LocalPath);
                                }
                            }
                        }
                    }
                }

                string code = File.ReadAllText(filePath);

                CompilerParameters parameters = new CompilerParameters()
                {
                    GenerateInMemory   = true,
                    GenerateExecutable = false,
                };

                parameters.ReferencedAssemblies.AddRange(list.ToArray());

                using (CSharpCodeProvider provider = new CSharpCodeProvider())
                {
                    var compilerResults = provider.CompileAssemblyFromSource(parameters, code);

                    if (compilerResults.Errors.Count == 0)
                    {
                        var types = compilerResults.CompiledAssembly.DefinedTypes;

                        AppDomain.CurrentDomain.SetData(configResult, types.FirstOrDefault()?.FullName);
                    }

                    AppDomain.CurrentDomain.AssemblyResolve -= resolver.Domain_AssemblyResolve;
                    AppDomain.CurrentDomain.AssemblyResolve -= resolver.Domain_AssemblyResolve;
                    AppDomain.CurrentDomain.ReflectionOnlyAssemblyResolve -= resolver.Domain_ReflectionOnlyAssemblyResolve;
                    AppDomain.CurrentDomain.ReflectionOnlyAssemblyResolve -= resolver.Domain_ReflectionOnlyAssemblyResolve;
                }
            }
            catch (Exception ex)
            {
                DTEHelper.WriteExceptionToOutput(null, ex);
            }
        }
        private static async Task LoadOrganizationDataAsync(OrganizationServiceExtentedProxy service, OrganizationDetail organizationDetail, WhoAmIResponse whoAmIResponse = null)
        {
            try
            {
                Guid?idOrganization = null;

                if (organizationDetail != null)
                {
                    idOrganization = organizationDetail.OrganizationId;

                    service.ConnectionData.OrganizationInformationExpirationDate = DateTime.Now.AddHours(_hoursOrganizationInformation);

                    service.ConnectionData.FriendlyName        = organizationDetail.FriendlyName;
                    service.ConnectionData.OrganizationId      = organizationDetail.OrganizationId;
                    service.ConnectionData.OrganizationVersion = organizationDetail.OrganizationVersion;
                    service.ConnectionData.OrganizationState   = organizationDetail.State.ToString();
                    service.ConnectionData.UniqueOrgName       = organizationDetail.UniqueName;
                    service.ConnectionData.UrlName             = organizationDetail.UrlName;

                    if (organizationDetail.Endpoints.ContainsKey(EndpointType.OrganizationService))
                    {
                        var organizationUrlEndpoint = organizationDetail.Endpoints[EndpointType.OrganizationService];

                        if (string.IsNullOrEmpty(service.ConnectionData.OrganizationUrl) &&
                            !string.IsNullOrEmpty(organizationUrlEndpoint)
                            )
                        {
                            service.ConnectionData.OrganizationUrl = organizationUrlEndpoint;
                        }
                    }

                    if (organizationDetail.Endpoints.ContainsKey(EndpointType.WebApplication))
                    {
                        var publicUrl = organizationDetail.Endpoints[EndpointType.WebApplication];

                        if (string.IsNullOrEmpty(service.ConnectionData.PublicUrl) &&
                            !string.IsNullOrEmpty(publicUrl)
                            )
                        {
                            service.ConnectionData.PublicUrl = publicUrl;
                        }
                    }
                }

                if (!idOrganization.HasValue)
                {
                    if (whoAmIResponse == null)
                    {
                        whoAmIResponse = await service.ExecuteAsync <WhoAmIResponse>(new WhoAmIRequest());
                    }

                    idOrganization = whoAmIResponse.OrganizationId;
                }

                service.ConnectionData.DefaultLanguage        = string.Empty;
                service.ConnectionData.BaseCurrency           = string.Empty;
                service.ConnectionData.DefaultLanguage        = string.Empty;
                service.ConnectionData.InstalledLanguagePacks = string.Empty;

                if (idOrganization.HasValue)
                {
                    var organization = await service
                                       .RetrieveAsync <Organization>(Organization.EntityLogicalName, idOrganization.Value, new ColumnSet(Organization.Schema.Attributes.languagecode, Organization.Schema.Attributes.basecurrencyid))
                    ;

                    if (organization.BaseCurrencyId != null)
                    {
                        service.ConnectionData.BaseCurrency = organization.BaseCurrencyId.Name;
                    }

                    var request  = new RetrieveInstalledLanguagePacksRequest();
                    var response = await service.ExecuteAsync <RetrieveInstalledLanguagePacksResponse>(request);

                    var rep = new EntityMetadataRepository(service);

                    var isEntityExists = rep.IsEntityExists(LanguageLocale.EntityLogicalName);

                    if (isEntityExists)
                    {
                        var repository = new LanguageLocaleRepository(service);

                        if (organization.LanguageCode.HasValue)
                        {
                            var lang = (await repository.GetListAsync(organization.LanguageCode.Value)).FirstOrDefault();

                            if (lang != null)
                            {
                                service.ConnectionData.DefaultLanguage = lang.ToString();
                            }
                            else
                            {
                                service.ConnectionData.DefaultLanguage = LanguageLocale.GetLocaleName(organization.LanguageCode.Value);
                            }
                        }

                        if (response.RetrieveInstalledLanguagePacks != null && response.RetrieveInstalledLanguagePacks.Any())
                        {
                            var list = await repository.GetListAsync(response.RetrieveInstalledLanguagePacks);

                            service.ConnectionData.InstalledLanguagePacks = string.Join(",", list.OrderBy(s => s.LocaleId.Value, LocaleComparer.Comparer).Select(l => l.ToString()));
                        }
                    }
                    else
                    {
                        if (organization.LanguageCode.HasValue)
                        {
                            service.ConnectionData.DefaultLanguage = LanguageLocale.GetLocaleName(organization.LanguageCode.Value);
                        }

                        if (response.RetrieveInstalledLanguagePacks != null && response.RetrieveInstalledLanguagePacks.Any())
                        {
                            service.ConnectionData.InstalledLanguagePacks = string.Join(",", response.RetrieveInstalledLanguagePacks.OrderBy(s => s, LocaleComparer.Comparer).Select(l => LanguageLocale.GetLocaleName(l)));
                        }
                    }
                }

                if (string.IsNullOrEmpty(service.ConnectionData.PublicUrl) &&
                    !string.IsNullOrEmpty(service.ConnectionData.OrganizationUrl)
                    )
                {
                    var orgUrl = service.ConnectionData.OrganizationUrl.TrimEnd('/');

                    if (orgUrl.EndsWith("/XRMServices/2011/Organization.svc", StringComparison.InvariantCultureIgnoreCase))
                    {
                        var lastIndex = orgUrl.LastIndexOf("/XRMServices/2011/Organization.svc", StringComparison.InvariantCultureIgnoreCase);

                        var publicUrl = orgUrl.Substring(0, lastIndex + 1).TrimEnd('/');

                        service.ConnectionData.PublicUrl = publicUrl;
                    }
                }
            }
            catch (Exception ex)
            {
                DTEHelper.WriteExceptionToOutput(service.ConnectionData, ex);
            }
        }