Exemple #1
0
        public System.Net.WebRequest SetResourceData(string id, string dataname, ResourceDataType datatype, System.IO.Stream outStream, System.IO.Stream content, Utility.StreamCopyProgressDelegate callback)
        {
            if (m_sessionID == null)
                throw new Exception("Connection is not yet logged in");

            NameValueCollection param = new NameValueCollection();
            param.Add("OPERATION", "SETRESOURCEDATA");
            param.Add("VERSION", "1.0.0");
            param.Add("SESSION", m_sessionID);
            param.Add("CLIENTAGENT", m_userAgent);
            if (m_locale != null)
                param.Add("LOCALE", m_locale);

            param.Add("RESOURCEID", id);
            param.Add("DATANAME", dataname);
            param.Add("DATATYPE", datatype.ToString());

            //This does not appear to be used anywhere in the MG WebTier code
            //anyway, set this if stream supports seeking
            if (content.CanSeek)
                param.Add("DATALENGTH", content.Length.ToString());

            string boundary;
            System.Net.WebRequest req = PrepareFormContent(outStream, out boundary);

            EncodeFormParameters(boundary, param, outStream);
            AppendFormContent("DATA", "content.bin", boundary, outStream, content, callback);

            req.ContentLength = outStream.Length;
            return req;
        }
Exemple #2
0
        /// <summary>
        /// Writes a value/file to a form-multipart HttpRequest stream
        /// </summary>
        /// <param name="name">The name of the parameter</param>
        /// <param name="filename">The name of the file uploaded, set to null if this parameter is not a file</param>
        /// <param name="boundary">The request boundary string</param>
        /// <param name="responseStream">The stream to write to</param>
        /// <param name="dataStream">The stream to read from. When using non-file parameters, use UTF8 encoding</param>
        private void AppendFormContent(string name, string filename, string boundary, System.IO.Stream responseStream, System.IO.Stream dataStream, Utility.StreamCopyProgressDelegate callback)
        {
            string contenttype;
            if (filename == null)
            {
                filename = "";
                contenttype = "";
            }
            else
            {
                filename = " filename=\"" + filename + "\"";
                contenttype = "\r\nContent-Type: application/octet-stream";
            }

            byte[] headers = System.Text.Encoding.UTF8.GetBytes(string.Concat(new String[] { "Content-Disposition: form-data; name=\"" + name + "\";" + filename , "\"", contenttype, "\r\n\r\n"}));
            responseStream.Write(headers, 0, headers.Length);

            Utility.CopyStream(dataStream, responseStream, callback, 0);

            byte[] footer =  System.Text.Encoding.UTF8.GetBytes("\r\n--" + boundary + "\r\n");
            responseStream.Write(footer, 0, footer.Length);
        }
Exemple #3
0
        public System.Net.WebRequest ApplyPackage(System.IO.Stream filestream, Utility.StreamCopyProgressDelegate callback)
        {
            if (m_sessionID == null)
                throw new Exception("Connection is not yet logged in");

            NameValueCollection param = new NameValueCollection();
            param.Add("OPERATION", "APPLYRESOURCEPACKAGE");
            param.Add("VERSION", "1.0.0");
            param.Add("SESSION", m_sessionID);
            param.Add("MAX_FILE_SIZE", "100000000");
            param.Add("CLIENTAGENT", m_userAgent);
            if (m_locale != null)
                param.Add("LOCALE", m_locale);

            string boundary;
            System.IO.MemoryStream outStream = new System.IO.MemoryStream();
            System.Net.WebRequest req = PrepareFormContent(outStream, out boundary);
            req.Timeout = 1000 * 60 * 5; //Wait up to five minutes

            EncodeFormParameters(boundary, param, outStream);

            /*try { req.ContentLength = outStream.Length + filestream.Length; }
            catch {}*/

            System.IO.Stream s = req.GetRequestStream();

            Utility.CopyStream(outStream, s);
            outStream.Dispose();

            AppendFormContent("PACKAGE", "package.mgp", boundary, s, filestream, callback);
            s.Close();

            return req;
        }