Skip to content
Browse files

All necessary adaptions to the new hive API

  • Loading branch information...
1 parent f7a295e commit d0ecc037989cbc1ad69c46c378b0388e86b947ed @kmees kmees committed Mar 12, 2013
View
4 scripts/Get-IronHiveRegistry.ps1
@@ -1,8 +1,8 @@
function Global:Get-IronHiveRegistry
{
Add-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue
- [void][System.Reflection.Assembly]::LoadWithPartialName("IronSharePoint")
- return [IronSharePoint.Administration.IronHiveRegistry]::Local
+ [void][System.Reflection.Assembly]::LoadWithPartialName("IronSharePoint.Framework")
+ return [IronSharePoint.Framework.Administration.IronHiveRegistry]::Local
}
'Use Get-IronHiveRegistry to load the IronHiveRegistry'| out-host
View
2 src/IronSharePoint.Framework/IronConsole/IronConsole.cs
@@ -55,7 +55,7 @@ public void Dispose()
public static IronConsole GetConsoleForRuntime(IronRuntime runtime)
{
- var hiveId = runtime.IronHive.Id;
+ var hiveId = runtime.Id;
IronConsole console;
if (!_hiveConsoles.TryGetValue(hiveId, out console) || console.IsDisposed)
{
View
2 src/IronSharePoint.Framework/IronConsole/IronConsoleTask.cs
@@ -33,7 +33,7 @@ public void Execute()
IronConsoleResult = new IronConsoleResult();
try
{
- _engine = _runtime.GetEngineByExtension(_extension, false);
+ _engine = _runtime.GetEngineByExtension(_extension);
var scriptEngine = _engine.ScriptEngine;
ExecuteBeforeHooks(scriptEngine, IronConsoleResult);
View
18 src/IronSharePoint.Framework/IronDebug.cs
@@ -1,18 +0,0 @@
-#if DEBUG
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-
-namespace IronSharePoint
-{
- public class IronDebug
- {
- public static string IronDevHivePah
- {
-
- get{ return System.Environment.GetEnvironmentVariable("IRONSPDEVHIVE").Replace("\\","/");}
- }
- }
-}
-#endif
View
2 src/IronSharePoint.Framework/IronExpressionBuilder.cs
@@ -59,7 +59,7 @@ public override object EvaluateExpression(object target, System.Web.UI.BoundProp
{
IronRuntime.LogError("Error", ex);
- if (SPContext.Current.Web.UserIsSiteAdmin && engine.IronRuntime.IronHive.Web.CurrentUser.IsSiteAdmin)
+ if (SPContext.Current.Web.UserIsSiteAdmin)
{
var eo = engine.ScriptEngine.GetService<ExceptionOperations>();
string error = eo.FormatException(ex);
View
331 src/IronSharePoint.Framework/IronHive.cs
@@ -1,331 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Collections.ObjectModel;
-using System.Linq;
-using System.Runtime.CompilerServices;
-using System.Text;
-using System.Text.RegularExpressions;
-using IronSharePoint.Util;
-using Microsoft.Scripting.Hosting;
-using Microsoft.SharePoint;
-using Microsoft.Scripting;
-using System.IO;
-using System.Web;
-using IronSharePoint.Administration;
-using System.Security;
-using Microsoft.SharePoint.Utilities;
-
-namespace IronSharePoint
-{
- public class IronHive : ScriptHost, IDisposable
- {
- private static object _sync = new object();
-
- private IronPlatformAdaptationLayer _ironAdaptationLayer;
-
- public Guid Id { get; internal set; }
-
- [ThreadStatic] private static Dictionary<Guid, SPSite> _sites;
-
- public Dictionary<Guid, SPSite> Sites
- {
- get { return _sites ?? (_sites = new Dictionary<Guid, SPSite>()); }
- }
-
- public SPSite Site
- {
- get
- {
- var key = IronHelper.GetPrefixedKey("Hive_" + Id);
- var context = HttpContext.Current;
- SPSite site;
-
- if (context != null)
- {
- if (!context.Items.Contains(key))
- {
- context.Items[key] = new SPSite(Id, SPUserToken.SystemAccount);
- }
- site = context.Items[key] as SPSite;
- }
- else
- {
- if (!Sites.ContainsKey(Id))
- {
- Sites[Id] = new SPSite(Id, SPUserToken.SystemAccount);
- }
- site = Sites[Id];
- }
-
- return site;
- }
- }
-
- public SPWeb Web
- {
- get
- {
- return Site.RootWeb;
- }
- }
-
- public SPFolder Folder
- {
- get
- {
- return Web.GetFolder(IronConstant.HiveLibraryPath);
- }
- }
-
- public SPList List
- {
- get
- {
- return Folder.DocumentLibrary;
- }
- }
-
- public SPFeature Feature
- {
- get
- {
- var hiveFeature = Site.Features[new Guid(IronConstant.IronHiveSiteFeatureId)];
-
- if (hiveFeature == null)
- {
- throw new InvalidOperationException(String.Format("'IronSP Hive Site' feature is not activated on the site with the id {0}", Id));
- }
-
- return hiveFeature;
- }
- }
-
-
- public string FeatureFolderPath
- {
- get
- {
- return new DirectoryInfo(Feature.Definition.RootDirectory).Parent.FullName;
- }
- }
-
- public event EventHandler<HiveChangedArgs> Events;
-
- internal void FireHiveEvent(object sender, string eventName, SPItemEventProperties eventProperties)
- {
- if (Events != null)
- {
- Events.Invoke(sender, new HiveChangedArgs(){ Event=eventName, EventProperties=eventProperties});
- }
- }
-
- public string CurrentDir
- {
- get { return Path.Combine(FeatureFolderPath, IronConstant.IronSpRoot); }
- }
-
- public override PlatformAdaptationLayer PlatformAdaptationLayer
- {
- get
- {
- return _ironAdaptationLayer ?? (_ironAdaptationLayer = new IronPlatformAdaptationLayer(this));
- }
- }
-
- public IronPlatformAdaptationLayer IronPlatformAdaptationLayer
- {
- get
- {
- return _ironAdaptationLayer ?? (_ironAdaptationLayer = new IronPlatformAdaptationLayer(this));
- }
- }
-
-
-
- private volatile string[] _files;
-
- public string[] Files
- {
- get
- {
- if (_files == null)
- {
- lock (_sync)
- {
- if (_files == null)
- {
- var query = new SPQuery();
- query.Query = "<Where></Where>";
- query.ViewFields = "<FieldRef Name='FileRef'/><FieldRef Name='FileLeafRef'/>";
- query.ViewAttributes = "Scope='Recursive'";
- query.IncludeMandatoryColumns = false;
-
- var allItems = this.List.GetItems(query);
-
- var files = new List<String>();
-
- foreach (SPListItem item in allItems)
- {
- var fileRef = item["FileRef"].ToString();
- var siteRelative = fileRef.Replace((Web.ServerRelativeUrl + "/"), String.Empty);
- var hiveRelative = siteRelative.Replace(IronConstant.HiveLibraryPath + "/",
- string.Empty);
-
- files.Add(hiveRelative);
- }
-
- _files = files.ToArray();
- }
- }
- }
-
- return _files;
- }
- }
-
- public string LoadText(string file)
- {
- if (ContainsFile(file))
- {
- return Web.GetFileAsString(GetFullPath(file));
- }
-
- return null;
- }
-
- internal void Close()
- {
- if (Sites.ContainsKey(Id))
- {
- Sites[Id].Dispose();
- Sites.Remove(Id);
- }
- }
-
- public void Dispose()
- {
- Close();
- _files = null;
- }
-
- public bool ContainsFile(string file)
- {
- file = Normalize(file);
-
- return Files.Contains(file);
- }
-
- public bool ContainsDirectory(string path)
- {
- if (path == ".") return true;
-
- path = Normalize(path);
-
- return !Files.Contains(path) && Files.Any(x => x.StartsWith(path));
- }
-
- public string GetFullPath(string file)
- {
- file = Normalize(file);
-
- return String.Format("{0}/{1}", Folder.ServerRelativeUrl, file);
- }
-
- public SPFile LoadFile(string file)
- {
- using (new SPMonitoredScope(string.Format("IronHive Access - {0}", file)))
- {
- if (ContainsFile(file))
- {
- var spFile = Web.GetFile(GetFullPath(file));
- if (spFile.Exists)
- {
- return spFile;
- }
- }
-
- return null;
- }
- }
-
- public void Add(string file, byte[] data)
- {
- if (ContainsFile(file))
- {
- var spFile = LoadFile(file);
- spFile.SaveBinary(data);
- }
- else
- {
- Folder.Files.Add(GetFullPath(file), data);
- }
- }
-
- internal string Normalize(string file)
- {
- if (file.StartsWith(IronConstant.IronHiveRoot))
- {
- file = file.Replace(IronConstant.IronHiveRoot, string.Empty);
- }
- else if (file.StartsWith(IronConstant.HiveLibraryPath + "/"))
- {
- file = file.Replace(IronConstant.HiveLibraryPath + "/", string.Empty);
- }
- else if (file.StartsWith("."))
- {
- string fullPath;
- try
- {
- file = Path.GetFullPath(file).Replace(CurrentDir + "\\", string.Empty);
- }
- catch
- {
- // do nothing
- }
- }
-
- return file.Replace('\\', '/');
- }
-
- public class HiveChangedArgs : EventArgs
- {
- public string Event { get; set; }
- public SPItemEventProperties EventProperties { get; set; }
- }
-
-
- public string[] GetDirectories(string path, string searchPattern)
- {
- path = Normalize(path);
-
- var regexPath = path == string.Empty ? "" : path + "/";
- var regexPattern = string.Format("({0}{1})/", regexPath, searchPattern.Replace("*", "[^/]+"));
- var regex = new Regex(regexPattern);
- return Files.Select(file =>
- {
- var match = regex.Match(file);
- return match.Success ? match.Groups[1].Value : null;
- })
- .Where(x => x != null)
- .Distinct()
- .ToArray();
- }
-
- public string[] GetFiles(string path, string searchPattern)
- {
- path = Normalize(path);
-
- var regexPath = path == string.Empty ? "" : path + "/";
- var regexPattern = string.Format("{0}{1}", regexPath, searchPattern.Replace("*", "[^/]+$"));
- var regex = new Regex(regexPattern);
- return Files.Select(file =>
- {
- var match = regex.Match(file);
- return match.Success ? match.Groups[0].Value : null;
- })
- .Where(x => x != null)
- .Distinct()
- .ToArray();
- }
- }
-}
View
3 src/IronSharePoint.Framework/IronHttpModule.cs
@@ -44,15 +44,14 @@ void Error(object sender, EventArgs e)
logger.Log(String.Format("Error: {0} at {1}!", exception.Message, exception.StackTrace), LogLevel.Fatal);
- //hack: ruby engine hard coded
var engine = runtime.GetEngineByExtension(".rb");
if (engine != null)
{
var eo = engine.ScriptEngine.GetService<ExceptionOperations>();
string error = eo.FormatException(exception);
- logger.Log(String.Format("Ruby Error: {0} at {1}", exception.Message, error),LogLevel.Fatal);
+ logger.Log(String.Format("Ruby Error: {0} at {1}", exception.Message, error), LogLevel.Fatal);
}
}
View
2 src/IronSharePoint.Framework/IronLog/IronLogger.cs
@@ -27,7 +27,7 @@ public void Log(string message, LogLevel level)
try
{
- SPSite site = _runtime.IronHive.Site;
+ var site = _runtime.Site;
site.AddWorkItem(Guid.NewGuid(),
DateTime.UtcNow,
View
120 src/IronSharePoint.Framework/IronPlatformAdaptationLayer.cs
@@ -1,121 +1,93 @@
using System;
using System.Collections.Generic;
using System.Linq;
-using System.Text;
using System.Text.RegularExpressions;
using Microsoft.Scripting;
-using Microsoft.SharePoint;
using System.IO;
-using System.Web;
-using Microsoft.SharePoint.Utilities;
namespace IronSharePoint
{
public class IronPlatformAdaptationLayer : PlatformAdaptationLayer
{
- private readonly IronHive _ironHive;
+ private readonly IHive _hive;
- public IronPlatformAdaptationLayer(IronHive host)
+ public IronPlatformAdaptationLayer(IHive hive)
{
- _ironHive=host;
+ _hive = hive;
}
public override string[] GetFileSystemEntries(string path, string searchPattern, bool includeFiles, bool includeDirectories)
{
- using (new SPMonitoredScope(string.Format("AdaptionLayer Query - {0}", path)))
+ var entries = new List<string>();
+ if (includeFiles)
{
- var entries = base.GetFileSystemEntries(path, searchPattern, includeFiles, includeDirectories);
- /*
- * HACK: if you just return 'app/foo/bar.rb', IronRuby removes the first two characters for whatever reason. Therefore, appending to random chars fixes this
- */
- return entries;//.Select(x => Regex.IsMatch(x, @"^\w:") ? x : "@@" + x).ToArray();
+ //entries.AddRange(Directory.GetFiles(path, searchPattern));
+ entries.AddRange(_hive.GetFiles(path, searchPattern));
}
+ if (includeDirectories)
+ {
+ //entries.AddRange(Directory.GetDirectories(path, searchPattern));
+ entries.AddRange(_hive.GetDirectories(path, searchPattern));
+ }
+ var result = entries.Distinct().Select(x => Regex.IsMatch(x, @"^\w:") ? x : "@@" + x).ToArray();
+ return result;
}
public override bool DirectoryExists(string path)
{
- return base.DirectoryExists(path) || _ironHive.ContainsDirectory(path);
+ return base.DirectoryExists(path) || _hive.DirectoryExists(path);
}
public override bool FileExists(string file)
{
- bool fileExists = !file.StartsWith(IronConstant.IronHiveRoot) && base.FileExists(file);
-
- if (!fileExists)
- {
- fileExists = _ironHive.ContainsFile(file);
- }
-
- return fileExists;
+ return base.FileExists(file) || _hive.FileExists(file);
}
- public override System.IO.Stream OpenOutputFileStream(string path)
+ public override string GetFullPath(string file)
{
- Stream fileStream = null;
- if (!path.StartsWith(IronConstant.IronHiveRoot) && base.FileExists(path))
- {
- fileStream = base.OpenOutputFileStream(path);
- }
- else
- {
- var spFile = _ironHive.LoadFile(path);
-
- if (spFile != null)
- {
- fileStream = spFile.OpenBinaryStream();
- }
- }
-
- return fileStream;
+ return base.FileExists(file) ? base.GetFullPath(file) : _hive.GetFullPath(file);
}
- public override string GetFullPath(string file)
+ public override Stream OpenOutputFileStream(string path)
{
- if (_ironHive.ContainsFile(file))
- {
- return _ironHive.GetFullPath(file);
- }
- return base.GetFullPath(file);
+ return base.FileExists(path) ? base.OpenInputFileStream(path) : _hive.OpenOutputFileStream(path);
}
public override Stream OpenInputFileStream(string path)
{
- Stream fileStream = null;
- if (!path.StartsWith(IronConstant.IronHiveRoot) && base.FileExists(path))
- {
- fileStream = base.OpenInputFileStream(path);
- }
- else
- {
- var spFile = _ironHive.LoadFile(path);
+ return base.FileExists(path) ? base.OpenInputFileStream(path) : _hive.OpenOutputFileStream(path);
+ }
- if (spFile != null)
- {
- fileStream = spFile.OpenBinaryStream();
- }
- }
+ public override Stream OpenInputFileStream(string path, FileMode mode, FileAccess access, FileShare share)
+ {
+ return base.FileExists(path) ? base.OpenInputFileStream(path, mode, access, share) : _hive.OpenOutputFileStream(path);
+ }
- return fileStream;
+ public override Stream OpenInputFileStream(string path, FileMode mode, FileAccess access, FileShare share, int bufferSize)
+ {
+ return base.FileExists(path) ?
+ base.OpenInputFileStream(path, mode, access, share, bufferSize) :
+ _hive.OpenOutputFileStream(path);
}
- public override Stream OpenInputFileStream(string path, FileMode mode, FileAccess access, FileShare share)
+ public override void CreateDirectory(string path)
{
- Stream fileStream = null;
- if (!path.StartsWith(IronConstant.IronHiveRoot) && base.FileExists(path))
- {
- fileStream = base.OpenInputFileStream(path, mode, access, share);
- }
- else
- {
- var spFile = _ironHive.LoadFile(path);
+ throw new NotSupportedException();
+ }
- if (spFile != null)
- {
- fileStream = spFile.OpenBinaryStream();
- }
- }
+ public override void DeleteDirectory(string path, bool recursive)
+ {
+ throw new NotSupportedException();
+ }
- return fileStream;
+ public override void DeleteFile(string path, bool deleteReadOnly)
+ {
+ throw new NotSupportedException();
+ }
+
+ public override void MoveFileSystemEntry(string sourcePath, string destinationPath)
+ {
+ throw new NotSupportedException();
}
}
}
View
272 src/IronSharePoint.Framework/IronRuntime.cs
@@ -1,41 +1,36 @@
using System;
using System.Collections.Generic;
-using System.Diagnostics;
using System.IO;
-using System.Threading;
using System.Web;
-using IronSharePoint.Administration;
using IronSharePoint.Diagnostics;
using Microsoft.Scripting.Hosting;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;
using Microsoft.SharePoint.Utilities;
-using System.Linq;
namespace IronSharePoint
{
public class IronRuntime : IDisposable
{
- // the key is the ID of the hive
+ // SiteId -> Runtime
private static readonly Dictionary<Guid, IronRuntime> _staticLivingRuntimes =
new Dictionary<Guid, IronRuntime>();
private static readonly object _sync = new Object();
- private readonly Guid _hiveId;
+ private readonly Guid _siteId;
+ private readonly Guid _id;
private IronConsole.IronConsole _console;
- private bool _isInitialized;
private ScriptRuntime _scriptRuntime;
- private IList<Guid> _authenticatedSites;
- private IronRuntime(Guid hiveId)
+ private IronRuntime(Guid siteId)
{
- _hiveId = hiveId;
+ _siteId = siteId;
+ _id = Guid.NewGuid();
DynamicTypeRegistry = new Dictionary<string, Object>();
DynamicFunctionRegistry = new Dictionary<string, Object>();
Engines = new Dictionary<string, IronEngine>();
- _authenticatedSites = new List<Guid>();
}
internal static Dictionary<Guid, IronRuntime> LivingRuntimes
@@ -56,32 +51,58 @@ public IronConsole.IronConsole IronConsole
public ScriptRuntime ScriptRuntime
{
- get
- {
- if (_scriptRuntime == null)
- {
- Initialize();
- }
+ get { return _scriptRuntime; }
+ }
- return _scriptRuntime;
- }
+ public IronScriptHost ScripHost
+ {
+ get { return (IronScriptHost) ScriptRuntime.Host; }
}
- public IronHive IronHive
+ public IHive Hive
{
- get { return (IronHive) ScriptRuntime.Host; }
+ get { return ScripHost.Hive; }
}
public Dictionary<string, Object> DynamicTypeRegistry { get; private set; }
public Dictionary<string, Object> DynamicFunctionRegistry { get; private set; }
+
public string HttpHandlerClass { get; set; }
public bool IsDisposed { get; private set; }
- public bool IsInitialized { get; set; }
- public bool IsInitializing { get; set; }
+
+ public Guid SiteId
+ {
+ get { return _siteId; }
+ }
public Guid Id
{
- get { return _hiveId; }
+ get { return _id; }
+ }
+
+ public SPSite Site
+ {
+ get
+ {
+ var key = IronHelper.GetPrefixedKey("Site_" + Id);
+ var httpContext = HttpContext.Current;
+ SPSite site;
+
+ if (httpContext != null)
+ {
+ if (!httpContext.Items.Contains(key))
+ {
+ httpContext.Items[key] = new SPSite(Id, SPUserToken.SystemAccount);
+ }
+ site = httpContext.Items[key] as SPSite;
+ }
+ else
+ {
+ site = new SPSite(Id, SPUserToken.SystemAccount);
+ }
+
+ return site;
+ }
}
#region IDisposable Members
@@ -91,96 +112,87 @@ public void Dispose()
if (!IsDisposed)
{
IsDisposed = true;
- if (IronHive != null)
- {
- IronHive.Close();
- }
if (_console != null)
{
_console.Dispose();
_console = null;
}
- LivingRuntimes.Remove(_hiveId);
+ LivingRuntimes.Remove(_siteId);
}
}
#endregion
private void Initialize()
{
- if (!IsInitialized && !IsInitializing)
+ var setup = new ScriptRuntimeSetup();
+ var languageSetup = new LanguageSetup(
+ "IronRuby.Runtime.RubyContext, IronRuby, Version=1.1.3.0, Culture=neutral, PublicKeyToken=7f709c5b713576e1",
+ IronConstant.IronRubyLanguageName,
+ new[] {"IronRuby", "Ruby", "rb"},
+ new[] {".rb"});
+ setup.LanguageSetups.Add(languageSetup);
+ setup.HostType = typeof (IronScriptHost);
+ setup.HostArguments = new object[] {_siteId};
+ setup.DebugMode = IronConstant.IronEnv == IronEnvironment.Debug;
+
+ _scriptRuntime = new ScriptRuntime(setup);
+
+ _scriptRuntime.LoadAssembly(typeof (IronRuntime).Assembly); // IronSharePoint
+ _scriptRuntime.LoadAssembly(typeof (SPSite).Assembly); // Microsoft.SharePoint
+ _scriptRuntime.LoadAssembly(typeof (IHttpHandler).Assembly); // System.Web
+
+ using (new SPMonitoredScope("Creating IronEngine(s)"))
{
- lock (_sync)
- {
- if (!IsInitialized && !IsInitializing)
+ string ironRubyRoot =
+ @"C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\TEMPLATE\FEATURES\IronSP_IronRuby";
+ SPSecurity.RunWithElevatedPrivileges(() => PrivilegedInitialize(ironRubyRoot));
+
+ ScriptEngine rubyEngine = _scriptRuntime.GetEngineByFileExtension(".rb");
+ rubyEngine.SetSearchPaths(new List<String>
{
- IsInitializing = true;
-
- var setup = new ScriptRuntimeSetup();
- var languageSetup = new LanguageSetup(
- "IronRuby.Runtime.RubyContext, IronRuby, Version=1.1.3.0, Culture=neutral, PublicKeyToken=7f709c5b713576e1",
- IronConstant.IronRubyLanguageName,
- new[] {"IronRuby", "Ruby", "rb"},
- new[] {".rb"});
- setup.LanguageSetups.Add(languageSetup);
- setup.HostType = typeof (IronHive);
- setup.DebugMode = IronConstant.IronEnv == IronEnvironment.Debug;
-
- _scriptRuntime = new ScriptRuntime(setup);
- (_scriptRuntime.Host as IronHive).Id = _hiveId;
-
- _scriptRuntime.LoadAssembly(typeof (IronRuntime).Assembly); // IronSharePoint
- _scriptRuntime.LoadAssembly(typeof (SPSite).Assembly); // Microsoft.SharePoint
- _scriptRuntime.LoadAssembly(typeof (IHttpHandler).Assembly); // System.Web
-
- using (new SPMonitoredScope("Creating IronEngine(s)"))
- {
- string ironRubyRoot = Path.Combine(IronHive.FeatureFolderPath, "IronSP_IronRuby\\");
- SPSecurity.RunWithElevatedPrivileges(() => PrivilegedInitialize(ironRubyRoot));
-
- ScriptEngine rubyEngine = _scriptRuntime.GetEngineByFileExtension(".rb");
- rubyEngine.SetSearchPaths(new List<String>
- {
- Path.Combine(ironRubyRoot, @"ironruby"),
- Path.Combine(ironRubyRoot, @"ruby\site_ruby\1.9.1"),
- Path.Combine(ironRubyRoot, @"ruby\1.9.1"),
- IronHive.CurrentDir
- });
-
- var ironRubyEngine = new IronEngine(this, rubyEngine);
- Engines[".rb"] = ironRubyEngine;
-
- ScriptScope scope = rubyEngine.CreateScope();
- scope.SetVariable("iron_runtime", this);
- scope.SetVariable("ruby_engine", ironRubyEngine);
- scope.SetVariable("rails_root", IronHive.CurrentDir);
- scope.SetVariable("rails_env", IronConstant.IronEnv == IronEnvironment.Debug ? "development" : IronConstant.IronEnv.ToString().ToLower());
- rubyEngine.Execute("$RUNTIME = iron_runtime; $RUBY_ENGINE = ruby_engine; RAILS_ROOT = rails_root; RAILS_ENV = rails_env", scope);
- IronConsole.Execute(@"
+ Path.Combine(ironRubyRoot, @"ironruby"),
+ Path.Combine(ironRubyRoot, @"ruby\site_ruby\1.9.1"),
+ Path.Combine(ironRubyRoot, @"ruby\1.9.1")
+ });
+
+ var ironRubyEngine = new IronEngine(this, rubyEngine);
+ Engines[".rb"] = ironRubyEngine;
+
+ ScriptScope scope = rubyEngine.CreateScope();
+ scope.SetVariable("iron_runtime", this);
+ scope.SetVariable("ruby_engine", ironRubyEngine);
+ scope.SetVariable("rails_root", ironRubyRoot);
+ scope.SetVariable("rails_env",
+ IronConstant.IronEnv == IronEnvironment.Debug
+ ? "development"
+ : IronConstant.IronEnv.ToString().ToLower());
+ rubyEngine.Execute(
+ "$RUNTIME = iron_runtime; " +
+ "RUBY_ENGINE = ruby_engine;" +
+ "RAILS_ROOT = rails_root;" +
+ "RAILS_ENV = rails_env",
+ scope);
+ IronConsole.Execute(@"
Dir.chdir RAILS_ROOT
require 'rubygems'
begin
load_assembly 'Microsoft.SharePoint.Publishing, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'
- require './iron_sharepoint'
- require 'application'
+#require './iron_sharepoint'
+# require 'application'
rescue Exception => ex
IRON_DEFAULT_LOGGER.error ex
ensure
$RUBY_ENGINE.is_initialized = true
end", ".rb", false);
- IsInitializing = false;
- IsInitialized = true;
- }
- }
- }
}
}
private void PrivilegedInitialize(string rubyRoot)
{
- string gemDir = Path.Combine(rubyRoot, "lib/ironruby/gems/1.8").Replace("\\", "/");
+ string gemDir = Path.Combine(rubyRoot, "lib/ironruby/gems/1.9.1").Replace("\\", "/");
Environment.SetEnvironmentVariable("IRONRUBY_10_20", rubyRoot);
Environment.SetEnvironmentVariable("GEM_PATH", gemDir);
@@ -189,100 +201,43 @@ private void PrivilegedInitialize(string rubyRoot)
public static IronRuntime GetDefaultIronRuntime(SPSite targetSite)
{
- const string RuntimeKey = "IronSP_Runtime";
using (new SPMonitoredScope("Retrieving IronRuntime"))
{
- var runtime = TryGetFromAuthenticated(targetSite);
- runtime = TryGetFromHttpContext(RuntimeKey, runtime);
+ Guid targetId = targetSite.ID;
+ IronRuntime runtime;
- if (runtime == null)
+ if (!TryGetExistingRuntime(targetId, out runtime))
{
- using (new SPMonitoredScope("Checking IronHiveRegistry"))
+ lock (_sync)
{
- Guid hiveId = IronHiveRegistry.Local.GetHiveForSite(targetSite.ID);
- if (hiveId == Guid.Empty)
- {
- throw new InvalidOperationException(
- String.Format("There is no IronHive mapping for the site with id {0}", targetSite.ID));
- }
-
- if (!LivingRuntimes.ContainsKey(hiveId))
+ if (!TryGetExistingRuntime(targetId, out runtime))
{
- lock (_sync)
+ using (new SPMonitoredScope("Creating IronRuntime"))
{
- if (!LivingRuntimes.TryGetValue(hiveId, out runtime))
- {
- using (new SPMonitoredScope("Creating IronRuntime"))
- {
- runtime = new IronRuntime(hiveId);
- runtime.Authenticate(targetSite.ID);
- LivingRuntimes[hiveId] = runtime;
- runtime.Initialize();
- }
- }
+ runtime = new IronRuntime(targetId);
+ LivingRuntimes[targetId] = runtime;
+ runtime.Initialize();
}
}
-
- runtime = LivingRuntimes[hiveId];
- if (HttpContext.Current != null)
- {
- HttpContext.Current.Items[RuntimeKey] = runtime;
- }
}
}
-
-
- if (!runtime.IsInitialized)
- {
- ShowUnavailable();
- }
+ if (HttpContext.Current != null) HttpContext.Current.Items[IronConstant.IronRuntimeKey] = runtime;
return runtime;
}
}
- private static IronRuntime TryGetFromHttpContext(string RuntimeKey, IronRuntime runtime)
- {
- if (HttpContext.Current != null)
- {
- if (runtime != null)
- {
- HttpContext.Current.Items[RuntimeKey] = runtime;
- }
- else if (HttpContext.Current.Items.Contains(RuntimeKey))
- {
- runtime = HttpContext.Current.Items[RuntimeKey] as IronRuntime;
- }
- }
- return runtime;
- }
-
- private static IronRuntime TryGetFromAuthenticated(SPSite targetSite)
+ private static bool TryGetExistingRuntime(Guid targetId, out IronRuntime runtime)
{
- IronRuntime runtime = LivingRuntimes.Values.FirstOrDefault(x => x.IsAuthenticated(targetSite.ID));
- return runtime;
- }
-
- private void Authenticate(Guid targetSite)
- {
- if (!_authenticatedSites.Contains(targetSite))
+ if (!LivingRuntimes.TryGetValue(targetId, out runtime) && HttpContext.Current != null)
{
- _authenticatedSites.Add(targetSite);
+ runtime = HttpContext.Current.Items[IronConstant.IronRuntimeKey] as IronRuntime;
}
- }
-
- private bool IsAuthenticated(Guid targetSite)
- {
- return _authenticatedSites.Contains(targetSite);
+ return runtime != null;
}
public IronEngine GetEngineByExtension(string extension)
{
- return GetEngineByExtension(extension, true);
- }
-
- public IronEngine GetEngineByExtension(string extension, bool initialized)
- {
IronEngine ironEngine = null;
if (!Engines.TryGetValue(extension, out ironEngine))
@@ -293,11 +248,6 @@ public IronEngine GetEngineByExtension(string extension, bool initialized)
throw ex;
}
- if (initialized && !ironEngine.IsInitialized)
- {
- ShowUnavailable();
- }
-
return ironEngine;
}
@@ -346,7 +296,7 @@ public static void LogVerbose(string msg)
TraceSeverity.Verbose, String.Format("{0}.", msg));
}
- static void ShowUnavailable()
+ private static void ShowUnavailable()
{
HttpContext.Current.Response.StatusCode = 503;
HttpContext.Current.Response.WriteFile(SPUtility.GetGenericSetupPath(@"TEMPLATE\LAYOUTS\IronSP\503.html"));
View
2 src/IronSharePoint.Framework/IronWrapperControl.cs
@@ -87,7 +87,7 @@ protected override void Render(HtmlTextWriter writer)
{
if (Exception != null)
{
- if (SPContext.Current.Web.UserIsSiteAdmin && engine.IronRuntime.IronHive.Web.CurrentUser.IsSiteAdmin)
+ if (SPContext.Current.Web.UserIsSiteAdmin)
{
var eo = engine.ScriptEngine.GetService<ExceptionOperations>();
string error = eo.FormatException(Exception);
View
7 src/IronSharePoint.Framework/IronWrapperUserControl.cs
@@ -79,10 +79,7 @@ protected override void OnInit(EventArgs e)
if (!String.IsNullOrEmpty(TemplatePath))
{
var path = TemplatePath.Replace("~site", SPContext.Current.Site.ServerRelativeUrl)
- .Replace("~web", SPContext.Current.Web.ServerRelativeUrl)
- .Replace("~hiveSite", engine.IronRuntime.IronHive.Site.ServerRelativeUrl)
- .Replace("~hiveWeb", engine.IronRuntime.IronHive.Web.ServerRelativeUrl)
- .Replace("~hiveFolder", engine.IronRuntime.IronHive.Folder.ServerRelativeUrl);
+ .Replace("~web", SPContext.Current.Web.ServerRelativeUrl);
Template = this.LoadTemplate(path);
Template.InstantiateIn(ctrl);
@@ -105,7 +102,7 @@ protected override void Render(HtmlTextWriter writer)
{
if (_exception!=null)
{
- if (SPContext.Current.Web.UserIsSiteAdmin && engine.IronRuntime.IronHive.Web.CurrentUser.IsSiteAdmin)
+ if (SPContext.Current.Web.UserIsSiteAdmin)
{
var eo = engine.ScriptEngine.GetService<ExceptionOperations>();
string error = eo.FormatException(_exception);
View
6 src/IronSharePoint.Framework/Properties/AssemblyInfo.cs
@@ -34,5 +34,7 @@
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
-[assembly: InternalsVisibleTo("IronSharePoint.Test, PublicKey=00240000048000009400000006020000002400005253413100040000010001003d8f4a0ce7a813cd4e641c03cfb699cfb2d8ce38f38fc35768fd6cc67390df5e0cddb42a22313644ab2a253e5f94bc0ba3c40c3f6df903da664e30052588ac2ac8470ca4915399d29377dd1518aedaba85e22c25074724339d263036869d1500a8cf02d013f4874313660c5f1bf2390b57bb2cba2b7c865495bc8d273ccd95c1")]
-[assembly: InternalsVisibleTo("IronSharePoint, PublicKey=00240000048000009400000006020000002400005253413100040000010001003d8f4a0ce7a813cd4e641c03cfb699cfb2d8ce38f38fc35768fd6cc67390df5e0cddb42a22313644ab2a253e5f94bc0ba3c40c3f6df903da664e30052588ac2ac8470ca4915399d29377dd1518aedaba85e22c25074724339d263036869d1500a8cf02d013f4874313660c5f1bf2390b57bb2cba2b7c865495bc8d273ccd95c1")]
+[assembly: InternalsVisibleTo("IronSharePoint.Framework.Test, PublicKey=00240000048000009400000006020000002400005253413100040000010001003d8f4a0ce7a813cd4e641c03cfb699cfb2d8ce38f38fc35768fd6cc67390df5e0cddb42a22313644ab2a253e5f94bc0ba3c40c3f6df903da664e30052588ac2ac8470ca4915399d29377dd1518aedaba85e22c25074724339d263036869d1500a8cf02d013f4874313660c5f1bf2390b57bb2cba2b7c865495bc8d273ccd95c1")]
+[assembly: InternalsVisibleTo("IronSharePoint, PublicKey=00240000048000009400000006020000002400005253413100040000010001003d8f4a0ce7a813cd4e641c03cfb699cfb2d8ce38f38fc35768fd6cc67390df5e0cddb42a22313644ab2a253e5f94bc0ba3c40c3f6df903da664e30052588ac2ac8470ca4915399d29377dd1518aedaba85e22c25074724339d263036869d1500a8cf02d013f4874313660c5f1bf2390b57bb2cba2b7c865495bc8d273ccd95c1")]
+
+[assembly: System.Security.SecurityRules(System.Security.SecurityRuleSet.Level1)]
View
28 src/IronSharePoint/EventReceivers/IronHiveEventReceiver.cs
@@ -17,73 +17,73 @@ public new bool EventFiringEnabled
public override void ItemAdded(SPItemEventProperties properties)
{
- IronRuntime.GetDefaultIronRuntime(properties.Web.Site).IronHive.FireHiveEvent(this, "ItemAdded", properties);
+ //IronRuntime.GetDefaultIronRuntime(properties.Web.Site).IronHive.FireHiveEvent(this, "ItemAdded", properties);
}
public override void ItemUpdated(SPItemEventProperties properties)
{
- IronRuntime.GetDefaultIronRuntime(properties.Web.Site).IronHive.FireHiveEvent(this, "ItemUpdated", properties);
+ //IronRuntime.GetDefaultIronRuntime(properties.Web.Site).IronHive.FireHiveEvent(this, "ItemUpdated", properties);
}
public override void ItemDeleted(SPItemEventProperties properties)
{
- IronRuntime.GetDefaultIronRuntime(properties.Web.Site).IronHive.FireHiveEvent(this, "ItemDeleted", properties);
+ //IronRuntime.GetDefaultIronRuntime(properties.Web.Site).IronHive.FireHiveEvent(this, "ItemDeleted", properties);
}
public override void ItemFileMoved(SPItemEventProperties properties)
{
- IronRuntime.GetDefaultIronRuntime(properties.Web.Site).IronHive.FireHiveEvent(this, "ItemDeleted", properties);
+ //IronRuntime.GetDefaultIronRuntime(properties.Web.Site).IronHive.FireHiveEvent(this, "ItemDeleted", properties);
}
public override void ItemCheckedIn(SPItemEventProperties properties)
{
- IronRuntime.GetDefaultIronRuntime(properties.Web.Site).IronHive.FireHiveEvent(this, "ItemCheckedIn", properties);
+ //IronRuntime.GetDefaultIronRuntime(properties.Web.Site).IronHive.FireHiveEvent(this, "ItemCheckedIn", properties);
}
public override void ItemCheckedOut(SPItemEventProperties properties)
{
- IronRuntime.GetDefaultIronRuntime(properties.Web.Site).IronHive.FireHiveEvent(this, "ItemCheckedOut", properties);
+ //IronRuntime.GetDefaultIronRuntime(properties.Web.Site).IronHive.FireHiveEvent(this, "ItemCheckedOut", properties);
}
public override void ItemAdding(SPItemEventProperties properties)
{
- IronRuntime.GetDefaultIronRuntime(properties.Web.Site).IronHive.FireHiveEvent(this, "ItemAdding", properties);
+ //IronRuntime.GetDefaultIronRuntime(properties.Web.Site).IronHive.FireHiveEvent(this, "ItemAdding", properties);
}
public override void ItemUpdating(SPItemEventProperties properties)
{
- IronRuntime.GetDefaultIronRuntime(properties.Web.Site).IronHive.FireHiveEvent(this, "ItemUpdating", properties);
+ //IronRuntime.GetDefaultIronRuntime(properties.Web.Site).IronHive.FireHiveEvent(this, "ItemUpdating", properties);
}
public override void ItemDeleting(SPItemEventProperties properties)
{
- IronRuntime.GetDefaultIronRuntime(properties.Web.Site).IronHive.FireHiveEvent(this, "ItemDeleting", properties);
+ // IronRuntime.GetDefaultIronRuntime(properties.Web.Site).IronHive.FireHiveEvent(this, "ItemDeleting", properties);
}
public override void ItemFileMoving(SPItemEventProperties properties)
{
- IronRuntime.GetDefaultIronRuntime(properties.Web.Site).IronHive.FireHiveEvent(this, "ItemFileMoving", properties);
+ //IronRuntime.GetDefaultIronRuntime(properties.Web.Site).IronHive.FireHiveEvent(this, "ItemFileMoving", properties);
}
public override void ItemCheckingIn(SPItemEventProperties properties)
{
- IronRuntime.GetDefaultIronRuntime(properties.Web.Site).IronHive.FireHiveEvent(this, "ItemCheckingIn", properties);
+ //IronRuntime.GetDefaultIronRuntime(properties.Web.Site).IronHive.FireHiveEvent(this, "ItemCheckingIn", properties);
}
public override void ItemCheckingOut(SPItemEventProperties properties)
{
- IronRuntime.GetDefaultIronRuntime(properties.Web.Site).IronHive.FireHiveEvent(this, "ItemCheckingOut", properties);
+ //IronRuntime.GetDefaultIronRuntime(properties.Web.Site).IronHive.FireHiveEvent(this, "ItemCheckingOut", properties);
}
public override void ItemUncheckedOut(SPItemEventProperties properties)
{
- IronRuntime.GetDefaultIronRuntime(properties.Web.Site).IronHive.FireHiveEvent(this, "ItemUncheckedOut", properties);
+ //IronRuntime.GetDefaultIronRuntime(properties.Web.Site).IronHive.FireHiveEvent(this, "ItemUncheckedOut", properties);
}
public override void ItemUncheckingOut(SPItemEventProperties properties)
{
- IronRuntime.GetDefaultIronRuntime(properties.Web.Site).IronHive.FireHiveEvent(this, "ItemUncheckingOut", properties);
+ //IronRuntime.GetDefaultIronRuntime(properties.Web.Site).IronHive.FireHiveEvent(this, "ItemUncheckingOut", properties);
}
}
View
2 src/IronSharePoint/EventReceivers/IronScriptCompilerReceiver.cs
@@ -61,7 +61,7 @@ private void CompileScript(SPItemEventProperties properties)
if (runtime != null)
{
- runtime.IronHive.Dispose();
+ //runtime.IronHive.Dispose();
}
}
}
View
4 src/IronSharePoint/Features/IronSP_Hive_Site/IronSP_Hive_Site.EventReceiver.cs
@@ -26,7 +26,7 @@ public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
//var site = properties.Feature.Parent as SPSite;
//var web = site.RootWeb;
- //var list = web.GetList(web.ServerRelativeUrl + "/" + IronConstant.HiveLibraryPath);
+ //var list = web.GetList(web.ServerRelativeUrl + "/" + IronConstant.IronHiveLibraryPath);
//string assembly = typeof(IronHiveEventReceiver).Assembly.FullName;
//string type = typeof(IronHiveEventReceiver).FullName;
@@ -55,7 +55,7 @@ public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
{
var site = properties.Feature.Parent as SPSite;
var web = site.RootWeb;
- var list = web.GetList(web.ServerRelativeUrl + "/" + IronConstant.HiveLibraryPath);
+ var list = web.GetList(web.ServerRelativeUrl + "/" + IronConstant.IronHiveLibraryPath);
string type = typeof(IronHiveEventReceiver).FullName;
View
0 ...amework/IronConsole/IronConsoleWebPart.cs → ...rePoint/IronConsole/IronConsoleWebPart.cs
File renamed without changes.
View
5 src/IronSharePoint/IronPart/IronPart.cs
@@ -92,9 +92,10 @@ protected override void Render(HtmlTextWriter writer)
{
if (Exception != null)
{
- if (SPContext.Current.Web.UserIsSiteAdmin && ironRuntime.IronHive.Web.CurrentUser.IsSiteAdmin)
+ if (SPContext.Current.Web.UserIsSiteAdmin)
{
- IronRuntime.LogError(String.Format("Error: {0}", ScriptName, Exception.Message), Exception);
+ IronRuntime.LogError(String.Format("Script: {0}, Error: {1}", ScriptName, Exception.Message),
+ Exception);
writer.Write(Exception.Message);
}
View
1 src/IronSharePoint/IronSharePoint.csproj
@@ -133,6 +133,7 @@
<Compile Include="IronConsole\IronConsoleUserControl.ascx.designer.cs">
<DependentUpon>IronConsoleUserControl.ascx.cs</DependentUpon>
</Compile>
+ <Compile Include="IronConsole\IronConsoleWebPart.cs" />
<Compile Include="IronPart\IronPart.cs" />
<Compile Include="Layouts\IronSP\IronEditor.aspx.cs">
<DependentUpon>IronEditor.aspx</DependentUpon>
View
4 src/IronSharePoint/Layouts/IronSP/IronConsoleService.ashx.cs
@@ -1,11 +1,11 @@
using System;
using System.Collections.Generic;
using System.Web.Script.Serialization;
+using IronSharePoint.Administration;
using IronSharePoint.IronConsole;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using System.Web;
-using IronSharePoint.Administration;
using System.Linq;
namespace IronSharePoint
@@ -32,7 +32,7 @@ public void ProcessRequest(HttpContext context)
return;
}
- IronHiveRegistry.Local.EnsureTrustedHive(site.ID);
+ //HiveRegistry.Local.IsTrusted(site.ID);
//var ironRuntime = IronRuntime.GetIronRuntime(site, site.ID);
var ironRuntime = IronRuntime.GetDefaultIronRuntime(site);
View
2 src/IronSharePoint/Package/Package.package
@@ -5,7 +5,7 @@
<customAssembly location="Microsoft.Scripting.dll" deploymentTarget="GlobalAssemblyCache" sourcePath="..\..\lib\Microsoft.Scripting.dll" />
<customAssembly location="Microsoft.Scripting.Metadata.dll" deploymentTarget="GlobalAssemblyCache" sourcePath="..\..\lib\Microsoft.Scripting.Metadata.dll" />
<projectOutputAssembly location="IronSharePoint.Framework.dll" deploymentTarget="GlobalAssemblyCache" projectPath="..\IronSharePoint.Framework\IronSharePoint.Framework.csproj" />
- <customAssembly location="Newtonsoft.Json.dll" deploymentTarget="GlobalAssemblyCache" sourcePath="..\..\packages\Newtonsoft.Json.4.5.9\lib\net40\Newtonsoft.Json.dll" />
+ <customAssembly location="Newtonsoft.Json.dll" deploymentTarget="GlobalAssemblyCache" sourcePath="..\..\packages\Newtonsoft.Json.4.5.11\lib\net40\Newtonsoft.Json.dll" />
</assemblies>
<features>
<featureReference itemId="02961df1-c0a7-44bf-8545-5a24466136f9" />
View
2 src/IronSharePoint/Properties/AssemblyInfo.cs
@@ -37,3 +37,5 @@
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AllowPartiallyTrustedCallers()]
[assembly: InternalsVisibleTo("IronSharePoint.Test, PublicKey=00240000048000009400000006020000002400005253413100040000010001003d8f4a0ce7a813cd4e641c03cfb699cfb2d8ce38f38fc35768fd6cc67390df5e0cddb42a22313644ab2a253e5f94bc0ba3c40c3f6df903da664e30052588ac2ac8470ca4915399d29377dd1518aedaba85e22c25074724339d263036869d1500a8cf02d013f4874313660c5f1bf2390b57bb2cba2b7c865495bc8d273ccd95c1")]
+
+[assembly: System.Security.SecurityRules(System.Security.SecurityRuleSet.Level1)]
View
20 test/IronSharePoint.Framework.Test/Dummy.cs
@@ -1,20 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using FluentAssertions;
-using NUnit.Framework;
-
-namespace IronSharePoint.Framework.Test
-{
- [TestFixture]
- class Dummy
- {
- [Test]
- public void Test()
- {
- true.Should().BeTrue("works");
- }
- }
-}

0 comments on commit d0ecc03

Please sign in to comment.
Something went wrong with that request. Please try again.