Пример #1
0
        public void CanResolveFile()
        {
            //dealing with working directory on a non-C location
            var currentDirectory = Environment.CurrentDirectory;
            var driveLetter      = currentDirectory.Substring(0, currentDirectory.IndexOf("\\"));//ignoring UNC paths

            //resharper doesn't support the TestCase attribute
            var values = new Dictionary <string, string>
            {
                { @"C:\testfile.js", @"C:\testfile.js" },
                { @"C:\test\testfile.js", @"C:\test\testfile.js" },
                { @"D:\testfile.js", @"D:\testfile.js" },
                { @"\testfile.js", driveLetter + @"\testfile.js" },
                { @"\test\testfile.js", driveLetter + @"\test\testfile.js" },
                { @"\test\test3\testfile.js", driveLetter + @"\test\test3\testfile.js" },
                { @"testfile.js", Environment.CurrentDirectory + @"\testfile.js" },
                { @"..\testfile.js", Path.GetFullPath(Environment.CurrentDirectory + @"\..\testfile.js") },
                { @"..\..\testfile.js", Path.GetFullPath(Environment.CurrentDirectory + @"\..\..\testfile.js") }
            };

            var fileResolver = new FileResolver();

            foreach (string key in values.Keys)
            {
                var resolvedFile = fileResolver.Resolve(key).ToList();
                Assert.AreEqual(values[key], resolvedFile[0], key);
            }
        }
Пример #2
0
        public void ShouldReadReleaseTrackFile()
        {
            var sut        = new FileResolver();
            var collection = sut.Resolve(@"..\\..\\scenario1");

            Assert.IsTrue(collection.Any());
        }
Пример #3
0
        public void CanResolveFile_Unix()
        {
            var currentDirectory = Environment.CurrentDirectory;

            var values = new Dictionary <string, string>
            {
                { @"testfile.js", Path.Combine(currentDirectory, "testfile.js") },
                { @"/testfile.js", @"/testfile.js" },
                { @"../testfile.js", Path.Combine(currentDirectory.Substring(0, currentDirectory.LastIndexOf("/")), "testfile.js") }
            };

            var fileResolver = new FileResolver();

            foreach (string key in values.Keys)
            {
                var resolvedFile = fileResolver.Resolve(key).ToList();
                Assert.AreEqual(values[key], resolvedFile[0], key);
            }
        }
Пример #4
0
        private List <string> ResolveFilePathsToEmbed(IEnumerable <IntermediateSection> sections)
        {
            var embedFilePaths = new List <string>();

            // Resolve paths to files that are to be embedded in the library.
            if (this.Context.BindFiles)
            {
                var variableResolver = new WixVariableResolver(this.Messaging);

                var fileResolver = new FileResolver(this.Context.BindPaths, this.Context.Extensions);

                foreach (var tuple in sections.SelectMany(s => s.Tuples))
                {
                    foreach (var field in tuple.Fields.Where(f => f?.Type == IntermediateFieldType.Path))
                    {
                        var pathField = field.AsPath();

                        if (pathField != null)
                        {
                            var resolution = variableResolver.ResolveVariables(tuple.SourceLineNumbers, pathField.Path, false);

                            var file = fileResolver.Resolve(tuple.SourceLineNumbers, tuple.Definition, resolution.Value);

                            if (!String.IsNullOrEmpty(file))
                            {
                                // File was successfully resolved so track the embedded index as the embedded file index.
                                field.Set(new IntermediateFieldPathValue {
                                    EmbeddedFileIndex = embedFilePaths.Count
                                });

                                embedFilePaths.Add(file);
                            }
                            else
                            {
                                this.Messaging.Write(ErrorMessages.FileNotFound(tuple.SourceLineNumbers, pathField.Path, tuple.Definition.Name));
                            }
                        }
                    }
                }
            }

            return(embedFilePaths);
        }
Пример #5
0
        private void ResolveFilePathsToEmbed(ILibraryContext context, IEnumerable <IntermediateSection> sections)
        {
            // Resolve paths to files that are to be embedded in the library.
            if (context.BindFiles)
            {
                var variableResolver = this.ServiceProvider.GetService <IVariableResolver>();

                var fileResolver = new FileResolver(context.BindPaths, context.Extensions);

                foreach (var symbol in sections.SelectMany(s => s.Symbols))
                {
                    foreach (var field in symbol.Fields.Where(f => f?.Type == IntermediateFieldType.Path))
                    {
                        var pathField = field.AsPath();

                        if (pathField != null && !String.IsNullOrEmpty(pathField.Path))
                        {
                            var resolution = variableResolver.ResolveVariables(symbol.SourceLineNumbers, pathField.Path);

                            var file = fileResolver.Resolve(symbol.SourceLineNumbers, symbol.Definition, resolution.Value);

                            if (!String.IsNullOrEmpty(file))
                            {
                                // File was successfully resolved so track the embedded index as the embedded file index.
                                field.Set(new IntermediateFieldPathValue {
                                    Embed = true, Path = file
                                });
                            }
                            else
                            {
                                this.Messaging.Write(ErrorMessages.FileNotFound(symbol.SourceLineNumbers, pathField.Path, symbol.Definition.Name));
                            }
                        }
                    }
                }
            }
        }