示例#1
0
 private void OnTableLoaded()
 {
     TableLoaded?.Invoke();
 }
示例#2
0
        /// <summary>Populates the table with all the requested shell items.</summary>
        /// <param name="columns">The columns to populate.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        public async Task PopulateTableAsync(IEnumerable <DataColumn> columns, CancellationToken cancellationToken)
        {
            var columnsToGet = columns.ToArray();

            if (columnsToGet.Except(Columns.Cast <DataColumn>()).Any())
            {
                throw new ArgumentException("Columns specified that are not in table.", nameof(columnsToGet));
            }
            colsToGet = columnsToGet;

            if (!(parent is null))
            {
                items = parent.IShellFolder.EnumObjects((SHCONTF)itemFilter);
            }

            if (items is null && !(parent is null))
            {
                items = parent.IShellFolder.EnumObjects((SHCONTF)itemFilter);
            }

            if (Rows.Count > 0)
            {
                Rows.Clear();
            }

            var f2 = parent?.IShellFolder as IShellFolder2;

            if (!(items is null))
            {
                var slowFetchItems = new List <Task>();
                var cInfo          = columnsToGet.ToLookup(c => IsColumnSlow(c), c => ((PROPERTYKEY)c.ExtendedProperties[extPropKey], c));
                var fastCols       = cInfo[false].ToList();
                var slowCols       = cInfo[true].ToList();
                foreach (var i in items)
                {
                    if (cancellationToken.IsCancellationRequested)
                    {
                        break;
                    }

                    // Add row with fast properties
                    var row = NewRow();
                    row[colId] = i.GetBytes();
                    foreach (var(pk, col) in fastCols)
                    {
                        row[col] = GetProp(pk, i) ?? DBNull.Value;
                    }
                    Rows.Add(row);
                    // If there are slow props, spawn thread to get them
                    if (slowCols.Count > 0)
                    {
                        slowFetchItems.Add(GetSlowProps(i, row, slowCols, cancellationToken));
                    }
                }
                AllFastRowsAdded?.Invoke(this, EventArgs.Empty);
                AcceptChanges();
                await TaskAgg.WhenAll(slowFetchItems);
            }
            TableLoaded?.Invoke(this, EventArgs.Empty);
            return;

            object GetProp(in PROPERTYKEY pk, PIDL i)
            {
                object o = null;

                try
                {
                    if (f2 is null)
                    {
                        using var si = new ShellItem(i);
                        o            = si.Properties[pk];
                    }
                    else
                    {
                        f2.GetDetailsEx(i, pk, out o).ThrowIfFailed();
                    }
                }
                catch { }

                return(o switch
                {
                    System.Runtime.InteropServices.ComTypes.FILETIME ft => ft.ToDateTime(),
                    _ => o
                });
示例#3
0
 public void OnTableLoaded(TableContent e)
 {
     TableLoaded?.Invoke(this, e);
 }