Пример #1
0
        /// <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);
        }
Пример #2
0
        /// <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);
        }
Пример #3
0
        /// <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);
        }
Пример #6
0
        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);
            }
        }
Пример #7
0
        public void GenericArray()
        {
            Composer composer = new Composer();

            Object[] array = null;
            Assert.ThrowsException <ArgumentNullException>(delegate { composer.Compose <Object>(array); });
        }
Пример #8
0
        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();
            }
        }
Пример #9
0
        public static void PrintLevel(LevelModel level)
        {
            string[] levelPrintable = Composer.Compose(level.Matrix);
            var      levelState     = new StaticElement(levelPrintable);

            levelState.Print();
        }
Пример #10
0
        public void BadDoubleNest()
        {
            Composer composer = new Composer();

            Object[] objects = { new Top(), new Middle() };
            Assert.ThrowsException <ArgumentException>(delegate { composer.Compose <Top>(objects); });
        }
Пример #11
0
        private void Init()
        {
            this.layout = new Layout(0, 0);
            var matrix = Composer.MakeBoxLayout(this.width, this.height);

            this.layout.SetLayout(Composer.Compose(matrix));
        }
Пример #12
0
        public void GenericEnumerator()
        {
            Composer             composer   = new Composer();
            IEnumerator <Object> enumerator = null;

            Assert.ThrowsException <ArgumentNullException>(delegate { composer.Compose <Object>(enumerator); });
        }
Пример #13
0
        public virtual void Compose(T useCase)
        {
            Composer.Factor(useCase);
            BackendComposer.Factor(useCase);

            BackendComposer.Compose(useCase);
            Composer.Compose(useCase);
        }
Пример #14
0
        /// <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();
        }
Пример #15
0
        public void NoNest()
        {
            Composer composer = new Composer();

            Object[] objects = { new Bottom() };
            Bottom   bottom  = composer.Compose <Bottom>(objects);

            Assert.AreEqual(objects[0], bottom);
        }
Пример #16
0
        /// <summary>
        /// 畫面構造函數
        /// </summary>
        public FrmMain()
        {
            InitializeComponent();

            // 獲取HTML支援類Composer
            Composer composer = ComposerFactory.GetComporser(this.GetType().Assembly);

            composer.Compose(this);
        }
Пример #17
0
        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));
        }
Пример #18
0
        public void NoNestEnumerator()
        {
            Composer composer = new Composer();

            Object[] objects = { new Bottom() };
            Object   bottom  = composer.Compose(((IEnumerable <Object>)objects).GetEnumerator());

            Assert.AreEqual(objects[0], bottom);
        }
Пример #19
0
        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);
        }
Пример #20
0
        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);
        }
Пример #21
0
        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);
        }
Пример #22
0
        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);
        }
Пример #23
0
        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);
        }
Пример #24
0
        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;
        }
Пример #25
0
        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();
            };
        }
Пример #26
0
        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);
        }
Пример #27
0
        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);
        }
Пример #28
0
        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();
        }
Пример #29
0
 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());
 }
Пример #30
0
        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();
        }
Пример #31
0
        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);
        }