Skip to content

Commit

Permalink
Merge pull request #304 from Orckestra/dev
Browse files Browse the repository at this point in the history
Orckestra CMS 5.5
  • Loading branch information
Marcus Wendt authored Nov 14, 2016
2 parents 40060b5 + 7b5d39e commit a834e36
Show file tree
Hide file tree
Showing 23 changed files with 852 additions and 681 deletions.
21 changes: 12 additions & 9 deletions Composite/Composite.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,10 @@
<Compile Include="C1Console\Workflow\FormsWorkflowExtensions.cs" />
<Compile Include="C1Console\Workflow\IFormsWorkflowExtension.cs" />
<Compile Include="Core\Extensions\DateTimeExtensionMethods.cs" />
<Compile Include="Core\WebClient\PhantomJs\PhantomServer.cs" />
<Compile Include="Core\WebClient\PhantomJs\RenderingResult.cs" />
<Compile Include="Core\WebClient\PhantomJs\RenderingResultStatus.cs" />
<Compile Include="Core\WebClient\PhantomJs\RenderPreviewRequest.cs" />
<Compile Include="Core\WebClient\Services\ConsoleMessageService\OpenSlideViewParams.cs" />
<Compile Include="Data\DataScopeServicesFacade.cs" />
<Compile Include="Data\DataServiceScopeManager.cs" />
Expand Down Expand Up @@ -263,7 +267,6 @@
<Compile Include="Core\Routing\Pages\SeoFriendlyRedirectRouteHandler.cs" />
<Compile Include="Core\Threading\ThreadCultureScope.cs" />
<Compile Include="Core\WebClient\BrowserRender.cs" />
<Compile Include="Core\WebClient\BrowserRender_PhantomServer.cs" />
<Compile Include="Core\WebClient\BuildManagerHelper.cs" />
<Compile Include="Core\WebClient\Captcha\CaptchaConfiguration.cs" />
<Compile Include="Core\WebClient\Renderings\FunctionPreview.cs" />
Expand Down Expand Up @@ -2521,16 +2524,16 @@
</BootstrapperPackage>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Import Project="$(MSBuildExtensionsPath)\Microsoft\Windows Workflow Foundation\v3.5\Workflow.Targets" />
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Import Project="$(MSBuildExtensionsPath)\Microsoft\Windows Workflow Foundation\v3.5\Workflow.Targets" />
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
<PropertyGroup>
<PostBuildEvent>copy "$(TargetPath)" "$(ProjectDir)..\bin\"
<PostBuildEvent>copy "$(TargetPath)" "$(ProjectDir)..\bin\"
copy "$(TargetPath)" "$(ProjectDir)..\Website\bin\"</PostBuildEvent>
</PropertyGroup>
</Project>
76 changes: 38 additions & 38 deletions Composite/Core/PackageSystem/PackageAssemblyHandler.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using Composite.C1Console.Events;
using Composite.Core.Types.Foundation;
Expand All @@ -11,29 +10,36 @@ namespace Composite.Core.PackageSystem
{
internal static class PackageAssemblyHandler
{
private static bool _initialized = false;
private static bool _initialized;
private static readonly object _lock = new object();
private static AssemblyFilenameCollection _loadedAssemblyFilenames = new AssemblyFilenameCollection();

private static List<Assembly> _inMemoryAssemblies = new List<Assembly>();

public static void Initialize()
{
if (!_initialized)
if (_initialized) return;

lock (_lock)
{
lock (_lock)
{
if (!_initialized)
{
GlobalEventSystemFacade.SubscribeToFlushEvent(OnFlushEvent);
if (_initialized) return;

AppDomain.CurrentDomain.AssemblyResolve += OnAssemblyResolve;
GlobalEventSystemFacade.SubscribeToFlushEvent(args => ClearAssemblyList());

_initialized = true;
}
}
AppDomain.CurrentDomain.AssemblyResolve += OnAssemblyResolve;
AppDomain.CurrentDomain.AssemblyLoad += OnAssemblyLoad;

_initialized = true;
}
}

private static void OnAssemblyLoad(object sender, AssemblyLoadEventArgs args)
{
var asm = args.LoadedAssembly;
if (!asm.IsDynamic)
{
Log.LogVerbose(nameof(PackageAssemblyHandler), $"Assembly loaded: {asm.Location}");
}
}


public static void AddAssembly(string assemblyFilePath)
Expand All @@ -47,24 +53,25 @@ public static void AddAssembly(string assemblyFilePath)
}



private static Assembly OnAssemblyResolve(object sender, ResolveEventArgs args)
public static Assembly TryGetAlreadyLoadedAssembly(string assemblyFileName)
{
string filename = args.Name;
string assemblyName = AssemblyFilenameCollection.GetAssemblyName(assemblyFileName);

// Why can the system not load the "System.Web.Extensions" assembly?
// And "Composite.Core.XmlSerializers" <-- Licensing?
// For now ignore it, so no exception is thrown /MRJ
if ((filename == "System.Web.Extensions") ||
(filename.StartsWith("Composite.Core.XmlSerializers")))
lock (_lock)
{
return null;
return _inMemoryAssemblies.FirstOrDefault(asm => asm.GetName().Name == assemblyName);
}
}


private static Assembly OnAssemblyResolve(object sender, ResolveEventArgs args)
{
string filename = args.Name;

string fn = filename;
if (fn.Contains(","))
{
fn = fn.Remove(fn.IndexOf(",")).Trim();
fn = fn.Remove(fn.IndexOf(',')).Trim();
}

if (_loadedAssemblyFilenames.ContainsAssemblyName(fn))
Expand All @@ -77,11 +84,16 @@ private static Assembly OnAssemblyResolve(object sender, ResolveEventArgs args)
{
try
{
assembly = Assembly.LoadFile(filename);
assembly = Assembly.LoadFrom(filename);
}
catch (Exception ex)
{
Log.LogError("PackageAssemblyHandler", ex);
Log.LogError(nameof(PackageAssemblyHandler), ex);
}

lock (_lock)
{
_inMemoryAssemblies.Add(assembly);
}
}

Expand All @@ -90,24 +102,12 @@ private static Assembly OnAssemblyResolve(object sender, ResolveEventArgs args)


public static void ClearAssemblyList()
{
Flush();
}


private static void Flush()
{
lock (_lock)
{
_loadedAssemblyFilenames = new AssemblyFilenameCollection();
_inMemoryAssemblies = new List<Assembly>();
}
}



private static void OnFlushEvent(FlushEventArgs args)
{
Flush();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ private XElement AddData(DataType dataType, CultureInfo cultureInfo)
{
IData existingData = DataFacade.TryGetDataByUniqueKey(interfaceType, dataKey);

if (data != null)
if (existingData != null)
{
CopyFieldValues(dataType, existingData, addElement);
DataFacade.Update(existingData, false, true, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,24 +347,7 @@ public override IEnumerable<XElement> Install()
if (targetFilePath.StartsWith(Path.Combine(PathUtil.BaseDirectory, "Bin"), StringComparison.InvariantCultureIgnoreCase)
&& targetFilePath.EndsWith(".dll", StringComparison.InvariantCultureIgnoreCase))
{
string fileName = Path.GetFileName(targetFilePath);

if (!DllsNotToLoad.Any(fileName.StartsWith))
{
Assembly assembly;

try
{
assembly = Assembly.LoadFrom(targetFilePath);
}
catch (Exception)
{
continue;
}

DataTypeTypesManager.AddNewAssembly(assembly, false);
}

LoadDataTypesFromDll(targetFilePath);
}

var fileElement = new XElement("File", new XAttribute("filename", fileToCopy.TargetRelativeFilePath));
Expand All @@ -380,6 +363,29 @@ public override IEnumerable<XElement> Install()
yield return new XElement("Files", fileElements);
}

private void LoadDataTypesFromDll(string filePath)
{
string fileName = Path.GetFileName(filePath);

if (DllsNotToLoad.Any(fileName.StartsWith)) return;

var assembly = PackageAssemblyHandler.TryGetAlreadyLoadedAssembly(filePath);

if(assembly == null)
{
try
{
assembly = Assembly.LoadFrom(filePath);
}
catch (Exception)
{
return;
}
}

DataTypeTypesManager.AddNewAssembly(assembly, false);
}

private string GetBackupFileName(string targetFilePath)
{
string fileName = Path.GetFileName(targetFilePath);
Expand Down
Loading

0 comments on commit a834e36

Please sign in to comment.