private void threadHandler() { byte[] inData = new byte[4096]; FileInfo fi = new FileInfo(localFile); HttpWebRequest req = (HttpWebRequest)WebRequest.Create(uri); req.ContentType = "multipart/form-data; boundary=" + bounds; req.AllowWriteStreamBuffering = true; req.Method = "POST"; // we need the request stream Stream reqStream = req.GetRequestStream(); writeField("xmlrsp", "true", reqStream); writeField("agentkey", AppController.sKwxClient.agentKey, reqStream); writeField("name", name, reqStream); // add the file... reqStream.Write(PREFIX, 0, PREFIX.Length); reqStream.Write(boundary, 0, boundary.Length); reqStream.Write(NEWLINE, 0, NEWLINE.Length); // write content header string t = "Content-Disposition: form-data; name=\"" + name + "\"; filename=\"" + fi.Name + "\""; inData = encoding.GetBytes(t); reqStream.Write(inData, 0, inData.Length); reqStream.Write(NEWLINE, 0, NEWLINE.Length); t = "Content-Type: " + mimeType; inData = encoding.GetBytes(t); reqStream.Write(inData, 0, inData.Length); reqStream.Write(NEWLINE, 0, NEWLINE.Length); reqStream.Write(NEWLINE, 0, NEWLINE.Length); // write content inData = new byte[1024]; FileStream rdr = File.OpenRead(localFile); //FileStream rdr = new FileStream(localFile, FileMode.Open); int bytesRead = (int)rdr.Length; AppController.sProgBar.bumpUp(); int total = 0; bytesRead = rdr.Read(inData, 0, 1024); while (bytesRead > 0) { reqStream.Write(inData, 0, bytesRead); bytesRead = rdr.Read(inData, 0, 1024); total += bytesRead; } rdr.Close(); // add last boundary reqStream.Write(NEWLINE, 0, NEWLINE.Length); reqStream.Write(PREFIX, 0, PREFIX.Length); reqStream.Write(boundary, 0, boundary.Length); // reqStream.Write(PREFIX, 0, PREFIX.Length); reqStream.Write(NEWLINE, 0, NEWLINE.Length); reqStream.Close(); try { HttpWebResponse response = (HttpWebResponse)req.GetResponse(); StreamReader sr = new StreamReader(response.GetResponseStream()); string pageData = sr.ReadToEnd(); sr.Close(); XMLement xml = XMLement.createFromRawXml(pageData); if (xml != null) { if (xml.tag == "medium-insert-rsp") { xml = AppController.sKwxClient.addMedium(xml.getAttributeValue("id")); } } if ((AppController.sQuitting == false) && callb != null) { callb(); } } catch (IOException) { } if (AppController.sQuitting == false) { AppController.sProgBar.bumpDown(); } }
void navPointReceive(XMLement xml, float lat, float lon) { if (mIsActive) { XMLement poi = xml.getChildByName("poi-hit"); XMLement ugc = xml.getChildByName("ugc-hit"); if (poi != null) { List <string> pois = new List <string>(); for (int i = 0; ; i++) { XMLement t = xml.getChild(i); if (t == null) { break; } if (t.tag == "poi-hit") { string poiId = t.getAttributeValue("id"); if (!mHitPOI.Contains(poiId)) { mHitPOI.Add(poiId); pois.Add(poiId); } } } if (pois.Count > 0) { doPoi(pois); } } if (ugc != null) { List <XMLement> ugcs = new List <XMLement>(); for (int i = 0; ; i++) { XMLement t = xml.getChild(i); if (t == null) { break; } if (t.tag == "ugc-hit") { string ugcId = t.getAttributeValue("id"); if (!mHitUGC.Contains(ugcId)) { mHitUGC.Add(ugcId); ugcs.Add(t); } } } if (ugcs.Count > 0) { doUgcs(ugcs); } } XMLement msg = xml.getChildByName("msg"); if (msg != null) { string text = msg.nodeText; if (text == "roam" && checkStruinWithUser == true) { checkStruinWithUser = false; doCheckStruin(0, ""); } } } }
/// <summary> /// login, select app and make a track /// currently no error recovery... /// </summary> public void start() { if (messageCallback != null) { messageCallback("login: "******"login-rsp") { StreamWriter userProps = new StreamWriter(AppController.sUserProps); if (userProps != null) { AppController.sUserName = mUser; AppController.sUserPass = mPass; userProps.WriteLine(mUser); userProps.WriteLine(mPass); userProps.Close(); } if (messageCallback != null) { messageCallback("login: succesful!"); } } else { return; } x = selectApp(); if (x != null) { if (messageCallback != null) { string s = x.toString(); messageCallback("select-app: succesful!"); } } mSendSamplesThread = new Thread(sendSamplesThread); mSendSamplesThread.Start(); XMLement xml = new XMLement(Protocol.TAG_UGC_OFF_REQ); lock (this) { xml = utopiaRequest(xml); } x = getRouteList(); if (x != null) { AppController.sRoutes = x; if (messageCallback != null) { string s = x.toString(); messageCallback("got route list!"); } } AppController.sActiveRoute = null; x = navState(); if (x != null) { string s = x.getAttributeValue("routeid"); if (s != null && s != "") { AppController.sActiveRoute = AppController.sRoutes.getChildForAttribute("id", s); AppController.sActiveRouteID = int.Parse(s); AppController.sActiveRouteMapPathHor = null; AppController.sActiveRouteMapPathVer = null; if (AppController.sActiveRoute == null) { AppController.sActiveRouteID = -1; } } if (messageCallback != null) { messageCallback("get_state: succesful!"); ; // do something with nav state } } x = doNavStart(); }