public object Backtest(object json) { var body = JsonConverter.Decode(json); var code = body["code"]; var strategy_id = int.Parse(body["strategy_id"]); var time = body["time"]; var user_id = body["user_id"]; // generate report path var report_path = ""; using (var ctx = new quantEntities()) { DateTime dt = DateTime.ParseExact(time, "yyyy-MM-dd HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture); string new_time = dt.ToString("yyyyMMddHHmmss"); string path = common_path + @"\" + user_id; string file = new_time + ".py"; utils.saveFile(code, path, file); //utils.copyFile(path + @"\" + file, common_path + @"\" + file); // save to mongodb //string hashName = NameHashTool.HashGivenString(strategy_id); //HashTool.HashNameAndPassword(hashName, userInfo.Password, out string hashCode); //userInfo.Password = hashCode; var strategy_code = new StrategyInMongo { StrategyId = strategy_id, Code = code }; var filter = Builders <StrategyInMongo> .Filter.Eq("StrategyId", strategy_code.StrategyId); var checkCode = _strategy_code.Find(filter).FirstOrDefault(); if (checkCode != null) // 策略代码已经存在 { var update = Builders <StrategyInMongo> .Update.Set("Code", code); _strategy_code.UpdateOne(filter, update); } else { _strategy_code.InsertOne(strategy_code); } //checkCode = _strategy_code.Find(filter).FirstOrDefault(); var data = new { save_file = "ok" }; return(Helper.JsonConverter.BuildResult(data)); } }