Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored ODataTable class to simplify adding batch support.
- Loading branch information
Showing
13 changed files
with
584 additions
and
433 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,4 +1,6 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | <?xml version="1.0" encoding="utf-8"?> | ||
<configuration> | <configuration> | ||
<mm-GraphProvider>BUILTINDARK</mm-GraphProvider> | |||
<StartPaused>true</StartPaused> | |||
<BuildExecutable>C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe</BuildExecutable> | <BuildExecutable>C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe</BuildExecutable> | ||
</configuration> | </configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,78 @@ | |||
using System; | |||
using System.Net; | |||
using System.Text; | |||
using Simple.NExtLib; | |||
using Simple.OData; | |||
|
|||
namespace Simple.Data.OData | |||
{ | |||
public class BatchRequestBuilder : RequestBuilder | |||
{ | |||
private string _batchId; | |||
private string _changesetId; | |||
private StringBuilder _contentBuilder; | |||
|
|||
public BatchRequestBuilder(string urlBase) | |||
: base(urlBase) | |||
{ | |||
} | |||
|
|||
public void BeginBatch(string command, string method, string content = null) | |||
{ | |||
var uri = CreateRequestUrl(command); | |||
this.Request = (HttpWebRequest)WebRequest.Create(uri); | |||
this.Request.Method = RestVerbs.POST; | |||
_batchId = Guid.NewGuid().ToString(); | |||
this.Request.ContentType = "multipart/mixed; boundary=" + _batchId; | |||
_contentBuilder = new StringBuilder(); | |||
} | |||
|
|||
public void EndBatch() | |||
{ | |||
_contentBuilder.AppendLine(string.Format("--batch({0})--", _batchId)); | |||
AddContent(this.Request, _contentBuilder.ToString()); | |||
} | |||
|
|||
public override void AddTableCommand(string command, string method, string content = null) | |||
{ | |||
_contentBuilder.AppendLine(string.Format("--batch_{0}", _batchId)); | |||
if (method == RestVerbs.GET) | |||
{ | |||
if (_changesetId != null) | |||
{ | |||
_contentBuilder.AppendLine(string.Format("--changeset_{0}--", _changesetId)); | |||
_contentBuilder.AppendLine(); | |||
} | |||
_changesetId = null; | |||
} | |||
else | |||
{ | |||
if (_changesetId == null) | |||
{ | |||
_changesetId = Guid.NewGuid().ToString(); | |||
_contentBuilder.AppendLine(string.Format("Content-Type: multipart/mixed; boundary=changeset_{0}", _changesetId)); | |||
_contentBuilder.AppendLine(string.Format("Content-Length: {0}", 0)); | |||
_contentBuilder.AppendLine(); | |||
_contentBuilder.AppendLine(string.Format("--changeset_{0}", _changesetId)); | |||
} | |||
} | |||
_contentBuilder.AppendLine("Content-Type: application/http"); | |||
_contentBuilder.AppendLine("Content-Transfer-Encoding:binary"); | |||
_contentBuilder.AppendLine(); | |||
_contentBuilder.AppendLine(string.Format("{0} {1} HTTP/{2}", method, command, "1.1")); | |||
_contentBuilder.AppendLine(this.Host); | |||
|
|||
if (content != null) | |||
{ | |||
_contentBuilder.AppendLine(string.Format("Content-Type: application/atom+xml;type=entry")); | |||
_contentBuilder.AppendLine(string.Format("Content-Length: {0}", (content ?? string.Empty).Length)); | |||
_contentBuilder.Append(content); | |||
} | |||
} | |||
|
|||
protected override void AddContent(WebRequest request, string content) | |||
{ | |||
_contentBuilder.AppendLine(content); | |||
} | |||
} | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,46 @@ | |||
using System.Net; | |||
using Simple.NExtLib; | |||
using Simple.OData; | |||
|
|||
namespace Simple.Data.OData | |||
{ | |||
public class CommandRequestBuilder : RequestBuilder | |||
{ | |||
public CommandRequestBuilder(string urlBase) | |||
: base(urlBase) | |||
{ | |||
} | |||
|
|||
public override void AddTableCommand(string command, string method, string content = null) | |||
{ | |||
this.Request = CreateTableRequest(command, method, content); | |||
} | |||
|
|||
protected override void AddContent(WebRequest request, string content) | |||
{ | |||
request.ContentType = "application/atom+xml"; | |||
request.SetContent(content); | |||
} | |||
|
|||
private HttpWebRequest CreateTableRequest(string command, string method, string content = null) | |||
{ | |||
var uri = CreateRequestUrl(command); | |||
var request = (HttpWebRequest)WebRequest.Create(uri); | |||
request.Method = method; | |||
request.ContentLength = (content ?? string.Empty).Length; | |||
|
|||
// TODO: revise | |||
//if (method == "PUT" || method == "DELETE" || method == "MERGE") | |||
//{ | |||
// request.Headers.Add("If-Match", "*"); | |||
//} | |||
|
|||
if (content != null) | |||
{ | |||
AddContent(request, content); | |||
} | |||
|
|||
return request; | |||
} | |||
} | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,8 @@ | |||
using Simple.OData; | |||
|
|||
namespace Simple.Data.OData | |||
{ | |||
public class CommandRequestRunner : RequestRunner | |||
{ | |||
} | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.