private string CopyFiles(string codeQualityProfilePackageName, string targetVersion) { var nuGetPackagePath = _nuGetPathHelper.GetPackageContentPath(codeQualityProfilePackageName, targetVersion); var ruleSetFilePath = _directoryHelper.GetFiles(nuGetPackagePath, "*.ruleset").FirstOrDefault(); if (string.IsNullOrWhiteSpace(ruleSetFilePath)) { throw new InvalidOperationException($"Could not locate a *.ruleset file in the package folder '{nuGetPackagePath}'."); } var ruleSetFileName = Path.GetFileName(ruleSetFilePath); var localRuleSetFilePath = Path.Combine(_basePath, ruleSetFileName); _logger.LogInformation($"Moving file {ruleSetFilePath} to {localRuleSetFilePath} ..."); _fileHelper.Copy(ruleSetFilePath, localRuleSetFilePath, true); if (HasSolutionFile) { var dotsettingsFilePath = _directoryHelper.GetFiles(nuGetPackagePath, "*.DotSettings").FirstOrDefault(); if (string.IsNullOrWhiteSpace(dotsettingsFilePath)) { throw new InvalidOperationException($"Could not locate a *.DotSettings file in the package folder '{nuGetPackagePath}'."); } var localDotDettingsFilePath = Path.Combine(_basePath, $"{_solutionFileName}.DotSettings"); _logger.LogInformation($"Moving file {dotsettingsFilePath} to {localDotDettingsFilePath} ..."); _fileHelper.Copy(dotsettingsFilePath, localDotDettingsFilePath, true); } return(localRuleSetFilePath); }
public CodeQualitySolution(string basePath, IDirectoryHelper directoryHelper, INuGetPathHelper nuGetPathHelper, IFileHelper fileHelper, IProjectFactory projectFactory) { _directoryHelper = directoryHelper; _nuGetPathHelper = nuGetPathHelper; _fileHelper = fileHelper; if (!Path.IsPathRooted(basePath)) { throw new ArgumentOutOfRangeException(nameof(basePath), "The base path of the solution must be absolute."); } _basePath = basePath; var solutionFilePath = _directoryHelper.GetFiles(".", "*.sln", SearchOption.TopDirectoryOnly, _basePath).FirstOrDefault(); _solutionFileName = Path.GetFileName(solutionFilePath); if (HasSolutionFile) { _logger.LogInformation($"Using solution file: {_solutionFileName}"); } else { _logger.LogWarning("No solution file found."); } var projectFiles = _directoryHelper.GetFiles(".", "*.csproj", SearchOption.AllDirectories, _basePath); foreach (var projectFile in projectFiles) { _projects.Add(projectFactory.CreateProject(Path.GetFullPath(Path.Combine(_basePath, projectFile)))); } }
public void Save(Book book) { var file = book.File; var bookZip = ZipFile.Open(file, ZipArchiveMode.Update); var tempFile = @"C:\Users\pgathany\Desktop\Personal\Books\tempDirectory" + Path.GetFileNameWithoutExtension(file); bookZip.ExtractToDirectory(tempFile); var tempBookFiles = directory.GetFiles(tempFile, "*.opf", SearchOption.AllDirectories); var opf = tempBookFiles.FirstOrDefault(f => f.EndsWith(".opf")); var doc = XDocument.Load(opf); var elements = doc.Root.Elements(); var metadata = elements.Where(e => e.Name.LocalName == "metadata").FirstOrDefault(); var metaDataElements = metadata.Elements(); var title = metaDataElements.Where(e => e.Name.LocalName == "title").FirstOrDefault(); title.Value = book.Title; var creator = metaDataElements.Where(e => e.Name.LocalName == "creator").FirstOrDefault(); creator.Value = book.Creator; File.Delete(opf); doc.Save(opf); File.Delete(file); ZipFile.CreateFromDirectory(tempFile, file); directory.Delete(tempFile, true); }
public EpubContentReader(string file, SettingsBase settings, IDirectoryHelper directory) { var bookZip = ZipFile.Open(file, ZipArchiveMode.Update); var tempFile = Path.Combine(settings.TempDirectory, Path.GetFileNameWithoutExtension(file)); bookZip.ExtractToDirectory(tempFile); bookZip.Dispose(); var contentInfoFile = directory.GetFiles(tempFile, "*.opf", SearchOption.AllDirectories).FirstOrDefault(f => f.EndsWith(".opf")); var doc = XDocument.Load(contentInfoFile); var elements = doc.Root.Elements(); var metadata = elements.Where(e => e.Name.LocalName == "metadata").FirstOrDefault(); var metaDataElements = metadata.Elements(); this.title = metaDataElements.Where(e => e.Name.LocalName == "title").FirstOrDefault().Value; this.creator = metaDataElements.Where(e => e.Name.LocalName == "creator").FirstOrDefault().Value; var coverInfoElement = metaDataElements.Where(e => e.Attributes("name").Where(a => a.Value == "cover").FirstOrDefault() != null).FirstOrDefault(); coverLocation = ""; if (coverInfoElement != null) { var coverValue = coverInfoElement.Attributes("content").FirstOrDefault().Value; var manifest = elements.Where(e => e.Name.LocalName == "manifest").FirstOrDefault(); var manifestElements = manifest.Elements(); var coverManifest = manifestElements.Where(e => e.Attributes("id").FirstOrDefault() != null && e.Attributes("id").FirstOrDefault().Value == coverValue).FirstOrDefault(); var coverHref = coverManifest.Attributes("href").FirstOrDefault().Value; var fullCoverLocation = Path.Combine(Path.GetDirectoryName(contentInfoFile), coverHref.Replace("/", "\\")); coverLocation = fullCoverLocation; } }
/// <summary> /// Wraps existing view engines with ViewTrackerRazorEngine. /// </summary> /// <param name="application">Mvc Application</param> /// <param name="viewEngines">View Engines</param> public void StartTracking(HttpApplication application, ViewEngineCollection viewEngines) { _viewUsage = new ConcurrentDictionary <string, ulong>(_directoryHelper .GetFiles(HostingEnvironment.ApplicationPhysicalPath, "*.cshtml", SearchOption.AllDirectories) .ToDictionary(f => f, _ => (ulong)0)); var engines = viewEngines.Select(v => new ViewTrackerRazorEngine(v, this)).ToList(); viewEngines.Clear(); engines.ForEach(viewEngines.Add); }
public IEnumerable <Book> LoadLibrary() { var books = db.GetItems(); var bookpath = settings.LibraryDirectory; var bookfiles = directory.GetFiles(bookpath); foreach (var bookfile in bookfiles) { if (!books.Select(b => b.File).Contains(bookfile)) { AddBook(bookfile); } } RemoveDeletedBooks(books, bookfiles); db.Save(); return(books); }
public void Save(Book book) { var file = book.File; var bookZip = ZipFile.Open(file, ZipArchiveMode.Update); var tempFile = Path.Combine(TempPath, Path.GetFileNameWithoutExtension(file) + "SavingTemp"); bookZip.ExtractToDirectory(tempFile); bookZip.Dispose(); var tempBookFiles = directory.GetFiles(tempFile, "*.opf", SearchOption.AllDirectories); var opf = tempBookFiles.FirstOrDefault(f => f.EndsWith(".opf")); var doc = XDocument.Load(opf); var elements = doc.Root.Elements(); var metadata = elements.Where(e => e.Name.LocalName == "metadata").FirstOrDefault(); var metaDataElements = metadata.Elements(); var title = metaDataElements.Where(e => e.Name.LocalName == "title").FirstOrDefault(); title.Value = book.Title; var creator = metaDataElements.Where(e => e.Name.LocalName == "creator").FirstOrDefault(); creator.Value = book.Creator; var coverInfoElement = metaDataElements.Where(e => e.Attributes("name").Where(a => a.Value == "cover").FirstOrDefault() != null).FirstOrDefault(); if (coverInfoElement != null) { var coverValue = coverInfoElement.Attributes("content").FirstOrDefault().Value; var manifest = elements.Where(e => e.Name.LocalName == "manifest").FirstOrDefault(); var manifestElements = manifest.Elements(); var coverManifest = manifestElements.Where(e => e.Attributes("id").FirstOrDefault() != null && e.Attributes("id").FirstOrDefault().Value == coverValue).FirstOrDefault(); var coverHrefElement = coverManifest.Attributes("href").FirstOrDefault(); var coverHref = coverHrefElement.Value; var fullCoverLocation = Path.Combine(Path.GetDirectoryName(opf), coverHref.Replace("/", "\\")); var coverLocation = fullCoverLocation; if (coverLocation != book.BookCover) { File.Delete(coverLocation); var coverExtension = Path.GetExtension(book.BookCover).Replace(".", ""); var coverMediaType = (coverExtension.StartsWith("jp") ? "image/jpeg" : "image/png"); var newCover = Path.ChangeExtension(coverLocation, coverExtension); var localCoverPath = Path.ChangeExtension(coverHref, coverExtension); coverHrefElement.Value = localCoverPath; File.Copy(book.BookCover, newCover); var mediaTypeAttr = coverManifest.Attribute("media-type"); if (mediaTypeAttr != null) { mediaTypeAttr.Value = coverMediaType; } else { coverManifest.Add(new XAttribute("media-type", coverMediaType)); } } } else { if (!string.IsNullOrEmpty(book.BookCover)) { var coverExtension = Path.GetExtension(book.BookCover).Replace(".", ""); var mediaType = (coverExtension.StartsWith("jp") ? "image/jpeg" : "image/png"); metadata.Add(new XElement("meta", new XAttribute("name", "cover"), new XAttribute("content", "bookinatorcover"))); var manifest = elements.Where(e => e.Name.LocalName == "manifest").FirstOrDefault(); var newCoverName = "bookinatorcover" + Path.GetExtension(book.BookCover); manifest.AddFirst(new XElement("item", new XAttribute("id", "bookinatorcover"), new XAttribute("href", newCoverName), new XAttribute("media-type", mediaType))); File.Copy(book.BookCover, Path.Combine(Path.GetDirectoryName(opf), newCoverName)); } } File.Delete(opf); doc.Save(opf); OverwriteEpub(file, tempFile); }