public ChannelWorker(IPushChannel channel, Action <IPushChannel, CancellationTokenSource> worker) { this.CancelTokenSource = new CancellationTokenSource(); this.Channel = channel; this.WorkerTask = Task.Factory.StartNew(() => worker(channel, this.CancelTokenSource), TaskCreationOptions.LongRunning); }
/// <summary> /// Channels the exception. /// </summary> /// <param name="sender">The sender.</param> /// <param name="pushChannel">The push channel.</param> /// <param name="error">The error.</param> private void ChannelException(object sender, IPushChannel pushChannel, System.Exception error) { try { if (this.DoLog) { string msg = ""; if (this.IsTechnocalLog) { msg = string.Format(@"Channel Exception: {0} <br/> Exception Message: {1}", sender, error.Message); } else { msg = string.Format("Channel Exception: {0}", sender); } //CommonUtility.LogToFileWithStack(msg); LogNotificationToClient(NotificationType.danger, msg); } } catch (Exception ex) { ex.ExceptionValueTracker(sender, pushChannel, error); } }
public ChannelWorker(IPushChannel channel, Action <IPushChannel, CancellationTokenSource> worker) { PushServiceBase.ChannelWorker channelWorker = this; this.Id = Guid.NewGuid().ToString(); this.CancelTokenSource = new CancellationTokenSource(); this.Channel = channel; this.WorkerTask = Task.Factory.StartNew((Action)(() => worker(channel, channelWorker.CancelTokenSource)), TaskCreationOptions.LongRunning); }
protected virtual void RaiseOnChannelException(object sender, IPushChannel pushchannel, Exception error) { var handler = OnChannelException; if (handler != null) { handler(this, pushchannel, error); } }
protected virtual void RaiseOnChannelCreated(object sender, IPushChannel pushchannel) { var handler = OnChannelCreated; if (handler != null) { handler(sender, pushchannel); } }
public void ChannelCreated(object sender, IPushChannel pushChannel) { lock (_notification) { var sb = new StringBuilder(_notification.Stack); sb.AppendLine(string.Format("** ChannelCreated ({0}) {1}", DateTime.Now.ToString("hh.mm.ss.ffffff"), sender)); _notification.Stack = sb.ToString(); Finish = true; } }
public void ChannelException(object sender, IPushChannel pushChannel, Exception error) { lock (_notification) { var sb = new StringBuilder(_notification.Stack); sb.AppendLine(string.Format("** ChannelException ({0})", DateTime.Now.ToString("hh.mm.ss.ffffff"))); sb.AppendLine(error.ToString()); sb.AppendLine(error.StackTrace); _notification.Stack = sb.ToString(); Finish = true; } }
private void ScaleChannels(ChannelScaleAction action, int count = 1) { for (int index = 0; index < count && !this.cancelTokenSource.IsCancellationRequested; ++index) { int num = 0; bool? nullable = new bool?(); IPushChannel pushChannel = (IPushChannel)null; lock (this.channelsLock) { switch (action) { case ChannelScaleAction.Create: pushChannel = this.PushChannelFactory.CreateChannel(this.ChannelSettings); PushServiceBase.ChannelWorker channelWorker = new PushServiceBase.ChannelWorker(pushChannel, new Action <IPushChannel, CancellationTokenSource>(this.DoChannelWork)); channelWorker.WorkerTask.ContinueWith((Action <Task>)(t => Log.Error("Channel Worker Failed Task: " + t.Exception.ToString())), TaskContinuationOptions.OnlyOnFaulted); this.channels.Add(channelWorker); num = this.channels.Count; nullable = new bool?(false); break; case ChannelScaleAction.Destroy: if (this.channels.Count > 0) { PushServiceBase.ChannelWorker channel = this.channels[0]; this.channels.RemoveAt(0); channel.Dispose(); num = this.channels.Count; nullable = new bool?(true); break; } break; } } if (nullable.HasValue && !nullable.Value) { ChannelCreatedDelegate onChannelCreated = this.OnChannelCreated; if (onChannelCreated != null) { onChannelCreated((object)this, pushChannel); } } else if (nullable.HasValue && nullable.Value) { ChannelDestroyedDelegate channelDestroyed = this.OnChannelDestroyed; if (channelDestroyed != null) { channelDestroyed((object)this); } } } }
/// <summary> /// Channels the created. /// </summary> /// <param name="sender">The sender.</param> /// <param name="pushChannel">The push channel.</param> private void ChannelCreated(object sender, IPushChannel pushChannel) { try { if (this.DoLog) { string msg = string.Format("Channel Created For: {0}", sender); //CommonUtility.LogToFileWithStack(msg); LogNotificationToClient(NotificationType.info, msg); } } catch (Exception ex) { ex.ExceptionValueTracker(sender, pushChannel); } }
private void BrokerOnOnChannelException(object sender, IPushChannel pushChannel, Exception error) { Logger.Error("Pusher.ChannelException", error); }
private void ChannelCreated(object sender, IPushChannel pushChannel) { Debug.WriteLine("Channel Created for: " + sender); }
private static void ChannelCreated(object sender, IPushChannel pushchannel) { }
static void ChannelCreated(object sender, IPushChannel pushChannel) { Debug.WriteLine("Channel created for: " + sender); }
private void ChannelCreated(object sender, IPushChannel pushChannel) { logger.Info("Channel Created for: " + sender); }
//this is raised when the channel is created static void ChannelCreated(object sender, IPushChannel pushChannel) { //Do something here }
private void DoChannelWork(IPushChannel channel, CancellationTokenSource cancelTokenSource) { string id = Guid.NewGuid().ToString(); long sendCount = 0; while (!cancelTokenSource.IsCancellationRequested) { var waitForNotification = new ManualResetEvent(false); INotification notification; if (!queuedNotifications.TryDequeue(out notification)) { Thread.Sleep(100); continue; } var msWaited = (DateTime.UtcNow - notification.EnqueuedTimestamp).TotalMilliseconds; lock (measurements) { measurements.Add(new WaitTimeMeasurement((long) msWaited)); } //Log.Info("Waited: {0} ms", msWaited); var sendStart = DateTime.UtcNow; sendCount++; Interlocked.Increment(ref totalSendCount); if (sendCount % 1000 == 0) Log.Info("{0}> Send Count: {1} ({2})", id, sendCount, Interlocked.Read(ref totalSendCount)); channel.SendNotification(notification, (sender, result) => { Interlocked.Decrement(ref trackedNotificationCount); var sendTime = DateTime.UtcNow - sendStart; lock (sendTimeMeasurements) { sendTimeMeasurements.Add(new WaitTimeMeasurement((long)sendTime.TotalMilliseconds)); } //Log.Info("Send Time: " + sendTime.TotalMilliseconds + " ms"); //Trigger if (this.BlockOnMessageResult) waitForNotification.Set(); //Handle the notification send callback here if (result.ShouldRequeue) { var eventArgs = new NotificationRequeueEventArgs(result.Notification); var evt = this.OnNotificationRequeue; if (evt != null) evt(this, eventArgs); //See if the requeue was cancelled in the event args if (!eventArgs.Cancel) this.QueueNotification(result.Notification, result.CountsAsRequeue, true); } else { //Result was a success, but there are still more possible outcomes than an outright success if (!result.IsSuccess) { //Check if the subscription was expired if (result.IsSubscriptionExpired) { //If there is a new id, the subscription must have changed //This is a fairly special case that only GCM should really ever raise if (!string.IsNullOrEmpty(result.NewSubscriptionId)) { var evt = this.OnDeviceSubscriptionChanged; if (evt != null) evt(this, result.OldSubscriptionId, result.NewSubscriptionId, result.Notification); } else { var evt = this.OnDeviceSubscriptionExpired; if (evt != null) evt(this, result.OldSubscriptionId, result.SubscriptionExpiryUtc, result.Notification); } } else //Otherwise some general failure { var evt = this.OnNotificationFailed; if (evt != null) evt(this, result.Notification, result.Error); } } else { var evt = this.OnNotificationSent; if (evt != null) evt(this, result.Notification); } } }); if (this.BlockOnMessageResult && !waitForNotification.WaitOne(ServiceSettings.NotificationSendTimeout)) { Interlocked.Decrement(ref trackedNotificationCount); Log.Info("Notification send timeout"); var evt = this.OnNotificationFailed; if (evt != null) evt(this, notification, new TimeoutException("Notification send timed out")); } } channel.Dispose(); }
/// <summary> /// Channels the exception. /// </summary> /// <param name="sender">The sender.</param> /// <param name="pushChannel">The push channel.</param> /// <param name="error">The error.</param> private void ChannelException(object sender, IPushChannel pushChannel, System.Exception error) { try { if (this.DoLog) { string msg = ""; if (this.IsTechnocalLog) msg = string.Format(@"Channel Exception: {0} <br/> Exception Message: {1}", sender, error.Message); else msg = string.Format("Channel Exception: {0}", sender); //CommonUtility.LogToFileWithStack(msg); LogNotificationToClient(NotificationType.danger, msg); } } catch (Exception ex) { ex.ExceptionValueTracker(sender, pushChannel, error); } }
private void broker_OnChannelCreated(object sender, IPushChannel pushChannel) { On(DisplayMessage, "Channel created!"); }
private void broker_OnChannelException(object sender, IPushChannel pushChannel, Exception error) { On(DisplayErrorMessage, "Channel exception!"); SimpleErrorLogger.LogError(error); }
static void ChannelCreated(object sender, IPushChannel pushChannel) { Logger.Log.Info("Channel Created for: " + sender); }
static void ChannelException(object sender, IPushChannel channel, Exception exception) { Logger.Log.Error("Channel Exception: " + sender + " -> " + exception); }
private void ChannelCreated(object sender, IPushChannel pushChannel) { //logging }
//this is fired when there is exception is raised by the channel static void ChannelException(object sender, IPushChannel channel, Exception exception) { //Do something here }
private void ChannelException(object sender, IPushChannel channel, Exception exception) { logger.Debug("App Push channel exception from {0} : {1}", sender, exception.ToString()); }
public static void ChannelException(object sender, IPushChannel channel, Exception exception) { log.ErrorException("Channel Exception: " + sender, exception); }
//this is fired when there is exception is raised by the channel static void ChannelException (object sender, IPushChannel channel, Exception exception) { //Do something here }
private static void ChannelCreated(object sender, IPushChannel pushChannel) { Console.WriteLine("Channel Created for: " + sender); }
private void DoChannelWork(IPushChannel channel, CancellationTokenSource cancelTokenSource) { string id = Guid.NewGuid().ToString(); long sendCount = 0; while (!cancelTokenSource.IsCancellationRequested) { var waitForNotification = new ManualResetEvent(false); var notification = queuedNotifications.Dequeue(); if (notification == null) { Thread.Sleep(100); continue; } var msWaited = (DateTime.UtcNow - notification.EnqueuedTimestamp).TotalMilliseconds; lock (measurementsLock) { measurements.Add(new WaitTimeMeasurement((long)msWaited)); } //Log.Info("Waited: {0} ms", msWaited); var sendStart = DateTime.UtcNow; sendCount++; Interlocked.Increment(ref totalSendCount); if (sendCount % 1000 == 0) { Log.Info("{0}> Send Count: {1} ({2})", id, sendCount, Interlocked.Read(ref totalSendCount)); } channel.SendNotification(notification, (sender, result) => { Interlocked.Decrement(ref trackedNotificationCount); var sendTime = DateTime.UtcNow - sendStart; lock (sendTimeMeasurementsLock) { sendTimeMeasurements.Add(new WaitTimeMeasurement((long)sendTime.TotalMilliseconds)); } //Log.Info("Send Time: " + sendTime.TotalMilliseconds + " ms"); //Trigger if (this.BlockOnMessageResult) { waitForNotification.Set(); } //Handle the notification send callback here if (result.ShouldRequeue) { var eventArgs = new NotificationRequeueEventArgs(result.Notification, result.Error); var evt = this.OnNotificationRequeue; if (evt != null) { evt(this, eventArgs); } //See if the requeue was cancelled in the event args if (!eventArgs.Cancel) { this.QueueNotification(result.Notification, result.CountsAsRequeue, true, true); } } else { //Result was a success, but there are still more possible outcomes than an outright success if (!result.IsSuccess) { //Check if the subscription was expired if (result.IsSubscriptionExpired) { //If there is a new id, the subscription must have changed //This is a fairly special case that only GCM should really ever raise if (!string.IsNullOrEmpty(result.NewSubscriptionId)) { var evt = this.OnDeviceSubscriptionChanged; if (evt != null) { evt(this, result.OldSubscriptionId, result.NewSubscriptionId, result.Notification); } } else { var evt = this.OnDeviceSubscriptionExpired; if (evt != null) { evt(this, result.OldSubscriptionId, result.SubscriptionExpiryUtc, result.Notification); } } } else //Otherwise some general failure { var evt = this.OnNotificationFailed; if (evt != null) { evt(this, result.Notification, result.Error); } } } else { var evt = this.OnNotificationSent; if (evt != null) { evt(this, result.Notification); } } } }); if (this.BlockOnMessageResult && !waitForNotification.WaitOne(ServiceSettings.NotificationSendTimeout)) { Interlocked.Decrement(ref trackedNotificationCount); Log.Info("Notification send timeout"); var evt = this.OnNotificationFailed; if (evt != null) { evt(this, notification, new TimeoutException("Notification send timed out")); } } } channel.Dispose(); }
private static void ChannelException(object sender, IPushChannel pushchannel, Exception error) { }
private void ChannelException(object sender, IPushChannel channel, Exception exception) { Debug.WriteLine("Channel Exception: " + sender + " -> " + exception); //throw exception; }
static void OnChannelException(object sender, IPushChannel pushChannel, Exception error) { logger.Error("ChannelException", error); }
private void BrokerOnOnChannelCreated(object sender, IPushChannel pushChannel) { Logger.Info("Pusher.ChannelCreated"); }
static void ChannelException(object sender, IPushChannel channel, Exception exception) { Console.WriteLine("Channel Exception: " + sender + " -> " + exception); }
private static void ChannelException(object sender, IPushChannel channel, Exception exception) { Console.WriteLine("Channel Exception: " + sender + " -> " + exception); }
/// <summary> /// Event handler for when there is an error with the push channel. /// </summary> /// <param name="sender"></param> /// <param name="pushchannel"></param> /// <param name="error"></param> private static void ChannelException(object sender, IPushChannel pushchannel, Exception error) { Log.ErrorFormat("Channel exception: {0} -> {1}", sender, error); }
private void ScaleChannels(ChannelScaleAction action, int count = 1) { //if (stopping) // return; for (int i = 0; i < count; i++) { if (cancelTokenSource.IsCancellationRequested) { break; } var newCount = 0; bool? destroyed = null; IPushChannel newChannel = default(IPushChannel); lock (channelsLock) { if (action == ChannelScaleAction.Create) { newChannel = this.PushChannelFactory.CreateChannel(this.ChannelSettings); var chanWorker = new ChannelWorker(newChannel, DoChannelWork); chanWorker.WorkerTask.ContinueWith(t => { var ex = t.Exception; Log.Error("Channel Worker Failed Task: " + ex.ToString()); }, TaskContinuationOptions.OnlyOnFaulted); channels.Add(chanWorker); newCount = channels.Count; destroyed = false; } else if (action == ChannelScaleAction.Destroy && channels.Count > 0) { var channelOn = channels[0]; channels.RemoveAt(0); //Stop the channel worker, which will dispose the channel too channelOn.Dispose(); newCount = channels.Count; destroyed = true; } } if (destroyed.HasValue && !destroyed.Value) { var evt = OnChannelCreated; if (evt != null) { evt(this, newChannel); } } else if (destroyed.HasValue && destroyed.Value) { var evt = this.OnChannelDestroyed; if (evt != null) { evt(this); } } } }
private void DoChannelWork(IPushChannel channel, CancellationTokenSource cancelTokenSource) { string str = Guid.NewGuid().ToString(); long num = 0; while (!cancelTokenSource.IsCancellationRequested) { INotification notification = this.queuedNotifications.Dequeue(); if (notification == null) { Thread.Sleep(100); } else { ManualResetEvent waitForNotification = (ManualResetEvent)null; if (this.BlockOnMessageResult) { waitForNotification = new ManualResetEvent(false); } double totalMilliseconds = (DateTime.UtcNow - notification.EnqueuedTimestamp).TotalMilliseconds; lock (this.measurementsLock) this.measurements.Add(new PushServiceBase.WaitTimeMeasurement((long)totalMilliseconds)); DateTime sendStart = DateTime.UtcNow; ++num; Interlocked.Increment(ref this.totalSendCount); if (num % 1000L == 0L) { Log.Debug("{0}> Send Count: {1} ({2})", (object)str, (object)num, (object)Interlocked.Read(ref this.totalSendCount)); } channel.SendNotification(notification, (SendNotificationCallbackDelegate)((sender, result) => { Interlocked.Decrement(ref this.trackedNotificationCount); TimeSpan timeSpan = DateTime.UtcNow - sendStart; lock (this.sendTimeMeasurementsLock) this.sendTimeMeasurements.Add(new PushServiceBase.WaitTimeMeasurement((long)timeSpan.TotalMilliseconds)); waitForNotification?.Set(); if (result.ShouldRequeue) { NotificationRequeueEventArgs e = new NotificationRequeueEventArgs(result.Notification, result.Error); NotificationRequeueDelegate notificationRequeue = this.OnNotificationRequeue; if (notificationRequeue != null) { notificationRequeue((object)this, e); } if (e.Cancel) { return; } this.QueueNotification(result.Notification, result.CountsAsRequeue, true, true); } else if (!result.IsSuccess) { if (result.IsSubscriptionExpired) { if (!string.IsNullOrEmpty(result.NewSubscriptionId)) { DeviceSubscriptionChangedDelegate subscriptionChanged = this.OnDeviceSubscriptionChanged; if (subscriptionChanged == null) { return; } subscriptionChanged((object)this, result.OldSubscriptionId, result.NewSubscriptionId, result.Notification); } else { DeviceSubscriptionExpiredDelegate subscriptionExpired = this.OnDeviceSubscriptionExpired; if (subscriptionExpired == null) { return; } subscriptionExpired((object)this, result.OldSubscriptionId, result.SubscriptionExpiryUtc, result.Notification); } } else { NotificationFailedDelegate notificationFailed = this.OnNotificationFailed; if (notificationFailed == null) { return; } notificationFailed((object)this, result.Notification, result.Error); } } else { NotificationSentDelegate notificationSent = this.OnNotificationSent; if (notificationSent == null) { return; } notificationSent((object)this, result.Notification); } })); if (waitForNotification != null && !waitForNotification.WaitOne(this.ServiceSettings.NotificationSendTimeout)) { Interlocked.Decrement(ref this.trackedNotificationCount); Log.Info("Notification send timeout"); NotificationFailedDelegate notificationFailed = this.OnNotificationFailed; if (notificationFailed != null) { notificationFailed((object)this, notification, (Exception) new TimeoutException("Notification send timed out")); } } if (waitForNotification != null) { waitForNotification.Close(); waitForNotification = (ManualResetEvent)null; } } } channel.Dispose(); }
//this is fired when there is exception is raised by the channel static void ChannelException (object sender, IPushChannel channel, Exception exception) { Console.WriteLine("ChannelException***"); Console.WriteLine(exception); }
private static void PushOnOnChannelException(object sender, IPushChannel pushChannel, Exception error) { NotificationFailureException err = error as NotificationFailureException; var errorDescription = err.ErrorStatusDescription; }
//this is raised when the channel is created static void ChannelCreated(object sender, IPushChannel pushChannel) { Console.WriteLine("ChannelCreated***"); Console.WriteLine(pushChannel); }
static void ChannelCreated(object sender, IPushChannel pushChannel) { Console.WriteLine("Channel Created for: " + sender); }
private void ChannelException(object sender, IPushChannel channel, Exception exception) { Logger.Error("Channel Exception: " + sender + " -> " + exception, exception); Result = new ApiCallResult(false, "Channel Exception: " + exception.Message); }
static void ChannelException(object sender, IPushChannel channel, Exception exception) { logging.Error(exception.ToString()); }
private bool IsValid(IPushChannel channel) => !(channel is NullEndpoint nullEndpoint) || !nullEndpoint.ShouldBeRevalidated();
private void DoChannelWork(IPushChannel channel, CancellationTokenSource cancelTokenSource) { while (!cancelTokenSource.IsCancellationRequested) { var waitForNotification = new ManualResetEvent(false); INotification notification; if (!queuedNotifications.TryDequeue(out notification)) { Thread.Sleep(100); continue; } var msWaited = (DateTime.UtcNow - notification.EnqueuedTimestamp).TotalMilliseconds; measurements.Add(new WaitTimeMeasurement((long) msWaited)); channel.SendNotification(notification, (sender, result) => { //Trigger if (this.BlockOnMessageResult) waitForNotification.Set(); Interlocked.Decrement(ref trackedNotificationCount); //Handle the notification send callback here if (result.ShouldRequeue) this.QueueNotification(result.Notification, result.CountsAsRequeue, true); else { //This is a fairly special case that only GCM should really ever raise if (!string.IsNullOrEmpty(result.NewSubscriptionId) && !string.IsNullOrEmpty(result.OldSubscriptionId)) { var evt = this.OnDeviceSubscriptionChanged; if (evt != null) evt(this, result.OldSubscriptionId, result.NewSubscriptionId, result.Notification); } if (!result.IsSuccess) { var evt = this.OnNotificationFailed; if (evt != null) evt(this, result.Notification, result.Error); } else { var evt = this.OnNotificationSent; if (evt != null) evt(this, result.Notification); } } }); if (this.BlockOnMessageResult && !waitForNotification.WaitOne(ServiceSettings.NotificationSendTimeout)) { Interlocked.Decrement(ref trackedNotificationCount); var evt = this.OnNotificationFailed; if (evt != null) evt(this, notification, new TimeoutException("Notification send timed out")); } } channel.Dispose(); }
public ChannelWorker(IPushChannel channel, Action<IPushChannel, CancellationTokenSource> worker) { this.Id = Guid.NewGuid().ToString(); this.CancelTokenSource = new CancellationTokenSource(); this.Channel = channel; this.WorkerTask = Task.Factory.StartNew(() => worker(channel, this.CancelTokenSource), TaskCreationOptions.LongRunning); }
public static void ChannelCreated(object sender, IPushChannel pushChannel) { log.Debug("Channel Created for: " + sender); }