Пример #1
0
        public Dictionary <string, string> LoadMappings(Project project)
        {
            var projectRootPath = projectHelper.GetProjectRoot(project);
            var projectFiles    = projectHelper.GetProjectFiles(project);
            var mappingFilePath = this.GetMappingFilePath(project);

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

            var mappingList = new Dictionary <string, string>();

            XDocument doc      = XDocument.Load(mappingFilePath);
            var       mappings = doc.Descendants("Mapping");

            foreach (var mapping in mappings)
            {
                var shortScriptPath = mapping.Attribute("localPath") == null ? null : mapping.Attribute("localPath").Value;
                shortScriptPath = shortScriptPath ?? (mapping.Attribute("scriptPath") == null ? null : mapping.Attribute("scriptPath").Value);
                if (shortScriptPath == null)
                {
                    throw new ArgumentNullException("Mappings contains 'Mapping' tag without 'localPath' attribute");
                }
                var scriptPath = projectRootPath + "\\" + shortScriptPath;
                scriptPath = scriptPath.ToLower();
                var webResourceName = mapping.Attribute("webResourceName") == null ? null : mapping.Attribute("webResourceName").Value;
                if (webResourceName == null)
                {
                    throw new ArgumentNullException("Mappings contains 'Mapping' tag without 'webResourceName' attribute");
                }
                if (mappingList.ContainsKey(scriptPath))
                {
                    throw new ArgumentException("Mappings contains dublicate for \"" + shortScriptPath + "\"");
                }
                projectFiles.RemoveAll(x => x.ToLower() == scriptPath);
                mappingList.Add(scriptPath, webResourceName);
            }
            foreach (var mapping in mappingList)
            {
                var scriptPath               = mapping.Key;
                var webResourceName          = mapping.Value;
                var projectMappingDublicates = projectFiles.Where(x => Path.GetFileName(x).ToLower() == webResourceName.ToLower());
                if (projectMappingDublicates.Count() > 0)
                {
                    throw new ArgumentException("Project contains dublicate(s) for mapped web resource \"" + webResourceName + "\"");
                }
            }
            return(mappingList);
        }
Пример #2
0
        public static Dictionary <string, string> LoadMappings(Project project)
        {
            var mappingFilePath = GetMappingFilePath(project);

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

            var projectRootPath = ProjectHelper.GetProjectRoot(project);
            var projectFiles    = ProjectHelper.GetProjectFiles(project.ProjectItems);
            var mappingList     = new Dictionary <string, string>();

            XDocument doc      = XDocument.Load(mappingFilePath);
            var       mappings = doc.Descendants("Mapping");

            foreach (var mapping in mappings)
            {
                var shortScriptPath = mapping.Attribute("localPath")?.Value;
                shortScriptPath = shortScriptPath ?? mapping.Attribute("scriptPath")?.Value;
                if (shortScriptPath == null)
                {
                    throw new ArgumentNullException("Mappings contains 'Mapping' tag without 'localPath' attribute");
                }
                var scriptPath = projectRootPath + "\\" + shortScriptPath;
                scriptPath = scriptPath.ToLower();
                var webResourceName = mapping.Attribute("webResourceName")?.Value;
                if (webResourceName == null)
                {
                    throw new ArgumentNullException("Mappings contains 'Mapping' tag without 'webResourceName' attribute");
                }
                if (mappingList.ContainsKey(scriptPath))
                {
                    throw new ArgumentException($"Mappings contains dublicate for \"{shortScriptPath}\"");
                }
                projectFiles.RemoveAll(x => x.ToLower() == scriptPath);
                mappingList.Add(scriptPath, webResourceName);
            }
            foreach (var mapping in mappingList)
            {
                var webResourceName             = mapping.Value;
                var hasProjectMappingDublicates = projectFiles.Any(x => string.Equals(Path.GetFileName(x), webResourceName, StringComparison.OrdinalIgnoreCase));
                if (hasProjectMappingDublicates)
                {
                    throw new ArgumentException($"Project contains dublicate(s) for mapped web resource \"{webResourceName}\"");
                }
            }
            return(mappingList);
        }
Пример #3
0
        public static string GetMappingFilePath(Project project)
        {
            var projectFiles = ProjectHelper.GetProjectFiles(project.ProjectItems);

            if (projectFiles == null || projectFiles.Count == 0)
            {
                return(null);
            }
            foreach (var file in projectFiles)
            {
                if (string.Equals(Path.GetFileName(file), Settings.MappingFileName, StringComparison.OrdinalIgnoreCase))
                {
                    return(file.ToLower());
                }
            }
            return(null);
        }