EventLogEntryCollection.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / whidbey / NetFXspW7 / ndp / fx / src / Services / Monitoring / system / Diagnosticts / EventLogEntryCollection.cs / 1 / EventLogEntryCollection.cs

                            //------------------------------------------------------------------------------ 
// 
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// 
//----------------------------------------------------------------------------- 

namespace System.Diagnostics { 
    using System.Text; 
    using System;
    using System.Collections; 

    //Consider, V2, [....]: Is there a way to implement Contains
    //and IndexOf, can we live withouth this part of the ReadOnly
    //collection pattern? 
    /// 
    ///    [To be supplied.] 
    ///  
    public class EventLogEntryCollection : ICollection {
        private EventLog log; 

        internal EventLogEntryCollection(EventLog log) {
            this.log = log;
        } 

        ///  
        ///     
        ///       Gets the number of entries in the event log
        ///     
        /// 
        public int Count {
            get {
                return log.EntryCount; 
            }
        } 
 
        /// 
        ///     
        ///       Gets an entry in
        ///       the event log, based on an index starting at 0.
        ///    
        ///  
        public virtual EventLogEntry this[int index] {
            get { 
                return log.GetEntryAt(index); 
            }
        } 

        /// 
        ///    [To be supplied.]
        ///  
        public void CopyTo(EventLogEntry[] entries, int index) {
            ((ICollection)this).CopyTo((Array)entries, index); 
        } 

        ///  
        /// 
        /// 
        public IEnumerator GetEnumerator() {
            return new EntriesEnumerator(this); 
        }
 
        internal EventLogEntry GetEntryAtNoThrow(int index) { 
            return log.GetEntryAtNoThrow(index);
        } 

        /// 
        bool ICollection.IsSynchronized {
            get { 
                return false;
            } 
        } 

        ///  
        ///    ICollection private interface implementation.
        /// 
        /// 
        object ICollection.SyncRoot { 
            get {
                return this; 
            } 
        }
 
        /// 
        ///    ICollection private interface implementation.
        /// 
        ///  
        void ICollection.CopyTo(Array array, int index) {
            EventLogEntry[] entries = log.GetAllEntries(); 
            Array.Copy(entries, 0, array, index, entries.Length);			       				 
        }
 
        /// 
        ///    
        ///       Holds an System.Diagnostics.EventLog.EventLogEntryCollection that
        ///       consists of the entries in an event 
        ///       log.
        ///     
        ///  
        private class EntriesEnumerator : IEnumerator {
            private EventLogEntryCollection entries; 
            private int num = -1;
            private EventLogEntry cachedEntry = null;

            internal EntriesEnumerator(EventLogEntryCollection entries) { 
                this.entries = entries;
            } 
 
            /// 
            ///     
            ///       Gets the entry at the current position.
            ///    
            /// 
            public object Current { 
                get {
                    if (cachedEntry == null) 
                        throw new InvalidOperationException(SR.GetString(SR.NoCurrentEntry)); 

                    return cachedEntry; 
                }
            }

            ///  
            ///    
            ///       Advances the enumerator to the next entry in the event log. 
            ///     
            /// 
            public bool MoveNext() { 
                num++;
                cachedEntry = entries.GetEntryAtNoThrow(num);

                return cachedEntry != null; 
            }
 
            ///  
            ///    
            ///       Resets the state of the enumeration. 
            ///    
            /// 
            public void Reset() {
                num = -1; 
            }
        } 
    } 
}

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------------------------ 
// 
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// 
//----------------------------------------------------------------------------- 

namespace System.Diagnostics { 
    using System.Text; 
    using System;
    using System.Collections; 

    //Consider, V2, [....]: Is there a way to implement Contains
    //and IndexOf, can we live withouth this part of the ReadOnly
    //collection pattern? 
    /// 
    ///    [To be supplied.] 
    ///  
    public class EventLogEntryCollection : ICollection {
        private EventLog log; 

        internal EventLogEntryCollection(EventLog log) {
            this.log = log;
        } 

        ///  
        ///     
        ///       Gets the number of entries in the event log
        ///     
        /// 
        public int Count {
            get {
                return log.EntryCount; 
            }
        } 
 
        /// 
        ///     
        ///       Gets an entry in
        ///       the event log, based on an index starting at 0.
        ///    
        ///  
        public virtual EventLogEntry this[int index] {
            get { 
                return log.GetEntryAt(index); 
            }
        } 

        /// 
        ///    [To be supplied.]
        ///  
        public void CopyTo(EventLogEntry[] entries, int index) {
            ((ICollection)this).CopyTo((Array)entries, index); 
        } 

        ///  
        /// 
        /// 
        public IEnumerator GetEnumerator() {
            return new EntriesEnumerator(this); 
        }
 
        internal EventLogEntry GetEntryAtNoThrow(int index) { 
            return log.GetEntryAtNoThrow(index);
        } 

        /// 
        bool ICollection.IsSynchronized {
            get { 
                return false;
            } 
        } 

        ///  
        ///    ICollection private interface implementation.
        /// 
        /// 
        object ICollection.SyncRoot { 
            get {
                return this; 
            } 
        }
 
        /// 
        ///    ICollection private interface implementation.
        /// 
        ///  
        void ICollection.CopyTo(Array array, int index) {
            EventLogEntry[] entries = log.GetAllEntries(); 
            Array.Copy(entries, 0, array, index, entries.Length);			       				 
        }
 
        /// 
        ///    
        ///       Holds an System.Diagnostics.EventLog.EventLogEntryCollection that
        ///       consists of the entries in an event 
        ///       log.
        ///     
        ///  
        private class EntriesEnumerator : IEnumerator {
            private EventLogEntryCollection entries; 
            private int num = -1;
            private EventLogEntry cachedEntry = null;

            internal EntriesEnumerator(EventLogEntryCollection entries) { 
                this.entries = entries;
            } 
 
            /// 
            ///     
            ///       Gets the entry at the current position.
            ///    
            /// 
            public object Current { 
                get {
                    if (cachedEntry == null) 
                        throw new InvalidOperationException(SR.GetString(SR.NoCurrentEntry)); 

                    return cachedEntry; 
                }
            }

            ///  
            ///    
            ///       Advances the enumerator to the next entry in the event log. 
            ///     
            /// 
            public bool MoveNext() { 
                num++;
                cachedEntry = entries.GetEntryAtNoThrow(num);

                return cachedEntry != null; 
            }
 
            ///  
            ///    
            ///       Resets the state of the enumeration. 
            ///    
            /// 
            public void Reset() {
                num = -1; 
            }
        } 
    } 
}

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK