public override Map Execute(Map input, ServerFacade sf, ConfigHelper cfg, out bool hasMore, out bool cut) { hasMore = false; var text = this.GetString("content"); var cached = this["cached"] as ScriptEngine; if (cached == null) { var script = new ScriptEngine(); script.References("Solari.Core.dll"); script.Using("Solari.Core"); script.DeclareGlobal("sf", typeof(ServerFacade), sf); script.DeclareGlobal("cfg", typeof(Map), cfg.Data); script.DeclareGlobal("context", typeof(Map), this); try { script.SetCode("public bool Filter(Map input) { " + text + " ; return false; }"); script.Compile(); this["cached"] = script; cut = !(bool)script.Execute("Filter", input); return input; } catch (Exception ex) { throw new ScriptingException(ex); } } else { var script = cached; try { cut = !(bool)script.Execute("Filter", input); return input; } catch (Exception ex) { throw new ScriptingException(ex); } } }
public static Map FromHashtable(Hashtable h) { Map ret = new Map(); foreach (object k in h.Keys) ret.Add(k, h[k]); return ret; }
public virtual int ExecuteSql(string query, Map map) { if (_sf == null) return ServerFacade.ExecuteNonQueryQs(ModelHelper.Instance.ShortName(_baseType),query, map); else return _sf.InstanceExecuteNonQuery(_sf.GetSQLFromQueryStore(ModelHelper.Instance.ShortName(_baseType), query), map); }
public Modifica(ServerFacade sf, Map map) { this.Copy(map); if (this.IsModificaAnagrafica || this.IsModificaProfilo) { Map anagrafica = Utils.Read(sf, "SELECT * FROM anagrafico a, profilo p WHERE a.id = @_iKey_int AND p.idUtilizzatore = a.id AND p.dataInizio < @_dtAdesso AND (p.DataFine IS NULL OR p.DataFine > @_dtAdesso)", this); this["anagrafica"] = anagrafica; this["ufficio"] = Utils.Read(sf, "SELECT * FROM UnitaPianta WHERE id = @_iIdUfficioVisitato", anagrafica); } else if (this.IsModificaImmagine) { Map anagrafica = Utils.Read(sf, "SELECT * FROM anagrafico a, profilo p WHERE a.id = @_iKey_int AND p.idUtilizzatore = a.id AND p.dataInizio < @_dtAdesso AND (p.DataFine IS NULL OR p.DataFine > @_dtAdesso)", this); Image img = Utils.ReadImageFile(anagrafica.GetString("imgdip")); if (img != null) { this["immagine"] = Utils.ResizeImage(img, 200, 200); this["immaginethumb"] = Utils.ResizeImage(img, 80, 80); } } else if (this.IsModificaVisite) { Map visita = Utils.Read(sf, "SELECT * FROM visite WHERE codicebadge = @Key_char AND datainiziobadge = @_dtKey_date", this); Map anagrafica = Utils.Read(sf, "SELECT a.*, p.* FROM badge b, anagrafico a, profilo p WHERE b.codicebadge = @Key_char AND b.datainiziobadge = @_dtKey_date AND b.idUtilizzatore = a.id AND p.idUtilizzatore = a.id AND p.dataInizio < @_dtAdesso AND (p.DataFine IS NULL OR p.DataFine > @_dtAdesso)", this); this["visita"] = visita; this["anagrafica"] = anagrafica; this["visitato"] = Utils.Read(sf, "SELECT * FROM anagrafico a, profilo p WHERE a.id = @_iIdVisitato AND p.idUtilizzatore = a.id AND p.dataInizio < @_dtAdesso AND (p.DataFine IS NULL OR p.DataFine > @_dtAdesso)", visita); this["ufficio"] = Utils.Read(sf, "SELECT * FROM UnitaPianta WHERE id = @_iIdUfficioVisitato", anagrafica); } else if (this.IsModificaTimbratura) { this["presenti"] = Utils.ReadValue(sf.InstanceExecuteReader("SELECT MAX(id) FROM PresentiPerArea", new Map()), 0); } else if (this.IsModificaUtenti) { this["utente"] = Utils.Read(sf, "SELECT * FROM Utenti WHERE id = @_iKey_int", this); } }
public virtual IDataReader GetReader(string query, Map map) { IDataReader rdr = _sf == null ? ServerFacade.ExecuteReaderQs(ModelHelper.Instance.ShortName(_baseType), query, map): _sf.InstanceExecuteReader(_sf.GetSQLFromQueryStore(ModelHelper.Instance.ShortName(_baseType), query), map); return rdr; }
public static Map FillMap(ArrayList vett, string keyField) { var ret = new Map(); foreach (Map m in vett) ret[m.GetString(keyField)] = m; return ret; }
public override Map Execute(Map input, ServerFacade sf, ConfigHelper cfg, out bool hasMore, out bool cut) { var mc = new MiniClient(Utils.EvalExpression(this.GetString("content"), input).Trim(), 60000); var data = mc.Get(""); hasMore = cut = false; return Map.FromJsonObject(data); }
public static string RenderTemplateToString(string templateFile, Map map) { NVelocity.VelocityContext vc = new NVelocity.VelocityContext(map); using (StringWriter contentWriter = new StringWriter()) { VelocityHelper.RenderTemplateToWriter(templateFile, contentWriter, vc); return contentWriter.ToString(); } }
public string DoPrettyPrint(Map map) { StringBuilder sb = new StringBuilder(); _newLine = true; sb.AppendLine("{"); DoPrettyPrint(map, sb, 1); sb.AppendLine("}"); return sb.ToString(); }
private Map ExecuteUnit(UnitOfWork unit, Map input, ServerFacade sf, ConfigHelper cfg, out bool hasMore, out bool cut) { try { return unit.Execute(input, sf, cfg, out hasMore, out cut); } catch (Exception ex) { _logger.Log(string.Format("Errore nell'esecuzione della unit {0}", unit.Label), ex); throw; } }
public override Map Execute(Map input, ServerFacade sf, ConfigHelper cfg, out bool hasMore, out bool cut) { hasMore = false; cut = false; string testo; if (VelocityHelper.RenderStringTemplateToString(this.GetString("content"), input, out testo) && testo.Length > 0) SendMail(input, cfg.Data); return input; }
private void WriteCsvMap(TextWriter writer, Map map, string[] fields) { var sb = new StringBuilder(); foreach (var field in fields) { if (sb.Length > 0) sb.Append(','); sb.Append(MakeValueCsvFriendly(map[field])); } writer.WriteLine(sb.ToString()); }
public static string EvalExpression(string expression, Map vars) { int pos1, pos2; for (pos1 = expression.IndexOf('@'); pos1 != -1; pos1 = expression.IndexOf('@', pos1)) { for (pos2 = pos1 + 1; pos2 < expression.Length; pos2++) if (!IsIdentifier(expression[pos2])) break; string var = expression.Substring(pos1, pos2 - pos1); expression = expression.Replace(var, vars.GetString(var.Substring(1))); } return expression; }
public override Map Execute(Map input, ServerFacade sf, ConfigHelper cfg, out bool hasMore, out bool cut) { hasMore = cut = false; var fields = this.GetString("fields").Split(','); var data = Utils.SelectValues(input, this.GetString("path")); if (data != null) using (TextWriter tw = new StreamWriter(Utils.EvalExpression(this.GetString("outfile"), input))) { foreach (Map map in data) WriteCsvMap(tw, map, fields); } return input; }
public void Load(XmlElement el) { _units = new ArrayList(); var list = el.SelectNodes("unit"); if (list != null) foreach (XmlNode n in list) if (n.Attributes != null) { var map = new Map(); foreach (XmlAttribute a in n.Attributes) map[a.Name] = a.Value; if (n is XmlElement) map["content"] = (n as XmlElement).InnerText; _units.Add(map); } }
public override Map Execute(Map input, ServerFacade sf, ConfigHelper cfg, out bool hasMore, out bool cut) { var vett = Utils.SelectValues(input, this.GetString("path")); var ret = new Map(); var idx = -1; if (vett != null) { idx = this.GetInt("__IDX__", 0); this["__IDX__"] = idx + 1; if (idx < vett.Count) ret = vett[idx] as Map; } hasMore = vett != null && idx < vett.Count - 1; cut = false; return ret; }
private void DoPrettyPrint(Map map, StringBuilder sb, int indent) { ArrayList keyArray = new ArrayList(map.Keys); keyArray.Sort(); for (int i = 0; i < keyArray.Count; i++) { string key = keyArray[i] as string; object val = map[key]; if (i > 0) { sb.AppendLine(","); _newLine = true; } sb.Append(' ', indent * 4).Append('\"').Append(key).Append('\"').Append(':'); _newLine = false; PrettyPrintValue(val, sb, indent); } }
public static UnitOfWork GetUnitOfWork(Map map) { var cached = map["cached"] as UnitOfWork; if (cached != null) { Logger.InfoFormat("Trova in cache la UnitOfWork id {0}", cached.Uid); return cached; } var def = _mapPlugins.GetMap(map.GetString("type")); if (def == null) { Logger.WarnFormat("Tipo unit sconosciuto {0}", map.GetString("type")); return null; } cached = (UnitOfWork)(Activator.CreateInstance(def["type"] as Type) as UnitOfWork).Copy(map); map["cached"] = cached; Logger.InfoFormat("Mette in cache la UnitOfWork id {0} tipo {1}", cached.Uid, map.GetString("type")); return cached; }
public static string FormatException(Exception ex) { while (ex.InnerException != null) ex = ex.InnerException; string template; Map hint; if (ex is ApplicationError) { ApplicationError ea = (ApplicationError)ex; template = Path.Combine("Errors", ea.Template); hint = ea.Hint; } else { template = Path.Combine("Errors", "Generic.vm"); hint = new Map("msg", ex.Message); } return VelocityHelper.RenderTemplateToString(template, hint); }
public ConfigHelper(string path) { Logger.InfoFormat("Inizializzazione ConfigHelper da {0}", path); _cachedValues = new Map(); var cfg = new Xml(path); using (cfg.Buffer()) { foreach (string section in cfg.GetSectionNames()) { var map = new Map(); _cachedValues[section] = map; foreach (string key in cfg.GetEntryNames(section)) map[key] = cfg.GetValue(section, key); } _cachedValues["ModelloDatabase"] = cfg.GetValue("Settings", "ModelloDatabase", ServerFacade.SqlServer); _cachedValues["StringaDiConnessione"] = Crypto.FastDecrypt(cfg.GetValue("Settings", "StringaDiConnessione", Crypto.FastEncrypt(""))); _cachedValues["MainTimer"] = cfg.GetValue("Settings", "MainTimer", 60); } }
private void InternalExecute(ArrayList units, Map input, ServerFacade sf, ConfigHelper cfg) { if (units.Count == 0) return; var unit = PluginHelper.GetUnitOfWork(units[0] as Map); _logger.Log(string.Format("Inizia l'esecuzione della unit {0}", unit.Label)); // _logger.Debug(PrettyPrinter.PrettyPrint(input)); bool more; do { bool cut; var tempData = input.DeepCopy(); tempData = ExecuteUnit(unit, tempData, sf, cfg, out more, out cut); if (!cut) InternalExecute(new ArrayList(units.GetRange(1, units.Count - 1)), tempData, sf, cfg); if (more) _logger.Log(string.Format("Continua l'esecuzione della unit {0}", unit.Label)); } while (more); }
private void SendMail(Map dati, Map config) { if (dati.GetString("smtpServer") == string.Empty) return; // tratto da http://blogs.ugidotnet.org/PietroLibroBlog/archive/2008/08/06/93635.aspx var message = new MailMessage(); message.From = new MailAddress(dati.GetString("mittente")); message.To.Add(dati.GetString("destinatari")); message.Subject = dati.GetString("oggetto"); message.IsBodyHtml = true; message.Body = dati.GetString("testo"); var smtpClient = new SmtpClient(config.GetString("smtpServer"), config.GetInt("smtpPort", 25)); if (config.ContainsKey("smtpUser")) { smtpClient.UseDefaultCredentials = false; smtpClient.Credentials = new NetworkCredential(config.GetString("smtpUser"), config.GetString("smtpPassword")); } smtpClient.Send(message); }
public static bool RenderStringTemplateToString(string templateString, Map dati, out string ret) { NVelocity.App.VelocityEngine engine = new NVelocity.App.VelocityEngine(); engine.Init(); NVelocity.VelocityContext vc = new NVelocity.VelocityContext(dati); StringBuilder sb = new StringBuilder(); string logMsg = null; bool bOk = false; try { using (StringWriter wr = new StringWriter(sb)) using (StringReader rdr = new StringReader(templateString)) bOk = engine.Evaluate(vc, wr, logMsg, rdr); ret = bOk ? sb.ToString() : logMsg; } catch (Exception e) { Logger.Warn("Errore in RenderStringTemplateToString", e); ret = e.Message; } return bOk; }
public override Map Execute(Map input, ServerFacade sf, ConfigHelper cfg, out bool hasMore, out bool cut) { hasMore = false; if (!this.ContainsKey("__DATA__")) { var text = this.GetString("content"); this["__DATA__"] = Utils.List(sf, text, input); } var vett = this.GetArray("__DATA__"); var ret = new Map(); var idx = -1; if (vett != null) { idx = this.GetInt("__IDX__", 0); this["__IDX__"] = idx + 1; if (idx < vett.Count) ret = vett[idx] as Map; } hasMore = vett != null && idx < vett.Count - 1; cut = false; return ret; }
public static void RenderTemplateToResponse(string templateFile, Map map, bool useMaster) { DisableBrowserCache(); string requestedFormat = HttpContext.Current.Request.QueryString["format"]; if (requestedFormat != null && requestedFormat.ToUpper() == "JSON") { HttpContext.Current.Response.Write(map.ToJson()); return; } if (requestedFormat != null && requestedFormat.ToUpper() == "XML") { HttpContext.Current.Response.ContentType = "text/xml"; map.WriteToXml(HttpContext.Current.Response.Output); return; } NVelocity.VelocityContext vc = new NVelocity.VelocityContext(map); if (useMaster) { vc.Put("childContent", VelocityHelper.RenderTemplateToString(templateFile, map)); vc.Put("templateFile", templateFile); templateFile = VelocityHelper.MASTER_TEMPLATE; } using (StreamWriter pageWriter = new StreamWriter(HttpContext.Current.Response.OutputStream)) VelocityHelper.RenderTemplateToWriter(templateFile, pageWriter, vc); }
public override Map Execute(Map input, ServerFacade sf, ConfigHelper cfg, out bool hasMore, out bool cut) { hasMore = cut = false; var text = this.GetString("content"); var cached = this["cached"] as ScriptEngine; if (cached == null) { System.Diagnostics.Debug.WriteLine("Compila script per " + this.Uid); var script = new ScriptEngine(); script.References("Solari.Core.dll"); script.Using("Solari.Core"); script.DeclareGlobal("sf", typeof (ServerFacade), sf); script.DeclareGlobal("cfg", typeof (Map), cfg.Data); script.DeclareGlobal("context", typeof (Map), this); script.DeclareGlobal("hasMore", typeof (bool), false); try { script.SetCode("public Map DoExecute(Map input) { hasMore = false; " + text + " ; return input; }"); script.Compile(); this["cached"] = script; var ret = script.Execute("DoExecute", input) as Map; hasMore = (bool) script.GlobalGet("hasMore"); return ret; } catch (Exception ex) { throw new ScriptingException(ex); } } else { System.Diagnostics.Debug.WriteLine("Trova in cache script per " + this.Uid); var script = cached; try { var ret = script.Execute("DoExecute", input) as Map; hasMore = (bool)script.GlobalGet("hasMore"); return ret; } catch (Exception ex) { throw new ScriptingException(ex); } } }
public static void ReadfirstRecord(IDataReader rdr, ref Map firstRecord) { using (rdr) if (rdr != null && rdr.Read()) { DbHelper.FillHashtable(rdr, firstRecord); } }
public static ArrayList MakeArray(IDataReader rdr) { ArrayList ret = new ArrayList(); using (rdr) { while (rdr != null && rdr.Read()) { //Map record = new Map(rdr); Map record = new Map(); DbHelper.FillHashtable(rdr, record); ret.Add(record); } } return ret; }
public ApplicationError(string template, Map hint) : base() { _template = template; _hint = hint; }
public ApplicationError(string template) : base() { _template = template; _hint = new Map(); }