Ejemplo n.º 1
0
        public override async Task <IScriptCommand> ExecuteAsync(ParameterDic pm)
        {
            var evm = pm.GetValue <IExplorerViewModel>(ExplorerKey);
            var dm  = DirectoryEntryKey == null ? null :
                      (await pm.GetValueAsEntryModelArrayAsync(DirectoryEntryKey)).FirstOrDefault();

            if (evm == null)
            {
                var events = pm.GetValue <IEventAggregator>(EventsKey);
                if (events != null)
                {
                    events.PublishOnUIThread(new DirectoryChangedEvent(this, dm, null));
                }
                else
                {
                    return(ResultCommand.Error(new ArgumentNullException(ExplorerKey)));
                }
            }
            else
            {
                await evm.GoAsync(dm);
            }

            logger.Info("Path = " + dm.FullPath);
            return(NextCommand);
        }
Ejemplo n.º 2
0
        public override async Task <IScriptCommand> ExecuteAsync(ParameterDic pm)
        {
            DestinationKey = DestinationKey ?? "{Explorer}";
            var tevm = pm.GetValue <ITabbedExplorerViewModel>(TabbedExplorerKey);

            if (tevm == null)
            {
                return(ResultCommand.Error(new ArgumentNullException(TabbedExplorerKey)));
            }

            var dm = DirectoryEntryKey == null ? null :
                     (await pm.GetValueAsEntryModelArrayAsync(DirectoryEntryKey)).FirstOrDefault();

            if (dm != null && !dm.IsDirectory)
            {
                dm = null;
            }

            var destTab = tevm.OpenTab(dm);

            logger.Info(String.Format("New Tab #{0}", tevm.GetTabIndex(destTab)));
            logger.Debug(String.Format("{0} = {1}", DestinationKey, destTab));
            pm.SetValue(DestinationKey, destTab);
            return(NextCommand);
        }
Ejemplo n.º 3
0
        public override async Task <IScriptCommand> ExecuteAsync(ParameterDic pm)
        {
            IEntryModel[] srcEntries = null;
            IEntryModel   destEntry  = null;

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

                destEntry = await pm.GetValueAsEntryModelAsync(DestinationDirectoryEntryKey, null);
            }
            catch (ArgumentException ex)
            {
                return(ResultCommand.Error(ex));
            }

            if (!destEntry.IsDirectory)
            {
                return(ResultCommand.Error(new ArgumentException(DestinationDirectoryEntryKey + " is not a folder.")));
            }
            if (srcEntries.Length == 0)
            {
                return(ResultCommand.Error(new ArgumentException("Nothing to transfer.")));
            }

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

            if (srcEntries == null || destProfile == null)
            {
                return(ResultCommand.Error(new ArgumentException("Either source or dest is not IDiskProfile.")));
            }

            var progress = pm.GetProgress() ?? NullTransferProgress.Instance;


            if (AllowCustomImplementation)
            {
                logger.Info(String.Format("{0} {1} -> {2} using CustomImplementation",
                                          RemoveOriginal ? "Move" : "Copy", srcEntries.GetDescription(), destEntry.Name));
                return(destProfile.DiskIO
                       .GetTransferCommand(SourceEntryKey, DestinationDirectoryEntryKey, DestinationKey, RemoveOriginal, NextCommand));
            }
            else
            {
                var srcMapper   = srcProfile.DiskIO.Mapper;
                var destMapping = destProfile.DiskIO.Mapper[destEntry];

                if (!destMapping.IsVirtual && RemoveOriginal && srcEntries.All(entry => !srcMapper[entry].IsVirtual))
                {
                    return(await transferSystemIOAsync(pm, srcEntries, destEntry, DestinationKey));
                }
                else
                {
                    return(await transferScriptCommandAsync(pm, srcEntries, destEntry, DestinationKey));
                }
            }
        }
Ejemplo n.º 4
0
        public override async Task <IScriptCommand> ExecuteAsync(ParameterDic pm)
        {
            IEntryModel[] entryModels = DirectoryEntryKey == null ? new IEntryModel[] { } :
            (await pm.GetValueAsEntryModelArrayAsync(DirectoryEntryKey));

            object evnt = new RootChangedEvent(ChangeType, entryModels);;

            return(CoreScriptCommands.BroadcastEvent(EventsKey, evnt, NextCommand));
        }
Ejemplo n.º 5
0
        public override async Task <IScriptCommand> ExecuteAsync(ParameterDic pm)
        {
            var flValue             = pm.GetValue(FileListKey);
            IFileListViewModel flvm = flValue is IExplorerViewModel ?
                                      (flValue as IExplorerViewModel).FileList :
                                      flValue as IFileListViewModel;

            IEntryModel[] ems = await pm.GetValueAsEntryModelArrayAsync(EntriesKey, null);

            if (flvm == null)
            {
                return(ResultCommand.Error(new KeyNotFoundException(FileListKey)));
            }

            logger.Info(String.Format("Select {0} {1}", FileListKey, EntriesKey));
            using (var releaser = await flvm.ProcessedEntries.EntriesHelper.LoadingLock.LockAsync())
            {
                flvm.Selection.Select(evm => evm != null && ems.Contains(evm.EntryModel));
            }

            return(NextCommand);
        }
Ejemplo n.º 6
0
        public override async Task <IScriptCommand> ExecuteAsync(ParameterDic pm)
        {
            IEntryModel[] entryModel;
            try
            {
                entryModel = await pm.GetValueAsEntryModelArrayAsync(EntryKey);
            }
            catch
            {
                return(ResultCommand.Error(new ArgumentException(EntryKey + " is not found or not a directory IEntryModel or IEntryModel[]")));
            }
            string masks  = pm.ReplaceVariableInsideBracketed(MaskKey);
            var    filter = createFilter(ListOptions, masks);


            IEntryModel[] listItems = (await EntryUtils.ListAsync(entryModel, pm.CancellationToken, filter, false)).ToArray();

            logger.Debug(String.Format("{0} = IEntryModel[{1}]", DestinationKey, listItems.Length));
            pm.SetValue(DestinationKey, listItems);

            return(NextCommand);
        }
Ejemplo n.º 7
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);
        }
        private async Task <IScriptCommand> setParameterAsync(ParameterDic pm, IExplorerViewModel evm)
        {
            object value = ValueKey is string && (ValueKey as string).StartsWith("{") ? pm.GetValue <object>(ValueKey as string) : ValueKey;

            switch (ParameterType)
            {
            case ExplorerParameterType.EnableContextMenu:
                if (value is bool)
                {
                    evm.FileList.EnableContextMenu = evm.DirectoryTree.EnableContextMenu = true.Equals(value);
                }
                break;

            case ExplorerParameterType.EnableDrag:
                if (value is bool)
                {
                    evm.FileList.EnableDrag = evm.DirectoryTree.EnableDrag = true.Equals(value);
                }
                break;

            case ExplorerParameterType.EnableDrop:
                if (value is bool)
                {
                    evm.FileList.EnableDrop = evm.DirectoryTree.EnableDrop = true.Equals(value);
                }
                break;

            case ExplorerParameterType.EnableMultiSelect:
                if (value is bool)
                {
                    evm.FileList.EnableMultiSelect = true.Equals(value);
                }
                break;

            case ExplorerParameterType.ExplorerWidth:
                if (value is int)
                {
                    evm.Parameters.Width = (int)value;
                }
                break;

            case ExplorerParameterType.ExplorerHeight:
                if (value is int)
                {
                    evm.Parameters.Height = (int)value;
                }
                break;

            case ExplorerParameterType.ExplorerPosition:
                if (value is Point)
                {
                    evm.Parameters.Position = (Point)value;
                }
                break;

            case ExplorerParameterType.RootModels:
                if (ValueKey == null)
                {
                    return(ResultCommand.Error(new ArgumentNullException("ValueKey")));
                }

                IEntryModel[] rootModels = ValueKey is string?
                                           await pm.GetValueAsEntryModelArrayAsync(ValueKey as string, null) :
                                               ValueKey as IEntryModel[];

                if (rootModels == null)
                {
                    return(ResultCommand.Error(new KeyNotFoundException(ValueKey.ToString())));
                }
                evm.RootModels = rootModels;

                break;

            case ExplorerParameterType.FileName:
                if (evm is FilePickerViewModel)
                {
                    (evm as FilePickerViewModel).FileName = value as string;
                }
                break;

            case ExplorerParameterType.FilePickerMode:
                var            mode = pm.GetValue(ValueKey as string);
                FilePickerMode pickerMode;
                if (mode is FilePickerMode)
                {
                    pickerMode = (FilePickerMode)mode;
                }
                else if (mode is string)
                {
                    Enum.TryParse <FilePickerMode>(mode as string, out pickerMode);
                }
                else
                {
                    break;
                }
                if (evm is FilePickerViewModel)
                {
                    (evm as FilePickerViewModel).PickerMode = pickerMode;
                }
                break;

            case ExplorerParameterType.FilterString:
                string filterStr = pm.ReplaceVariableInsideBracketed(ValueKey as string);
                if (filterStr != null)
                {
                    evm.FilterStr = filterStr;
                }
                break;

            case ExplorerParameterType.ColumnList:
                ColumnInfo[] columnInfo = pm.GetValue <ColumnInfo[]>(ValueKey as string);
                if (columnInfo != null)
                {
                    evm.FileList.Columns.ColumnList = columnInfo;
                }
                break;

            case ExplorerParameterType.ColumnFilters:
                ColumnFilter[] columnfilters = pm.GetValue <ColumnFilter[]>(ValueKey as string);
                if (columnfilters != null)
                {
                    evm.FileList.Columns.ColumnFilters = columnfilters;
                }
                break;

            case ExplorerParameterType.ViewMode:
                if (value is string)
                {
                    evm.FileList.Parameters.ViewMode = value as string;
                }
                break;

            case ExplorerParameterType.ItemSize:

                if (value is int)
                {
                    evm.FileList.Parameters.ItemSize = (int)value;
                }
                break;

            case ExplorerParameterType.ShowToolbar:
                if (value is bool)
                {
                    evm.FileList.ShowToolbar = true.Equals(value);
                }
                break;

            case ExplorerParameterType.ShowSidebar:
                if (value is bool)
                {
                    evm.FileList.ShowSidebar = true.Equals(value);
                }
                break;

            case ExplorerParameterType.ShowGridHeader:
                if (value is bool)
                {
                    evm.FileList.ShowGridHeader = true.Equals(value);
                }
                break;

            case ExplorerParameterType.EnableBookmark:
                if (value is bool)
                {
                    evm.Breadcrumb.EnableBookmark = true.Equals(value);
                }
                break;

            default: return(ResultCommand.Error(new NotSupportedException(ParameterType.ToString())));
            }

            logger.Debug(String.Format("Set {0} to {1} ({2})", ParameterType, ValueKey, value));

            return(NextCommand);
        }
Ejemplo n.º 9
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
            }
        }