Skip to content

Commit 8152564

Browse files
Merge pull request #9 from hiddenswitch/unity5
Unity 5 update
2 parents b6c0d90 + 664463f commit 8152564

File tree

106 files changed

+6528
-6478
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

106 files changed

+6528
-6478
lines changed

.gitmodules

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
[submodule "JsonFx"]
2-
path = JsonFx
3-
url = git@github.com:hiddenswitch/jsonfx-1.x.git
1+

Extensions/ObjectExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using System.Reflection;
44
using System.Collections;
55

6-
namespace Extensions {
6+
namespace Meteor.Extensions {
77
public static partial class ObjectExtensions
88
{
99
/// <summary>

Extensions/StringExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using System;
22

3-
namespace Extensions {
3+
namespace Meteor.Extensions {
44
public static partial class StringExtensions
55
{
66
/// <summary>

JsonFx

Lines changed: 0 additions & 1 deletion
This file was deleted.

JsonFx/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.DS_Store
2+
3+
.svn/

JsonFx/DataReaderProvider.cs

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#region License
2+
/*---------------------------------------------------------------------------------*\
3+
4+
Distributed under the terms of an MIT-style license:
5+
6+
The MIT License
7+
8+
Copyright (c) 2006-2009 Stephen M. McKamey
9+
10+
Permission is hereby granted, free of charge, to any person obtaining a copy
11+
of this software and associated documentation files (the "Software"), to deal
12+
in the Software without restriction, including without limitation the rights
13+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14+
copies of the Software, and to permit persons to whom the Software is
15+
furnished to do so, subject to the following conditions:
16+
17+
The above copyright notice and this permission notice shall be included in
18+
all copies or substantial portions of the Software.
19+
20+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26+
THE SOFTWARE.
27+
28+
\*---------------------------------------------------------------------------------*/
29+
#endregion License
30+
31+
using System;
32+
using System.Collections.Generic;
33+
34+
namespace JsonFx.Json
35+
{
36+
public interface IDataReaderProvider
37+
{
38+
IDataReader Find(string contentTypeHeader);
39+
}
40+
41+
/// <summary>
42+
/// Provides lookup capabilities for finding an IDataReader
43+
/// </summary>
44+
public class DataReaderProvider : IDataReaderProvider
45+
{
46+
#region Fields
47+
48+
private readonly IDictionary<string, IDataReader> ReadersByMime = new Dictionary<string, IDataReader>(StringComparer.OrdinalIgnoreCase);
49+
50+
#endregion Fields
51+
52+
#region Init
53+
54+
/// <summary>
55+
/// Ctor
56+
/// </summary>
57+
/// <param name="readers">inject with all possible readers</param>
58+
public DataReaderProvider(IEnumerable<IDataReader> readers)
59+
{
60+
if (readers != null)
61+
{
62+
foreach (IDataReader reader in readers)
63+
{
64+
if (!String.IsNullOrEmpty(reader.ContentType))
65+
{
66+
this.ReadersByMime[reader.ContentType] = reader;
67+
}
68+
}
69+
}
70+
}
71+
72+
#endregion Init
73+
74+
#region Methods
75+
76+
/// <summary>
77+
/// Finds an IDataReader by content-type header
78+
/// </summary>
79+
/// <param name="contentTypeHeader"></param>
80+
/// <returns></returns>
81+
public IDataReader Find(string contentTypeHeader)
82+
{
83+
string type = DataWriterProvider.ParseMediaType(contentTypeHeader);
84+
85+
if (this.ReadersByMime.ContainsKey(type))
86+
{
87+
return ReadersByMime[type];
88+
}
89+
90+
return null;
91+
}
92+
93+
#endregion Methods
94+
}
95+
}
Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

JsonFx/DataWriterProvider.cs

Lines changed: 219 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,219 @@
1+
#region License
2+
/*---------------------------------------------------------------------------------*\
3+
4+
Distributed under the terms of an MIT-style license:
5+
6+
The MIT License
7+
8+
Copyright (c) 2006-2009 Stephen M. McKamey
9+
10+
Permission is hereby granted, free of charge, to any person obtaining a copy
11+
of this software and associated documentation files (the "Software"), to deal
12+
in the Software without restriction, including without limitation the rights
13+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14+
copies of the Software, and to permit persons to whom the Software is
15+
furnished to do so, subject to the following conditions:
16+
17+
The above copyright notice and this permission notice shall be included in
18+
all copies or substantial portions of the Software.
19+
20+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26+
THE SOFTWARE.
27+
28+
\*---------------------------------------------------------------------------------*/
29+
#endregion License
30+
31+
using System;
32+
using System.Collections.Generic;
33+
using System.IO;
34+
35+
namespace JsonFx.Json
36+
{
37+
public interface IDataWriterProvider
38+
{
39+
IDataWriter DefaultDataWriter { get; }
40+
41+
IDataWriter Find(string extension);
42+
43+
IDataWriter Find(string acceptHeader, string contentTypeHeader);
44+
}
45+
46+
/// <summary>
47+
/// Provides lookup capabilities for finding an IDataWriter
48+
/// </summary>
49+
public class DataWriterProvider : IDataWriterProvider
50+
{
51+
#region Fields
52+
53+
private readonly IDataWriter DefaultWriter;
54+
private readonly IDictionary<string, IDataWriter> WritersByExt = new Dictionary<string, IDataWriter>(StringComparer.OrdinalIgnoreCase);
55+
private readonly IDictionary<string, IDataWriter> WritersByMime = new Dictionary<string, IDataWriter>(StringComparer.OrdinalIgnoreCase);
56+
57+
#endregion Fields
58+
59+
#region Init
60+
61+
/// <summary>
62+
/// Ctor
63+
/// </summary>
64+
/// <param name="writers">inject with all possible writers</param>
65+
public DataWriterProvider(IEnumerable<IDataWriter> writers)
66+
{
67+
if (writers != null)
68+
{
69+
foreach (IDataWriter writer in writers)
70+
{
71+
if (this.DefaultWriter == null)
72+
{
73+
// TODO: decide less arbitrary way to choose default
74+
// without hardcoding value into IDataWriter
75+
this.DefaultWriter = writer;
76+
}
77+
78+
if (!String.IsNullOrEmpty(writer.ContentType))
79+
{
80+
this.WritersByMime[writer.ContentType] = writer;
81+
}
82+
83+
if (!String.IsNullOrEmpty(writer.ContentType))
84+
{
85+
string ext = DataWriterProvider.NormalizeExtension(writer.FileExtension);
86+
this.WritersByExt[ext] = writer;
87+
}
88+
}
89+
}
90+
}
91+
92+
#endregion Init
93+
94+
#region Properties
95+
96+
public IDataWriter DefaultDataWriter
97+
{
98+
get { return this.DefaultWriter; }
99+
}
100+
101+
#endregion Properties
102+
103+
#region Methods
104+
105+
public IDataWriter Find(string extension)
106+
{
107+
extension = DataWriterProvider.NormalizeExtension(extension);
108+
109+
if (this.WritersByExt.ContainsKey(extension))
110+
{
111+
return WritersByExt[extension];
112+
}
113+
114+
return null;
115+
}
116+
117+
public IDataWriter Find(string acceptHeader, string contentTypeHeader)
118+
{
119+
foreach (string type in DataWriterProvider.ParseHeaders(acceptHeader, contentTypeHeader))
120+
{
121+
if (this.WritersByMime.ContainsKey(type))
122+
{
123+
return WritersByMime[type];
124+
}
125+
}
126+
127+
return null;
128+
}
129+
130+
#endregion Methods
131+
132+
#region Utility Methods
133+
134+
/// <summary>
135+
/// Parses HTTP headers for Media-Types
136+
/// </summary>
137+
/// <param name="accept">HTTP Accept header</param>
138+
/// <param name="contentType">HTTP Content-Type header</param>
139+
/// <returns>sequence of Media-Types</returns>
140+
/// <remarks>
141+
/// http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
142+
/// </remarks>
143+
public static IEnumerable<string> ParseHeaders(string accept, string contentType)
144+
{
145+
string mime;
146+
147+
// check for a matching accept type
148+
foreach (string type in DataWriterProvider.SplitTrim(accept, ','))
149+
{
150+
mime = DataWriterProvider.ParseMediaType(type);
151+
if (!String.IsNullOrEmpty(mime))
152+
{
153+
yield return mime;
154+
}
155+
}
156+
157+
// fallback on content-type
158+
mime = DataWriterProvider.ParseMediaType(contentType);
159+
if (!String.IsNullOrEmpty(mime))
160+
{
161+
yield return mime;
162+
}
163+
}
164+
165+
/// <summary>
166+
///
167+
/// </summary>
168+
/// <param name="type"></param>
169+
/// <returns></returns>
170+
public static string ParseMediaType(string type)
171+
{
172+
foreach (string mime in DataWriterProvider.SplitTrim(type, ';'))
173+
{
174+
// only return first part
175+
return mime;
176+
}
177+
178+
// if no parts then was empty
179+
return String.Empty;
180+
}
181+
182+
private static IEnumerable<string> SplitTrim(string source, char ch)
183+
{
184+
if (String.IsNullOrEmpty(source))
185+
{
186+
yield break;
187+
}
188+
189+
int length = source.Length;
190+
for (int prev=0, next=0; prev<length && next>=0; prev=next+1)
191+
{
192+
next = source.IndexOf(ch, prev);
193+
if (next < 0)
194+
{
195+
next = length;
196+
}
197+
198+
string part = source.Substring(prev, next-prev).Trim();
199+
if (part.Length > 0)
200+
{
201+
yield return part;
202+
}
203+
}
204+
}
205+
206+
private static string NormalizeExtension(string extension)
207+
{
208+
if (String.IsNullOrEmpty(extension))
209+
{
210+
return String.Empty;
211+
}
212+
213+
// ensure is only extension with leading dot
214+
return Path.GetExtension(extension);
215+
}
216+
217+
#endregion Utility Methods
218+
}
219+
}
Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)