Esempio n. 1
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));
        }
Esempio n. 2
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);
        }
Esempio n. 3
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()));
        }
Esempio n. 4
0
        public override async Task <IScriptCommand> ExecuteAsync(ParameterDic pm)
        {
            var    srcProfile   = _srcModel.Profile as IDiskProfile;
            var    destProfile  = _destDirModel.Profile as IDiskProfile;
            string destName     = _srcModel.GetName();
            string srcFullName  = _srcModel.FullPath;
            string destFullName = _destDirModel.Combine(destName);

            ChangeType ct = ChangeType.Created;

            if (destFullName.StartsWith("::"))
            {
                return(ResultCommand.Error(new ArgumentException("Transfer does not work with shell folders.")));
            }
            if (File.Exists(destFullName))
            {
                File.Delete(destFullName);
                ct = ChangeType.Changed;
            }

            using (var srcStream = await srcProfile.DiskIO.OpenStreamAsync(_srcModel.FullPath,
                                                                           FileExplorer.Defines.FileAccess.Read, pm.CancellationToken))
                using (var destStream = await destProfile.DiskIO.OpenStreamAsync(destFullName,
                                                                                 FileExplorer.Defines.FileAccess.Write, pm.CancellationToken))
                {
                    _progress.Report(TransferProgress.From(srcFullName, destFullName));
                    await StreamUtils.CopyStreamAsync(srcStream, destStream, false, false, false,
                                                      p => _progress.Report(new TransferProgress()
                    {
                        CurrentProgressPercent = p
                    })).ConfigureAwait(false);
                }
            if (_removeOriginal)
            {
                await srcProfile.DiskIO.DeleteAsync(_srcModel, pm.CancellationToken).ConfigureAwait(false);
            }

            _progress.Report(TransferProgress.IncrementProcessedEntries());

            return(new NotifyChangedCommand(_destDirModel.Profile, destFullName,
                                            _srcModel.Profile, srcFullName, ct));
        }
Esempio n. 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);
        }
Esempio n. 6
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))));
 }
Esempio n. 7
0
        public override async Task <IScriptCommand> ExecuteAsync(ParameterDic pm)
        {
            try
            {
                var srcProfile  = _srcModel.Profile as IDiskProfile;
                var destProfile = _destDirModel.Profile as IDiskProfile;
                var progress    = pm.ContainsKey("Progress") ? pm["Progress"] as IProgress <TransferProgress> : NullTransferProgress.Instance;

                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);


                if (!srcMapping.IsVirtual && !destMapping.IsVirtual && _removeOriginal)
                {
                    //Disk based transfer
                    progress.Report(TransferProgress.From(_srcModel.FullPath, destFullName));
                    if (_srcModel.IsDirectory)
                    {
                        if (Directory.Exists(destFullName))
                        {
                            Directory.Delete(destFullName, true);
                        }
                        Directory.Move(srcMapping.IOPath, destFullName); //Move directly.
                        progress.Report(TransferProgress.IncrementProcessedEntries());
                    }
                    else
                    {
                        if (File.Exists(destFullName))
                        {
                            File.Delete(destFullName);
                        }
                        File.Move(srcMapping.IOPath, destFullName);
                    }
                    progress.Report(TransferProgress.IncrementProcessedEntries());
                    return(new NotifyChangedCommand(_destDirModel.Profile, destFullName, _srcModel.Profile,
                                                    _srcModel.FullPath, ChangeType.Moved));
                }
                else
                {
                    if (_srcModel.IsDirectory)
                    {
                        return(new CopyDirectoryTransferCommand(_srcModel, _destDirModel, _removeOriginal, progress));
                    }
                    else
                    {
                        return(new StreamFileTransferCommand(_srcModel, _destDirModel, _removeOriginal, progress));
                    }
                }



                //switch (_transferMode)
                //{
                //    case DragDropEffects.Move:
                //
                //

                //    case DragDropEffects.Copy:
                //        Directory.CreateDirectory(destFullName);
                //        _destDirModel.Profile.Events.Publish(new EntryChangedEvent(destFullName, ChangeType.Created));

                //        var destModel = (await _destDirModel.Profile.ListAsync(_destDirModel, em =>
                //                em.FullPath.Equals(destFullName,
                //                StringComparison.CurrentCultureIgnoreCase))).FirstOrDefault();
                //        var srcSubModels = (await _srcModel.Profile.ListAsync(_srcModel)).ToList();

                //        var resultCommands = srcSubModels.Select(m =>
                //            (IScriptCommand)new FileTransferScriptCommand(m, destModel, _transferMode)).ToList();
                //        resultCommands.Insert(0, new NotifyChangedCommand(_destDirModel.Profile, destFullName, ChangeType.Created));

                //        return new RunInSequenceScriptCommand(resultCommands.ToArray());
                //    default:
                //        throw new NotImplementedException();
                //}

                //}
                //else
                //{

                //}

                return(ResultCommand.NoError);
            }
            catch (Exception ex)
            {
                return(ResultCommand.Error(ex));
            }
        }
Esempio n. 8
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()
            //{

            //}));
        }
Esempio n. 9
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())
                                                                                  ));
            }));
        }