示例#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);
            }
            //this bit totally fine when you have mapping for say uitls.js defined in mapping file and file on disk by the same name -> code below was throwing an error
            //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 duplicate(s) for mapped web resource \"" + webResourceName + "\"");
            //    }

            //}
            return(mappingList);
        }
示例#2
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);
        }