Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
        public void TestAssemblyCreate()
        {
            string fileName = "strategy.common.strategyconfig";
            string filePath = TestCaseManager.GetTestCasePath(typeof(TestStrategyAssemblyConfig), fileName);
            //StrategyAssembly config = new StrategyAssembly();
            //config.Load(filePath);

            StrategyAssembly strategyAssembly = StrategyAssembly.Create(filePath);
            IStrategyInfo    strategyInfo     = strategyAssembly.GetStrategyInfo("com.wer.sc.strategy.common.ma.Strategy_MultiMa");

            Console.WriteLine(strategyInfo);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 刷新一个assembly
        /// </summary>
        /// <param name="ass"></param>
        public void Refresh(IStrategyAssembly ass)
        {
            int index = this.assemblies.IndexOf(ass);

            this.assemblies.Remove(ass);
            string           path   = ass.ConfigPath;
            StrategyAssembly newAss = StrategyAssembly.Create(path);

            if (newAss != null)
            {
                this.assemblies.Insert(index, newAss);
            }
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
0
        public IList <IStrategyAssembly> Scan(String path)
        {
            if (!Directory.Exists(path))
            {
                return(new List <IStrategyAssembly>());
            }

            String[] configfiles             = Directory.GetFiles(path, "*.strategyconfig", SearchOption.AllDirectories);
            List <IStrategyAssembly> plugins = new List <IStrategyAssembly>();

            for (int i = 0; i < configfiles.Length; i++)
            {
                string file = configfiles[i];
                //StrategyAssembly strategyAssembly = new StrategyAssembly();
                //strategyAssembly.Load(file);
                StrategyAssembly strategyAssembly = StrategyAssembly.Create(file);
                plugins.Add(strategyAssembly);
            }
            return(plugins);
        }