Skip to content

Commit

Permalink
removed #if silverlight
Browse files Browse the repository at this point in the history
  • Loading branch information
ml054 committed Mar 3, 2014
1 parent d51c0ec commit 75fad74
Show file tree
Hide file tree
Showing 48 changed files with 46 additions and 759 deletions.
1 change: 0 additions & 1 deletion .gitignore
Expand Up @@ -39,7 +39,6 @@ StyleCop.Cache
*.dotCover
RavenDB*.nupkg
*.orig
/Raven.Database/Server/WebUI/Raven.Studio.xap
*.ncrunchsolution
Raven.Web/Tenants/
Raven.Web/NLog.config
Expand Down
10 changes: 2 additions & 8 deletions CommonAssemblyInfo.cs
Expand Up @@ -9,9 +9,7 @@
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]

#if SILVERLIGHT
[assembly: AssemblyTitle("RavenDB (for Silverlight 5)")]
#elif NETFX_CORE
#if NETFX_CORE
[assembly: AssemblyTitle("RavenDB (for WinRT)")]
#else
[assembly: AssemblyTitle("RavenDB (for .NET 4.5)")]
Expand All @@ -23,13 +21,9 @@
[assembly: AssemblyProduct("RavenDB")]
[assembly: AssemblyDescription("RavenDB is a second generation LINQ enabled document database for .NET")]

#if SILVERLIGHT
[assembly: CLSCompliant(false)]
#else
[assembly: CLSCompliant(true)]
#endif

#if !SILVERLIGHT && !NETFX_CORE
#if !NETFX_CORE
[assembly: SuppressIldasm()]
#endif

Expand Down
5 changes: 0 additions & 5 deletions Raven.Abstractions/Connection/CompressedStringContent.cs
Expand Up @@ -4,11 +4,6 @@
using System.Text;
using System.Threading.Tasks;
using System.IO.Compression;
#if SILVERLIGHT
using Ionic.Zlib;
#else

#endif

namespace Raven.Abstractions.Connection
{
Expand Down
9 changes: 1 addition & 8 deletions Raven.Abstractions/Connection/OAuthHelper.cs
Expand Up @@ -86,14 +86,7 @@ public static string EncryptAsymmetric(byte[] exponent, byte[] modulus, string d
#endif
}

#if SILVERLIGHT
private static byte[] AddEncryptedKeyAndIv(byte[] exponent, byte[] modulus, byte[] key, byte[] iv)
{
// http://msdn.microsoft.com/en-us/library/cc265159(v=vs.95).aspx
// http://msdn.microsoft.com/en-us/library/system.security.cryptography.rsacryptoserviceprovider(v=vs.95).aspx
return null;
}
#elif NETFX_CORE
#if NETFX_CORE

#else
private static byte[] AddEncryptedKeyAndIv(byte[] exponent, byte[] modulus, byte[] key, byte[] iv)
Expand Down
9 changes: 1 addition & 8 deletions Raven.Abstractions/Connection/WebRequestEventArgs.cs
Expand Up @@ -21,21 +21,14 @@ public class WebRequestEventArgs : EventArgs
/// <value>The request.</value>
public HttpClient Client { get; set; }

#if !SILVERLIGHT && !NETFX_CORE
#if !NETFX_CORE
/// <summary>
/// Gets or sets the web request.
/// </summary>
/// <value>The request.</value>
public WebRequest Request { get; set; }
#endif

#if SILVERLIGHT
/// <summary>
/// The RavenDB json request
/// </summary>
public Client.Silverlight.Connection.HttpJsonRequest JsonRequest { get; set; }
#endif

public OperationCredentials Credentials { get; set; }
}
}
5 changes: 0 additions & 5 deletions Raven.Abstractions/Connection/WebResponseExtensions.cs
Expand Up @@ -9,12 +9,7 @@
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;

#if SILVERLIGHT
using Ionic.Zlib;
#else
using System.IO.Compression;
#endif

namespace Raven.Abstractions.Connection
{
Expand Down
4 changes: 2 additions & 2 deletions Raven.Abstractions/Data/Etag.cs
Expand Up @@ -3,7 +3,7 @@
using System.Globalization;
using System.Text;
using System.Linq;
#if SILVERLIGHT || NETFX_CORE
#if NETFX_CORE
using Raven.Abstractions.Util;
#else
using System.Security.Cryptography;
Expand Down Expand Up @@ -267,7 +267,7 @@ public Etag HashWith(Etag other)
public Etag HashWith(IEnumerable<byte> bytes)
{
var etagBytes = ToBytes().Concat(bytes).ToArray();
#if SILVERLIGHT || NETFX_CORE
#if NETFX_CORE
return Parse(MD5Core.GetHash(etagBytes));
#else
using (var md5 = MD5.Create())
Expand Down
64 changes: 0 additions & 64 deletions Raven.Abstractions/Extensions/MetadataExtensions.cs
Expand Up @@ -144,69 +144,6 @@ public static RavenJObject FilterHeadersToObject(this RavenJObject self)
return metadata;
}

#if SILVERLIGHT
public static RavenJObject FilterHeadersAttachment(this NameValueCollection self)
{
var filterHeaders = self.FilterHeadersToObject();
if (self.ContainsKey("Content-Type"))
filterHeaders["Content-Type"] = self["Content-Type"].FirstOrDefault();
return filterHeaders;
}

/// <summary>
/// Filters the headers from unwanted headers
/// </summary>
/// <returns></returns>public static RavenJObject FilterHeadersToObject(this System.Collections.Specialized.NameValueCollection self, bool isServerDocument)
public static RavenJObject FilterHeadersToObject(this NameValueCollection self)
{
var metadata = new RavenJObject();
foreach (var header in self.Headers)
{
if (prefixesInHeadersToIgnoreClient.Any(prefix => header.Key.StartsWith(prefix, StringComparison.OrdinalIgnoreCase)))
continue;
if (headersToIgnoreClient.Contains(header.Key))
continue;
var values = header.Value;
var headerName = CaptureHeaderName(header.Key);
if (values.Count == 1)
metadata.Add(headerName, GetValue(values[0]));
else
metadata.Add(headerName, new RavenJArray(values.Select(GetValue)));
}
return metadata;
}

public static RavenJObject FilterHeadersAttachment(this IDictionary<string, IList<string>> self)
{
var filterHeaders = self.FilterHeadersToObject();
if (self.ContainsKey("Content-Type"))
filterHeaders["Content-Type"] = self["Content-Type"].FirstOrDefault();
return filterHeaders;
}

/// <summary>
/// Filters the headers from unwanted headers
/// </summary>
/// <returns></returns>public static RavenJObject FilterHeadersToObject(this System.Collections.Specialized.NameValueCollection self, bool isServerDocument)
public static RavenJObject FilterHeadersToObject(this IDictionary<string, IList<string>> self)
{
var metadata = new RavenJObject();
foreach (var header in self)
{
if (prefixesInHeadersToIgnoreClient.Any(prefix => header.Key.StartsWith(prefix, StringComparison.OrdinalIgnoreCase)))
continue;
if (headersToIgnoreClient.Contains(header.Key))
continue;
var values = header.Value;
var headerName = CaptureHeaderName(header.Key);
if (values.Count == 1)
metadata.Add(headerName, GetValue(values[0]));
else
metadata.Add(headerName, new RavenJArray(values.Select(GetValue)));
}
return metadata;
}
#else
public static RavenJObject FilterHeadersAttachment(this NameValueCollection self)
{
var filterHeaders = self.FilterHeadersToObject();
Expand Down Expand Up @@ -248,7 +185,6 @@ public static RavenJObject FilterHeadersToObject(this NameValueCollection self)
}
return metadata;
}
#endif

public static RavenJObject FilterHeadersAttachment(this HttpHeaders self)
{
Expand Down
4 changes: 0 additions & 4 deletions Raven.Abstractions/Extensions/TaskExtensions.cs
Expand Up @@ -51,11 +51,7 @@ public static async Task<bool> WaitWithTimeout(this Task task, TimeSpan? timeout
await task;
return true;
}
#if SILVERLIGHT
if (task == await TaskEx.WhenAny(task, TaskEx.Delay(timeout.Value)))
#else
if (task == await Task.WhenAny(task, Task.Delay(timeout.Value)))
#endif
return true;
return false;
}
Expand Down
5 changes: 1 addition & 4 deletions Raven.Abstractions/Logging/LogManager.cs
Expand Up @@ -21,10 +21,7 @@ public static void EnsureValidLogger()
#endif
public static ILog GetCurrentClassLogger()
{
#if SILVERLIGHT
var stackFrame = new StackTrace().GetFrame(1);
return GetLogger(stackFrame.GetMethod().DeclaringType);
#elif NETFX_CORE
#if NETFX_CORE
// WinRT exceptions doesn't have an informative stack traces.
// This is an ugly hack to have something instead of a name class.
return GetLogger("Raven.WinRT-" + System.Threading.Interlocked.Increment(ref counter));
Expand Down
16 changes: 3 additions & 13 deletions Raven.Abstractions/OAuth/BasicAuthenticator.cs
Expand Up @@ -7,11 +7,7 @@
using Raven.Abstractions.Connection;
using Raven.Abstractions.Extensions;

#if SILVERLIGHT
using Raven.Client.Connection;
using Raven.Client.Silverlight.Connection;
using System.Net.Browser;
#elif NETFX_CORE
#if NETFX_CORE
using Raven.Client.WinRT.Connection;
#endif

Expand All @@ -32,22 +28,16 @@ public async Task<Action<HttpClient>> HandleOAuthResponseAsync(string oauthSourc
httpClient.DefaultRequestHeaders.TryAddWithoutValidation("grant_type", "client_credentials");
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json") { CharSet = "UTF-8" });

#if !SILVERLIGHT
httpClient.DefaultRequestHeaders.AcceptEncoding.Add(new StringWithQualityHeaderValue("deflate"));
httpClient.DefaultRequestHeaders.AcceptEncoding.Add(new StringWithQualityHeaderValue("gzip"));
#endif

if (string.IsNullOrEmpty(apiKey) == false)
httpClient.DefaultRequestHeaders.TryAddWithoutValidation("Api-Key", apiKey);

if (oauthSource.StartsWith("https", StringComparison.OrdinalIgnoreCase) == false && enableBasicAuthenticationOverUnsecuredHttp == false)
throw new InvalidOperationException(BasicOAuthOverHttpError);

var requestUri = oauthSource
#if SILVERLIGHT
.NoCache()
#endif
;
var requestUri = oauthSource;
var response = await httpClient.GetAsync(requestUri)
.ConvertSecurityExceptionToServerNotFound()
.AddUrlIfFaulting(new Uri(requestUri));
Expand All @@ -60,7 +50,7 @@ public async Task<Action<HttpClient>> HandleOAuthResponseAsync(string oauthSourc
}
}

#if !SILVERLIGHT && !NETFX_CORE
#if !NETFX_CORE
private HttpWebRequest PrepareOAuthRequest(string oauthSource, string apiKey)
{
var authRequest = (HttpWebRequest)WebRequest.Create(oauthSource);
Expand Down
56 changes: 2 additions & 54 deletions Raven.Abstractions/OAuth/SecuredAuthenticator.cs
Expand Up @@ -11,14 +11,6 @@
using System.Net.Http.Headers;
using System.Threading.Tasks;

#if SILVERLIGHT
using System.Diagnostics;
using System.Net.Browser;

using Raven.Client.Changes;
using Raven.Client.Connection;
#endif

namespace Raven.Abstractions.OAuth
{
public class SecuredAuthenticator : AbstractAuthenticator
Expand All @@ -35,7 +27,7 @@ public override void ConfigureRequest(object sender, WebRequestEventArgs e)
{
if (e.Client != null)
e.Client.DefaultRequestHeaders.Add("Has-Api-Key", "true");
#if !NETFX_CORE && !SILVERLIGHT
#if !NETFX_CORE
if (e.Request != null)
e.Request.Headers["Has-Api-Key"] = "true";
#endif
Expand All @@ -44,11 +36,7 @@ public override void ConfigureRequest(object sender, WebRequestEventArgs e)

private Tuple<HttpWebRequest, string> PrepareOAuthRequest(string oauthSource, string serverRSAExponent, string serverRSAModulus, string challenge, string apiKey)
{
#if !SILVERLIGHT
var authRequest = (HttpWebRequest)WebRequest.Create(oauthSource);
#else
var authRequest = (HttpWebRequest)WebRequestCreator.ClientHttp.Create(new Uri(oauthSource));
#endif
authRequest.Headers["grant_type"] = "client_credentials";
authRequest.Accept = "application/json;charset=UTF-8";
authRequest.Method = "POST";
Expand Down Expand Up @@ -226,11 +214,7 @@ public async Task<Action<HttpClient>> DoOAuthRequestAsync(string baseUrl, string
});
}

var requestUri = oauthSource
#if SILVERLIGHT
.NoCache()
#endif
;
var requestUri = oauthSource;

var response = await httpClient.PostAsync(requestUri, data != null ? (HttpContent)new CompressedStringContent(data, true) : new StringContent(""))
.AddUrlIfFaulting(new Uri(requestUri))
Expand Down Expand Up @@ -266,46 +250,10 @@ public async Task<Action<HttpClient>> DoOAuthRequestAsync(string baseUrl, string
using (var reader = new StreamReader(stream))
{
CurrentOauthToken = reader.ReadToEnd();


#if SILVERLIGHT
BrowserCookieToAllowUserToUseStandardRequests(baseUrl, reader.ReadToEnd());
#endif
return (Action<HttpClient>)(SetAuthorization);
}
}
}

#if SILVERLIGHT
private void BrowserCookieToAllowUserToUseStandardRequests(string baseUrl, string currentOauthToken)
{
var webRequest = WebRequestCreator.BrowserHttp.Create(new Uri(baseUrl + "/OAuth/Cookie"));
webRequest.Headers["Authorization"] = currentOauthToken;
webRequest.Headers["Has-Api-Key"] = "True";
webRequest.Method = "POST";
webRequest.BeginGetResponse(ar =>
{
try
{
using (webRequest.EndGetResponse(ar))
{
}
}
catch (WebException we)
{
Debug.WriteLine("Failed to set browser cookie: " + we.Message);
using(we.Response)
{
}
}
catch (Exception e)
{
Debug.WriteLine("Failed to set browser cookie: " + e.Message);
}
}, null);
}
#endif
}
}

0 comments on commit 75fad74

Please sign in to comment.