public ManagerResponseObj ChatMessages() { Searchwar_netEntities db = new Searchwar_netEntities(); GetChatMessagesColumnNoPosition p = new GetChatMessagesColumnNoPosition() { userid = user.UserID }; List <SW_ChatMessage> result = GetFastChatMessages(db, p).ToList <SW_ChatMessage>(); XElement chatRootTag = new XElement("chat"); chatRootTag.Add(new XElement("ci")); XElement chatitemsTag = chatRootTag.Descendants("ci").Single(); if (result != null) { if (result.Count() > 0) { List <SW_ChatMessage> chats = new List <SW_ChatMessage>(); foreach (SW_ChatMessage citem in result) { if (!chats.Any(c => c.ChatId == citem.ChatId)) { chats.Add(citem); } } foreach (SW_ChatMessage citem in chats) { XElement createChatTag = new XElement("i", new XAttribute("id", citem.ChatId)); foreach (SW_ChatMessage mitem in result.Where(c => c.ChatId == citem.ChatId)) { createChatTag.Add(new XElement("m", new XAttribute("ui", mitem.ChatPersonId.ToString()), new XAttribute("d", mitem.ChatMsgDateAdded.ToString()), new XElement("t", mitem.ChatMsgText))); } chatitemsTag.Add(createChatTag); } chats = null; } } ManagerResponseObj mro = new ManagerResponseObj(); mro.DataObject = result; mro.Xml = chatRootTag; db.Dispose(); return(mro); }
public void ProcessRequest(HttpContext context) { context.Response.ClearHeaders(); context.Response.ContentType = "text/xml"; context.Response.ContentEncoding = Encoding.UTF8; context.Response.StatusCode = 202; context.Response.SubStatusCode = 202; context.Response.Status = "202 continue"; context.Response.StatusDescription = "continue"; //try //{ string action = context.Request.QueryString["action"]; string mngOption = context.Request.QueryString["option"]; string outputData = ""; SearchEngineMng engineMng = null; string currentUserIp = "62.107.21.129"; if (action == "1") { //Guid newId = new Guid(context.Request.QueryString["searchmathid"]); //Guid userid = new Guid(context.Request.QueryString["userid"]); //ANOProfile.SaveCookies(currentUserIp, newId, userid); context.Session["chatmessages"] = null; context.Session["searchresult"] = null; } if (!string.IsNullOrEmpty(mngOption)) { for (int i = 0; i < 2 * 60; i++) { if (context.Response.IsClientConnected) { outputData = null; XDocument createMngXml = new XDocument(new XDeclaration("1.0", "iso-8859-1", "true"), new XElement("manager")); XElement root = createMngXml.Descendants("manager").Single(); XElement insertsearchX = null; ManagerResponseObj chatobjresponse = null; ManagerResponseObj searchobjresponse = null; if (mngOption.ToLower().Contains("chat")) { ChatSystem cs = new ChatSystem(context, currentUserIp); chatobjresponse = cs.ChatMessages(); if (chatobjresponse.DataObject != null) { List <Guid> chatMsgIds = new List <Guid>(); if (context.Session["chatmessages"] != null) { chatMsgIds = (List <Guid>)context.Session["chatmessages"]; } foreach (Searchwar_netModel.SW_ChatMessage item in ((List <Searchwar_netModel.SW_ChatMessage>)chatobjresponse.DataObject)) { chatMsgIds.Add(item.ChatMsgId); } context.Session["chatmessages"] = chatMsgIds; } root.Add(chatobjresponse.Xml); } if (mngOption.ToLower().Contains("search")) { engineMng = new SearchEngineMng(currentUserIp, context, action); // insert search data to server searchobjresponse = engineMng.SearchNow(); insertsearchX = searchobjresponse.Xml; if (searchobjresponse.DataObject != null) { List <Guid> searchIds = new List <Guid>(); if (context.Session["searchresult"] != null) { searchIds = (List <Guid>)context.Session["searchresult"]; } foreach (SearchObject item in ((List <SearchObject>)searchobjresponse.DataObject)) { searchIds.Add(item.SearchWarID); } context.Session["searchresult"] = searchIds; } if (insertsearchX == null) { outputData = ""; } else { if (searchobjresponse.DataObject != null && chatobjresponse.DataObject != null) { if (((List <SearchObject>)searchobjresponse.DataObject).Count() > 0 || ((List <Searchwar_netModel.SW_ChatMessage>)chatobjresponse.DataObject).Count() > 0 || engineMng.isValid == false) { root.Add(insertsearchX); // Write/save data StringWriter sw = new StringWriter(); XmlWriterSettings xws = new XmlWriterSettings(); xws.CheckCharacters = false; xws.ConformanceLevel = ConformanceLevel.Auto; xws.Indent = false; xws.OmitXmlDeclaration = false; XmlWriter w = XmlWriter.Create(sw, xws); createMngXml.Save(w); w.Close(); outputData = sw.ToString(); sw.Close(); } } } } context.Response.Write(outputData); context.Response.Write(" "); context.Response.Flush(); if (engineMng.isValid == false || !string.IsNullOrEmpty(outputData)) { engineMng.Close(); context.Response.End(); context.Response.Close(); return; } // wait (performance) Thread.Sleep(5000); } } } engineMng.Close(); //} //catch (Exception ex) //{ // context.Response.ClearContent(); // context.Response.Write("<?xml version='1.0'?><manager><error>" + ex.Source + ": " + ex.Message + "</error></manager>"); // context.Response.Write(" "); // context.Response.Flush(); // // do nothing //} context.Response.End(); context.Response.Close(); return; }
public ManagerResponseObj SearchNow() { bool isUpdateInfoSucces = true; List <SearchObject> searchResult = new List <SearchObject>(); // default option if (userOption != SearchWar.SearchEngine.SearchEngine.UserSearchOption.CreateUserSearch) { userOption = SearchWar.SearchEngine.SearchEngine.UserSearchOption.UpdateUserSearch; } if (isValid == true) { // Update user activity if (userOption == SearchWar.SearchEngine.SearchEngine.UserSearchOption.UpdateUserSearch) { isUpdateInfoSucces = engine.GetUserMatchInfo(usi); } // Validate DateTimes if (isUpdateInfoSucces == true) { if (TimeNowValidate(usi.SearchMatchStart) == true) { if (DateNowValidate(usi.SearchMatchStart) != true) { isValid = false; errorMessage = "FromDateIsSmallerThanDateNow"; } } else { isValid = false; errorMessage = "FromTimeIsSmallerThanTimeNow"; } } else { isValid = false; errorMessage = "UserSearchMatchIsNotOnline"; } if (isValid == true) { SearchEngine.SearchNoticeMessage searchNotice = SearchWar.SearchEngine.SearchEngine.SearchNoticeMessage.Searching; const int defaultMaxResult = 10; const int defaultPageIndex = 0; const int defaultMaxSearchTimeSeconds = 1200; const int defaultMinUserActivitySeconds = 10; const int defaultFromLastSeconds = 10; searchResult = engine.UserSearchMatch(usi, userOption, defaultMaxResult, defaultPageIndex, currentLangId, defaultMaxSearchTimeSeconds, defaultMinUserActivitySeconds, out searchNotice, defaultFromLastSeconds, context); } } // create search root XElement getSearchsElement = new XElement("search"); ManagerResponseObj mro = new ManagerResponseObj(); mro.DataObject = searchResult; mro.Xml = getSearchsElement; // items element getSearchsElement.Add(new XElement("is")); // Get element "is" for "Items" XElement getItemsElement = getSearchsElement.Descendants("is").Single(); if (isValid == true) { if (searchResult != null) { if (searchResult.Count() > 0) { // Insert/Create data as xml for (int i = 0; i < searchResult.Count(); i++) { var s = searchResult[i]; // Create element data getItemsElement.Add( new XElement("i", new XAttribute("id", s.SearchWarID.ToString()), new XElement("cn", s.ClanName), new XElement("ct", new XAttribute("i", s.ClanContinentData.SearchWarContinentId), s.ClanContinentData.SearchWarContinentName), new XElement("cy", new XAttribute("i", s.ClanCountryData.SearchWarCountrytId), new XAttribute("t", s.ClanCountryData.SearchWarCountryTLD), s.ClanCountryData.SearchWarCountryName), new XElement("cs", new XAttribute("i", s.ClanSkillData != null ? s.ClanSkillData.SearchWarSkillId.ToString() : ""), s.ClanSkillData != null ? s.ClanSkillData.SearchWarSkillName : ""), new XElement("st", new XAttribute("i", s.SearchContinentData.SearchWarContinentId), s.SearchContinentData.SearchWarContinentName), new XElement("sy", new XAttribute("i", s.SearchCountryData != null ? s.SearchCountryData.SearchWarCountrytId.ToString() : ""), new XAttribute("t", s.SearchCountryData != null ? s.SearchCountryData.SearchWarCountryTLD : ""), s.SearchCountryData != null ? s.SearchCountryData.SearchWarCountryName : ""), new XElement("ss", new XAttribute("i", s.SearchSkillData != null ? s.SearchSkillData.SearchWarSkillId.ToString() : ""), s.SearchSkillData != null ? s.SearchSkillData.SearchWarSkillName : ""), new XElement("g", new XAttribute("i", s.SearchGame.SearchWarGameId), s.SearchGame.SearchWarGameName), new XElement("gt", new XAttribute("i", s.SearchGameType != null ? s.SearchGameType.SearchWarGameTypeId.ToString() : ""), s.SearchGameType != null ? s.SearchGameType.SearchWarGameTypeName : ""), new XElement("fd", mngInfo.ConvertDateTimeFromUtc(s.SearchMatchStart).ToString()), new XElement("x", s.SearchXvs), new XElement("y", s.SearchvsX), new XElement("m", s.SearchMap))); } } else { return(mro); } } else { return(mro); } } // write status for result getSearchsElement.Add(new XElement("status", new XAttribute("bool", isValid.ToString()), errorMessage)); return(mro); }