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); } } }
private static CompositionInfo GetCompositionInfo(string path) { AggregateCatalog catalog = GetCatalog(path); var host = new CompositionContainer(catalog); var compositionInfo = new CompositionInfo(catalog, host); return(compositionInfo); }
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(); } }
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); }
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 void EndComposition() { if (this._imeComposition != null) { if (this._textView.IsReadOnly == false) { this._textView.SelectedText = this._imeComposition.Text; } } this._imeComposition = null; this.IsCompositioning = false; }
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); }
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(); } } }
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(); } } }
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); } }
/// <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); }
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); }
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(); } } }
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); } }
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}"); } }
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(); }