예제 #1
0
        public void TestConfigLoad()
        {
            string           fileName = "strategy.common.strategyconfig";
            string           filePath = TestCaseManager.GetTestCasePath(typeof(TestStrategyAssemblyConfig), fileName);
            StrategyAssembly config   = new StrategyAssembly();

            config.Load(filePath);
            Assert.AreEqual("com.wer.sc.strategy.common", config.AssemblyName);
            Assert.AreEqual("基础策略测试", config.Description);
            Assert.AreEqual("基础策略", config.Name);

            IList <IStrategyInfo> strategies = config.GetSubStrategyInfo("");

            Assert.AreEqual(1, strategies.Count);
            Assert.AreEqual("mock测试", strategies[0].Name);
            Assert.AreEqual("com.wer.sc.strategy.common.test.Strategy_Mock", strategies[0].ClassName);

            IList <string> paths = config.GetSubPath("");

            Assert.AreEqual(4, paths.Count);
            Assert.AreEqual("\\均线", paths[0]);
            Assert.AreEqual("\\转折点查找", paths[1]);
            Assert.AreEqual("\\量能分析", paths[2]);
            Assert.AreEqual("\\平台分析", paths[3]);

            Assert.AreEqual("\\平台分析\\子平台分析", config.GetSubPath("\\平台分析")[0]);

            IList <IStrategyInfo> subStrategies = config.GetSubStrategyInfo("\\均线");

            Assert.AreEqual(1, subStrategies.Count);
            Assert.AreEqual("均线策略", subStrategies[0].Name);
        }
예제 #2
0
        public static StrategyAssembly Create(string file)
        {
            StrategyAssembly strategyAssembly = new StrategyAssembly();

            strategyAssembly.Load(file);

            if (!File.Exists(strategyAssembly.FullPath))
            {
                strategyAssembly.isError   = true;
                strategyAssembly.errorInfo = "无法找到Assembly" + strategyAssembly.AssemblyName;
                return(strategyAssembly);
            }
            byte[]   buffer = File.ReadAllBytes(strategyAssembly.FullPath);
            Assembly ass    = Assembly.Load(buffer);

            if (ass == null)
            {
                strategyAssembly.isError   = true;
                strategyAssembly.errorInfo = strategyAssembly.AssemblyName + "装载失败";
                return(strategyAssembly);
            }
            strategyAssembly.assembly = ass;

            List <IStrategyInfo> strategies = strategyAssembly.GetAllStrategies();

            foreach (StrategyInfo config in strategies)
            {
                string clsName   = config.ClassName;
                Type   classType = ass.GetType(clsName, false, true);

                if (classType == null)
                {
                    config.IsError   = true;
                    config.ErrorInfo = "类型" + clsName + "不存在";
                    continue;
                }
                config.strategyType = classType;
                Type inheritType = classType.GetInterface(typeof(IStrategy).FullName);
                if (inheritType == null)
                {
                    config.IsError   = true;
                    config.ErrorInfo = "类型" + clsName + "没有实现IStrategy";
                    continue;
                }
            }
            return(strategyAssembly);
        }