예제 #1
0
 public WinCred.Credential ToManaged()
 {
     return(new WinCred.Credential
     {
         Flags = Flags,
         Type = Type,
         TargetName = TargetName,
         Comment = Comment,
         LastWritten = LastWritten.ToDateTime(),
         CredentialBlob = CredentialBlob,
         Persist = Persist,
         Attributes = (Attributes ?? Enumerable.Empty <CredentialAttribute>())
                      .Select(uca => uca.ToManaged())
                      .ToArray(),
         TargetAlias = TargetAlias,
         UserName = UserName,
     });
 }
예제 #2
0
        public void GetNetworkTest()
        {
            var ns = mgr.GetNetworks(NLM_ENUM_NETWORK.NLM_ENUM_NETWORK_CONNECTED);

            Assert.That(ns, Is.Not.Null);
            var n = ns.Cast <INetwork>().FirstOrDefault();

            Assert.That(n, Is.Not.Null);
            var g  = n.GetNetworkId();
            var n1 = mgr.GetNetwork(g);

            Assert.That(n.GetName() == n1.GetName());
            Assert.That(n.GetName(), Is.Not.Null);
            var nm = n.GetName();

            n.SetName("XXXX");
            Assert.That(n.GetName(), Is.EqualTo("XXXX"));
            n.SetName(nm);
            var de = n.GetDescription();

            n.SetDescription("XXXX");
            Assert.That(n.GetDescription(), Is.EqualTo("XXXX"));
            n.SetDescription(de);
            Assert.That((int)n.GetDomainType(), Is.InRange(0, 2));
            n.GetTimeCreatedAndConnected(out uint pdwLowDateTimeCreated, out uint pdwHighDateTimeCreated, out uint pdwLowDateTimeConnected, out uint pdwHighDateTimeConnected);
            var cft = new FILETIME {
                dwHighDateTime = (int)pdwHighDateTimeCreated, dwLowDateTime = (int)pdwLowDateTimeCreated
            };
            var nft = new FILETIME {
                dwHighDateTime = (int)pdwHighDateTimeConnected, dwLowDateTime = (int)pdwLowDateTimeConnected
            };

            Assert.That(cft.ToDateTime(), Is.GreaterThan(new DateTime(2000, 1, 1)));
            Assert.That(nft.ToDateTime(), Is.GreaterThan(new DateTime(2000, 1, 1)));
            Assert.That(n.IsConnected, Is.True);
            Assert.That(n.IsConnectedToInternet, Is.True);
            Assert.That((int)n.GetConnectivity(), Is.GreaterThan(0));
            Assert.That((int)n.GetCategory(), Is.InRange(0, 2));
            Assert.That(n.GetNetworkConnections(), Is.Not.Empty);
            TestContext.WriteLine($"{nm} ({n.GetNetworkId()}): '{de}'");
            TestContext.WriteLine($"  CrD:{cft.ToString("s")}; CnD:{nft.ToString("s")}; Cn:{n.IsConnected}; Int:{n.IsConnectedToInternet}; Dom:{n.GetDomainType()}");
            TestContext.WriteLine($"  Cnt:{n.GetConnectivity()}; Cat:{n.GetCategory()}");
        }
예제 #3
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
                });