/// <summary>
 /// Write a summary of info to output.
 /// </summary>
 /// <param name="info">Object to format.</param>
 /// <param name="output">Destination for formatted text.</param>
 public static void Write(CompositionInfo info, TextWriter output)
 {
     foreach (var part in info.PartDefinitions)
     {
         PartDefinitionInfoTextFormatter.Write(part, output);
         output.WriteLine();
     }
 }
 public static string Format(CompositionInfo info)
 {
     using (var output = new StringWriter())
     {
         Write(info, output);
         return output.ToString();
     }
 }
Пример #3
0
 /// <summary>
 /// Write a summary of info to output.
 /// </summary>
 /// <param name="info">Object to format.</param>
 /// <param name="output">Destination for formatted text.</param>
 public static void Write(CompositionInfo info, TextWriter output)
 {
     foreach (var part in info.PartDefinitions)
     {
         PartDefinitionInfoTextFormatter.Write(part, output);
         output.WriteLine();
     }
 }
Пример #4
0
        static void Main(string[] args)
        {
            var cat = new AssemblyCatalog(typeof(Program).Assembly);
            using (var container = new CompositionContainer(cat))
            {
                var ci = new CompositionInfo(cat, container);
                CompositionInfoTextFormatter.Write(ci, Console.Out);
            }

            Console.ReadKey(true);
        }
        public static void Write(CompositionInfo info, TextWriter output)
        {
            var partDefinitions = info.PartDefinitions;
            if (partDefinitions == null)
            {
                return;
            }

            var orderedDefinitions = partDefinitions.OrderBy(GetPartDefinitionKey);

            foreach (var part in orderedDefinitions)
            {
                PartDefinitionInfoTextFormatter.Write(part, output);
                output.WriteLine();
            }
        }
Пример #6
0
		public void when_retrieving_exports_then_reports_duplicate_services(Type serviceType)
		{
			var componentModel = GlobalServices.GetService<SComponentModel, IComponentModel>();
			var contractName = AttributedModelServices.GetContractName(serviceType);
			var components = componentModel.DefaultExportProvider
				.GetExports<object, IDictionary<string, object>>(contractName)
				.ToArray();

			if (components.Length != 1)
			{
				var info = new CompositionInfo(componentModel.DefaultCatalog, componentModel.DefaultExportProvider);
				var log = Path.GetTempFileName();
				using (var writer = new StreamWriter(log))
				{
					CompositionInfoTextFormatter.Write(info, writer);
					writer.Flush();
				}

				output.WriteLine(log);
				// Process.Start(new ProcessStartInfo("notepad", log) { UseShellExecute = true });

				Assert.False(true, $"Expected only one component of {serviceType.Name}. Composition log at {log}");
			}
		}
Пример #7
0
        static int Run(
            List<string> directories,
            List<string> files, 
            Command programCommand, 
            Func<CompositionContractInfo, bool> contractPredicate, 
            Func<CompositionInfo, PartDefinitionInfo, bool> partPredicate, 
            bool verbose, RejectionWhitelist whitelist, Options opts)
        {
            int exitCode = 0;

            if (programCommand == Command.None ||
                programCommand == Command.PrintUsage ||
                !files.Concat(directories).Any())
            {
                PrintUsage(opts);
            }
            else
            {
                var cat = new AggregateCatalog(
                    directories.Select(d => new DirectoryCatalog(d)).Cast<ComposablePartCatalog>()
                    .Concat(directories.Select(d => new DirectoryCatalog(d, "*.exe")).Cast<ComposablePartCatalog>())
                    .Concat(files.Select(f => new AssemblyCatalog(f)).Cast<ComposablePartCatalog>()));

                var container = new CompositionContainer(cat);
                var compositionInfo = new CompositionInfo(cat, container);

                if (programCommand == Command.PrintParts)
                {
                    var partsToPrint = compositionInfo.PartDefinitions
                        .Where(p => partPredicate(compositionInfo, p));

                    foreach (var pdi in partsToPrint)
                    {
                        if (pdi.IsRejected &&
                            !whitelist.IsRejectionAllowed(pdi))
                        {
                            Console.Write("[Unexpected] ");
                            exitCode = 1;
                        }
                        PrintPartDefinition(pdi, Console.Out, verbose);
                    }
                }
                else if (programCommand == Command.PrintContracts)
                {
                    PrintContracts(compositionInfo.Contracts.Where(contractPredicate));
                }
            }
            return exitCode;
        }
Пример #8
0
        /// <summary>
        /// Reports the composition error.
        /// </summary>
        private void ReportPluginCompositionError(CompositionException ex)
        {
            // save composition errors to string
            using (System.IO.StringWriter sw = new System.IO.StringWriter())
            {
                var ci = new CompositionInfo(this.compositionContainer.Catalog, this.compositionContainer);
                CompositionInfoTextFormatter.Write(ci, sw);

                // create error and add it to our list
                this.errors.Add(new PluginLoadError
                {
                    Message = sw.GetStringBuilder().ToString(),
                    Exception = ex,
                    Plugin = null
                });
            }
        }