Exemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance.
        /// </summary>
        /// <param name="xml"></param>
        /// <param name="catalog"></param>
        /// <param name="exports"></param>
        Document(
            Func<Document, XDocument> xml,
            ComposablePartCatalog catalog,
            ExportProvider exports)
        {
            Contract.Requires<ArgumentNullException>(xml != null);

            // configure composition
            this.configuration = GetConfiguration(catalog, exports);
            this.container = new CompositionContainer(configuration.HostCatalog, true, new CompositionContainer(configuration.GlobalCatalog, true, configuration.Exports));
            this.container.GetExportedValue<DocumentEnvironment>().SetHost(this);

            // required services
            this.invoker = container.GetExportedValue<IInvoker>();
            this.trace = container.GetExportedValue<ITraceService>();

            // initialize xml
            this.xml = xml(this);
            this.xml.AddAnnotation(this);

            // parallel initialization of common interfaces
            Parallel.ForEach(this.xml.DescendantNodesAndSelf(), i =>
            {
                Enumerable.Empty<object>()
                    .Concat(i.Interfaces<IOnInit>())
                    .Concat(i.Interfaces<IOnLoad>())
                    .ToLinkedList();
            });

            // initial invocation entry
            this.invoker.Invoke(() => { });
        }
Exemplo n.º 2
0
 public void Prepare()
 {
     container = new CompositionContainer(
         new AggregateCatalog(
             new AssemblyCatalog(
                 typeof (ITypedPool).Assembly
                 ),
             new TypeCatalog(typeof (Registrator)),
             new TypeCatalog(typeof(ResourcePool)),
             new TypeCatalog(typeof (NotifiedElementGetter)),
             new TypeCatalog(typeof (UnnotifiedElementGetter)),
             new TypeCatalog(typeof (NotifiedElementPoster)),
             new TypeCatalog(typeof (UnnotifiedElementPoster))));
     _uplink = _mockRepository.DynamicMock<AnnouncerUplink>();
     _downlink = _mockRepository.DynamicMock<AnnouncerDownlink>(); 
     _downlink.Expect(k => k.Subscribe(null))                   
            .IgnoreArguments()
            .Repeat.Once();
     _downlink.Replay();
     
     container.ComposeExportedValue(_uplink);
     container.ComposeExportedValue(_downlink);
     var service = container.GetExportedValue<ICacheServicing>(); 
     service.Initialize(new Settings
                            {
                                AutoSubscription = (TestContext.Properties["AutoSubscription"] as string)== "true"                                      
                            }, container);
     _pool = container.GetExportedValue<ITypedPool>();
     _subscriptor = container.GetExportedValue<IAnnouncerSubscriptor>();                        
 }
Exemplo n.º 3
0
        public ApplicationController(CompositionContainer container, IPresentationService presentationService,
            IMessageService messageService, ShellService shellService, ProxyController proxyController, DataController dataController)
        {
            InitializeCultures();
            presentationService.InitializeCultures();

            this.container = container;
            this.dataController = dataController;
            this.proxyController = proxyController;
            this.messageService = messageService;

            this.dataService = container.GetExportedValue<IDataService>();

            this.floatingViewModel = container.GetExportedValue<FloatingViewModel>();
            this.mainViewModel = container.GetExportedValue<MainViewModel>();
            this.userBugsViewModel = container.GetExportedValue<UserBugsViewModel>();
            this.teamBugsViewModel = container.GetExportedValue<TeamBugsViewModel>();

            shellService.MainView = mainViewModel.View;
            shellService.UserBugsView = userBugsViewModel.View;
            shellService.TeamBugsView = teamBugsViewModel.View;

            this.floatingViewModel.Closing += FloatingViewModelClosing;

            this.showMainWindowCommand = new DelegateCommand(ShowMainWindowCommandExcute);
            this.englishCommand = new DelegateCommand(() => SelectLanguage(new CultureInfo("en-US")));
            this.chineseCommand = new DelegateCommand(() => SelectLanguage(new CultureInfo("zh-CN")));
            this.settingCommand = new DelegateCommand(SettingDialogCommandExcute, CanSettingDialogCommandExcute);
            this.aboutCommand = new DelegateCommand(AboutDialogCommandExcute);
            this.exitCommand = new DelegateCommand(ExitCommandExcute);
        }
    protected override void Initialize()
    {
        base.Initialize();

        var exceptionDialog = new ExceptionDialog("http://code.google.com/p/notifypropertyweaver/issues/list", "NotifyPropertyWeaver");
        try
        {
            using (var catalog = new AssemblyCatalog(GetType().Assembly))
            using (var container = new CompositionContainer(catalog))
            {
                var menuCommandService = (IMenuCommandService) GetService(typeof (IMenuCommandService));
                var errorListProvider = new ErrorListProvider(ServiceProvider.GlobalProvider);

                container.ComposeExportedValue(exceptionDialog);
                container.ComposeExportedValue(menuCommandService);
                container.ComposeExportedValue(errorListProvider);

                container.GetExportedValue<MenuConfigure>().RegisterMenus();
                container.GetExportedValue<SolutionEvents>().RegisterSolutionEvents();
                container.GetExportedValue<TaskFileReplacer>().CheckForFilesToUpdate();
            }
        }
        catch (Exception exception)
        {
            exceptionDialog.HandleException(exception);
        }
    }
Exemplo n.º 5
0
        static void Main()
        {
            try
            {
               
                programCatalog = new AggregateCatalog();
                programCatalog.Catalogs.Add(new DirectoryCatalog(Directory.GetCurrentDirectory()));
                programCatalog.Catalogs.Add(new AssemblyCatalog(Assembly.GetExecutingAssembly()));
                programContainer = new CompositionContainer(programCatalog);
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.ThreadException += new ThreadExceptionEventHandler(Program.otherException);
                Application.Run(programContainer.GetExportedValue<FrmMain>());
            }
            catch (Exception e)
            {
                programContainer.GetExportedValue<FrmMain>().richTextBox1.AppendText("\n" + e.Message);
                string logStr = string.Concat(new string[]
				{
					DateTime.Now.ToString("yyyy/MM/dd hh:mm:ss"),
					"\t",
					e.Message,
					"\t",
					e.Source
				});
                FileLog.FileLogOut("Client.log", logStr);
            }
           
        }
Exemplo n.º 6
0
        public void WhenInitializingAModuleWithACatalogPendingToBeLoaded_ThenLoadsTheCatalogInitializesTheModule()
        {
            var aggregateCatalog = new AggregateCatalog(new AssemblyCatalog(typeof(MefModuleInitializer).Assembly));
            var compositionContainer = new CompositionContainer(aggregateCatalog);
            compositionContainer.ComposeExportedValue(aggregateCatalog);

            var serviceLocatorMock = new Mock<IServiceLocator>();
            var loggerFacadeMock = new Mock<ILoggerFacade>();

            var serviceLocator = serviceLocatorMock.Object;
            var loggerFacade = loggerFacadeMock.Object;

            compositionContainer.ComposeExportedValue(serviceLocator);
            compositionContainer.ComposeExportedValue(loggerFacade);

            var moduleInitializer = compositionContainer.GetExportedValue<IModuleInitializer>();
            var repository = compositionContainer.GetExportedValue<DownloadedPartCatalogCollection>();

            var moduleInfo = new ModuleInfo("TestModuleForInitializer", typeof(TestModuleForInitializer).AssemblyQualifiedName);

            repository.Add(moduleInfo, new TypeCatalog(typeof(TestModuleForInitializer)));

            moduleInitializer.Initialize(moduleInfo);

            ComposablePartCatalog existingCatalog;
            Assert.IsFalse(repository.TryGet(moduleInfo, out existingCatalog));

            var module = compositionContainer.GetExportedValues<IModule>().OfType<TestModuleForInitializer>().First();

            Assert.IsTrue(module.Initialized);
        }
Exemplo n.º 7
0
 static void Main(string[] args)
 {
     var container = new CompositionContainer();
     ComposeBatchOne(container);
     container.GetExportedValue<Bootstrapper>().Run();
     ComposeBatchTwo(container);
     container.GetExportedValue<Bootstrapper>().Run();
 }
Exemplo n.º 8
0
 public static void Initialize(TestContext context) {
   _container = SetupServerMefContainer();
   _registry = _container.GetExportedValue<IFileSystemProcessor>();
   _searchEngine = _container.GetExportedValue<ISearchEngine>();
   _searchEngine.FilesLoaded += (sender, result) => _serverReadyEvent.Set();
   _testFile = Utils.GetChromiumTestEnlistmentFile();
   _registry.RegisterFile(new FullPath(_testFile.FullName));
 }
Exemplo n.º 9
0
        /// <summary>
        /// 同一コントラクト名・別クラステスト
        /// </summary>
        /// <param name="container"></param>
        private static void Test1(CompositionContainer container)
        {
            // インスタンスを取得する
            var type1 = container.GetExportedValue<ITest1>("test");
            var type2 = container.GetExportedValue<ITest2>("test");

            type1.Execute();
            type2.Execute();
        }
Exemplo n.º 10
0
        public static ITextBuffer CreateTextBuffer(CompositionContainer container, string text)
        {
            var contentTypeRegistry = container.GetExportedValue<IContentTypeRegistryService>();
            var contentType = contentTypeRegistry.GetContentType(HlslConstants.ContentTypeName)
                ?? contentTypeRegistry.AddContentType(HlslConstants.ContentTypeName, null);

            var textBufferFactory = container.GetExportedValue<ITextBufferFactoryService>();
            var textBuffer = textBufferFactory.CreateTextBuffer(text, contentType);

            return textBuffer;
        }
Exemplo n.º 11
0
        public void ContainerResolvesBothAbstractionAndConcreteType()
        {
            var catalog = new TypeCatalog(typeof(Ploeh.Samples.Menu.Mef.Attributed.Unmodified.Abstract.SauceBéarnaise));
            var container = new CompositionContainer(catalog);

            var sauce = container.GetExportedValue<SauceBéarnaise>();
            var ingredient = container.GetExportedValue<IIngredient>();

            Assert.NotNull(sauce);
            Assert.NotNull(ingredient);
        }
	public void WhenPartIsNonShared_ThenGetExportGetsDifferent()
	{
		var catalog = new TypeCatalog(typeof(NonSharedFoo));
		var filtered = new FilteringReflectionCatalog(catalog);

		var container = new CompositionContainer(filtered);

		var export1 = container.GetExportedValue<NonSharedFoo>();
		var export2 = container.GetExportedValue<NonSharedFoo>();

		Assert.NotSame(export1, export2);
	}
        protected override void Configure()
        {
            InitializeApplicationDataDirectory();

            var composeTask = Task.Factory.StartNew(() =>
                {
                    // var aggregateCatalog = new AggregateCatalog(AssemblySource.Instance.Select(x => new AssemblyCatalog(x)));
                    var aggregateCatalog = new AggregateCatalog(new AssemblyCatalog(GetType().Assembly), new AssemblyCatalog(typeof(AutoCaptureEngine).Assembly), new AssemblyCatalog(typeof(IRepository<>).Assembly));
                    Container = new CompositionContainer(aggregateCatalog);
                    var batch = new CompositionBatch();
                    batch.AddExportedValue(Container);
                    batch.AddExportedValue<IEventAggregator>(new EventAggregator());
                    batch.AddExportedValue<IWindowManager>(new CustomWindowManager());
                    batch.AddExportedValue<Func<IMessageBox>>(() => Container.GetExportedValue<IMessageBox>());
                    batch.AddExportedValue<Func<HearthStatsDbContext>>(() => new HearthStatsDbContext());

                    // batch.AddExportedValue<IWindowManager>(new AppWindowManager());
                    // batch.AddExportedValue(MessageBus.Current);

                    var compose = Container.GetExportedValue<CompositionBuilder>();
                    compose.Compose(batch);
                    // var composeTasks = this.GetAllInstances<ICompositionTask>();
                    // composeTasks.Apply(s => s.Compose(batch));
                    Container.Compose(batch);
                });

            var initDbTask = Task.Factory.StartNew(InitializeDatabase);

            Task.WaitAll(composeTask, initDbTask);

            var logPath = Path.Combine((string)AppDomain.CurrentDomain.GetData("DataDirectory"), "logs");
            _logManager = Container.GetExportedValue<IAppLogManager>();
            _logManager.Initialize(logPath);
            Container.GetExportedValue<CrashManager>().WireUp();

            // Apply xaml/wpf fixes
            var currentUICult = Thread.CurrentThread.CurrentUICulture.Name;
            var currentCult = Thread.CurrentThread.CurrentCulture.Name;

            Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(currentUICult);
            Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo(currentCult);

            FrameworkElement.LanguageProperty.OverrideMetadata(
                typeof(FrameworkElement),
                new FrameworkPropertyMetadata(XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag)));

            // Hook caliburn filter
            FilterFrameworkCoreCustomization.Hook();

            // Hook application events
            Application.Activated += (s, e) => Container.GetExportedValue<IEventAggregator>().PublishOnCurrentThread(new ApplicationActivatedEvent());
            Application.Deactivated += (s, e) => Container.GetExportedValue<IEventAggregator>().PublishOnCurrentThread(new ApplicationDeActivatedEvent());
        }
Exemplo n.º 14
0
        public void RegisterInstancesAndResolveByName()
        {
            using (CompositionContainer mefContainer = new CompositionContainer())
            {
                mefContainer.ComposeExportedValue<IService>("add", new ServiceAdd());
                mefContainer.ComposeExportedValue<IService>("sub", new ServiceSub());

                IService serviceAdd = mefContainer.GetExportedValue<IService>("add");
                IService serviceSub = mefContainer.GetExportedValue<IService>("sub");
                Assert.That(serviceAdd.Calc(1, 2), Is.EqualTo(3));
                Assert.That(serviceSub.Calc(5, 2), Is.EqualTo(3));
            }
        }
Exemplo n.º 15
0
        public void StateIsNotShared()
        {
            var container =
                new CompositionContainer(
                    new AggregateCatalog(
                        new AssemblyCatalog(typeof(ICurrentState<>).Assembly),
                        new TypeCatalog(typeof(TestCurrentState), typeof(TestState))));

            var state = container.GetExportedValue<IState<string>>();

            Assert.IsInstanceOfType(state, typeof(TestState));
            Assert.AreNotSame(state, container.GetExportedValue<IState<string>>());
        }
Exemplo n.º 16
0
        public SetTokenController(CompositionContainer container,object shellView)
        {
            this.shellView = shellView;
             this.container = container;
             setTokenViewModel = container.GetExportedValue<SetTokenViewModel>();

            //var apiTokenSettings = LoadApiTokenList();
            //setTokenViewModel.SetApiTokenList(apiTokenSettings.userApiTokenList);
            setTokenViewModel.ShowDetailsCommand = new DelegateCommand(ShowDetails);
            setTokenViewModel.CreateNewCommand = new DelegateCommand(CreateNewUserToken);
            setTokenViewModel.DeleteTokenCommand = new DelegateCommand(DeleteToken);
            setTokenViewModel.UpdateCommand = new DelegateCommand(UpdateToken);
            setTokenDetailsViewModel = container.GetExportedValue<SetTokenDetailsViewModel>();
        }
Exemplo n.º 17
0
		static void Main (string[] args)
		{
			#region Deprecated

			//var telemetry = new TelemetryClient ();
			//telemetry.Context.InstrumentationKey = "f200ff9e-3a4a-47a4-8288-3c4a485c173b";
			//telemetry.TrackTrace ("App Started");
			//telemetry.Flush ();
			//telemetry.TrackEvent ("AppStarted");
			//telemetry.TrackEvent ("AppFinished", 
			//	metrics: new Dictionary<string, double> { { "Elapsed", 2000 } });
			//telemetry.Flush ();
			//telemetry.TrackException (new InvalidOperationException ("Boo!"));
			//telemetry.Flush ();
			//telemetry.TrackMetric ("AppRunning", 2000);
			//telemetry.Flush ();

			#endregion

			var container = new CompositionContainer(new AssemblyCatalog(typeof(Program).Assembly));

			TraceEvents (container);

			// Components that need to be started up-front, like event subscribers

			container.GetExportedValues<IAutoLoad> ().ToArray ();

			var stream = container.GetExportedValue<IEventStream>();

			var eventsGenerator = container.GetExportedValue<IEventsGenerator>();
			var errorsGenerator = container.GetExportedValue<IErrorsGenerator>();

			var events = eventsGenerator.Generate();

			foreach(var ev in events) {
				stream.Push (ev);
			}

			var errors = errorsGenerator.Generate();

			foreach (var error in errors) {
				stream.Push (error);
			}

			container.GetExportedValue<TelemetryClient> ().Flush ();

			Thread.Sleep (1000);
		}
Exemplo n.º 18
0
 public static CompositionContainer MakeContainerAndCache(Settings settings,IEnumerable<Type> types)
 {
     var catalog = MockHelper.CatalogForContainer(new[]{typeof (ITypedPool).Assembly}, types);
     var container = new CompositionContainer(catalog);
     container.GetExportedValue<ICacheServicing>().Initialize(settings,container);
     return container;
 }
Exemplo n.º 19
0
        public void WhenInitializingAModuleWithNoCatalogPendingToBeLoaded_ThenInitializesTheModule()
        {
            var aggregateCatalog = new AggregateCatalog(new AssemblyCatalog(typeof(MefModuleInitializer).Assembly));
            var compositionContainer = new CompositionContainer(aggregateCatalog);
            compositionContainer.ComposeExportedValue(aggregateCatalog);

            var serviceLocatorMock = new Mock<IServiceLocator>();
            var loggerFacadeMock = new Mock<ILoggerFacade>();

            var serviceLocator = serviceLocatorMock.Object;
            var loggerFacade = loggerFacadeMock.Object;

            compositionContainer.ComposeExportedValue(serviceLocator);
            compositionContainer.ComposeExportedValue(loggerFacade);

            aggregateCatalog.Catalogs.Add(new TypeCatalog(typeof(TestModuleForInitializer)));

            var moduleInitializer = compositionContainer.GetExportedValue<IModuleInitializer>();

            var moduleInfo = new ModuleInfo("TestModuleForInitializer", typeof(TestModuleForInitializer).AssemblyQualifiedName);

            var module = compositionContainer.GetExportedValues<IModule>().OfType<TestModuleForInitializer>().First();

            Assert.IsFalse(module.Initialized);

            moduleInitializer.Initialize(moduleInfo);

            Assert.IsTrue(module.Initialized);
        }
Exemplo n.º 20
0
        public void StateCapturesTheCurrentState()
        {
            var container =
                new CompositionContainer(
                    new AggregateCatalog(
                        new AssemblyCatalog(typeof(ICurrentState<>).Assembly),
                        new TypeCatalog(typeof(TestCurrentState), typeof(TestState))));

            var currentState = container.GetExportedValue<ICurrentState<string>>();

            currentState.Value = "value";

            var state = container.GetExportedValue<IState<string>>();

            Assert.AreEqual("value", state.Value);
        }
Exemplo n.º 21
0
        private void txtMo_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == '\r')
            {
                using (CompositionContainer container = new CompositionContainer(Program.programCatalog))
                {                   
                    OperationResult operationResult = container.GetExportedValue<IFrmGoodNgService>().FindSnCheck(tetMo.Text);
                    if (operationResult.ResultType == OperationResultType.Success)
                    {
                        if (operationResult.AppendData != null)
                        {                            
                            txtLength.Text = ((Item2SnCheck)operationResult.AppendData).SNLENGTH == null ? null : ((Item2SnCheck)operationResult.AppendData).SNLENGTH.ToString();
                            txtPrefix.Text = ((Item2SnCheck)operationResult.AppendData).SNPREFIX;
                            if (txtLength.Text.Length==0)
                                txtLength.Enabled = true;
                            if (txtPrefix.Text.Length==0)
                                txtPrefix.Enabled = true;
                        }

                    }
                    else
                        richTextBox1.AppendText("\n" + operationResult.Message);                    
                }  
            }
            

        }
Exemplo n.º 22
0
        public void GetValuesByType()
        {
            var cat = CatalogFactory.CreateDefaultAttributed();

            var container = new CompositionContainer(cat);

            string itestName = AttributedModelServices.GetContractName(typeof(ITest));

            var e1 = container.GetExportedValues<ITest>();
            var e2 = container.GetExports<ITest, object>(itestName);

            Assert.IsInstanceOfType(e1.First(), typeof(T1), "First should be T1");
            Assert.IsInstanceOfType(e1.Skip(1).First(), typeof(T2), "Second should be T2");

            Assert.IsInstanceOfType(e2.First().Value, typeof(T1), "First should be T1");
            Assert.IsInstanceOfType(e2.Skip(1).First().Value, typeof(T2), "Second should be T2");

            CompositionContainer childContainer = new CompositionContainer(container);
            CompositionBatch batch = new CompositionBatch();
            batch.AddPart(new T1());
            container.Compose(batch);
            var t1 = childContainer.GetExportedValue<ITest>();
            var t2 = childContainer.GetExport<ITest, object>(itestName);

            Assert.IsInstanceOfType(t1, typeof(T1), "First (resolved) should be T1");
            Assert.IsInstanceOfType(t2.Value, typeof(T1), "First (resolved) should be T1");
        }
Exemplo n.º 23
0
        private static IRun CreateRun()
        {
            ThreadPool.SetMinThreads(32, 32);

            var args = ParseArguments();

            var compositionContainer = new CompositionContainer(new AssemblyCatalog(typeof(Program).Assembly));

            compositionContainer.ComposeExportedValue(new RunData
            {
                SampleRate = args.SampleRate,
                Warmup = args.Warmup,
                Duration = args.Duration,
                Connections = args.Connections,
                Payload = GetPayload(args.PayloadSize),
                Senders = args.Senders,
                Transport = args.Transport,
                Host = args.Host,
                Url = args.Url,
                SendDelay = args.SendDelay,

                // Scaleout
                RedisServer = args.RedisServer,
                RedisPort = args.RedisPort,
                RedisPassword = args.RedisPassword,
                ServiceBusConnectionString = args.ServiceBusConnectionString,
                SqlConnectionString = args.SqlConnectionString,
                SqlTableCount = args.SqlTableCount,
            });

            return compositionContainer.GetExportedValue<IRun>(args.RunName);
        }
        public void ActionNg()
        {
            var catalog = new AggregateCatalog();
            catalog.Catalogs.Add(new DirectoryCatalog(Directory.GetCurrentDirectory()));
            catalog.Catalogs.Add(new AssemblyCatalog(Assembly.GetExecutingAssembly()));
            const string mocode = "mocode1";
            const string usercode = "usercode1";
            const string card = "20141107005";
            const string rescode = "rescode1";
            const string rescode2 = "rescode2";
            const string leng = "11";
            const string prefix = "2014";
            const string ecg = "AUTONG";
            const string ec = "AUTONG";
            
            
            using (var testContainer = new CompositionContainer(catalog))
            {
                testContainer.GetExportedValue<IFrmGoodNgService>().CardGoMo(mocode, leng, prefix, card, rescode, usercode);

            }
            using (var testContainer = new CompositionContainer(catalog))
            {
                OperationResult operationResult = testContainer.GetExportedValue<IFrmGoodNgService>().ActionNg(card, usercode, rescode2, ecg, ec);
                Assert.IsTrue(operationResult.Message.Equals(card +Properties.Resources.String_FrmGoodNGService_CollectSuccess));
            }

        }
Exemplo n.º 25
0
        public void When_removing_a_part_from_the_intercepted_catalog_intercepting_catalog_is_recomposed_and_removes_that_part()
        {
            var innerCatalog1 = new TypeCatalog(typeof(RecomposablePart1), typeof(RecomposablePartImporter));
            var innerCatalog2 = new TypeCatalog(typeof(RecomposablePart2));
            var cfg = new InterceptionConfiguration().AddInterceptor(new RecomposablePartInterceptor());
            var aggregateCatalog = new AggregateCatalog(innerCatalog1, innerCatalog2);
            var catalog = new InterceptingCatalog(aggregateCatalog, cfg);
            container = new CompositionContainer(catalog);

            var importer = container.GetExportedValue<RecomposablePartImporter>();
            Assert.That(importer, Is.Not.Null);
            Assert.That(importer.Parts, Is.Not.Null);
            Assert.That(importer.Parts.Length, Is.EqualTo(2));
            Assert.That(importer.Parts[0].Count, Is.EqualTo(1));
            Assert.That(importer.Parts[1].Count, Is.EqualTo(1));
            Assert.That(catalog.Parts.Count(), Is.EqualTo(3));

            // Recompose
            aggregateCatalog.Catalogs.Remove(innerCatalog2);

            Assert.That(importer, Is.Not.Null);
            Assert.That(importer.Parts, Is.Not.Null);
            Assert.That(importer.Parts.Length, Is.EqualTo(1));
            Assert.That(importer.Parts[0].Count, Is.EqualTo(1));
            Assert.That(catalog.Parts.Count(), Is.EqualTo(2));
        }
Exemplo n.º 26
0
        public void CanImportSampleData()
        {
            // Arrange
            string httpClientFactoryContract = AttributedModelServices.GetContractName(typeof(IHttpClientFactory));
            string routeServiceFactoryContract = AttributedModelServices.GetContractName(typeof(IRouteServiceFactory));

            using (ApplicationCatalog initialCatalog = Program.BuildCompositionCatalog())
            using (FilteredCatalog filteredCatalog = initialCatalog.Filter(d => !d.Exports(httpClientFactoryContract) && !d.Exports(routeServiceFactoryContract)))
            using (TypeCatalog httpClientFactoryCatalog = new TypeCatalog(typeof(WtaResultFromEmbeddedResourceFactory)))
            using (TypeCatalog routeServiceFactoryCatalog = new TypeCatalog(typeof(RouteServiceFromCalculatedDistanceFactory)))
            using (AggregateCatalog aggregateCatalog = new AggregateCatalog(filteredCatalog, httpClientFactoryCatalog, routeServiceFactoryCatalog))
            using (CompositionContainer container = new CompositionContainer(aggregateCatalog))
            {
                // Act
                ITrailsImporter importer = container.GetExportedValue<ITrailsImporter>();
                importer.Run();
            }

            using (MyTrailsContext context = new MyTrailsContext())
            {
                // Assert
                ImportLogEntry logEntry = context.ImportLog
                    .OrderByDescending(le => le.Id)
                    .FirstOrDefault();

                Assert.IsNotNull(logEntry);
                Assert.IsNull(logEntry.ErrorString, message: logEntry.ErrorString);
                Assert.AreEqual(0, logEntry.ErrorsCount);

                Assert.IsTrue(context.Trails.Any());
                Assert.IsTrue(context.Guidebooks.Any());
                Assert.IsTrue(context.Passes.Any());
                Assert.IsTrue(context.TripReports.Any());
            }
        }
Exemplo n.º 27
0
        public void Run()
        {
            PermissionPrincipal permissionsPrincipal = new PermissionPrincipal();
            AppDomain.CurrentDomain.SetThreadPrincipal(permissionsPrincipal);

            if (Assembly.GetCallingAssembly().GetName().Name != ServiceAssemblyName)
            {
                throw new Exception(Core.UI.Properties.Resources.ErrorMustBeLoadedFromService);
            }
            var catalog = new AggregateCatalog();
            catalog.Catalogs.Add(new DirectoryCatalog(@"..\..\..\TixCRM.TestModule\bin\Debug"));
            catalog.Catalogs.Add(new AssemblyCatalog(Assembly.GetAssembly(typeof(MainWindow))));
            catalog.Catalogs.Add(new DirectoryCatalog(@"..\..\..\TixCRM.Core.Services\bin\Debug"));
            catalog.Catalogs.Add(new DirectoryCatalog(@"..\..\..\TixCRM.Core.Data\bin\Debug"));
            var container = new CompositionContainer(catalog);
            container.ComposeParts(this);

            foreach (var module in modules)
            {
                if (CheckModule(module))
                {
                    module.Init(menuServiceFactory.CreateMenuService(),
                        container.GetExportedValues<ITixViewModel>().Single(x => x.TixViewModelName == module.ViewModelName),
                        container.GetExportedValues<ITixView>().Single(x => x.TixViewName == module.ViewName), mRegistery);
                }
                else
                {
                    throw new ModuleLoadException(String.Format(Core.UI.Properties.Resources.ErrorCouldNotLoadModule, module.DisplayName));
                }

            }

            App.Start(container.GetExportedValue<ITixViewModel>("TixCRM.Core.UI.MainViewModel"));
        }
Exemplo n.º 28
0
 private void txtRuningCard_KeyPress(object sender, KeyPressEventArgs e)
 {
     if (e.KeyChar == '\r')
     {
         if (tetMo.Text.Length != 0)
         {
             using (CompositionContainer testContainer = new CompositionContainer(Program.programCatalog))
             {
                 OperationResult operationResult = testContainer.GetExportedValue<IFrmGoodNgService>().CardGoMo(tetMo.Text, txtLength.Text, txtPrefix.Text,txtRuningCard.Text , Program.rescode, Program.usercode);
                 richTextBox1.AppendText(operationResult.Message+"\n");
             }
         }
         else
         {
             if (radioButtonGood.Checked)
                 using (CompositionContainer testContainer = new CompositionContainer(Program.programCatalog))
                 {
                     OperationResult operationResult = testContainer.GetExportedValue<IFrmGoodNgService>().ActionGood(Program.usercode, Program.rescode, txtRuningCard.Text);
                     richTextBox1.AppendText(operationResult.Message + "\n");
                 }
             else
                 using (CompositionContainer testContainer = new CompositionContainer(Program.programCatalog))
                 {
                     OperationResult operationResult = testContainer.GetExportedValue<IFrmGoodNgService>().ActionNg( txtRuningCard.Text,Program.usercode, Program.rescode,"AUTONG","AUTONG");
                     richTextBox1.AppendText(operationResult.Message + "\n");
                 }                        ;
         }
     } 
 }
Exemplo n.º 29
0
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            #if (DEBUG != true)
            // Don't handle the exceptions in Debug mode because otherwise the Debugger wouldn't
            // jump into the code when an exception occurs.
            DispatcherUnhandledException += AppDispatcherUnhandledException;
            AppDomain.CurrentDomain.UnhandledException += AppDomainUnhandledException;
            #endif

            AggregateCatalog catalog = new AggregateCatalog();
            // Add the WpfApplicationFramework assembly to the catalog
            catalog.Catalogs.Add(new AssemblyCatalog(typeof(Controller).Assembly));
            // Add the Waf.BookLibrary.Library.Presentation assembly to the catalog
            catalog.Catalogs.Add(new AssemblyCatalog(Assembly.GetExecutingAssembly()));
            // Add the Waf.BookLibrary.Library.Applications assembly to the catalog
            catalog.Catalogs.Add(new AssemblyCatalog(typeof(ShellViewModel).Assembly));

            this.container = new CompositionContainer(catalog);
            CompositionBatch batch = new CompositionBatch();
            batch.AddExportedValue(container);
            this.container.Compose(batch);

            this.applicationController = container.GetExportedValue<IApplicationController>();
            this.applicationController.Initialize();
            this.applicationController.Run();
        }
Exemplo n.º 30
0
 private void App_OnStartup(object sender, StartupEventArgs e)
 {
     var catalog = new AssemblyCatalog(Assembly.GetExecutingAssembly());
     var container = new CompositionContainer(catalog);
     var mainWindow = container.GetExportedValue<MainWindow>();
     mainWindow.Show();
 }