/// <summary>
 /// Send as json
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="client"></param>
 /// <param name="messages"></param>
 /// <param name="eventSchema"></param>
 /// <returns></returns>
 public static Task SendJsonEventAsync <T>(this IEventClient client, IEnumerable <T> messages,
                                           string eventSchema)
 {
     return(client.SendEventAsync(messages.Select(message =>
                                                  Encoding.UTF8.GetBytes(JsonConvertEx.SerializeObject(message))),
                                  ContentMimeType.Json, eventSchema, "utf-8"));
 }
 public ClubController(IClubClient api, IEventClient _eContext, IClubMemberClient _member, UserManager <ApplicationUser> _user)
 {
     _context       = api;
     _userManager   = _user;
     _memberContext = _member;
     _eventContext  = _eContext;
 }
 public ClubController(IClubClient api, IEventClient _eContext, IClubMemberClient _member, UserManager<ApplicationUser> _user)
 {
     _context = api;
     _userManager = _user;
     _memberContext = _member;
     _eventContext = _eContext;
 }
Exemple #4
0
 /// <summary>
 /// Create test telemetry publisher
 /// </summary>
 /// <param name="events"></param>
 /// <param name="serializer"></param>
 /// <param name="logger"></param>
 public TestTelemetry(IEventClient events, IJsonSerializer serializer,
                      ILogger logger)
 {
     _serializer = serializer ?? throw new ArgumentNullException(nameof(serializer));
     _events     = events ?? throw new ArgumentNullException(nameof(events));
     _logger     = logger ?? throw new ArgumentNullException(nameof(logger));
 }
 public EventController(IClubClient _club, IEventClient _repo,IEventRegistration _reg, UserManager<ApplicationUser> _user, IMapClient _rContext)
 {
     _context = _repo;
     _routeContext = _rContext;
     _userManager = _user;
     _clubContext = _club;
     _evntReg = _reg;
 }
Exemple #6
0
 public NavetNotifier(IEventClient webClient, INotifyManager pushManager, ITaskScheduler taskScheduler, ILogger logger)
 {
     TaskScheduler = taskScheduler;
     WebClient     = webClient;
     PushManager   = pushManager;
     Logger        = logger;
     RuleChecker   = new BusinessRuleChecker();
 }
Exemple #7
0
 public EventController(IClubClient _club, IEventClient _repo, IEventRegistration _reg, UserManager <ApplicationUser> _user, IMapClient _rContext)
 {
     _context      = _repo;
     _routeContext = _rContext;
     _userManager  = _user;
     _clubContext  = _club;
     _evntReg      = _reg;
 }
Exemple #8
0
 /// <summary>
 /// Create handler factory
 /// </summary>
 /// <param name="client"></param>
 /// <param name="serializer"></param>
 /// <param name="handlers"></param>
 /// <param name="logger"></param>
 public HttpTunnelHandlerFactory(IEventClient client, IJsonSerializer serializer,
                                 IEnumerable <IHttpHandler> handlers, ILogger logger)
 {
     _logger      = logger ?? throw new ArgumentNullException(nameof(logger));
     _serializer  = serializer ?? throw new ArgumentNullException(nameof(serializer));
     _handlers    = handlers?.ToList() ?? new List <IHttpHandler>();
     _client      = client ?? throw new ArgumentNullException(nameof(client));
     _outstanding = new ConcurrentDictionary <string, RequestTask>();
 }
 /// <summary>
 /// Create handler factory
 /// </summary>
 /// <param name="client"></param>
 /// <param name="handlers"></param>
 /// <param name="logger"></param>
 public HttpTunnelHandlerFactory(IEventClient client,
                                 IEnumerable <IHttpHandler> handlers, ILogger logger)
 {
     _logger      = logger ?? throw new ArgumentNullException(nameof(logger));
     _handlers    = handlers?.ToList() ?? new List <IHttpHandler>();
     _client      = client ?? throw new ArgumentNullException(nameof(client));
     _outstanding = new ConcurrentDictionary <string,
                                              TaskCompletionSource <HttpResponseMessage> >();
 }
Exemple #10
0
 public HomeController(IEventClient _repo, UserManager <ApplicationUser> _user, IMapClient _rContext, ILoggerFactory factory)
 {
     if (_logger == null)
     {
         _logger = factory.CreateLogger("Unhandled Error");
     }
     _context      = _repo;
     _routeContext = _rContext;
     _userManager  = _user;
 }
 public HomeController(IEventClient _repo, UserManager<ApplicationUser> _user, IMapClient _rContext, ILoggerFactory factory)
 {
     if (_logger == null)
     {
         _logger = factory.CreateLogger("Unhandled Error");
     }
     _context = _repo;
     _routeContext = _rContext;
     _userManager = _user;
 }
 public CreateOrderHandler(
     OrderContext dbContext,
     IValidator <Order> validator,
     IMapper mapper,
     IEventClient eventClient)
 {
     _dbContext   = dbContext;
     _validator   = validator;
     _mapper      = mapper;
     _eventClient = eventClient;
 }
Exemple #13
0
        public static async Task _DispatchEventInternalAsync(IEvent message, Type messageType)
        {
            IEventClient client          = null;
            Type         messageBaseType = messageType;

            while (client == null && messageBaseType != null)
            {
                if (eventClients.TryGetValue(messageBaseType, out client))
                {
                    await client.DispatchAsync(message);
                }
                messageBaseType = messageBaseType.BaseType;
            }

            await HandleEventAsync((IEvent)message, messageType, true);
        }
Exemple #14
0
        public EventClientTest()
        {
            config =
                new ClientConfig.Builder()
            {
                Environment    = ClientConfig.Environments.Sandbox,
                ConsumerKey    = Config.ConsumerKey,
                ConsumerSecret = Config.ConsumerSecret
            };

            client      = ClientFactory.Create(config);
            eventClient = client.Events;

            smartObject = TestUtils.CreateBasicObject();

            client.Objects.Create(smartObject);
        }
Exemple #15
0
 private void SetEventClient()
 {
     if (GeneralLayerData.Enabled)
     {
         INativeProcessExecutable nativeProcessExecutable = new NativeProcessExecutableService();
         IFilter filter = new FilterService(GeneralLayerData, nativeProcessExecutable);
         eventClient = new GeneralEventClientService(mainForm, eventExecutable, locationEventExecutable, filter);
     }
     else if (BorderLayerData.Enabled || ShadowLayerData.Enabled)
     {
         eventClient = new LayerEventClientService(mainForm, eventExecutable, locationEventExecutable);
     }
     else if (GeneralLayerData.RadiusEnabled && !DesignMode)
     {
         eventClient = new PureRadiusEventClientService(mainForm, eventExecutable);
     }
     eventClient?.Subscribe();
 }
Exemple #16
0
 public static void AddEventClient <TInterface>(IEventClient eventClient) where TInterface : IBaseProvider
 {
     lock (serviceLock)
     {
         Type type       = typeof(TInterface);
         var  eventTypes = GetEventTypesFromInterface(type);
         foreach (var eventType in eventTypes)
         {
             if (eventServerTypes.Contains(type))
             {
                 throw new InvalidOperationException($"Cannot create loopback. Event Server already registered for type {type.GetNiceName()}");
             }
             if (eventClients.Keys.Contains(eventType))
             {
                 throw new InvalidOperationException($"Event Client already registered for type {eventType.GetNiceName()}");
             }
             eventClients.TryAdd(eventType, eventClient);
             _ = Log.InfoAsync($"{nameof(Bus)} Added Event Client For {eventType.GetNiceName()}");
         }
     }
 }
Exemple #17
0
        public static void StartServices(string serviceName, ServiceSettings serviceSettings, IServiceCreator serviceCreator, IRelayRegister relayRegister = null)
        {
            _ = Log.InfoAsync($"Starting {serviceName}");
            lock (serviceLock)
            {
                var serverSetting = serviceSettings.Services.FirstOrDefault(x => x.Name == serviceName);
                if (serverSetting == null)
                {
                    throw new Exception($"Service {serviceName} not found in {CQRSSettings.SettingsFileName}");
                }

                var serverUrl = Config.GetSetting("urls");
                if (String.IsNullOrWhiteSpace(serverUrl))
                {
                    serverUrl = Config.GetSetting("ASPNETCORE_URLS");
                }
                if (String.IsNullOrWhiteSpace(serverUrl))
                {
                    serverUrl = Config.GetSetting("DOTNET_URLS");
                }
                if (String.IsNullOrWhiteSpace(serverUrl))
                {
                    serverUrl = serverSetting.ExternalUrl;
                }

                ICommandServer commandServer = null;
                IEventServer   eventServer   = null;
                IQueryServer   queryServer   = null;

                var serverTypes = new HashSet <Type>();
                foreach (var clientSetting in serviceSettings.Services)
                {
                    if (clientSetting.Types == null || clientSetting.Types.Length == 0)
                    {
                        continue;
                    }
                    if (clientSetting != serverSetting)
                    {
                        continue;
                    }
                    foreach (var typeName in clientSetting.Types)
                    {
                        var type = Discovery.GetTypeFromName(typeName);
                        if (!type.IsInterface)
                        {
                            throw new Exception($"{type.GetNiceName()} is not an interface");
                        }
                        var typeDetails = TypeAnalyzer.GetTypeDetail(type);
                        if (!typeDetails.Interfaces.Contains(typeof(IBaseProvider)))
                        {
                            throw new Exception($"{type.GetNiceName()} does not inherit {nameof(IBaseProvider)}");
                        }

                        var commandTypes = GetCommandTypesFromInterface(type);
                        foreach (var commandType in commandTypes)
                        {
                            serverTypes.Add(commandType);
                        }

                        var eventTypes = GetEventTypesFromInterface(type);
                        foreach (var eventType in eventTypes)
                        {
                            serverTypes.Add(eventType);
                        }

                        if (typeDetails.Attributes.Any(x => x is ServiceExposedAttribute))
                        {
                            serverTypes.Add(type);
                        }
                    }
                }

                foreach (var serviceSetting in serviceSettings.Services)
                {
                    if (serviceSetting.Types == null || serviceSetting.Types.Length == 0)
                    {
                        continue;
                    }

                    ICommandClient commandClient = null;
                    IEventClient   eventClient   = null;
                    IQueryClient   queryClient   = null;

                    foreach (var typeName in serviceSetting.Types)
                    {
                        var type = Discovery.GetTypeFromName(typeName);
                        if (!type.IsInterface)
                        {
                            throw new Exception($"{type.GetNiceName()} is not an interface");
                        }
                        var typeDetails = TypeAnalyzer.GetTypeDetail(type);
                        if (!typeDetails.Interfaces.Contains(typeof(IBaseProvider)))
                        {
                            throw new Exception($"{type.GetNiceName()} does not inherit {nameof(IBaseProvider)}");
                        }

                        var commandTypes = GetCommandTypesFromInterface(type);
                        if (commandTypes.Count > 0)
                        {
                            if (serviceSetting == serverSetting)
                            {
                                if (commandServer == null)
                                {
                                    var encryptionKey = String.IsNullOrWhiteSpace(serviceSetting.EncryptionKey) ? null : SymmetricEncryptor.GetKey(serviceSetting.EncryptionKey);
                                    commandServer = serviceCreator.CreateCommandServer(serverUrl, encryptionKey);
                                    commandServer.SetHandler(HandleRemoteCommandDispatchAsync, HandleRemoteCommandDispatchAwaitAsync);
                                    if (!commandServers.Contains(commandServer))
                                    {
                                        commandServers.Add(commandServer);
                                    }
                                }
                                foreach (var commandType in commandTypes)
                                {
                                    if (commandClients.Keys.Contains(commandType))
                                    {
                                        throw new InvalidOperationException($"Command Client already registered for type {commandType.GetNiceName()}");
                                    }
                                    if (commandServerTypes.Contains(commandType))
                                    {
                                        throw new InvalidOperationException($"Command Server already registered for type {commandType.GetNiceName()}");
                                    }
                                    commandServerTypes.Add(commandType);
                                    commandServer.RegisterCommandType(commandType);
                                }
                            }
                            else
                            {
                                if (commandClient == null)
                                {
                                    var encryptionKey = String.IsNullOrWhiteSpace(serviceSetting.EncryptionKey) ? null : SymmetricEncryptor.GetKey(serviceSetting.EncryptionKey);
                                    commandClient = serviceCreator.CreateCommandClient(relayRegister?.RelayUrl ?? serviceSetting.ExternalUrl, encryptionKey);
                                }
                                var clientCommandTypes = commandTypes.Where(x => !serverTypes.Contains(x)).ToArray();
                                if (clientCommandTypes.Length > 0)
                                {
                                    foreach (var commandType in clientCommandTypes)
                                    {
                                        if (commandServerTypes.Contains(commandType))
                                        {
                                            throw new InvalidOperationException($"Command Server already registered for type {commandType.GetNiceName()}");
                                        }
                                        if (commandClients.Keys.Contains(commandType))
                                        {
                                            throw new InvalidOperationException($"Command Client already registered for type {commandType.GetNiceName()}");
                                        }
                                        commandClients.TryAdd(commandType, commandClient);
                                    }
                                }
                                else
                                {
                                    if (commandClient is IDisposable disposable)
                                    {
                                        disposable.Dispose();
                                    }
                                }
                            }
                        }

                        var eventTypes = GetEventTypesFromInterface(type);
                        if (eventTypes.Count > 0)
                        {
                            if (serviceSetting == serverSetting)
                            {
                                if (eventServer == null)
                                {
                                    var encryptionKey = String.IsNullOrWhiteSpace(serviceSetting.EncryptionKey) ? null : SymmetricEncryptor.GetKey(serviceSetting.EncryptionKey);
                                    eventServer = serviceCreator.CreateEventServer(serverUrl, encryptionKey);
                                    eventServer.SetHandler(HandleRemoteEventDispatchAsync);
                                    if (!eventServers.Contains(eventServer))
                                    {
                                        eventServers.Add(eventServer);
                                    }
                                }
                                foreach (var eventType in eventTypes)
                                {
                                    if (eventClients.Keys.Contains(eventType))
                                    {
                                        throw new InvalidOperationException($"Event Client already registered for type {eventType.GetNiceName()}");
                                    }
                                    if (eventServerTypes.Contains(eventType))
                                    {
                                        throw new InvalidOperationException($"Event Server already registered for type {eventType.GetNiceName()}");
                                    }
                                    eventServerTypes.Add(eventType);
                                    eventServer.RegisterEventType(eventType);
                                }
                            }
                            else
                            {
                                if (eventClient == null)
                                {
                                    var encryptionKey = String.IsNullOrWhiteSpace(serviceSetting.EncryptionKey) ? null : SymmetricEncryptor.GetKey(serviceSetting.EncryptionKey);
                                    eventClient = serviceCreator.CreateEventClient(relayRegister?.RelayUrl ?? serviceSetting.ExternalUrl, encryptionKey);
                                }
                                var clientEventTypes = eventTypes.Where(x => !serverTypes.Contains(x)).ToArray();
                                if (clientEventTypes.Length > 0)
                                {
                                    foreach (var eventType in eventTypes)
                                    {
                                        if (eventServerTypes.Contains(eventType))
                                        {
                                            throw new InvalidOperationException($"Event Server already registered for type {eventType.GetNiceName()}");
                                        }
                                        if (!eventClients.Keys.Contains(eventType))
                                        {
                                            eventClients.TryAdd(eventType, eventClient);
                                        }
                                    }
                                }
                                else
                                {
                                    if (eventClient is IDisposable disposable)
                                    {
                                        disposable.Dispose();
                                    }
                                }
                            }
                        }

                        if (typeDetails.Attributes.Any(x => x is ServiceExposedAttribute))
                        {
                            if (serviceSetting == serverSetting)
                            {
                                if (queryServer == null)
                                {
                                    var encryptionKey = String.IsNullOrWhiteSpace(serviceSetting.EncryptionKey) ? null : SymmetricEncryptor.GetKey(serviceSetting.EncryptionKey);
                                    queryServer = serviceCreator.CreateQueryServer(serverUrl, encryptionKey);
                                    queryServer.SetHandler(HandleRemoteQueryCallAsync);
                                    if (!queryServers.Contains(queryServer))
                                    {
                                        queryServers.Add(queryServer);
                                    }
                                }
                                if (queryClients.Keys.Contains(type))
                                {
                                    throw new InvalidOperationException($"Query Client already registered for type {type.GetNiceName()}");
                                }
                                if (queryServerTypes.Contains(type))
                                {
                                    throw new InvalidOperationException($"Query Server already registered for type {type.GetNiceName()}");
                                }
                                queryServerTypes.Add(type);
                                queryServer.RegisterInterfaceType(type);
                            }
                            else
                            {
                                if (queryClient == null)
                                {
                                    var encryptionKey = String.IsNullOrWhiteSpace(serviceSetting.EncryptionKey) ? null : SymmetricEncryptor.GetKey(serviceSetting.EncryptionKey);
                                    queryClient = serviceCreator.CreateQueryClient(relayRegister?.RelayUrl ?? serviceSetting.ExternalUrl, encryptionKey);
                                }
                                if (!serverTypes.Contains(type))
                                {
                                    if (queryServerTypes.Contains(type))
                                    {
                                        throw new InvalidOperationException($"Query Server already registered for type {type.GetNiceName()}");
                                    }
                                    if (commandClients.Keys.Contains(type))
                                    {
                                        throw new InvalidOperationException($"Query Client already registered for type {type.GetNiceName()}");
                                    }
                                    queryClients.TryAdd(type, queryClient);
                                }
                                else
                                {
                                    if (queryClient is IDisposable disposable)
                                    {
                                        disposable.Dispose();
                                    }
                                }
                            }
                        }
                    }
                }

                Dictionary <string, HashSet <string> > relayRegisterTypes = null;
                if (relayRegister != null)
                {
                    relayRegisterTypes = new Dictionary <string, HashSet <string> >();
                }

                if (commandServer != null)
                {
                    commandServer.Open();
                    if (relayRegister != null)
                    {
                        var commandTypes = commandServer.GetCommandTypes().Select(x => x.GetNiceName()).ToArray();
                        if (!relayRegisterTypes.TryGetValue(commandServer.ConnectionString, out HashSet <string> relayTypes))
                        {
                            relayTypes = new HashSet <string>();
                            relayRegisterTypes.Add(commandServer.ConnectionString, relayTypes);
                        }
                        foreach (var type in commandTypes)
                        {
                            relayTypes.Add(type);
                        }
                    }
                }
                if (eventServer != null)
                {
                    eventServer.Open();
                    if (relayRegister != null)
                    {
                        var eventTypes = eventServer.GetEventTypes().Select(x => x.GetNiceName()).ToArray();
                        if (!relayRegisterTypes.TryGetValue(eventServer.ConnectionString, out HashSet <string> relayTypes))
                        {
                            relayTypes = new HashSet <string>();
                            relayRegisterTypes.Add(eventServer.ConnectionString, relayTypes);
                        }
                        foreach (var type in eventTypes)
                        {
                            relayTypes.Add(type);
                        }
                    }
                }
                if (queryServer != null)
                {
                    queryServer.Open();
                    if (relayRegister != null)
                    {
                        var queryTypes = queryServer.GetInterfaceTypes().Select(x => x.GetNiceName()).ToArray();
                        if (!relayRegisterTypes.TryGetValue(queryServer.ConnectionString, out HashSet <string> relayTypes))
                        {
                            relayTypes = new HashSet <string>();
                            relayRegisterTypes.Add(queryServer.ConnectionString, relayTypes);
                        }
                        foreach (var type in queryTypes)
                        {
                            relayTypes.Add(type);
                        }
                    }
                }

                if (relayRegister != null)
                {
                    foreach (var group in relayRegisterTypes)
                    {
                        relayRegister.Register(group.Key, group.Value.ToArray());
                    }
                }

                if (serverSetting.InstantiateTypes != null && serverSetting.InstantiateTypes.Length > 0)
                {
                    foreach (var instantiation in serverSetting.InstantiateTypes)
                    {
                        try
                        {
                            var type     = Discovery.GetTypeFromName(instantiation);
                            var instance = Activator.CreateInstance(type);
                            instanciations.Add(instance);
                        }
                        catch (Exception ex)
                        {
                            _ = Log.ErrorAsync($"Failed to instantiate {instantiation}", ex);
                        }
                    }
                }
            }
        }
 /// <summary>
 /// Create test publisher
 /// </summary>
 /// <param name="events"></param>
 /// <param name="logger"></param>
 public TestPublisher(IEventClient events, ILogger logger)
 {
     _events = events ?? throw new ArgumentNullException(nameof(events));
     _logger = logger ?? throw new ArgumentNullException(nameof(logger));
 }
 public void Init()
 {
     _stripe = Substitute.For<IStripeClient>();
     _client = new EventClient(_stripe);
 }
 public void Init()
 {
     _stripe = Substitute.For <IStripeClient>();
     _client = new EventClient(_stripe);
 }
Exemple #21
0
 public HomeController(IEventClient eventClient)
 {
     _eventClient = eventClient;
 }
Exemple #22
0
 /// <inheritdoc/>
 public HttpTunnelConfigurableFactory(IEventClient client, IWebProxy proxy,
                                      IJsonSerializer serializer, IEnumerable <IHttpHandler> handlers, ILogger logger)
 {
     _tunnel   = new HttpTunnelHandlerFactory(client, serializer, handlers, logger);
     _fallback = new HttpHandlerFactory(handlers, proxy, logger);
 }
 public ProcessEvent(IEventClient eventClient)
 {
     _eventClient = eventClient;
 }
Exemple #24
0
 public void Remove(IEventClient client)
 {
     this.idArray_0[client.Id] = client;
     byte[] eventTypes = client.EventTypes;
     for (int i = 0; i < eventTypes.Length; i++)
     {
         byte id = eventTypes[i];
         this.idArray_1[(int)id].Remove(client);
     }
     this.permanentQueue_0.RemoveReader(client);
 }
 public BalancedService(string key, IBalancedRest rest)
 {
     this.accountClient = new AccountClient(this, rest);
     this.bankClient = new BankAccountClient(this, rest);
     this.cardClient = new CardClient(this, rest);
     this.holdClient = new HoldClient(this, rest);
     this.creditClient = new CreditClient(this, rest);
     this.debitClient = new DebitClient(this, rest);
     this.refundClient = new RefundClient(this, rest);
     this.eventClient = new EventClient(this, rest);
     this.verificationClient = new VerificationClient(this, rest);
     this.marketplaceClient = new MarketplaceClient(this, rest);
     this.key = key;
 }
Exemple #26
0
 public void Add(IEventClient client)
 {
     this.idArray_0[client.Id] = client;
     byte[] eventTypes = client.EventTypes;
     for (int i = 0; i < eventTypes.Length; i++)
     {
         byte id = eventTypes[i];
         if (this.idArray_1[(int)id] == null)
         {
             this.idArray_1[(int)id] = new List<IEventClient>();
         }
         this.idArray_1[(int)id].Add(client);
     }
     this.permanentQueue_0.AddReader(client);
 }