Ejemplo n.º 1
0
        void doUgcs(List <XMLement> ugcs)
        {
            AppController.poiHit();


            XMLement raw = XMLement.createFromRawXml("<poi><name>VolksMond</name><description>Door andere gebruikers gemaakte media</description></poi>");
            XMLement mmd = new XMLement("media");

            foreach (XMLement x in ugcs)
            {
                mmd.addChild(x);
            }

            raw.addChild(mmd);

            AppController.sEventLog.WriteLine("hit {0} ugc:", ugcs.Count);
            AppController.sEventLog.WriteLine("\t", raw.toString());

            if (sUgcViewerPage == null)
            {
                sUgcViewerPage = new PoiViewerPage(this);
            }

            if (sUgcViewerPage.setContent(raw))
            {
                mIsActive = false;
                sUgcViewerPage.ShowDialog();
                mBlendTimer.Change(0, 3000);
            }
        }
Ejemplo n.º 2
0
        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();
            }
        }
Ejemplo n.º 3
0
        private XMLement doRequest(XMLement anElement, int lAttempt)
        {
            string url = mServer;

            if (mAgentKey != null)
            {
                url += "?agentkey=" + mAgentKey;
            }
            else
            {
                // login
                url += "?timeout=" + Diwi.Properties.Resources.KwxServerTimeout;
            }

            try {
                // create the web request
                sKwxWebRequest = (HttpWebRequest)WebRequest.Create(url);
                UTF8Encoding encoding  = new UTF8Encoding();
                byte[]       postBytes = encoding.GetBytes(anElement.toString());

                sKwxWebRequest.KeepAlive     = true;
                sKwxWebRequest.Timeout       = 25000;
                sKwxWebRequest.Method        = "POST";
                sKwxWebRequest.ContentType   = "text/xml";
                sKwxWebRequest.ContentLength = postBytes.Length;
                Stream postStream = sKwxWebRequest.GetRequestStream();
                postStream.Write(postBytes, 0, postBytes.Length);
                postStream.Close();

                // make the connect
                HttpWebResponse resp = (HttpWebResponse)sKwxWebRequest.GetResponse();

                // get the page data
                StreamReader sr       = new StreamReader(resp.GetResponseStream());
                string       pageData = sr.ReadToEnd();
                sr.Close();

                // get the status code (should be 200)
                // status = resp.StatusCode;

                // close the connection
                resp.Close();

                AppController.showStatus("");

                return(XMLement.createFromRawXml(pageData));
            } catch (TimeoutException e) {
                AppController.sEventLog.WriteLine("Caught Timeout Excepotion;");
                if (lAttempt < 3)
                {
                    AppController.sEventLog.WriteLine("trying again...");
                    return(doRequest(anElement, lAttempt + 1));
                }
                else
                {
                    AppController.sEventLog.WriteLine("aborting after 3 attemps...");
                }
                AppController.showStatus("");
                return(null);
            } catch (WebException e) {
                AppController.showStatus("");
                string str = string.Format("Caught WebException: {0}", e.Status.ToString());
                AppController.sEventLog.WriteLine(str);
                return(new XMLement("web-exception"));
            } catch (Exception) {
                AppController.showStatus("");
                return(null);
            }
        }