Exemple #1
0
        private static IWebHost HostInitialization(HttpApplication application)
        {
            var kernelBuilder = new KernelBuilder();

            kernelBuilder.UseCaching(c => c.UseMemoryCache());
            kernelBuilder.UseLogging(c => c.UseNLog());
            kernelBuilder.UseWeb(c => c.EnableMvc().EnableSecurity());
            kernelBuilder.UseData(c =>
            {
                c.UseEntityFramework();
                c.EnableMvcFilterTransaction();
                c.EnableDataMigrators();
            });

            //开启基础设置层。
            kernelBuilder.UseInfrastructures();

            var container = kernelBuilder.Build();

            var host = container.Resolve <IWebHost>();

            host.Initialize();
            host.BeginRequest();
            host.EndRequest();

            return(host);
        }
 public static KernelBuilder UseMvvmInterface(this KernelBuilder kernelBuilder, Action <IMvvmBuilder> builder)
 {
     kernelBuilder.buildActions.Add(() => kernelBuilder._containerBuilder.RegisterType <KernelViewModelManager>().As <IViewModelManager>().SingleInstance());
     kernelBuilder.buildActions.Add(() => kernelBuilder._containerBuilder.RegisterType <KernelViewComponentManager>().As <IViewComponentManager>().SingleInstance());
     builder(new MvvmBuilder(kernelBuilder));
     return(kernelBuilder);
 }
Exemple #3
0
        private static IWebHost HostInitialization(HttpApplication application)
        {
            var kernelBuilder = new KernelBuilder();

            kernelBuilder.UseCaching(c => c.UseMemoryCache());
            kernelBuilder.UseLogging(c => c.UseNLog());
            kernelBuilder.UseWeb(c => c.EnableMvc().EnableSecurity());
            kernelBuilder.UseData(c =>
            {
                c.UseEntityFramework();
                c.EnableMvcFilterTransaction();

                //如果开启了EntityFramework的自动迁移则不启动数据迁移。
                var automaticMigrationsEnabled = ConfigurationManager.AppSettings["Data.EntityFramework.AutomaticMigrationsEnabled"];
                if (!string.Equals(automaticMigrationsEnabled, "true", StringComparison.OrdinalIgnoreCase))
                {
                    c.EnableDataMigrators();
                }
            });

            kernelBuilder.UseResources();

            var container = kernelBuilder.Build();

            var host = container.Resolve <IWebHost>();

            host.Initialize();
            host.BeginRequest();
            host.EndRequest();

            return(host);
        }
 public static KernelBuilder UseWindowManager <T, TWindow>(this KernelBuilder kernelBuilder)
     where T : IWindowManager <TWindow>
 {
     kernelBuilder.buildActions.Add(() => kernelBuilder._containerBuilder
                                    .RegisterType <T>()
                                    .AsSelf()
                                    .As <IWindowManager>()
                                    .As <IWindowManager <TWindow> >()
                                    .SingleInstance());
     return(kernelBuilder);
 }
Exemple #5
0
        /// <summary>
        /// Starts the application
        /// </summary>
        public static void Start()
        {
            DynamicModuleUtility.RegisterModule(typeof(OnePerRequestHttpModule));
            DynamicModuleUtility.RegisterModule(typeof(NinjectHttpModule));

            //Setup for web application
            bootstrapper.Initialize(() =>
            {
                var kernel = new KernelBuilder().ForWebApplication().Build();

                //Only register the interceptor once per application (Hangfire job is the same application scope)
                DbInterception.Add(new EFEntityInterceptor(() => kernel.Get <IOperationClock>(), () => kernel.Get <Maybe <ActiveUserIdContext> >(), () => kernel.Get <IFallbackUserResolver>()));

                return(kernel);
            });
        }
Exemple #6
0
        protected TestBase()
        {
            var kernelBuilder = new KernelBuilder();
            kernelBuilder.OnStarting(Register);
            kernelBuilder.UseCaching(c => c.UseMemoryCache());
            kernelBuilder.UseLogging(c => c.UseNLog());

            var container = Container = kernelBuilder.Build();
            var type = GetType();
            var properties = type.GetProperties();
            foreach (var property in properties)
            {
                var propertyType = property.PropertyType;
                if (!container.IsRegistered(propertyType))
                    continue;
                property.SetValue(this, container.Resolve(propertyType), null);
            }
        }
Exemple #7
0
        private static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            var kernelBuilder = new KernelBuilder();

            kernelBuilder.OnStarting(builder => builder.RegisterType <MainForm>().AsSelf().As <IUserInterfaceController>().InstancePerLifetimeScope());
            kernelBuilder.UseCaching(c => c.UseMemoryCache());

            var hostContainer = kernelBuilder.Build();
            var host          = hostContainer.Resolve <IHost>();

            host.Initialize();

            var work = host.CreateStandaloneEnvironment(new ShellSettings {
                Name = "Default"
            });
            var form = work.Resolve <MainForm>();

            Application.Run(form);
        }
Exemple #8
0
        protected TestBase()
        {
            var kernelBuilder = new KernelBuilder();

            kernelBuilder.OnStarting(Register);
            kernelBuilder.UseCaching(c => c.UseMemoryCache());
            //.UseLogging(c => c.UseNLog());

            var container  = Container = kernelBuilder.Build();
            var type       = GetType();
            var properties = type.GetProperties();

            foreach (var property in properties)
            {
                var propertyType = property.PropertyType;
                if (!container.IsRegistered(propertyType))
                {
                    continue;
                }
                property.SetValue(this, container.Resolve(propertyType), null);
            }
        }
Exemple #9
0
        private static void InitializeHangfire(IAppBuilder app)
        {
            // Initializing the Hangfire scheduler
            var standardKernel = new KernelBuilder().ForHangFire().Build();

            GlobalConfiguration.Configuration.UseNinjectActivator(standardKernel);
            GlobalConfiguration.Configuration.UseSqlServerStorage("kitos_HangfireDB");
            GlobalJobFilters.Filters.Add(new AdvisSendFailureFilter(standardKernel));
            GlobalJobFilters.Filters.Add(new AutomaticRetryAttribute {
                Attempts = KitosConstants.MaxHangfireRetries
            });

            app.UseHangfireDashboard();
            app.UseHangfireServer(new KeepReadModelsInSyncProcess());

            ServiceEndpointConfiguration.ConfigureValidationOfOutgoingConnections();

            var recurringJobManager = new RecurringJobManager();

            recurringJobManager.AddOrUpdate(
                recurringJobId: StandardJobIds.CheckExternalLinks,
                job: Job.FromExpression((IBackgroundJobLauncher launcher) => launcher.LaunchLinkCheckAsync(CancellationToken.None)),
                cronExpression: Cron.Weekly(DayOfWeek.Sunday, 0),
                timeZone: TimeZoneInfo.Local);

            new RecurringJobManager().AddOrUpdate(
                recurringJobId: StandardJobIds.RebuildDataProcessingReadModels,
                job: Job.FromExpression((IBackgroundJobLauncher launcher) => launcher.LaunchFullReadModelRebuild(ReadModelRebuildScope.DataProcessingRegistration, CancellationToken.None)),
                cronExpression: Cron.Never(), //On demand
                timeZone: TimeZoneInfo.Local);

            new RecurringJobManager().AddOrUpdate(
                recurringJobId: StandardJobIds.RebuildItSystemUsageReadModels,
                job: Job.FromExpression((IBackgroundJobLauncher launcher) => launcher.LaunchFullReadModelRebuild(ReadModelRebuildScope.ItSystemUsage, CancellationToken.None)),
                cronExpression: Cron.Never(), //On demand
                timeZone: TimeZoneInfo.Local);
        }
Exemple #10
0
 public MvvmBuilder(KernelBuilder kernelBuilder)
 {
     this.kernelBuilder = kernelBuilder;
 }
Exemple #11
0
    public static void Compute(
        string filePath,
        ViewPort viewPort,
        ComputationType computationType,
        CancellationToken token)
    {
        Log.Info($"Outputting to: {filePath}");
        Log.Info($"Resolution: {viewPort.Resolution.Width:N0}x{viewPort.Resolution.Height:N0}");
        Log.Info($"Area: {viewPort.Area}");
        Log.Info($"Computation type: {computationType}");

        IEnumerable <bool> GetPointsInSetScalar()
        {
            var kernel = KernelBuilder.BuildScalarKernel(computationType);

            var rowPointsInSet = new bool[viewPort.Resolution.Width];

            using var progress = TimedOperation.Start("points", totalWork: viewPort.Resolution.Area());
            for (int row = 0; row < viewPort.Resolution.Height; row++)
            {
                Parallel.For(
                    0,
                    viewPort.Resolution.Width,
                    col => rowPointsInSet[col] = kernel.FindEscapeTime(viewPort.GetComplex(col, row), Constant.IterationRange.Max).IsInfinite);

                for (int x = 0; x < viewPort.Resolution.Width; x++)
                {
                    yield return(rowPointsInSet[x]);
                }

                progress.AddWorkDone(viewPort.Resolution.Width);
            }
        }

        IEnumerable <bool> GetPointsInSetVectorDoubles()
        {
            using var progress = TimedOperation.Start("points", totalWork: viewPort.Resolution.Area());
            var vWidth = VectorDoubleKernel.Capacity;

            var vectorBatches = viewPort.Resolution.Width / vWidth;
            var remainder     = viewPort.Resolution.Width % vWidth;

            if (remainder != 0)
            {
                vectorBatches++;
            }
            var lastIndex = vectorBatches - 1;

            var rowPointsInSet = new bool[viewPort.Resolution.Width];

            // TODO: Why is the Parallel.For inside a loop?
            for (int row = 0; row < viewPort.Resolution.Height; row++)
            {
                Parallel.For(
                    0,
                    vectorBatches,
                    batchIndex =>
                {
                    var realBatch = new double[vWidth];
                    var imagBatch = new double[vWidth];
                    var times     = new EscapeTime[vWidth];

                    var batchSize = (batchIndex == lastIndex) ? remainder : vWidth;

                    for (int i = 0; i < batchSize; i++)
                    {
                        var c        = viewPort.GetComplex(batchIndex * vWidth + i, row);
                        realBatch[i] = c.Real;
                        imagBatch[i] = c.Imaginary;
                    }

                    VectorDoubleKernel.FindEscapeTimes(
                        realBatch, imagBatch, Constant.IterationRange.Max, times);

                    for (int i = 0; i < batchSize; i++)
                    {
                        rowPointsInSet[batchIndex * vWidth + i] = times[i].Iterations == Constant.IterationRange.Max;
                    }
                });

                for (int x = 0; x < viewPort.Resolution.Width; x++)
                {
                    yield return(rowPointsInSet[x]);
                }

                progress.AddWorkDone(viewPort.Resolution.Width);
            }
        }

        IEnumerable <bool> ChooseEnumerator() =>
        computationType switch
        {
            ComputationType.ScalarDouble => GetPointsInSetScalar(),
            ComputationType.ScalarFloat => GetPointsInSetScalar(),
            ComputationType.VectorDouble => GetPointsInSetVectorDoubles(),
            _ => throw new ArgumentException("Unsupported computation type: " + computationType)
        };

        Write(filePath, viewPort, computationType, ChooseEnumerator());
    }
}
 public StatisticBuilder(KernelBuilder builder)
 {
     Builder = builder;
 }