Exemplo n.º 1
0
        /// <summary>
        /// Gets the friendly name of the <see cref="IServiceId"/> instance.
        /// </summary>
        public static string FriendlyName(this IServiceId src)
        {
            if (src is null)
            {
                throw new ArgumentNullException(nameof(src));
            }

            string result = src.Interface.GetFriendlyName();

            if (src.Name is not null)
            {
                result += $":{src.Name}";
            }
            return(result);
        }
Exemplo n.º 2
0
 public HomeController(IServiceId serviceId, IOptions <ApiOptions> apiOptions)
 {
     _serviceId  = serviceId;
     _apiOptions = apiOptions;
 }
Exemplo n.º 3
0
 public AccountDetails(IServiceId serviceId, IServiceClient serviceClient)
 {
     _serviceId     = serviceId;
     _serviceClient = serviceClient;
 }
Exemplo n.º 4
0
        public MqttListenerService(IManagedMqttClient client, IManagedMqttClientOptions options, IConfiguration configuration, IServiceId serviceId,
                                   ILogger <MqttListenerService> logger, IPointsOfSaleService posService, IServiceProvider serviceProvider, IPosTopicClassifier posTopicClassifier)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }
            if (serviceId == null)
            {
                throw new ArgumentNullException(nameof(serviceId));
            }

            _client             = client ?? throw new ArgumentNullException(nameof(client));
            _options            = options ?? throw new ArgumentNullException(nameof(options));
            _logger             = logger ?? throw new ArgumentNullException(nameof(logger));
            _posService         = posService ?? throw new ArgumentNullException(nameof(posService));
            _posTopicClassifier = posTopicClassifier ?? throw new ArgumentNullException(nameof(posTopicClassifier));

            _client.UseApplicationMessageReceivedHandler(OnMqttMessageReceived);
            _client.UseConnectedHandler(args => OnConnectedHandler(args));
            _client.UseDisconnectedHandler(args => OnDisconnectedHandler(args));

            _messageHandlers = serviceProvider.GetServices <IMqttMessageHandler>().ToArray();
        }
Exemplo n.º 5
0
        /// <summary>
        /// Constructor used in Unit testing to mock services
        /// </summary>
        /// <param name="serviceClient"></param>
        /// <param name="graphService"></param>
        /// <param name="b2CGraphService"></param>
        /// <param name="serviceId"></param>
        public EzPassService(IServiceClient serviceClient, IGraphService graphService, IB2CGraphService b2CGraphService, IServiceId serviceId)
        {
            var serviceClient1   = serviceClient;
            var b2CGraphService1 = b2CGraphService;
            var graphService1    = graphService;
            var serviceId1       = serviceId;

            _services = new List <object>()
            {
                new TollTag(serviceId1, serviceClient1),
                new AccountDetails(serviceId1, serviceClient1),
                new Payment(serviceId1, serviceClient1),
                new Vehicle(serviceId1, serviceClient1)
            };
        }
Exemplo n.º 6
0
 public Vehicle(IServiceId serviceId, IServiceClient serviceClient)
 {
     _serviceId     = serviceId;
     _serviceClient = serviceClient;
 }
Exemplo n.º 7
0
 public Payment(IServiceId serviceId, IServiceClient serviceClient)
 {
     _serviceId     = serviceId;
     _serviceClient = serviceClient;
 }
Exemplo n.º 8
0
 public TollTag(IServiceId serviceId, IServiceClient serviceClient)
 {
     _serviceId     = serviceId;
     _serviceClient = serviceClient;
 }
Exemplo n.º 9
0
        public virtual AbstractServiceEntry?Get(Type serviceInterface, string?name, QueryModes mode)
        {
            CheckNotDisposed();
            Ensure.Parameter.IsNotNull(serviceInterface, nameof(serviceInterface));
            Ensure.Parameter.IsInterface(serviceInterface, nameof(serviceInterface));

            IServiceId key = MakeId(serviceInterface);

            AbstractServiceEntry existing;

            using (FLock.AcquireReaderLock())
            {
                //
                // 1. eset: Vissza tudjuk adni amit kerestunk.
                //

                if (FEntries.TryGetValue(key, out existing))
                {
                    return(existing);
                }

                //
                // 2. eset: A bejegyzes generikus parjat kell majd feldolgozni.
                //

                bool hasGenericEntry = mode.HasFlag(QueryModes.AllowSpecialization) &&
                                       serviceInterface.IsGenericType &&
                                       FEntries.TryGetValue
                                       (
                    MakeId(serviceInterface.GetGenericTypeDefinition()),
                    out existing
                                       );

                //
                // 3. eset: Egyik se jott be, vagy kivetelt v NULL-t adunk vissza.
                //

                if (!hasGenericEntry)
                {
                    return(!mode.HasFlag(QueryModes.ThrowOnError)
                        ? (AbstractServiceEntry?)null
                        : throw new ServiceNotFoundException(string.Format(Resources.Culture, Resources.SERVICE_NOT_FOUND, key.FriendlyName())));
                }
            }

            Assert(existing.IsGeneric());
            Assert(mode.HasFlag(QueryModes.AllowSpecialization));

            using (FLock.AcquireWriterLock())
            {
                //
                // Kozben vki berakta mar?
                //

                if (FEntries.TryGetValue(key, out AbstractServiceEntry? specialized))
                {
                    return(specialized);
                }

                //
                // Ha nem mi vagyunk a tulajdonosok akkor ertesitjuk a tulajdonost h tipizalja o a bejegyzest
                // majd masoljuk az uj elemet sajat magunkhoz (epp ugy mint ha "orokoltuk" vna).
                //
                // Igy lehetove tesszuk h pl singleton elettartamnal a tipizalt peldany elettartamarol is a
                // deklaralo kollekcio gondoskodjon.
                //

                if (existing.Owner != this)
                {
                    specialized = existing
                                  .Owner
                                  .Get(serviceInterface, name, mode);

                    //
                    // "specialized" lehet NULL ha a "QueryModes.ThrowOnError" nem volt beallitva es "existing"
                    // nem valositja meg a "ISupportsSpecialization" interface-t.
                    //

                    return(specialized?.CopyTo(this));
                }

                //
                // Ha mi vagyunk a tulajdonosok akkor nekunk kell tipizalni majd felvenni a bejegyzest.
                //

                if (existing is ISupportsSpecialization generic)
                {
                    //
                    // Ne az "FEntries.Add(specialized, specialized)"-ot hivjuk mert a "this.Add()" virtualis.
                    //

                    Add(specialized = generic.Specialize(serviceInterface.GetGenericArguments()));
                    return(specialized);
                }

                return(!mode.HasFlag(QueryModes.ThrowOnError)
                    ? (AbstractServiceEntry?)null
                    : throw new NotSupportedException(Resources.ENTRY_CANNOT_BE_SPECIALIZED));
            }

            IServiceId MakeId(Type iface) => new ServiceId(iface, name);
        }