Example #1
0
        public BarcodeForm()
        {
            InitializeComponent();
            try
            {
                string sPath = "";
                if (isIntermec)
                {
                    sPath = "MEFdemo1.HAL.Intermec.*Control*.dll";
                }
                else
                {
                    sPath = "MEFdemo1.HAL.ACME.*Control*.dll";
                }

                //I was unable to use the different catalog and let it look in a subfolder
                //so the plugin names are used as a filter
                catalog2 = new DirectoryCatalog(".", sPath);

                foreach (string s in catalog2.LoadedFiles)
                {
                    System.Diagnostics.Debug.WriteLine(s);
                }

                container2 = new CompositionContainer(catalog2);

#if DEBUG
                //some diagnostics...
                //see http://mef.codeplex.com/wikipage?title=Debugging%20and%20Diagnostics&referringTitle=Guide
                // using Samples\.... as in MEF preview 7 and 8
                CompositionInfo        ci = new CompositionInfo(catalog2, container2);
                System.IO.MemoryStream ms = new System.IO.MemoryStream();
                System.IO.TextWriter   tw = new System.IO.StreamWriter(ms);
                CompositionInfoTextFormatter.Write(ci, tw);
                System.Diagnostics.Debug.WriteLine(Encoding.UTF8.GetString(ms.GetBuffer(), 0, ms.GetBuffer().Length));
                foreach (PartDefinitionInfo pi in ci.PartDefinitions)
                {
                    System.Diagnostics.Debug.WriteLine("isRejected: " + pi.IsRejected.ToString());
                    System.Diagnostics.Debug.WriteLine("partInfo: " + pi.PartDefinition.ToString());
                }
                tw.Close();
#endif
                container2.ComposeParts(this);
                initBarcode();
            }
            catch (Exception ex)
            {
                if (ex is ChangeRejectedException)
                {
                    MessageBox.Show("HW-Components not found!");
                }
                else
                {
                    MessageBox.Show("Exception in ComposeParts: " + ex.Message + "\n" + ex.StackTrace);
                }
                this.Close();
            }
        }
Example #2
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);
        }
Example #3
0
        public static void Log()
        {
            var globalContainer = VsIdeTestHostContext.ServiceProvider.GetService <SComponentModel, IComponentModel>();
            var tempFile        = Path.Combine(Path.GetTempPath(), "mef.txt");

            using (var writer = new StreamWriter(tempFile, false))
            {
                CompositionInfoTextFormatter.Write(new CompositionInfo(globalContainer.DefaultCatalog, globalContainer.DefaultExportProvider), writer);
            }

            Process.Start(tempFile);
        }
        private void DumpMefLog(IComponentModel componentModel)
        {
            PackageUtility.ShowError(this, string.Format(CultureInfo.InvariantCulture, Resources.RuntimeShellPackage_DumpMefLogs, Constants.ProductName));

            var tempFile = string.Empty;

            try
            {
                // Write out the default VS catalog
                tempFile = Path.Combine(Path.GetTempPath(), "mef.txt");
                using (var writer = new StreamWriter(tempFile, false))
                {
                    CompositionInfoTextFormatter.Write(new CompositionInfo(componentModel.DefaultCatalog, componentModel.DefaultExportProvider), writer);
                }

                Process.Start(tempFile);
            }
            catch (IOException)
            {
                // Ignore writing issues
            }

            try
            {
                // Write out the NuPattern catalog
                tempFile = Path.Combine(Path.GetTempPath(), "mef-nupattern.txt");
                using (var writer = new StreamWriter(tempFile, false))
                {
                    CompositionInfoTextFormatter.Write(new CompositionInfo(componentModel.GetCatalog(
                                                                               Catalog.DefaultCatalogName), componentModel.DefaultExportProvider), writer);
                }

                Process.Start(tempFile);
            }
            catch (IOException)
            {
                // Ignore writing issues
            }
        }
Example #5
0
        public MainForm()
        {
            InitializeComponent();
            try
            {
                catalog   = new DirectoryCatalog(".", "MEFdemo1.Plugins.*.dll");
                container = new CompositionContainer(catalog);
                container.ComposeParts(this);
#if DEBUG
                //some diagnostics...
                //see http://mef.codeplex.com/wikipage?title=Debugging%20and%20Diagnostics&referringTitle=Guide
                // using Samples\.... as in MEF preview 7 and 8
                CompositionInfo        ci = new CompositionInfo(catalog, container);
                System.IO.MemoryStream ms = new System.IO.MemoryStream();
                System.IO.TextWriter   tw = new System.IO.StreamWriter(ms);
                CompositionInfoTextFormatter.Write(ci, tw);
                System.Diagnostics.Debug.WriteLine(Encoding.UTF8.GetString(ms.GetBuffer(), 0, ms.GetBuffer().Length));
                foreach (PartDefinitionInfo pi in ci.PartDefinitions)
                {
                    iPluginCount++;
                    System.Diagnostics.Debug.WriteLine("isRejected: " + pi.IsRejected.ToString());
                    System.Diagnostics.Debug.WriteLine("partInfo: " + pi.PartDefinition.ToString());
                }

                tw.Close();
#else
                foreach (PartDefinitionInfo pi in ci.PartDefinitions)
                {
                    iPluginCount++;
                }
#endif
                drawPlugins();
            }
            catch (Exception ex)
            {
                MessageBox.Show("No Plugins loaded: " + ex.Message);
            }
        }
Example #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}");
            }
        }
Example #7
0
        static void Main(string[] args)
        {
            AssemblyCatalog      catalog   = new AssemblyCatalog(Assembly.GetExecutingAssembly());
            CompositionContainer container = new CompositionContainer(catalog);

            try
            {
                container.GetExportedValue <PluginConsumer>();
            }
            catch
            {
                CompositionInfo ci = new CompositionInfo(catalog, container);
                //we can use the GetPartDefinitionInfo to examine parts for potential issues.We can see if a part was rejected,
                // if its the primary rejection, then we can ask it to return a potential root causes.
                var partDef        = ci.GetPartDefinitionInfo(typeof(PluginConsumer));
                var possibleCauses = partDef.FindPossibleRootCauses();

                //If you want to get a detailed analysis then we can use the Write method provided by the
                // CompositionInforTextFormatter
                CompositionInfoTextFormatter.Write(ci, Console.Out);
            }

            Console.ReadKey();
        }