Skip to content

Commit 6dc862a

Browse files
committed
Tweaks for Mono
1 parent 2aca1c7 commit 6dc862a

File tree

8 files changed

+78
-8
lines changed

8 files changed

+78
-8
lines changed

src/React.Sample.Mvc4/Content/Sample.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,4 @@ var Avatar = React.createClass({
106106
getPhotoUrl: function(author) {
107107
return 'http://graph.facebook.com/' + author.Facebook + '/picture';
108108
}
109-
});
109+
});

src/React.Web/AssemblyRegistration.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,19 @@ public void Register(TinyIoCContainer container)
3737

3838
// Unique per request
3939
container.Register<IFileSystem, AspNetFileSystem>().AsPerRequestSingleton();
40-
container.Register<ICache, AspNetCache>().AsPerRequestSingleton();
4140
container.Register<IJsxHandler, JsxHandler>().AsPerRequestSingleton();
4241

42+
// Mono for Mac OS does not properly handle caching
43+
// TODO: Remove this once https://bugzilla.xamarin.com/show_bug.cgi?id=19071 is fixed
44+
if (SystemEnvironmentUtils.IsRunningOnMac())
45+
{
46+
container.Register<ICache, NullCache>().AsSingleton();
47+
}
48+
else
49+
{
50+
container.Register<ICache, AspNetCache>().AsPerRequestSingleton();
51+
}
52+
4353
// Wrappers for built-in objects
4454
container.Register<HttpContextBase>((c, o) => new HttpContextWrapper(HttpContext.Current));
4555
container.Register<HttpServerUtilityBase>((c, o) => c.Resolve<HttpContextBase>().Server);

src/React.Web/Content/web.config.transform

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<configuration>
22
<system.web>
3-
<!-- Uncomment if using IIS 7 Classic Mode or IIS 6 -->
3+
<!-- Uncomment if using IIS 7 Classic Mode, IIS 6, or Mono -->
44
<!--
55
<httpHandlers>
66
<add verb="GET" path="*.jsx" type="React.Web.JsxHandlerFactory, React.Web" />

src/React.Web/JsxHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public void Execute()
5151
var result = _environment.JsxTransformer.TransformJsxFile(relativePath);
5252

5353
// Only cache on the server-side for now
54-
_response.AddCacheDependency(new CacheDependency(_fileSystem.MapPath(relativePath)));
54+
_response.AddFileDependency(_fileSystem.MapPath(relativePath));
5555
_response.Cache.SetCacheability(HttpCacheability.Server);
5656
_response.Cache.SetLastModifiedFromFileDependencies();
5757
_response.Cache.SetETagFromFileDependencies();

src/React/AssemblyRegistration.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
* of patent rights can be found in the PATENTS file in the same directory.
88
*/
99

10-
using JavaScriptEngineSwitcher.Msie;
11-
using JavaScriptEngineSwitcher.Msie.Configuration;
1210
using React.TinyIoC;
1311

1412
namespace React

src/React/JsxTransformer.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99

1010
using System;
1111
using System.IO;
12-
using System.Security.Cryptography;
13-
using System.Text;
1412
using Newtonsoft.Json;
1513
using React.Exceptions;
1614

src/React/React.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
<Link>Properties\SharedAssemblyVersionInfo.cs</Link>
8484
</Compile>
8585
<Compile Include="AssemblyRegistration.cs" />
86+
<Compile Include="SystemEnvironmentUtils.cs" />
8687
<Compile Include="Exceptions\JsxUnsupportedEngineException.cs" />
8788
<Compile Include="Exceptions\ReactConfigurationException.cs" />
8889
<Compile Include="Exceptions\ReactException.cs" />

src/React/SystemEnvironmentUtils.cs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Copyright (c) 2014, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*/
9+
10+
using System;
11+
using System.Runtime.InteropServices;
12+
13+
namespace React
14+
{
15+
/// <summary>
16+
/// Utility functions for handling system environmental differences
17+
/// </summary>
18+
public class SystemEnvironmentUtils
19+
{
20+
[DllImport("libc")]
21+
private static extern int uname(IntPtr buf);
22+
23+
/// <summary>
24+
/// Determines whether the application is running on Mac OS.
25+
/// Based off Mono's XplatUI.cs, licensed under LGPL.
26+
/// </summary>
27+
/// <returns><c>true</c> if running on Mac OS</returns>
28+
public static bool IsRunningOnMac()
29+
{
30+
return _isRunningOnMac.Value;
31+
}
32+
33+
private readonly static Lazy<bool> _isRunningOnMac = new Lazy<bool>(() =>
34+
{
35+
if (Environment.OSVersion.Platform != PlatformID.Unix)
36+
{
37+
return false;
38+
}
39+
40+
var buf = IntPtr.Zero;
41+
try
42+
{
43+
buf = Marshal.AllocHGlobal(8192);
44+
if (uname(buf) == 0)
45+
{
46+
string os = Marshal.PtrToStringAnsi(buf);
47+
if (os == "Darwin")
48+
return true;
49+
}
50+
}
51+
catch
52+
{
53+
// YOLO
54+
}
55+
finally
56+
{
57+
if (buf != IntPtr.Zero)
58+
Marshal.FreeHGlobal(buf);
59+
}
60+
return false;
61+
});
62+
}
63+
}

0 commit comments

Comments
 (0)