private void Page_Load(object sender, System.EventArgs e) { // Put user code to initialize the page here FormulaSpace fs = FormulaSpace.Read(FmlFile); string s = Request.Form[ddlFormula.UniqueID]; FindFormula(fs, s); if (CurrentProgram != null) { lParam.Text = "<table border=1 cellspacing=0 cellpadding=3><tr><td>Name</td><td>Default Value</td><td>Minimum Value</td><td>Maxmum Value</td></tr>"; foreach (FormulaParam fpm in CurrentProgram.Params) { lParam.Text += "<tr><td>"; lParam.Text += fpm.Name + "</td><td>"; string Value = fpm.DefaultValue; string r = "__Param" + fpm.Name; if (Request.Form[r] != null) { Value = Request.Form[r]; } lParam.Text += "<input Name=" + r + " value=" + Value + "></td><td>"; lParam.Text += fpm.MinValue + "</td><td>"; lParam.Text += fpm.MaxValue + "</td></tr>"; } lParam.Text += "</table>"; lFullName.Text = CurrentProgram.FullName; lDescription.Text = CurrentProgram.Description.Replace("\n", "<br>"); lCode.Text = Server.HtmlEncode(CurrentProgram.Code).Replace("\n", "<br>"); } }
private void Bind() { string FmlFile = Config.PluginsDirectory + "Scan.fml"; FormulaSpace fs = FormulaSpace.Read(FmlFile); string s = Request.Form[ddlFormula.UniqueID]; if (s == null && ddlFormula.Items.Count > 0) { s = ddlFormula.Items[0].Value; } FindFormula(fs, s); if (CurrentProgram != null) { lParam.Text = "<table border=1 cellspacing=0 cellpadding=3><tr><td>Name</td><td>Default Value</td><td>Minimum Value</td><td>Maxmum Value</td></tr>"; foreach (FormulaParam fpm in CurrentProgram.Params) { lParam.Text += "<tr><td>"; lParam.Text += fpm.Name + "</td><td>"; string Value = fpm.DefaultValue; string r = "__Param" + fpm.Name; lParam.Text += "<input Name=" + r + " value=" + Value + "></td><td>"; lParam.Text += fpm.MinValue + "</td><td>"; lParam.Text += fpm.MaxValue + "</td></tr>"; } lParam.Text += "</table><br>"; lFullName.Text = CurrentProgram.FullName; lDescription.Text = CurrentProgram.Description.Replace("\n", "<br>"); lCode.Text = Server.HtmlEncode(CurrentProgram.Code).Replace("\n", "<br>"); } }
private void FindFormula(FormulaSpace fs, string Formula) { foreach (FormulaProgram fp in fs.Programs) { if (Formula == null) { if (CurrentProgram == null) { CurrentProgram = fp; } } else if (Formula == fp.Name) { CurrentProgram = fp; } if (!IsPostBack) { ddlFormula.Items.Add(new ListItem(fp.FullName, fp.Name)); } } foreach (FormulaSpace fsc in fs.Namespaces) { FindFormula(fsc, Formula); } }
private void LoadToTree(TreeNode tn, FormulaSpace fs, string FullName) { tn.Text = fs.Name; foreach (FormulaSpace n in fs.Namespaces) { TreeNode t = new TreeNode(); t.ImageUrl = Root() + "/Images/Namespace.bmp"; tn.Nodes.Add(t); if (n.GroupOnly) { LoadToTree(t, n, FullName); } else { LoadToTree(t, n, FullName + "." + n.Name); } } foreach (FormulaProgram p in fs.Programs) { TreeNode t = new TreeNode(); t.ImageUrl = Root() + "/Images/Program.bmp"; t.NavigateUrl = "Explore.aspx?Id=" + Index++ + "&File=" + ddlFormulaFile.SelectedItem.Value; tn.Nodes.Add(t); LoadToTree(t, p, FullName + "." + p.Name); } }
private void LoadToTree(FormulaSpace fs) { Index = 0; FormulaTree.Nodes.Clear(); FormulaTree.Nodes.Add(new TreeNode()); LoadToTree(FormulaTree.Nodes[0], fs, "FML"); }
private void btnOK_Click(object sender, System.EventArgs e) { //Create a Formula namespace FormulaSpace fms = new FormulaSpace("FML"); //Create a Formula program , set Formula name and script code on the fly FormulaProgram fp = new FormulaProgram(); fp.Name = tbFormulaName.Text; fp.Code = tbProgramScript.Text; //Add the script program to the Formula namespace fms.Programs.Add(fp); //Add parameters to Formula program for (int i = 1; i < 5; i++) { if (Request.Form["tbParamName" + i] != "") { fp.Params.Add(new FormulaParam( Request.Form["tbParamName" + i], Request.Form["tbDefValue" + i], Request.Form["tbMinValue" + i], Request.Form["tbMaxValue" + i], FormulaParamType.Double)); } } try { //Compile the Formula script on the fly Assembly a = fms.CompileInMemory(); FormulaBase fb = FormulaBase.GetFormulaByName(a, fms.Name + "." + fp.Name); //Create YahooDataManager , Get stock data from yahoo. YahooDataManager ydm = new YahooDataManager(); ydm.CacheRoot = HttpRuntime.AppDomainAppPath + "Cache\\"; CommonDataProvider DataProvider = (CommonDataProvider)ydm[tbCode.Text]; //Create financial chart instance FormulaChart fc = new FormulaChart(); fc.PriceLabelFormat = "{CODE}"; fc.LatestValueType = LatestValueType.Custom; fc.AddArea("MAIN", 3); fc.AddArea(fb); fc.DataProvider = DataProvider; fc.SetSkin(Config.DefaultSkin); //Show the temp image just created lChart.Text = "<img src=ImageFromCache.aspx?CacheId=" + fc.SaveToImageStream(440, 440, ImageFormat.Png, 0, 0) + ">"; } catch (FormulaErrorException fee) { //Show the compile result if the script has some errors lChart.Text = fee.ToHtml(); } }
private void BindData() { string F = Request.QueryString["File"]; if (F != null && F != "") { ListItem li = ddlFormulaFile.Items.FindByText(F); if (li != null) { foreach (ListItem l in ddlFormulaFile.Items) { l.Selected = false; } li.Selected = true; } } string PluginsRoot = Config.PluginsDirectory; if (PluginsRoot == null) { PluginsRoot = HttpRuntime.BinDirectory; } string FileName = PluginsRoot + ddlFormulaFile.SelectedItem.Value; FormulaSpace fs = FormulaSpace.Read(FileName); string Id = Request.Params["Id"]; if (Id == null || Id == "") { CurrentId = -1; } else { CurrentId = int.Parse(Id); } CurrentName = Request.Params["Name"]; LoadToTree(fs); if (CurrentProgram == null) { TreeNode t = FormulaTree.Nodes[0]; while (t.Nodes.Count > 0) { t.Expanded = true; t = t.Nodes[0]; } tdChart.Visible = false; } else { for (object o = CurrentNode; !(o is TreeView); o = ((TreeNode)o).Parent) { ((TreeNode)o).Expanded = true; } FormulaTree.SelectedNodeIndex = CurrentNode.GetNodeIndex(); lParam.Text = "<table border=1><tr><td>Name</td><td>Default Value</td><td>Minimum Value</td><td>Maxmum Value</td></tr>"; foreach (FormulaParam fpm in CurrentProgram.Params) { lParam.Text += "<tr><td>"; lParam.Text += fpm.Name + "</td><td>"; string Value = fpm.DefaultValue; string r = "__Param" + fpm.Name; if (Request.Form[r] != null && Request.Form[r] != "") { Value = Request.Form[r]; } lParam.Text += "<input Name=" + r + " value=\"" + Value + "\"></td><td>"; lParam.Text += fpm.MinValue + "</td><td>"; lParam.Text += fpm.MaxValue + "</td></tr>"; } lParam.Text += "</table><br>"; lName.Text = CurrentProgram.Name; lFullName.Text = CurrentProgram.FullName; lDescription.Text = "<br>" + CurrentProgram.Description.Replace("\n", "<br>"); lCode.Text = "<br>" + ReplaceMethodWithColor( ReplaceMethodWithColor(Server.HtmlEncode(CurrentProgram.Code), "#008000", CurrentProgram.Params.GetParamList(), false) ).Replace("\n", "<br>"); lMainView.Visible = CurrentProgram.IsMainView; } }
protected void btnOK_Click(object sender, System.EventArgs e) { //Create a Formula namespace FormulaSpace fms = new FormulaSpace("FML"); //Create a Formula program , set Formula name and script code on the fly FormulaProgram fp = new FormulaProgram(); fp.Name = tbFormulaName.Text; fp.Code = tbProgramScript.Text; //Add the script program to the Formula namespace fms.Programs.Add(fp); //Add parameters to Formula program for (int i = 1; i < 5; i++) { if (Request.Form["tbParamName" + i] != "") { fp.Params.Add(new FormulaParam( Request.Form["tbParamName" + i], float.Parse(Request.Form["tbDefValue" + i]), float.Parse(Request.Form["tbMinValue" + i]), float.Parse(Request.Form["tbMaxValue" + i]))); } } try { //Compile the Formula script on the fly Assembly a = fms.CompileInMemory(HttpRuntime.BinDirectory); FormulaBase fb = FormulaBase.GetFormulaByName(a, fms.Name + "." + fp.Name); //Create YahooDataManager , Get stock data from yahoo. YahooDataManager ydm = new YahooDataManager(); ydm.CacheRoot = HttpRuntime.AppDomainAppPath + "Cache\\"; CommonDataProvider DataProvider = (CommonDataProvider)ydm[tbCode.Text]; //Create financial chart instance FormulaChart fc = new FormulaChart(); fc.AddArea("MAIN", 3); fc.AddArea(fb); fc.DataProvider = DataProvider; fc.SetSkin(Config.DefaultSkin); //Show the temp image just created lChart.Text = "<img src=ImageFromCache.aspx?CacheId=" + fc.SaveToImageStream(440, 440, ImageFormat.Png, 0, 0) + ">"; } catch (FormulaErrorException fee) { //Show the compile result if the script has some errors lChart.Text = "<font color=red>"; foreach (System.CodeDom.Compiler.CompilerError ce in fee.ces) { FormulaProgram fpa = fms.GetProgramByLineNum(ce.Line); if (fpa != null) { fpa.AdjustErrors(ce); lChart.Text += string.Format("Name:{0} line:{1} column:{2} error:{3} {4}<br>", fpa.Name, ce.Line, ce.Column, ce.ErrorNumber, ce.ErrorText); } } lChart.Text += "</font>"; } }