Example #1
0
        private string GetOutputPath(string sourcePath, BatchCompileConfiguration compileConfiguration)
        {
            if (sourcePath.IndexOf(compileConfiguration.SourceDirectory, StringComparison.OrdinalIgnoreCase) >= 0)
            {
                var relativePath = FileProbe.GetRelativePath(compileConfiguration.SourceDirectory, sourcePath);
                var outputPath   = Path.Combine(compileConfiguration.OutDirectory, relativePath);
                outputPath = Path.ChangeExtension(outputPath, ".js");
                return(outputPath);
            }
            else
            {
                ChutzpahTracer.TraceWarning(
                    "Can't find location for generated path on {0} since it is not inside of configured source dir {1}",
                    sourcePath,
                    compileConfiguration.SourceDirectory);
            }

            return(null);
        }
Example #2
0
        /// <summary>
        /// Is this a source mapping for the current referenced file
        /// </summary>
        private bool IsCurrentFile(string relativePath, ReferencedFile referencedFile)
        {
            var candidatePath = FileProbe.NormalizeFilePath(new Uri(Path.Combine(Path.GetDirectoryName(referencedFile.SourceMapFilePath), relativePath)).AbsolutePath);

            return(referencedFile.Path.Equals(candidatePath, StringComparison.OrdinalIgnoreCase));
        }
Example #3
0
        public void Test_MaxFileSize()
        {
            var testDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Test");

            Directory.CreateDirectory(testDirectory);
            var testFile = Path.Combine(testDirectory, "Hello.txt");

            if (File.Exists(testFile))
            {
                File.Delete(testFile);
            }

            // Setup ConfigurationManager
            Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

            config.Sections.Clear();
            config.SectionGroups.Clear();
            DefaultSection section = new DefaultSection();
            string         rawXml  =
                @"<Test.FileProbe>
            <add key=""FileName"" value=""{0}""/>
            <add key=""MaxFileSize"" value=""0""/>
            <add key=""MaxFileAge"" value=""1""/>
            <add key=""EventId"" value=""30""/>
            <add key=""EventType"" value=""Warning""/>
            <add key=""ProbeFrequency"" value=""10""/>
            </Test.FileProbe>";

            rawXml = string.Format(rawXml, testFile);

            section.SectionInformation.SetRawXml(rawXml);
            section.SectionInformation.Type = typeof(NameValueSectionHandler).FullName;
            config.Sections.Add("Test.FileProbe", section);
            config.Save();
            ConfigurationManager.RefreshSection("Test.FileProbe");

            FileProbe fileProbe   = new FileProbe();
            var       traceSource = fileProbe.ConfigureProbe("Test.FileProbe");

            traceSource.Switch = new SourceSwitch("Test.FileProbe")
            {
                Level = SourceLevels.All
            };

            FileProbeTestListener probeListener = new FileProbeTestListener();

            traceSource.Listeners.Clear();
            traceSource.Listeners.Add(probeListener);
            fileProbe.ExecuteProbe();

            Assert.AreEqual(TraceEventType.Critical, probeListener.TriggeredEvent, "Failed to detect missing file");

            File.Create(testFile).Dispose();
            fileProbe.ExecuteProbe();
            Assert.AreEqual(TraceEventType.Information, probeListener.TriggeredEvent, "Failed to detect file");

            System.Threading.Thread.Sleep(2000);
            fileProbe.ExecuteProbe();
            Assert.AreEqual(TraceEventType.Warning, probeListener.TriggeredEvent, "Failed to detect old file");

            File.WriteAllText(testFile, "");
            fileProbe.ExecuteProbe();
            Assert.AreEqual(TraceEventType.Information, probeListener.TriggeredEvent, "Failed to detect new file");

            File.WriteAllText(testFile, "Error");
            fileProbe.ExecuteProbe();
            Assert.AreEqual(TraceEventType.Warning, probeListener.TriggeredEvent, "Failed to detect large file");
        }
Example #4
0
        public bool IsIgnored(string filePath)
        {
            // If no ignore pattern is given then include all files. Otherwise ignore the ones that match an ignore pattern
            if (ignorePatterns.Any() && ignorePatterns.Any(ignorePattern => NativeImports.PathMatchSpec(filePath, FileProbe.NormalizeFilePath(ignorePattern))))
            {
                return(true);
            }

            return(false);
        }
Example #5
0
        private bool IsFileEligibleForInstrumentation(string filePath)
        {
            // If no include patterns are given then include all files. Otherwise include only the ones that match an include pattern
            if (includePatterns.Any() && !includePatterns.Any(includePattern => NativeImports.PathMatchSpec(filePath, FileProbe.NormalizeFilePath(includePattern))))
            {
                return(false);
            }

            // If no exclude pattern is given then exclude none otherwise exclude the patterns that match any given exclude pattern
            if (excludePatterns.Any() && excludePatterns.Any(excludePattern => NativeImports.PathMatchSpec(filePath, FileProbe.NormalizeFilePath(excludePattern))))
            {
                return(false);
            }

            return(true);
        }
        private string GetOutputPath(string filePath, BatchCompileConfiguration compileConfiguration)
        {
            foreach (var pathMap in compileConfiguration.Paths)
            {
                if (filePath.IndexOf(pathMap.SourcePath, StringComparison.OrdinalIgnoreCase) >= 0)
                {
                    // If the configured sourcePath is a full file path we just assume the fileName is the relative name
                    // Otherwise we calculate the relative path from the configured sourcePath to the current file
                    var relativePath = pathMap.SourcePathIsFile ? Path.GetFileName(pathMap.SourcePath) : FileProbe.GetRelativePath(pathMap.SourcePath, filePath);

                    string outputPath = pathMap.OutputPath;
                    if (!pathMap.OutputPathIsFile)
                    {
                        // If output path is not a file we calculate the file path using the input filePath's relative location compared
                        // to the output directory
                        outputPath = Path.Combine(outputPath, relativePath);
                        outputPath = Path.ChangeExtension(outputPath, ".js");
                    }

                    return(outputPath);
                }
            }

            ChutzpahTracer.TraceError("Can't find location for generated path on {0}", filePath);

            return(null);
        }
Example #7
0
        public void LaunchTest(TestContext testContext)
        {
            // Start IE.
            ProcessStartInfo startInfo = new ProcessStartInfo()
            {
                UseShellExecute = true,
                FileName        = BrowserPathHelper.GetBrowserPath("ie"),
                Arguments       = string.Format("-noframemerging -suspended -debug {0}", FileProbe.GenerateFileUrl(testContext.TestHarnessPath))
                                  // -noframemerging
                                  //      This is what VS does when launching the script debugger.
                                  //      Unsure whether strictly necessary.
                                  // -suspended
                                  //      This is what VS does when launching the script debugger.
                                  //      Seems to cause IE to suspend all threads which is what we want.
                                  // -debug
                                  //      This is what VS does when launching the script debugger.
                                  //      Not sure exactly what it does.
            };
            Process ieMainProcess = Process.Start(startInfo);

            // Get child 'tab' process spawned by IE.
            // We need to wait a few ms for IE to open the process.
            Process ieTabProcess = null;

            for (int i = 0;; ++i)
            {
                System.Threading.Thread.Sleep(10);
                ieTabProcess = ProcessExtensions.FindFirstChildProcessOf(ieMainProcess.Id);
                if (ieTabProcess != null)
                {
                    break;
                }
                if (i > 400)   // 400 * 10 = 4s timeout
                {
                    throw new InvalidOperationException("Timeout waiting for Internet Explorer child process to start.");
                }
            }

            // Debug the script in that tab process.
            DteHelpers.DebugAttachToProcess(ieTabProcess.Id, "script");

            // Resume the threads in the IE process which where started off suspended.
            ieTabProcess.Resume();
        }