Ejemplo n.º 1
0
        /// <include file='doc.xml' path='doc/ScriptFork/*'/>
        /// <param name="args">.</param>
        public sealed override IEnumerable <FarFile> GetFiles(GetFilesEventArgs args)
        {
            if (AsGetFiles == null)
            {
                return(DoGetFiles(args));
            }

            // nothing, use the predefined file list
            var output = A.InvokeScript(AsGetFiles, this, args);

            if (output.Count == 0)
            {
                return(Cache);
            }

            // convert the output to files
            var result = new List <FarFile>();

            foreach (var it in output)
            {
                FarFile file = (FarFile)LanguagePrimitives.ConvertTo(it, typeof(FarFile), null);
                if (file != null)
                {
                    result.Add(file);
                }
            }

            return(result);
        }
Ejemplo n.º 2
0
        /// <inheritdoc/>
        public override IList <FarFile> UIGetFiles(GetFilesEventArgs args)
        {
            if (args == null)
            {
                return(null);
            }

            //Far.Api.ShowError("Not implemented", new NotImplementedException("Not implemented: " + this.Explorer.Location));

            args.Parameter = this;

            try
            {
                var files = base.UIGetFiles(args);
                return(files);
            }
            catch (TaskCanceledException)
            { }

            args.Result = JobResult.Default;
            //UIEscape(false); // crashes far
            //this.Close(); // exception or far crash

            return(new List <FarFile>());
        }
Ejemplo n.º 3
0
        IEnumerable <FarFile> DoInvokeDeep(ProgressBox progress, Explorer explorer, int depth)
        {
            // stop?
            if (Stopping || progress != null && UIUserStop())
            {
                yield break;
            }

            ++ProcessedDirectoryCount;

            // progress
            if (progress != null && progress.ElapsedFromShow.TotalMilliseconds > 500)
            {
                var directoryPerSecond = ProcessedDirectoryCount / progress.ElapsedFromStart.TotalSeconds;
                progress.Activity = string.Format(null, Res.SearchActivityDeep,
                                                  FoundFileCount, ProcessedDirectoryCount, directoryPerSecond);
                progress.ShowProgress();
            }

            var args = new GetFilesEventArgs(ExplorerModes.Find);

            foreach (var file in explorer.GetFiles(args))
            {
                // stop?
                if (Stopping)
                {
                    break;
                }

                // process and add
                bool add = Directory || !file.IsDirectory;
                if (add && Filter != null)
                {
                    add = Filter(explorer, file);
                }
                if (add)
                {
                    ++FoundFileCount;
                    yield return(new SuperFile(explorer, file));
                }

                // skip if deep or leaf
                if (Depth > 0 && depth >= Depth || !file.IsDirectory)
                {
                    continue;
                }

                Explorer explorer2 = SuperExplorer.ExploreSuperDirectory(explorer, ExplorerModes.Find, file);
                if (explorer2 == null)
                {
                    continue;
                }

                foreach (var file2 in DoInvokeDeep(progress, explorer2, depth + 1))
                {
                    yield return(file2);
                }
            }
        }
Ejemplo n.º 4
0
        /// <inheritdoc/>
        public override IList<FarFile> UIGetFiles(GetFilesEventArgs args)
        {
            if (args == null) return null;

            args.Parameter = this;

            return base.UIGetFiles(args);
        }
Ejemplo n.º 5
0
        IList <XPathObjectNode> ActivateSuperFileElements()
        {
            var file = (SuperFile)_target;             //????

            if (!file.IsDirectory)
            {
                _elements.Target = _emptyElements;
                return(_emptyElements);
            }

            // progress
            if (_context.IncrementDirectoryCount != null)
            {
                _context.IncrementDirectoryCount(1);
            }

            var elements = new List <XPathObjectNode>();

            Explorer explorer;

            if (file.Explorer.CanExploreLocation)
            {
                var argsExplore = new ExploreLocationEventArgs(ExplorerModes.Find, file.File.Name);
                explorer = file.Explorer.ExploreLocation(argsExplore);
            }
            else
            {
                var argsExplore = new ExploreDirectoryEventArgs(ExplorerModes.Find, file.File);
                explorer = file.Explorer.ExploreDirectory(argsExplore);
            }

            if (explorer != null)
            {
                var argsFiles = new GetFilesEventArgs(ExplorerModes.Find);
                foreach (var it in explorer.GetFiles(argsFiles))
                {
                    // filter out a leaf
                    if (_context.Filter != null && !it.IsDirectory && !_context.Filter(explorer, it))
                    {
                        continue;
                    }

                    // add
                    elements.Add(new XPathObjectNode(_context, new SuperFile(explorer, it), null, this, elements, elements.Count));
                }
            }

            if (elements.Count == 0)
            {
                _elements.Target = _emptyElements;
            }
            else
            {
                _elements.Target = elements;
            }

            return(elements);
        }
Ejemplo n.º 6
0
        /// <inheritdoc/>
        public override IList <FarFile> UIGetFiles(GetFilesEventArgs args)
        {
            if (args == null)
            {
                return(null);
            }

            args.Parameter = this;

            return(base.UIGetFiles(args));
        }
Ejemplo n.º 7
0
        public override IList<FarFile> GetFiles(GetFilesEventArgs args)
        {
            IList<FarFile> realList = new List<FarFile>();

            realList.Add(createParentElement());

            foreach (var playList in CurrentDevice.Playlists)
            {
                realList.Add(createDirectory(getPlaylistName(playList), playList));
            }

            return realList;
        }
Ejemplo n.º 8
0
        public override IList<FarFile> GetFiles(GetFilesEventArgs args)
        {
            IList<FarFile> realList = new List<FarFile>();

            realList.Add(createParentElement());

            foreach (var dev in FarPodContext.Current.DeviceSource.GetDevices())
            {
                realList.Add(createDirectory(getDeviceName(dev), dev));
            }

            return realList;
        }
Ejemplo n.º 9
0
        /// <inheritdoc/>
        public override IList<FarFile> GetFiles(GetFilesEventArgs args)
        {
            if (args == null) return null;

            _Files.Clear();

            var parameter = args.ParameterOrDefault<TreeExplorerGetFilesParameter>();

            foreach (TreeFile ti in _RootFiles)
                AddFileFromTreeItem(ti, parameter.ShowHidden);

            return _Files;
        }
Ejemplo n.º 10
0
        /// <inheritdoc/>
        public override IList <FarFile> UIGetFiles(GetFilesEventArgs args)
        {
            if (args == null)
            {
                return(null);
            }

            args.Parameter = new TreeExplorerGetFilesParameter()
            {
                ShowHidden = ShowHidden
            };

            return(base.UIGetFiles(args));
        }
Ejemplo n.º 11
0
        /// <inheritdoc/>
        public override IList <FarFile> GetFiles(GetFilesEventArgs args)
        {
            if (args == null)
            {
                return(null);
            }

            _Files.Clear();

            var parameter = args.ParameterOrDefault <TreeExplorerGetFilesParameter>();

            foreach (TreeFile ti in _RootFiles)
            {
                AddFileFromTreeItem(ti, parameter.ShowHidden);
            }

            return(_Files);
        }
Ejemplo n.º 12
0
        internal IList <FarFile> Explore(GetFilesEventArgs args)
        {
            if (args == null)
            {
                return(null);
            }
            var Files = Explorer.Cache;

            // refill
            if (NeedsNewFiles)
            {
                if (CanClose())
                {
                    if (Adapter != null)
                    {
                        Table.Clear();
                    }
                    Fill();
                }
            }

            // no job?
            if (!ToUpdateData && !NeedsNewFiles)
            {
                return(Files);
            }

            // refresh data
            for (int iFile = Files.Count; --iFile >= 0;)
            {
                FarFile f   = Files[iFile];
                DataRow Row = f.Data as DataRow;
                if (Row == null || Row.RowState == DataRowState.Deleted || Row.RowState == DataRowState.Detached)
                {
                    Files.RemoveAt(iFile);
                    continue;
                }
            }

            // prevent next job
            ToUpdateData = false;
            return(Files);
        }
Ejemplo n.º 13
0
        public override IList<FarFile> GetFiles(GetFilesEventArgs args)
        {
            IList<FarFile> realList = new List<FarFile>();

            realList.Add(createParentElement());

            foreach (var track in CurrentPlayList.Tracks)
            {
                FarFile ff = new SetFile();

                ff.Name = IPodTrackFormatter.Get(track, FarPodSetting.Default.TrackNameFormatForPanel, true) + Path.GetExtension(track.FilePath);

                ff.Data = track;

                ff.Length = track.FileSize.ByteCount;

                realList.Add(ff);
            }

            return realList;
        }
Ejemplo n.º 14
0
 /// <inheritdoc/>
 public override IEnumerable <FarFile> GetFiles(GetFilesEventArgs args)
 {
     return(_Cache);
 }
Ejemplo n.º 15
0
        /// <inheritdoc/>
        public override IEnumerable <FarFile> GetFiles(GetFilesEventArgs args)
        {
            var result = new List <FarFile>();

            if (args == null)
            {
                return(result);
            }

            try
            {
                //! get properties
                // - Using -LiteralPath is a problem, e.g. Registry: returns nothing.
                // - Script is used for PS conversion of property values to string.
                // - Script has to ignore a property with empty name (if any, can be in Registry).
                // - If PS* included then they can't be found by `gp <path> <name>`;
                // so, don't add, they are noisy anyway (even if marked system or hidden).

                // get property bag 090409
                Collection <PSObject> bag = A.Psf.Engine.InvokeProvider.Property.Get(Kit.EscapeWildcard(ItemPath), null);

                // filter
                var filter = new List <string>(5);
                filter.Add("PSChildName");
                filter.Add("PSDrive");
                filter.Add("PSParentPath");
                filter.Add("PSPath");
                filter.Add("PSProvider");

                // add
                foreach (PSObject o in bag)
                {
                    foreach (PSPropertyInfo pi in o.Properties)
                    {
                        // skip empty ?? still needed?
                        string name = pi.Name;
                        if (string.IsNullOrEmpty(name))
                        {
                            continue;
                        }

                        // filter and shrink filter
                        int i = filter.IndexOf(name);
                        if (i >= 0)
                        {
                            filter.RemoveAt(i);
                            continue;
                        }

                        // create file
                        SetFile file = new SetFile()
                        {
                            Name       = name,
                            IsReadOnly = !pi.IsSettable,
                            Data       = pi,
                            // set its value
                            Description = Converter.FormatValue(pi.Value, Settings.Default.FormatEnumerationLimit)
                        };

                        // add
                        result.Add(file);
                    }
                }
            }
            catch (RuntimeException error)
            {
                if (args.UI)
                {
                    A.Message(error.Message);
                }
            }

            return(result);
        }
Ejemplo n.º 16
0
 /// <summary>
 /// <see cref="Explorer.GetFiles"/> worker.
 /// </summary>
 /// <param name="args">.</param>
 public virtual IList<FarFile> DoGetFiles(GetFilesEventArgs args)
 {
     return Cache;
 }
Ejemplo n.º 17
0
 public override IList <FarFile> GetFiles(GetFilesEventArgs args) => _files;
Ejemplo n.º 18
0
 /// <inheritdoc/>
 public override IList<FarFile> GetFiles(GetFilesEventArgs args)
 {
     return _Cache;
 }
Ejemplo n.º 19
0
        IEnumerable<FarFile> DoInvokeXPath(ProgressBox progress)
        {
            // object context
            var objectContext = new XPathObjectContext()
            {
                Filter = this.Filter,
                IncrementDirectoryCount = delegate(int count)
                {
                    ProcessedDirectoryCount += count;
                    if (progress == null)
                        return;

                    var directoryPerSecond = ProcessedDirectoryCount / progress.ElapsedFromStart.TotalSeconds;
                    progress.Activity = string.Format(null, Res.SearchActivityDeep,
                        FoundFileCount, ProcessedDirectoryCount, directoryPerSecond);
                    progress.ShowProgress();
                },
                Stopping = delegate
                {
                    return Stopping || progress != null && UIUserStop();
                }
            };

            var xsltContext = new XPathXsltContext(objectContext.NameTable);
            if (_XVariables != null)
            {
                foreach (var kv in _XVariables)
                    xsltContext.AddVariable(kv.Key, kv.Value);
            }

            // XPath text
            string xpath;
            if (string.IsNullOrEmpty(XFile))
            {
                xpath = XPath;
            }
            else
            {
                var input = XPathInput.ParseFile(XFile);
                xpath = input.Expression;
                foreach (var kv in input.Variables)
                    xsltContext.AddVariable(kv.Key, kv.Value);
            }

            var expression = XPathExpression.Compile(xpath);
            if (expression.ReturnType != XPathResultType.NodeSet)
                throw new InvalidOperationException("Invalid expression return type.");
            expression.SetContext(xsltContext);

            ++ProcessedDirectoryCount;
            var args = new GetFilesEventArgs(ExplorerModes.Find);
            foreach (var file in _RootExplorer.GetFiles(args))
            {
                // stop?
                if (Stopping || progress != null && UIUserStop()) //???? progress to navigator
                    break;

                // filter out a leaf
                if (Filter != null && !file.IsDirectory && !Filter(_RootExplorer, file))
                    continue;

                var xfile = new SuperFile(_RootExplorer, file);
                var navigator = new XPathObjectNavigator(xfile, objectContext);
                var iterator = navigator.Select(expression);
                while (iterator.MoveNext())
                {
                    // stop?
                    if (Stopping || progress != null && UIUserStop()) //???? progress to navigator
                        break;

                    // found file or directory, ignore anything else
                    var currentFile = iterator.Current.UnderlyingObject as SuperFile;
                    if (currentFile == null)
                        continue;

                    // filter out directory, it is already done for files
                    if (Filter != null && currentFile.IsDirectory && (!Directory || !Filter(currentFile.Explorer, currentFile.File)))
                        continue;

                    // add
                    yield return currentFile;
                    ++FoundFileCount;
                }
            }
        }
Ejemplo n.º 20
0
        internal IList<FarFile> Explore(GetFilesEventArgs args)
        {
            if (args == null) return null;
            var Files = Explorer.Cache;

            // refill
            if (NeedsNewFiles)
            {
                if (CanClose())
                {
                    if (Adapter != null)
                        Table.Clear();
                    Fill();
                }
            }

            // no job?
            if (!ToUpdateData && !NeedsNewFiles)
                return Files;

            // refresh data
            for (int iFile = Files.Count; --iFile >= 0; )
            {
                FarFile f = Files[iFile];
                DataRow Row = f.Data as DataRow;
                if (Row == null || Row.RowState == DataRowState.Deleted || Row.RowState == DataRowState.Detached)
                {
                    Files.RemoveAt(iFile);
                    continue;
                }
            }

            // prevent next job
            ToUpdateData = false;
            return Files;
        }
Ejemplo n.º 21
0
 internal abstract object GetData(GetFilesEventArgs args);
Ejemplo n.º 22
0
 public override IList <FarFile> GetFiles(GetFilesEventArgs args)
 {
     return(_files);
 }
Ejemplo n.º 23
0
        internal override object GetData(GetFilesEventArgs args)
        {
            // custom script
            if (AsGetData != null)
            {
                // call
                var result = A.InvokeScript(AsGetData, this, args);

                // discover and get the cache or get other objects as they are
                if (result.Count == 1 && result[0].BaseObject == Cache)
                    return Cache;
                else
                    return result;
            }

            var Files = Cache;
            try
            {
                //???? it works but smells
                if (!args.NewFiles && _AddedValues == null && (Map != null || Files.Count > 0 && Files[0] is SetFile))
                    return Files;

                if (Map == null || Columns == null)
                {
                    if (Files.Count == 0)
                        return _AddedValues ?? new Collection<PSObject>();

                    var result = new Collection<PSObject>();
                    foreach (FarFile file in Files)
                        result.Add(PSObject.AsPSObject(file.Data));
                    if (_AddedValues != null)
                        foreach (PSObject value in _AddedValues)
                            result.Add(value);

                    return result;
                }

                // _100330_191639
                if (_AddedValues == null)
                    return Files;

                var map = Map;
                var files = new List<FarFile>(_AddedValues.Count);
                foreach (PSObject value in _AddedValues)
                    files.Add(new MapFile(value, map));

                return files;
            }
            finally
            {
                _AddedValues = null;
            }
        }
Ejemplo n.º 24
0
        /// <inheritdoc/>
        public override IList<FarFile> GetFiles(GetFilesEventArgs args)
        {
            var result = new List<FarFile>();
            if (args == null) return result;

            try
            {
                //! get properties
                // - Using -LiteralPath is a problem, e.g. Registry: returns nothing.
                // - Script is used for PS conversion of property values to string.
                // - Script has to ignore a property with empty name (if any, can be in Registry).
                // - If PS* included then they can't be found by `gp <path> <name>`;
                // so, don't add, they are noisy anyway (even if marked system or hidden).

                // get property bag 090409
                Collection<PSObject> bag = A.Psf.Engine.InvokeProvider.Property.Get(Kit.EscapeWildcard(ItemPath), null);

                // filter
                var filter = new List<string>(5);
                filter.Add("PSChildName");
                filter.Add("PSDrive");
                filter.Add("PSParentPath");
                filter.Add("PSPath");
                filter.Add("PSProvider");

                // add
                foreach (PSObject o in bag)
                {
                    foreach (PSPropertyInfo pi in o.Properties)
                    {
                        // skip empty ?? still needed?
                        string name = pi.Name;
                        if (string.IsNullOrEmpty(name))
                            continue;

                        // filter and shrink filter
                        int i = filter.IndexOf(name);
                        if (i >= 0)
                        {
                            filter.RemoveAt(i);
                            continue;
                        }

                        // create file
                        SetFile file = new SetFile()
                        {
                            Name = name,
                            IsReadOnly = !pi.IsSettable,
                            Data = pi,
                            // set its value
                            Description = Converter.FormatValue(pi.Value, Settings.Default.FormatEnumerationLimit)
                        };

                        // add
                        result.Add(file);
                    }
                }
            }
            catch (RuntimeException error)
            {
                if (args.UI)
                    A.Message(error.Message);
            }

            return result;
        }
Ejemplo n.º 25
0
        /// <inheritdoc/>
        public override IList<FarFile> DoGetFiles(GetFilesEventArgs args)
        {
            if (args == null) return null;

            var panel = args.Parameter as FormatPanel;

            // call the worker
            // _090408_232925 If we throw then FarNet returns false and Far closes the panel.
            object data;
            try
            {
                data = GetData(args);
            }
            catch (RuntimeException ex)
            {
                if (args.UI)
                    Far.Api.ShowError(Res.Me, ex);

                data = new List<FarFile>();
            }

            // if the data are files just use them, assume all is done
            IList<FarFile> readyFiles = data as IList<FarFile>;
            if (readyFiles != null)
            {
                Cache = readyFiles;
                return Cache;
            }

            // PS objects
            Collection<PSObject> values = (Collection<PSObject>)data;

            // empty?
            if (values.Count == 0)
            {
                // drop files in any case
                Cache.Clear();

                // no panel, no job
                if (panel == null)
                    return Cache;

                // respect custom columns
                if (Columns != null)
                    return Cache;

                // is it already <empty>?
                PanelPlan plan = panel.GetPlan(PanelViewMode.AlternativeFull);
                if (plan == null)
                    plan = new PanelPlan();
                else if (plan.Columns.Length == 1 && plan.Columns[0].Name == "<empty>")
                    return Cache;

                // reuse the mode: reset columns, keep other data intact
                plan.Columns = new FarColumn[] { new SetColumn() { Kind = "N", Name = "<empty>" } };
                panel.SetPlan(PanelViewMode.AlternativeFull, plan);
                return Cache;
            }

            // not empty; values has to be removed in any case
            try
            {
                // custom
                if (Columns != null)
                {
                    BuildFiles(values);
                    return Cache;
                }

                // Check some special cases and try to get the common type.
                // _100309_121508 Linear type case
                Type theType;
                if (Converter.IsLinearType(values[0].BaseObject.GetType()) ||
                    values[0].BaseObject is System.Collections.IEnumerable ||
                    null == (theType = A.FindCommonType(values)))
                {
                    // use index, value, type mode
                    if (panel != null)
                        panel.BuildPlan(Format.BuildFilesMixed(Cache, values));
                    return Cache;
                }

                Meta[] metas = null;

                // try to get format
                if (theType != typeof(PSCustomObject))
                    metas = Format.TryFormatByTableControl(values[0], panel == null ? 80 : panel.Window.Width); //???? avoid formatting at all

                // use members
                if (metas == null)
                    metas = Format.TryFormatByMembers(values, theType != null && theType == values[0].BaseObject.GetType());

                if (metas == null)
                {
                    if (panel != null)
                        panel.BuildPlan(Format.BuildFilesMixed(Cache, values));
                }
                else
                {
                    MakeMap(metas);
                    if (panel != null)
                        panel.SetPlan(PanelViewMode.AlternativeFull, Format.SetupPanelMode(Metas));

                    BuildFiles(values);
                }
            }
            finally
            {
                values.Clear();
            }

            return Cache;
        }
Ejemplo n.º 26
0
 internal abstract object GetData(GetFilesEventArgs args);
Ejemplo n.º 27
0
 /// <summary>
 /// Returns the files.
 /// </summary>
 /// <param name="args">.</param>
 /// <remarks>
 /// <para>
 /// The method should choose the type of the result list carefully.
 /// The caller does not make a copy, it users the result as it is.
 /// The caller may iterate through the list many times.
 /// The caller assumes that the list is never changed.
 /// If this is not the case then the method has to return a copy.
 /// But it is fine to reuse or update the same list on next calls.
 /// </para>
 /// <include file='doc.xml' path='doc/ExplorerModes/*'/>
 /// </remarks>
 public abstract IList<FarFile> GetFiles(GetFilesEventArgs args);
Ejemplo n.º 28
0
        IEnumerable<FarFile> DoInvokeDeep(ProgressBox progress, Explorer explorer, int depth)
        {
            // stop?
            if (Stopping || progress != null && UIUserStop())
                yield break;

            ++ProcessedDirectoryCount;

            // progress
            if (progress != null && progress.ElapsedFromShow.TotalMilliseconds > 500)
            {
                var directoryPerSecond = ProcessedDirectoryCount / progress.ElapsedFromStart.TotalSeconds;
                progress.Activity = string.Format(null, Res.SearchActivityDeep,
                    FoundFileCount, ProcessedDirectoryCount, directoryPerSecond);
                progress.ShowProgress();
            }

            var args = new GetFilesEventArgs(ExplorerModes.Find);
            foreach (var file in explorer.GetFiles(args))
            {
                // stop?
                if (Stopping)
                    break;

                // process and add
                bool add = Directory || !file.IsDirectory;
                if (add && Filter != null)
                    add = Filter(explorer, file);
                if (add)
                {
                    ++FoundFileCount;
                    yield return new SuperFile(explorer, file);
                }

                // skip if deep or leaf
                if (Depth > 0 && depth >= Depth || !file.IsDirectory)
                    continue;

                Explorer explorer2 = SuperExplorer.ExploreSuperDirectory(explorer, ExplorerModes.Find, file);
                if (explorer2 == null)
                    continue;

                foreach (var file2 in DoInvokeDeep(progress, explorer2, depth + 1))
                    yield return file2;
            }
        }
Ejemplo n.º 29
0
 /// <summary>
 /// Calls <see cref="FarNet.Explorer.GetFiles"/>.
 /// </summary>
 /// <param name="args">.</param>
 public virtual IList<FarFile> UIGetFiles(GetFilesEventArgs args)
 {
     return Explorer.GetFiles(args);
 }
Ejemplo n.º 30
0
        IEnumerable<FarFile> DoInvokeWide(ProgressBox progress)
        {
            var queue = new Queue<Explorer>();
            queue.Enqueue(_RootExplorer);

            while (queue.Count > 0 && !Stopping)
            {
                // cancel?
                if (progress != null && UIUserStop())
                    break;

                // current
                var explorer = queue.Dequeue();
                ++ProcessedDirectoryCount;

                // progress
                if (progress != null && progress.ElapsedFromShow.TotalMilliseconds > 500)
                {
                    var directoryPerSecond = ProcessedDirectoryCount / progress.ElapsedFromStart.TotalSeconds;
                    progress.Activity = string.Format(null, Res.SearchActivityWide,
                        FoundFileCount, ProcessedDirectoryCount, queue.Count, directoryPerSecond);
                    progress.ShowProgress();
                }

                var args = new GetFilesEventArgs(ExplorerModes.Find);
                foreach (var file in explorer.GetFiles(args))
                {
                    // stop?
                    if (Stopping)
                        break;

                    // process and add
                    bool add = Directory || !file.IsDirectory;
                    if (add && Filter != null)
                        add = Filter(explorer, file);
                    if (add)
                    {
                        ++FoundFileCount;
                        yield return new SuperFile(explorer, file);
                    }

                    // skip if flat or leaf
                    if (!Recurse || !file.IsDirectory)
                        continue;

                    Explorer explorer2 = SuperExplorer.ExploreSuperDirectory(explorer, ExplorerModes.Find, file);
                    if (explorer2 != null)
                        queue.Enqueue(explorer2);
                }
            }
        }
Ejemplo n.º 31
0
        public override IList<FarFile> GetFiles(GetFilesEventArgs args)
        {
            if (args == null) return null;

            var result = new List<FarFile>();
            try
            {
                if (MemberMode == 0)
                {
                    //! _100426_034702
                    //! Get actual members to show:
                    //! _Value.Properties contains too much, i.e. for DataRow: HasErrors, ItemArray, RowError, RowState;
                    //! use Get-Member at first (don't use it itself, because it returns sorted data, we want unsorted).
                    //! Idea to cache them is not good:
                    //! price: high (have to sync on exclude, add, delete, etc.)
                    //! value: low (it is UI and member number is normally small)
                    var membersToShow = new List<string>();
                    {
                        //_131002_111804 in a DictionaryEntry avoid Name (same as Key)
                        if (Value.BaseObject.GetType() == typeof(DictionaryEntry))
                        {
                            membersToShow.Add("Key");
                            membersToShow.Add("Value");
                        }
                        else
                        {
                            string code = "Get-Member -InputObject $args[0] -MemberType Properties -ErrorAction 0";
                            foreach (PSObject o in A.InvokeCode(code, Value))
                            {
                                string name = o.Properties[Word.Name].Value.ToString();
                                if (_ExcludeMemberRegex == null || !_ExcludeMemberRegex.IsMatch(name))
                                    membersToShow.Add(name);
                            }
                        }
                    }

                    // to check hidden columns
                    var datarow = Value.BaseObject as DataRow;

                    // now we are ready to process properties in their original order
                    foreach (PSPropertyInfo pi in Value.Properties)
                    {
                        if (!membersToShow.Contains(pi.Name))
                            continue;

                        var value = A.SafePropertyValue(pi);

                        SetFile file = new SetFile()
                        {
                            Name = pi.Name,
                            Data = pi
                        };

                        // base object
                        PSObject asPSObject = value as PSObject;
                        if (asPSObject != null)
                            value = asPSObject.BaseObject;

                        // value
                        file.Description = Converter.FormatValue(value, Settings.Default.FormatEnumerationLimit);

                        // hidden by user
                        if (_HideMemberRegex != null && _HideMemberRegex.IsMatch(file.Name))
                            file.IsHidden = true;

                        // hidden due to column features
                        if (!file.IsHidden && datarow != null)
                        {
                            var column = datarow.Table.Columns[file.Name];
                            if (column.AutoIncrement || column.ColumnMapping == MappingType.Hidden || column.Expression.Length > 0)
                                file.IsHidden = true;
                        }

                        result.Add(file);
                    }
                }
                else
                {
                    string code;
                    if (MemberMode == 1)
                        code = "Get-Member -InputObject $args[0] -ErrorAction 0 -View All";
                    else
                        code = "Get-Member -InputObject $args[0] -ErrorAction 0 -View All -Static";
                    foreach (PSObject o in A.InvokeCode(code, Value))
                    {
                        SetFile f = new SetFile();
                        f.Name = o.Properties[Word.Name].Value.ToString();

                        PSPropertyInfo pi;
                        pi = o.Properties["MemberType"];
                        f.Description = pi.Value.ToString();

                        pi = o.Properties["Definition"];
                        f.Description += " " + pi.Value.ToString();

                        f.Data = o;
                        result.Add(f);
                    }
                }
            }
            catch (RuntimeException exception)
            {
                if (args.UI)
                    A.Message(exception.Message);
            }

            return result;
        }
Ejemplo n.º 32
0
        /// <inheritdoc/>
        public override IList<FarFile> UIGetFiles(GetFilesEventArgs args)
        {
            if (args == null) return null;

            args.Parameter = new TreeExplorerGetFilesParameter() { ShowHidden = ShowHidden };

            return base.UIGetFiles(args);
        }
Ejemplo n.º 33
0
 public override IList <FarFile> GetFiles(GetFilesEventArgs args)
 {
     // Return the ready file list. It never changes and this
     // method does not have to create files again on requests.
     return(Files);
 }
Ejemplo n.º 34
0
        IEnumerable <FarFile> DoInvokeWide(ProgressBox progress)
        {
            var queue = new Queue <Explorer>();

            queue.Enqueue(_RootExplorer);

            while (queue.Count > 0 && !Stopping)
            {
                // cancel?
                if (progress != null && UIUserStop())
                {
                    break;
                }

                // current
                var explorer = queue.Dequeue();
                ++ProcessedDirectoryCount;

                // progress
                if (progress != null && progress.ElapsedFromShow.TotalMilliseconds > 500)
                {
                    var directoryPerSecond = ProcessedDirectoryCount / progress.ElapsedFromStart.TotalSeconds;
                    progress.Activity = string.Format(null, Res.SearchActivityWide,
                                                      FoundFileCount, ProcessedDirectoryCount, queue.Count, directoryPerSecond);
                    progress.ShowProgress();
                }

                var args = new GetFilesEventArgs(ExplorerModes.Find);
                foreach (var file in explorer.GetFiles(args))
                {
                    // stop?
                    if (Stopping)
                    {
                        break;
                    }

                    // process and add
                    bool add = Directory || !file.IsDirectory;
                    if (add && Filter != null)
                    {
                        add = Filter(explorer, file);
                    }
                    if (add)
                    {
                        ++FoundFileCount;
                        yield return(new SuperFile(explorer, file));
                    }

                    // skip if flat or leaf
                    if (!Recurse || !file.IsDirectory)
                    {
                        continue;
                    }

                    Explorer explorer2 = SuperExplorer.ExploreSuperDirectory(explorer, ExplorerModes.Find, file);
                    if (explorer2 != null)
                    {
                        queue.Enqueue(explorer2);
                    }
                }
            }
        }
Ejemplo n.º 35
0
 internal override object GetData(GetFilesEventArgs args)
 {
     // get items for the location
     return(A.GetChildItems(Location));
 }
Ejemplo n.º 36
0
        IEnumerable <FarFile> DoInvokeXPath(ProgressBox progress)
        {
            // object context
            var objectContext = new XPathObjectContext()
            {
                Filter = this.Filter,
                IncrementDirectoryCount = delegate(int count)
                {
                    ProcessedDirectoryCount += count;
                    if (progress == null)
                    {
                        return;
                    }

                    var directoryPerSecond = ProcessedDirectoryCount / progress.ElapsedFromStart.TotalSeconds;
                    progress.Activity = string.Format(null, Res.SearchActivityDeep,
                                                      FoundFileCount, ProcessedDirectoryCount, directoryPerSecond);
                    progress.ShowProgress();
                },
                Stopping = delegate
                {
                    return(Stopping || progress != null && UIUserStop());
                }
            };

            var xsltContext = new XPathXsltContext(objectContext.NameTable);

            if (_XVariables != null)
            {
                foreach (var kv in _XVariables)
                {
                    xsltContext.AddVariable(kv.Key, kv.Value);
                }
            }

            // XPath text
            string xpath;

            if (string.IsNullOrEmpty(XFile))
            {
                xpath = XPath;
            }
            else
            {
                var input = XPathInput.ParseFile(XFile);
                xpath = input.Expression;
                foreach (var kv in input.Variables)
                {
                    xsltContext.AddVariable(kv.Key, kv.Value);
                }
            }

            var expression = XPathExpression.Compile(xpath);

            if (expression.ReturnType != XPathResultType.NodeSet)
            {
                throw new InvalidOperationException("Invalid expression return type.");
            }
            expression.SetContext(xsltContext);

            ++ProcessedDirectoryCount;
            var args = new GetFilesEventArgs(ExplorerModes.Find);

            foreach (var file in _RootExplorer.GetFiles(args))
            {
                // stop?
                if (Stopping || progress != null && UIUserStop())                 //???? progress to navigator
                {
                    break;
                }

                // filter out a leaf
                if (Filter != null && !file.IsDirectory && !Filter(_RootExplorer, file))
                {
                    continue;
                }

                var xfile     = new SuperFile(_RootExplorer, file);
                var navigator = new XPathObjectNavigator(xfile, objectContext);
                var iterator  = navigator.Select(expression);
                while (iterator.MoveNext())
                {
                    // stop?
                    if (Stopping || progress != null && UIUserStop())                     //???? progress to navigator
                    {
                        break;
                    }

                    // found file or directory, ignore anything else
                    if (!(iterator.Current.UnderlyingObject is SuperFile currentFile))
                    {
                        continue;
                    }

                    // filter out directory, it is already done for files
                    if (Filter != null && currentFile.IsDirectory && (!Directory || !Filter(currentFile.Explorer, currentFile.File)))
                    {
                        continue;
                    }

                    // add
                    yield return(currentFile);

                    ++FoundFileCount;
                }
            }
        }
Ejemplo n.º 37
0
 /// <summary>
 /// <see cref="Explorer.GetFiles"/> worker.
 /// </summary>
 /// <param name="args">.</param>
 public virtual IList <FarFile> DoGetFiles(GetFilesEventArgs args)
 {
     return(Cache);
 }
Ejemplo n.º 38
0
        internal override object GetData(GetFilesEventArgs args)
        {
            // custom script
            if (AsGetData != null)
            {
                // call
                var result = A.InvokeScript(AsGetData, this, args);

                // discover and get the cache or get other objects as they are
                if (result.Count == 1 && result[0].BaseObject == Cache)
                {
                    return(Cache);
                }
                else
                {
                    return(result);
                }
            }

            var Files = Cache;

            try
            {
                //???? it works but smells
                if (!args.NewFiles && _AddedValues == null && (Map != null || Files.Count > 0 && Files[0] is SetFile))
                {
                    return(Files);
                }

                if (Map == null || Columns == null)
                {
                    if (Files.Count == 0)
                    {
                        return(_AddedValues ?? new Collection <PSObject>());
                    }

                    var result = new Collection <PSObject>();
                    foreach (FarFile file in Files)
                    {
                        result.Add(PSObject.AsPSObject(file.Data));
                    }
                    if (_AddedValues != null)
                    {
                        foreach (PSObject value in _AddedValues)
                        {
                            result.Add(value);
                        }
                    }

                    return(result);
                }

                // _100330_191639
                if (_AddedValues == null)
                {
                    return(Files);
                }

                var map   = Map;
                var files = new List <FarFile>(_AddedValues.Count);
                foreach (PSObject value in _AddedValues)
                {
                    files.Add(new MapFile(value, map));
                }

                return(files);
            }
            finally
            {
                _AddedValues = null;
            }
        }
Ejemplo n.º 39
0
        public override IList <FarFile> GetFiles(GetFilesEventArgs args)
        {
            if (args == null)
            {
                return(null);
            }

            var result = new List <FarFile>();

            try
            {
                if (MemberMode == 0)
                {
                    //! _100426_034702
                    //! Get actual members to show:
                    //! _Value.Properties contains too much, i.e. for DataRow: HasErrors, ItemArray, RowError, RowState;
                    //! use Get-Member at first (don't use it itself, because it returns sorted data, we want unsorted).
                    //! Idea to cache them is not good:
                    //! price: high (have to sync on exclude, add, delete, etc.)
                    //! value: low (it is UI and member number is normally small)
                    var membersToShow = new List <string>();
                    {
                        //_131002_111804 in a DictionaryEntry avoid Name (same as Key)
                        if (Value.BaseObject.GetType() == typeof(DictionaryEntry))
                        {
                            membersToShow.Add("Key");
                            membersToShow.Add("Value");
                        }
                        else
                        {
                            string code = "Get-Member -InputObject $args[0] -MemberType Properties -ErrorAction 0";
                            foreach (PSObject o in A.InvokeCode(code, Value))
                            {
                                string name = o.Properties[Word.Name].Value.ToString();
                                if (_ExcludeMemberRegex == null || !_ExcludeMemberRegex.IsMatch(name))
                                {
                                    membersToShow.Add(name);
                                }
                            }
                        }
                    }

                    // to check hidden columns
                    var datarow = Value.BaseObject as DataRow;

                    // now we are ready to process properties in their original order
                    foreach (PSPropertyInfo pi in Value.Properties)
                    {
                        if (!membersToShow.Contains(pi.Name))
                        {
                            continue;
                        }

                        var value = A.SafePropertyValue(pi);

                        SetFile file = new SetFile()
                        {
                            Name = pi.Name,
                            Data = pi
                        };

                        // base object
                        PSObject asPSObject = value as PSObject;
                        if (asPSObject != null)
                        {
                            value = asPSObject.BaseObject;
                        }

                        // value
                        file.Description = Converter.FormatValue(value, Settings.Default.FormatEnumerationLimit);

                        // hidden by user
                        if (_HideMemberRegex != null && _HideMemberRegex.IsMatch(file.Name))
                        {
                            file.IsHidden = true;
                        }

                        // hidden due to column features
                        if (!file.IsHidden && datarow != null)
                        {
                            var column = datarow.Table.Columns[file.Name];
                            if (column.AutoIncrement)
                            {
                                file.IsHidden = true;
                            }
                        }

                        result.Add(file);
                    }
                }
                else
                {
                    string code;
                    if (MemberMode == 1)
                    {
                        code = "Get-Member -InputObject $args[0] -ErrorAction 0 -View All";
                    }
                    else
                    {
                        code = "Get-Member -InputObject $args[0] -ErrorAction 0 -View All -Static";
                    }
                    foreach (PSObject o in A.InvokeCode(code, Value))
                    {
                        SetFile f = new SetFile();
                        f.Name = o.Properties[Word.Name].Value.ToString();

                        PSPropertyInfo pi;
                        pi            = o.Properties["MemberType"];
                        f.Description = pi.Value.ToString();

                        pi             = o.Properties["Definition"];
                        f.Description += " " + pi.Value.ToString();

                        f.Data = o;
                        result.Add(f);
                    }
                }
            }
            catch (RuntimeException exception)
            {
                if (args.UI)
                {
                    A.Message(exception.Message);
                }
            }

            return(result);
        }
Ejemplo n.º 40
0
 public override IList<FarFile> GetFiles(GetFilesEventArgs args)
 {
     // Return the ready file list. It never changes and this
     // method does not have to create files again on requests.
     return Files;
 }
Ejemplo n.º 41
0
        /// <include file='doc.xml' path='doc/ScriptFork/*'/>
        /// <param name="args">.</param>
        public override sealed IList<FarFile> GetFiles(GetFilesEventArgs args)
        {
            if (AsGetFiles == null)
                return DoGetFiles(args);

            // nothing, use the predefined file list
            var output = A.InvokeScript(AsGetFiles, this, args);
            if (output.Count == 0)
                return Cache;

            // convert the output to files
            var result = new List<FarFile>();
            foreach (var it in output)
            {
                FarFile file = (FarFile)LanguagePrimitives.ConvertTo(it, typeof(FarFile), null);
                if (file != null)
                    result.Add(file);
            }

            return result;
        }
Ejemplo n.º 42
0
        /// <inheritdoc/>
        public override IList <FarFile> DoGetFiles(GetFilesEventArgs args)
        {
            if (args == null)
            {
                return(null);
            }

            var panel = args.Parameter as FormatPanel;

            // call the worker
            // _090408_232925 If we throw then FarNet returns false and Far closes the panel.
            object data;

            try
            {
                data = GetData(args);
            }
            catch (RuntimeException ex)
            {
                if (args.UI)
                {
                    Far.Api.ShowError(Res.Me, ex);
                }

                data = new List <FarFile>();
            }

            // if the data are files just use them, assume all is done
            IList <FarFile> readyFiles = data as IList <FarFile>;

            if (readyFiles != null)
            {
                Cache = readyFiles;
                return(Cache);
            }

            // PS objects
            Collection <PSObject> values = (Collection <PSObject>)data;

            // empty?
            if (values.Count == 0)
            {
                // drop files in any case
                Cache.Clear();

                // no panel, no job
                if (panel == null)
                {
                    return(Cache);
                }

                // respect custom columns
                if (Columns != null)
                {
                    return(Cache);
                }

                // is it already <empty>?
                PanelPlan plan = panel.GetPlan(PanelViewMode.AlternativeFull);
                if (plan == null)
                {
                    plan = new PanelPlan();
                }
                else if (plan.Columns.Length == 1 && plan.Columns[0].Name == "<empty>")
                {
                    return(Cache);
                }

                // reuse the mode: reset columns, keep other data intact
                plan.Columns = new FarColumn[] { new SetColumn()
                                                 {
                                                     Kind = "N", Name = "<empty>"
                                                 } };
                panel.SetPlan(PanelViewMode.AlternativeFull, plan);
                return(Cache);
            }

            // not empty; values has to be removed in any case
            try
            {
                // custom
                if (Columns != null)
                {
                    BuildFiles(values);
                    return(Cache);
                }

                // Check some special cases and try to get the common type.
                // _100309_121508 Linear type case
                Type theType;
                if (Converter.IsLinearType(values[0].BaseObject.GetType()) ||
                    values[0].BaseObject is System.Collections.IEnumerable ||
                    null == (theType = A.FindCommonType(values)))
                {
                    // use index, value, type mode
                    if (panel != null)
                    {
                        panel.BuildPlan(Format.BuildFilesMixed(Cache, values));
                    }
                    return(Cache);
                }

                Meta[] metas = null;

                // try to get format
                if (theType != typeof(PSCustomObject))
                {
                    metas = Format.TryFormatByTableControl(values[0], panel == null ? 80 : panel.Window.Width);                     //???? avoid formatting at all
                }
                // use members
                if (metas == null)
                {
                    metas = Format.TryFormatByMembers(values, theType != null && theType == values[0].BaseObject.GetType());
                }

                if (metas == null)
                {
                    if (panel != null)
                    {
                        panel.BuildPlan(Format.BuildFilesMixed(Cache, values));
                    }
                }
                else
                {
                    MakeMap(metas);
                    if (panel != null)
                    {
                        panel.SetPlan(PanelViewMode.AlternativeFull, Format.SetupPanelMode(Metas));
                    }

                    BuildFiles(values);
                }
            }
            finally
            {
                values.Clear();
            }

            return(Cache);
        }
Ejemplo n.º 43
0
 ///
 public override IList<FarFile> DoGetFiles(GetFilesEventArgs args)
 {
     return Panel.Explore(args);
 }
Ejemplo n.º 44
0
 ///
 public override IList <FarFile> DoGetFiles(GetFilesEventArgs args)
 {
     return(Panel.Explore(args));
 }
Ejemplo n.º 45
0
 internal override object GetData(GetFilesEventArgs args)
 {
     // get items for the location
     return A.GetChildItems(Location);
 }