Пример #1
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 (_srcModel.IsDirectory)
                {
                    Func <IEntryModel, bool> filter       = em => !em.IsDirectory || (em is SzsRootModel);
                    Func <IEntryModel, bool> lookupFilter = em => em.IsDirectory && !(em is SzsRootModel);
                    return(WPFScriptCommands.List(_srcModel, filter, lookupFilter, true, ems =>
                                                  new SimpleScriptCommandAsync("BatchTransfer", pd => transferAsync(pm, ems, progress,
                                                                                                                    new NotifyChangedCommand(_destDirModel.Profile, destFullName,
                                                                                                                                             _srcModel.Profile, _srcModel.FullPath, Defines.ChangeType.Changed)))));
                }
                else
                {
                    return(IOScriptCommands.DiskTransfer(_srcModel, _destDirModel, _removeOriginal));
                }

                return(ResultCommand.NoError);
            }
            catch (Exception ex)
            {
                return(ResultCommand.Error(ex));
            }
        }
Пример #2
0
 public static IScriptCommand DiskTransferChild(string srcDirectoryVariable  = "{Source}",
                                                string destDirectoryVariable = "{DestinationDirectory}",
                                                string mask         = "*", ListOptions listOptions = ListOptions.File | ListOptions.Folder,
                                                bool removeOriginal = false, bool allowCustomImplementation = true, IScriptCommand nextCommand = null)
 {
     return(CoreScriptCommands.List(srcDirectoryVariable, "{DTC-ItemToTransfer}", mask, listOptions,
                                    ScriptCommands.ForEach("{DTC-ItemToTransfer}", "{DTC-CurrentItem}",
                                                           IOScriptCommands.DiskTransfer("{DTC-CurrentItem}", destDirectoryVariable, null, removeOriginal, allowCustomImplementation),
                                                           ScriptCommands.Reset(nextCommand, "{DTC-DestDirectory}", "{DTC-SrcDirectory}"))));
 }
Пример #3
0
        public override async Task <IScriptCommand> ExecuteAsync(ParameterDic pm)
        {
            switch (Operation)
            {
            case ClipboardOperation.Copy:
            case ClipboardOperation.Cut:
                var _srcModels = await pm.GetValueAsEntryModelArrayAsync(EntriesKey);

                var          da         = _srcModels.First().Profile.DragDrop.GetDataObject(_srcModels);
                byte[]       moveEffect = Operation == ClipboardOperation.Cut ? preferCut : preferCopy;
                MemoryStream dropEffect = new MemoryStream();
                dropEffect.Write(moveEffect, 0, moveEffect.Length);
                da.SetData("Preferred DropEffect", dropEffect);

                Clipboard.Clear();
                Clipboard.SetDataObject(da, true);
                break;

            case ClipboardOperation.Paste:
                var currentDirectory = await pm.GetValueAsEntryModelAsync(CurrentDirectoryEntryKey);

                if (currentDirectory != null)
                {
                    IDataObject da1 = Clipboard.GetDataObject();
                    if (da1 != null)
                    {
                        IEntryModel[] srcModels      = currentDirectory.Profile.DragDrop.GetEntryModels(da1).ToArray();
                        string        sourceModelKey = "{Clipboard-SourceModels}";
                        return(ScriptCommands.Assign(sourceModelKey, srcModels, false,
                                                     IOScriptCommands.DiskTransfer(sourceModelKey, CurrentDirectoryEntryKey, DestinationKey, false, true, NextCommand)));
                    }
                }
                break;
            }

            return(NextCommand);
        }
Пример #4
0
        public override async Task <IScriptCommand> ExecuteAsync(ParameterDic pm)
        {
            Dictionary <string, Stream> compressDic = new Dictionary <string, Stream>();

            try
            {
                IEntryModel[] srcEntries = await pm.GetValueAsEntryModelArrayAsync(SourceEntryKey);

                ISzsItemModel destEntry = await pm.GetValueAsEntryModelAsync(DestinationDirectoryEntryKey, null) as ISzsItemModel;

                //If destination is not SzsRoot, use DiskTransfer instead.
                SzsProfile destProfile = destEntry.Profile as SzsProfile;
                if (destProfile == null)
                {
                    logger.Warn(String.Format("{0} isn't Szs based entry, DiskTransfer is used instead.", destEntry.Name));
                    return(IOScriptCommands.DiskTransfer(SourceEntryKey, DestinationDirectoryEntryKey, null, RemoveOriginal, false, NextCommand));
                }
                if (!destEntry.IsDirectory)
                {
                    return(ResultCommand.Error(new ArgumentException(DestinationDirectoryEntryKey + " is not a folder.")));
                }

                Func <IEntryModel, bool> fileAndArchiveOnly = em => !em.IsDirectory || (em is SzsRootModel);
                Func <IEntryModel, bool> lookupDirectoryNotArchiveFilter = em => em.IsDirectory && !(em is SzsRootModel);

                IProgress <TransferProgress> progress = pm.GetProgress();

                string archiveType = destProfile.Path.GetExtension((destEntry as ISzsItemModel).Root.Name);
                logger.Info(String.Format("Compressing {0} -> {1} using SzsDiskTransfer",
                                          srcEntries.GetDescription(), destEntry.Name));

                await Task.Run(async() =>
                {
                    #region OpenStream of files
                    foreach (var srcEntry in srcEntries)
                    {
                        IDiskProfile srcProfile = srcEntry.Profile as IDiskProfile;
                        if (srcProfile == null)
                        {
                            break;
                        }


                        if (fileAndArchiveOnly(srcEntry))
                        {
                            logger.Debug(String.Format("Added to Dictionary : {0} -> {1}", srcEntry.FullPath, srcEntry.Name));
                            progress.Report(TransferProgress.SetMessage(ProgressType.Running, srcEntry.Name));
                            compressDic.Add(srcEntry.Name, await srcProfile.DiskIO
                                            .OpenStreamAsync(srcEntry, Defines.FileAccess.Read, pm.CancellationToken));
                        }
                        else
                        {
                            IList <IEntryModel> srcSubEntries = await srcProfile.ListRecursiveAsync(srcEntry, pm.CancellationToken,
                                                                                                    fileAndArchiveOnly, lookupDirectoryNotArchiveFilter, false);

                            foreach (var srcSubEntry in srcSubEntries)
                            {
                                string relativePath =
                                    destProfile.Path.Combine(
                                        destEntry.RelativePath,
                                        srcSubEntry.FullPath.Replace(srcEntry.Parent.FullPath, "").TrimStart('\\')
                                        );
                                logger.Debug(String.Format("Added to Dictionary : {0} -> {1}", srcSubEntry.FullPath, relativePath));
                                progress.Report(TransferProgress.SetMessage(ProgressType.Running, relativePath));
                                compressDic.Add(relativePath, await srcProfile.DiskIO
                                                .OpenStreamAsync(srcSubEntry, Defines.FileAccess.Read, pm.CancellationToken));
                            }
                        }
                    }
                    #endregion

                    Progress <Defines.ProgressEventArgs> progress1 = new Progress <Defines.ProgressEventArgs>(
                        (pea) =>
                    {
                        if (!String.IsNullOrEmpty(pea.Message))
                        {
                            progress.Report(TransferProgress.SetMessage(Defines.ProgressType.Running, pea.Message));
                        }
                        if (!String.IsNullOrEmpty(pea.File))
                        {
                            progress.Report(TransferProgress.From(pea.File));
                        }
                        if (pea.CurrentProgress != -1 && pea.TotalProgress != -1)
                        {
                            progress.Report(TransferProgress.UpdateCurrentProgress((short)((float)pea.CurrentProgress / (float)pea.TotalProgress * 100.0)));
                        }
                    }
                        );

                    progress.Report(TransferProgress.To(destEntry.Name));
                    using (await destProfile.WorkingLock.LockAsync())
                        using (var stream = await destProfile.DiskIO.OpenStreamAsync(destEntry, Defines.FileAccess.ReadWrite, pm.CancellationToken))
                            destProfile.Wrapper.CompressMultiple(archiveType, stream, compressDic, progress1);

                    logger.Info(String.Format("{0} items transfered", compressDic.Count()));
                    return(CoreScriptCommands.NotifyEntryChanged(ChangeType.Changed, destEntry, NextCommand));
                });


                return(NextCommand);
            }
            finally
            {
                #region Dispose Streams
                if (compressDic != null)
                {
                    foreach (var stream in compressDic.Values)
                    {
                        stream.Dispose();
                    }
                }
                #endregion
            }
        }