/// <summary> /// 對指定計算式策略實例化 /// </summary> /// <param name="topicIdentifier">題型識別ID</param> /// <returns>策略實例</returns> public virtual ITopic CreateTopicInstance(string topicIdentifier) { // 以題型為單位取得Composer _composer = ComposerFactory.GetComporser(topicIdentifier); // 返回緩衝區中的運算符對象 Lazy <ITopic, ITogicMetaDataView> lazyTopic = TopicCache.GetOrAdd(_composer, (o) => { // 內部部件組合 _composer.Compose(this); // 指定運算符并獲取處理類型 IEnumerable <Lazy <ITopic, ITogicMetaDataView> > topics = Topics.Where(d => { return(d.Metadata.TopicIdentifier.Equals(topicIdentifier, StringComparison.CurrentCultureIgnoreCase)); }); // 部件是否存在 if (!topics.Any()) { // 指定的題型策略對象未找到 throw new TopicNotFoundException(MessageUtil.GetMessage(() => MsgResources.E0018L, topicIdentifier)); } LogUtil.LogDebug(MessageUtil.GetMessage(() => MsgResources.I0003L)); return(topics.First()); }); // 返回該運算符處理類型的實例(實例化) var topic = lazyTopic.Value; // 內部部件組合(策略抽象類中的計算式工廠對象注入) _composer.Compose(topic); return(topic); }
/// <summary> /// 題型指定獲取HTML支援類實例 /// </summary> /// <param name="topicIdentifier">題型類型</param> /// <returns>HTML支援類實例</returns> public IHtmlSupport CreateHtmlSupportInstance(string topicIdentifier) { // 獲取HTML支援類Composer _composer = ComposerFactory.GetComporser(topicIdentifier); // 返回緩衝區中的支援類對象 Lazy <IHtmlSupport, IHtmlSupportMetaDataView> lazyHtmlSupport = HtmlSupportCache.GetOrAdd(_composer, (o) => { // 從MEF容器中注入本類的屬性信息(注入HTML支援類屬性) _composer.Compose(this); // 取得指定類型下的支援類類型參數 IEnumerable <Lazy <IHtmlSupport, IHtmlSupportMetaDataView> > supports = Supports.Where(d => d.Metadata.TopicIdentifier.Equals(topicIdentifier, StringComparison.CurrentCultureIgnoreCase)); if (!supports.Any()) { throw new HtmlSupportNotFoundException(MessageUtil.GetMessage(() => MsgResources.E0021L, topicIdentifier)); } LogUtil.LogDebug(MessageUtil.GetMessage(() => MsgResources.I0008L)); return(supports.First()); }); // 該題型HTML支持類實例(實例化) var htmlSupport = lazyHtmlSupport.Value; // 內部部件組合 _composer.Compose(htmlSupport); // 返回該題型HTML支持類實例 return(htmlSupport); }
/// <summary> /// 對指定運算符實例化 /// </summary> /// <param name="sign">運算符</param> /// <returns>運算符實例</returns> public IArithmetic GetFormulaOperator(SignOfOperation sign) { // 返回緩衝區中的運算符對象 Lazy <ArithmeticBase, IArithmeticMetaDataView> lazyArithmetic = ArithmeticCache.GetOrAdd(sign, (c) => { // 從MEF容器中注入本類的屬性信息(注入運算符屬性) _composer.Compose(this); LogUtil.LogDebug(MessageUtil.GetMessage(() => MsgResources.I0001L)); // 指定運算符并獲取處理類型 IEnumerable <Lazy <ArithmeticBase, IArithmeticMetaDataView> > arithmetics = Arithmetics.Where(d => { return(d.Metadata.Sign == sign); }); if (!arithmetics.Any()) { // 指定的題型參數對象未找到 throw new ArithmeticNotFoundException(MessageUtil.GetMessage(() => MsgResources.E0020L, sign.ToString())); } LogUtil.LogDebug(MessageUtil.GetMessage(() => MsgResources.I0002L, sign.ToString())); return(arithmetics.First()); }); ArithmeticBase arithmetic = lazyArithmetic.Value; // 內部部件組合 _composer.Compose(arithmetic); // 返回該運算符處理類型的實例 return(arithmetic); }
public MainWindow() { InitializeComponent(); Composer.LoadExports(Assembly.GetExecutingAssembly()); if (File.Exists("..\\..\\..\\..\\CodingConnected.Composition.Example.WPF.Core.Plugin\\bin\\Debug\\netcoreapp3.0\\CodingConnected.Composition.Example.WPF.Core.Plugin.dll")) { Composer.LoadExports(Assembly.LoadFrom("..\\..\\..\\..\\CodingConnected.Composition.Example.WPF.Core.Plugin\\bin\\Debug\\netcoreapp3.0\\CodingConnected.Composition.Example.WPF.Core.Plugin.dll")); } Composer.Compose(PluginsHost.Default); // Load toolbars; this must be done here because one cannot // bind a collection of toolbars to a toolbartray. MainToolBarTray.DataContextChanged += (s, e) => { if (!(e.NewValue is MainWindowViewModel vm)) { return; } foreach (var pl in PluginsHost.Default.Plugins) { if (pl is IToolBar itb) { var tb = new ToolBar(); tb.Items.Add(itb.ToolBarView); MainToolBarTray.ToolBars.Add(tb); } } }; this.DataContext = new MainWindowViewModel(); }
/// <summary> /// <see cref="CompileController"/>構造 構築依賴組合並導入<see cref="ApiProcess"/>API處理類 /// </summary> public CompileController() { // 獲取HTML支援類Composer Composer composer = ComposerFactory.GetComporser(this.GetType().Assembly); composer.Compose(this); }
public override CommandResult Execute() { try { FileSystemMigrator.Migrate(); var assemblyPaths = Enumerable.Empty <string>(); var workingDirectory = FileSystem.GetWorkingDirectory(Script); if (workingDirectory != null) { assemblyPaths = AssemblyResolver.GetAssemblyPaths(workingDirectory); } Composer.Compose(workingDirectory); ScriptExecutor.Initialize(assemblyPaths, _scriptPackResolver.GetPacks(), ScriptArgs); // HACK: This is a (dirty) fix for #1086. This might be a temporary solution until some further refactoring can be done. ScriptExecutor.ScriptEngine.CacheDirectory = Path.Combine(workingDirectory ?? FileSystem.CurrentDirectory, FileSystem.DllCacheFolder); var scriptResult = ScriptExecutor.Execute(Script, ScriptArgs); var commandResult = Inspect(scriptResult); ScriptExecutor.Terminate(); return(commandResult); } catch (Exception ex) { Logger.ErrorException("Error executing script '{0}'", ex, Script); return(CommandResult.Error); } }
public void GenericArray() { Composer composer = new Composer(); Object[] array = null; Assert.ThrowsException <ArgumentNullException>(delegate { composer.Compose <Object>(array); }); }
public void OnExecute() { if (LaunchDebugger && !Debugger.IsAttached) { Debugger.Launch(); } Composer composer = new Composer(); composer.Compose(InitialSeed, TestMode); ILog log = SourceMe.The <ILog>(); log.Info("\n======================================"); log.Info("Run started"); try { composer.LaunchGame(); } finally { log.Info("Run ended"); composer.Release(); } }
public static void PrintLevel(LevelModel level) { string[] levelPrintable = Composer.Compose(level.Matrix); var levelState = new StaticElement(levelPrintable); levelState.Print(); }
public void BadDoubleNest() { Composer composer = new Composer(); Object[] objects = { new Top(), new Middle() }; Assert.ThrowsException <ArgumentException>(delegate { composer.Compose <Top>(objects); }); }
private void Init() { this.layout = new Layout(0, 0); var matrix = Composer.MakeBoxLayout(this.width, this.height); this.layout.SetLayout(Composer.Compose(matrix)); }
public void GenericEnumerator() { Composer composer = new Composer(); IEnumerator <Object> enumerator = null; Assert.ThrowsException <ArgumentNullException>(delegate { composer.Compose <Object>(enumerator); }); }
public virtual void Compose(T useCase) { Composer.Factor(useCase); BackendComposer.Factor(useCase); BackendComposer.Compose(useCase); Composer.Compose(useCase); }
/// <summary> /// Compose any loose imports /// </summary> public void Recompose() { Composer.Compose(this); configuredStorageProvider = (from provider in StorageProviders where provider.Name == ConfigManager.Current.Database select provider).FirstOrDefault(); }
public void NoNest() { Composer composer = new Composer(); Object[] objects = { new Bottom() }; Bottom bottom = composer.Compose <Bottom>(objects); Assert.AreEqual(objects[0], bottom); }
/// <summary> /// 畫面構造函數 /// </summary> public FrmMain() { InitializeComponent(); // 獲取HTML支援類Composer Composer composer = ComposerFactory.GetComporser(this.GetType().Assembly); composer.Compose(this); }
private void Init() { this.layout = new Layout(0, 0); var matrix = Composer.MakeBoxLayout(49, 16); Composer.AddHorizontalLine(matrix, 10, 0, 48); Composer.AddVerticalLine(matrix, 10, 0, 10); this.layout.SetLayout(Composer.Compose(matrix)); }
public void NoNestEnumerator() { Composer composer = new Composer(); Object[] objects = { new Bottom() }; Object bottom = composer.Compose(((IEnumerable <Object>)objects).GetEnumerator()); Assert.AreEqual(objects[0], bottom); }
public void DoubleNestWithNull() { Composer composer = new Composer(); Object[] objects = { null, new Middle(), new Bottom() }; Top top = composer.Compose <Top>(objects); Assert.AreEqual(objects[0], top); }
public void SingleNest() { Composer composer = new Composer(); Object[] objects = { new Middle(), new Bottom() }; Middle middle = composer.Compose <Middle>(objects); Assert.AreEqual(objects[0], middle); Assert.AreEqual(objects[1], middle.Bottom); }
public void DoubleNest() { Composer composer = new Composer(); Object[] objects = { new Top(), new Middle(), new Bottom() }; Top top = composer.Compose <Top>(objects); Assert.AreEqual(objects[0], top); Assert.AreEqual(objects[1], top.Middle); Assert.AreEqual(objects[2], top.Middle.Bottom); }
public void SingleNest() { Composer composer = new Composer(); Object[] objects = { new MiddleLeft(), new BottomCenter(), new BottomLeft() }; MiddleLeft middleLeft = composer.Compose <MiddleLeft>(objects); Assert.AreEqual(objects[0], middleLeft); Assert.AreEqual(objects[1], middleLeft.BottomCenter); Assert.AreEqual(objects[2], middleLeft.BottomLeft); }
public void NoNestEnumeratorGeneric() { Composer composer = new Composer(); Object[] objects = { new Top(), new Middle(), new Bottom() }; Top top = composer.Compose <Top>(((IEnumerable <Object>)objects).GetEnumerator()); Assert.AreEqual(objects[0], top); Assert.AreEqual(objects[1], top.Middle); Assert.AreEqual(objects[2], top.Middle.Bottom); }
public HomeScreenController(OrganazerContext context, KeyboardInput parser) : base(context, parser) { var matrix = Composer.MakeBoxLayout(49, 16); Composer.AddHorizontalLine(matrix, 10, 0, 48); Composer.AddVerticalLine(matrix, 10, 0, 10); var layout = new Layout(0, 0); layout.SetLayout(Composer.Compose(matrix)); this.root = layout; }
static void Export() { var process = Helpers.LoadProcess("BRESSANA-ARTICOLI"); var message = Helpers.LoadMessage(process.message); XMLExtractor extractor = new XMLExtractor(process, custom); using (Composer composer = new Composer(message, process, "out.txt", extractor)) { composer.Compose(); }; }
private void Init(int w, int h, string text) { this.layout = new Layout(this.X, this.Y); var matrix = Composer.MakeBoxLayout(w, h); this.layout.SetLayout(Composer.Compose(matrix)); int textX = this.X + ((w - text.Length) / 2); int textY = this.Y + ((h - 1) / 2); this.label = new Label(textX, textY, content: text); }
public void DoubleNest() { Composer composer = new Composer(); Object[] objects = { new Top(), new MiddleLeft(), new BottomCenter(), new BottomLeft(), new MiddleRight(), new BottomCenter(), new BottomRight() }; Top top = composer.Compose <Top>(objects); Assert.AreEqual(objects[0], top); Assert.AreEqual(objects[1], top.MiddleLeft); Assert.AreEqual(objects[2], top.MiddleLeft.BottomCenter); Assert.AreEqual(objects[3], top.MiddleLeft.BottomLeft); Assert.AreEqual(objects[4], top.MiddleRight); Assert.AreEqual(objects[5], top.MiddleRight.BottomCenter); Assert.AreEqual(objects[6], top.MiddleRight.BottomRight); }
protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); new UnhandledExceptionHook(this); Application.Current.Exit += OnShutdown; myComposer = new Composer(); myComposer.Add(new AssemblyCatalog(GetType().Assembly)); myComposer.Compose(); Application.Current.MainWindow = myComposer.Resolve <Shell>(); Application.Current.MainWindow.Show(); }
public TestContext(Composer composer, TestFilesRepository testFilesRepository, string testFolder) { if (composer == null) throw new ArgumentNullException(nameof(composer)); if (string.IsNullOrWhiteSpace(testFolder)) throw new ArgumentNullException(nameof(testFolder)); _viewModel = composer.Compose(); _composer = composer; _rootFolder = testFolder; _sourceDirectory = Path.Combine(_rootFolder, "Source"); _targetDirectory = Path.Combine(_rootFolder, "Target"); _testFilesRepository = testFilesRepository; if (!Directory.Exists(SourceDirectory)) { Directory.CreateDirectory(SourceDirectory); } if (!Directory.Exists(TargetDirectory)) { Directory.CreateDirectory(TargetDirectory); } _logger = _composer.Resolve<Func<string, ILogger>>()("TestContext"); _logger.Info("Root folder is " + _rootFolder); _logger.Info("Test context hashcode is " + GetHashCode()); }
public static void Main(string[] args) { Console.WriteLine("Begin ..."); Program.configureTracing(); MyTarget target = new MyTarget(); // Our composition target Console.WriteLine($"New MyTarget: {target}"); using (Composer <MyTarget> composer = new Composer <MyTarget>(() => target)) { // Composer composer.Participate(new MyParticipant()); // Manual addition of Participant Console.WriteLine($"Composer: {composer}"); Console.WriteLine("Compose ..."); composer.Compose(); // Compose } Console.WriteLine($"MyTarget: {target}"); Console.WriteLine("Done"); Console.ReadKey(); }
public Node Compose(Node node, ComposerList list) { if (node == null || list == null) { return(node); } Node result = node; if (this.contextComposer != null) { // first, give precedence to the context composer if it is in the list for (int i = 0, n = list.Count; i < n; i++) { if (list[i] == this.contextComposer) { result = this.contextComposer.Compose(node, this.contextComposer, this.hasContextReference, this.scope); if (result != node) { return(result); } } } } // next, try each composer in order for (int i = 0, n = list.Count; i < n; i++) { Composer c = list[i]; if (c != this.contextComposer) { result = c.Compose(node, this.contextComposer, this.hasContextReference, this.scope); if (result != node) { return(result); } } } // lastly, if there was at least one composer that chose not to compose the node, // try the context composer if (list.Count > 0 && this.contextComposer != null) { result = this.contextComposer.Compose(node, this.contextComposer, this.hasContextReference, this.scope); } return(result); }