예제 #1
0
        public void SetDbMovieFilesInfo(MovieImportData myImportData, StoreData myStoreData)
        {
            if (myStoreData == null)
            {
                throw new Exception("使われる想定のないメソッドが使用された、StoreDataを設定して下さい");
            }

            targetImportData       = myImportData;
            targetFileContentsData = new MovieFileContents();

            targetFileContentsData.Name       = DestFilename;
            targetFileContentsData.Label      = LabelPath;
            targetFileContentsData.StoreLabel = myStoreData.Label;

            if (listExtension == null)
            {
                return;
            }

            foreach (string ext in listExtension)
            {
                if (ext.ToUpper().Equals(".JPG") ||
                    ext.ToUpper().Equals(".JPEG") ||
                    ext.ToUpper().Equals(".PNG") ||
                    ext.ToUpper().Equals(".ISO"))
                {
                    continue;
                }

                // 動画ファイルが複数合った場合に後ろに付加する「_1」などのために名前順に並べ替える
                var dataMatch = from seldata in listSelectedFiles
                                where seldata.FileInfo.Extension == ext
                                orderby seldata.Name ascending
                                select seldata;

                targetFileContentsData.Extension = ext.Replace(".", "").ToUpper();
                targetFileContentsData.FileCount = dataMatch.Count();

                if (dataMatch.Count() == 1)
                {
                    foreach (TargetFiles sel in dataMatch)
                    {
                        targetFileContentsData.Size     = sel.FileInfo.Length;
                        targetFileContentsData.FileDate = sel.FileInfo.LastWriteTime;
                    }
                }
                else
                {
                    long size = 0;
                    foreach (TargetFiles sel in dataMatch)
                    {
                        size += sel.FileInfo.Length;
                        targetFileContentsData.FileDate = sel.FileInfo.LastWriteTime;
                    }

                    targetFileContentsData.Size = size;
                }
            }
            // 品番、販売日を設定
            //DatabaseMovieFile.Parse();
            targetFileContentsData.SellDate      = targetImportData.ProductDate;
            targetFileContentsData.ProductNumber = targetImportData.ProductNumber;

            targetFileContentsData.Tag    = targetImportData.Tag;
            targetFileContentsData.Rating = targetImportData.Rating;
        }
예제 #2
0
        public void Execute(MovieImportData myImportData, MovieFileContents myFileContents)
        {
            string destDir = "HD-" + myFileContents.GetLastSentenceFromLabel();

            string fullPath = Path.Combine(BasePath, destDir);

            if (!Directory.Exists(fullPath))
            {
                Directory.CreateDirectory(fullPath);
            }

            long     size = 0;
            string   ext  = "";
            DateTime dt   = new DateTime(1900, 1, 1);

            foreach (TargetFiles data in listSelectedFiles)
            {
                string destFilename = Path.Combine(fullPath, myImportData.Filename + data.FileInfo.Extension);
                size += data.FileInfo.Length;
                ext   = data.FileInfo.Extension.Substring(1);
                dt    = data.FileInfo.LastWriteTime;
                File.Move(data.FileInfo.FullName, destFilename);
            }

            // JPEGなどのファイルのファイル名を変更(ファイル名を「XXX FHD」に更新する前にファイル名変更を実行)
            string[] mvFiles = Directory.GetFiles(myFileContents.Label, myFileContents.Name + "*");
            Debug.Print(" " + myFileContents.Label + "   " + myFileContents.Name);

            foreach (string pathname in mvFiles)
            {
                FileInfo fileinfo       = new FileInfo(pathname);
                string   sourcePathname = pathname;
                string   sufix          = fileinfo.Name.Replace(myFileContents.Name, "");
                Debug.Print("sufix" + sufix + " pathname " + pathname);
                string destPathname = Path.Combine(myFileContents.Label, myImportData.Filename + sufix.ToLower());

                File.Move(sourcePathname, destPathname);
            }

            MovieFileContentsService service = new MovieFileContentsService();

            myFileContents.Name = myImportData.Filename;
            myFileContents.Size = size;
            if (!myFileContents.Extension.ToUpper().Equals(ext.ToUpper()))
            {
                MessageBoxResult result = MessageBox.Show("既存のファイルは削除しますか?", "削除確認", MessageBoxButton.OKCancel);

                if (result == MessageBoxResult.OK)
                {
                    string[] files = Directory.GetFiles(myFileContents.Label, myFileContents.Name + "*" + myFileContents.Extension);

                    List <TargetFiles> delTargetList = new List <TargetFiles>();

                    foreach (string pathname in files)
                    {
                        TargetFiles targetFiles = new TargetFiles();
                        targetFiles.FileInfo = new FileInfo(pathname);
                        delTargetList.Add(targetFiles);
                    }

                    FilesRegisterService serviceFileRegister = new FilesRegisterService(dbcon);
                    serviceFileRegister.BasePath = BasePath;
                    serviceFileRegister.SetDbMovieFilesInfo(myImportData, null);
                    serviceFileRegister.DeleteFiles(delTargetList);
                }
                myFileContents.Extension = ext;
            }

            try
            {
                dbcon.BeginTransaction("MOVIE_REGISTER");

                service.DbUpdateFileInfo(myFileContents, dbcon);

                dbcon.CommitTransaction();

                // MOVIE_IMPORTから削除
                MovieImportService serviceImportService = new MovieImportService();
                serviceImportService.DbDelete(myImportData, new MySqlDbConnection());
            }
            catch (Exception ex)
            {
                Debug.Write(ex);
                dbcon.RollbackTransaction();
                throw new Exception(ex.Message);
            }

            return;
        }