Exemplo n.º 1
0
        public async override void InvokeCore(MovselexClient client)
        {
            client.IsProgressing = true;

            // TODO: MoveDirectoryActionと共通化する。

            //TODO: メッセージを国際化する。
            var appConfig = client.AppConfig;

            var movedDic = new Dictionary<long, string>();


            await Task.Run(() =>
            {
                // ファイル移動は時間がかかるので別スレッドで。

                var i = 1;
                foreach (var library in _selectLibraries)
                {
                    var oldFilePath = library.FilePath;
                    var newfilepath = Path.Combine(_moveDestDirectory, Path.GetFileName(oldFilePath));

                    client.ProgressInfo.UpdateProgressMessage("Moving Library Files",oldFilePath, i++,
                        _selectLibraries.Length);

                    var isMoved = File.Exists(oldFilePath) && FileUtils.Move(oldFilePath, newfilepath);

                    if (isMoved)
                    {
                        _log.Info("Moved File. {0} to {1}.", library.FilePath, newfilepath);

                        movedDic.Add(library.Id, newfilepath);

                        DirecotryUtils.DeleteEmptyDirecotry(Path.GetDirectoryName(library.FilePath));
                    }
                    else
                    {
                        _log.Warn(" Fail Move File. {0} to {1}.", oldFilePath, newfilepath);
                    }
                    
                }

            });

            client.PostCallback(new CallbackAction(() =>
            {
                client.MovselexLibrary.UpdateFilePaths(movedDic);
                client.IsProgressing = false;
            }));
            
            
        }
        public async override void InvokeCore(MovselexClient client)
        {
            client.IsProgressing = true;

            //TODO: メッセージを国際化する。
            var appConfig = client.AppConfig;
           
            appConfig.MoveBaseDirectory = _baseDirectory;

            // 移動先フォルダ作成
            var moveDirectory = _baseDirectory + "\\" + _group.GroupName;

            Directory.CreateDirectory(moveDirectory);

            var movedDic = new Dictionary<long, string>();


            var moveLibraries = client.Libraries.ToArray();

            await Task.Run(() =>
            {
                // ファイル移動は時間がかかるので別スレッドで。

                var i = 1;
                foreach (var library in moveLibraries)
                {
                    var oldFilePath = library.FilePath;
                    var newfilepath = Path.Combine(moveDirectory, Path.GetFileName(oldFilePath));

                    client.ProgressInfo.UpdateProgressMessage("Moving Group Files", _group.GroupName, i++,
                        moveLibraries.Length);

                    var isMoved = File.Exists(oldFilePath) && FileUtils.Move(oldFilePath, newfilepath);

                    if (isMoved)
                    {
                        _log.Info("Moved File. {0} to {1}.", oldFilePath, newfilepath);
                        movedDic.Add(library.Id, newfilepath);
                        DirecotryUtils.DeleteEmptyDirecotry(Path.GetDirectoryName(oldFilePath));
                    }
                    else
                    {
                        _log.Warn(" Fail Move File. {0} to {1}.", oldFilePath, newfilepath);
                    }
                    
                }

            });

            client.PostCallback(new CallbackAction(() =>
            {
                client.MovselexLibrary.UpdateFilePaths(movedDic);

                if (_group != null) _group.ModifyDriveLetter(FileUtils.GetDriveLetter(moveDirectory));

                _log.Info("Moved Group Direcotry. Group:{0} NewPath:{1}", _group.GroupName, moveDirectory);

                client.IsProgressing = false;
            }));
            
            

        }