예제 #1
0
        private static void AddContent(string content, WebRequest request)
        {
            request.Headers["Content-MD5"] = HashMD5(content);
            request.ContentType = "application/atom+xml";
#if(SILVERLIGHT)
            request.SetContentAsync(content);
#else
            request.SetContent(content);
#endif
        }
예제 #2
0
 private void AddContent(string content, WebRequest request)
 {
     request.Headers.Add("Content-MD5", HashMD5(content));
     request.ContentType = "application/atom+xml";
     request.SetContent(content);
 }
    public IPromise<Stream> Upload(UploadCommand upload, bool async)
    {
      // Files need to be uploaded, so build the vault request

      // Compile the headers and AML query into the appropriate content
      var multiWriter = new MultiPartFormWriter(async, _conn.AmlContext.LocalizationContext);
      multiWriter.AddFiles(upload);
      _conn.SetDefaultHeaders(multiWriter.WriteFormField);
      multiWriter.WriteFormField("SOAPACTION", upload.Action.ToString());
      multiWriter.WriteFormField("VAULTID", upload.Vault.Id);
      multiWriter.WriteFormField("XMLdata", "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:i18n=\"http://www.aras.com/I18N\"><SOAP-ENV:Body><ApplyItem>" +
                                upload.ToNormalizedAml(_conn.AmlContext.LocalizationContext) +
                                "</ApplyItem></SOAP-ENV:Body></SOAP-ENV:Envelope>");

      // Transform the vault URL (as necessary)
      var urlPromise = upload.Vault.Url.IndexOf("$[") < 0 ?
        Promises.Resolved(upload.Vault.Url) :
        _conn.Process(new Command("<url>@0</url>", upload.Vault.Url)
                .WithAction(CommandAction.TransformVaultServerURL), async)
                .Convert(s => s.AsString());
        //GetResult("TransformVaultServerURL", "<url>" + upload.Vault.Url + "</url>", async);

      return urlPromise.Continue(u =>
      {
        // Determine the authentication used by the vault
        if (u != upload.Vault.Url) upload.Vault.Url = u;
        return CheckAuthentication(upload.Vault, async);
      }).Continue(a =>
      {
        // Build the request to perform the upload
        var hReq = (HttpWebRequest)System.Net.WebRequest.Create(upload.Vault.Url);
        hReq.AllowWriteStreamBuffering = false;
        hReq.Timeout = -1;
        hReq.ReadWriteTimeout = 300000;
        hReq.SendChunked = true;
        hReq.Method = "POST";
        hReq.KeepAlive = true;
        hReq.ProtocolVersion = HttpVersion.Version11;
        hReq.ContentType = multiWriter.ContentType;
        hReq.ContentLength = multiWriter.GetLength();
        hReq.CookieContainer = upload.Vault.Cookies;

        switch (a)
        {
          case AuthenticationSchemes.Negotiate:
            hReq.PreAuthenticate = true;
            hReq.UnsafeAuthenticatedConnectionSharing = true;
            break;
          case AuthenticationSchemes.Ntlm:
            hReq.UnsafeAuthenticatedConnectionSharing = true;
            break;
          case AuthenticationSchemes.Basic:
            hReq.PreAuthenticate = true;
            break;
        }

        var req = new WebRequest(hReq, _conn.Compression);
        foreach (var ac in _conn.DefaultSettings)
        {
          ac.Invoke(req);
        }
        if (upload.Settings != null) upload.Settings.Invoke(req);

        //hReq.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; MyIE2; .NET CLR 1.1.4322)";
        req.SetContent(multiWriter.WriteToRequest);
        return req.Execute(async);
      }).Convert(r => r.AsStream);
    }