-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
929fe2f
commit 3d94400
Showing
59 changed files
with
205 additions
and
79,384 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
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
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Converters; | ||
using Newtonsoft.Json.Linq; | ||
using System; | ||
using System.Dynamic; | ||
using System.IO; | ||
using System.Net; | ||
using System.Net.Http; | ||
using System.Net.Http.Formatting; | ||
using System.Net.Http.Headers; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace App.Api.Formatting | ||
{ | ||
public class JsonNetMediaTypeFormatter : MediaTypeFormatter | ||
{ | ||
public JsonNetMediaTypeFormatter() | ||
{ | ||
SupportedMediaTypes.Add(new MediaTypeHeaderValue("application/json")); | ||
} | ||
|
||
public override bool CanReadType(Type type) | ||
{ | ||
if (type == typeof(JValue) || type == typeof(JObject) || type == typeof(JArray)) | ||
return false; | ||
|
||
return true; | ||
} | ||
|
||
public override bool CanWriteType(Type type) | ||
{ | ||
//if (type == typeof(IKeyValueModel)) | ||
|
||
if (type.Name == "IKeyValueModel") | ||
return false; | ||
|
||
return true; | ||
} | ||
|
||
public override Task<object> ReadFromStreamAsync(Type type, Stream readStream, HttpContent content, IFormatterLogger formatterLogger) | ||
{ | ||
TaskCompletionSource<object> completionSource = new TaskCompletionSource<object>(); | ||
|
||
var settings = new JsonSerializerSettings() | ||
{ | ||
NullValueHandling = NullValueHandling.Ignore, | ||
}; | ||
|
||
string jsonText; | ||
|
||
using (StreamReader reader = new StreamReader(readStream)) | ||
{ | ||
jsonText = reader.ReadToEnd(); | ||
} | ||
|
||
if (jsonText.Trim().StartsWith("{")) | ||
{ | ||
completionSource.SetResult(JsonConvert.DeserializeObject<ExpandoObject>(jsonText, new ExpandoObjectConverter())); | ||
} | ||
else | ||
{ | ||
object deserializedObject = JsonConvert.DeserializeObject(jsonText); | ||
JToken token; | ||
|
||
if ((token = deserializedObject as JToken) != null) | ||
{ | ||
Type clrType; | ||
|
||
switch (token.Type) | ||
{ | ||
case JTokenType.Array: | ||
clrType = typeof(object[]); | ||
break; | ||
|
||
default: | ||
throw new NotSupportedException("Source type not supported"); | ||
} | ||
|
||
completionSource.SetResult(token.ToObject(clrType)); | ||
} | ||
else | ||
{ | ||
completionSource.SetResult(deserializedObject); | ||
} | ||
} | ||
|
||
return completionSource.Task; | ||
} | ||
|
||
public override Task WriteToStreamAsync(Type type, object value, Stream writeStream, HttpContent content, TransportContext transportContext) | ||
{ | ||
TaskCompletionSource<object> completionSource = new TaskCompletionSource<object>(); | ||
completionSource.SetResult(null); | ||
|
||
var settings = new JsonSerializerSettings() | ||
{ | ||
NullValueHandling = NullValueHandling.Ignore, | ||
ReferenceLoopHandling = ReferenceLoopHandling.Ignore | ||
}; | ||
|
||
string json = JsonConvert.SerializeObject(value); | ||
|
||
byte[] buf = Encoding.Default.GetBytes(json); | ||
writeStream.Write(buf, 0, buf.Length); | ||
writeStream.Flush(); | ||
|
||
return completionSource.Task; | ||
} | ||
} | ||
} |
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using App.Api.Redis; | ||
using StackExchange.Redis; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Net.Http; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Web.Http; | ||
|
||
namespace App.Api | ||
{ | ||
[RoutePrefix("v1/products")] | ||
public sealed class ProductController : ApiController | ||
{ | ||
[HttpGet] | ||
public async Task<HttpResponseMessage> GetProductsAsync() | ||
{ | ||
HttpResponseMessage response = null; | ||
IDatabase db = RedisClientFactory.GetDatabase(); | ||
|
||
if(await db.KeyExistsAsync("users")) | ||
{ | ||
|
||
} | ||
|
||
return response; | ||
|
||
} | ||
} | ||
} |
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using StackExchange.Redis; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace App.Api.Redis | ||
{ | ||
public static class RedisClientFactory | ||
{ | ||
private readonly static AutoResetEvent _multiplexerResetEvent = new AutoResetEvent(true); | ||
private readonly static ConnectionMultiplexer _multiplexer; | ||
|
||
static RedisClientFactory() | ||
{ | ||
_multiplexerResetEvent.WaitOne(); | ||
|
||
try | ||
{ | ||
ConfigurationOptions options = new ConfigurationOptions(); | ||
options.EndPoints.Add("localhost", 6379); | ||
options.AbortOnConnectFail = false; | ||
|
||
_multiplexer = ConnectionMultiplexer.Connect(options); | ||
} | ||
finally | ||
{ | ||
_multiplexerResetEvent.Set(); | ||
} | ||
} | ||
|
||
public static IDatabase GetDatabase() | ||
{ | ||
return _multiplexer.GetDatabase(); | ||
} | ||
|
||
public static ITransaction GetTransaction() | ||
{ | ||
return GetDatabase().CreateTransaction(); | ||
} | ||
} | ||
} |
Binary file modified
BIN
+110 Bytes
(100%)
App.Api/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache
Binary file not shown.
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
Binary file not shown.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Binary file removed
BIN
-184 KB
packages/Microsoft.AspNet.WebApi.Client.5.2.2/Microsoft.AspNet.WebApi.Client.5.2.2.nupkg
Binary file not shown.
Binary file removed
BIN
-181 KB
packages/Microsoft.AspNet.WebApi.Client.5.2.2/lib/net45/System.Net.Http.Formatting.dll
Binary file not shown.
Oops, something went wrong.