当前位置: 首页>>代码示例>>C#>>正文


C# AtomicComposition类代码示例

本文整理汇总了C#中AtomicComposition的典型用法代码示例。如果您正苦于以下问题:C# AtomicComposition类的具体用法?C# AtomicComposition怎么用?C# AtomicComposition使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


AtomicComposition类属于命名空间,在下文中一共展示了AtomicComposition类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetExportsCore

        /// <summary>
        /// Gets the available set of exports for the given import definition.
        /// </summary>
        /// <param name="definition">The defintion of the import.</param>
        /// <param name="atomicComposition">The atomic composition of the import.</param>
        /// <returns>The available set of exports for the given import definition.</returns>
        protected override IEnumerable<Export> GetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition)
        {
            Throw.IfArgumentNull(definition, "definition");
            if (SourceProvider == null)
                Throw.InvalidOperation(
                    string.Format(
                        CultureInfo.CurrentUICulture,
                        Resources.Exceptions.PropertyCannotBeNull,
                        "Sourceprovider"));

            var contractDefinition = definition as ContractBasedImportDefinition;
            if (contractDefinition == null
                || !contractDefinition.RequiredTypeIdentity.StartsWith(PartFactoryContractPrefix))
                return EmptyExports;

            var info = _definitionCache.Fetch(contractDefinition, () => new PartFactoryImport(contractDefinition));

            var exports = SourceProvider.GetExports(info.ImportDefinition, atomicComposition);
            var result = exports
                .Select(e => info.CreateMatchingExport(e.Definition, SourceProvider))
                .ToArray();

            foreach (var export in exports.OfType<IDisposable>())
                export.Dispose();

            return result;
        }
开发者ID:jd-pantheon,项目名称:Titan-Framework-v2,代码行数:33,代码来源:DynamicInstantiationExportProvider.cs

示例2: NetworkAvailabilityChanged

        private void NetworkAvailabilityChanged(object sender, NetworkAvailabilityEventArgs e)
        {
            // We invoke on the dispatcher because we are needing to recompose UI.
            // If we don't do this, an exception will be thrown as the composition isn't
            // guaranteed to happen on the necesary UI thread.
            Dispatcher.CurrentDispatcher.Invoke(new Action(() =>
            {
                var oldStatus = _networkStatus;
                var newStatus = (e.IsAvailable) ? "Online" : "Offline";

                var added = MatchingParts(newStatus);
                var removed = NonMatchingParts(newStatus);

                using (var atomic = new AtomicComposition())
                {
                    atomic.AddCompleteAction(() => _networkStatus = newStatus);
                    if (Changing != null)
                    {
                        Changing(this, new ComposablePartCatalogChangeEventArgs(added, removed, atomic));
                    }
                    atomic.Complete();
                }

                if (Changed != null)
                {
                    Changed(this, new ComposablePartCatalogChangeEventArgs(added, removed, null));
                }
            }));
        }
开发者ID:Helen1987,项目名称:edu,代码行数:29,代码来源:NetworkAwareCatalog.cs

示例3: GetExportsCore

        protected override IEnumerable<Export> GetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition)
        {
            if (definition.Cardinality != ImportCardinality.ExactlyOne)
            {
                return Enumerable.Empty<Export>();
            }

            ExportSource exportSource;
            if (_exactlyOneExports.TryGetValue(definition.ContractName, out exportSource))
            {
                AddMemberType(exportSource, definition);
                return new[] { exportSource.Export };
            }

            string typeName = ImportDefinitionConstraintAnalyser.GetRequiredTypeIdentity(definition.Constraint);
            Type type = GetType(typeName);
            if (!CanHandleType(type))
            {
                return Enumerable.Empty<Export>();
            }

            exportSource = new ExportSource(definition.ContractName, definition.Metadata);
            exportSource.AddType(type);
            AddMemberType(exportSource, definition);

            _exactlyOneExports[definition.ContractName] = exportSource;
            return new[] { exportSource.Export };
        }
开发者ID:AlexanderSher,项目名称:RTVS-Old,代码行数:28,代码来源:NSubstituteExportProvider.cs

示例4: GetExportsCore

        protected override IEnumerable<Export> GetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition)
        {
            if (definition == null) throw new ArgumentNullException("definition");
            if (SourceProvider == null) throw new InvalidOperationException("SourceProvider must be set.");

            var cbid = definition as ContractBasedImportDefinition;

            if (cbid == null || !cbid.RequiredTypeIdentity.StartsWith(PartCreatorContractPrefix))
                return EmptyExports;

            var importInfo = _importDefinitionCache.GetOrCreate(
                cbid,
                () => new ExportFactoryImport(cbid));

            var sourceExports = SourceProvider
                .GetExports(importInfo.ProductImport, atomicComposition);

            var result = sourceExports
                .Select(e => importInfo.CreateMatchingExport(e.Definition, SourceProvider))
                .ToArray();

            foreach (var e in sourceExports.OfType<IDisposable>())
                e.Dispose();

            return result;
        }
开发者ID:DamianReeves,项目名称:PostEdge,代码行数:26,代码来源:ExportFactoryInstantiationProvider.cs

示例5: GetExportsCore

		protected override IEnumerable<Export> GetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition)
		{
			var serviceTypeName = definition.ContractName;
			if (serviceTypeName.IndexOf('.') == -1 ||
				serviceTypeName.StartsWith("System.") ||
				serviceTypeName.StartsWith("Clide."))
				return Enumerable.Empty<Export>();

			return serviceExports.GetOrAdd (serviceTypeName, contractName => {
				var serviceType = typeMap.GetOrAdd(contractName, typeName => MapType(typeName));
				if (serviceType == null)
					return Enumerable.Empty<Export>();

				// NOTE: if we can retrieve a valid instance of the service at least once, we 
				// assume we'll be able to retrieve it later on. Note also that we don't return 
				// the single retrieved instance from the export, but rather provide a function 
				// that does the GetService call every time, since we're caching the export but 
				// we don't know if the service can be safely cached.
				var service = services.GetService(serviceType);
				if (service == null)
					return Enumerable.Empty<Export>();

				return new Export[] { new Export(serviceTypeName, () => services.GetService(serviceType)) };
			});
		}
开发者ID:MobileEssentials,项目名称:clide,代码行数:25,代码来源:ServicesExportProvider.cs

示例6: GetExportsCore

            protected override IEnumerable<Export> GetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition)
            {
                List<Export> exports = new List<Export>();

                ImportDefinition queryImport = TranslateImport(definition);
                if (queryImport == null)
                {
                    return exports;
                }

                // go through the catalogs and see if there's anything there of interest
                foreach (CompositionScopeDefinition childCatalog in this._scopeDefinition.Children)
                {
                    foreach (var partDefinitionAndExportDefinition in childCatalog.GetExportsFromPublicSurface(queryImport))
                    {
                        using (var container = this.CreateChildContainer(childCatalog))
                        {
                            // We create a nested AtomicComposition() because the container will be Disposed and 
                            // the RevertActions need to operate before we Dispose the child container
                            using (var ac = new AtomicComposition(atomicComposition))
                            {
                                var childCatalogExportProvider = container.CatalogExportProvider;
                                if (!childCatalogExportProvider.DetermineRejection(partDefinitionAndExportDefinition.Item1, ac))
                                {
                                    exports.Add(this.CreateScopeExport(childCatalog, partDefinitionAndExportDefinition.Item1, partDefinitionAndExportDefinition.Item2));
                                }
                            }
                        }
                    }
                }

                return exports;
            }
开发者ID:nlhepler,项目名称:mono,代码行数:33,代码来源:CatalogExportProvider.ScopeManager.cs

示例7: GetExportsCore

        protected override IEnumerable<Export> GetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition)
        {
            var contractName = definition.ContractName;

            if (contractName != SettingsConstants.SettingsContract)
                yield break;

            if (definition.Cardinality == ImportCardinality.ZeroOrMore)
                yield break;

            // TODO can't figure out how to get data injected into the Metadata collection
            //string settingsKey = definition.Metadata[SettingsConstants.SettingsMetadataKey] as string;

            LazyMemberInfo lazyMember = ReflectionModelServices.GetImportingMember(definition);
            MemberInfo member = lazyMember.GetAccessors().First();

            MethodInfo getterOrSetter = (MethodInfo)member;
            
            // HACK this is pretty evil
            PropertyInfo propInfo = getterOrSetter.DeclaringType.GetProperty(getterOrSetter.Name.Substring(4));

            ImportSettingAttribute settingsAttr = propInfo.GetCustomAttribute<ImportSettingAttribute>();

            if (settingsAttr == null)
                yield break;

            object value;
            if (!this._settingsProvider.TryGetValue(settingsAttr.SettingsKey, out value))
                yield break;

            yield return new Export(SettingsConstants.SettingsContract, () => value);
        }
开发者ID:LBiNetherlands,项目名称:LBi.LostDoc,代码行数:32,代码来源:SettingsExportProvider.cs

示例8: Recompose

        private void Recompose(IEnumerable<ComposablePartDefinition> added, IEnumerable<ComposablePartDefinition> removed, AtomicComposition outerComposition)
        {
            EnsurePartsInitialized();

            var addedInnerPartDefinitions = added.Select(GetPart);
            var removedInnerPartDefinitions = removed.Select(def => innerParts[def]);

            using (var composition = new AtomicComposition(outerComposition))
            {
                var addedDefinitions = addedInnerPartDefinitions.Select(p => p.Definition).ToList();
                var removedDefinitions = removedInnerPartDefinitions.Select(p => p.Definition).ToList();

                composition.AddCompleteAction(() => OnChanged(
                    addedDefinitions,
                    removedDefinitions,
                    null));

                OnChanging(
                    addedDefinitions,
                    removedDefinitions,
                    composition);

                foreach (var innerPart in addedInnerPartDefinitions)
                {
                    innerParts.Add(innerPart.Original, innerPart);
                }

                foreach (var removedDefinition in removedInnerPartDefinitions)
                {
                    innerParts.Remove(removedDefinition.Original);
                }

                composition.Complete();
            }
        }
开发者ID:doublekill,项目名称:MefContrib,代码行数:35,代码来源:InterceptingCatalog.cs

示例9: GetExportsCore

        protected override System.Collections.Generic.IEnumerable<Export> GetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition)
        {
            var type = Type.GetType(definition.ContractName);
            Export e;
            var exports = base.GetExportsCore(definition, atomicComposition);

            return exports;
        }
开发者ID:petriw,项目名称:Balder,代码行数:8,代码来源:Container.cs

示例10: GetExportsCore

 protected override IEnumerable<Export> GetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition)
 {
     if (definition.ContractName == _textUndoHistoryRegistryContractName ||
         definition.ContractName == _basicUndoHistoryRegistryContractName)
     {
         yield return _export;
     }
 }
开发者ID:jaredpar,项目名称:EditorUtils,代码行数:8,代码来源:EditorHostFactory.UndoExportProvider.cs

示例11: Constructor2

        public void Constructor2()
        {
            // Null should be allowed
            var ct = new AtomicComposition(null);

            // Another AtomicComposition should be allowed
            var ct2 = new AtomicComposition(ct);
        }
开发者ID:nlhepler,项目名称:mono,代码行数:8,代码来源:CompositionTransactionTests.cs

示例12: GetExportsCore

        protected override IEnumerable<Export> GetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition)
        {

            if (definition.ContractName.Equals(typeof(ILogger).FullName))
            {
                yield return new Export(definition.ContractName, () => new Logger() { Header = "Factory - " });
            }
        }
开发者ID:yasu-s,项目名称:MEF-Sample,代码行数:8,代码来源:LogExportProvider.cs

示例13: Constructor2_MultipleTimes

        public void Constructor2_MultipleTimes()
        {
            var outer = new AtomicComposition();

            var ct1 = new AtomicComposition(outer);

            ExceptionAssert.Throws<InvalidOperationException>(() => new AtomicComposition(outer));
        }
开发者ID:nlhepler,项目名称:mono,代码行数:8,代码来源:CompositionTransactionTests.cs

示例14: TryGetExports

        /// <summary>
        /// Invokes TryGetExports, returning the output as a collection.
        /// </summary>
        /// <param name="provider"></param>
        /// <param name="definition"></param>
        /// <param name="atomicComposition"></param>
        /// <returns></returns>
        public static IEnumerable<Export> TryGetExports(this ExportProvider provider, ImportDefinition definition, AtomicComposition atomicComposition)
        {
            Contract.Requires<ArgumentNullException>(provider != null);
            Contract.Requires<ArgumentNullException>(definition != null);

            IEnumerable<Export> exports;
            provider.TryGetExports(definition, atomicComposition, out exports);
            return exports;
        }
开发者ID:chenzuo,项目名称:Nancy.Bootstrappers.Mef,代码行数:16,代码来源:ExportProviderExtensions.cs

示例15: GetExportsCore

        protected override IEnumerable<Export> GetExportsCore(
            ImportDefinition definition,
            AtomicComposition atomicComposition
        ) {

            return from kv in _exports
                   where definition.IsConstraintSatisfiedBy(kv.Key)
                   select kv.Value;
        }
开发者ID:wenh123,项目名称:PTVS,代码行数:9,代码来源:MockExportProvider.cs


注:本文中的AtomicComposition类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。