Example #1
0
        public async Task <IActionResult> Explore(
            ExploreParams data,
            [FromServices] ExplorationLauncher launcher,
            [FromServices] IAircloakAuthenticationProvider authProvider,
            [FromServices] ContextBuilder contextBuilder,
            [FromServices] AircloakConnectionBuilder connectionBuilder)
        {
            // Register the authentication token for this scope.
            if (authProvider is ExplorerApiAuthProvider auth)
            {
                auth.RegisterApiKey(data.ApiKey);
            }

            var apiUri  = new Uri(data.ApiUrl);
            var cts     = new CancellationTokenSource();
            var conn    = connectionBuilder.Build(apiUri, data.DataSource, cts.Token);
            var ctxList = await contextBuilder.Build(apiUri, data.DataSource, data.Table, data.Columns);

            var explorationSettings = ctxList.Select(ctx => (ComponentComposition.ColumnConfiguration(ctx.ColumnType), ctx));
            var exploration         = launcher.LaunchExploration(data.DataSource, data.Table, conn, explorationSettings);

            // Register the exploration for future reference.
            var id = explorationRegistry.Register(exploration, cts);

            return(Ok(new ExploreResult(id, ExplorationStatus.New, data.DataSource, data.Table, versionInfo)));
        }
Example #2
0
        public void ParametricInstancingBuilderTest()
        {
            var b = ContextBuilder.Build(new[] { typeof(Comment), typeof(Post), typeof(User) }, ConfigTest).New();

            Assert.IsInstanceOf <DbContext>(b);
            TestContextSets(b);
        }
        /// <summary>
        /// Configures the host builder to host an Orleans silo.
        /// </summary>
        /// <param name="hostBuilder">The host builder.</param>
        /// <param name="configureDelegate">The delegate used to configure the silo.</param>
        /// <returns>The host builder.</returns>
        /// <remarks>
        /// Calling this method multiple times on the same <see cref="IHostBuilder"/> instance will result in one silo being configured.
        /// However, the effects of <paramref name="configureDelegate"/> will be applied once for each call.
        /// </remarks>
        public static IWebHostBuilder UseOrleans(this IWebHostBuilder hostBuilder, Action <HostBuilderContext, ISiloBuilder> configureDelegate)
        {
            if (configureDelegate == null)
            {
                throw new ArgumentNullException(nameof(configureDelegate));
            }

            // Track how many times this method is called.
            var thisCallNumber = GetCallCount(hostBuilder) + 1;

            hostBuilder.UseSetting(ConfigurationMarker, thisCallNumber.ToString(CultureInfo.InvariantCulture));

            return(hostBuilder.ConfigureServices((hostContext, services) =>
            {
                var siloBuilder = GetOrAddSiloBuilder(services);

                siloBuilder.ConfigureSilo(configureDelegate);

                // Check if this is the final call to this method.
                var callNumber = GetCallCount(hostBuilder);

                if (callNumber == thisCallNumber)
                {
                    var context = ContextBuilder.Build(siloBuilder, hostContext.Configuration, hostContext.HostingEnvironment);

                    siloBuilder.Build(context, services);
                }
            }));
        }
Example #4
0
        public virtual IRepository <T> AsUnsecured()
        {
            var context = new ContextBuilder <T>()
                          .WithDeletableEntity()
                          .WithAuditableEntity();

            if (this.context is UntrackedContext)
            {
                context.WithUntracked();
            }

            return(new BasicRepository <T>(context.Build()));
        }
Example #5
0
        /// <summary>
        /// Configures the service collection to host an Orleans silo.
        /// </summary>
        /// <param name="services">The services. Cannot be null.</param>
        /// <param name="environment">The host environment. Cannot be null.</param>
        /// <param name="configuration">The configuration object. Cannot be null.</param>
        /// <param name="configureDelegate">The delegate used to configure the silo. Cannot be null.</param>
        /// <returns>The host builder.</returns>
        /// <remarks>
        /// Do not call this method multiple times.
        /// </remarks>
        public static IServiceCollection AddOrleans(this IServiceCollection services, IConfiguration configuration, IWebHostEnvironment environment, Action <HostBuilderContext, ISiloBuilder> configureDelegate)
        {
            Guard.NotNull(environment, nameof(environment));
            Guard.NotNull(configuration, nameof(configuration));
            Guard.NotNull(configureDelegate, nameof(configureDelegate));

            var siloBuilder = new SiloServiceBuilder();

            var context = ContextBuilder.Build(siloBuilder, configuration, environment);

            siloBuilder.ConfigureSilo(configureDelegate);
            siloBuilder.Build(context, services);

            return(services);
        }
 public async Task Drive()
 {
     _context = _contextBuilder.Build();
     await _context.Invoke <CabRideController>((x) => x.Post(_command));
 }
Example #7
0
        public void ExampleContextBuild()
        {
            //
            // Context
            //
            var contextBuilder = new ContextBuilder();

            contextBuilder
            .WithContentId(MimeUtils.GenerateMessageId())
            .WithDisposition("metadata.txt")
            .WithTransferEncoding(ContentEncoding.Base64)
            .WithVersion("1.0")
            .WithId(MimeUtils.GenerateMessageId())
            .WithPatientId(
                new PatientInstance
            {
                PidContext     = "2.16.840.1.113883.19.999999",
                LocalPatientId = "123456"
            }.ToList()
                )
            .WithType(ContextStandard.Type.CategoryRadiology, ContextStandard.Type.ActionReport)
            .WithPurpose(ContextStandard.Purpose.PurposeResearch)
            .WithPatient(
                new Patient
            {
                GivenName   = "John",
                SurName     = "Doe",
                MiddleName  = "Jacob",
                DateOfBirth = "1961-12-31",
                Gender      = "M",
                PostalCode  = "12345"
            }
                );

            var context = contextBuilder.Build();

            //
            // Mime message and simple body
            //
            var message = new MimeMessage();

            message.From.Add(new MailboxAddress("HoboJoe", "*****@*****.**"));
            message.To.Add(new MailboxAddress("Toby", "*****@*****.**"));
            message.Subject = "Sample message with pdf and context attached";
            message.Headers.Add(MailStandard.Headers.DirectContext, context.Headers[ContextStandard.ContentIdHeader]);
            Assert.StartsWith("<", context.Headers[HeaderId.ContentId]);
            Assert.EndsWith(">", context.Headers[HeaderId.ContentId]);

            var body = new TextPart("plain")
            {
                Text = @"Simple Body"
            };

            //
            // Mime message and simple body
            //
            var pdf = new MimePart("application/pdf")
            {
                ContentDisposition      = new ContentDisposition(ContentDisposition.Attachment),
                FileName                = "report.pdf",
                ContentTransferEncoding = ContentEncoding.Base64
            };

            var byteArray = Encoding.UTF8.GetBytes("Fake PDF (invalid)");
            var stream    = new MemoryStream(byteArray);

            pdf.ContentObject = new ContentObject(stream);

            //
            // Multi part construction
            //
            var multiPart = new Multipart("mixed")
            {
                body,
                contextBuilder.BuildMimePart(),
                pdf
            };

            message.Body = multiPart;


            //
            // Assert context can be serialized and parsed.
            //
            var messageParsed = MimeMessage.Load(message.ToString().ToStream());

            Assert.True(messageParsed.ContainsDirectContext());
            Assert.Equal(context.ContentId, messageParsed.DirectContextId());
            Assert.StartsWith("<", messageParsed.Headers[MailStandard.Headers.DirectContext]);
            Assert.EndsWith(">", messageParsed.Headers[MailStandard.Headers.DirectContext]);

            var contextParsed = message.DirectContext();

            Assert.NotNull(contextParsed);

            //
            // Headers
            //
            Assert.Equal("text", contextParsed.ContentType.MediaType);
            Assert.Equal("plain", contextParsed.ContentType.MediaSubtype);
            Assert.Equal("attachment", contextParsed.ContentDisposition.Disposition);
            Assert.Equal("metadata.txt", contextParsed.ContentDisposition.FileName);
            Assert.Equal(context.ContentId, contextParsed.ContentId);

            //
            // Metadata
            //
            Assert.Equal("1.0", contextParsed.Metadata.Version);
            Assert.Equal(context.Metadata.Id, contextParsed.Metadata.Id);

            //
            // Metatdata PatientId
            //
            Assert.Equal("2.16.840.1.113883.19.999999:123456", contextParsed.Metadata.PatientId);
            Assert.Equal(1, contextParsed.Metadata.PatientIdentifier.Count());
            var patientIdentifiers = Enumerable.ToList(contextParsed.Metadata.PatientIdentifier);

            Assert.Equal("2.16.840.1.113883.19.999999", patientIdentifiers[0].PidContext);
            Assert.Equal("123456", patientIdentifiers[0].LocalPatientId);

            //
            // Metatdata Type
            //
            Assert.Equal("radiology/report", contextParsed.Metadata.Type.ToString());
            Assert.Equal("radiology", contextParsed.Metadata.Type.Category);
            Assert.Equal("report", contextParsed.Metadata.Type.Action);

            //
            // Metatdata Purpose
            //
            Assert.Equal("research", contextParsed.Metadata.Purpose);

            //
            // Metadata Patient
            //
            Assert.Equal("givenName=John; surname=Doe; middleName=Jacob; dateOfBirth=1961-12-31; gender=M; postalCode=12345",
                         contextParsed.Metadata.Patient.ToString());

            Assert.Equal("John", contextParsed.Metadata.Patient.GivenName);
            Assert.Equal("Doe", contextParsed.Metadata.Patient.SurName);
            Assert.Equal("1961-12-31", contextParsed.Metadata.Patient.DateOfBirth);
        }