當前位置: 首頁>>代碼示例>>C#>>正文


C# Modularity.ModuleInfo類代碼示例

本文整理匯總了C#中Prism.Modularity.ModuleInfo的典型用法代碼示例。如果您正苦於以下問題:C# ModuleInfo類的具體用法?C# ModuleInfo怎麽用?C# ModuleInfo使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ModuleInfo類屬於Prism.Modularity命名空間,在下文中一共展示了ModuleInfo類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: CanRetrieveWithCorrectRef

        public void CanRetrieveWithCorrectRef()
        {
            var retriever = new FileModuleTypeLoader();
            var moduleInfo = new ModuleInfo() { Ref = "file://somefile" };

            Assert.IsTrue(retriever.CanLoadModuleType(moduleInfo));
        }
開發者ID:ValdimarThor,項目名稱:Prism,代碼行數:7,代碼來源:FileModuleTypeLoaderFixture.Desktop.cs

示例2: EnsureModulesDiscovered

        private void EnsureModulesDiscovered()
        {
            ModulesConfigurationSection section = this.Store.RetrieveModuleConfigurationSection();

            if (section != null)
            {
                foreach (ModuleConfigurationElement element in section.Modules)
                {
                    IList<string> dependencies = new List<string>();

                    if (element.Dependencies.Count > 0)
                    {
                        foreach (ModuleDependencyConfigurationElement dependency in element.Dependencies)
                        {
                            dependencies.Add(dependency.ModuleName);
                        }
                    }

                    ModuleInfo moduleInfo = new ModuleInfo(element.ModuleName, element.ModuleType)
                    {
                        Ref = GetFileAbsoluteUri(element.AssemblyFile),
                        InitializationMode = element.StartupLoaded ? InitializationMode.WhenAvailable : InitializationMode.OnDemand
                    };
                    moduleInfo.DependsOn.AddRange(dependencies.ToArray());
                    AddModule(moduleInfo);
                }
            }
        }
開發者ID:Citringo,項目名稱:Prism,代碼行數:28,代碼來源:ConfigurationModuleCatalog.Desktop.cs

示例3: CanLoadModuleType

        /// <summary>
        /// Evaluates the <see cref="ModuleInfo.Ref"/> property to see if the current typeloader will be able to retrieve the <paramref name="moduleInfo"/>.
        /// Returns true if the <see cref="ModuleInfo.Ref"/> property starts with "file://", because this indicates that the file
        /// is a local file.
        /// </summary>
        /// <param name="moduleInfo">Module that should have it's type loaded.</param>
        /// <returns>
        ///     <see langword="true"/> if the current typeloader is able to retrieve the module, otherwise <see langword="false"/>.
        /// </returns>
        public virtual bool CanLoadModuleType(ModuleInfo moduleInfo)
        {
            if (moduleInfo == null)
                throw new ArgumentNullException(nameof(moduleInfo));

            return moduleInfo.Ref != null && moduleInfo.Ref.StartsWith(RefFilePrefix, StringComparison.Ordinal);
        }
開發者ID:Citringo,項目名稱:Prism,代碼行數:16,代碼來源:MefFileModuleTypeLoader.Desktop.cs

示例4: CannotRetrieveWithIncorrectRef

        public void CannotRetrieveWithIncorrectRef()
        {
            var retriever = new FileModuleTypeLoader();
            var moduleInfo = new ModuleInfo() { Ref = "NotForLocalRetrieval" };

            Assert.IsFalse(retriever.CanLoadModuleType(moduleInfo));
        }
開發者ID:ValdimarThor,項目名稱:Prism,代碼行數:7,代碼來源:FileModuleTypeLoaderFixture.Desktop.cs

示例5: WhenInitializingAModuleWithACatalogPendingToBeLoaded_ThenLoadsTheCatalogInitializesTheModule

        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);
        }
開發者ID:Citringo,項目名稱:Prism,代碼行數:31,代碼來源:MefModuleInitializerFixture.cs

示例6: CreateModule

        /// <summary>
        /// Uses the container to resolve a new <see cref="IModule"/> by specifying its <see cref="Type"/>.
        /// </summary>
        /// <param name="moduleInfo">The module to create.</param>
        /// <returns>
        /// A new instance of the module specified by <paramref name="moduleInfo"/>.
        /// </returns>
        protected override IModule CreateModule(ModuleInfo moduleInfo)
        {
            // If there is a catalog that needs to be integrated with the AggregateCatalog as part of initialization, I add it to the container's catalog.
            ComposablePartCatalog partCatalog;
            if (this.downloadedPartCatalogs.TryGet(moduleInfo, out partCatalog))
            {
                if (!this.aggregateCatalog.Catalogs.Contains(partCatalog))
                {
                    this.aggregateCatalog.Catalogs.Add(partCatalog);
                }

                this.downloadedPartCatalogs.Remove(moduleInfo);
            }

            if (this.ImportedModules != null && this.ImportedModules.Count() != 0)
            {
                Lazy<IModule, IModuleExport> lazyModule =
                    this.ImportedModules.FirstOrDefault(x => (x.Metadata.ModuleName == moduleInfo.ModuleName));
                if (lazyModule != null)
                {
                    return lazyModule.Value;
                }
            }

            // This does not fall back to the base implementation because the type must be in the MEF container and not just in the application domain.
            throw new ModuleInitializeException(
                string.Format(CultureInfo.CurrentCulture, Properties.Resources.FailedToGetType, moduleInfo.ModuleType));
        }
開發者ID:Citringo,項目名稱:Prism,代碼行數:35,代碼來源:MefModuleInitializer.cs

示例7: WhenItemsInCollection_TryGetReturnsTrueAndCatalog

        public void WhenItemsInCollection_TryGetReturnsTrueAndCatalog()
        {
            // Prepare
            ModuleInfo moduleInfo1 = new ModuleInfo();
            ModuleInfo moduleInfo2 = new ModuleInfo();
            ModuleInfo moduleInfo3 = new ModuleInfo();

            ComposablePartCatalog catalog1 = new TypeCatalog();
            ComposablePartCatalog catalog2 = new TypeCatalog();
            ComposablePartCatalog catalog3 = new TypeCatalog();

            DownloadedPartCatalogCollection target = new DownloadedPartCatalogCollection();

            target.Add(moduleInfo1, catalog1);
            target.Add(moduleInfo2, catalog2);
            target.Add(moduleInfo3, catalog3);

            // Act
            bool actual = target.TryGet(moduleInfo3, out catalog3);    
        
            // Verify
            Assert.IsTrue(actual);
            Assert.AreSame(catalog3, target.Get(moduleInfo3));
            
        }
開發者ID:Citringo,項目名稱:Prism,代碼行數:25,代碼來源:DownloadedPartCatalogCollectionFixture.cs

示例8: HandleModuleInitializationError

        /// <summary>
        /// Handles any exception occurred in the module Initialization process,
        /// logs the error using the <see cref="ILoggerFacade"/> and throws a <see cref="ModuleInitializeException"/>.
        /// This method can be overridden to provide a different behavior. 
        /// </summary>
        /// <param name="moduleInfo">The module metadata where the error happenened.</param>
        /// <param name="assemblyName">The assembly name.</param>
        /// <param name="exception">The exception thrown that is the cause of the current error.</param>
        /// <exception cref="ModuleInitializeException"></exception>
        public virtual void HandleModuleInitializationError(ModuleInfo moduleInfo, string assemblyName, Exception exception)
        {
            if (moduleInfo == null) throw new ArgumentNullException("moduleInfo");
            if (exception == null) throw new ArgumentNullException("exception");

            Exception moduleException;

            if (exception is ModuleInitializeException)
            {
                moduleException = exception;
            }
            else
            {
                if (!string.IsNullOrEmpty(assemblyName))
                {
                    moduleException = new ModuleInitializeException(moduleInfo.ModuleName, assemblyName, exception.Message, exception);
                }
                else
                {
                    moduleException = new ModuleInitializeException(moduleInfo.ModuleName, exception.Message, exception);
                }
            }

            this.loggerFacade.Log(moduleException.ToString(), Category.Exception, Priority.High);

            throw moduleException;
        }
開發者ID:dl0618,項目名稱:Prism,代碼行數:36,代碼來源:ModuleInitializer.cs

示例9: WhenInitializingAModuleWithNoCatalogPendingToBeLoaded_ThenInitializesTheModule

        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);
        }
開發者ID:Citringo,項目名稱:Prism,代碼行數:29,代碼來源:MefModuleInitializerFixture.cs

示例10: CreateModuleInfo

        public ModuleInfo CreateModuleInfo()
        {
            ModuleInfo info = new ModuleInfo();
            info.ModuleName = "MefModuleOne";
            info.Ref = "file:///MefModulesForTesting.dll";

            return info;
        }
開發者ID:ValdimarThor,項目名稱:Prism,代碼行數:8,代碼來源:MefFileModuleTypeLoaderFixture.Desktop.cs

示例11: CanLoadModuleType

        /// <summary>
        /// Evaluates the <see cref="ModuleInfo.Ref"/> property to see if the current typeloader will be able to retrieve the <paramref name="moduleInfo"/>.
        /// Returns true if the <see cref="ModuleInfo.Ref"/> property starts with "file://", because this indicates that the file
        /// is a local file. 
        /// </summary>
        /// <param name="moduleInfo">Module that should have it's type loaded.</param>
        /// <returns>
        /// 	<see langword="true"/> if the current typeloader is able to retrieve the module, otherwise <see langword="false"/>.
        /// </returns>
        /// <exception cref="ArgumentNullException">An <see cref="ArgumentNullException"/> is thrown if <paramref name="moduleInfo"/> is null.</exception>
        public bool CanLoadModuleType(ModuleInfo moduleInfo)
        {
            if (moduleInfo == null)
            {
                throw new System.ArgumentNullException("moduleInfo");
            }

            return moduleInfo.Ref != null && moduleInfo.Ref.StartsWith(RefFilePrefix, StringComparison.Ordinal);
        }
開發者ID:ValdimarThor,項目名稱:Prism,代碼行數:19,代碼來源:FileModuleTypeLoader.Desktop.cs

示例12: CanCreateCatalogFromList

        public void CanCreateCatalogFromList()
        {
            var moduleInfo = new ModuleInfo("MockModule", "type");
            List<ModuleInfo> moduleInfos = new List<ModuleInfo> { moduleInfo };

            var moduleCatalog = new ModuleCatalog(moduleInfos);

            Assert.AreEqual(1, moduleCatalog.Modules.Count());
            Assert.AreEqual(moduleInfo, moduleCatalog.Modules.ElementAt(0));
        }
開發者ID:Citringo,項目名稱:Prism,代碼行數:10,代碼來源:ModuleCatalogFixture.cs

示例13: LoadModuleCompletedEventArgs

        /// <summary>
        /// Initializes a new instance of the <see cref="LoadModuleCompletedEventArgs"/> class.
        /// </summary>
        /// <param name="moduleInfo">The module info.</param>
        /// <param name="error">Any error that occurred during the call.</param>
        public LoadModuleCompletedEventArgs(ModuleInfo moduleInfo, Exception error)
        {
            if (moduleInfo == null)
            {
                throw new ArgumentNullException("moduleInfo");
            }

            this.ModuleInfo = moduleInfo;
            this.Error = error;
        }
開發者ID:dl0618,項目名稱:Prism,代碼行數:15,代碼來源:LoadModuleCompletedEventArgs.cs

示例14: ModuleDownloadProgressChangedEventArgs

        /// <summary>
        /// Initializes a new instance of the <see cref="ModuleDownloadProgressChangedEventArgs"/> class.
        /// </summary>
        /// <param name="moduleInfo">The module info.</param>
        /// <param name="bytesReceived">The bytes received.</param>
        /// <param name="totalBytesToReceive">The total bytes to receive.</param>
        public ModuleDownloadProgressChangedEventArgs(ModuleInfo moduleInfo, long bytesReceived, long totalBytesToReceive)
            : base(CalculateProgressPercentage(bytesReceived, totalBytesToReceive), null)
        {
            if (moduleInfo == null)
                throw new ArgumentNullException(nameof(moduleInfo));

            this.ModuleInfo = moduleInfo;
            this.BytesReceived = bytesReceived;
            this.TotalBytesToReceive = totalBytesToReceive;
        }
開發者ID:Citringo,項目名稱:Prism,代碼行數:16,代碼來源:ModuleDownloadProgressChangedEventArgs.cs

示例15: LoadModuleType

        /// <summary>
        /// Retrieves the <paramref name="moduleInfo"/>.
        /// </summary>
        /// <param name="moduleInfo">Module that should have it's type loaded.</param>
        public virtual void LoadModuleType(ModuleInfo moduleInfo)
        {
            if (moduleInfo == null)
            {
                throw new System.ArgumentNullException("moduleInfo");
            }

            try
            {
                Uri uri = new Uri(moduleInfo.Ref, UriKind.RelativeOrAbsolute);

                // If this module has already been downloaded, I fire the completed event.
                if (this.IsSuccessfullyDownloaded(uri))
                {
                    this.RaiseLoadModuleCompleted(moduleInfo, null);
                }
                else
                {
                    string path;

                    if (moduleInfo.Ref.StartsWith(RefFilePrefix + "/", StringComparison.Ordinal))
                    {
                        path = moduleInfo.Ref.Substring(RefFilePrefix.Length + 1);
                    }
                    else
                    {
                        path = moduleInfo.Ref.Substring(RefFilePrefix.Length);
                    }

                    long fileSize = -1L;
                    if (File.Exists(path))
                    {
                        FileInfo fileInfo = new FileInfo(path);
                        fileSize = fileInfo.Length;
                    }

                    // Although this isn't asynchronous, nor expected to take very long, I raise progress changed for consistency.
                    this.RaiseModuleDownloadProgressChanged(moduleInfo, 0, fileSize);

                    this.aggregateCatalog.Catalogs.Add(new AssemblyCatalog(path));

                    // Although this isn't asynchronous, nor expected to take very long, I raise progress changed for consistency.
                    this.RaiseModuleDownloadProgressChanged(moduleInfo, fileSize, fileSize);

                    // I remember the downloaded URI.
                    this.RecordDownloadSuccess(uri);

                    this.RaiseLoadModuleCompleted(moduleInfo, null);
                }
            }
            catch (Exception ex)
            {
                this.RaiseLoadModuleCompleted(moduleInfo, ex);
            }
        }
開發者ID:dl0618,項目名稱:Prism,代碼行數:59,代碼來源:MefFileModuleTypeLoader.Desktop.cs


注:本文中的Prism.Modularity.ModuleInfo類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。