示例#1
0
        private CompositionInfo GetCurrentComposition(IntPtr handle)
        {
            var hIMC = IntPtr.Zero;

            try
            {
                hIMC = SafeNativeMethods.ImmGetContext(handle);

                var start = 0;
                var end   = 0;
                this.GetSelection(hIMC, ref start, ref end);

                var info = new CompositionInfo
                {
                    Text           = GetString(hIMC),
                    SelectionStart = start,
                    SelectionEnd   = end,
                    CaretStart     = SafeNativeMethods.ImmGetCompositionStringW(hIMC, (int)GCS.GCS_CURSORPOS, null, 0)
                };

                return(info);
            }
            finally
            {
                if (hIMC != IntPtr.Zero)
                {
                    SafeNativeMethods.ImmReleaseContext(handle, hIMC);
                }
            }
        }
示例#2
0
        private static CompositionInfo GetCompositionInfo(string path)
        {
            AggregateCatalog catalog = GetCatalog(path);
            var host            = new CompositionContainer(catalog);
            var compositionInfo = new CompositionInfo(catalog, host);

            return(compositionInfo);
        }
示例#3
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();
            }
        }
示例#4
0
        public IntegrationTests()
        {
            _catalog = new TypeCatalog(
                typeof(Foo), typeof(Bar), typeof(Biff), typeof(MissingMeta),
                typeof(WrongCreationPolicy), typeof(WrongTypeIdentity));

            _container = new CompositionContainer(_catalog);

            _analysis = new CompositionInfo(_catalog, _container);
        }
示例#5
0
        public IntegrationTests()
        {
            _catalog = new TypeCatalog(
                typeof(Foo), typeof(Bar), typeof(Biff), typeof(MissingMeta),
                typeof(WrongCreationPolicy), typeof(WrongTypeIdentity));

            _container = new CompositionContainer(_catalog);

            _analysis = new CompositionInfo(_catalog, _container);
        }
示例#6
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);
        }
示例#7
0
        public void EndComposition()
        {
            if (this._imeComposition != null)
            {
                if (this._textView.IsReadOnly == false)
                {
                    this._textView.SelectedText = this._imeComposition.Text;
                }
            }

            this._imeComposition  = null;
            this.IsCompositioning = false;
        }
示例#8
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 test = new AssemblyCatalog(@"C:\Users\daplaist\Documents\My Dropbox\MEF\Tech Ed 2010\MEFConsole\bin\Debug\MEFConsole.exe");

                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);
        }
示例#9
0
        private void RefreshOutput()
        {
            ResetContainer();

            this._container = new CompositionContainer(_aggregateCatalog);
            {
                this._compositionInfo = new CompositionInfo(_aggregateCatalog, _container);

                if (this._compositionInfo != null)
                {
                    _partViewModelMap = this._compositionInfo.PartDefinitions.ToDictionary(pd => pd, pd => new PartInfoViewModel(pd, this));

                    this.partDefinitions.Source = _partViewModelMap.Values.ToList();
                    this.partDefinitions.View.MoveCurrentToFirst();
                }
            }
        }
示例#10
0
        public void LoadAllCompositionType()
        {
            string ocode = ((SessionUser)Session["SessionUser"]).OCode;

            List <LC_Composition> dataList = aCompositionBLL.LoadDataForGrid(ocode);

            if (dataList.Count > 0)
            {
                CompositionInfo.DataSource = dataList.ToList();
                CompositionInfo.DataBind();
            }
            else
            {
                CompositionInfo.DataSource = null;
                CompositionInfo.DataBind();
            }
        }
        public static void ApplyCompositionInfo(CompositionInfo info, XmlProcessingContext xmlProcessingContext)
        {
            if (info.CommandInfos == null)
            {
                return;
            }

            foreach (var commandInfo in info.CommandInfos)
            {
                if (!Runners.ContainsKey(commandInfo.GetType()))
                {
                    throw new CompositionException("Provided type is not supported for applying to a component context: " +
                                                   commandInfo.GetType().FullName);
                }

                var runner = Runners[commandInfo.GetType()];


                try
                {
                    xmlProcessingContext.EnterRunningLocation("Processing '" + commandInfo + "'");
                    runner(commandInfo, xmlProcessingContext);
                    xmlProcessingContext.LeaveRunningLocation();
                }
                catch (Exception e)
                {
                    // Ignore the exception if the "IgnoreOnError" property is set.
                    // If not, just report the exception (in case it happened in an
                    // include command) and let it bubble up.

                    if (!commandInfo.IgnoreOnError)
                    {
                        // TODO: Fix logging / tracing mechanism

                        xmlProcessingContext.ReportError("Exception: " + e.Message);
                        throw;
                    }

                    // If exception has occured, then the "LeaveRunningLocation"
                    // method is not executed in the "try" block, so call it here.

                    xmlProcessingContext.LeaveRunningLocation();
                }
            }
        }
示例#12
0
        public void StartComposition(IntPtr handle)
        {
            this._imeComposition  = null;
            this.IsCompositioning = true;

            // Move the IME windows.
            var hIMC = SafeNativeMethods.ImmGetContext(handle);

            try
            {
                this.MoveImeWindow(handle, hIMC, this._textView.Caret.Location);
                SafeNativeMethods.ImmReleaseContext(handle, hIMC);
            }
            finally
            {
                SafeNativeMethods.ImmReleaseContext(handle, hIMC);
            }
        }
示例#13
0
        /// <summary>
        /// Updates the composition to a copy of what the Operating System has in its IME input.
        /// </summary>
        /// <param name="handle"></param>
        /// <param name="gcs"></param>
        /// <returns>Returns True if update was handled, False if not and hence default OS behavior should be fallbacked upon.</returns>
        public bool UpdateCurrentComposition(IntPtr handle, GCS gcs)
        {
            if (((gcs & GCS.GCS_RESULTSTR) == GCS.GCS_RESULTSTR))
            {
                if (this._imeComposition != null)
                {
                    //this.textView.SelectedText = this.imeComposition.Text;
                    //this.imeComposition = this.GetCurrentComposition(handle);
                }
                else
                {
                    return(false);
                }
            }
            else if (((gcs & GCS.GCS_RESULTSTR) == GCS.GCS_RESULTSTR) == false)
            {
                this._imeComposition = this.GetCurrentComposition(handle);
            }

            return(true);
        }
示例#14
0
        public static IEnumerable <string> DiscoverExportParts(string path, IList <string> acceptableContractNames)
        {
            var results = new List <string>();

            try
            {
                CompositionInfo compositionInfo = GetCompositionInfo(path);
                results.AddRange(from partDefinitionInfo in compositionInfo.PartDefinitions
                                 from exportDefinition in partDefinitionInfo.PartDefinition.ExportDefinitions
                                 let compositionElement = exportDefinition as ICompositionElement
                                                          where compositionElement != null
                                                          let displayName = compositionElement.Origin?.DisplayName
                                                                            let contractName = exportDefinition.ContractName
                                                                                               // HARD-CODED constant
                                                                                               let compositionType = exportDefinition.Metadata["ExportTypeIdentity"] as string
                                                                                               // HARD-CODED constant
                                                                                                                     let compositionName = exportDefinition.Metadata["Name"] as string
                                                                                                                                           where acceptableContractNames.Contains(contractName)
                                                                                                                                           select compositionName);

                /*
                 * string output;
                 * using (var stringWriter = new StringWriter())
                 * {
                 *  CompositionInfoTextFormatter.Write(compositionInfo, stringWriter);
                 *  output = stringWriter.ToString();
                 * }
                 * return output;
                 */
            }
            catch (ReflectionTypeLoadException ex)
            {
                foreach (Exception exception in ex.LoaderExceptions)
                {
                    throw new CompositionException(exception.Message);
                }
                throw new CompositionException(ex.Message);
            }
            return(results);
        }
示例#15
0
        private void RefreshOutput()
        {
            ResetContainer();
            _container = new CompositionContainer(_aggregateCatalog);
            {
                this.compositionInfo = new CompositionInfo(_aggregateCatalog, _container);

                if (this.compositionInfo != null)
                {
                    StringBuilder builder = new StringBuilder();

                    //var definitions = from x in this.compositionInfo.PartDefinitions
                    //                  select new PartInfo(x, this);

                    _partViewModelMap = this.compositionInfo.PartDefinitions.ToDictionary(pd => pd, pd => new PartInfo(pd, this));

                    //this.partDefinitions.Source = definitions;
                    this.partDefinitions.Source = _partViewModelMap.Values;
                    this.partDefinitions.View.MoveCurrentToFirst();
                }
            }
        }
示例#16
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);
            }
        }
示例#17
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}");
            }
        }
示例#18
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();
        }