public override Task WriteResponseBodyAsync(OutputFormatterWriteContext context, Encoding selectedEncoding) { var @object = CResponse.Generate(context.Object, (HttpStatusCode)context.HttpContext.Response.StatusCode); var newContext = new OutputFormatterWriteContext(context.HttpContext, context.WriterFactory, typeof(CResponse), @object); newContext.ContentType = context.ContentType; newContext.ContentTypeIsServerDefined = context.ContentTypeIsServerDefined; return(base.WriteResponseBodyAsync(newContext, selectedEncoding)); }
public JObject FunctionHandler(JObject input, ILambdaContext context) { //input. Console.WriteLine("JObject:" + Regex.Replace(input.ToString(), @"\t|\n|\r", "")); CResponse response = new CResponse(); string action = input["action"].ToString(); LambdaLogger.Log("action: " + action); System.Console.Out.WriteLine("Starting calculation"); try { switch (action) { case "getProfesiones": // Retorna Listado De objetos response.Exito = true; response.Response["getProfesiones"] = JToken.FromObject(CProfesion.List()); break; case "getUser": { CUser user = new CUser(); string key = input["key"].ToString(); string mail = input["mail"].ToString(); string clave = input["clave"].ToString(); int id = int.Parse(input["id"].ToString()); Console.WriteLine("Inside getUser "); user = CUser.Load(id, mail, clave, key); // Retorna Un Objeto response.Exito = true; response.Response = JObject.FromObject(user); } break; case "getSearch": COfertaSearch of = new COfertaSearch(); of.IDProfesion = int.Parse(input["IDProfesion"].ToString()); List <COfertaResult> lr = COferta.getOfertas(of); response.Exito = true; response.Response["getSearch"] = JToken.FromObject(lr); break; case "editarPerfil": { CUser user = new CUser(); bool bolExito = false; string mail = input["mail"].ToString(); string clave = input["clave"].ToString(); int id = int.Parse(input["id"].ToString()); string nombre = input["nombre"].ToString(); string apaterno = input["apaterno"].ToString(); string amaterno = input["amaterno"].ToString(); int rating = int.Parse(input["rating"].ToString()); string link_foto = input["link_foto"].ToString(); string link_cv = input["link_cv"].ToString(); string descripcion = input["descripcion"].ToString(); Console.WriteLine("Inside getUser "); user.Mail = mail; user.Clave = clave; user.Id = id; user.Nombre = nombre; user.APaterno = apaterno; user.AMaterno = amaterno; user.Rating = rating; user.Avatar = link_foto; user.CV = link_cv; user.Descripcion = descripcion; bolExito = user.Update(); // Retorna Un Objeto response.Exito = bolExito; } break; case "insProfesion": { int idP = 0; CProfesion prof = new CProfesion(); string nombre = input["nombre"].ToString(); prof.Nombre = nombre; idP = prof.Create(); if (idP > 0) { response.Exito = true; } } break; default: { CUser user = new CUser(); user.Nombre = action; } break; } } catch (Exception ex) { LambdaLogger.Log(ex.ToString()); response.Exito = true; } Console.WriteLine("Response From Function:" + response.ToString()); return(JObject.FromObject(response)); }
//---------------------------------------------------------------------------------------------------- // UpdateReponseList //---------------------------------------------------------------------------------------------------- public void UpdateReponseList(CResponse response) { if (m_intCurIdx < 0) return; // no reponse to update if (response.m_intScore > 0) m_intTotalCorrect++; m_lsResponse [m_intCurIdx].m_lsSelectedStimulusIdx = new List<int> (response.m_lsSelectedStimulusIdx); m_lsResponse [m_intCurIdx].m_intScore = response.m_intScore; m_lsResponse [m_intCurIdx].m_intCoinNum = response.m_intCoinNum; /*for (int k = 0; k < m_lsResponse.Count; k++) { for (int i = 0; i < m_lsResponse[k].m_lsSelectedStimulusIdx.Count; i++) Debug.Log ("*** CTrialList - UpdateReponseList - selectedIdx = " + m_lsResponse[k].m_lsSelectedStimulusIdx [i]); Debug.Log ("*** CTrialList - UpdateReponseList - Score = " + m_lsResponse[k].m_intScore + " - coinNum = " + m_lsResponse[k].m_intCoinNum); }*/ }
//---------------------------------------------------------------------------------------------------- // LoadTrials: load from xml file all stimuli's images, audio and target index for all trials/challenges //---------------------------------------------------------------------------------------------------- public void LoadTrials(int intLevel) { m_intCurLevel = intLevel; // if xml has already been loaded, then return //if (m_lsTrial.Count > 0) return; m_lsTrial.Clear (); m_lsResponse.Clear (); // which triallist to load string strTrialList = ""; switch (intLevel) { case 0: strTrialList = "level01-N2-xml"; break; case 1: strTrialList = "level02-N1-xml"; break; case 2: strTrialList = "level03-N4-xml"; break; case 3: strTrialList = "level04-V3-xml"; break; case 4: strTrialList = "level05-PRN2-xml"; break; case 5: strTrialList = "level06-N5-xml"; break; case 6: strTrialList = "level07-N6-xml"; break; case 7: strTrialList = "level08-V2-xml"; break; case 8: strTrialList = "level09-V1-xml"; break; case 9: strTrialList = "level10-A1-xml"; break; case 10: strTrialList = "level11-A2-xml"; break; case 11: strTrialList = "level12-V4-xml"; break; case 12: strTrialList = "level13-PREP1-xml"; break; case 13: strTrialList = "level14-PREP2-xml"; break; case 14: strTrialList = "level11-A2-xml"; break; case 15: strTrialList = "level07-N6-xml"; break; case 16: strTrialList = "level08-V2-xml"; break; case 17: strTrialList = "level04-V3-xml"; break; default: break; } // load xml //XElement root = XElement.Load(strXmlFile); //TextAsset textAsset = Resources.Load("Doc/triallist") as TextAsset; TextAsset textAsset = Resources.Load("Doc/" + strTrialList) as TextAsset; XElement root = XElement.Parse(textAsset.text); m_lsTrial = ( from el in root.Elements("node") select new CTrial { m_lsStimulus = ( from el2 in el.Elements("stimulus") select new CStimulus { m_strName = (string)el2.Element("name"), m_strImage = (string)el2.Element("image"), m_strType = (string)el2.Element("type"), } ).ToList(), m_strTargetAudio = (string)el.Element("targetAudio"), m_intTargetIdx = (int)el.Element("targetIdx") } ).ToList(); // shuffle stimuli in each trial for (var i = 0; i < m_lsTrial.Count; ++i) m_lsTrial [i].RandomizeStimuli (); // shuffle trials in m_lsTrial using Knuth shuffle algorithm :: courtesy of Wikipedia for (int t = 0; t < m_lsTrial.Count; t++ ) { CTrial tmp = m_lsTrial[t]; int r = UnityEngine.Random.Range(t, m_lsTrial.Count); m_lsTrial[t] = m_lsTrial[r]; m_lsTrial[r] = tmp; } //tell the score master how many questions we're asking ScoreMaster.SetQuestionAmount(m_lsTrial.Count); // add empty responses for (var i = 0; i < m_lsTrial.Count; ++i) { CResponse res = new CResponse(); m_lsResponse.Add(res); } // reset current idx m_intCurIdx = -1; m_intTotalCorrect = 0; }