public IndexModule() { Get["/"] = parameters => { var mfc = new MFCClient(); JsonSettings.MaxJsonLength = Int32.MaxValue; Exception socketError = null ; mfc.SocketError += (object s, SocketErrorEventArgs e) => { socketError = e.Exception; }; var processed = false; mfc.UsersProcessed += (s, e) => { processed = true; }; var now = DateTime.Now; var timeout = now.AddSeconds(10); while (!processed && DateTime.Now < timeout && null == socketError) { }; if (null != socketError) return Response.AsJson(new { error = "Socket exception.", exception = socketError }); if (!processed) return Response.AsJson(new { error = "Timed out." }); var res = mfc.Models.Select(x => new { name = x.Name, broadcasterId = x.UserId, state = x.VideoState.ToString(), camscore = x.ModelDetails.Camscore }).OrderByDescending(y => y.camscore); return Response.AsJson(res); }; }
void Page_Load(object sender, EventArgs evt) { var processed = false; var client = new MFCClient(); client.UsersProcessed += (s, e) => { processed = true; }; var now = DateTime.Now; var timeout = now.AddSeconds(30); while (!processed && DateTime.Now < timeout) { }; if (!processed) { Response.Write("Timed out"); Response.End(); } var rawList = client.Users.ToList(); Camscores.DataSource = rawList.Where(model => model.Value.ModelDetails.Camscore > 3000) .Select(user => new { Model = user.Value.Name, CamScore = user.Value.ModelDetails.Camscore }) .OrderByDescending(x => x.CamScore); Camscores.DataBind(); CamscoresGrouped.DataSource = rawList.Where(model => model.Value.ModelDetails.Camscore > 3000) .Select(user => new {Model=user.Value.Name, Camscore = user.Value.ModelDetails.Camscore, Modded=(Math.Truncate((decimal)user.Value.ModelDetails.Camscore / 1000))*1000}) .GroupBy(k => k.Modded) .Select(x => new {Camscore=x.Key, Count = x.Count()}) .OrderByDescending(y=> y.Camscore); CamscoresGrouped.DataBind(); }