public IAsyncResult BeginProcessRequest (HttpContext context, AsyncCallback cb, object extraData) { m_asyncResult = new NuxleusAsyncResult(cb, extraData); using (XmlWriter writer = XmlWriter.Create(context.Response.Output)) { bool useMemcached = (bool)context.Application["usememcached"]; MemcachedClient client = (MemcachedClient)context.Application["memcached"]; HttpCookieCollection cookieCollection = context.Request.Cookies; String hostAddress = context.Request.UserHostAddress; LatLongLocation location; String guid = "not-set"; String openid = "not-set"; if (hostAddress == "127.0.0.1") { //hostAddress = Dns.GetHostAddresses(Dns.GetHostName()).GetValue(0).ToString(); hostAddress = "66.93.224.237"; } if (context.Request.QueryString.Count > 0) { if (context.Request.QueryString.Get("ip") != null) { hostAddress = context.Request.QueryString.Get("ip"); } } if (useMemcached && client != null) { if (client.KeyExists(hostAddress)) { location = new LatLongLocation(((String)client.Get(hostAddress)).Split(new char[] { '|' })); } else { location = new LatLongLocation(GetIPLocation(hostAddress)); client.Add(hostAddress, LatLongLocation.ToDelimitedString("|", location)); } } else { location = new LatLongLocation(GetIPLocation(hostAddress)); } if (cookieCollection.Count > 0) { try { guid = cookieCollection.Get("guid").Value; openid = cookieCollection.Get("openid").Value; } catch (Exception e) { Console.WriteLine(e.Message); } } writer.WriteStartDocument(); writer.WriteStartElement("message", "http://nuxleus.com/message/response"); writer.WriteStartElement("session"); writer.WriteStartAttribute("session-id"); writer.WriteString(guid); writer.WriteEndAttribute(); writer.WriteStartAttribute("openid"); writer.WriteString(openid); writer.WriteEndAttribute(); writer.WriteEndElement(); writer.WriteStartElement("request-date"); writer.WriteString(DateTime.Now.ToLongDateString()); writer.WriteEndElement(); writer.WriteStartElement("request-guid"); writer.WriteString(Guid.NewGuid().ToString()); writer.WriteEndElement(); writer.WriteStartElement("geo"); writer.WriteStartElement("city"); writer.WriteString(location.City); writer.WriteEndElement(); writer.WriteStartElement("country"); writer.WriteString(location.Country); writer.WriteEndElement(); writer.WriteStartElement("lat"); writer.WriteString(location.Lat); writer.WriteEndElement(); writer.WriteStartElement("long"); writer.WriteString(location.Long); writer.WriteEndElement(); writer.WriteEndElement(); // Begin navigation section //IEnumerator pathEnumerator = context.Request.FilePath.Split(new char[] { '/' }).GetEnumerator(); writer.WriteStartElement("navigation"); writer.WriteStartElement("path"); writer.WriteElementString("Home", "/"); writer.WriteElementString("Profile", "./profile"); //for (int i = 0; pathEnumerator.MoveNext(); i++) //{ // writer.WriteElementString("path", ((string)pathEnumerator.Current)); //} writer.WriteEndElement(); writer.WriteStartElement("member"); writer.WriteElementString("blog", "./blog"); writer.WriteElementString("event", "./event"); writer.WriteEndElement(); writer.WriteEndElement(); writer.WriteEndElement(); writer.WriteEndDocument(); } m_asyncResult.CompleteCall(); return m_asyncResult; }
public IAsyncResult BeginProcessRequest(HttpContext context, AsyncCallback cb, object extraData) { HttpRequest request = context.Request; Dictionary<string, string> cookies = new Dictionary<string, string>(m_cookieDict); m_request = context.Request; m_response = context.Response; m_cookieCollection = context.Request.Cookies; m_asyncResult = new NuxleusAsyncResult(cb, extraData); string ip = m_request.UserHostAddress; for (var i = 0; i < m_cookieCollection.Count; i++ ) { cookies[m_cookieCollection[i].Name] = m_cookieCollection[i].Value; } if (ip == "::1" || ip == "127.0.0.1") //ip = GetLocalIPAddress(); ip = "75.169.248.106"; LatLongLocation location = new LatLongLocation(GetIPLocation(ip)); NameValueCollection form = request.Form; //IPLocation.DefaultCity = "Salt Lake City"; //IPLocation.DefaultCountry = "UNITED STATES"; //IPLocation location = new IPLocation(ip); //Select task = new Select { DomainName = "account", SelectExpression = String.Format("select name from account where itemName() = '{0}'", "0123456") }; //IResponse response = task.Invoke(); //TextReader tReader = new StringReader(response.Response); //XmlReader reader = XmlReader.Create(tReader); XDocument doc = new XDocument( new XDeclaration("1.0", "UTF-8", "yes"), new XElement(r + "message", new XAttribute("id", Guid.NewGuid()), new XAttribute("date", DateTime.Now.Date), new XAttribute("time", DateTime.Now.TimeOfDay), new XElement(r + "session", new XAttribute("id", cookies["sessionid"]), new XElement(r + "name", cookies["name"]), new XElement(r + "username", cookies["username"]), new XElement(r + "userid", cookies["userid"]), new XElement(r + "uservalidated", cookies["uservalidated"]), new XElement(r + "preferences", new XElement(r + "location", new XElement(r + "country", (cookies["location:country"] == "not-set") ? location.Country : cookies["location:country"]), new XElement(r + "region", (cookies["location:region"] == "not-set") ? location.Region : cookies["location:region"]), new XElement(r + "city", (cookies["location:city"] == "not-set") ? location.City : cookies["location:city"]) ), new XElement(r + "address", new XElement(r + "street", (cookies["address:street"] == "not-set") ? location.Country : cookies["address:street"]), new XElement(r + "region", (cookies["address:region"] == "not-set") ? location.Region : cookies["address:region"]), new XElement(r + "city", (cookies["address:city"] == "not-set") ? location.City : cookies["address:city"]), new XElement(r + "postalCode", (cookies["address:postalCode"] == "not-set") ? location.City : cookies["address:postalCode"]) ) ) ), new XElement(r + "geo", new XElement(r + "lat", location.Lat), new XElement(r + "long", location.Long), new XElement(r + "city", location.City), new XElement(r + "country", location.Country), new XElement(r + "region", location.Region), new XElement(r + "postalCode", location.PostalCode), new XElement(r + "areaCode", location.AreaCode), new XElement(r + "ip", ip) ) ) ); string xmlOutput = null; XmlWriterSettings settings = new XmlWriterSettings(); settings.Encoding = Encoding.UTF8; using (XmlWriter writer = XmlWriter.Create(m_response.Output, settings)) { doc.Save(writer); writer.Flush(); } m_asyncResult.CompleteCall(); return m_asyncResult; }
public static string ToDelimitedString (string delimiter, LatLongLocation location) { return String.Join(delimiter, location.LocationArray); }