コード例 #1
0
ファイル: TestHost.cs プロジェクト: ALealC/blip-sdk-csharp
        public async Task <IServiceContainer> StartAsync(Action <IServiceContainer> serviceOverrides = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            var applicationFileName = Bootstrapper.DefaultApplicationFileName;
            var application         = Application.ParseFromJsonFile(Path.Combine(GetAssemblyRoot(), applicationFileName));
            var typeResolver        = new AggregateTypeResolver(new TypeResolver(new AssemblyProvider(_assembly)), _typeResolver);

            var localServiceProvider = BuildServiceContainer(application, typeResolver);

            localServiceProvider.RegisterService(typeof(IServiceProvider), localServiceProvider);
            localServiceProvider.RegisterService(typeof(IServiceContainer), localServiceProvider);
            localServiceProvider.RegisterService(typeof(Application), application);

            Bootstrapper.RegisterSettingsContainer(application, localServiceProvider, typeResolver);

            var serializer = new JsonNetSerializer();

            _onDemandClientChannel = new InternalOnDemandClientChannel(serializer, application);
            _client = await Bootstrapper.BuildClientAsync(
                application,
                () => new BlipClient(new InternalOnDemandClientChannel(serializer, application)),
                localServiceProvider,
                typeResolver,
                cancellationToken,
                serviceOverrides);

            // The listener should be active?
            _blipChannelListener = new BlipChannelListener(_client, !application.DisableNotify);

            await _client.StartAsync(_blipChannelListener, cancellationToken).ConfigureAwait(false);

            await Bootstrapper.BuildStartupAsync(application, localServiceProvider, typeResolver);

            Identity = Identity.Parse($"{application.Identifier}@{application.Domain ?? "msging.net"}");
            return(localServiceProvider);
        }
コード例 #2
0
 /// <summary>
 /// Starts the client with the specified envelope consumers.
 /// </summary>
 /// <param name="client"></param>
 /// <param name="messageConsumer">The consumer func for received messages.</param>
 /// <param name="notificationConsumer">The consumer func for received notifications.</param>
 /// <param name="commandConsumer">The consumer func for received commands.</param>
 /// <param name="cancellationToken">The cancellation token.</param>
 /// <returns></returns>
 public static Task StartAsync(
     this IBlipClient client,
     Func <Message, Task <bool> > messageConsumer,
     Func <Notification, Task <bool> > notificationConsumer,
     Func <Command, Task <bool> > commandConsumer,
     CancellationToken cancellationToken)
 => client.StartAsync(
     new ChannelListener(messageConsumer, notificationConsumer, commandConsumer),
     cancellationToken);
コード例 #3
0
        public CustomSender(IConfiguration configuration)
        {
            _configuration = configuration;
            (string botIdentifier, string botAccessKey) = GetBotConfiguration();

            var builder = new BlipClientBuilder()
                          .UsingAccessKey(botIdentifier, botAccessKey)
                          .UsingRoutingRule(Lime.Messaging.Resources.RoutingRule.Instance); // Deve ser Instance, caso contrário poderá receber mensagens de clientes!!

            _client    = builder.Build();
            _isStarted = false;
        }
コード例 #4
0
 /// <summary>
 /// Starts the client with no envelope consumers.
 /// </summary>
 /// <param name="client"></param>
 /// <param name="cancellationToken">The cancellation token.</param>
 /// <returns></returns>
 public static Task StartAsync(this IBlipClient client, CancellationToken cancellationToken)
 => client.StartAsync(
     m => TaskUtil.TrueCompletedTask,
     n => TaskUtil.TrueCompletedTask,
     c => TaskUtil.TrueCompletedTask,
     cancellationToken);
コード例 #5
0
 public static IServiceProvider AddBlipClientToContainer(this IServiceCollection services, Container container, IBlipClient blipClient, string botIdentifier)
 {
     container.Configure(config =>
     {
         config.For <IBlipClient>().Add(blipClient).Named(botIdentifier);
         config.Populate(services);
     });
     return(container.GetInstance <IServiceProvider>());
 }