示例#1
0
        public static List <System.Threading.Tasks.Task> GenerateScrapPagesTasks(ILibrary libVM, string title, ref PageViewModel[] pages, string masterDirectory)
        {
            pages = pages.OrderBy(a => a.Title, new NaturalStringComparer()).ToArray();

            var workingDirectory = Configuration.ApplicationConfiguration.WorkingDirectory;
            var now = DateTime.Now;

            Guid entryNameSeedGuid = Guid.NewGuid();
            var  bookDir           = entryNameSeedGuid.ToString("N");

            var copyTo = workingDirectory + "\\"
                         + masterDirectory + "\\"
                         + now.Year + "\\"
                         + now.Month.ToString("00") + "\\"
                         + now.Day.ToString("00") + "\\"
                         + bookDir;

            //保存先ディレクトリ準備
            if (!Directory.Exists(copyTo))
            {
                Directory.CreateDirectory(copyTo);
                s_logger.Debug($"Create directory:{copyTo}");
            }

            List <System.Threading.Tasks.Task> tasks = new List <System.Threading.Tasks.Task>();

            PageScrapping sptask = new PageScrapping();

            tasks.Add(new System.Threading.Tasks.Task(() => sptask.CreateBook(bookDir, title)));

            var page        = pages.ElementAt(0);
            var img         = page.Image;
            var destination = copyTo + "\\" + Path.GetFileName(img.AbsoluteMasterPath);

            AddTaskToProcessScrapPage(tasks, sptask, page, img, destination);

            tasks.Add(new System.Threading.Tasks.Task(() => sptask.SetFirstPage()));

            tasks.Add(new System.Threading.Tasks.Task(() => libVM.AddToMemory(sptask.NewBook)));

            //ファイルコピー
            for (int i = 1; i < pages.Count(); ++i)
            {
                page        = pages.ElementAt(i);
                img         = page.Image;
                destination = copyTo + "\\" + Path.GetFileName(img.AbsoluteMasterPath);
                AddTaskToProcessScrapPage(tasks, sptask, page, img, destination);
            }

            tasks.Add(new System.Threading.Tasks.Task(() => libVM.FireFillContents(sptask.NewBook)));
            tasks.Add(new System.Threading.Tasks.Task(() => s_logger.Info($"Pages Scrapped as:{sptask.NewBook}")));
            tasks.Add(new System.Threading.Tasks.Task(() => sptask.SetContentsRegistered()));
            return(tasks);
        }
示例#2
0
        private static void AddTaskToProcessScrapPage(List <System.Threading.Tasks.Task> tasks, PageScrapping sptask, PageViewModel page, ImageViewModel img, string destination)
        {
            page.IsScrapped = true;

            tasks.Add(new System.Threading.Tasks.Task(() => sptask.CopyFile(img.AbsoluteMasterPath, destination)));

            //Image Create
            tasks.Add(new System.Threading.Tasks.Task(() => sptask.CreateImage(img, destination)));

            //Page Create
            tasks.Add(new System.Threading.Tasks.Task(() => sptask.CreatePage(img)));

            tasks.Add(new System.Threading.Tasks.Task(() => sptask.CountUp()));
        }