Пример #1
0
        public void CreateRawFileUrlReturnsUrlWithRoutePrefixAndHashAndPathWithoutTilde()
        {
            SourceDirectory.Add("~\\test.png", "content");
            var url = UrlGenerator.CreateRawFileUrl("~/test.png");

            url.ShouldEqual("cassette.axd/file/test-040f06fd774092478d450774f5ba30c5da78acc8.png");
        }
        protected override bool ValidateParameters()
        {
            base.ValidateParameters();

            var retVal = true;

            if (File.Exists(DestinationArchive))
            {
                if (OverwriteDestination == true)
                {
                    Log.LogMessage(MessageImportance.Low, $"{DestinationArchive} will be overwritten");
                }
                else
                {
                    Log.LogError($"'{DestinationArchive}' already exists. Did you forget to set '{nameof(OverwriteDestination)}' to true?");

                    retVal = false;
                }
            }

            SourceDirectory = Path.GetFullPath(SourceDirectory);

            SourceDirectory = SourceDirectory.EndsWith(Path.DirectorySeparatorChar.ToString())
                ? SourceDirectory
                : SourceDirectory + Path.DirectorySeparatorChar;

            if (!Directory.Exists(SourceDirectory))
            {
                Log.LogError($"SourceDirectory '{SourceDirectory} does not exist.");

                retVal = false;
            }

            return(retVal);
        }
Пример #3
0
        public Configuration FixOptionalValues()
        {
            if (string.IsNullOrWhiteSpace(SourceDirectory))
            {
                return(this);
            }

            if (MinLineForDuplicate < 5)
            {
                MinLineForDuplicate = 5;
            }

            if (MinLineForFullMethodDuplicateCheck < 5)
            {
                MinLineForFullMethodDuplicateCheck = 5;
            }

            if (!SourceDirectory.EndsWith(@"\"))
            {
                SourceDirectory += @"\";
            }

            if (string.IsNullOrWhiteSpace(CacheFileName))
            {
                CacheFileName = Path.Combine(SourceDirectory, "XsDupFinderCache.db");
            }
            if (string.IsNullOrWhiteSpace(OutputDirectory))
            {
                OutputDirectory = SourceDirectory;
            }

            return(this);
        }
Пример #4
0
        public void InsertsHashBeforeLastPeriod()
        {
            SourceDirectory.Add("~\\test\\foo.bar.png", "content");
            var url = UrlGenerator.CreateRawFileUrl("~\\test\\foo.bar.png");

            url.ShouldEqual("cassette.axd/file/test/foo.bar-040f06fd774092478d450774f5ba30c5da78acc8.png");
        }
Пример #5
0
        public void ToleratesFilenameWithoutExtension()
        {
            SourceDirectory.Add("~\\test\\foo", "content");
            var url = UrlGenerator.CreateRawFileUrl("~\\test\\foo");

            url.ShouldEqual("cassette.axd/file/test/foo-040f06fd774092478d450774f5ba30c5da78acc8");
        }
 private bool IsMultiConversionEnabled()
 {
     return((_isProcessing == false) &&
            !SourceDirectory.IsNullOrEmpty() &&
            !DestinationDirectory.IsNullOrEmpty() &&
            Textures.Any(node => node.IsPicked));
 }
Пример #7
0
        public static Book CreateNew(SourceDirectory sourceDirectory, string file)
        {
            var book = new Book
            {
                SourceDirectory =
                    new SourceDirectory
                {
                    Id                 = sourceDirectory.Id,
                    EntityState        = EntityState.Unchanged,
                    SourceDirectoryUrl = sourceDirectory.SourceDirectoryUrl
                },
                CoverImage = CoverImageFactory.CreateEmpty(),
                BookFile   = BookFileFactory.CreateNew(file),
                Title      = Path.GetFileNameWithoutExtension(file),
                Abstract   = Empty
            };

            book.SourceDirectory.EntityState = EntityState.Unchanged;
            book.BookFile.Book = book;
            book.BookHistory   = new BookHistory {
                Book = book
            };
            book.Authors           = new HashSet <Author>();
            book.Publishers        = new HashSet <Publisher>();
            book.BookMarks         = new HashSet <BookMark>();
            book.Notes             = new HashSet <Note>();
            book.SourceDirectoryId = sourceDirectory.Id;
            return(book);
        }
 private bool IsSingleConversionEnabled()
 {
     return((_isProcessing == false) &&
            !TexturePreview.IsEmpty &&
            !SourceDirectory.IsNullOrEmpty() &&
            !DestinationDirectory.IsNullOrEmpty());
 }
Пример #9
0
 public Analyzer(IDsiModel model, AnalyzerSettings analyzerSettings, IProgress <ProgressInfo> progress)
 {
     _model            = model;
     _analyzerSettings = analyzerSettings;
     _progress         = progress;
     _sourceDirectory  = new SourceDirectory(_analyzerSettings);
 }
Пример #10
0
 public static Book CreateNew(SourceDirectory sourceDirectory, string file)
 {
     var book = new Book
     {
         SourceDirectory =
             new SourceDirectory
             {
                 Id = sourceDirectory.Id,
                 EntityState = EntityState.Unchanged,
                 SourceDirectoryUrl = sourceDirectory.SourceDirectoryUrl
             },
         CoverImage = CoverImageFactory.CreateEmpty(),
         BookFile = BookFileFactory.CreateNew(file),
         Title = Path.GetFileNameWithoutExtension(file),
         Abstract = Empty
     };
     book.SourceDirectory.EntityState = EntityState.Unchanged;
     book.BookFile.Book = book;
     book.BookHistory = new BookHistory {Book = book};
     book.Authors = new HashSet<Author>();
     book.Publishers = new HashSet<Publisher>();
     book.BookMarks = new HashSet<BookMark>();
     book.Notes = new HashSet<Note>();
     book.SourceDirectoryId = sourceDirectory.Id;
     return book;
 }
Пример #11
0
        public void ConvertsToForwardSlashes()
        {
            SourceDirectory.Add("~\\test\\foo.png", "content");
            var url = UrlGenerator.CreateRawFileUrl("~\\test\\foo.png");

            url.ShouldEqual("cassette.axd/file/test/foo-040f06fd774092478d450774f5ba30c5da78acc8.png");
        }
        public void EscapesSpaces()
        {
            SourceDirectory.Add("~\\space test.png", "content");
            var url = UrlGenerator.CreateRawFileUrl("~/space test.png");

            url.ShouldEqual("cassette.axd/file/space%20test-040f06fd774092478d450774f5ba30c5da78acc8.png");
        }
Пример #13
0
 public RawFileData(SourceDirectory directory, FilePath path)
 {
     Directory      = directory;
     this.Path      = path;
     this.Type      = path.GetExtension().GetFileType();
     this._fileInfo = null;
     this.Hash      = null;
 }
Пример #14
0
    public void WildCardInDir_missing()
    {
        var directory = SourceDirectory.Replace("Tests", "Test*.Foo");
        var path      = Path.Combine(directory, "WildcardFileFinderTests.cs");

        Assert.False(WildcardFileFinder.TryFind(path, out var result));
        Assert.Null(result);
    }
Пример #15
0
 private async void OpenExplorer(object path)
 {
     if (path != null && (path as string).ValidateDirectory())
     {
         LogDirectory directory = new SourceDirectory(path as string); //TODO: LogDirectory -> SourceDirectory
         await FileHandler.OpenExplorer(directory);
     }
 }
Пример #16
0
    public void WildCardInDir()
    {
        var directory = SourceDirectory.Replace("Tests", "Test*");
        var path      = Path.Combine(directory, "WildcardFileFinderTests.cs");

        Assert.True(WildcardFileFinder.TryFind(path, out var result));
        Assert.True(File.Exists(result), result);
    }
Пример #17
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Analyzer"/> class.
        /// </summary>
        /// <param name="rootDirectory"></param>
        public Analyzer(SourceDirectory rootDirectory)
        {
            if (rootDirectory == null)
            {
                throw new ArgumentNullException(nameof(rootDirectory));
            }

            mRootDirectory = rootDirectory;
            mLogger        = new NoLoggingLogger();
        }
Пример #18
0
        internal DirectoryInfo CreateContentDirectory(DirectoryInfo outputPath)
        {
            var model = new LaunchPageModel(Manifest, AppInfo)
            {
                ContentDirectory = "./Web Files",
                Launcher         = outputPath.GetFiles("*.application").First().Name,
                Installer        = outputPath.GetFiles("setup.exe").FirstOrDefault()?.Name ?? "#"
            };

            if (model.AppInfo.Links == null)
            {
                model.AppInfo.Links = new LinkList();
            }
            var webFilesDir = Directory.CreateDirectory(Path.Combine(WorkingDirectory.FullName, "Web Files"));
            var otherFiles  = SourceDirectory.EnumerateFiles("*", SearchOption.AllDirectories).Where(f => !f.Extension.Contains("cshtml"));

            foreach (var otherFile in otherFiles)
            {
                var targetRelativePath = otherFile.FullName.Replace(SourceDirectory.FullName, string.Empty).Substring(1);
                var fullPath           = Path.Combine(webFilesDir.FullName, targetRelativePath);
                Directory.CreateDirectory(new FileInfo(fullPath).Directory.FullName);
                otherFile.CopyTo(
                    fullPath, true);
            }

            var templateFiles = SourceDirectory.EnumerateFiles("*.cshtml", SearchOption.AllDirectories).Where(f => f.Name.ToLower() != "index.cshtml");

            foreach (var templateFile in templateFiles)
            {
                var targetRelativePath = templateFile.FullName.Replace(SourceDirectory.FullName, string.Empty).Substring(1);
                var fullPath           = Path.Combine(webFilesDir.FullName, targetRelativePath);
                Directory.CreateDirectory(new FileInfo(fullPath).Directory.FullName);
                var compile = Engine.RunCompile(templateFile.Name, typeof(LaunchPageModel), model);
                File.WriteAllText(compile, fullPath);
            }
            var indexFile = SourceDirectory.GetFiles("index.cshtml").FirstOrDefault();

            if (indexFile != null)
            {
                var indexDestPath = Path.Combine(WorkingDirectory.FullName,
                                                 indexFile.FullName.Replace(indexFile.Extension, ".html")
                                                 .Replace(SourceDirectory.FullName, string.Empty)
                                                 .Substring(1));

                var indexOutput = Engine.RunCompile(indexFile.Name, typeof(LaunchPageModel), model);
                File.WriteAllText(indexDestPath, indexOutput);
            }
            foreach (var file in WorkingDirectory.EnumerateFiles("*.cshtml", SearchOption.AllDirectories))
            {
                file.Delete();
            }
            return(WorkingDirectory);
        }
Пример #19
0
        private void AcceptFolderToSources(string folder)
        {
            if (folder.ValidateDirectory())
            {
                SourceDirectory sourceDir    = new SourceDirectory(folder);
                var             sourceExists = SourceDirectories.Where(item => item.DirectoryName == sourceDir.DirectoryName).FirstOrDefault();

                if (sourceExists == null)
                {
                    SourceDirectories.Add(sourceDir);                        //ensure duplicate entries are not allowed
                }
            }
        }
Пример #20
0
 public void Scrape(SourceDirectory source, List <Book> books, bool generateCovers, bool reScrape)
 {
     _sourceDirectory = source;
     _booksToScrape   = books;
     if (_booksToScrape.Count == 0)
     {
         return;
     }
     _generateCovers = generateCovers;
     _rescrape       = reScrape;
     _noInternet     = false;
     OnProgressStarted();
     Worker.RunWorkerAsync();
 }
Пример #21
0
        private async Task PickSourceDirectoryAsync()
        {
            var path = _directoryPicker.Pick(SourceDirectory.IsNotNullOrEmpty()
                                                 ? SourceDirectory
                                                 : null);

            if (path.IsNullOrEmpty())
            {
                return;
            }

            SourceDirectory = path;
            await OnChangedAsync();
            await InitializeAsync();
        }
Пример #22
0
        public static FileList Build(SourceDirectory directory)
        {
            if (directory.Directory[directory.Directory.Length - 1] != Path.DirectorySeparatorChar)
            {
                directory.Directory += Path.DirectorySeparatorChar;
            }

            var fl = new FileList(directory.Directory);

            var files = Walk(directory.Directory, directory);

            if (files.Count > 0)
            {
                fl.Files.AddRange(files);
            }

            return(fl);
        }
Пример #23
0
        private bool ApplySourceDirectoryFilter(object item)
        {
            var book = item as Book;

            if (SourceDirectoryFilter == null)
            {
                SourceDirectoryFilter = new SourceDirectory
                {
                    SourceDirectoryUrl = "All Sources",
                    NickName           = "All Source"
                };
            }
            if (SourceDirectoryFilter.NickName == "All Sources")
            {
                return(true);
            }
            return(book != null && book.SourceDirectory.NickName == SourceDirectoryFilter.NickName);
        }
Пример #24
0
 public Importer(SourceDirectory source)
 {
     _excludedDomain = new ExcludedDomain();
     ProgressService.RegisterPublisher(this);
     _source = source;
     _source.Books = new HashSet<Book>();
     _foundPdfFiles = new List<string>();
     Worker = new BackgroundWorker();
     Worker.DoWork += _worker_DoWork;
     Worker.ProgressChanged += _worker_ProgressChanged;
     Worker.RunWorkerCompleted += _worker_RunWorkerCompleted;
     Worker.WorkerReportsProgress = true;
     Worker.WorkerSupportsCancellation = true;
     ProgressArgs = new ProgressWindowEventArgs();
     _booksImported = 0;
     _booksExisted = 0;
     _booksExcluded = 0;
 }
Пример #25
0
 public Importer(SourceDirectory source)
 {
     _excludedDomain = new ExcludedDomain();
     ProgressService.RegisterPublisher(this);
     _source                           = source;
     _source.Books                     = new HashSet <Book>();
     _foundPdfFiles                    = new List <string>();
     Worker                            = new BackgroundWorker();
     Worker.DoWork                    += _worker_DoWork;
     Worker.ProgressChanged           += _worker_ProgressChanged;
     Worker.RunWorkerCompleted        += _worker_RunWorkerCompleted;
     Worker.WorkerReportsProgress      = true;
     Worker.WorkerSupportsCancellation = true;
     ProgressArgs                      = new ProgressWindowEventArgs();
     _booksImported                    = 0;
     _booksExisted                     = 0;
     _booksExcluded                    = 0;
 }
Пример #26
0
 public virtual void Validate()
 {
     char[] invalid = Path.GetInvalidFileNameChars();
     if (FileInclusions.Any(ext => ext.Any(c => invalid.Contains(c))))
     {
         throw new ArgumentException("One or more file extensions are not valid");
     }
     if (MinSize < 0)
     {
         throw new ArgumentException("The minimum file size must be a positive number");
     }
     if (MaxSize <= MinSize)
     {
         throw new ArgumentException("The maximum size must be greater than the minimum size");
     }
     if (string.IsNullOrEmpty(SourceDirectory) && !SourceDirectoryCurrent)
     {
         throw new ArgumentException("The source directory can't be empty");
     }
     if (SourceDirectoryCurrent && !string.IsNullOrEmpty(SourceDirectory))
     {
         throw new ArgumentException("The --source-current and --source options can't be used at the same time");
     }
     if (!string.IsNullOrEmpty(SourceDirectory))
     {
         invalid = Path.GetInvalidPathChars();
         if (SourceDirectory.Any(c => invalid.Contains(c)))
         {
             throw new ArgumentException("The source directory isn't valid");
         }
         if (!Directory.Exists(SourceDirectory))
         {
             throw new ArgumentException("The source directory doesn't exist");
         }
     }
     if (FileInclusions.Any() && FileExclusions.Any())
     {
         throw new ArgumentException("The list of extensions to exclude must be empty when other extensions to look for are specified");
     }
     if (Preset.HasValue && (FileInclusions.Any() || FileExclusions.Any()))
     {
         throw new ArgumentException("The preset option cannot be used with --include or --exclude");
     }
 }
Пример #27
0
        public void TestSourceFilesFound()
        {
            AnalyzerSettings analyzerSettings = AnalyzerSettings.CreateDefault();

            analyzerSettings.Input.RootDirectory = TestData.RootDirectory;
            analyzerSettings.Input.SourceDirectories.Clear();
            analyzerSettings.Input.SourceDirectories.Add(TestData.RootDirectory);
            analyzerSettings.Input.ExternalIncludeDirectories.Clear();
            analyzerSettings.Input.IgnorePaths.Clear();
            analyzerSettings.Analysis.ResolveMethod = ResolveMethod.AddBestMatch;

            SourceDirectory sourceDirectory = new SourceDirectory(analyzerSettings);

            sourceDirectory.Analyze();
            const int numberOfHeaderFiles         = 7;
            const int numberOfImplementationFiles = 5;

            Assert.AreEqual(numberOfHeaderFiles + numberOfImplementationFiles, sourceDirectory.SourceFiles.Count);
        }
Пример #28
0
        /// <summary>
        /// 递归拷贝文件,把源目录下所有文件和文件夹拷贝到目标目录
        /// </summary>
        /// <param name="sourceDirectory">源路径</param>
        /// <param name="aimDirectory">目标路径</param>
        public void CopyFiles()
        {
            if (!System.IO.Directory.Exists(SourceDirectory) & !System.IO.Directory.Exists(AimDirectory))
            {
                throw new Exception("文件夹不存在");
            }

            string strTemp             = SourceDirectory.Substring(SourceDirectory.LastIndexOf(@"\"));
            string strRealAimDirecotry = AimDirectory + strTemp;// System.IO.Path.Combine(aimDirectory,strTemp);

            if (!System.IO.Directory.Exists(strRealAimDirecotry))
            {
                System.IO.Directory.CreateDirectory(strRealAimDirecotry);
            }

            RecursionCopyFiles(SourceDirectory, strRealAimDirecotry); //调用真正文件夹复制程序

            WorkOvered();                                             //触发事件,调用完成复制后的处理程序
        }
Пример #29
0
        // If your activity returns a value, derive from CodeActivity<TResult>
        // and return the value from the Execute method.
        protected override void Execute(CodeActivityContext context)
        {
            if (!Directory.Exists(SourceDirectory.Get(context)))
            {
                throw new DirectoryNotFoundException();
            }

            if (!Directory.Exists(TargetDirectory.Get(context)))
            {
                Directory.CreateDirectory(TargetDirectory.Get(context));
            }

            foreach (var item in Directory.EnumerateFiles(SourceDirectory.Get(context)))
            {
                var filename   = Path.GetFileName(item);
                var targetFile = Path.Combine(TargetDirectory.Get(context), filename);
                File.Copy(item, targetFile);
            }
        }
Пример #30
0
        private static List <FileEntry> Walk(string directory, SourceDirectory sDir)
        {
            var entries = new List <FileEntry>();
            var config  = JsonConfiguration.Configuration;
            var logger  = Logger.Global;

            Parallel.ForEach(Directory.EnumerateFileSystemEntries(directory), new ParallelOptions()
            {
                MaxDegreeOfParallelism = config.MaxThreads != 0 ? config.MaxThreads : Environment.ProcessorCount
            },
                             f => {
                var relPath = sDir.Directory.RelativePath(f);
                if (!MatchFilters(relPath, sDir.Includes) && MatchFilters(relPath, sDir.Filters))
                {
                    return;
                }

                var attr = File.GetAttributes(f);
                if (attr.HasFlag(FileAttributes.Directory))
                {
                    logger.Write($"Found directory {f}.", Severity.DEBUG);
                    var t = Walk(f, sDir);
                    if (t.Count > 0)
                    {
                        lock (entries)
                        {
                            entries.AddRange(t);
                        }
                    }
                    t = null;
                }
                else
                {
                    lock (entries)
                    {
                        logger.Write($"Found file {f}.", Severity.DEBUG);
                        entries.Add(new FileEntry(f));
                    }
                }
            });

            return(entries);
        }
Пример #31
0
        public override bool Execute()
        {
            //Log.LogWarning("HEY!!!! " + SourceFiles.Length);
            if (!System.IO.Directory.Exists(OutputDirectory.ItemSpec))
            {
                System.IO.Directory.CreateDirectory(OutputDirectory.ItemSpec);
            }

            /*foreach (ITaskItem sourceFile in SourceFiles)
             * {
             *  Log.LogMessage(MessageImportance.High, "Assembling file '" + sourceFile.ItemSpec + "'...");
             *  bool success = false;
             *  string resultFilename = Assemble(sourceFile.GetMetadata("FullPath"), out success);
             *  if (success)
             *  {
             *      Log.LogMessage(MessageImportance.High, sourceFile.ItemSpec + " -> " + resultFilename);
             *  }
             *  else
             *  {
             *
             *  }
             * }*/

            bool success = false;

            /*List<string> sourceFiles = new List<string>();
             * foreach (ITaskItem task in SourceFiles)
             * {
             *  sourceFiles.Add(task.GetMetadata("FullPath"));
             * }
             * string resultFilename = Assemble(sourceFiles.ToArray(), out success);*/
            string resultFilename = Assemble(new string[] { SourceDirectory.GetMetadata("FullPath") }, out success);

            if (success)
            {
                Log.LogMessage(MessageImportance.High, " -> " + resultFilename);
            }
            else
            {
            }

            return(!Log.HasLoggedErrors);
        }
        public void Add()
        {
            var dialog = new FolderBrowserDialog();

            if (dialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            var nickname = "";
            //NickName
            var view = new NickNameView();

            view.ViewModel.NickName = dialog.SelectedPath;
            if (view.ShowDialog() == true)
            {
                if (IsNullOrEmpty(view.ViewModel.NickName))
                {
                    nickname = dialog.SelectedPath;
                }
                else
                {
                    nickname = view.ViewModel.NickName;
                }
            }


            var source = new SourceDirectory {
                SourceDirectoryUrl = dialog.SelectedPath, NickName = nickname
            };

            if (_domain.Exists(source.SourceDirectoryUrl))
            {
                MessageBox.Show("Source directory already exists", "Information", MessageBoxButtons.OK,
                                MessageBoxIcon.Exclamation);
                return;
            }
            source.EntityState = EntityState.Added;
            _domain.AddSourceDirectory(source);

            Refresh();
        }
Пример #33
0
 private bool ApplySourceDirectoryFilter(object item)
 {
     var book = item as Book;
     if (SourceDirectoryFilter == null)
     {
         SourceDirectoryFilter = new SourceDirectory
         {
             SourceDirectoryUrl = "All Sources",
             NickName = "All Source"
         };
     }
     if (SourceDirectoryFilter.NickName == "All Sources")
     {
         return true;
     }
     return book != null && book.SourceDirectory.NickName == SourceDirectoryFilter.NickName;
 }
        public void Add()
        {
            var dialog = new FolderBrowserDialog();
            if (dialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            var nickname = "";
            //NickName
            var view = new NickNameView();
            view.ViewModel.NickName = dialog.SelectedPath;
            if (view.ShowDialog() == true)
            {
                if (IsNullOrEmpty(view.ViewModel.NickName))
                {
                    nickname = dialog.SelectedPath;
                }
                else
                {
                    nickname = view.ViewModel.NickName;
                }
            }


            var source = new SourceDirectory {SourceDirectoryUrl = dialog.SelectedPath, NickName = nickname};

            if (_domain.Exists(source.SourceDirectoryUrl))
            {
                MessageBox.Show("Source directory already exists", "Information", MessageBoxButtons.OK,
                    MessageBoxIcon.Exclamation);
                return;
            }
            source.EntityState = EntityState.Added;
            _domain.AddSourceDirectory(source);

            Refresh();
        }
Пример #35
0
 public void Scrape(SourceDirectory source, List<Book> books, bool generateCovers, bool reScrape)
 {
     _sourceDirectory = source;
     _booksToScrape = books;
     if (_booksToScrape.Count == 0)
     {
         return;
     }
     _generateCovers = generateCovers;
     _rescrape = reScrape;
     _noInternet = false;
     OnProgressStarted();
     Worker.RunWorkerAsync();
 }