CalDavSynchronizer.DataAccess.CardDavDataAccess.CreateNewEntity C# (CSharp) Method

CreateNewEntity() protected method

protected CreateNewEntity ( string name, string content ) : string>>.Task
name string
content string
return string>>.Task
    protected async Task<EntityVersion<WebResourceName, string>> CreateNewEntity (string name, string content)
    {
      var contactUrl = new Uri (_serverUrl, name);

      s_logger.DebugFormat ("Creating entity '{0}'", contactUrl);

      IHttpHeaders responseHeaders = await _webDavClient.ExecuteWebDavRequestAndReturnResponseHeaders (
        contactUrl,
        "PUT",
        null,
        null,
        "*",
        "text/vcard",
        content);

      Uri effectiveContactUrl;
      if (responseHeaders.Location != null)
      {
        s_logger.DebugFormat ("Server sent new location: '{0}'", responseHeaders.Location);
        effectiveContactUrl = responseHeaders.Location.IsAbsoluteUri ? responseHeaders.Location : new Uri (_serverUrl, responseHeaders.Location);
        s_logger.DebugFormat ("New entity location: '{0}'", effectiveContactUrl);
      }
      else
      {
        effectiveContactUrl = contactUrl;
      }

      var etag = responseHeaders.ETag;
      string version;
      if (etag != null)
      {
        version = etag;
      }
      else
      {
        version = await GetEtag (effectiveContactUrl);
      }

      return new EntityVersion<WebResourceName, string> (new WebResourceName(effectiveContactUrl), version);
    }