public SingleTestRunBase Load(FileInfoBase fileInfo)
        {
            var document = this.ReadResultsFile(fileInfo);
            var features = this.ToFeatures(document);

            return new SpecRunSingleResults(features);
        }
        private XDocument ReadResultsFile(FileInfoBase testResultsFile)
        {
            XDocument document;
            using (var stream = testResultsFile.OpenRead())
            {
                using (var streamReader = new System.IO.StreamReader(stream))
                {
                    string content = streamReader.ReadToEnd();

                    int begin = content.IndexOf("<!-- Pickles Begin", StringComparison.Ordinal);

                    content = content.Substring(begin);

                    content = content.Replace("<!-- Pickles Begin", string.Empty);

                    int end = content.IndexOf("Pickles End -->", System.StringComparison.Ordinal);

                    content = content.Substring(0, end);

                    content = content.Replace("&lt;", "<").Replace("&gt;", ">");

                    var xmlReader = XmlReader.Create(new System.IO.StringReader(content));
                    document = XDocument.Load(xmlReader);
                }
            }

            return document;
        }
        public SpecRunSingleResults(FileInfoBase fileInfo)
        {
            var resultsDocument = this.ReadResultsFile(fileInfo);

            this.specRunFeatures =
                resultsDocument.Descendants("feature").Select(Parser.SpecRun.Factory.ToSpecRunFeature).ToList();
        }
Esempio n. 4
0
        public static string MakeRelativePath(DirectoryInfoBase fromPath, FileInfoBase toPath)
        {
            if (fromPath == null) throw new ArgumentNullException("fromPath");
            if (toPath == null) throw new ArgumentNullException("toPath");

            string root = fromPath.FullName;
            if (!(root.EndsWith("\\") || root.EndsWith("/")))
                root += "\\";
            root += "a.txt";

            Uri fromUri = new Uri(root);
            Uri toUri = new Uri(toPath.FullName);

            if (fromUri.Scheme != toUri.Scheme) { return toPath.FullName; } // path can't be made relative.

            Uri relativeUri = fromUri.MakeRelativeUri(toUri);
            string relativePath = Uri.UnescapeDataString(relativeUri.ToString());

            if (toUri.Scheme.ToUpperInvariant() == "FILE")
            {
                relativePath = relativePath.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar);
            }

            return relativePath;
        }
        public void Setup()
        {
            this._testFeature = new Feature { Name = "Test" };
            this._featureFileInfo = this.FileSystem.FileInfo.FromFileName(FileSystem.Path.Combine(ROOT_PATH, FEATURE_PATH));
            this._featureDirectoryNode = new FeatureNode(this._featureFileInfo, RELATIVE_PATH, this._testFeature);

            this._featureWithMeta = new FeatureWithMetaInfo(this._featureDirectoryNode);
        }
        public void Setup()
        {
            this.testFeature = new Feature { Name = "Test" };
            this.featureFileInfo = this.FileSystem.FileInfo.FromFileName(FileSystem.Path.Combine(RootPath, FeaturePath));
            this.featureDirectoryNode = new FeatureNode(this.featureFileInfo, RelativePath, this.testFeature);

            this.featureWithMeta = new JsonFeatureWithMetaInfo(this.featureDirectoryNode);
        }
Esempio n. 7
0
        public XDocument Load(FileInfoBase fileInfo)
        {
            XDocument document;
            using (var stream = fileInfo.OpenRead())
            {
                document = this.Load(stream);
            }

            return document;
        }
Esempio n. 8
0
 public static void AddFile(this ZipArchive zipArchive, FileInfoBase file, string directoryNameInArchive)
 {
     string fileName = Path.Combine(directoryNameInArchive, file.Name);
     ZipArchiveEntry entry = zipArchive.CreateEntry(fileName, CompressionLevel.Fastest);
     using (Stream zipStream = entry.Open(),
                   fileStream = file.OpenRead())
     {
         fileStream.CopyTo(zipStream);
     }
 }
Esempio n. 9
0
 private void AddTestResultFileIfItExists(FileInfoBase fileInfoBase)
 {
     if (fileInfoBase.Exists)
     {
         this.testResultsFiles.Add(fileInfoBase);
     }
     else
     {
         Log.Error("A test result file could not be found, it will be skipped: {0}", fileInfoBase.FullName);
     }
 }
Esempio n. 10
0
        private void StreamFile(FileInfoBase file)
        {
            // Set varaibles.
            const int bufferReadSize = 1024 * 8;
            var fileSize = file.Length;
            long start = 0;
            long end = fileSize - 1;

            // Check if range specified.
            if(Request.Headers.AllKeys.Contains("Range"))
            {
                // Extract range details.
                var range = Request.Headers.Get("Range");
                var rangeRegex = new Regex(@"^bytes=(\d+)-(\d*)", RegexOptions.IgnoreCase);
                var match = rangeRegex.Match(range);

                // Extract start.
                if(match.Groups.Count>1 && !string.IsNullOrEmpty(match.Groups[1].Value))
                {
                    long.TryParse(match.Groups[1].Value, out start);
                }

                // Extract end.
                if(match.Groups.Count>2 && !string.IsNullOrEmpty(match.Groups[2].Value))
                {
                    long.TryParse(match.Groups[2].Value, out end);
                }

                // Check if Offset is valid.
                if(start < 0 || start > end)
                {
                    Response.StatusCode = 416;
                    Response.StatusDescription = "Requested Range Not Satisfiable";
                    Response.End();
                    return;
                }
            }

            if(start != 0)
            {
                Response.StatusCode = 206;
                Response.StatusDescription = "Partial Content";
            }

            // Set headers.
            Response.ContentType = file.Name.ResoveContentType();
            Response.AddHeader("Accept-Ranges", "bytes");
            Response.AddHeader("Content-Range", string.Format("bytes {0}-{1}/{2}", start, end, fileSize));
            Response.AddHeader("Content-Length", (end + 1 - start).ToString());

            // Transmit the file.
            Response.OutputStream.TransmitFile(file, start, (end + 1 - start));
            Response.End();
        }
Esempio n. 11
0
 public XDocument Load(FileInfoBase fileInfo)
 {
   XDocument document;
   using (var stream = fileInfo.OpenRead())
   {
     XmlReader xmlReader = XmlReader.Create(stream);
     document = XDocument.Load(xmlReader);
     stream.Close();
   }
   return document;
 }
        public static ICsvWriter Create(FileInfoBase fileInfo)
        {
            var csvConfiguration = new CsvConfiguration
            {
                Delimiter = ";",
                HasHeaderRecord = true
            };

            var streamWriter = new StreamWriter(fileInfo.OpenWrite(), Encoding.UTF8);
            return new CsvHelper.CsvWriter(streamWriter, csvConfiguration);
        }
 private List<Feature> ReadResultsFile(FileInfoBase testResultsFile)
 {
     List<Feature> result;
       using (var stream = testResultsFile.OpenRead())
       {
     using (var reader = new StreamReader(stream))
     {
       result = JsonConvert.DeserializeObject<List<Feature>>(reader.ReadToEnd());
     }
       }
       return result;
 }
Esempio n. 14
0
        static void ListFile(FileInfoBase file)
        {
            if (!file.Exists)
            {
                throw new FileNotFoundException(file.FullName + " does not exist.");
            }

            Console.WriteLine();
            Console.WriteLine(" Directory of {0}", file.Directory.FullName.TrimEnd('\\'));
            Console.WriteLine();
            Console.WriteLine(String.Format("{0} {1,17} {2}", ToDisplayString(file.LastWriteTime), file.Length.ToString("#,##0"), file.Name));
            Console.WriteLine(String.Format("{0,16} File(s) {1,14} bytes", 1, file.Length.ToString("#,##0")));
        }
Esempio n. 15
0
        public bool ExtractDetails(FileInfoBase showFile)
        {
            // Run AtomicParsley to get details.
            var details = new Dictionary<string, string>();
            if(!AtomicParsley.AtomicParsley.ExtractDetails(showFile.FullName, out details))
            {
                return false;
            }

            // Extract the details out of the output.
            if(!details.ContainsKey("tvsh") || !details.ContainsKey("tves"))
            {
                return false;
            }

            // Set default values.
            ShowName = details["tvsh"];
            SeasonNumber = null;
            EpisodeNumber = Convert.ToInt32(details["tves"]);
            EpisodeName = null;
            AiredDate = null;
            Overview = null;
            TVNetwork = null;
            Artworks = null;

            // Set optional values.
            if(details.ContainsKey("tvsn"))
            {
                SeasonNumber = Convert.ToInt32(details["tvsn"]);
            }
            if(details.ContainsKey("@nam"))
            {
                EpisodeName = details["@nam"];
            }
            if(details.ContainsKey("@day"))
            {
                AiredDate = DateTime.Parse(details["@day"]);
            }
            if(details.ContainsKey("@desc"))
            {
                Overview = details["desc"];
            }
            if(details.ContainsKey("tvnn"))
            {
                TVNetwork = details["tvnn"];
            }

            HasDetails = true;
            return true;
        }
Esempio n. 16
0
        public bool IsRelevant(FileInfoBase fileInfo)
        {
            if (fileInfo == null)
            {
                return false;
            }

            string extension = fileInfo.Extension.ToUpperInvariant();

            if (this.validExtensions.Contains(extension))
            {
                return true;
            }

            return false;
        }
        /// <summary>
        /// Loads a file from the file name.
        /// </summary>
        /// <param name="fileInfo">The file info.</param>
        /// <returns>The file's content.</returns>
        protected string LoadFile(FileInfoBase fileInfo)
        {
            // Data validation
            if (null == fileInfo)
                throw new ArgumentNullException("fileInfo");

            // Load the file content
            MemoryStream memoryStream = new MemoryStream();
            using (StreamReader streamReader = new StreamReader(fileInfo.OpenRead()))
            using (var fileWriter = new StreamWriter(memoryStream))
            {
                fileWriter.Write(streamReader.ReadToEnd());
            }

            // Read the code snippet from the file
            return Encoding.UTF8.GetString(memoryStream.ToArray());
        }
 public WorkingTVShow(ITVShow tvShow, FileInfoBase file)
 {
     File = file;
     Definition = tvShow.Definition;
     TVShowName = tvShow.TVShowName;
     SeasonNumber = tvShow.SeasonNumber;
     EpisodeNumber = tvShow.EpisodeNumber;
     Name = tvShow.Name;
     Description = tvShow.Description;
     Genres = tvShow.Genres;
     Cast = tvShow.Cast;
     Directors = tvShow.Directors;
     Screenwriters = tvShow.Screenwriters;
     ReleaseDate = tvShow.ReleaseDate;
     Network = tvShow.Network;
     Artwork = tvShow.Artwork;
 }
Esempio n. 19
0
        public bool IsMarkdownFile(FileInfoBase file)
        {
            switch (file.Extension.ToLowerInvariant())
            {
                case ".markdown":
                case ".mdown":
                case ".mkdn":
                case ".md":
                case ".mdwn":
                case ".mdtxt":
                case ".mdtext":
                case ".text":
                case ".txt":
                    return true;
            }

            return false;
        }
Esempio n. 20
0
            private static Definition ExtractDefinition(FileInfoBase file)
            {
                var streams = new MediaStreamsExtractor(file).Extract();
                var videoStream = streams.Where(stream => stream is MediaStreamsExtractor.IVideoStream).Select(stream => ((MediaStreamsExtractor.IVideoStream) stream).Height).OrderByDescending(h => h);
                if(!videoStream .Any())
                {
                    return Definition.Unknown;
                }

                var height = videoStream.First();
                if(height >= 1080)
                {
                    return Definition.HD1080;
                }
                else if(height >= 720)
                {
                    return Definition.HD720;
                }
                return Definition.SD;
            }
        public static IFileReader CreateFromFileName(FileInfoBase fileInfoBase)
        {
            if (IsCsvFile(fileInfoBase.FullName))
            {
                var reader = new CsvHelper.CsvReader(new StreamReader(fileInfoBase.OpenRead()), new CsvConfiguration
                {
                    HasHeaderRecord = true,
                    Delimiter = ";"
                });

                return new CsvReader(reader);
            }

            if (IsExcelFile(fileInfoBase.FullName))
            {
                var excelReader = ExcelReaderFactory.CreateOpenXmlReader(fileInfoBase.Open(FileMode.Open, FileAccess.Read));
                excelReader.IsFirstRowAsColumnNames = true;
                return new ExcelReader(excelReader);
            }

            throw new InvalidOperationException();
        }
Esempio n. 22
0
        static Task CopyInternalAsync(IFileSystem srcFileSystem, FileInfoBase srcFileInfo, IFileSystem dstFileSystem, FileInfoBase dstFileInfo)
        {
            return TaskHelpers.RunSynchronously(() =>
            {
                if (srcFileInfo.Exists && dstFileInfo.Exists && srcFileInfo.LastWriteTimeUtc == dstFileInfo.LastWriteTimeUtc)
                {
                    lock (_semaphore)
                    {
                        Console.WriteLine("          File up-to-date from \"" + srcFileInfo.FullName + "\" to \"" + dstFileInfo.FullName + "\"");
                    }
                }
                else
                {
                    byte[] bytes = srcFileSystem.File.ReadAllBytes(srcFileInfo.FullName);
                    if (dstFileSystem is FileSystem)
                    {
                        EnsureDirectory(Path.GetDirectoryName(dstFileInfo.FullName));
                    }
                    dstFileSystem.File.WriteAllBytes(dstFileInfo.FullName, bytes);

                    if (dstFileSystem is FileSystem)
                    {
                        dstFileInfo.LastWriteTimeUtc = srcFileInfo.LastWriteTimeUtc;
                    }
                    else if (srcFileSystem is FileSystem)
                    {
                        srcFileInfo.LastWriteTimeUtc = dstFileSystem.FileInfo.FromFileName(dstFileInfo.FullName).LastWriteTimeUtc;
                    }

                    lock (_semaphore)
                    {
                        Console.WriteLine("{0,12} bytes copied from \"" + srcFileInfo.FullName + "\" to \"" + dstFileInfo.FullName + "\"", bytes.Length.ToString("#,##0"));
                        ++_totalFiles;
                        _totalBytes += bytes.Length;
                    }
                }
            });
        }
        public virtual void ProcessFile(ITaskContext context, FileInfoBase file, string currentVersion, string currentReleaseVersion, string currentTestVersion, string newVersion)
        {
            var rel = file.FullName.Replace(context.Data["WorkingDirectory"] as string, "").TrimStart('/', '\\');

            // Read the whole file.
            context.Log.InfoFormat("Reading file {0}",file.FullName);
            var text = context.FileSystem.File.ReadAllText(file.FullName);

            // Return if the file contents don't contain the version number
            var mode = (context.Data["Mode"] as string).ToLower();
            switch (mode)
            {
                case "release":
                    if (!text.Contains(currentVersion) && !text.Contains(currentReleaseVersion)) return;
                    break;
                case "test":
                    if (!text.Contains(currentVersion) && !text.Contains(currentTestVersion)) return;
                    break;
            }

            context.Log.InfoFormat("Replacing version number in file {0}",file.FullName);

            // Replace all occurrences of the oldVersion with the newVersion
            text = text.Replace(currentVersion, newVersion);
            switch (mode)
            {
                case "release":
                    text = text.Replace(currentReleaseVersion, newVersion);
                    break;
                case "test":
                    text = text.Replace(currentTestVersion, newVersion);
                    break;
            }
            context.Log.InfoFormat("Writing file {0}",file.FullName);

            // Write the new file to the file system.
            context.FileSystem.File.WriteAllText(file.FullName, text);
        }
Esempio n. 24
0
        public bool IsMarkdownFile(FileInfoBase file)
        {
            if (file.Name.EndsWith("csproj.FileListAbsolute.txt"))
            {
                return false;
            }

            switch (file.Extension.ToLowerInvariant())
            {
                case ".markdown":
                case ".mdown":
                case ".mkdn":
                case ".md":
                case ".mdwn":
                case ".mdtxt":
                case ".mdtext":
                case ".text":
                case ".txt":
                    return true;
            }

            return false;
        }
        public virtual void ProcessFile(ITaskContext context, FileInfoBase file, string[] filesToIgnore, string currentVersion, string newVersion)
        {
            // Should we ignore this?
            if (filesToIgnore.Contains(file.Name)) return;
            if (file.Extension.ToLower() == ".exe" || file.Extension.ToLower() == "*.dll") return;
            var rel = file.FullName.Replace(context.Data["WorkingDirectory"] as string, "").TrimStart('/', '\\');
            if (rel.StartsWith(".git") || file.FullName.Contains("packages")) return;
            if ((context.Data["Mode"] as string).ToLower() == "test") if (rel == "deploy\\currentversion.txt") return;

            // Read the whole file.
            context.Log.InfoFormat("Reading file {0}",file.FullName);
            var text = context.FileSystem.File.ReadAllText(file.FullName);

            // Return if the file contents don't contain the version number
            if (!text.Contains(currentVersion)) return;
            context.Log.InfoFormat("Replacing version number in file {0}",file.FullName);

            // Replace all occurrences of the oldVersion with the newVersion
            text = text.Replace(currentVersion, newVersion);
            context.Log.InfoFormat("Writing file {0}",file.FullName);

            // Write the new file to the file system.
            context.FileSystem.File.WriteAllText(file.FullName, text);
        }
Esempio n. 26
0
 public void AddTestResultFile(FileInfoBase fileInfoBase)
 {
     this.AddTestResultFileIfItExists(fileInfoBase);
 }
Esempio n. 27
0
        private static IFileSystem CreateFileSystem(string path, DirectoryInfoBase dir, FileInfoBase file)
        {
            var directoryFactory = new Mock<IDirectoryInfoFactory>();
            directoryFactory.Setup(d => d.FromDirectoryName(path))
                            .Returns(dir);
            var fileInfoFactory = new Mock<IFileInfoFactory>();
            fileInfoFactory.Setup(f => f.FromFileName(path))
                           .Returns(file);

            var pathBase = new Mock<PathBase>();
            pathBase.Setup(p => p.GetFullPath(It.IsAny<string>()))
                    .Returns<string>(s => s);

            var fileSystem = new Mock<IFileSystem>();
            fileSystem.SetupGet(f => f.DirectoryInfo).Returns(directoryFactory.Object);
            fileSystem.SetupGet(f => f.FileInfo).Returns(fileInfoFactory.Object);
            fileSystem.SetupGet(f => f.Path).Returns(pathBase.Object);

            FileSystemHelpers.Instance = fileSystem.Object;

            return fileSystem.Object;
        }
 protected override ITestResults ConstructSingleTestResult(FileInfoBase fileInfo)
 {
     // not needed since we use the other constructor
     throw new NotSupportedException();
 }
 public SingleTestRunBase Load(FileInfoBase fileInfo)
 {
     return new XUnit2SingleResults(this.xmlDeserializer.Load(fileInfo));
 }
Esempio n. 30
-1
        public static void AddFile(this ZipArchive zipArchive, FileInfoBase file, ITracer tracer, string directoryNameInArchive)
        {
            Stream fileStream = null;
            try
            {
                fileStream = file.OpenRead();
            }
            catch (Exception ex)
            {
                // tolerate if file in use.
                // for simplicity, any exception.
                tracer.TraceError(String.Format("{0}, {1}", file.FullName, ex));
                return;
            }

            try
            {
                string fileName = ForwardSlashCombine(directoryNameInArchive, file.Name);
                ZipArchiveEntry entry = zipArchive.CreateEntry(fileName, CompressionLevel.Fastest);
                entry.LastWriteTime = file.LastWriteTime;

                using (Stream zipStream = entry.Open())
                {
                    fileStream.CopyTo(zipStream);
                }
            }
            finally
            {
                fileStream.Dispose();
            }
        }