Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added IronScriptHost and support for sites without hives

  • Loading branch information...
commit 0c2c20514a2f2f59259f63731072aafa2a479d28 1 parent 0dca4fe
@kmees kmees authored
View
13 src/IronSharePoint.Framework/Administration/HiveRegistry.cs
@@ -17,12 +17,12 @@ public class HiveRegistry : SPPersistedObject
/// <summary>
/// Maps a target id (SPSite, SPWebApplication, ...) to a list of hives
/// </summary>
- [Persisted] private readonly Dictionary<Guid, HiveSetupCollection> _mappedHives = new Dictionary<Guid, HiveSetupCollection>();
+ [Persisted] private Dictionary<Guid, HiveSetupCollection> _mappedHives = new Dictionary<Guid, HiveSetupCollection>();
/// <summary>
/// The list of trusted hives
/// </summary>
- [Persisted] private readonly List<HiveSetup> _trustedHives = new List<HiveSetup>();
+ [Persisted] private List<HiveSetup> _trustedHives = new List<HiveSetup>();
public IEnumerable<HiveSetup> TrustedHives
{
@@ -178,7 +178,7 @@ public virtual void EnsureTrustedHive(object id)
/// <exception cref="SecurityException"></exception>
public virtual void EnsureTrustedHive(HiveSetup hive)
{
- if (hive == null || !TrustedHives.Contains(hive))
+ if(hive != null && !TrustedHives.Contains(hive))
{
throw new SecurityException(String.Format("Hive '{0}' is not a trusted hive", hive));
}
@@ -201,5 +201,12 @@ public override void Update(bool ensure)
}
});
}
+
+ protected override void OnDeserialization()
+ {
+ base.OnDeserialization();
+ if (_trustedHives == null) _trustedHives = new List<HiveSetup>();
+ if (_mappedHives == null) _mappedHives = new Dictionary<Guid, HiveSetupCollection>();
+ }
}
}
View
2  src/IronSharePoint.Framework/Hives/SPDocumentHive.cs
@@ -34,7 +34,7 @@ public IEnumerable<string> CachedDirs
}
public SPDocumentHive(Guid siteId)
- : this(siteId, IronConstant.HiveLibraryPath)
+ : this(siteId, IronConstant.IronHiveLibraryPath)
{
}
View
22 src/IronSharePoint.Framework/IronConstant.cs
@@ -1,21 +1,28 @@
using System;
using System.Collections.Generic;
+using System.IO;
using System.Linq;
using System.Text;
+using Microsoft.SharePoint.Administration;
namespace IronSharePoint
{
public static class IronConstant
{
- public const string IronHiveRoot = "IronHive://";
- public const string HiveLibraryPath = "_catalogs/IronHive";
+ public const string IronHiveLibraryPath = "_catalogs/IronHive";
public const string IronLogsListPath = "Lists/IronLogs";
+
public const string IronSiteFeatureId = "a1752f91-1403-40c1-a257-69eddf8976cf";
public const string IronHiveSiteFeatureId = "354ee774-7d04-4ad6-91f9-1bc433a70bee";
public const string IronRubyFeatureId = "183909b9-cfb3-477c-a48c-02e3d5e59844";
- public const string IronRubyLanguageName = "IronRuby";
+
public const string IronPrefix = "IronSP_";
- public const string IronSpRoot = IronPrefix + "Root";
+
+ public const string IronRubyLanguageName = "IronRuby";
+ public const string IronRuntimeKey = IronPrefix + "Runtime";
+
+ public static string IronSPRootDirectory =
+ @"C:\Program Files\Common Files\microsoft shared\Web Server Extensions\14\TEMPLATE\FEATURES\IronSP_Root";
public static IronEnvironment IronEnv
{
@@ -39,5 +46,12 @@ public static IronEnvironment IronEnv
return env;
}
}
+
+ // static IronConstant()
+ // {
+ // var siteFeatureDirectory = SPFarm.Local.FeatureDefinitions[IronConstant.IronHiveSiteFeatureId].RootDirectory;
+ // var featureDirectory = new DirectoryInfo(siteFeatureDirectory).Parent.FullName;
+ // IronSPRootDirectory = Path.Combine(featureDirectory, "IronSP_Root");
+ // }
}
}
View
68 src/IronSharePoint.Framework/IronScriptHost.cs
@@ -0,0 +1,68 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using IronSharePoint.Administration;
+using IronSharePoint.Hives;
+using Microsoft.Scripting.Hosting;
+using Microsoft.SharePoint.Administration;
+
+namespace IronSharePoint
+{
+ public class IronScriptHost : ScriptHost
+ {
+ private readonly IronPlatformAdaptationLayer _ironPlatformAdaptationLayer;
+ private readonly Guid _siteId;
+ private readonly IHive _hive;
+
+ public IHive Hive
+ {
+ get { return _hive; }
+ }
+
+ public IronScriptHost(Guid siteId)
+ {
+ _siteId = siteId;
+ _hive = CreateHive();
+ _ironPlatformAdaptationLayer = new IronPlatformAdaptationLayer(Hive);
+ }
+
+ public override Microsoft.Scripting.PlatformAdaptationLayer PlatformAdaptationLayer
+ {
+ get { return _ironPlatformAdaptationLayer; }
+ }
+
+ private IHive CreateHive()
+ {
+ var hives = CreateHivesFromRegistry().ToList();
+
+ if (!hives.Any(x => x is PhysicalHive &&
+ (x as PhysicalHive).Root == IronConstant.IronSPRootDirectory))
+ {
+ var spRootHive = new PhysicalHive(IronConstant.IronSPRootDirectory);
+ hives.Add(spRootHive);
+ }
+
+ return new OrderedHiveList(hives.ToArray());
+ }
+
+ private IEnumerable<IHive> CreateHivesFromRegistry()
+ {
+ var registry = HiveRegistry.Local;
+ try
+ {
+ var descriptions = registry.GetMappedHivesForSite(_siteId).OrderBy(x => x.Priority);
+ return descriptions.Select(x =>
+ {
+ var argTypes = x.HiveArguments.GetType();
+ var ctor = x.HiveType.GetConstructor(new[] {argTypes});
+ return (IHive) ctor.Invoke(new[] {x.HiveArguments});
+ });
+ }
+ catch (ArgumentException)
+ {
+ return new IHive[0];
+ }
+ }
+ }
+}
View
3  src/IronSharePoint.Framework/IronSharePoint.Framework.csproj
@@ -120,9 +120,6 @@
<Compile Include="IronExpressionBuilder.cs" />
<Compile Include="IronField.cs" />
<Compile Include="IronHelper.cs" />
- <Compile Include="IronHive.cs">
- <SubType>Code</SubType>
- </Compile>
<Compile Include="IronHttpHandler.cs" />
<Compile Include="IronHttpModule.cs" />
<Compile Include="IronJob.cs" />
View
2  test/IronSharePoint.Framework.Test/Hive/SPDocumentHive_Fixture.cs
@@ -247,7 +247,7 @@ private SPSite FakeNextSPSite()
});
Isolate.WhenCalled(() => site.RootWeb).WillReturn(web);
- Isolate.WhenCalled(() => web.GetFolder(IronConstant.HiveLibraryPath)).WillReturn(folder);
+ Isolate.WhenCalled(() => web.GetFolder(IronConstant.IronHiveLibraryPath)).WillReturn(folder);
Isolate.WhenCalled(() => web.ServerRelativeUrl).WillReturn("/sites/IronSP");
Isolate.WhenCalled(() => folder.DocumentLibrary).WillReturn(lib);
Isolate.WhenCalled(() => lib.ParentWeb).WillReturn(web);
View
1  test/IronSharePoint.Framework.Test/IronSharePoint.Framework.Test.csproj
@@ -39,6 +39,7 @@
<Reference Include="FluentAssertions">
<HintPath>..\..\packages\FluentAssertions.2.0.1\lib\net45\FluentAssertions.dll</HintPath>
</Reference>
+ <Reference Include="Microsoft.Scripting, Version=1.1.0.20, Culture=neutral, PublicKeyToken=7f709c5b713576e1, processorArchitecture=MSIL" />
<Reference Include="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c, processorArchitecture=MSIL" />
<Reference Include="Moq">
<HintPath>..\..\packages\Moq.4.0.10827\lib\NET40\Moq.dll</HintPath>
Please sign in to comment.
Something went wrong with that request. Please try again.