예제 #1
0
            public void MInit()
            {
                HttpWebRequest  request  = null;
                HttpWebResponse response = null;

                try
                {
                    string url = URL(PROCESS_TYPE.MINIT);
                    request           = (HttpWebRequest)WebRequest.Create(url);
                    request.Method    = "POST";
                    request.KeepAlive = false;
                    Utils.SetHeaders(request, "", m_bucket, m_key, "POST");
                    response = HttpWebResponseExt.GetResponseNoException(request);
                    Stream body = response.GetResponseStream();

                    if (response.StatusCode != HttpStatusCode.OK)
                    {
                        string e = UFileErrorSerializer.FormatString(body);
                        throw new Exception(string.Format("{0} {1}", response.StatusDescription, e));
                    }

                    //parsing to get the uploadid & blksize
                    MInitResponse minitRes = new MInitResponse();
                    minitRes.Parse(body);

                    m_uploadid = minitRes.GetUploadId();
                    m_blk_size = minitRes.GetBlkSize();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.ToString());
                    throw;
                }
                finally
                {
                    if (request != null)
                    {
                        request.Abort();
                    }
                    if (response != null)
                    {
                        response.Close();
                    }
                }
            }
예제 #2
0
            public void Parse(Stream stream)
            {
                if (null == stream)
                {
                    throw new Exception("null stream to call MInitResponse.Parse");
                }

                try
                {
                    DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(MInitResponse));
                    MInitResponse obj = (MInitResponse)ser.ReadObject(stream);

                    this.UploadId = obj.GetUploadId();
                    this.BlkSize  = obj.GetBlkSize();
                }catch (Exception e) {
                    Console.WriteLine(e.ToString());
                    throw;
                }
            }
예제 #3
0
파일: Proxy.cs 프로젝트: hsiun/yoyo
            public void MInit()
            {
                HttpWebRequest request = null;
                HttpWebResponse response = null;
                try
                {
                    string url = URL(PROCESS_TYPE.MINIT);
                    request = (HttpWebRequest)WebRequest.Create(url);
                    request.Method = "POST";
                    request.KeepAlive = false;
                    Utils.SetHeaders(request, "", m_bucket, m_key, "POST");
                    response = HttpWebResponseExt.GetResponseNoException(request);
                    Stream body = response.GetResponseStream();

                    if (response.StatusCode != HttpStatusCode.OK)
                    {
                        string e = UFileErrorSerializer.FormatString(body);
                        throw new Exception(string.Format("{0} {1}", response.StatusDescription, e));
                    }

                    //parsing to get the uploadid & blksize
                    MInitResponse minitRes = new MInitResponse();
                    minitRes.Parse(body);

                    m_uploadid = minitRes.GetUploadId();
                    m_blk_size = minitRes.GetBlkSize();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.ToString());
                    throw;
                }
                finally
                {
                    if (request != null) request.Abort();
                    if (response != null) response.Close();
                }
            }