PushSharp 3.0 Info: https://github.com/Redth/PushSharp/tree/3.0-dev#pushsharp-v30---the-push-awakens
dependabot[bot] on nuget
Bump Newtonsoft.Json from 7.0.1… (compare)
public abstract class PushChannelBase<T> : ISendChannel<MessageData>, IDisposable where T : INotification
{
protected static readonly Log log = Log.GetLogger<PushChannelBase<T>>();
protected bool IsDisposed;
protected readonly ServiceBroker<T> Broker;
public virtual ChannelSetting[] Settings => ApplicationSettings.Settings;
public ApplicationSetting ApplicationSettings { get; }
public Guid ApplicationID => ApplicationSettings.ID;
public string Name => ApplicationSettings.Name;
public bool IsInitialized => Broker != null;
public virtual ChannelResult SendData(IEnumerable<MessageData> data)
{
foreach (var message in data)
{
SendData(message);
}
return new ChannelResult { Status = StatusCodes.Success };
}
public abstract ChannelResult SendData(MessageData data);
protected PushChannelBase(ApplicationSetting settings)
{
ApplicationSettings = settings;
Broker = CreateBroker(settings);
if (Broker == null)
throw new NullReferenceException("Push service not initialized!");
Broker.OnNotificationSucceeded += OnNotificationSuccess;
Broker.OnNotificationFailed += OnNotificationFailed;
Broker.Start();
}
protected abstract ServiceBroker<T> CreateBroker(ApplicationSetting settings);
protected abstract void OnNotificationFailed(T notification, AggregateException exception);
protected abstract void OnNotificationSuccess(T notification);
protected virtual void OnError(int statusCode, MessageData data, Exception exception)
{
log.Error(exception);
var response = new ResponseData
{
Code = statusCode,
MessageID = data.ID,
Message = exception.SerializeToJson(),
By = data.UserID
};
SendProvider.SendStatus(response);
}
protected virtual void RegisterMessage(T notification, int errorCode, string errorMessage)
{
SendProvider.SendStatus(MakeResultResponse(notification, errorCode, errorMessage));
}
protected abstract ResponseData MakeResultResponse(T notification, int errorCode, string errorMessage);
public virtual void Dispose()
{
if (!IsDisposed)
{
Broker?.Stop();
IsDisposed = true;
}
}
}