Beispiel #1
0
 private void emailSubscriptionConnection_OnDisconnect(object sender, SubscriptionErrorEventArgs args)
 {
     if (emailSubscriptionConnection.IsOpen == false)
     {
         emailSubscriptionConnection.Open();
     }
 }
        static void OnError(object sender, SubscriptionErrorEventArgs args)
        {
            // Handle error conditions.
            Exception e = args.Exception;

            Console.WriteLine("\n-------------Error ---" + e.Message + "-------------");
        }
        private void Connection_OnDisconnect(object sender, SubscriptionErrorEventArgs args)
        {
            lock (this.lockObject)
            {
                if (args.Exception != null)
                {
                    this.connectionException = args.Exception;
                }
                else
                {
                    // It should be possible to reconnect here, but due to a bug in EWS
                    // this is not possible:
                    //
                    // https://github.com/OfficeDev/ews-managed-api/issues/83
                    //
                    // The Nuget package is ancient but other than this workaround it's easier
                    // to use than to download the source and build for this project.

                    this.OnDebug(
                        this,
                        "Connect has been closed gracefully due to max session limit, connection will be restored"
                        );
                    this.connectionClosedGracefully = true;
                }
            }
        }
Beispiel #4
0
        static void OnError(object sender, SubscriptionErrorEventArgs args)
        {
            // Handle error conditions.
            Exception e = args.Exception;

            Log("Błąd. " + e.Message);
        }
Beispiel #5
0
 private void SubscriptionOnError(object sender, SubscriptionErrorEventArgs e)
 {
     // Вызов функции обратного вызова и попытка переподключения при возникновении ошибки от сигнала
     logger.Error($"Ошибка при получении сигнала от датчика: {e.Message}");
     Connected = false;
     TryReconnect();
 }
        public void OnError(object sender, SubscriptionErrorEventArgs args)
        {
            // Handle error conditions.
            Exception e = args.Exception;

            LoggerHelper.Logger.Info("\n-------------Error ---" + e.Message + "-------------");
        }
        private static void OnDisconnect(object sender, SubscriptionErrorEventArgs args)
        {
            // Cast the sender as a StreamingSubscriptionConnection object.
            var connection = (StreamingSubscriptionConnection)sender;

            // Ask the user if they want to reconnect or close the subscription.
            Console.WriteLine("The connection has been aborted; probably because it timed out.");
            Console.WriteLine("Do you want to reconnect to the subscription? Y/N");
            while (true)
            {
                var keyInfo = Console.ReadKey(true);
                {
                    switch (keyInfo.Key)
                    {
                    case ConsoleKey.Y:
                        // Reconnect the connection
                        connection.Open();
                        Console.WriteLine("Connection has been reopened.");
                        break;

                    case ConsoleKey.N:
                        // Signal the main thread to exit.
                        Console.WriteLine("Terminating.");
                        _Signal.Set();
                        break;
                    }
                }
            }
        }
 private void OnDisconnect(object sender, SubscriptionErrorEventArgs args)
 {
     Console.WriteLine("Disconnected");
     if (!connection.IsOpen)
     {
         connection.Open();
     }
 }
Beispiel #9
0
 private void OnDisconnect(object sender, SubscriptionErrorEventArgs args)
 {
     if (isClosingControlled == false)
     {
         Debug.WriteLine(string.Format("Restoring connection for subscription collection {0}", this.TargetEwsUrl.ToString()));
         this._connection.Open();
     }
 }
Beispiel #10
0
        void _connection_OnSubscriptionError(object sender, SubscriptionErrorEventArgs args)
        {
            if (args.Exception == null)
            {
                return;
            }

            _logger.Log("Subscription error: " + args.Exception.Message);
        }
        private static void OnSubscriptionError(object sender, SubscriptionErrorEventArgs args)
        {
            // Handle error conditions.
            var e = args.Exception;

            Console.Out.WriteLine("The following error occured:");
            Console.Out.WriteLine(e.ToString());
            Console.Out.WriteLine();
        }
        private static void OnDisconnect(object sender, SubscriptionErrorEventArgs args)
        {
            var connection = (StreamingSubscriptionConnection)sender;

            WriteLine($"Date: {DateTime.Now:HH:mm:ss}");
            WriteLine("The connection to the subscription is disconnected.");
            WriteLine("Reconnect the subscription.");

            connection.Open();
        }
Beispiel #13
0
 private void exchange_OnSubscriptionError(object sender, SubscriptionErrorEventArgs args)
 {
     // ここは、Unsbscribe のときにも呼ばれるので注意 ! (そのときは、クライアントも消えているはず)
     if (Context.ConnectionId != null)
     {
         JObject jsonObj = new JObject();
         jsonObj["Message"] = new JValue(args.Exception.Message);
         this.Clients.Client(Context.ConnectionId).notifyEvent("Exception", jsonObj.ToString());
     }
 }
Beispiel #14
0
 void connection_OnSubscriptionError(object sender, SubscriptionErrorEventArgs args)
 {
     try
     {
         _logger.Log(String.Format("OnSubscriptionError received for {0}: {1}", args.Subscription.Service.ImpersonatedUserId.Id, args.Exception.Message));
     }
     catch
     {
         _logger.Log("OnSubscriptionError received");
     }
 }
Beispiel #15
0
        public static void OnDisconnect(object sender, SubscriptionErrorEventArgs args)
        {
            StreamingSubscriptionConnection connection = (StreamingSubscriptionConnection)sender;

            if (receivedEmail)
            {
                return;
            }

            connection.Open();
        }
Beispiel #16
0
 /// <summary>
 /// Write Subscription Errors TODO: Increase error handling
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="args"></param>
 private void Connection_OnSubscriptionError(object sender, SubscriptionErrorEventArgs args)
 {
     try
     {
         _traceListener.Trace("SyncProgram", $"OnSubscriptionError received for {args.Subscription.Service.ImpersonatedUserId.Id}.");
         _traceListener.Trace("SyncProgram", $"OnSubscriptionError(Exception) : {args.Exception.Message} Stack Trace : {args.Exception.StackTrace} Inner Exception : {args.Exception.InnerException}");
     }
     catch
     {
         _traceListener.Trace("SyncProgram", "OnSubscriptionError received");
     }
 }
Beispiel #17
0
 void connection_OnDisconnect(object sender, SubscriptionErrorEventArgs args)
 {
     try
     {
         _logger.Log(String.Format("OnDisconnection received for {0}", args.Subscription.Service.ImpersonatedUserId.Id));
     }
     catch
     {
         _logger.Log("OnDisconnection received");
     }
     _reconnect = true;  // We can't reconnect in the disconnect event, so we set a flag for the timer to pick this up and check all the connections
 }
Beispiel #18
0
        /// <summary>
        /// The StreamingSubscriptionConnection's disconnected event
        /// </summary>
        /// <param name="sender">The email service connection</param>
        /// <param name="args">The email service args</param>
        public void OnNotificationDisconnect(object sender, SubscriptionErrorEventArgs args)
        {
            _Logger.Info("notification disconnected.");
            var conn = (StreamingSubscriptionConnection)sender;

            if (conn != null && conn.IsOpen == false)
            {
                conn.Open();
                _Logger.Info("notification reconnected.");
                PullEmail();
            }
        }
Beispiel #19
0
        private void emailSubscriptionConnection_OnSubscriptionError(object sender, SubscriptionErrorEventArgs args)
        {
            this.eventLog.WriteEntry(args.Exception.Message, EventLogEntryType.Error);
            Logger.LoggerAsync.InstanceOf.GeneralLogger.Error("RfiCoder had a subscription error: {0}", args.Exception);

            if (emailSubscriptionConnection.IsOpen)
            {
                emailSubscriptionConnection.Close();
            }

            var timer = new System.Timers.Timer(1000d);

            timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed);
        }
Beispiel #20
0
        private void exchange_OnDisconnect(object sender, SubscriptionErrorEventArgs args)
        {
            // 1 分ごとに継続 (Unsbscribe のときも呼ばれるので、その際は Close になる)
            StreamingSubscriptionConnection subcon = (StreamingSubscriptionConnection)sender;

            if (exchangeClients.ContainsKey(Context.ConnectionId))
            {
                subcon.Open();
            }
            else
            {
                try { subcon.Close(); }
                catch { };
            }
        }
Beispiel #21
0
        private void Connection_OnSubscriptionError(object sender, SubscriptionErrorEventArgs args)
        {
            Debugger.Break();

            StreamingSubscriptionConnection connection = sender as StreamingSubscriptionConnection;

            if (!connection.IsOpen)
            {
                connection.Close();
            }

            connection.Dispose();
            Status = EProviderStatus.Error;
            Connect();
        }
Beispiel #22
0
        //// Testing
        //// https://msdn.microsoft.com/en-us/library/office/hh312849(v=exchg.140).aspx
        //public static void ProcessChanges(FolderId folderId)
        //{
        //    bool moreChangesAvailable;
        //    do
        //    {
        //        // Get all changes since the last call. The synchronization cookie is stored in the _SynchronizationState field.
        //        // Just get the IDs of the items.
        //        // For performance reasons, do not use the PropertySet.FirstClassProperties.
        //        var changes = ThreadLocalService.SyncFolderItems(folderId, PropertySet.IdOnly,
        //           null, 512, SyncFolderItemsScope.NormalItems, _SynchronizationState);
        //        // Update the synchronization
        //        cookie._SynchronizationState = changes.SyncState;
        //        // Process all changes. If required, add a GetItem call here to request additional properties.
        //        foreach (var itemChange in changes)
        //        {
        //            // This example just prints the ChangeType and ItemId to the console.
        //            // A LOB application would apply business rules to each
        //            item.Console.Out.WriteLine("ChangeType = {0}", itemChange.ChangeType);
        //            Console.Out.WriteLine("ChangeType = {0}", itemChange.ItemId.ToString());
        //        }
        //        // If more changes are available, issue additional SyncFolderItems requests.
        //        moreChangesAvailable = changes.MoreChangesAvailable;
        //    }
        //    while (moreChangesAvailable);
        //}


        private void OnSubscriptionError(object sender, SubscriptionErrorEventArgs args)
        {
            DebugLog.WriteException("SubscriptionError", args.Exception);
            ListViewItem item = new ListViewItem();

            item.Tag         = "[local]OnSubscriptionError";
            item.Text        = "[local]OnSubscriptionError";
            item.ToolTipText = args.Exception.ToString();
            item.SubItems.Add(Thread.CurrentThread.ManagedThreadId.ToString("[0]"));
            item.SubItems.Add(DateTime.Now.ToString());
            AddToDisplay(lstEvents, item);

            //System.Diagnostics.Debug.WriteLine("-");
            //System.Diagnostics.Debug.WriteLine("OnSubscriptionError.");
            //System.Diagnostics.Debug.WriteLine("-");
        }
Beispiel #23
0
 private void OnDisconnect(object sender, SubscriptionErrorEventArgs args)
 {
     if (args.Exception == null)
     {
         if (!_disposing && _connection != null)
         {
             _connection.Open();
         }
     }
     else
     {
         if (Disconnected != null)
         {
             Disconnected(this, new DisconnectEventArgs("Exchange exception", args.Exception));
         }
     }
 }
Beispiel #24
0
        private void OnDisconnect(object sender, SubscriptionErrorEventArgs args)
        {
            string TID = Thread.CurrentThread.ManagedThreadId.ToString("[0]");

            System.Diagnostics.Debug.WriteLine("-");
            System.Diagnostics.Debug.WriteLine("OnDisconnectDisconnect");
            System.Diagnostics.Debug.WriteLine("-");

            if (SubscriptionsRunning)
            {
                StreamingSubscriptionConnection CurrentConnection = (StreamingSubscriptionConnection)sender;
                ListViewItem item = new ListViewItem();
                item.Tag  = "[local]Reconnect";
                item.Text = "[local]Reconnect";
                item.SubItems.Add(TID);
                item.SubItems.Add(DateTime.Now.ToString());
                AddToDisplay(lstEvents, item);

                try
                {
                    CurrentConnection.Open();

                    //System.Diagnostics.Debug.WriteLine("-");
                    //System.Diagnostics.Debug.WriteLine("OnDisconnectDisconnect - Reopened.");
                    //System.Diagnostics.Debug.WriteLine("-");
                }
                catch (Exception ex)
                {
                    DebugLog.WriteException("OnDisconnectError", ex);
                    item             = new ListViewItem();
                    item.Tag         = "[local]ReconnectError";
                    item.Text        = "[local]ReconnectError";
                    item.ToolTipText = ex.ToString();
                    item.SubItems.Add(Thread.CurrentThread.ManagedThreadId.ToString("[0]"));
                    item.SubItems.Add(DateTime.Now.ToString());
                    AddToDisplay(lstEvents, item);

                    //System.Diagnostics.Debug.WriteLine("-");
                    //System.Diagnostics.Debug.WriteLine("OnDisconnect - Error:  " + ex.ToString() );
                    //System.Diagnostics.Debug.WriteLine("-");
                }
            }
        }
Beispiel #25
0
        private void Connection_OnDisconnect(object sender, SubscriptionErrorEventArgs args)
        {
            StreamingSubscriptionConnection connection = sender as StreamingSubscriptionConnection;

            try
            {
                connection.Open();
            }
            catch (Exception ex)
            {
                if (Status != EProviderStatus.Error)
                {
                    Status = EProviderStatus.Offline;
                }

                connection.Dispose();
                Connect();
            }
        }
Beispiel #26
0
        void _connection_OnDisconnect(object sender, SubscriptionErrorEventArgs args)
        {
            // Subscription disconnected, so reconnect

            foreach (StreamingSubscriptionConnection connection in _connections.Values)
            {
                if (!connection.IsOpen)
                {
                    try
                    {
                        connection.Open();
                        _logger.Log("Reconnected");
                    }
                    catch (Exception ex)
                    {
                        _logger.Log("Failed to reconnect: " + ex.Message);
                    }
                }
            }
        }
        public void OnDisconnect(object sender, SubscriptionErrorEventArgs args)
        {
            // Cast the sender as a StreamingSubscriptionConnection object.
            StreamingSubscriptionConnection connection = (StreamingSubscriptionConnection)sender;

            // Ask the user if they want to reconnect or close the subscription.
            if (!connection.IsOpen)
            {
                try
                {
                    //if (connection.CurrentSubscriptions.ToArray().Length < 3)
                    //{
                    //    SubscribeNotification(exchangeService, connection);
                    //}
                    connection.Open();
                }
                catch (Exception ex)
                {
                }
            }
        }
Beispiel #28
0
        /// <summary>
        /// Disconnected subscription
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        private void Connection_OnDisconnect(object sender, SubscriptionErrorEventArgs args)
        {
            try
            {
                _traceListener.Trace("SyncProgram", $"StreamingSubscriptionChangesAsync OnDisconnect with exception: {args.Exception}");
                _traceListener.Trace("SyncProgram", $"OnDisconnection received for {args.Subscription.Service.ImpersonatedUserId.Id}");
            }
            catch (Exception ex)
            {
                _traceListener.Trace("SyncProgram", $"OnDisconnection received exception {ex.Message}");
            }

            try
            {
                if (CancellationTokenSource.IsCancellationRequested)
                {
                    _reconnect = false;
                    _traceListener.Trace("SyncProgram", $"OnDisconnect Closing streamingsubscriptionconnection at {DateTime.UtcNow}..");
                    CloseConnections();
                }
                else
                {
                    _traceListener.Trace("SyncProgram", $"StreamingSubscriptionChangesAsync re-connect");

                    if (!_reconnect)
                    {
                        return;
                    }

                    ReconnectToSubscriptions();
                    _reconnect = true;  // We can't reconnect in the disconnect event, so we set a flag for the timer to pick this up and check all the connections
                }
            }
            catch (Exception ex)
            {
                _traceListener.Trace("SyncProgram", $"Reconnect received exception {ex.Message}");
            }
        }
        static private void OnDisconnect(object sender, SubscriptionErrorEventArgs args)
        {
            // Cast the sender as a StreamingSubscriptionConnection object.
            StreamingSubscriptionConnection connection = (StreamingSubscriptionConnection)sender;

            if (autoReconnect)
            {
                connection.Open();
                counter = 0;
                Console.WriteLine("{0}: Connection automatically reconnected after {1} minutes", DateTime.Now.ToString(), intervalMin.ToString());
            }
            else
            {
                // Ask the user if they want to reconnect or close the subscription.
                ConsoleKeyInfo cki;
                Console.WriteLine("The connection to the subscription is disconnected.");
                Console.WriteLine("Do you want to reconnect to the subscription? Y/N");
                while (true)
                {
                    cki = Console.ReadKey(true);
                    {
                        if (cki.Key == ConsoleKey.Y)
                        {
                            connection.Open();
                            counter = 0;
                            Console.WriteLine("{0}; Connection reconnected.", DateTime.Now.ToString());
                            break;
                        }
                        else if (cki.Key == ConsoleKey.N)
                        {
                            // The ReadKey in the Main() consumes the E.
                            Console.WriteLine("\n\nPress E to exit");
                            break;
                        }
                    }
                }
            }
        }
Beispiel #30
0
        static private void OnDisconnect(object sender, SubscriptionErrorEventArgs args)
        {
            ((StreamingSubscriptionConnection)sender).Open();

            #region user interaction on disconnecting (OFF)
            //ConsoleKeyInfo cki;
            //Console.WriteLine("The connection to the subscription is disconnected.");
            //Console.WriteLine("Do you want to reconnect to the subscription? Y/N");
            //while (true)
            //{
            //    cki = Console.ReadKey(true);
            //    {
            //        if (cki.Key == ConsoleKey.Y)
            //        {
            //            connection.Open();
            //            Console.WriteLine("Connection open.");
            //            Console.WriteLine("\r\n");
            //            break;
            //        }
            //        else if (cki.Key == ConsoleKey.N)
            //        {
            //            Signal.Set();
            //            bool isOpen = connection.IsOpen;

            //            if (isOpen == true)
            //            {
            //            // Close the connection
            //            connection.Close();
            //            }
            //            else
            //            {
            //                break;
            //            }
            //        }
            //    }
            //}
            #endregion
        }