internal string ToHTML() { string result = string.Empty; if (VariableName.Contains("Log")) { Log log = Log.ParseFromHTML(VariableName); for (int i = Odds.Count() - 1; i >= 0; i--) { log.SetPower(i); if (Odds[i] != (double)0) { result += Odds[i] > (Fraction)0 ? "+" : "-"; result += i < Odds.Count() - 1 ? " " : ""; result += Odds[i].Abs() > (Fraction)1 || i == 0 ? $"{Odds[i].Abs()}" : ""; result += i > 0 ? $"{log.ToHTML()} " : ""; } } } else if (VariableName.Contains("power")) { VariableName = VariableName.Replace("power", ""); PowerFunc powerFunc = PowerFunc.ParseFromHTML(VariableName); for (int i = Odds.Count() - 1; i >= 0; i--) { powerFunc.SetPower(i); if (Odds[i] != (double)0) { result += Odds[i] > (Fraction)0 ? "+" : "-"; result += i < Odds.Count() - 1 ? " " : ""; if (Odds[i].IntDenominator == 0) { result += Odds[i].Abs() != (Fraction)1 || i == 0 ? $"{Odds[i].Abs()}{(i != 0 ? "⋅" : "")}" : ""; } else { result += Odds[i].Abs() != 1 || i == 0 ? $"{Odds[i].Abs().ToHTML()}{(i != 0 ? "⋅" : "")}" : ""; } result += i > 0 ? $"{powerFunc.ToHTML()} " : ""; } } } else { for (int i = Odds.Count() - 1; i >= 0; i--) { if (Odds[i] != (double)0) { result += Odds[i] > (Fraction)0 ? "+" : "-"; result += i < Odds.Count() - 1 ? " " : ""; result += Odds[i].Abs() > (Fraction)1 || i == 0 ? $"{Odds[i].Abs()}" : ""; result += i > 0 ? $"{VariableName}" : ""; result += i > 1 ? $"<sup>{i}</sup> " : " "; } } } result = result.Trim('+'); result = result.Trim(' '); return($"{result}"); }
private void AddNewVariableCommandAction() { var model = new VariableModel { VariableName = VariableName.Replace(" ", "_"), VariableValue = VariableValue, UserDefined = true }; Variables.Add(model); }
private void SetValue() { Expect.IsTrue(this.VariableName.StartsWith(BoxServer.VariablePrefix), "Invalid variableName specified"); Expect.IsTrue(this.VariableName.EndsWith(BoxServer.VariableSuffix), "Invalid variableName specified"); string property = VariableName.Replace(BoxServer.VariablePrefix, string.Empty).Replace(BoxServer.VariableSuffix, string.Empty); string[] split = property.Split('.'); foreach (string propertyName in split) { PropertyInfo propInfo = this.currentlyReading.GetType().GetProperty(propertyName); if (propInfo != null) { if (propInfo.PropertyType == typeof(string) || propInfo.PropertyType == typeof(int) || propInfo.PropertyType == typeof(long) || propInfo.PropertyType == typeof(decimal) || propInfo.PropertyType == typeof(DateTime) || propInfo.PropertyType == typeof(bool)) { object val = propInfo.GetValue(this.currentlyReading, null); this.Value = val != null?val.ToString() : string.Empty; if (propInfo.PropertyType == typeof(bool)) { this.Value = this.Value.ToLower(); } } else { this.currentlyReading = propInfo.GetValue(this.currentlyReading, null); } } else { this.IsValid = false; return; } } }
private void tvScriptVariables_DoubleClick(object sender, EventArgs e) { //handle double clicks outside if (tvScriptVariables.SelectedNode == null) { return; } //if parent was selected return if (tvScriptVariables.SelectedNode.Parent == null) { //user selected top parent return; } //top node check var topNode = GetSelectedTopNode(); if (topNode.Text != "My Task Variables") { return; } string VariableName, VariableValue; TreeNode parentNode; if (tvScriptVariables.SelectedNode.Nodes.Count == 0) { parentNode = tvScriptVariables.SelectedNode.Parent; VariableName = tvScriptVariables.SelectedNode.Parent.Text; VariableValue = tvScriptVariables.SelectedNode.Text.Replace(_leadingValue, "").Replace(_emptyValue, ""); } else { parentNode = tvScriptVariables.SelectedNode; VariableName = tvScriptVariables.SelectedNode.Text; VariableValue = tvScriptVariables.SelectedNode.Nodes[0].Text.Replace(_leadingValue, "").Replace(_emptyValue, ""); } if (VariableName.Replace("{", "").Replace("}", "") == "ProjectPath") { return; } //create variable editing form frmAddVariable addVariableForm = new frmAddVariable(VariableName, VariableValue); addVariableForm.ScriptVariables = ScriptVariables; ExpandUserVariableNode(); //validate if user added variable if (addVariableForm.ShowDialog() == DialogResult.OK) { //remove parent parentNode.Remove(); //add newly edited node AddUserVariableNode(_userVariableParentNode, addVariableForm.txtVariableName.Text, addVariableForm.txtDefaultValue.Text); LastModifiedVariableName = addVariableForm.txtVariableName.Text; } }