/// <summary>
        /// Load your modules or register your services here!
        /// </summary>
        /// <param name="kernel">The kernel.</param>
        private static void RegisterServices(IKernel kernel)
        {
            //try
            //{
            var mockupService           = typeof(IFhirMockupService);
            var fhirService             = typeof(IFhirService);
            var fhirStructureDefinition = typeof(AbstractStructureDefinitionService);
            //var typesToEnable = new List<TypeInitializer> {mockupService, fhirService, fhirStructureDefinition};
            var serviceTypes = new List <TypeInitializer>
            {
                new TypeInitializer(false, mockupService, nameof(IFhirMockupService)),
                new TypeInitializer(true, fhirService, nameof(IFhirService)),
                new TypeInitializer(true, fhirStructureDefinition, nameof(AbstractStructureDefinitionService))
            };

            var serviceAssemblies = AssemblyLoaderHelper.GetFhirServiceAssemblies();

            foreach (var asm in serviceAssemblies)
            {
                var types = asm.GetTypes();
                foreach (var classType in asm.GetTypes())
                {
                    BindIFhirServices(kernel, serviceTypes, classType);
                }
            }

            //}
            //catch (ReflectionTypeLoadException ex)
            //{
            //   ExceptionLogger.LogReflectionTypeLoadException(ex);
            //}

            CheckForLackingServices();
        }
示例#2
0
 static SnoopUI()
 {
     AssemblyLoaderHelper.Initialize();
     IntrospectCommand.InputGestures.Add(new KeyGesture(Key.I, ModifierKeys.Control));
     RefreshCommand.InputGestures.Add(new KeyGesture(Key.F5));
     HelpCommand.InputGestures.Add(new KeyGesture(Key.F1));
     ClearSearchFilterCommand.InputGestures.Add(new KeyGesture(Key.Escape));
     CopyPropertyChangesCommand.InputGestures.Add(new KeyGesture(Key.C, ModifierKeys.Control | ModifierKeys.Shift));
 }
示例#3
0
        /// <summary>
        /// Processes the given stream to construct a Payload object.
        /// </summary>
        /// <param name="stream">The stream to read from</param>
        /// <returns>
        /// Returns a valid payload object if the stream contains all the necessary data.
        /// Returns null if the stream is already closed at the beginning of the read.
        /// </returns>
        internal Payload Process(Stream stream)
        {
            var payload = new Payload();

            byte[] splitIndexBytes;
            try
            {
                splitIndexBytes = SerDe.ReadBytes(stream, sizeof(int));
                // For socket stream, read on the stream returns 0, which
                // SerDe.ReadBytes() returns as null to denote the stream is closed.
                if (splitIndexBytes == null)
                {
                    return(null);
                }
            }
            catch (ObjectDisposedException)
            {
                // For stream implementation such as MemoryStream will throw
                // ObjectDisposedException if the stream is already closed.
                return(null);
            }

            payload.SplitIndex = BinaryPrimitives.ReadInt32BigEndian(splitIndexBytes);
            payload.Version    = SerDe.ReadString(stream);

            payload.TaskContext = new TaskContextProcessor(_version).Process(stream);
            TaskContextHolder.Set(payload.TaskContext);

            payload.SparkFilesDir = SerDe.ReadString(stream);
            SparkFiles.SetRootDirectory(payload.SparkFilesDir);

            // Register additional assembly handlers after SparkFilesDir has been set
            // and before any deserialization occurs. BroadcastVariableProcessor may
            // deserialize objects from assemblies that are not currently loaded within
            // our current context.
            AssemblyLoaderHelper.RegisterAssemblyHandler();

            if (ConfigurationService.IsDatabricks)
            {
                SerDe.ReadString(stream);
                SerDe.ReadString(stream);
            }

            payload.IncludeItems       = ReadIncludeItems(stream);
            payload.BroadcastVariables = new BroadcastVariableProcessor(_version).Process(stream);

            // TODO: Accumulate registration should be done here.

            payload.Command = new CommandProcessor(_version).Process(stream);

            return(payload);
        }
示例#4
0
        public void GetControllers_CurrentAssembly_GetsControllers()
        {
            // Arrange
            var initializer = new DummyControllerContainerInitializer();

            // Act
            var types = initializer.GetControllersPublic(new[] { AssemblyLoaderHelper.GetTestUtilitiesAssembly() });

            // Assert
            Assert.IsNotNull(types, "GetControllers returned null.");

            // Don't check for exact count. They can change while this assembly grows.
            Assert.IsTrue(types.Any(), "No controllers were found.");
        }
示例#5
0
        private PluginInfo[] LoadPlugins()
        {
            var pluginFolder             = GetPluginFolder();
            var pluginFolderSettingsName = $"{nameof(Plugin)}:{nameof(Plugin.Folder)}";

            if (string.IsNullOrWhiteSpace(pluginFolder))
            {
                _logger.Info($"'{pluginFolderSettingsName}' setting not configured. No plugins will be loaded.");
                return(new PluginInfo[0]);
            }

            if (!Directory.Exists(pluginFolder))
            {
                _logger.Warn($"Plugin folder '{pluginFolder}' does not exist. No plugins will be loaded.");

                _logger.Warn(
                    $"To configure plugins update the '{pluginFolderSettingsName}' setting with either an absolute path, a path relative to the 'Ed-Fi-ODS-Implementation\\Application\\EdFi.Ods.WebApi\', or a path relative to the deployed EdFi.Ods.WebApi executable.");

                return(new PluginInfo[0]);
            }

            try
            {
                _logger.Info($"Loading plugins from: '{pluginFolder}'");
                var assemblyFiles = AssemblyLoaderHelper.FindPluginAssemblies(pluginFolder);

                // IMPORTANT: Load the plug-in assembly into the Default context
                return(assemblyFiles
                       .Select(
                           assemblyFile => new PluginInfo
                {
                    AssemblyFileName = assemblyFile,
                    Assembly = AssemblyLoadContext.Default.LoadFromAssemblyPath(assemblyFile)
                })
                       .ToArray());
            }
            finally
            {
                // LoadPluginAssemblies method creates a pluginFinderAssemblyContext and loads assembles in it to
                // determine plugins to load in the app domain. Need to force a garbage collection to unload
                // the pluginFinderAssemblyContext immediately or else assemblies loaded in this context will
                // be in the current app domain.
                GC.Collect();
            }
        }
 public void NewsAssembly_HasPrecompiledViews()
 {
     string[] failedViews;
     Assert.IsTrue(AssemblyLoaderHelper.EnsurePrecompiledRazorViews(typeof(NewsController).Assembly, out failedViews), "Some views are not precompiled: " + string.Join(", ", failedViews));
 }
示例#7
0
 public static void Setup(TestContext testContext)
 {
     AssemblyLoaderHelper.EnsureAllAssembliesAreLoadedForSinkTest();
 }
示例#8
0
 public void FrontendAssembly_HasPrecompiledViews()
 {
     string[] failedViews;
     Assert.IsTrue(AssemblyLoaderHelper.EnsurePrecompiledRazorViews(typeof(FrontendModule).Assembly, out failedViews), "Some views are not precompiled: " + string.Join(", ", failedViews));
 }
示例#9
0
        public void ConfigureServices(IServiceCollection services)
        {
            _logger.Debug("Building services collection");

            services.AddSingleton(ApiSettings);
            services.AddSingleton(Configuration);

            AssemblyLoaderHelper.LoadAssembliesFromExecutingFolder();

            var pluginInfos = LoadPlugins();

            services.AddSingleton(pluginInfos);

            // this allows the solution to resolve the claims principal. this is not best practice defined by the
            // netcore team, as the claims principal is on the controllers.
            // c.f. https://docs.microsoft.com/en-us/aspnet/core/migration/claimsprincipal-current?view=aspnetcore-3.1
            services.AddHttpContextAccessor();

            // this is opening up all sites to connect to the server. this should probably be reviewed.
            services.AddCors(
                options =>
            {
                options.AddPolicy(
                    CorsPolicyName,
                    builder => builder
                    .AllowAnyOrigin()
                    .AllowAnyMethod()
                    .AllowAnyHeader()
                    .WithExposedHeaders("*"));
            });

            // will apply the MvcConfigurator at runtime.
            var mvcBuilder = services
                             .AddControllers(options => options.OutputFormatters.Add(new GraphMLMediaTypeOutputFormatter()))
                             .AddNewtonsoftJson(
                options =>
            {
                options.SerializerSettings.NullValueHandling    = NullValueHandling.Ignore;
                options.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Utc;
                options.SerializerSettings.DateParseHandling    = DateParseHandling.None;
                options.SerializerSettings.Formatting           = Formatting.Indented;
                options.SerializerSettings.ContractResolver     = new CamelCasePropertyNamesContractResolver();
            });

            // Add controllers for the plugins
            foreach (var pluginInfo in pluginInfos)
            {
                var pluginAssembly = pluginInfo.Assembly;

                // This loads MVC application parts from plugin assemblies
                var partFactory = ApplicationPartFactory.GetApplicationPartFactory(pluginAssembly);

                foreach (var part in partFactory.GetApplicationParts(pluginAssembly))
                {
                    mvcBuilder.PartManager.ApplicationParts.Add(part);
                }
            }

            mvcBuilder.AddControllersAsServices();

            services.AddMvc()
            .ConfigureApiBehaviorOptions(
                options =>
            {
                options.InvalidModelStateResponseFactory = actionContext
                                                           => new BadRequestObjectResult(ErrorTranslator.GetErrorMessage(actionContext.ModelState));
            });

            services.AddAuthentication(EdFiAuthenticationTypes.OAuth)
            .AddScheme <AuthenticationSchemeOptions, EdFiOAuthAuthenticationHandler>(EdFiAuthenticationTypes.OAuth, null);

            services.AddApplicationInsightsTelemetry(
                options => { options.ApplicationVersion = ApiVersionConstants.Version; });

            if (ApiSettings.IsFeatureEnabled(ApiFeature.IdentityManagement.GetConfigKeyName()))
            {
                services.AddAuthorization(
                    options =>
                {
                    options.AddPolicy("IdentityManagement",
                                      policy => policy.RequireAssertion(
                                          context => context.User
                                          .HasClaim(c => c.Type == $"{EdFiConventions.EdFiOdsResourceClaimBaseUri}/domains/identity")));
                });
            }
        }