public static IApplicationBuilder UseByMessageId(
     this IApplicationBuilder builder,
     StreamMessageResource streamMessages)
 => builder
 .UseMiddlewareLogging(typeof(StreamMessageByMessageIdMiddleware))
 .MapWhen(HttpMethod.Delete, inner => inner.Use(DeleteStreamMessage(streamMessages)))
 .UseAllowedMethods(streamMessages);
        private static MidFunc GetStreamMessage(StreamMessageResource streamMessages) => async(context, next) =>
        {
            var options = new ReadStreamMessageByStreamVersionOperation(context.Request);

            var response = await streamMessages.Get(options, context.RequestAborted);

            await context.WriteResponse(response);
        };
        private static MidFunc DeleteStreamMessage(StreamMessageResource streamMessages) => async(context, next) =>
        {
            var operation = new DeleteStreamMessageByMessageIdOperation(context);

            var response = await streamMessages.Delete(operation, context.RequestAborted);

            await context.WriteResponse(response);
        };
Exemple #4
0
 public static IApplicationBuilder UseByVersion(
     this IApplicationBuilder builder,
     StreamMessageResource streamMessages)
 => builder
 .UseMiddlewareLogging(typeof(StreamMessageByVersionMiddleware))
 .MapWhen(HttpMethod.Get,
          inner => inner.UseAccept(Constants.MediaTypes.HalJson).Use(GetStreamMessage(streamMessages)))
 .MapWhen(HttpMethod.Delete, inner => inner.Use(DeleteStreamMessage(streamMessages)))
 .UseAllowedMethods(streamMessages);
Exemple #5
0
        public static IApplicationBuilder UseDeleteStream(this IApplicationBuilder builder, IStreamStore streamStore)
        {
            var streams        = new StreamResource(streamStore, false);
            var streamMessages = new StreamMessageResource(streamStore);

            return(builder
                   .MapWhen(IsStream, inner => inner.Use(DeleteStream(streams)))
                   .MapWhen(IsStreamMessage, inner => inner.Use(DeleteStreamMessage(streamMessages))));
        }
        private static MidFunc DeleteStreamMessage(StreamMessageResource streamMessages) => next => async env =>
        {
            var context = new OwinContext(env);

            var options = new DeleteStreamMessageOperation(context.Request);

            var response = await streamMessages.DeleteMessage(options, context.Request.CallCancelled);

            await context.WriteHalResponse(response);
        };
        public static IApplicationBuilder UseStreamOptions(this IApplicationBuilder builder, IStreamStore streamStore)
        {
            var streams         = new StreamResource(streamStore, false);
            var streamMessages  = new StreamMessageResource(streamStore);
            var streamsMetadata = new StreamMetadataResource(streamStore);

            return(builder
                   .MapWhen(IsStream, ConfigureOptions(streams))
                   .MapWhen(IsStreamMessage, ConfigureOptions(streamMessages))
                   .MapWhen(IsStreamMetadata, ConfigureOptions(streamsMetadata)));
        }
        public static IApplicationBuilder UseReadStream(
            this IApplicationBuilder builder,
            IStreamStore streamStore,
            SqlStreamStoreMiddlewareOptions options)
        {
            var streams        = new StreamResource(streamStore, options.UseCanonicalUrls);
            var streamMessages = new StreamMessageResource(streamStore);

            return(builder
                   .MapWhen(IsStreamMessage, inner => inner.Use(GetStreamMessage(streamMessages)))
                   .MapWhen(IsStream, inner => inner.Use(GetStream(streams))));
        }
        private static MidFunc GetStreamMessage(StreamMessageResource streamMessages) => next => async env =>
        {
            var context = new OwinContext(env);

            var options = new ReadStreamMessageByStreamVersionOperation(context.Request);

            var response = await streamMessages.GetMessage(options, context.Request.CallCancelled);

            using (new OptionalHeadRequestWrapper(context))
            {
                await context.WriteHalResponse(response);
            }
        };
Exemple #10
0
        public static IApplicationBuilder UseSqlStreamStoreHal(
            this IApplicationBuilder builder,
            IStreamStore streamStore,
            SqlStreamStoreMiddlewareOptions options = default)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }
            if (streamStore == null)
            {
                throw new ArgumentNullException(nameof(streamStore));
            }

            options = options ?? new SqlStreamStoreMiddlewareOptions();

            var index             = new IndexResource(streamStore, options.ServerAssembly);
            var allStream         = new AllStreamResource(streamStore, options.UseCanonicalUrls);
            var allStreamMessages = new AllStreamMessageResource(streamStore);
            var streamBrowser     = new StreamBrowserResource(streamStore);
            var streams           = new StreamResource(streamStore);
            var streamMetadata    = new StreamMetadataResource(streamStore);
            var streamMessages    = new StreamMessageResource(streamStore);
            var documentation     = new DocsResource(
                index,
                allStream,
                allStreamMessages,
                streams,
                streamMessages,
                streamMetadata,
                streamBrowser);

            s_Log.Info(index.ToString);

            return(builder
                   .UseExceptionHandling()
                   .Use(Rfc1738)
                   .Use(HeadRequests)
                   .UseRouter(router => router
                              .MapMiddlewareRoute($"{Constants.Paths.Docs}/{{doc}}", inner => inner.UseDocs(documentation))
                              .MapMiddlewareRoute(Constants.Paths.AllStream, inner => inner.UseAllStream(allStream))
                              .MapMiddlewareRoute($"{Constants.Paths.AllStream}/{{position:long}}",
                                                  inner => inner.UseAllStreamMessage(allStreamMessages))
                              .MapMiddlewareRoute(Constants.Paths.Streams, inner => inner.UseStreamBrowser(streamBrowser))
                              .MapMiddlewareRoute($"{Constants.Paths.Streams}/{{streamId}}", inner => inner.UseStreams(streams))
                              .MapMiddlewareRoute($"{Constants.Paths.Streams}/{{streamId}}/{Constants.Paths.Metadata}",
                                                  inner => inner.UseStreamMetadata(streamMetadata))
                              .MapMiddlewareRoute($"{Constants.Paths.Streams}/{{streamId}}/{{p}}",
                                                  inner => inner.UseStreamMessages(streamMessages))
                              .MapMiddlewareRoute(string.Empty, inner => inner.UseIndex(index))));
        }
Exemple #11
0
        public void TestCreateResponse()
        {
            var twilioRestClient = Substitute.For <ITwilioRestClient>();

            twilioRestClient.AccountSid.Returns("ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
            twilioRestClient.Request(Arg.Any <Request>())
            .Returns(new Response(
                         System.Net.HttpStatusCode.Created,
                         "{\"sid\": \"TZaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"data\": {}}"
                         ));

            var response = StreamMessageResource.Create("ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "TOaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "{}", client: twilioRestClient);

            Assert.NotNull(response);
        }
    static void Main(string[] args)
    {
        // Find your Account Sid and Token at twilio.com/console
        const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
        const string authToken  = "your_auth_token";

        TwilioClient.Init(accountSid, authToken);

        var streamMessage = StreamMessageResource.Create(
            data: "{\"id\": \"bob\", \"x\": 256, \"y\": 42}",
            pathServiceSid: "ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
            pathStreamSid: "MyStream"
            );

        Console.WriteLine(streamMessage.Sid);
    }
        public static MidFunc UseStreamStore(IStreamStore streamStore)
        {
            var streams        = new StreamResource(streamStore);
            var streamMessages = new StreamMessageResource(streamStore);

            var builder = new AppBuilder()
                          .MapWhen(IsStream, inner => inner.Use(DeleteStream(streams)))
                          .MapWhen(IsStreamMessage, inner => inner.Use(DeleteStreamMessage(streamMessages)));

            return(next =>
            {
                builder.Run(ctx => next(ctx.Environment));

                return builder.Build();
            });
        }
    static void Main(string[] args)
    {
        // Find your Account Sid and Token at twilio.com/console
        const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
        const string authToken  = "your_auth_token";

        TwilioClient.Init(accountSid, authToken);

        var streamMessage = StreamMessageResource.Create(
            data: new Dictionary <string, Object>(),
            pathServiceSid: "ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
            pathStreamSid: "TOXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
            );

        Console.WriteLine(streamMessage.Sid);
    }
Exemple #15
0
        public static IApplicationBuilder UseSqlStreamStoreHal(
            this IApplicationBuilder builder,
            IStreamStore streamStore,
            SqlStreamStoreMiddlewareOptions options = default)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }
            if (streamStore == null)
            {
                throw new ArgumentNullException(nameof(streamStore));
            }

            options = options ?? new SqlStreamStoreMiddlewareOptions();

            var index             = new IndexResource(streamStore, options.ServerAssembly);
            var allStream         = new AllStreamResource(streamStore, options.UseCanonicalUrls);
            var allStreamMessages = new AllStreamMessageResource(streamStore);
            var streamBrowser     = new StreamBrowserResource(streamStore);
            var streams           = new StreamResource(streamStore);
            var streamMetadata    = new StreamMetadataResource(streamStore);
            var streamMessages    = new StreamMessageResource(streamStore);
            var documentation     = new DocsResource(
                index,
                allStream,
                allStreamMessages,
                streams,
                streamMessages,
                streamMetadata,
                streamBrowser);

            s_Log.Info(index.ToString);

            return(builder
                   .UseExceptionHandling()
                   .Use(CaseSensitiveQueryStrings)
                   .Use(HeadRequests)
                   .UseDocs(documentation)
                   .UseIndex(index)
                   .UseAllStream(allStream)
                   .UseAllStreamMessage(allStreamMessages)
                   .UseStreamBrowser(streamBrowser)
                   .UseStreams(streams)
                   .UseStreamMetadata(streamMetadata)
                   .UseStreamMessages(streamMessages));
        }
Exemple #16
0
        public static MidFunc UseStreamStore(IStreamStore streamStore)
        {
            var streams         = new StreamResource(streamStore);
            var streamMessages  = new StreamMessageResource(streamStore);
            var streamsMetadata = new StreamMetadataResource(streamStore);

            var builder = new AppBuilder()
                          .MapWhen(IsStream, ConfigureOptions(streams))
                          .MapWhen(IsStreamMessage, ConfigureOptions(streamMessages))
                          .MapWhen(IsStreamMetadata, ConfigureOptions(streamsMetadata));

            return(next =>
            {
                builder.Run(context => next(context.Environment));

                return builder.Build();
            });
        }
Exemple #17
0
        public void TestCreateRequest()
        {
            var twilioRestClient = Substitute.For <ITwilioRestClient>();
            var request          = new Request(
                HttpMethod.Post,
                Twilio.Rest.Domain.Sync,
                "/v1/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Streams/TOaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages",
                ""
                );

            request.AddPostParam("Data", Serialize("{}"));
            twilioRestClient.Request(request).Throws(new ApiException("Server Error, no content"));

            try
            {
                StreamMessageResource.Create("ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "TOaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "{}", client: twilioRestClient);
                Assert.Fail("Expected TwilioException to be thrown for 500");
            }
            catch (ApiException) {}
            twilioRestClient.Received().Request(request);
        }
Exemple #18
0
    public static void Main(string[] args)
    {
        // Find your Account SID and Auth Token at twilio.com/console
        const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
        const string authToken  = "your_auth_token";
        const string serviceSid = "ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";

        TwilioClient.Init(accountSid, authToken);

        var data = new
        {
            id = "bob",
            x  = 256,
            y  = 42
        };

        var streamMessage = StreamMessageResource.Create(
            serviceSid,
            "MyStream",
            data);

        Console.WriteLine(streamMessage.Sid);
    }
    static void Main(string[] args)
    {
        // Find your Account Sid and Token at twilio.com/console
        // DANGER! This is insecure. See http://twil.io/secure
        const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
        const string authToken  = "your_auth_token";

        TwilioClient.Init(accountSid, authToken);

        var data = new Dictionary <string, Object>()
        {
            { "id", "bob" },
            { "x", 256 },
            { "y", 42 }
        };

        var streamMessage = StreamMessageResource.Create(
            data: data,
            pathServiceSid: "ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
            pathStreamSid: "MyStream"
            );

        Console.WriteLine(streamMessage.Sid);
    }
    public static void Main(string[] args)
    {
        // Find your Account SID and Auth Token at twilio.com/console
        // To set up environmental variables, see http://twil.io/secure
        const string accountSid = Environment.GetEnvironmentVariable("TWILIO_ACCOUNT_SID");
        const string authToken  = Environment.GetEnvironmentVariable("TWILIO_AUTH_TOKEN");
        const string serviceSid = Environment.GetEnvironmentVariable("TWILIO_SERVICE_SID");

        TwilioClient.Init(accountSid, authToken);

        var data = new
        {
            id = "bob",
            x  = 256,
            y  = 42
        };

        var streamMessage = StreamMessageResource.Create(
            serviceSid,
            "MyStream",
            data);

        Console.WriteLine(streamMessage.Sid);
    }