Initial Commit ...
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using xCommons.Extensions;
|
||||
using xExceptions.Constants;
|
||||
using xPushService.Base;
|
||||
using xPushService.Models;
|
||||
|
||||
namespace xPushService.Helpers {
|
||||
public class XPushServiceHelper {
|
||||
/// <summary>
|
||||
/// a collection of Hubs for Registring ...
|
||||
/// </summary>
|
||||
/// <typeparam name="XHubDescriptor"></typeparam>
|
||||
/// <returns></returns>
|
||||
private List<XHubDescriptor> hubs = new List<XHubDescriptor> ();
|
||||
|
||||
/// <summary>
|
||||
/// add specified hub to provided hubs for registration ...
|
||||
/// </summary>
|
||||
/// <param name="reoute"></param>
|
||||
/// <typeparam name="TXHub"></typeparam>
|
||||
public void AddHub<TXHub> (string route) where TXHub : XBaseHub {
|
||||
//
|
||||
#region Validate Args ...
|
||||
//
|
||||
// check route not null ...
|
||||
if (
|
||||
route.IsNullOrEmpty () ||
|
||||
route.Trim ().IsNullOrEmpty ()
|
||||
) {
|
||||
throw XException.InvalidArgs.ToException ();
|
||||
}
|
||||
|
||||
//
|
||||
// Normalize Route ...
|
||||
route = route.ToNormalString ();
|
||||
|
||||
//
|
||||
// check route and hub must be unique ...
|
||||
var isRouteExists = hubs.Any (hd => hd.Route == route);
|
||||
var isHubExists = hubs.Any (hd => hd.Hub == typeof (TXHub));
|
||||
if (
|
||||
isHubExists ||
|
||||
isRouteExists
|
||||
) {
|
||||
throw XException.Duplicate.ToException ();
|
||||
}
|
||||
#endregion
|
||||
|
||||
//
|
||||
// Add Provided Hub to List ...
|
||||
hubs.Add (new XHubDescriptor {
|
||||
Route = route,
|
||||
Hub = typeof (TXHub)
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// remove an specific hub from provided list ...
|
||||
/// </summary>
|
||||
/// <typeparam name="TXHub"></typeparam>
|
||||
public void RemoveHub<TXHub> () where TXHub : XBaseHub {
|
||||
//
|
||||
var existsHubDescriptor = hubs.SingleOrDefault (hd => hd.Hub == typeof (TXHub));
|
||||
if (!existsHubDescriptor.IsNull ()) {
|
||||
hubs.Remove (existsHubDescriptor);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// retrieve provided hubs count ...
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public int Count () {
|
||||
return hubs.Count;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// retrieve all provided hubs for registration ...
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public List<XHubDescriptor> GetHubs () {
|
||||
return hubs;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user