using SteamWare; using System; using System.Collections.Generic; using System.Diagnostics; using System.Web.Script.Serialization; using System.Web.Script.Services; using System.Web.Services; namespace MoonPro.WS { /// /// Descrizione di riepilogo per MPData /// [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [System.ComponentModel.ToolboxItem(false)] // Per consentire la chiamata di questo servizio Web dallo script utilizzando ASP.NET AJAX, rimuovere il commento dalla riga seguente. [ScriptService] public class MPData : System.Web.Services.WebService { [WebMethod] public string HelloWorld() { return "Hello World"; } [WebMethod] [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)] public void randomData(int numVal) { JavaScriptSerializer js = new JavaScriptSerializer(); Context.Response.Clear(); Context.Response.ContentType = "application/json"; // genero numVal valori random inizio/fine... int maxMinutes = 5; Random random = new Random(); visjsDsItem[] items = new visjsDsItem[numVal]; DateTime lastDate = DateTime.Now.AddDays(-7); DateTime endDate; int lancio = 0; string currCSS = "sv"; for (int i = 0; i < numVal; i++) { lancio = random.Next(10); if (lancio <= 7) { currCSS = "sv"; } else if (lancio <= 8) { currCSS = "sg"; } else { currCSS = "sr"; } endDate = lastDate.AddSeconds(random.Next(maxMinutes * 60)); items[i] = new visjsDsItem() { id = i, content = string.Format("Random data {0}", i), start = lastDate.ToString("yyyy-MM-dd HH:mm"), end = endDate.ToString("yyyy-MM-dd HH:mm"), group = "1", // per mostrare multi macchine type = "background", // importante x non vedere bordi... className = currCSS }; lastDate = endDate; } Context.Response.Write(js.Serialize(items)); } [WebMethod] [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)] public void seqStati(string idxMacch, string dataFrom, string dataTo, int numSplit) { Stopwatch stopwatch = new Stopwatch(); intervalloDate _intervallo = new intervalloDate() { inizio = Convert.ToDateTime(dataFrom), fine = Convert.ToDateTime(dataTo) }; string rKey = string.Format("jsonSeq_MIF_{0}_{1}_{2}_{3}", idxMacch, numSplit, _intervallo.inizio.ToString("yyyyMMdd_HHmmss"), _intervallo.fine.ToString("yyyyMMdd_HHmmss")).Replace(" ", "_"); //logger.lg.scriviLog("Nome key: " + rKey); // oggetti x proseguire... JavaScriptSerializer js = new JavaScriptSerializer() { MaxJsonLength = Int32.MaxValue / 2 }; Context.Response.Clear(); Context.Response.ContentType = "application/json"; string answ = ""; //creo un oggetto timeline fatto da GROUPS + ITEMS bool needRecalc = true; string redJson = memLayer.ML.getRSV(rKey); // controllo se ho già in sessione un oggetto seq... if (redJson != null && redJson != "") { try { needRecalc = false; answ = redJson; logger.lg.scriviLog("Recuperato jsonSeq " + rKey); } catch { } } if (needRecalc) { logger.lg.scriviLog(string.Format("Inizio calcolo dati per {0}", rKey)); // recupero GRUPPI List tlGroups; { resoconti _resoconti = new resoconti(); tlGroups = _resoconti.groupsVisJS(idxMacch); } // recupero ITEMS List tlSerie; { resoconti _resoconti = new resoconti(); intervalloDate intervallo = new intervalloDate(); intervallo.fine = Convert.ToDateTime(dataTo); intervallo.inizio = Convert.ToDateTime(dataFrom); tlSerie = _resoconti.sequenzaDatiVisJS(idxMacch, intervallo, numSplit); } // opzioni! visjsDsOptions opzioni = new visjsDsOptions { stack = false, horizontalScroll = true, moveable = true, zoomable = true, start = dataFrom, end = dataTo }; // unisco oggetti timelineVisJs fullData = new timelineVisJs { Groups = tlGroups, Items = tlSerie, Options = opzioni }; answ = js.Serialize(fullData); // salvo in sessione l'oggetto... secondo durata impostata in web.config.. memLayer.ML.setRSV(rKey, answ, 60 * memLayer.ML.CRI("seqCacheDurMin")); logger.lg.scriviLog(string.Format("Salvataggio in sessione jsonSeq {0} effettuato", rKey)); } Context.Response.Write(answ); } [WebMethod] [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)] public void getData() { JavaScriptSerializer js = new JavaScriptSerializer(); Context.Response.Clear(); Context.Response.ContentType = "application/json"; Random random = new Random(); int i = 1; DateTime lastDate = DateTime.Now; int maxMinutes = 60; visjsDsItem item = new visjsDsItem() { id = i, content = string.Format("Random data {0}", i), start = lastDate.ToString("yyyy-MM-dd HH:mm"), end = lastDate.AddHours(random.Next(maxMinutes)).ToString("yyyy-MM-dd HH:mm"), group = "1", className = "" }; Context.Response.Write(js.Serialize(item)); } } }