A class that handles the event functionality.
Inheritance: BaseLock, IDisposable
Exemplo n.º 1
0
        // Protected implementation of Dispose pattern.
        private void Dispose(bool isDisposing)
        {
            try
            {
                if (!this.IsDisposed)
                {
                    stop();
                    if (isDisposing)
                    {
                        // Free any other managed objects here.
                        if (m_threadStopEvent != null)
                        {
                            m_threadStopEvent.Dispose();
                            m_threadStopEvent = null;
                        }
                    }

                    // Free any unmanaged objects here.
                }
            }
            finally
            {
                this.IsDisposed = true;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Get response from the given uri with given credentials
        /// </summary>
        /// <param name="uri">uri</param>
        /// <param name="credentials">credentials</param>
        /// <param name="waitTimeInMilliSec">wait time in milliseconds</param>
        /// <returns></returns>
        public static String GetResponse(String uri, ICredentials credentials = null, int waitTimeInMilliSec = Timeout.Infinite)
        {
            if (uri == null || uri.Length == 0)
            {
                throw new Exception("Must supply valid URI!");
            }

            WebClient client = new WebClient(); WebRequest.Create(uri);
            string    result = null;

            if (credentials != null)
            {
                client.Credentials = credentials;
            }
            EventEx doneEvent = new EventEx(false, EventResetMode.AutoReset);

            client.DownloadStringCompleted += (s, e) =>
            {
                result = e.Result;
                doneEvent.SetEvent();
            };
            client.DownloadStringAsync(new Uri(uri, UriKind.Absolute));
            doneEvent.WaitForEvent(waitTimeInMilliSec);
            return(result);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Download file from given uri to given filepath
        /// </summary>
        /// <param name="uri">uri</param>
        /// <param name="filepath">filepath</param>
        /// <param name="waitTimeInMilliSec">wait time in milliseconds</param>
        public static void DownloadFile(String uri, String filepath, int waitTimeInMilliSec = Timeout.Infinite)
        {
            if (uri == null || uri.Length == 0)
            {
                throw new Exception("Must supply valid URI!");
            }
            if (filepath == null || filepath.Length == 0)
            {
                throw new Exception("Must supply valid filepath!");
            }
            WebClient webClient = new WebClient();
            EventEx   doneEvent = new EventEx(false, EventResetMode.AutoReset);

            webClient.OpenReadCompleted += (s, e) =>
            {
                try
                {
                    using (FileStream stream = new FileStream(filepath, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read))
                    {
                        e.Result.CopyTo(stream);
                        stream.Flush();
                        stream.Close();
                        doneEvent.SetEvent();
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message + " >" + ex.StackTrace);
                }
            };
            webClient.OpenReadAsync(new Uri(uri, UriKind.Absolute));
            doneEvent.WaitForEvent(waitTimeInMilliSec);
        }
Exemplo n.º 4
0
 /// <summary>
 /// Default Copy Constructor
 /// </summary>
 /// <param name="b">the object to copy from</param>
 public EventEx(EventEx b) : base(b)
 {
     m_isInitialRaised = b.m_isInitialRaised;
     m_eventResetMode  = b.m_eventResetMode;
     if (m_eventResetMode == EventResetMode.AutoReset)
     {
         m_event = new AutoResetEvent(m_isInitialRaised);
     }
     else
     {
         m_event = new ManualResetEvent(m_isInitialRaised);
     }
 }
Exemplo n.º 5
0
 /// <summary>
 /// Default Copy Constructor
 /// </summary>
 /// <param name="b">the object to copy from</param>
 public EventEx(EventEx b) : base(b)
 {
     m_isInitialRaised = b.m_isInitialRaised;
     m_name            = b.m_name;
     m_eventResetMode  = b.m_eventResetMode;
     if (m_name == null)
     {
         m_event = new EventWaitHandle(m_isInitialRaised, m_eventResetMode);
     }
     else
     {
         m_event = new EventWaitHandle(m_isInitialRaised, m_eventResetMode, m_name);
     }
 }
Exemplo n.º 6
0
        /// <summary>
        /// Get response from the given uri with given credentials
        /// </summary>
        /// <param name="uri">uri</param>
        /// <param name="credentials">credentials</param>
        /// <param name="waitTimeInMilliSec">wait time in milliseconds</param>
        /// <returns></returns>
        public static String GetResponse(String uri, ICredentials credentials = null, int waitTimeInMilliSec = Timeout.Infinite)
        {
            if (uri == null || uri.Length == 0)
                throw new Exception("Must supply valid URI!");

            WebClient client = new WebClient(); WebRequest.Create(uri);
            string result = null;
            if (credentials != null)
                client.Credentials = credentials;
            EventEx doneEvent = new EventEx(false, EventResetMode.AutoReset);
            client.DownloadStringCompleted += (s, e) =>
            {
                result = e.Result;
                doneEvent.SetEvent();
            };
            client.DownloadStringAsync(new Uri(uri, UriKind.Absolute));
            doneEvent.WaitForEvent(waitTimeInMilliSec);
            return result;
        }
Exemplo n.º 7
0
        /// <summary>
        /// Default Copy Constructor
        /// </summary>
        /// <param name="b">the object to copy from</param>
		public EventEx(EventEx b):base(b)
        {
            m_isInitialRaised=b.m_isInitialRaised;
	        m_name=b.m_name;
            m_eventResetMode=b.m_eventResetMode;
            if (m_name == null)
                m_event = new EventWaitHandle(m_isInitialRaised, m_eventResetMode);
            else
                m_event = new EventWaitHandle(m_isInitialRaised, m_eventResetMode, m_name);
        }
        /// <summary>
        /// Default copy constructor
        /// </summary>
        /// <param name="b">the object to copy from</param>
		public WorkerThreadInfinite(WorkerThreadInfinite  b):base(b)
        {
            m_terminateEvent=new EventEx(false,EventResetMode.AutoReset);
        }
 /// <summary>
 /// Default Constructor
 /// </summary>
 /// <param name="policy">the life policy of this worker thread.</param>
 public WorkerThreadInfinite(ThreadLifePolicy policy):base(policy)
 {
     m_terminateEvent=new EventEx(false,EventResetMode.AutoReset);
 }
Exemplo n.º 10
0
        // Protected implementation of Dispose pattern.
        private void Dispose(bool isDisposing)
        {
            try
            {
                if (!this.IsDisposed)
                {
                    if (IsConnectionAlive)
                        Disconnect();
                    if (isDisposing)
                    {
                        // Free any other managed objects here.
                        if (m_client != null)
                        {
                            m_client.Close();
                            m_client = null;
                        }
                        if (m_timeOutEvent != null)
                        {
                            m_timeOutEvent.Dispose();
                            m_timeOutEvent = null;
                        }
                        if (m_sendEvent != null)
                        {
                            m_sendEvent.Dispose();
                            m_sendEvent = null;
                        }
                    }

                    // Free any unmanaged objects here.
                }
            }
            finally
            {
                this.IsDisposed = true;
            }
        }
Exemplo n.º 11
0
 /// <summary>
 /// Default copy constructor
 /// </summary>
 /// <param name="b">the object to copy from</param>
 public WorkerThreadInfinite(WorkerThreadInfinite b) : base(b)
 {
     m_terminateEvent = new EventEx(false, EventResetMode.AutoReset);
 }
Exemplo n.º 12
0
 /// <summary>
 /// Default Constructor
 /// </summary>
 /// <param name="policy">the life policy of this worker thread.</param>
 public WorkerThreadInfinite(ThreadLifePolicy policy) : base(policy)
 {
     m_terminateEvent = new EventEx(false, EventResetMode.AutoReset);
 }
Exemplo n.º 13
0
        /// <summary>
        /// Download file from given uri to given filepath
        /// </summary>
        /// <param name="uri">uri</param>
        /// <param name="filepath">filepath</param>
        /// <param name="waitTimeInMilliSec">wait time in milliseconds</param>
        public static void DownloadFile(String uri, String filepath, int waitTimeInMilliSec=Timeout.Infinite)
        {
            if (uri == null || uri.Length == 0)
                throw new Exception("Must supply valid URI!");
            if (filepath == null || filepath.Length == 0)
                throw new Exception("Must supply valid filepath!");
            WebClient webClient = new WebClient();
            EventEx doneEvent = new EventEx(false, EventResetMode.AutoReset);
            webClient.OpenReadCompleted += (s, e) =>
            {
                try
                {
                    using (FileStream stream = new FileStream(filepath, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read))
                    {
                        e.Result.CopyTo(stream);
                        stream.Flush();
                        doneEvent.SetEvent();
                    }

                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message + " >" + ex.StackTrace);
                }
            };
            webClient.OpenReadAsync(new Uri(uri, UriKind.Absolute));
            doneEvent.WaitForEvent(waitTimeInMilliSec);
        }
Exemplo n.º 14
0
        // Protected implementation of Dispose pattern.
        private void Dispose(bool isDisposing)
        {
            try
            {
                if (!this.IsDisposed)
                {
                    stop();
                    if (isDisposing)
                    {
                        // Free any other managed objects here.
                        if (m_threadStopEvent != null)
                        {
                            m_threadStopEvent.Dispose();
                            m_threadStopEvent = null;
                        }
                    }

                    // Free any unmanaged objects here.
                }
            }
            finally
            {
                this.IsDisposed = true;
            }
        }
Exemplo n.º 15
0
        /// <summary>
        /// Default Copy Constructor
        /// </summary>
        /// <param name="b">the object to copy from</param>
		public EventEx(EventEx b):base(b)
        {
            m_isInitialRaised=b.m_isInitialRaised;
            m_eventResetMode = b.m_eventResetMode;
            if (m_eventResetMode == EventResetMode.AutoReset)
                m_event = new AutoResetEvent(m_isInitialRaised);
            else
            {
                m_event = new ManualResetEvent(m_isInitialRaised);
            }
        }