/// <summary>
        /// Gets the description of the event with the specified
        /// name in the collection.
        /// </summary>
        public virtual EventDescriptor?Find(string name, bool ignoreCase)
        {
            EventDescriptor?p = null;

            if (ignoreCase)
            {
                for (int i = 0; i < Count; i++)
                {
                    if (string.Equals(_events[i] !.Name, name, StringComparison.OrdinalIgnoreCase))
                    {
                        p = _events[i];
                        break;
                    }
                }
            }
            else
            {
                for (int i = 0; i < Count; i++)
                {
                    if (string.Equals(_events[i] !.Name, name, StringComparison.Ordinal))
                    {
                        p = _events[i];
                        break;
                    }
                }
            }

            return(p);
        }
        public int Add(EventDescriptor?value)
        {
            if (_readOnly)
            {
                throw new NotSupportedException();
            }

            EnsureSize(Count + 1);
            _events[Count++] = value;
            return(Count - 1);
        }
        public void Remove(EventDescriptor?value)
        {
            if (_readOnly)
            {
                throw new NotSupportedException();
            }

            int index = IndexOf(value);

            if (index != -1)
            {
                RemoveAt(index);
            }
        }
        /// <summary>
        /// Sorts the members of this EventDescriptorCollection. Any specified NamedSort arguments will
        /// be applied first, followed by sort using the specified IComparer.
        /// </summary>
        protected void InternalSort(string[]?names)
        {
            if (_events.Length == 0)
            {
                return;
            }

            InternalSort(_comparer);

            if (names != null && names.Length > 0)
            {
                List <EventDescriptor?> eventList = new List <EventDescriptor?>(_events);
                int foundCount = 0;
                int eventCount = _events.Length;

                for (int i = 0; i < names.Length; i++)
                {
                    for (int j = 0; j < eventCount; j++)
                    {
                        EventDescriptor?currentEvent = eventList[j];

                        // Found a matching event. Here, we add it to our array. We also
                        // mark it as null in our array list so we don't add it twice later.
                        //
                        if (currentEvent != null && currentEvent.Name.Equals(names[i]))
                        {
                            _events[foundCount++] = currentEvent;
                            eventList[j]          = null;
                            break;
                        }
                    }
                }

                // At this point we have filled in the first "foundCount" number of propeties, one for each
                // name in our name array. If a name didn't match, then it is ignored. Next, we must fill
                // in the rest of the properties. We now have a sparse array containing the remainder, so
                // it's easy.
                //
                for (int i = 0; i < eventCount; i++)
                {
                    if (eventList[i] != null)
                    {
                        _events[foundCount++] = eventList[i];
                    }
                }

                Debug.Assert(foundCount == eventCount, "We did not completely fill our event array");
            }
        }
        public void Insert(int index, EventDescriptor?value)
        {
            if (_readOnly)
            {
                throw new NotSupportedException();
            }

            EnsureSize(Count + 1);
            if (index < Count)
            {
                Array.Copy(_events, index, _events, index + 1, Count - index);
            }
            _events[index] = value;
            Count++;
        }
Example #6
0
        private void LoadEventDescriptor()
        {
            if (!this.idSpecified)
            {
                throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, this._resourceMgr.GetString("EventIdNotSpecified"), new object[0]), "Id");
            }
            List <EventMetadata> list = new List <EventMetadata>();

            foreach (EventMetadata metadata in this.providerMetadata.Events)
            {
                if (metadata.Id == this.id)
                {
                    list.Add(metadata);
                }
            }
            if (list.Count == 0)
            {
                throw new EventWriteException(string.Format(CultureInfo.InvariantCulture, this._resourceMgr.GetString("IncorrectEventId"), new object[] { this.id, this.providerName }));
            }
            EventMetadata emd = null;

            if (!this.versionSpecified && (list.Count == 1))
            {
                emd = list[0];
            }
            else
            {
                if (!this.versionSpecified)
                {
                    throw new EventWriteException(string.Format(CultureInfo.InvariantCulture, this._resourceMgr.GetString("VersionNotSpecified"), new object[] { this.id, this.providerName }));
                }
                foreach (EventMetadata metadata3 in list)
                {
                    if (metadata3.Version == this.version)
                    {
                        emd = metadata3;
                        break;
                    }
                }
                if (emd == null)
                {
                    throw new EventWriteException(string.Format(CultureInfo.InvariantCulture, this._resourceMgr.GetString("IncorrectEventVersion"), new object[] { this.version, this.id, this.providerName }));
                }
            }
            this.VerifyTemplate(emd);
            this.eventDescriptor = new EventDescriptor?(CreateEventDescriptor(this.providerMetadata, emd));
        }
        private void LoadEventDescriptor()
        {
            if (_idSpecified)
            {
                List <EventMetadata> matchedEvents = new();
                foreach (EventMetadata emd in _providerMetadata.Events)
                {
                    if (emd.Id == _id)
                    {
                        matchedEvents.Add(emd);
                    }
                }

                if (matchedEvents.Count == 0)
                {
                    string msg = string.Format(CultureInfo.InvariantCulture,
                                               _resourceMgr.GetString("IncorrectEventId"),
                                               _id,
                                               _providerName);
                    throw new EventWriteException(msg);
                }

                EventMetadata matchedEvent = null;
                if (!_versionSpecified && matchedEvents.Count == 1)
                {
                    matchedEvent = matchedEvents[0];
                }
                else
                {
                    if (_versionSpecified)
                    {
                        foreach (EventMetadata emd in matchedEvents)
                        {
                            if (emd.Version == _version)
                            {
                                matchedEvent = emd;
                                break;
                            }
                        }

                        if (matchedEvent == null)
                        {
                            string msg = string.Format(CultureInfo.InvariantCulture,
                                                       _resourceMgr.GetString("IncorrectEventVersion"),
                                                       _version,
                                                       _id,
                                                       _providerName);

                            throw new EventWriteException(msg);
                        }
                    }
                    else
                    {
                        string msg = string.Format(CultureInfo.InvariantCulture,
                                                   _resourceMgr.GetString("VersionNotSpecified"),
                                                   _id,
                                                   _providerName);

                        throw new EventWriteException(msg);
                    }
                }

                VerifyTemplate(matchedEvent);
                _eventDescriptor = CreateEventDescriptor(_providerMetadata, matchedEvent);
            }
            else
            {
                throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, _resourceMgr.GetString("EventIdNotSpecified")), "Id");
            }
        }
 public int IndexOf(EventDescriptor?value) => Array.IndexOf(_events, value, 0, Count);
 public bool Contains(EventDescriptor?value) => IndexOf(value) >= 0;
Example #10
0
        private void LoadEventDescriptor()
        {
            if (_idSpecified)
            {
                List<EventMetadata> matchedEvents = new List<EventMetadata>();
                foreach (EventMetadata emd in _providerMetadata.Events)
                {
                    if (emd.Id == _id)
                    {
                        matchedEvents.Add(emd);
                    }
                }

                if (matchedEvents.Count == 0)
                {
                    string msg = string.Format(CultureInfo.InvariantCulture,
                        _resourceMgr.GetString("IncorrectEventId"),
                        _id,
                        _providerName);
                    throw new EventWriteException(msg);
                }

                EventMetadata matchedEvent = null;
                if (!_versionSpecified && matchedEvents.Count == 1)
                {
                    matchedEvent = matchedEvents[0];
                }
                else
                {
                    if (_versionSpecified)
                    {
                        foreach (EventMetadata emd in matchedEvents)
                        {
                            if (emd.Version == _version)
                            {
                                matchedEvent = emd;
                                break;
                            }
                        }
                        if (matchedEvent == null)
                        {
                            string msg = string.Format(CultureInfo.InvariantCulture,
                                _resourceMgr.GetString("IncorrectEventVersion"),
                                _version,
                                _id,
                                _providerName);

                            throw new EventWriteException(msg);
                        }
                    }
                    else
                    {
                        string msg = string.Format(CultureInfo.InvariantCulture,
                            _resourceMgr.GetString("VersionNotSpecified"),
                            _id,
                            _providerName);

                        throw new EventWriteException(msg);
                    }
                }

                VerifyTemplate(matchedEvent);
                _eventDescriptor = CreateEventDescriptor(_providerMetadata, matchedEvent);
            }
            else
            {
                throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, _resourceMgr.GetString("EventIdNotSpecified")), "Id");
            }
        }
Example #11
0
 private void LoadEventDescriptor()
 {
     if (!this.idSpecified)
     {
         throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, this._resourceMgr.GetString("EventIdNotSpecified"), new object[0]), "Id");
     }
     List<EventMetadata> list = new List<EventMetadata>();
     foreach (EventMetadata metadata in this.providerMetadata.Events)
     {
         if (metadata.Id == this.id)
         {
             list.Add(metadata);
         }
     }
     if (list.Count == 0)
     {
         throw new EventWriteException(string.Format(CultureInfo.InvariantCulture, this._resourceMgr.GetString("IncorrectEventId"), new object[] { this.id, this.providerName }));
     }
     EventMetadata emd = null;
     if (!this.versionSpecified && (list.Count == 1))
     {
         emd = list[0];
     }
     else
     {
         if (!this.versionSpecified)
         {
             throw new EventWriteException(string.Format(CultureInfo.InvariantCulture, this._resourceMgr.GetString("VersionNotSpecified"), new object[] { this.id, this.providerName }));
         }
         foreach (EventMetadata metadata3 in list)
         {
             if (metadata3.Version == this.version)
             {
                 emd = metadata3;
                 break;
             }
         }
         if (emd == null)
         {
             throw new EventWriteException(string.Format(CultureInfo.InvariantCulture, this._resourceMgr.GetString("IncorrectEventVersion"), new object[] { this.version, this.id, this.providerName }));
         }
     }
     this.VerifyTemplate(emd);
     this.eventDescriptor = new EventDescriptor?(CreateEventDescriptor(this.providerMetadata, emd));
 }