public unsafe bool MoveNext()
        {
            if (_fetchedLastObject)
            {
                _current = null;
                return(false);
            }

            int numFetched = 0;

            if (_enumVariantObject.Next(1, _nextArray, (IntPtr)(&numFetched)) == HResults.S_FALSE)
            {
                _fetchedLastObject = true;

                if (numFetched == 0)
                {
                    _current = null;
                    return(false);
                }
            }

            _current = _nextArray[0];

            return(true);
        }
 public bool MoveNext ()
 {
     object val;
     uint fetched = 0;
     com_enum.Next (1, out val, out fetched);
     if (fetched == 0)
         return false;
     current = val;
     return true;
 }
        public bool MoveNext()
        {
            var items = new object[1];

            if (enumVariant.Next(1, items, IntPtr.Zero) == HResult.S_OK)
            {
                Current = items[0];
                return(true);
            }

            return(false);
        }
Esempio n. 4
0
            public bool MoveNext()
            {
                object val;
                uint   fetched = 0;

                com_enum.Next(1, out val, out fetched);
                if (fetched == 0)
                {
                    return(false);
                }
                current = val;
                return(true);
            }
Esempio n. 5
0
        public static IEnumerable <T> ToEnumerable <T>(this IEnumVARIANT enumVariant, int count)
        {
            enumVariant.Reset();

            var buffer = new object[count];
            var bufferLengthPointer = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(int)));

            enumVariant.Next(buffer.Length, buffer, bufferLengthPointer);
            var bufferLength = Marshal.ReadInt32(bufferLengthPointer);

            Marshal.FreeCoTaskMem(bufferLengthPointer);

            for (var i = 0; i < Math.Min(bufferLength, count); i++)
            {
                yield return((T)buffer[i]);
            }
        }
        private IEnumerable<FirewallRulePayload> GetPayloads()
        {
            INetFwRules rules = _firewallPolicy.Rules;

            int count = rules.Count;
            IEnumVARIANT enumVARIANT = rules.get__NewEnum();
            object[] obj = new object[1];

            for (int i = 0; i < count; i++)
            {
                if (enumVARIANT.Next(1, obj, IntPtr.Zero) == 0)
                {
                    var rule = (INetFwRule)obj[0];

                    if (!ShouldHandleRule(rule))
                    {
                        continue;
                    }

                    FirewallRulePayload payload = new FirewallRulePayload();
                    payload.Action = rule.Action.ToIoTValue();
                    payload.Direction = rule.Direction.ToIoTValue();
                    payload.Enabled = rule.Enabled;
                    payload.Application = rule.ApplicationName;
                    payload.SourceAddress = rule.Direction == NET_FW_RULE_DIRECTION_.NET_FW_RULE_DIR_IN ? rule.RemoteAddresses : rule.LocalAddresses;
                    payload.SourcePort = rule.Direction == NET_FW_RULE_DIRECTION_.NET_FW_RULE_DIR_IN ? rule.RemotePorts : rule.LocalPorts;
                    payload.DestinationAddress = rule.Direction == NET_FW_RULE_DIRECTION_.NET_FW_RULE_DIR_IN ? rule.LocalAddresses : rule.RemoteAddresses;
                    payload.DestinationPort = rule.Direction == NET_FW_RULE_DIRECTION_.NET_FW_RULE_DIR_IN ? rule.LocalPorts : rule.RemotePorts;
                    payload.Protocol = ((FirewallRuleProtocol)rule.Protocol).ToString();
                    payload.Priority = null;
                    payload.ExtraDetails = new Dictionary<string, string>() { { RuleNameExtraDetailsKey, rule.Name } };

                    yield return payload;
                }
            }
        }
        bool IEnumerator.MoveNext()
        {
            if (IsWrappingNullReference)
            {
                return(false);
            }

            _currentItem = null;

            object currentItemRCW;
            uint   celtFetched;
            int    hr = _enumeratorRCW.Next(1, out currentItemRCW, out celtFetched);

            // hr == S_FALSE (1) or S_OK (0), or <0 means error

            _currentItem = _itemWrapper.Invoke(currentItemRCW);     // creates a null wrapped reference even on end/error, just as a precaution

            if (hr < 0)
            {
                throw Marshal.GetExceptionForHR(hr);
            }

            return(celtFetched == 1);       // celtFetched will be 0 when we reach the end of the collection
        }