void IComponent.Append(ref Dictionary<string, object> variables,IOutputWriter writer) { object var = null; try { Type t = Type.GetType(_type, true); ConstructorInfo ci = null; foreach (ConstructorInfo c in t.GetConstructors()) { if ((_pars.Count == 0) && (c.GetParameters().Length == 0)) { ci = c; break; } else { bool isOkay = c.GetParameters().Length==_pars.Count; foreach (ParameterInfo pi in c.GetParameters()) { if (!_pars.ContainsKey("@" + pi.Name)) { isOkay = false; break; } } if (isOkay) { ci = c; break; } } } if (ci != null) { object[] pars = new object[_pars.Count]; StringOutputWriter swo = new StringOutputWriter(); for (int x = 0; x < pars.Length; x++) { ParameterInfo pi = ci.GetParameters()[x]; string tmp = ""; foreach (IComponent ic in _pars["@" + pi.Name]) { swo.Clear(); ic.Append(ref variables, swo); tmp += swo.ToString(); } pars[x] = Convert.ChangeType(tmp, pi.ParameterType); } var = ci.Invoke(pars); } } catch (Exception e) { EventController.TriggerEvent(new ErrorOccuredEvent(e)); Log.Error(e); } if (variables.ContainsKey(_varName)) variables.Remove(_varName); variables.Add(_varName, var); }
public override void Append(ref Dictionary<string, object> variables, IOutputWriter writer) { StringOutputWriter swo = new StringOutputWriter(); object obj = null; bool found = false; if (_val is ParameterComponent) obj = ((ParameterComponent)_val).GetObjectValue(variables); else { found = true; swo.Clear(); _val.Append(ref variables, swo); if (_val is GenericComponent) { obj = Utility.LocateObjectInVariables(swo.ToString(), variables); if (obj == null) writer.Append(swo.ToString().Length.ToString()); } else writer.Append(swo.ToString().Length.ToString()); } if (obj != null) { if (obj is ArrayList) writer.Append(((ArrayList)obj).Count.ToString()); else if (obj is IDictionary) writer.Append(((IDictionary)obj).Count.ToString()); else if (obj is string) writer.Append(((string)obj).Length.ToString()); else { int cnt = 0; foreach (object o in (IEnumerable)obj) cnt++; writer.Append(cnt.ToString()); } }else if (!found) writer.Append("-1"); }
public override void Append(ref Dictionary<string, object> variables, Org.Reddragonit.Stringtemplate.Outputs.IOutputWriter writer) { StringOutputWriter swo = new StringOutputWriter(); Decimal? d = null; try { _val.Append(ref variables, swo); d = Decimal.Parse(swo.ToString()); } catch (Exception e) { if (_val is GenericComponent) { swo.Clear(); _val.Append(ref variables, swo); string str = Utility.GenerateStringFromObject(Utility.LocateObjectInVariables(swo.ToString(), variables)); if (str != null) { try { d = Decimal.Parse(str); } catch (Exception ex) { d = null; } } } } if (d.HasValue) { if (d.Value % 2 == 0) writer.Append(true.ToString()); else writer.Append(false.ToString()); } else writer.Append(false.ToString()); }
public override void Append(ref Dictionary<string, object> variables, Org.Reddragonit.Stringtemplate.Outputs.IOutputWriter writer) { StringOutputWriter swo = new StringOutputWriter(); _eval.Append(ref variables,swo); string tmp = swo.ToString(); swo.Clear(); _search.Append(ref variables, swo); string search = swo.ToString(); swo.Clear(); _replace.Append(ref variables, swo); string replace = swo.ToString(); if ((tmp != null)&&(search!=null)&&(replace!=null)) { if (search.StartsWith("\"") && search.EndsWith("\"")) search = search.Substring(1, search.Length - 2); else if (search.StartsWith("'") && search.EndsWith("'")) search = search.Substring(1, search.Length - 2); if (replace.StartsWith("\"") && replace.EndsWith("\"")) replace = replace.Substring(1, replace.Length - 2); else if (replace.StartsWith("'") && replace.EndsWith("'")) replace = replace.Substring(1, replace.Length - 2); writer.Append(tmp.Replace(search, replace)); } }
void IComponent.Append(ref Dictionary<string, object> variables, IOutputWriter writer) { ClassQuery cq = new ClassQuery(_namespace, _query); List<IDbDataParameter> pars = new List<IDbDataParameter>(); StringOutputWriter swo = new StringOutputWriter(); foreach (string str in _parameters.Keys) { string par = ""; foreach (IComponent ic in _parameters[str]) { swo.Clear(); ic.Append(ref variables, swo); par += swo.ToString(); } pars.Add(cq.CreateParameter(str, par)); } cq.Execute(pars.ToArray()); object var = new ArrayList(); while (cq.Read()) { Hashtable ht = new Hashtable(); for (int x = 0; x < cq.FieldCount; x++) { if (!cq.IsDBNull(x)) { ht.Add(cq.GetName(x), cq[x]); } } ((ArrayList)var).Add(ht); } cq.Close(); if (((ArrayList)var).Count == 1 && ((Hashtable)((ArrayList)var)[0]).Count == 1) { Hashtable tmp = (Hashtable)((ArrayList)var)[0]; var = tmp; object[] objAr = new object[1]; ((Hashtable)var).Values.CopyTo(objAr, 0); var = objAr[0]; } if (variables.ContainsKey(_variableName)) variables.Remove(_variableName); variables.Add(_variableName, var); }
public void Append(ref Dictionary<string, object> variables, IOutputWriter writer) { StringOutputWriter swo = new StringOutputWriter(); object obj = null; Type t = null; object[] objs = new object[_components.Count]; if (_constructor) { t = Utility.LocateType(_constructorCall); foreach (ConstructorInfo c in t.GetConstructors()) { if (c.GetParameters().Length == _components.Count) { try { for (var x = 0; x < objs.Length; x++) { IComponent ic = _components[x]; if (ic is ParameterComponent) objs[x] = Convert.ChangeType(((ParameterComponent)ic).GetObjectValue(variables), c.GetParameters()[x].ParameterType); else { swo.Clear(); ic.Append(ref variables, swo); objs[x] = Convert.ChangeType(swo.ToString(), c.GetParameters()[x].ParameterType); } } obj = c.Invoke(objs); break; } catch (Exception e) { } } } } else if (_staticCall) { t = Utility.LocateType(_constructorCall.Substring(0, _constructorCall.LastIndexOf("."))); MethodInfo mi = null; foreach (MethodInfo m in t.GetMethods(BindingFlags.Static|BindingFlags.Public)) { if (m.Name == _constructorCall.Substring(_constructorCall.LastIndexOf(".") + 1)) { if (m.GetParameters().Length == _components.Count) { mi = m; break; } } } if (mi != null) { for (var x = 0; x < objs.Length; x++) { IComponent ic = _components[x]; if (ic is ParameterComponent) objs[x] = Convert.ChangeType(((ParameterComponent)ic).GetObjectValue(variables), mi.GetParameters()[x].ParameterType); else { swo.Clear(); ic.Append(ref variables, swo); objs[x] = Convert.ChangeType(swo.ToString(), mi.GetParameters()[x].ParameterType); } } obj = mi.Invoke(null, objs); } } else if (_isArray) { obj = new ArrayList(); foreach (IComponent ic in _components) { if (ic is ParameterComponent) ((ArrayList)obj).Add(Convert.ChangeType(((ParameterComponent)ic).GetObjectValue(variables), _variableType)); else { swo.Clear(); ic.Append(ref variables, swo); ((ArrayList)obj).Add(Convert.ChangeType(swo.ToString(), _variableType)); } } } else { if (_components.Count == 1) { if (_components[0] is ParameterComponent) obj = Convert.ChangeType(((ParameterComponent)_components[0]).GetObjectValue(variables), _variableType); else { swo.Clear(); _components[0].Append(ref variables, swo); obj = Convert.ChangeType(swo.ToString(), _variableType); } } else { swo.Clear(); foreach (IComponent ic in _components) ic.Append(ref variables, swo); obj = Convert.ChangeType(swo.ToString(),_variableType); } } if (variables.ContainsKey(_variableName)) variables.Remove(_variableName); variables.Add(_variableName, obj); }
public void Append(ref Dictionary<string, object> variables, IOutputWriter writer) { if (_components == null) { foreach (IComponent comp in _group.Components) { if (((SubTemplateComponent)comp)._functionReg.ToString() == _functionReg.ToString()) { _components = ((SubTemplateComponent)comp).Components; break; } } } Dictionary<string, object> vars = new Dictionary<string, object>(); if (_it != null) { StringOutputWriter swo = new StringOutputWriter(); _it.Append(ref variables, swo); vars.Add("it", swo.ToString()); } else { foreach (string str in _parameterMap.Keys) { object obj = Utility.LocateObjectInVariables(_parameterMap[str], variables); if (obj != null) vars.Add(str, obj); } } string ret = ""; foreach (IComponent comp in _components) { comp.Append(ref vars, writer); } }
public void Append(ref Dictionary<string, object> variables, IOutputWriter writer) { StringOutputWriter swo = new StringOutputWriter(); foreach (IfStatement state in _statements) { swo.Clear(); state.Condition.Append(ref variables, swo); if (Utility.IsComponentTrue(swo.ToString())) { foreach (IComponent child in state.Children) child.Append(ref variables, writer); break; } } }
public override string ToString(){ if (_tokenized == null) _tokenized = _tokenizer.TokenizeStream(_templateGroup); StringOutputWriter writer = new StringOutputWriter(); foreach (IComponent comp in _tokenized) comp.Append(ref _parameters,writer); return writer.ToString(); }
public void Append(ref Dictionary<string, object> variables, IOutputWriter writer) { string ret = "false"; StringOutputWriter swo = new StringOutputWriter(); _left.Append(ref variables, swo); string l = swo.ToString(); swo.Clear(); _right.Append(ref variables, swo); string r = swo.ToString(); swo.Clear(); switch (_type) { case CompareType.EQUAL: ret = Utility.StringsEqual(l, r).ToString(); break; case CompareType.GREATER_THAN: if (_regNumber.IsMatch(l) && _regNumber.IsMatch(r)) ret = (decimal.Parse(l) > decimal.Parse(r)).ToString(); else ret = ((l != null) && ((r == null) || (l.CompareTo(r) > 0))).ToString(); break; case CompareType.GREATER_THAN_OR_EQUAL_TO: if (_regNumber.IsMatch(l) && _regNumber.IsMatch(r)) ret = (decimal.Parse(l) >= decimal.Parse(r)).ToString(); else ret = (((l == null) && (r == null)) || ((l != null) && ((r == null) || (l.CompareTo(r) >= 0)))).ToString(); break; case CompareType.LESS_THAN: if (_regNumber.IsMatch(l) && _regNumber.IsMatch(r)) ret = (decimal.Parse(l) < decimal.Parse(r)).ToString(); else ret = ((r != null) && ((l == null) || l.CompareTo(r) < 0)).ToString(); break; case CompareType.LESS_THAN_OR_EQUAL_TO: if (_regNumber.IsMatch(l) && _regNumber.IsMatch(r)) ret = (decimal.Parse(l) <= decimal.Parse(r)).ToString(); else ret = (((l == null) && (r == null)) || ((r != null) && ((l == null) || l.CompareTo(r) <= 0))).ToString(); break; case CompareType.NOT_EQUAL: if (_regNumber.IsMatch(l) && _regNumber.IsMatch(r)) ret = (decimal.Parse(l) != decimal.Parse(r)).ToString(); else ret = (!Utility.StringsEqual(l, r)).ToString(); break; case CompareType.SIMILAR_TO: ret = Utility.StringContainsString(l, r).ToString(); break; case CompareType.NOT_SIMILAR_TO: ret = (!Utility.StringContainsString(l, r)).ToString(); break; } writer.Append(ret); }