private static void AddSpklMapping(SpklConfig spklConfig, Project project, string profile, WebResourceItem webResourceItem)
        {
            var spklConfigWebresourceFile = new SpklConfigWebresourceFile
            {
                uniquename  = webResourceItem.Name,
                file        = webResourceItem.BoundFile,
                description = webResourceItem.Description
            };

            if (WebResourceTypes.GetExtensionType(webResourceItem.BoundFile) == D365DeveloperExtensions.Core.Enums.FileExtensionType.Ts)
            {
                spklConfigWebresourceFile.file = TsHelper.GetJsForTsPath(webResourceItem.BoundFile, project);
                spklConfigWebresourceFile.ts   = webResourceItem.BoundFile;
            }

            if (profile.StartsWith(ExtensionConstants.NoProfilesText))
            {
                spklConfig.webresources[0].files.Add(spklConfigWebresourceFile);
            }
            else
            {
                spklConfig.webresources.FirstOrDefault(w => w.profile == profile)?.files.Add(spklConfigWebresourceFile);
            }

            var projectPath = D365DeveloperExtensions.Core.Vs.ProjectWorker.GetProjectPath(project);

            ConfigFile.UpdateSpklConfigFile(projectPath, spklConfig);
        }
        public void NoVersion()
        {
            const int majorVersion = 0;
            ObservableCollection <WebResourceType> types = WebResourceTypes.GetTypes(majorVersion, false);

            var min = types.Count(t => t.CrmMinimumMajorVersion > majorVersion);
            var max = types.Count(t => t.CrmMaximumMajorVersion < majorVersion);

            Assert.IsTrue(min == 0 && max == 0 && types.Count == 0);
        }
Beispiel #3
0
 public int GetWebResourceType(string extention)
 {
     if (extention != null && extention.StartsWith("."))
     {
         extention = extention.Substring(1);
     }
     if (WebResourceTypes.ContainsKey(extention))
     {
         return(WebResourceTypes[extention]);
     }
     throw new NotSupportedException(string.Format("No matching web resource type implemented for extention {0}", extention));
 }
        public static string AddMissingExtension(string name, int webResourceType)
        {
            if (!string.IsNullOrEmpty(Path.GetExtension(name)))
            {
                return(name);
            }

            string ext = WebResourceTypes.GetWebResourceTypeNameByNumber(webResourceType.ToString()).ToLower();

            name += "." + ext;

            return(name);
        }
        private static void UpdateSpklMapping(SpklConfig spklConfig, Project project, string profile, WebResourceItem webResourceItem)
        {
            var spklConfigWebresourceFiles = GetSpklConfigWebresourceFiles(profile, spklConfig);

            if (spklConfigWebresourceFiles == null)
            {
                return;
            }

            if (!string.IsNullOrEmpty(webResourceItem.BoundFile))
            {
                var isTs = WebResourceTypes.GetExtensionType(webResourceItem.BoundFile) == D365DeveloperExtensions.Core.Enums.FileExtensionType.Ts;
                foreach (var spklConfigWebresourceFile in
                         spklConfigWebresourceFiles.Where(w => w.uniquename == webResourceItem.Name))
                {
                    spklConfigWebresourceFile.file        = webResourceItem.BoundFile;
                    spklConfigWebresourceFile.description = webResourceItem.Description;
                    spklConfigWebresourceFile.ts          = null;

                    if (!isTs)
                    {
                        continue;
                    }

                    spklConfigWebresourceFile.file = TsHelper.GetJsForTsPath(webResourceItem.BoundFile, project);
                    spklConfigWebresourceFile.ts   = webResourceItem.BoundFile;
                }
            }
            else
            {
                spklConfigWebresourceFiles.RemoveAll(w => w.uniquename == webResourceItem.Name);
            }

            if (profile.StartsWith(ExtensionConstants.NoProfilesText))
            {
                spklConfig.webresources[0].files = spklConfigWebresourceFiles;
            }
            else
            {
                var webresourceDeployConfig = spklConfig.webresources.FirstOrDefault(w => w.profile == profile);
                if (webresourceDeployConfig != null)
                {
                    webresourceDeployConfig.files = spklConfigWebresourceFiles;
                }
            }

            var projectPath = D365DeveloperExtensions.Core.Vs.ProjectWorker.GetProjectPath(project);

            ConfigFile.UpdateSpklConfigFile(projectPath, spklConfig);
        }
        public static WebResourceItem WebResourceItemFromNew(NewWebResource newWebResource, Guid solutionId)
        {
            WebResourceItem webResourceItem = new WebResourceItem
            {
                WebResourceId       = newWebResource.NewId,
                Name                = newWebResource.NewName,
                DisplayName         = newWebResource.NewDisplayName,
                TypeName            = WebResourceTypes.GetWebResourceTypeNameByNumber(newWebResource.NewType.ToString()),
                Type                = newWebResource.NewType,
                SolutionId          = solutionId,
                Description         = newWebResource.NewDescription,
                PreviousDescription = newWebResource.NewDescription,
                IsManaged           = false
            };

            return(webResourceItem);
        }
        private static string GetFileContent(string filePath)
        {
            FileExtensionType extension = WebResourceTypes.GetExtensionType(filePath);

            string content;

            //Images
            if (WebResourceTypes.IsImageType(extension))
            {
                content = EncodedImage(filePath, extension);
                return(content);
            }

            //Everything else
            content = File.ReadAllText(filePath);

            return(EncodeString(content));
        }
        private static string GetFileContent(string filePath, Project project)
        {
            FileExtensionType extension = WebResourceTypes.GetExtensionType(filePath);

            //Images
            if (WebResourceTypes.IsImageType(extension))
            {
                var content = EncodedImage(filePath, extension);
                return(content);
            }

            //TypeScript
            if (extension == FileExtensionType.Ts)
            {
                string jsPath = TsHelper.GetJsForTsPath(filePath, project);
                jsPath = FileSystem.BoundFileToLocalPath(jsPath,
                                                         D365DeveloperExtensions.Core.Vs.ProjectWorker.GetProjectPath(project));
                return(GetNonImageFileContext(jsPath));
            }

            //Everything else
            return(GetNonImageFileContext(filePath));
        }
        public static ObservableCollection <WebResourceItem> CreateWebResourceItemView(EntityCollection webResources, string projectName)
        {
            ObservableCollection <WebResourceItem> webResourceItems = new ObservableCollection <WebResourceItem>();

            foreach (Entity webResource in webResources.Entities)
            {
                WebResourceItem webResourceItem = new WebResourceItem
                {
                    WebResourceId = (Guid)webResource.GetAttributeValue <AliasedValue>("webresource.webresourceid").Value,
                    Name          = webResource.GetAttributeValue <AliasedValue>("webresource.name").Value.ToString(),
                    IsManaged     = (bool)webResource.GetAttributeValue <AliasedValue>("webresource.ismanaged").Value,
                    TypeName      = WebResourceTypes.GetWebResourceTypeNameByNumber(((OptionSetValue)webResource.GetAttributeValue <AliasedValue>("webresource.webresourcetype").Value).Value.ToString()),
                    Type          = ((OptionSetValue)webResource.GetAttributeValue <AliasedValue>("webresource.webresourcetype").Value).Value,
                    SolutionId    = webResource.GetAttributeValue <EntityReference>("solutionid").Id
                };

                bool hasDescription = webResource.Attributes.TryGetValue("webresource.description", out var description);
                if (hasDescription)
                {
                    webResourceItem.Description         = ((AliasedValue)description).Value.ToString();
                    webResourceItem.PreviousDescription = webResourceItem.Description;
                }

                bool hasDisplayName = webResource.Attributes.TryGetValue("webresource.displayname", out var displayName);
                if (hasDisplayName)
                {
                    webResourceItem.DisplayName = ((AliasedValue)displayName).Value.ToString();
                }

                webResourceItems.Add(webResourceItem);
            }

            webResourceItems = new ObservableCollection <WebResourceItem>(webResourceItems.OrderBy(w => w.Name));

            return(webResourceItems);
        }