예제 #1
0
 public static IScriptCommand TransferChild(IEntryModel srcModel, IEntryModel destDirModel,
                                            Func <IEntryModel, bool> filterFunc = null, bool recrusive = false, IScriptCommand nextCommand = null)
 {
     return(WPFScriptCommands.List(srcModel, filterFunc, null, recrusive, ems =>
                                   WPFScriptCommands.ReportProgress(TransferProgress.IncrementTotalEntries(ems.Length),
                                                                    ScriptCommands.ForEach(ems, em =>
                                                                                           ScriptCommands.RunInSequence(
                                                                                               IOScriptCommands.Transfer(em, destDirModel),
                                                                                               WPFScriptCommands.ReportProgress(TransferProgress.IncrementProcessedEntries())),
                                                                                           nextCommand))));
 }
예제 #2
0
        private async Task <IScriptCommand> transferScriptCommandAsync(ParameterDic pm, IEntryModel[] srcEntries, IEntryModel destEntry, string destinationKey)
        {
            var progress = pm.GetProgress() ?? NullTransferProgress.Instance;

            var srcProfile  = srcEntries.First().Profile as IDiskProfile;
            var destProfile = destEntry.Profile as IDiskProfile;

            var srcMapper   = srcProfile.DiskIO.Mapper;
            var destMapping = destProfile.DiskIO.Mapper[destEntry];
            List <IScriptCommand> notifyChangeCommands = new List <IScriptCommand>();

            List <string> changedPath = new List <string>();

            progress.Report(TransferProgress.IncrementTotalEntries(srcEntries.Count()));
            foreach (var srcEntry in srcEntries)
            {
                var    srcMapping   = srcMapper[srcEntry];
                string destName     = PathFE.GetFileName(srcMapping.IOPath);
                string destFullName = destProfile.Path.Combine(destEntry.FullPath, destName);

                progress.Report(TransferProgress.From(srcEntry.FullPath, destEntry.FullPath));

                if (srcEntry.IsDirectory)
                {
                    await ScriptRunner.RunScriptAsync(pm,
                                                      ScriptCommands.Assign("{DT-SrcDirectory}", srcEntry, false,
                                                                            ScriptCommands.Assign("{DT-DestProfile}", destEntry.Profile, false,
                                                                                                  CoreScriptCommands.DiskParseOrCreateFolder("{DT-DestProfile}", destFullName, "{DT-DestDirectory}",
                                                                                                                                             IOScriptCommands.DiskTransferChild("{DT-SrcDirectory}", "{DT-DestDirectory}", RemoveOriginal, AllowCustomImplementation,
                                                                                                                                                                                ScriptCommands.Reset(ResultCommand.NoError, "{DT-DestDirectory}", "{DT-SrcDirectory}"))))));
                }
                else
                {
                    await ScriptRunner.RunScriptAsync(pm,
                                                      ScriptCommands.Assign("{DT-SrcFile}", srcEntry, false,
                                                                            ScriptCommands.Assign("{DT-SrcProfile}", srcEntry.Profile, false,
                                                                                                  ScriptCommands.Assign("{DT-DestProfile}", destEntry.Profile, false,
                                                                                                                        CoreScriptCommands.DiskParseOrCreateFile("{DT-DestProfile}", destFullName, "{DT-DestFile}",
                                                                                                                                                                 CoreScriptCommands.DiskCopyFile("{DT-SrcProfile}", "{DT-SrcFile}", "{DT-DestProfile}", "{DT-DestFile}",
                                                                                                                                                                                                 ScriptCommands.Reset(ResultCommand.NoError, "{DT-SrcFile}", "{DT-DestFile}")))))));
                }

                progress.Report(TransferProgress.IncrementProcessedEntries());
            }

            logger.Info(String.Format("{0} {1} -> {2} using ScriptCommand",
                                      RemoveOriginal ? "Move" : "Copy", srcEntries.GetDescription(), destEntry.Name));

            return(await GetAssignDestinationCommandAsync(pm, srcEntries, destEntry, destinationKey, NextCommand));
        }
예제 #3
0
        public override async Task <IScriptCommand> ExecuteAsync(IParameterDic pm)
        {
            IEnumerable e = pm.Get <IEnumerable>(ItemsKey);

            if (e == null)
            {
                return(ResultCommand.Error(new ArgumentException(ItemsKey)));
            }

            IProgress <TransferProgress> progress =
                NullProgress <TransferProgress> .Instance;

            if (IsProgressEnabled)
            {
                List <object> list;
                e        = list = e.Cast <object>().ToList();
                progress = pm.Progress <TransferProgress>();
                progress.Report(TransferProgress.IncrementTotalEntries(list.Count));
            }

            uint counter = 0;

            pm.Set <bool>(BreakKey, false);
            foreach (var item in e)
            {
                if (pm.Get <bool>(BreakKey))
                {
                    break;
                }

                counter++;
                pm.Set(CurrentItemKey, item);
                await ScriptRunner.RunScriptAsync(pm, NextCommand);

                progress.Report(TransferProgress.IncrementProcessedEntries());
                if (pm.Error() != null)
                {
                    pm.Set <Object>(CurrentItemKey, null);
                    return(ResultCommand.Error(pm.Error()));
                }
            }
            logger.Info(String.Format("Looped {0} items", counter));
            pm.Set <Object>(CurrentItemKey, null);

            return(ThenCommand);
        }
예제 #4
0
        public override async Task <IScriptCommand> ExecuteAsync(ParameterDic pm)
        {
            var destProfile = _destDirModel.Profile as IDiskProfile;

            var    destMapping  = (_destDirModel.Profile as IDiskProfile).DiskIO.Mapper[_destDirModel];
            var    srcMapping   = (_srcModel.Profile as IDiskProfile).DiskIO.Mapper[_srcModel];
            string destName     = PathFE.GetFileName(srcMapping.IOPath);
            string destFullName = destProfile.Path.Combine(_destDirModel.FullPath, destName); //PathFE.Combine(destMapping.IOPath, destName);

            IEntryModel destModel = await _destDirModel.Profile.ParseAsync(destFullName);

            if (destModel == null)
            {
                destModel = await destProfile.DiskIO.CreateAsync(destFullName, true, pm.CancellationToken);

                destModel = (await _destDirModel.Profile.ListAsync(_destDirModel, CancellationToken.None, em =>
                                                                   em.FullPath.Equals(destFullName,
                                                                                      StringComparison.CurrentCultureIgnoreCase), true)).FirstOrDefault();
                _destDirModel.Profile.Events.PublishOnUIThread(new EntryChangedEvent(ChangeType.Created, destFullName));
            }

            if (destModel == null)
            {
                return(ResultCommand.Error(new Exception("Cannot construct destination " + destFullName)));
            }
            else
            {
                _progress.Report(TransferProgress.From(_srcModel.FullPath, destFullName));
                _progress.Report(TransferProgress.IncrementProcessedEntries()); //dest directory created
            }
            var srcSubModels = (await _srcModel.Profile.ListAsync(_srcModel, CancellationToken.None)).ToList();

            _progress.Report(TransferProgress.IncrementTotalEntries(srcSubModels.Count())); //source entries

            var resultCommands = srcSubModels.Select(m =>
                                                     (IScriptCommand) new FileTransferScriptCommand(m, destModel, _removeOriginal)).ToList();

            resultCommands.Add(new NotifyChangedCommand(_destDirModel.Profile, destFullName, ChangeType.Created));

            //if (_removeOriginal)
            //    resultCommands.Add(new DeleteEntryCommand(_srcModel));

            return(new RunInSequenceScriptCommand(resultCommands.ToArray()));
        }
예제 #5
0
        public override async Task <IScriptCommand> ExecuteAsync(ParameterDic pm)
        {
            CancellationToken ct = pm.CancellationToken;
            var progress         = pm.ContainsKey("Progress") ? pm["Progress"] as IProgress <TransferProgress> : NullTransferProgress.Instance;
            var _srcModels       = _srcModelFunc(pm);

            if (_srcModels != null)
            {
                progress.Report(TransferProgress.IncrementTotalEntries(_srcModels.Count()));
                Task[] tasks = _srcModels.Select(m =>
                                                 (m.Profile as IDiskProfile).DiskIO.DeleteAsync(m, ct)
                                                 .ContinueWith(
                                                     tsk => progress.Report(TransferProgress.IncrementProcessedEntries()))
                                                 ).ToArray();
                await Task.WhenAll(tasks);

                return(new RunInSequenceScriptCommand(
                           _srcModels.Select(m => new NotifyChangedCommand(m.Profile, m.FullPath, ChangeType.Deleted))
                           .ToArray()));
            }

            return(ResultCommand.NoError);
        }
예제 #6
0
        public void ProgressDialog()
        {
            ScriptRunner.RunScript(
                WPFScriptCommands.ShowProgress(_windowManager, "Testing",
                                               WPFScriptCommands.ReportProgress(TransferProgress.From("C:\\Demo\\FileExplorer3.txt", "http://fileexplorer.codeplex.com/FileExplorer3.txt"),
                                                                                WPFScriptCommands.ReportProgress(TransferProgress.IncrementTotalEntries(100),
                                                                                                                 WPFScriptCommands.ReportProgress(TransferProgress.IncrementProcessedEntries(20),
                                                                                                                                                  WPFScriptCommands.ReportProgress(TransferProgress.UpdateCurrentProgress(50))))))
                );
            //_windowManager.ShowDialog(new ProgressDialogViewModel(new ParameterDic()
            //{

            //}));
        }
예제 #7
0
        private async Task <IScriptCommand> transferSystemIOAsync(ParameterDic pm, IEntryModel[] srcEntries, IEntryModel destEntry, string destinationKey)
        {
            return(await Task.Run <IScriptCommand>(async() =>
            {
                var progress = pm.ContainsKey("Progress") ? pm["Progress"] as IProgress <TransferProgress> : NullTransferProgress.Instance;

                var srcProfile = srcEntries.First().Profile as IDiskProfile;
                var destProfile = destEntry.Profile as IDiskProfile;

                var srcMapper = srcProfile.DiskIO.Mapper;
                var destMapping = destProfile.DiskIO.Mapper[destEntry];


                List <string> createdPath = new List <string>();
                List <string> changedPath = new List <string>();

                progress.Report(TransferProgress.IncrementTotalEntries(srcEntries.Count()));
                foreach (var srcEntry in srcEntries)
                {
                    var srcMapping = srcMapper[srcEntry];
                    string destName = PathFE.GetFileName(srcMapping.IOPath);
                    string destFullName = destProfile.Path.Combine(destEntry.FullPath, destName);

                    progress.Report(TransferProgress.From(srcEntry.FullPath, destEntry.FullPath));

                    if (srcEntry.IsDirectory)
                    {
                        if (Directory.Exists(destFullName))
                        {
                            changedPath.Add(destFullName);
                            //Directory.Delete(destFullName, true);
                        }
                        else
                        {
                            createdPath.Add(destFullName);
                        }

                        Directory.Move(srcMapping.IOPath, destFullName);     //Move directly.
                        progress.Report(TransferProgress.IncrementProcessedEntries());
                    }
                    else
                    {
                        if (File.Exists(destFullName))
                        {
                            changedPath.Add(destFullName);
                            File.Delete(destFullName);
                        }
                        else
                        {
                            createdPath.Add(destFullName);
                        }
                        File.Move(srcMapping.IOPath, destFullName);
                    }
                    progress.Report(TransferProgress.IncrementProcessedEntries());
                }

                logger.Info(String.Format("{0} {1} -> {2} using System.IO",
                                          RemoveOriginal ? "Move" : "Copy", srcEntries.GetDescription(), destEntry.Name));


                return
                await GetAssignDestinationCommandAsync(pm, srcEntries, destEntry, destinationKey,
                                                       ScriptCommands.RunParallel(NextCommand,

                                                                                  CoreScriptCommands.NotifyEntryChangedPath(ChangeType.Created, destEntry.Profile, createdPath.ToArray()),
                                                                                  CoreScriptCommands.NotifyEntryChangedPath(ChangeType.Changed, destEntry.Profile, changedPath.ToArray())
                                                                                  ));
            }));
        }