Permalink
Browse files

Various minor fixes but it kinda runs now

  • Loading branch information...
kmees committed Mar 14, 2013
1 parent 58251c6 commit 440f8325ae3ac65cdaf4eb03b24330bb4e15799b
@@ -76,15 +76,19 @@ public IEnumerable<string> GetFiles(string path, string searchPattern, bool abso
{
path = GetFullPath(path);
- var files = Directory.GetFiles(path, searchPattern).Select(Path.GetFullPath);
+ var files = DirectoryExists(path)
+ ? Directory.GetFiles(path, searchPattern).Select(Path.GetFullPath)
+ : new string[0];
return absolutePaths ? files : files.Select(GetPartialPath);
}
public IEnumerable<string> GetDirectories(string path, string searchPattern, bool absolutePaths = false)
{
path = GetFullPath(path);
- var directories = Directory.GetDirectories(path, searchPattern).Select(Path.GetFullPath);
+ var directories = DirectoryExists(path)
+ ? Directory.GetDirectories(path, searchPattern).Select(Path.GetFullPath)
+ : new string[0];
return absolutePaths ? directories : directories.Select(GetPartialPath);
}
@@ -4,6 +4,7 @@
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
+using System.Threading;
using System.Web;
using IronSharePoint.Util;
using Microsoft.SharePoint;
@@ -20,10 +21,14 @@ public class SPDocumentHive : IHive
private string _webUrl;
private string _hiveLibraryUrl;
- private SPSite _site;
- private SPDocumentLibrary _hiveLibrary;
+ private ThreadLocal<SPSite> _site;
- private string[] _cachedFiles;
+ public SPSite Site
+ {
+ get { return _site.Value; }
+ }
+
+ private string[] _cachedFiles;
private string[] _cachedDirs;
public IEnumerable<string> CachedFiles
@@ -45,6 +50,8 @@ public SPDocumentHive(Guid siteId, string hiveLibraryPath)
{
_siteId = siteId;
_hiveLibraryPath = hiveLibraryPath;
+
+ _site = new ThreadLocal<SPSite>(() => new SPSite(_siteId, SPUserToken.SystemAccount), true);
Reset();
}
@@ -64,15 +71,11 @@ public bool DirectoryExists(string path)
public Stream OpenInputFileStream(string path)
{
- return OpenLibrary(lib =>
- {
- string fullPath = GetFullPath(path);
- Console.WriteLine(fullPath);
- var spFile = lib.ParentWeb.GetFile(fullPath);
- if (!spFile.Exists) throw new FileNotFoundException("", fullPath);
+ string filePath = GetFullPath(path);
+ var spFile = Site.RootWeb.GetFile(filePath);
+ if (!spFile.Exists) throw new FileNotFoundException("", filePath);
- return spFile.OpenBinaryStream();
- });
+ return spFile.OpenBinaryStream();
}
public Stream OpenOutputFileStream(string path)
@@ -135,6 +138,8 @@ public IEnumerable<string> GetDirectories(string path, string searchPattern, boo
public void Reset()
{
+ Dispose();
+
var allFilesQuery = new SPQuery();
allFilesQuery.Query = "<Where></Where>";
allFilesQuery.ViewFields = "<FieldRef Name='FileRef'/><FieldRef Name='FileLeafRef'/>";
@@ -143,51 +148,28 @@ public void Reset()
var allFiles = new List<string>();
- OpenLibrary(lib =>
- {
- _webUrl = lib.ParentWebUrl;
- _hiveLibraryUrl = CombinePath(_webUrl, _hiveLibraryPath);
+ var folder = Site.RootWeb.GetFolder(_hiveLibraryPath);
+ var lib = folder.DocumentLibrary;
+ _webUrl = Site.RootWeb.Url;
+ _hiveLibraryUrl = CombinePath(_webUrl, _hiveLibraryPath);
- var allItems = lib.GetItems(allFilesQuery);
- foreach (SPListItem item in allItems)
- {
- var fileRef = item["FileRef"].ToString();
- var siteRelative = fileRef.ReplaceFirst(lib.ParentWeb.ServerRelativeUrl, string.Empty).TrimStart('/');
- var hiveRelative = siteRelative.ReplaceFirst(_hiveLibraryPath,string.Empty).TrimStart('/');
+ var allItems = lib.GetItems(allFilesQuery);
+ foreach (SPListItem item in allItems)
+ {
+ var fileRef = item["FileRef"].ToString();
+ var siteRelative = fileRef.ReplaceFirst(Site.RootWeb.ServerRelativeUrl, string.Empty).TrimStart('/');
+ var hiveRelative = siteRelative.ReplaceFirst(_hiveLibraryPath, string.Empty).TrimStart('/');
- allFiles.Add(hiveRelative);
- }
- });
+ allFiles.Add(hiveRelative);
+ }
_cachedFiles = allFiles.ToArray();
-// ReSharper disable PossibleNullReferenceException
+ // ReSharper disable PossibleNullReferenceException
_cachedDirs = _cachedFiles.Select(x => Path.GetDirectoryName(x).Replace('\\', '/'))
- .Distinct()
- .Where(x => !String.IsNullOrWhiteSpace(x))
- .ToArray();
-// ReSharper restore PossibleNullReferenceException
- }
-
- private T OpenLibrary<T>(Func<SPDocumentLibrary, T> func)
- {
- if (_site == null)
- {
- _site = new SPSite(_siteId);
- var folder = _site.RootWeb.GetFolder(_hiveLibraryPath);
- _hiveLibrary = folder.DocumentLibrary;
- }
-
- return func(_hiveLibrary);
- }
-
- private void OpenLibrary(Action<SPDocumentLibrary> action)
- {
- var func = new Func<SPDocumentLibrary, bool>(lib =>
- {
- action(lib);
- return true;
- });
- OpenLibrary(func);
+ .Distinct()
+ .Where(x => !String.IsNullOrWhiteSpace(x))
+ .ToArray();
+ // ReSharper restore PossibleNullReferenceException
}
private string GetPartialPath(string path)
@@ -199,11 +181,9 @@ private string GetPartialPath(string path)
public void Dispose()
{
- if (_site != null)
+ foreach (var spSite in _site.Values)
{
- _site.Dispose();
- _site = null;
- _hiveLibrary = null;
+ spSite.Dispose();
}
}
}
@@ -69,7 +69,7 @@ public override Stream OpenInputFileStream(string path)
return DelegateToHiveOrBase(path,
_hive.OpenInputFileStream,
x =>
- base.FileExists(x) ? base.OpenInputFileStream(x) : _hive.OpenOutputFileStream(x));
+ base.FileExists(x) ? base.OpenInputFileStream(x) : _hive.OpenInputFileStream(x));
}
public override Stream OpenInputFileStream(string path, FileMode mode, FileAccess access, FileShare share)
@@ -79,7 +79,7 @@ public override Stream OpenInputFileStream(string path, FileMode mode, FileAcces
x =>
base.FileExists(x)
? base.OpenInputFileStream(x, mode, access, share)
- : _hive.OpenOutputFileStream(x));
+ : _hive.OpenInputFileStream(x));
}
public override Stream OpenInputFileStream(string path, FileMode mode, FileAccess access, FileShare share,
@@ -90,12 +90,16 @@ public override Stream OpenInputFileStream(string path, FileMode mode, FileAcces
x =>
base.FileExists(x)
? base.OpenInputFileStream(x, mode, access, share, bufferSize)
- : _hive.OpenOutputFileStream(x));
+ : _hive.OpenInputFileStream(x));
}
private T DelegateToHiveOrBase<T>(string path, Func<string, T> hive, Func<string, T> @base)
{
T result;
+ if (path.StartsWith("./"))
+ {
+ path = path.ReplaceFirst("./", "");
+ }
if (path.StartsWith(IronConstant.FakeHiveDirectory))
{
result = hive(path.ReplaceFirst(IronConstant.FakeHiveDirectory, string.Empty));
@@ -120,6 +120,8 @@ public void Dispose()
_console.Dispose();
_console = null;
}
+ ScripHost.Dispose();
+
LivingRuntimes.Remove(_siteId);
}
}
@@ -182,8 +184,8 @@ Dir.chdir RAILS_ROOT
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
@@ -1,83 +1 @@
-<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
-<%@ Assembly Name="Microsoft.Web.CommandUI, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
-<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="IronConsoleUserControl.ascx.cs" Inherits="IronSharePoint.IronConsole.IronConsoleUserControl" %>
-<%@ Import Namespace="Microsoft.SharePoint" %>
-
-<style type="text/css">
- #ironSP-console-input {
- -webkit-box-sizing: border-box;
- -moz-box-sizing: border-box;
- box-sizing: border-box;
- border-width: 0px;
- overflow: auto;
- width: 90%;
- float: left;
- }
-
- #ironSP-console-container {
- padding: 5px;
- max-height: 500px;
- overflow: auto;
- }
-
- #ironSP-console { }
-
- .ironSP-console-edit { background-color: Yellow !important; }
-
- .ironSP-console-line td, .ironSP-console-prompt td, #ironSP-console-input {
- color: black !important;
- font-family: "Droid Sans Mono", Consolas, Courier !important;
- font-size: 12pt;
- }
-
- .ironSP-console-prefix { padding-right: 5px; }
-
- .ironSP-console-prefix {
- padding-top: 2px;
- vertical-align: top;
- }
-
- .ironSP-console-error td, .ironSP-console-stackTrace td {
- color: red !important;
- font-size: 10pt;
- }
-
- .ironSP-console-output { font-style: italic; }
-
- .ironSP-console-executing { background: url('_layouts/images/IronSP/ajax-loader.gif') no-repeat right top }
-</style>
-
-
-<script type="text/javascript">
- $(document).ready(function() {
- var console = new IronConsole('<%= SPContext.Current.Web.Url %>/_layouts/IronSP/IronConsoleService.ashx?ext=.rb')
- var consoleView = new IronConsoleView(console)
- });
-</script>
-
-<script id="ironSP-console-line-template" type='text/html'>
- <tr class='ironSP-console-line ironSP-console-{{type}}'>
- <td class='ironSP-console-prefix'>
- <span>{{prefix}}</span>
- </td>
- <td>
- <span>{{text}}</span>
- </td>
- </tr>
-</script>
-<script id="ironSP-console-template" type='text/html'>
- <table id="ironSP-console">
- <tr class='ironSP-console-prompt'>
- <td class='ironSP-console-prefix'>
- <span>{{prompt}}</span>
- </td>
- <td>
- <textarea id="ironSP-console-input" cols="80" rows="5"/>
- </td>
- </tr>
- </table>
-</script>
-
-<div id="ironSP-console-container">
-
-</div>
+<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %><%@ Assembly Name="Microsoft.Web.CommandUI, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %><%@ Control Language="C#" AutoEventWireup="true" CodeBehind="IronConsoleUserControl.ascx.cs" Inherits="IronSharePoint.IronConsole.IronConsoleUserControl" %><style type="text/css">#ironSP-console-input {-moz-box-sizing: border-box;-webkit-box-sizing: border-box;border-width: 0px;box-sizing: border-box;float: left;overflow: auto;width: 90%;}#ironSP-console-container {max-height: 500px;overflow: auto;padding: 5px;}#ironSP-console { }.ironSP-console-edit { background-color: Yellow !important; }.ironSP-console-line td, .ironSP-console-prompt td, #ironSP-console-input {color: black !important;font-family: "Droid Sans Mono", Consolas, Courier !important;font-size: 12pt;}.ironSP-console-prefix { padding-right: 5px; }.ironSP-console-prefix {padding-top: 2px;vertical-align: top;}.ironSP-console-error td, .ironSP-console-stackTrace td {color: red !important;font-size: 10pt;}.ironSP-console-output { font-style: italic; }.ironSP-console-executing { background: url('_layouts/images/IronSP/ajax-loader.gif') no-repeat right top }</style><script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.9.1.min.js" type="text/javascript"> </script><script src="/_layouts/15/IronSP/mustache.js" type="text/javascript"> </script><script src="/_layouts/15/IronSP/IronConsole.js" type="text/javascript"> </script><script type="text/javascript">$(document).ready(function() {var console = new IronConsole('<%= CurrentContext.Web.Url %>/_layouts/15/IronSP/IronConsoleService.ashx?ext=.rb');var consoleView = new IronConsoleView(console);});</script><script id="ironSP-console-line-template" type='text/html'><tr class='ironSP-console-line ironSP-console-{{type}}'><td class='ironSP-console-prefix'><span>{{prefix}}</span></td><td><span>{{text}}</span></td></tr></script><script id="ironSP-console-template" type='text/html'><table id="ironSP-console"><tr class='ironSP-console-prompt'><td class='ironSP-console-prefix'><span>{{prompt}}</span></td><td><textarea id="ironSP-console-input" cols="80" rows="5"/></td></tr></table></script><div id="ironSP-console-container"></div>
@@ -1,10 +1,16 @@
using System;
using System.Web.UI;
+using Microsoft.SharePoint;
namespace IronSharePoint.IronConsole
{
public partial class IronConsoleUserControl : UserControl
{
- protected void Page_Load(object sender, EventArgs e) {}
+ public SPContext CurrentContext
+ {
+ get { return SPContext.Current; }
+ }
+
+ protected void Page_Load(object sender, EventArgs e) { }
}
}
@@ -8,7 +8,7 @@ namespace IronSharePoint.IronConsole
public class IronConsoleWebPart : WebPart
{
// Visual Studio might automatically update this path when you change the Visual Web Part project item.
- const string _ascxPath = @"~/_CONTROLTEMPLATES/IronSP/IronConsole/IronConsoleUserControl.ascx";
+ const string _ascxPath = @"~/_CONTROLTEMPLATES/15/IronSP/IronConsole/IronConsoleUserControl.ascx";
protected override void CreateChildControls()
{
@@ -205,6 +205,8 @@
<None Include="TEMPLATE\Features\IronSP_Root\iron_sharepoint\mixins\sp_context_accessors.rb" />
<None Include="TEMPLATE\Features\IronSP_Root\iron_sharepoint\mixins\type_registration.rb" />
<None Include="TEMPLATE\Features\IronSP_Root\iron_sharepoint\mixins\view_helpers.rb" />
+ <None Include="TEMPLATE\Features\IronSP_Root\iron_sharepoint\patches\core\object.rb" />
+ <None Include="TEMPLATE\Features\IronSP_Root\iron_sharepoint\patches\core\regexp.rb" />
<None Include="TEMPLATE\Features\IronSP_Root\iron_sharepoint\patches\core\string.rb" />
<None Include="TEMPLATE\Features\IronSP_Root\iron_sharepoint\patches\log4r\logger.rb" />
<None Include="TEMPLATE\Features\IronSP_Root\iron_sharepoint\rescues\template_error.haml" />
@@ -222,6 +222,14 @@ public void GetFiles_OnRoot_DoesNotContainDirectory()
Sut.GetFiles(".", "*").Should().NotContain("bar");
}
+ [Test]
+ public void GetFiles_InMissingDirectory_DoesNotThrow()
+ {
+ Sut = new PhysicalHive(_assetsRoot);
+
+ Assert.DoesNotThrow(() => Sut.GetFiles("c:\\i_do_not_exist", "*"));
+ }
+
[Test]
public void GetDirectories_AbsolutePaths()
{
@@ -245,5 +253,13 @@ public void GetDirectories_OnRoot_DoesNotContainFile()
Sut.GetDirectories(".", "*").Should().NotContain("lorem.txt");
}
+
+ [Test]
+ public void GetDirectories_InMissingDirectory_DoesNotThrow()
+ {
+ Sut = new PhysicalHive(_assetsRoot);
+
+ Assert.DoesNotThrow(() => Sut.GetDirectories("c:\\i_do_not_exist", "*"));
+ }
}
}
@@ -258,9 +258,8 @@ private SPSite FakeNextSPSite()
Isolate.WhenCalled(() => site.RootWeb).WillReturn(web);
Isolate.WhenCalled(() => web.GetFolder(IronConstant.IronHiveLibraryPath)).WillReturn(folder);
Isolate.WhenCalled(() => web.ServerRelativeUrl).WillReturn("/sites/IronSP");
+ Isolate.WhenCalled(() => web.Url).WillReturn("http://foo.com/sites/IronSP");
Isolate.WhenCalled(() => folder.DocumentLibrary).WillReturn(lib);
- Isolate.WhenCalled(() => lib.ParentWeb).WillReturn(web);
- Isolate.WhenCalled(() => lib.ParentWebUrl).WillReturn("http://foo.com/sites/IronSP");
Isolate.WhenCalled(() => lib.GetItems((SPQuery) null)).WillReturnCollectionValuesOf(spListItems);
return site;

0 comments on commit 440f832

Please sign in to comment.