Exemple #1
0
        public static CrmDevExAssembly HandleMappings(string solutionPath, Project project, Guid organizationId, ObservableCollection <CrmSolution> solutions, ObservableCollection <CrmAssembly> assemblies)
        {
            CrmDexExConfig       crmDexExConfig       = CrmDeveloperExtensions2.Core.Config.Mapping.GetConfigFile(solutionPath, project.UniqueName, organizationId);
            CrmDevExConfigOrgMap crmDevExConfigOrgMap = CrmDeveloperExtensions2.Core.Config.Mapping.GetOrgMap(ref crmDexExConfig, organizationId, project.UniqueName);

            CrmDevExAssembly crmDevExAssembly = crmDevExConfigOrgMap.Assembly;

            if (crmDevExAssembly == null)
            {
                return(null);
            }

            if (assemblies.Count(a => a.AssemblyId == crmDevExAssembly.AssemblyId) < 1)
            {
                crmDevExConfigOrgMap.Assembly = null;

                ConfigFile.UpdateConfigFile(solutionPath, crmDexExConfig);

                return(null);
            }

            if (solutions.Count(s => s.SolutionId == crmDevExAssembly.SolutionId) >= 1)
            {
                return(crmDevExAssembly);
            }

            crmDevExAssembly.SolutionId = solutions[0].SolutionId; //Default

            ConfigFile.UpdateConfigFile(solutionPath, crmDexExConfig);

            return(crmDevExAssembly);
        }
        public static void AddOrUpdateMapping(string solutionPath, Project project, CrmDevExSolutionPackage solutionPackage, Guid organizationId)
        {
            CrmDexExConfig crmDexExConfig = CoreMapping.GetConfigFile(solutionPath, project.UniqueName, organizationId);
            CrmDevExConfigOrgMap crmDevExConfigOrgMap = CoreMapping.GetOrgMap(ref crmDexExConfig, organizationId, project.UniqueName);

            crmDevExConfigOrgMap.SolutionPackage = solutionPackage;

            ConfigFile.UpdateConfigFile(solutionPath, crmDexExConfig);
        }
        public static void RemoveMappings(string solutionPath, Project project, List <CrmDexExConfigWebResource> crmDexExConfigWebResources, Guid organizationId)
        {
            CrmDexExConfig       crmDexExConfig       = GetConfigFile(solutionPath, project.UniqueName, organizationId);
            CrmDevExConfigOrgMap crmDevExConfigOrgMap = GetOrgMap(ref crmDexExConfig, organizationId, project.UniqueName);

            crmDevExConfigOrgMap.WebResources.RemoveAll(
                w => crmDexExConfigWebResources.Any(m => m.WebResourceId == w.WebResourceId));

            ConfigFile.UpdateConfigFile(solutionPath, crmDexExConfig);
        }
        private static void UpdateMapping(CrmDexExConfig crmDexExConfig, string solutionPath, Project project, WebResourceItem webResourceItem, Guid organizationId)
        {
            CrmDevExConfigOrgMap crmDevExConfigOrgMap = GetOrgMap(ref crmDexExConfig, organizationId, project.UniqueName);

            List <CrmDexExConfigWebResource> crmDexExConfigWebResources = crmDevExConfigOrgMap.WebResources.Where(w => w.WebResourceId == webResourceItem.WebResourceId).ToList();

            crmDexExConfigWebResources.ForEach(w => w.File = webResourceItem.BoundFile);
            crmDevExConfigOrgMap.WebResources.RemoveAll(w => string.IsNullOrEmpty(w.File));

            ConfigFile.UpdateConfigFile(solutionPath, crmDexExConfig);
        }
        public static ObservableCollection <WebResourceItem> HandleMappings(string solutionPath, Project project, ObservableCollection <WebResourceItem> webResourceItems, Guid organizationId)
        {
            CrmDexExConfig       crmDexExConfig       = CrmDeveloperExtensions2.Core.Config.Mapping.GetConfigFile(solutionPath, project.UniqueName, organizationId);
            CrmDevExConfigOrgMap crmDevExConfigOrgMap = CrmDeveloperExtensions2.Core.Config.Mapping.GetOrgMap(ref crmDexExConfig, organizationId, project.UniqueName);

            if (crmDevExConfigOrgMap.WebResources == null)
            {
                crmDevExConfigOrgMap.WebResources = new List <CrmDexExConfigWebResource>();
            }

            List <CrmDexExConfigWebResource> mappingsToRemove = new List <CrmDexExConfigWebResource>();

            //Remove mappings where CRM web resource was deleted
            List <CrmDexExConfigWebResource> mappedWebResources = crmDevExConfigOrgMap.WebResources;

            foreach (CrmDexExConfigWebResource crmDexExConfigWebResource in mappedWebResources)
            {
                if (webResourceItems.Count(w => w.WebResourceId == crmDexExConfigWebResource.WebResourceId) != 0)
                {
                    continue;
                }

                mappingsToRemove.Add(crmDexExConfigWebResource);
                mappedWebResources.Remove(crmDexExConfigWebResource);
            }

            //Add bound file from mapping
            foreach (CrmDexExConfigWebResource crmDexExConfigWebResource in mappedWebResources)
            {
                if (webResourceItems.Count(w => w.WebResourceId == crmDexExConfigWebResource.WebResourceId) > 0)
                {
                    webResourceItems.Where(w => w.WebResourceId == crmDexExConfigWebResource.WebResourceId).ToList()
                    .ForEach(w => w.BoundFile = crmDexExConfigWebResource.File);
                }
            }

            //Remove mappings where project file was deleted
            foreach (CrmDexExConfigWebResource crmDexExConfigWebResource in mappedWebResources)
            {
                string mappedFilePath = FileSystem.BoundFileToLocalPath(crmDexExConfigWebResource.File, project.FullName);
                if (!File.Exists(mappedFilePath))
                {
                    mappingsToRemove.Add(crmDexExConfigWebResource);
                    webResourceItems.Where(w => w.BoundFile == crmDexExConfigWebResource.File).ToList().ForEach(w => w.BoundFile = null);
                }
            }

            if (mappingsToRemove.Count > 0)
            {
                RemoveMappings(solutionPath, project, mappingsToRemove, organizationId);
            }

            return(webResourceItems);
        }
        private static void AddMapping(CrmDexExConfig crmDexExConfig, string solutionPath, Project project, WebResourceItem webResourceItem, Guid organizationId)
        {
            CrmDevExConfigOrgMap crmDevExConfigOrgMap = GetOrgMap(ref crmDexExConfig, organizationId, project.UniqueName);

            CrmDexExConfigWebResource crmDexExConfigWebResource = new CrmDexExConfigWebResource
            {
                WebResourceId = webResourceItem.WebResourceId,
                File          = webResourceItem.BoundFile
            };

            crmDevExConfigOrgMap.WebResources.Add(crmDexExConfigWebResource);

            ConfigFile.UpdateConfigFile(solutionPath, crmDexExConfig);
        }
        private static CrmDevExConfigOrgMap GetOrgMap(ref CrmDexExConfig crmDexExConfig, Guid organizationId, string projectUniqueName)
        {
            CrmDevExConfigOrgMap orgMap = crmDexExConfig.CrmDevExConfigOrgMaps.FirstOrDefault(o => o.OrganizationId == organizationId);

            if (orgMap != null)
            {
                return(orgMap);
            }

            orgMap = new CrmDevExConfigOrgMap
            {
                OrganizationId    = organizationId,
                ProjectUniqueName = projectUniqueName,
                WebResources      = new List <CrmDexExConfigWebResource>()
            };

            crmDexExConfig.CrmDevExConfigOrgMaps.Add(orgMap);

            return(orgMap);
        }
        public static CrmDevExSolutionPackage HandleMappings(string solutionPath, Project project, ObservableCollection<CrmSolution> crmSolutions, Guid organizationId)
        {
            CrmDexExConfig crmDexExConfig = CoreMapping.GetConfigFile(solutionPath, project.UniqueName, organizationId);
            CrmDevExConfigOrgMap crmDevExConfigOrgMap = CoreMapping.GetOrgMap(ref crmDexExConfig, organizationId, project.UniqueName);

            if (crmDevExConfigOrgMap.SolutionPackage == null)
                return null;

            foreach (CrmSolution crmSolution in crmSolutions)
            {
                if (crmSolution.SolutionId == crmDevExConfigOrgMap.SolutionPackage.SolutionId)
                    return crmDevExConfigOrgMap.SolutionPackage;
            }

            crmDevExConfigOrgMap.SolutionPackage = null;

            ConfigFile.UpdateConfigFile(solutionPath, crmDexExConfig);

            return null;
        }
Exemple #9
0
        public static void AddOrUpdateMapping(string solutionPath, Project project, Guid assemblyId, Guid solutionId, int deploymentType, bool backupFiles, Guid organizationId)
        {
            CrmDexExConfig       crmDexExConfig       = CrmDeveloperExtensions2.Core.Config.Mapping.GetConfigFile(solutionPath, project.UniqueName, organizationId);
            CrmDevExConfigOrgMap crmDevExConfigOrgMap = CrmDeveloperExtensions2.Core.Config.Mapping.GetOrgMap(ref crmDexExConfig, organizationId, project.UniqueName);

            if (assemblyId != Guid.Empty)
            {
                CrmDevExAssembly crmDevExAssembly = new CrmDevExAssembly
                {
                    AssemblyId     = assemblyId,
                    SolutionId     = solutionId,
                    DeploymentType = deploymentType,
                    BackupFiles    = backupFiles
                };
                crmDevExConfigOrgMap.Assembly = crmDevExAssembly;
            }
            else
            {
                crmDevExConfigOrgMap.Assembly = null;
            }

            ConfigFile.UpdateConfigFile(solutionPath, crmDexExConfig);
        }
        public static void AddOrUpdateMapping(string solutionPath, Project project, WebResourceItem webResourceItem, Guid organizationId)
        {
            CrmDexExConfig       crmDexExConfig       = GetConfigFile(solutionPath, project.UniqueName, organizationId);
            CrmDevExConfigOrgMap crmDevExConfigOrgMap = GetOrgMap(ref crmDexExConfig, organizationId, project.UniqueName);

            List <CrmDexExConfigWebResource> crmDexExConfigWebResources = crmDevExConfigOrgMap.WebResources;

            if (crmDexExConfigWebResources == null)
            {
                crmDevExConfigOrgMap.WebResources = new List <CrmDexExConfigWebResource>();
            }

            CrmDexExConfigWebResource crmDexExConfigWebResource =
                crmDevExConfigOrgMap.WebResources.FirstOrDefault(w => w.WebResourceId == webResourceItem.WebResourceId);

            if (crmDexExConfigWebResource == null)
            {
                AddMapping(crmDexExConfig, solutionPath, project, webResourceItem, organizationId);
            }
            else
            {
                UpdateMapping(crmDexExConfig, solutionPath, project, webResourceItem, organizationId);
            }
        }