private static IConfigurationKernel LoadKernel() { if (SingletonConfigurationKernel.IsInstance()) { return(SingletonConfigurationKernel); } //var kernel = (IConfigurationKernel)ContainerFactory.Current(new ContextProviders.ScopeContext(null)).Resolve(typeof(IConfigurationKernel), KernelScope); //if (kernel.IsInstance()) return kernel; lock (Triowing) { if (SingletonConfigurationKernel.IsInstance()) { return(SingletonConfigurationKernel); } var newKernel = KernelFactory.CreateKernel(); // kernel = (IConfigurationKernel)ContainerFactory.Current(new ContextProviders.ScopeContext(ResolverKernel)).Resolve(typeof(IConfigurationKernel), KernelScope); //if (kernel.IsInstance()) return kernel; //ContainerFactory.Current(new ContextProviders.ScopeContext(ResolverKernel)).Bind(typeof(IConfigurationKernel), newKernel, KernelScope); if (SingletonConfigurationKernel == null && KernelScope == Scope.Singleton && OptimizedKernel) { SingletonConfigurationKernel = newKernel; } } return(SingletonConfigurationKernel); }
public static void Demo() { Model model = new Model(); var kernels = KernelFactory.Create(new string[] { "A", "B" }); model.AddLayer(new ConvLayer(kernels)); model.AddLayer(new MaxPoolLayer(2, 2)); model.AddLayer(new FlattenLayer()); Matrix[] inputs = DataGenerator.GenerateDataSet5_1(); foreach (var input in inputs) { input.Display(); } model.Fit(inputs); Matrix[] outputs = model.GetOutputs(); Console.WriteLine("**************OUTPUTS***************"); foreach (var output in outputs) { output.Display(); } }
private static IConfigurationKernel LoadKernel() { if (SingletonConfigurationKernel.IsInstance() && KernelScope == Scope.Singleton && OptimizedKernel) { return(SingletonConfigurationKernel); } var kernel = (IConfigurationKernel)ContainerFactory.Current.Resolve(typeof(IConfigurationKernel), KernelScope); if (kernel.IsInstance()) { return(kernel); } lock (Triowing) { var newKernel = KernelFactory.CreateKernel(); kernel = (IConfigurationKernel)ContainerFactory.Current.Resolve(typeof(IConfigurationKernel), KernelScope); if (kernel.IsInstance()) { return(kernel); } ContainerFactory.Current.Bind(typeof(IConfigurationKernel), newKernel, KernelScope); if (SingletonConfigurationKernel == null && KernelScope == Scope.Singleton && OptimizedKernel) { SingletonConfigurationKernel = newKernel; } } return(kernel); }
private static void TestReadWrite(IKernelFunctionWithParams kf) { string typeName = kf.GetType().Name; string fn = typeName + ".txt"; // Write out the kernel StreamWriter sw = new StreamWriter(fn); kf.Write(sw); sw.Close(); // Now read it back again StreamReader sr = new StreamReader(fn); KernelFactory kfact = KernelFactory.Instance; IKernelFunctionWithParams kf1 = kfact.CreateKernelFunction(typeName); kf1.Read(sr); sr.Close(); // Now test that they're the same Assert.Equal(kf.ThetaCount, kf1.ThetaCount); for (int i = 0; i < kf.ThetaCount; i++) { Assert.Equal(kf[i], kf1[i], 1e-6); } }
public static async Task Run( [QueueTrigger(QueueConstants.AzureMLJobQueueName, Connection = QueueConstants.QueueConnectionStringName)] string jobId, ExecutionContext executionContext, TraceWriter logger ) { logger.Info($"{FunctionName} Execution begun at {DateTime.Now}"); IConfiguration webConfiguration = new WebConfiguration(executionContext); var log = new FunctionLog(logger, executionContext.InvocationId); var objectLogger = (webConfiguration.UseObjectLogger) ? new BlobObjectLogger(webConfiguration, log) : null; using (var kernel = new KernelFactory().GetKernel( log, webConfiguration, objectLogger )) { var processor = kernel.Get <IScheduledAzureMLProcessor>(); var result = await processor.CheckAzureMLAndPostProcess(jobId); if (!result.LastJobStatus.IsTerminalState()) { var queue = CreateQueue(); // Job is not finished. Put it back on the queue to try again. var message = new CloudQueueMessage(jobId); queue.AddMessage(message, null, webConfiguration.AzureMlRetryTimeDelay); } } logger.Info($"{FunctionName} completed at {DateTime.Now}"); }
public NWMethod(int kernelType, double[] u, double[] w, double h) { _elementsNumber = u.Length; _u = u; _w = w; _h = h; _kernel = KernelFactory.Create(kernelType); }
public void KernelFactory_EnsureAppDomainAssembliesLoaded() { // Act KernelFactory.EnsureAppDomainAssembliesLoaded(); // Assert Assert.Pass("no results returned"); }
static IntegrationTestBase() { Kernel = KernelFactory.BuildDefaultKernelForTests(); Kernel.Get <ISolutionContext>().SolutionFileName = solutionFile; Kernel.Rebind <IFileWrapper>().To <CodeGeneratorFileWrapper>(); }
/// <summary> /// This method contains all binding configuration on one easy to use file. Add this statement to your applications startup code block (like Global.asax+Application_Start) /// </summary> /// <param name="config">an implementation of IModuleConfiguration that contains all bindings</param> public static void LoadModuleConfiguration(IBlueprint config) { HasExternalIoc = config is IContainerSetup; KernelFactory.LoadContainer(config); LoadKernel(); GetConfigurator().Bind <ILogging>().To(config.LoggingType).SetSingletonScope(); config.Bind(GetConfigurator()); LoggingExtentions.SetLogger(config.LoggingType); }
public FrmAnaMenu() { InitializeComponent(); _projeService = KernelFactory.GetService <IProjeService>(); _userService = KernelFactory.GetService <IUserService>(); _taskService = KernelFactory.GetService <ITaskService>(); _durumService = KernelFactory.GetService <IDurumService>(); _taskStateService = KernelFactory.GetService <ITaskStateService>(); }
public void CreateRedditPostProcessor() { var config = Mock.Of <IConfiguration>(); var kernel = new KernelFactory().GetKernel(new ConsoleLog(), config); var processor = kernel.Get <IThreadProcessor>(); Assert.IsNotNull(processor); }
protected IKernel GetKernel() { var bindings = new List <INinjectModule> { new AgentBindings(this), new ProductionServiceBindings(), new RelativityBindings(this.Helper) }; #if IntegrationTest bindings.Add(new AgentIntegrationTestBindings()); #endif return(KernelFactory.GetKernel(bindings, AgentConfiguration.DefaultBindingsExclusionList)); }
public void Setup() { var integrationHelper = TestUtilities.GetMockHelper(); var bindings = new List <INinjectModule> { new TestExecutionBindings(), new AgentIntegrationTestBindings(), new RelativityBindings(integrationHelper.Object) }; var kernel = KernelFactory.GetKernel(bindings); this.SetupTestingSystem(kernel); ScenarioContext.Current["Kernel"] = kernel; }
public void CreatesScheduledAzureMlProcessor() { // Create an empty config var config = Mock.Of <IConfiguration>(); var kernel = new KernelFactory().GetKernel(new ConsoleLog(), config); var processor = kernel.Get <IScheduledAzureMLProcessor>(); Assert.IsNotNull(processor); }
public void CreatesSocialGist() { // Create an empty config var config = Mock.Of <IConfiguration>(); var kernel = new KernelFactory().GetKernel(new ConsoleLog(), config); var runner = kernel.Get <ISocialGist>(); Assert.IsNotNull(runner); }
public void CreatesAzureMLExperimentRunner() { // Create an empty config var config = Mock.Of <IConfiguration>(); var kernel = new KernelFactory().GetKernel(new ConsoleLog(), config); var runner = kernel.Get <IAzureMLExperimentRunner>(); Assert.IsNotNull(runner); }
public void KernelFactory_Getkernel() { // Act var factory = new KernelFactory(new ServiceBindings(), new TestBindings()); var result = factory.GetKernel(new[] { typeof(ILogContext) }); // Assert Assert.That(result, Is.Not.Null); Assert.That(result.Get <ITestType>(), Is.Not.Null); Assert.Throws <ActivationException>(() => result.Get <ILogContext>(), "ILogContext Should not be bound"); }
static void Main(string[] args) { string inputFile = "D:/Pulpit/Pliki szkolne/Semestr 4/Projekt Indywidualny/SeeMore/SeeMoreDemo/SeeMoreDemo/resources/lenna.png"; string outputFile = "D:/Pulpit/Pliki szkolne/Semestr 4/Projekt Indywidualny/Output/output.png"; Image image = ImageFactory.LoadFromFile(inputFile); TestConvertions(image); Image outcome = image.Filter(kernel: KernelFactory.Neighborhood(KernelSize.SIZE_13x13), filter: FilterType.MEDIAN); ImageFactory.SaveImageToFile(outputFile, outcome); }
public static IConfigurator GetConfigurator() { if (Configurator != null && OptimizedKernel) { return(Configurator); } if (OptimizedKernel) { Configurator = KernelFactory.CreateConfigurator(ConfigurationKernel); return(Configurator); } return(KernelFactory.CreateConfigurator(ConfigurationKernel)); }
public async Task ServerRecoverabilityProcessorInt_ProcessRecoverabilityForServer() { // Arrange using (var kernel = KernelFactory.GetKernel(new TestBindings())) { var serverRecoverabilityProcessor = kernel.Get <ServerRecoverabilityProcessor>(); // Act await serverRecoverabilityProcessor.ProcessRecoverabilityForServer(2280); // Assert Assert.Pass("No return result or mocks to verify"); } }
public void CreateTelemetryClient() { var config = new Mock <IConfiguration>(); config.SetupGet(x => x.FunctionInvocationId).Returns(new System.Guid("00000000-0000-0000-0000-000000001234")); config.SetupGet(x => x.FunctionName).Returns("MyTestFunction"); var kernel = new KernelFactory().GetKernel(new ConsoleLog(), config.Object); var telemetryClient = kernel.Get <ITelemetryClient>(); Assert.IsNotNull(telemetryClient); telemetryClient.TrackEvent("My Event Name"); }
static void RunUtilityService <TSrv, TOpt>(TOpt options, Action <TSrv, TOpt> action) where TOpt : CommonOptions { var kernelFactory = new KernelFactory(new UtilityBindings(), new ProductionServiceBindings()); using (var kernel = kernelFactory.GetKernel()) using (var block = kernel.BeginBlock()) { action(block.Get <TSrv>(), options); if (options.Verbose) { Console.WriteLine(block.Get <TextLogger>().Text); } } }
public async Task RunWorkerLogic() { // start metric event system var cancellationToken = new CancellationToken(false); var factory = new KernelFactory(new AgentIntegrationModule(), new ServiceBindings()); using (var kernel = factory.GetKernel(AgentConfiguration.DefaultBindingsExclusionList)) { var agentRepo = new Mock <IAgentRepository>(); agentRepo.Setup(r => r.ReadAgentEnabled(It.IsAny <int>())).Returns(true); kernel.Rebind <IAgentRepository>().ToConstant(agentRepo.Object); var managerLogic = kernel.Get <MetricSystemWorkerAgentLogic>(); await managerLogic.Execute(cancellationToken, new EventWorker { Id = 123456, Name = "Integration test worker", Type = EventWorkerType.Other }); } // Assert Assert.Pass(); }
/// <summary> /// Loads the binding and IOC bridge based on configuration settings. There is no need to call this manually as it is run in pre app start. /// You can still add more binding files in you app start method. Even change the settings loaded in this. But be carefull not to brake the SOLID principles by modifying behavior at runtime. /// </summary> public static void LoadModuleConfiguration() { var c = Configuration.ConfigurationHelper.Configurations.Value; if (c.IocBridgeFactory != null) { KernelFactory.LoadContainer((IContainerSetup)ObjectFactory.Createinstance(c.IocBridgeFactory, new object[0])); } if (c.ConfigurationReaderType != null) { GetConfigurator().Bind <IConfigurationReader>().To(c.ConfigurationReaderType).SetSingletonScope(); GetConfigurator().Bind <IRuntimeContext>().To <DefaultRuntimeContext>().SetTransientScope(); } if (c.BindingConfigurationType != null) { LoadModuleConfiguration((IBlueprint)ObjectFactory.Createinstance(c.BindingConfigurationType, new object[0])); } }
public static IKernel CreateNewKernel(bool includeDataGridBindings = false) { var bindings = includeDataGridBindings ? new INinjectModule[] { new ServiceBindings(), new DataGridBindings() } : new INinjectModule[] { new ServiceBindings() }; // Init Kernel Kernel = new KernelFactory(bindings).GetKernel(AgentConfiguration.DefaultBindingsExclusionList); // Init logger and bind to Kernel Logger = Logger ?? TestUtilities.GetMockLogger(); Kernel.Bind <ILogger>().ToConstant(Logger.Object).InSingletonScope(); // Init Metrics Repositories in the Kernel Repositories.Init(Kernel); // Return initialized Kernel return(Kernel); }
public async Task MetricSystemManagerAgentLogic_StartManager_Integration() { // Arrange var cancellationToken = new CancellationToken(false); var factory = new KernelFactory(new AgentIntegrationModule()); using (var kernel = factory.GetKernel(AgentConfiguration.DefaultBindingsExclusionList)) { var agentRepo = new Mock <IAgentRepository>(); agentRepo.Setup(r => r.ReadAgentEnabled(It.IsAny <int>())).Returns(true); kernel.Rebind <IAgentRepository>().ToConstant(agentRepo.Object); var logic = kernel.Get <MetricSystemManagerAgentLogic>(); // Act await logic.Execute(cancellationToken); } // Assert Assert.Pass(); }
public void KernelFactory_GetAutoBindableTypes() { // Arrange var stopwatch = new Stopwatch(); // Act stopwatch.Start(); var results = KernelFactory.GetAutoBindableTypes(); stopwatch.Stop(); // Assert Assert.That(results, Is.Not.Empty); Assert.That(results.Values.Any(t => t.Assembly.GetName().Name.ToLower().StartsWith("kcura.pdb.data")), Is.True); Assert.That(results.Values.Any(t => t.Assembly.GetName().Name.ToLower().StartsWith("kcura.pdb.service")), Is.True); // Extra Console.WriteLine($"Bindings found in: {stopwatch.Elapsed.TotalMilliseconds}ms"); //results.ForEach(kvp => Console.WriteLine($"{kvp.Key} => {kvp.Value}")); }
static void Main(string[] args) { var commandStringBuilder = new StringBuilder(); commandStringBuilder.AppendLine("5 5"); commandStringBuilder.AppendLine("1 2 N"); commandStringBuilder.AppendLine("LMLMLMLMM"); commandStringBuilder.AppendLine("3 3 E"); commandStringBuilder.Append("MMRMMRMRRM"); Console.WriteLine(commandStringBuilder.ToString()); var kernel = KernelFactory.CreateKernel(); var moveInvoker = kernel.Get <IMoveInvoker>(); List <ICommand> commands = null; try { commands = moveInvoker.InvokeAll(commandStringBuilder.ToString()); } catch (Exception e) { Console.WriteLine(e); Console.ReadLine(); Environment.Exit(0); } foreach (var item in commands) { try { item.Execute(); } catch (Exception e) { Console.WriteLine(e.Message); Console.ReadLine(); } } Console.ReadLine(); }
public override void MainSetup() { TestSpecificKernel = KernelFactory.BuildDefaultKernelForTests(); EventProxy = TestSpecificKernel.Get <IVisualStudioEventProxy>() //This is important, if the casting isn't done, then EventProxy isn't returned via IoC as TestVisualStudioEventProxy; _MockFileWrapper = BuildMockFileReader(); TestSpecificKernel.Rebind <IFileWrapper>().ToMethod(c => _MockFileWrapper); _MockMicrosoftBuildProjectLoader = BuildMockMicrosoftBuildProjectLoader(); TestSpecificKernel.Rebind <IMicrosoftBuildProjectLoader>().ToMethod(c => _MockMicrosoftBuildProjectLoader); _MockCodeBehindFileHelper = BuildMockCodeBehindFileHelper(); TestSpecificKernel.Rebind <ICodeBehindFileHelper>().ToMethod(c => _MockCodeBehindFileHelper); _MockSolution = new MockSolution(); //Set solution context TestSpecificKernel.Get <ISolutionContext>().SolutionFileName = _MockSolution.FileName; }
public static async Task ProcessRedditPost( [QueueTrigger(QueueConstants.RedditPostQueueName, Connection = QueueConstants.QueueConnectionStringName)] SocialGistPostId socialGistPost, TraceWriter log, ExecutionContext executionContext ) { log.Info($"{FunctionName} Execution begun at {DateTime.Now}"); var config = new WebConfiguration(executionContext); var logger = new FunctionLog(log, executionContext.InvocationId); var objectLogger = (config.UseObjectLogger) ? new BlobObjectLogger(config, logger) : null; using (var kernel = new KernelFactory().GetKernel(logger, config, objectLogger)) { var processor = kernel.Get <IThreadProcessor>(); var socialGist = kernel.Get <ISocialGist>(); socialGist.ResultLimitPerPage = config.ResultLimitPerPage; socialGist.MaximumResultsPerSearch = config.MaximumResultsPerSearch; await processor.Process(socialGistPost); } log.Info($"{FunctionName} completed at {DateTime.Now}"); }