diff --git a/Composite.Workflows/Plugins/Elements/ElementProviders/GeneratedDataTypesElementProvider/AddNewCompositionTypeWorkflow.cs b/Composite.Workflows/Plugins/Elements/ElementProviders/GeneratedDataTypesElementProvider/AddNewCompositionTypeWorkflow.cs
index d9880ee27b..5a14407878 100644
--- a/Composite.Workflows/Plugins/Elements/ElementProviders/GeneratedDataTypesElementProvider/AddNewCompositionTypeWorkflow.cs
+++ b/Composite.Workflows/Plugins/Elements/ElementProviders/GeneratedDataTypesElementProvider/AddNewCompositionTypeWorkflow.cs
@@ -132,7 +132,7 @@ private void saveTypeCodeActivity_Save_ExecuteCode(object sender, EventArgs e)
helper.SetLocalizedControlled(hasLocalization);
}
- helper.SetCachable(hasCaching);
+ helper.SetCacheable(hasCaching);
helper.SetNewTypeFullName(typeName, typeNamespace);
helper.SetNewTypeTitle(typeTitle);
helper.SetNewFieldDescriptors(dataFieldDescriptors, null, labelFieldName);
diff --git a/Composite.Workflows/Plugins/Elements/ElementProviders/GeneratedDataTypesElementProvider/AddNewInterfaceTypeWorkflow.cs b/Composite.Workflows/Plugins/Elements/ElementProviders/GeneratedDataTypesElementProvider/AddNewInterfaceTypeWorkflow.cs
index 55eeae5aba..ab61d4eff7 100644
--- a/Composite.Workflows/Plugins/Elements/ElementProviders/GeneratedDataTypesElementProvider/AddNewInterfaceTypeWorkflow.cs
+++ b/Composite.Workflows/Plugins/Elements/ElementProviders/GeneratedDataTypesElementProvider/AddNewInterfaceTypeWorkflow.cs
@@ -166,7 +166,7 @@ private void codeActivity1_ExecuteCode(object sender, EventArgs e)
if (helper.IsEditProcessControlledAllowed)
{
- helper.SetCachable(hasCaching);
+ helper.SetCacheable(hasCaching);
helper.SetPublishControlled(hasPublishing);
helper.SetLocalizedControlled(hasLocalization);
helper.SetSearchable(isSearchable);
diff --git a/Composite.Workflows/Plugins/Elements/ElementProviders/GeneratedDataTypesElementProvider/EditCompositionTypeWorkflow.cs b/Composite.Workflows/Plugins/Elements/ElementProviders/GeneratedDataTypesElementProvider/EditCompositionTypeWorkflow.cs
index 78dba3175e..a9bfac6e93 100644
--- a/Composite.Workflows/Plugins/Elements/ElementProviders/GeneratedDataTypesElementProvider/EditCompositionTypeWorkflow.cs
+++ b/Composite.Workflows/Plugins/Elements/ElementProviders/GeneratedDataTypesElementProvider/EditCompositionTypeWorkflow.cs
@@ -62,7 +62,7 @@ private void initializeStateCodeActivity_Initialize_ExecuteCode(object sender, E
{"TypeNamespace", dataTypeDescriptor.Namespace},
{"TypeTitle", dataTypeDescriptor.Title},
{"LabelFieldName", dataTypeDescriptor.LabelFieldName},
- {"HasCaching", helper.IsCachable},
+ {"HasCaching", helper.IsCacheable},
{"HasPublishing", helper.IsPublishControlled},
{"DataFieldDescriptors", fieldDescriptors},
{"OldTypeName", dataTypeDescriptor.Name},
@@ -135,7 +135,7 @@ private void saveTypeCodeActivity_Save_ExecuteCode(object sender, EventArgs e)
helper.SetNewTypeTitle(typeTitle);
// TODO: fix
helper.SetNewFieldDescriptors(dataFieldDescriptors, null, labelFieldName);
- helper.SetCachable(hasCaching);
+ helper.SetCacheable(hasCaching);
if (helper.IsEditProcessControlledAllowed)
{
diff --git a/Composite.Workflows/Plugins/Elements/ElementProviders/GeneratedDataTypesElementProvider/EditInterfaceTypeWorkflow.cs b/Composite.Workflows/Plugins/Elements/ElementProviders/GeneratedDataTypesElementProvider/EditInterfaceTypeWorkflow.cs
index 79d99eb3f2..5cef7bb926 100644
--- a/Composite.Workflows/Plugins/Elements/ElementProviders/GeneratedDataTypesElementProvider/EditInterfaceTypeWorkflow.cs
+++ b/Composite.Workflows/Plugins/Elements/ElementProviders/GeneratedDataTypesElementProvider/EditInterfaceTypeWorkflow.cs
@@ -82,7 +82,7 @@ private void initialStateCodeActivity_ExecuteCode(object sender, EventArgs e)
{BindingNames.KeyFieldName, dataTypeDescriptor.KeyPropertyNames.Single() },
{BindingNames.LabelFieldName, dataTypeDescriptor.LabelFieldName},
{BindingNames.InternalUrlPrefix, dataTypeDescriptor.InternalUrlPrefix},
- {BindingNames.HasCaching, helper.IsCachable},
+ {BindingNames.HasCaching, helper.IsCacheable},
{BindingNames.HasPublishing, helper.IsPublishControlled},
{BindingNames.IsSearchable, helper.IsSearchable},
{BindingNames.DataFieldDescriptors, fieldDescriptors},
@@ -164,7 +164,7 @@ private void finalizeStateCodeActivity_ExecuteCode(object sender, EventArgs e)
if (helper.IsEditProcessControlledAllowed)
{
- helper.SetCachable(hasCaching);
+ helper.SetCacheable(hasCaching);
helper.SetSearchable(isSearchable);
helper.SetPublishControlled(hasPublishing);
helper.SetLocalizedControlled(hasLocalization);
diff --git a/Composite.Workflows/Plugins/Elements/ElementProviders/MethodBasedFunctionProviderElementProvider/AddInlineFunctionWorkflow.cs b/Composite.Workflows/Plugins/Elements/ElementProviders/MethodBasedFunctionProviderElementProvider/AddInlineFunctionWorkflow.cs
index 924c1a5d03..bffdc0842f 100644
--- a/Composite.Workflows/Plugins/Elements/ElementProviders/MethodBasedFunctionProviderElementProvider/AddInlineFunctionWorkflow.cs
+++ b/Composite.Workflows/Plugins/Elements/ElementProviders/MethodBasedFunctionProviderElementProvider/AddInlineFunctionWorkflow.cs
@@ -116,7 +116,7 @@ private void finalizeCodeActivity_Finalize_ExecuteCode(object sender, EventArgs
DataFacade.AddNew(reference);
}
- function.SetFunctinoCode(code);
+ function.SetFunctionCode(code);
function = DataFacade.AddNew(function);
diff --git a/Composite.Workflows/Plugins/Elements/ElementProviders/MethodBasedFunctionProviderElementProvider/EditInlineFunctionWorkflow.cs b/Composite.Workflows/Plugins/Elements/ElementProviders/MethodBasedFunctionProviderElementProvider/EditInlineFunctionWorkflow.cs
index 2b8c2d13b7..9e26d14b2a 100644
--- a/Composite.Workflows/Plugins/Elements/ElementProviders/MethodBasedFunctionProviderElementProvider/EditInlineFunctionWorkflow.cs
+++ b/Composite.Workflows/Plugins/Elements/ElementProviders/MethodBasedFunctionProviderElementProvider/EditInlineFunctionWorkflow.cs
@@ -162,7 +162,7 @@ private void saveCodeActivity_Save_ExecuteCode(object sender, EventArgs e)
ManagedParameterManager.Save(function.Id, parameters);
DataFacade.Update(function);
- InlineFunctionHelper.SetFunctinoCode(function, code);
+ function.SetFunctionCode(code);
transactionScope.Complete();
}
diff --git a/Composite/Composite.csproj b/Composite/Composite.csproj
index e07b7d5676..05215d67e2 100644
--- a/Composite/Composite.csproj
+++ b/Composite/Composite.csproj
@@ -256,6 +256,7 @@
+
diff --git a/Composite/Core/Types/CSharpCodeProviderFactory.cs b/Composite/Core/Types/CSharpCodeProviderFactory.cs
new file mode 100644
index 0000000000..eaf5a324bc
--- /dev/null
+++ b/Composite/Core/Types/CSharpCodeProviderFactory.cs
@@ -0,0 +1,13 @@
+using System.CodeDom.Compiler;
+using Microsoft.CSharp;
+
+namespace Composite.Core.Types
+{
+ internal class CSharpCodeProviderFactory
+ {
+ public static CSharpCodeProvider CreateCompiler()
+ {
+ return (CSharpCodeProvider)CodeDomProvider.CreateProvider("c#");
+ }
+ }
+}
diff --git a/Composite/Core/Types/CodeCompatibilityChecker.cs b/Composite/Core/Types/CodeCompatibilityChecker.cs
index 19d1696f01..b4fe57ac73 100644
--- a/Composite/Core/Types/CodeCompatibilityChecker.cs
+++ b/Composite/Core/Types/CodeCompatibilityChecker.cs
@@ -13,8 +13,6 @@
using Composite.Data;
using Composite.Data.DynamicTypes;
using Composite.Data.GeneratedTypes;
-using Microsoft.CSharp;
-
namespace Composite.Core.Types
{
@@ -30,11 +28,9 @@ internal static class CodeCompatibilityChecker
///
public static CompatibilityCheckResult CheckCompatibilityWithAppCodeFolder(DataTypeDescriptor dataTypeDescriptorToTest)
{
- return CheckAgainsAppCode(dataTypeDescriptorToTest, true);
+ return CheckAgainstAppCode(dataTypeDescriptorToTest, true);
}
-
-
///
/// This method will check if any code in en App_Code folder depends on the given data interface.
///
@@ -42,11 +38,9 @@ public static CompatibilityCheckResult CheckCompatibilityWithAppCodeFolder(DataT
///
public static CompatibilityCheckResult CheckIfAppCodeDependsOnInterface(DataTypeDescriptor dataTypeDescriptorToTest)
{
- return CheckAgainsAppCode(dataTypeDescriptorToTest, false);
+ return CheckAgainstAppCode(dataTypeDescriptorToTest, false);
}
-
-
///
/// This method checks to see if any change in the given data type descriptor will make code
/// in App_Code fail and hence the site will fail.
@@ -60,44 +54,57 @@ public static CompatibilityCheckResult CheckIfAppCodeDependsOnInterface(DataType
[SuppressMessage("Composite.IO", "Composite.DotNotUseStreamWriterClass:DotNotUseStreamWriterClass", Justification = "File api is used for creating temporary files")]
[SuppressMessage("Composite.IO", "Composite.DoNotUseFileStreamClass:DoNotUseFileStreamClass", Justification = "File api is used for creating temporary files")]
[SuppressMessage("Composite.IO", "Composite.DoNotUseFileClass:DoNotUseFileClass", Justification = "File api is used for creating temporary files")]
- private static CompatibilityCheckResult CheckAgainsAppCode(DataTypeDescriptor dataTypeDescriptorToTest, bool includeDataTypeDescriptor)
+ private static CompatibilityCheckResult CheckAgainstAppCode(DataTypeDescriptor dataTypeDescriptorToTest, bool includeDataTypeDescriptor)
{
- List filesToCompile = GetAppCodeFiles().ToList();
-
- if (filesToCompile.Count == 0) return new CompatibilityCheckResult();
+ var filesToCompile = GetAppCodeFiles().ToList();
+ if (filesToCompile.Count == 0)
+ {
+ return new CompatibilityCheckResult();
+ }
- var csCompiler = new CSharpCodeProvider();
+ var csCompiler = CSharpCodeProviderFactory.CreateCompiler();
- List referencedAssemblies = new List();
+ var referencedAssemblies = new List();
var codeTypeDeclarations = new Dictionary>();
foreach (var dataTypeDescriptor in DataMetaDataFacade.GeneratedTypeDataTypeDescriptors)
{
- if (!includeDataTypeDescriptor && dataTypeDescriptor.DataTypeId == dataTypeDescriptorToTest.DataTypeId) continue;
+ if (!includeDataTypeDescriptor && dataTypeDescriptor.DataTypeId == dataTypeDescriptorToTest.DataTypeId)
+ {
+ continue;
+ }
- DataTypeDescriptor dataTypeDescriptorToUse = dataTypeDescriptor;
- if (includeDataTypeDescriptor && dataTypeDescriptor.DataTypeId == dataTypeDescriptorToTest.DataTypeId) dataTypeDescriptorToUse = dataTypeDescriptorToTest;
+ var dataTypeDescriptorToUse = dataTypeDescriptor;
+
+ if (includeDataTypeDescriptor && dataTypeDescriptor.DataTypeId == dataTypeDescriptorToTest.DataTypeId)
+ {
+ dataTypeDescriptorToUse = dataTypeDescriptorToTest;
+ }
referencedAssemblies.AddRange(InterfaceCodeGenerator.GetReferencedAssemblies(dataTypeDescriptorToUse));
- CodeTypeDeclaration codeTypeDeclaration = InterfaceCodeGenerator.CreateCodeTypeDeclaration(dataTypeDescriptorToUse);
- List declarations;
- if (!codeTypeDeclarations.TryGetValue(dataTypeDescriptorToUse.Namespace, out declarations))
+ var codeTypeDeclaration = InterfaceCodeGenerator.CreateCodeTypeDeclaration(dataTypeDescriptorToUse);
+ if (!codeTypeDeclarations.TryGetValue(dataTypeDescriptorToUse.Namespace, out var declarations))
{
declarations = new List();
+
codeTypeDeclarations.Add(dataTypeDescriptorToUse.Namespace, declarations);
}
+
declarations.Add(codeTypeDeclaration);
- string tempFilePath = GetTempFileName(dataTypeDescriptorToUse);
+ var tempFilePath = GetTempFileName(dataTypeDescriptorToUse);
+
filesToCompile.Add(tempFilePath);
- using (FileStream file = File.Create(tempFilePath))
+ using (var file = File.Create(tempFilePath))
{
using (var sw = new StreamWriter(file))
{
var codeNamespace = new CodeNamespace(dataTypeDescriptorToUse.Namespace);
+
codeNamespace.Types.Add(codeTypeDeclaration);
+
csCompiler.GenerateCodeFromNamespace(codeNamespace, sw, new CodeGeneratorOptions());
}
@@ -111,7 +118,6 @@ private static CompatibilityCheckResult CheckAgainsAppCode(DataTypeDescriptor da
filesToCompile.Sort();
-
var compilerParameters = new CompilerParameters
{
GenerateExecutable = false,
@@ -120,24 +126,28 @@ private static CompatibilityCheckResult CheckAgainsAppCode(DataTypeDescriptor da
compilerParameters.ReferencedAssemblies.AddRangeIfNotContained(referencedAssemblies.Select(f => f.Location).ToArray());
compilerParameters.ReferencedAssemblies.AddRangeIfNotContained(CodeGenerationManager.CompiledAssemblies.Select(f => f.Location).ToArray());
+
compilerParameters.AddLoadedAssemblies(false);
compilerParameters.AddAssemblyLocationsFromBin();
compilerParameters.AddCommonAssemblies();
compilerParameters.RemoveGeneratedAssemblies();
-
var codeCompileUnit = new CodeCompileUnit();
foreach (var kvp in codeTypeDeclarations)
{
var codeNamespace = new CodeNamespace(kvp.Key);
+
codeNamespace.Types.AddRange(kvp.Value.ToArray());
codeCompileUnit.Namespaces.Add(codeNamespace);
}
- var compiler = new CSharpCodeProvider();
+ var compiler = CSharpCodeProviderFactory.CreateCompiler();
var compileResult = compiler.CompileAssemblyFromFile(compilerParameters, filesToCompile.ToArray());
- if (compileResult.Errors.Count == 0) return new CompatibilityCheckResult();
+ if (!compileResult.Errors.HasErrors)
+ {
+ return new CompatibilityCheckResult();
+ }
// Checking for a missing assembly error, if it is present, that means that App_Code check isn't applicable due to circular reference
foreach (CompilerError error in compileResult.Errors)
@@ -154,9 +164,9 @@ private static CompatibilityCheckResult CheckAgainsAppCode(DataTypeDescriptor da
private static string GetTempFileName(DataTypeDescriptor typeDescriptor)
{
- string folderPath = PathUtil.Resolve(GlobalSettingsFacade.GeneratedAssembliesDirectory);
+ var folderPath = PathUtil.Resolve(GlobalSettingsFacade.GeneratedAssembliesDirectory);
- string filePath = Path.Combine(folderPath, typeDescriptor.GetFullInterfaceName() + ".cs");
+ var filePath = Path.Combine(folderPath, typeDescriptor.GetFullInterfaceName() + ".cs");
if (filePath.Length > 255)
{
filePath = Path.Combine(folderPath, typeDescriptor.DataTypeId + ".cs");
@@ -166,11 +176,13 @@ private static string GetTempFileName(DataTypeDescriptor typeDescriptor)
}
[SuppressMessage("Composite.IO", "Composite.DoNotUseDirectoryClass:DoNotUseDirectoryClass")]
- private static string[] GetAppCodeFiles()
+ private static IEnumerable GetAppCodeFiles()
{
- string appCodeFolderPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, GlobalSettingsFacade.AppCodeDirectory);
-
- if (!Directory.Exists(appCodeFolderPath)) return new string[0];
+ var appCodeFolderPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, GlobalSettingsFacade.AppCodeDirectory);
+ if (!Directory.Exists(appCodeFolderPath))
+ {
+ return new string[0];
+ }
return Directory.GetFiles(appCodeFolderPath, "*.cs", SearchOption.AllDirectories);
}
diff --git a/Composite/Core/Types/CodeGenerationManager.cs b/Composite/Core/Types/CodeGenerationManager.cs
index ce654f61fc..ab852fe9d4 100644
--- a/Composite/Core/Types/CodeGenerationManager.cs
+++ b/Composite/Core/Types/CodeGenerationManager.cs
@@ -6,6 +6,7 @@
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Collections.Specialized;
+using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
@@ -17,8 +18,6 @@
using Composite.Core.PackageSystem;
using Composite.Data.Foundation.CodeGeneration;
using Composite.Data.GeneratedTypes;
-using Microsoft.CSharp;
-
namespace Composite.Core.Types
{
@@ -34,7 +33,7 @@ public static class CodeGenerationManager
private static bool _compositeGeneratedCompiled = true;
private static List _dynamicallyAddedCodeProviders = new List();
private static readonly List _compiledAssemblies = new List();
- private static readonly Dictionary _compiledTypesByFullName = new Dictionary();
+ private static readonly Dictionary _compiledTypesByFullName = new Dictionary();
///
/// If set to true, /Bin/Composite.Generated.dll won't be overwritten on shutdown
@@ -63,12 +62,10 @@ static CodeGenerationManager()
}
GlobalEventSystemFacade.SubscribeToFlushEvent(args => Flush());
-
GlobalEventSystemFacade.SubscribeToShutDownEvent(args => ClearOldTempFiles());
}
-
///
/// Validates that the current Composite.Generated.dll is not compiled after the given
/// time. If it is compiled after the given time. Any attempts to recompile Composite.Generated.dll
@@ -77,29 +74,37 @@ static CodeGenerationManager()
///
internal static void ValidateCompositeGenerate(DateTime time)
{
- if (SuppressGeneration) return;
-
- string filePath = Path.Combine(PathUtil.BaseDirectory, "Bin", "Composite.Generated.dll");
-
- if (!C1File.Exists(filePath)) return;
+ if (SuppressGeneration)
+ {
+ return;
+ }
- DateTime lastWrite = C1File.GetLastWriteTime(filePath);
+ var filePath = Path.Combine(PathUtil.BaseDirectory, "Bin", "Composite.Generated.dll");
+ if (!C1File.Exists(filePath))
+ {
+ return;
+ }
- if (lastWrite <= time) return;
+ var lastWrite = C1File.GetLastWriteTime(filePath);
+ if (lastWrite <= time)
+ {
+ return;
+ }
_compositeGeneratedCompiled = true;
Log.LogVerbose(LogTitle, $"Assembly in this application domain is newer than this application domain ({AppDomain.CurrentDomain.Id})");
}
-
-
///
/// This method will recompile Composite.Generated.dll and drop it into bin.
///
///
public static void GenerateCompositeGeneratedAssembly(bool forceGeneration = false)
{
- if (SuppressGeneration) return;
+ if (SuppressGeneration)
+ {
+ return;
+ }
if (forceGeneration || !_compositeGeneratedCompiled)
{
@@ -109,21 +114,21 @@ public static void GenerateCompositeGeneratedAssembly(bool forceGeneration = fal
{
Log.LogVerbose(LogTitle, $"Compiling new assembly in this application domain ({AppDomain.CurrentDomain.Id})");
- int t1 = Environment.TickCount;
+ var t1 = Environment.TickCount;
var builder = new CodeGenerationBuilder("Composite.Generated.dll");
PopulateBuilder(builder);
- int t2 = Environment.TickCount;
+ var t2 = Environment.TickCount;
Compile(builder);
- int t3 = Environment.TickCount;
+ var t3 = Environment.TickCount;
- int numberOfTypes = builder.Namespaces.SelectMany(f => f.Types.OfType()).Count();
+ var numberOfTypes = builder.Namespaces.SelectMany(f => f.Types.OfType()).Count();
Log.LogVerbose(LogTitle, "Number of types build: " + numberOfTypes +
- "\nBuilding code dom: " + (t2 - t1) + "ms" +
+ "\nBuilding code dom: " + (t2 - t1) + "ms" +
"\nCompiling code dom: " + (t3 - t2) + "ms" +
"\nTotal compilation: " + (t3 - t1) + "ms");
@@ -137,8 +142,6 @@ public static void GenerateCompositeGeneratedAssembly(bool forceGeneration = fal
Log.LogVerbose(LogTitle, "New assembly already compiled by this application domain ({0})", AppDomain.CurrentDomain.Id);
}
-
-
///
/// This method will compile the type defined in
/// and return the result types. These types exists in a temp assembly, that will be
@@ -149,7 +152,7 @@ public static void GenerateCompositeGeneratedAssembly(bool forceGeneration = fal
///
public static IEnumerable CompileRuntimeTempTypes(CodeGenerationBuilder codeGenerationBuilder, bool verbose = true)
{
- int t1 = Environment.TickCount;
+ var t1 = Environment.TickCount;
_compositeGeneratedCompiled = false; // When compiling a new type, Composite.Generated.dll should always be recompiled
@@ -164,27 +167,27 @@ public static IEnumerable CompileRuntimeTempTypes(CodeGenerationBuilder co
compilerParameters.ReferencedAssemblies.AddRangeIfNotContained(_compiledAssemblies.Select(f => f.Location).ToArray());
compilerParameters.AddAssemblyLocationsFromBin();
-
var codeCompileUnit = new CodeCompileUnit();
+
codeCompileUnit.Namespaces.AddRange(codeGenerationBuilder.Namespaces.ToArray());
- var compiler = new CSharpCodeProvider();
+ var compiler = CSharpCodeProviderFactory.CreateCompiler();
var compileResult = compiler.CompileAssemblyFromDom(compilerParameters, codeCompileUnit);
- if (compileResult.Errors.Count == 0)
+ if (!compileResult.Errors.HasErrors)
{
- Assembly resultAssembly = compileResult.CompiledAssembly;
+ var resultAssembly = compileResult.CompiledAssembly;
AddCompiledAssembly(resultAssembly);
- Type[] resultTypes = resultAssembly.GetTypes();
+ var resultTypes = resultAssembly.GetTypes();
- int t2 = Environment.TickCount;
+ var t2 = Environment.TickCount;
Log.LogVerbose(LogTitle, $"Compile '{codeGenerationBuilder.DebugLabel}' in {t2 - t1}ms");
Log.LogVerbose(LogTitle, $"Types from : {compilerParameters.OutputAssembly}");
- foreach (Type resultType in resultTypes)
+ foreach (var resultType in resultTypes)
{
_compiledTypesByFullName[resultType.FullName] = resultType;
}
@@ -192,17 +195,7 @@ public static IEnumerable CompileRuntimeTempTypes(CodeGenerationBuilder co
return resultTypes;
}
-
-#if OUTPUT_SOURCE_CODE_ON_ERROR
- using (FileStream file = File.Create(Path.Combine(PathUtil.BaseDirectory, "output.cs")))
- {
- using (var sw = new StreamWriter(file))
- {
- compiler.GenerateCodeFromCompileUnit(codeCompileUnit, sw, new CodeGeneratorOptions());
- }
- }
-#endif
-
+ OutputSourceCodeOnError(compiler, codeCompileUnit);
var failedAssemblyLoads = LoadAssembliesToMemory(compilerParameters.ReferencedAssemblies);
@@ -212,9 +205,12 @@ public static IEnumerable CompileRuntimeTempTypes(CodeGenerationBuilder co
sb.AppendLine("Failed building: " + codeGenerationBuilder.DebugLabel);
foreach (CompilerError compilerError in compileResult.Errors)
{
- if (compilerError.IsWarning) continue;
+ if (compilerError.IsWarning)
+ {
+ continue;
+ }
- string entry = "Compile error: " + compilerError.ErrorNumber + "(" + compilerError.Line + ")" + ": " + compilerError.ErrorText.Replace("{", "{{").Replace("}", "}}");
+ var entry = "Compile error: " + compilerError.ErrorNumber + "(" + compilerError.Line + ")" + ": " + compilerError.ErrorText.Replace("{", "{{").Replace("}", "}}");
if (verbose)
{
@@ -227,11 +223,10 @@ public static IEnumerable CompileRuntimeTempTypes(CodeGenerationBuilder co
throw new InvalidOperationException(sb.ToString());
}
-
- private static ICollection> LoadAssembliesToMemory(StringCollection assemblyLocations)
+ private static IEnumerable> LoadAssembliesToMemory(StringCollection assemblyLocations)
{
var failedAssemblyLoads = new List>();
- foreach (string assemblyLocation in assemblyLocations)
+ foreach (var assemblyLocation in assemblyLocations)
{
if (PackageAssemblyHandler.TryGetAlreadyLoadedAssembly(assemblyLocation) != null)
{
@@ -245,7 +240,7 @@ private static ICollection> LoadAssembliesToMemory(Strin
}
catch (Exception ex)
{
- Exception exceptionToLog = ex;
+ var exceptionToLog = ex;
var loadException = ex as ReflectionTypeLoadException;
if (loadException?.LoaderExceptions != null && loadException.LoaderExceptions.Any())
@@ -260,7 +255,6 @@ private static ICollection> LoadAssembliesToMemory(Strin
return failedAssemblyLoads;
}
-
///
/// This method returns true if the given type is
/// compiled at runetime. Otherwise false.
@@ -272,9 +266,6 @@ public static bool IsCompiledAtRuntime(Type type)
return type.Assembly.Location.StartsWith(PathUtil.Resolve(GlobalSettingsFacade.GeneratedAssembliesDirectory), StringComparison.InvariantCultureIgnoreCase);
}
-
-
-
///
/// This method returns true if the types given by needs a recompile because
/// they either is null or the type given by has changed and there for
@@ -285,18 +276,22 @@ public static bool IsCompiledAtRuntime(Type type)
/// Returns true if the types given by needs a recompile.
public static bool IsRecompileNeeded(Type dependableType, IEnumerable dependingTypes)
{
- foreach (Type dependingType in dependingTypes)
+ foreach (var dependingType in dependingTypes)
{
- if (dependingType == null) return true;
+ if (dependingType == null)
+ {
+ return true;
+ }
- if (IsCompiledAtRuntime(dependableType) && !IsCompiledAtRuntime(dependingType)) return true;
+ if (IsCompiledAtRuntime(dependableType) && !IsCompiledAtRuntime(dependingType))
+ {
+ return true;
+ }
}
return false;
}
-
-
///
/// Use this method to add a implementation
/// that will be used when (and only) generating the final Composite.Generated.dll.
@@ -307,18 +302,15 @@ public static void AddAssemblyCodeProvider(ICodeProvider codeProvider)
_dynamicallyAddedCodeProviders.Add(codeProvider);
}
-
///
/// Gets the compiled types.
///
///
public static Type GetCompiledType(string fullName)
{
- Type type;
- return _compiledTypesByFullName.TryGetValue(fullName, out type) ? type : null;
+ return _compiledTypesByFullName.TryGetValue(fullName, out var type) ? type : null;
}
-
private static void Compile(CodeGenerationBuilder builder)
{
var compilerParameters = new CompilerParameters
@@ -333,35 +325,32 @@ private static void Compile(CodeGenerationBuilder builder)
compilerParameters.AddAssemblyLocationsFromBin();
var codeCompileUnit = new CodeCompileUnit();
- codeCompileUnit.Namespaces.AddRange(builder.Namespaces.ToArray());
+ codeCompileUnit.Namespaces.AddRange(builder.Namespaces.ToArray());
- for (int i = 0; i < NumberOfCompileRetries; i++)
+ for (var i = 0; i < NumberOfCompileRetries; i++)
{
- var compiler = new CSharpCodeProvider();
+ var compiler = CSharpCodeProviderFactory.CreateCompiler();
CompilerResults compileResult = compiler.CompileAssemblyFromDom(compilerParameters, codeCompileUnit);
-
- if (compileResult.Errors.Count == 0) return;
+ if (!compileResult.Errors.HasErrors)
+ {
+ return;
+ }
if (i == NumberOfCompileRetries - 1)
{
-#if OUTPUT_SOURCE_CODE_ON_ERROR
- using (FileStream file = File.Create(Path.Combine(PathUtil.BaseDirectory, "output.cs")))
- {
- using (var sw = new StreamWriter(file))
- {
- compiler.GenerateCodeFromCompileUnit(codeCompileUnit, sw, new CodeGeneratorOptions());
- }
- }
-#endif
+ OutputSourceCodeOnError(compiler, codeCompileUnit);
var sb = new StringBuilder();
foreach (CompilerError compilerError in compileResult.Errors)
{
- if (compilerError.IsWarning) continue;
+ if (compilerError.IsWarning)
+ {
+ continue;
+ }
- string entry = "Compile error: " + compilerError.ErrorNumber + "(" + compilerError.Line + ")" + ": " + compilerError.ErrorText.Replace("{", "{{").Replace("}", "}}");
+ var entry = "Compile error: " + compilerError.ErrorNumber + "(" + compilerError.Line + ")" + ": " + compilerError.ErrorText.Replace("{", "{{").Replace("}", "}}");
Log.LogError(LogTitle, entry);
@@ -373,53 +362,35 @@ private static void Compile(CodeGenerationBuilder builder)
}
}
-
-
///
/// Returns all currently temp compiled assemblies.
///
internal static IEnumerable CompiledAssemblies => _compiledAssemblies;
-
///
///
internal static string TempAssemblyFolderPath => PathUtil.Resolve(GlobalSettingsFacade.GeneratedAssembliesDirectory);
-
///
///
- internal static string BinFolder
- {
- get
- {
- return RuntimeInformation.IsUnittest
- ? PathUtil.BaseDirectory
- : Path.Combine(PathUtil.BaseDirectory, "Bin");
- }
- }
-
-
+ internal static string BinFolder => RuntimeInformation.IsUnittest ? PathUtil.BaseDirectory : Path.Combine(PathUtil.BaseDirectory, "Bin");
///
///
internal static string CompositeGeneratedFileName => "Composite.Generated.dll";
-
///
///
internal static string CompositeGeneratedAssemblyPath => Path.Combine(BinFolder, "Composite.Generated.dll");
-
private static void PopulateBuilder(CodeGenerationBuilder builder)
{
- foreach (ICodeProvider provider in CodeProviders)
+ foreach (var provider in CodeProviders)
{
provider.GetCodeToCompile(builder);
}
}
-
-
private static IEnumerable CodeProviders
{
get
@@ -428,30 +399,28 @@ private static IEnumerable CodeProviders
yield return new EmptyDataClassCodeProvider();
yield return new DataWrapperClassCodeProvider();
- foreach (ICodeProvider codeProvider in _dynamicallyAddedCodeProviders)
+ foreach (var codeProvider in _dynamicallyAddedCodeProviders)
{
yield return codeProvider;
}
}
}
-
-
private static void AddCompiledAssembly(Assembly newAssembly)
{
- Type newType = newAssembly.GetTypes().First();
+ var newType = newAssembly.GetTypes().First();
var assembliesToRemove = new List();
- foreach (Assembly assembly in _compiledAssemblies)
+ foreach (var assembly in _compiledAssemblies)
{
- Type type = assembly.GetTypes().SingleOrDefault(f => f.FullName == newType.FullName);
+ var type = assembly.GetTypes().SingleOrDefault(f => f.FullName == newType.FullName);
if (type != null)
{
assembliesToRemove.Add(assembly);
}
}
- foreach (Assembly assemblyToRemove in assembliesToRemove)
+ foreach (var assemblyToRemove in assembliesToRemove)
{
_compiledAssemblies.Remove(assemblyToRemove);
}
@@ -459,8 +428,6 @@ private static void AddCompiledAssembly(Assembly newAssembly)
_compiledAssemblies.Add(newAssembly);
}
-
-
private static void Flush()
{
_dynamicallyAddedCodeProviders = new List();
@@ -468,7 +435,7 @@ private static void Flush()
private static void ClearOldTempFiles()
{
- DateTime yesterday = DateTime.Now.AddDays(-1);
+ var yesterday = DateTime.Now.AddDays(-1);
var oldFiles = C1Directory.GetFiles(TempAssemblyFolderPath, "*.*").Where(filePath => C1File.GetCreationTime(filePath) < yesterday).ToArray();
foreach (var file in oldFiles)
@@ -483,5 +450,17 @@ private static void ClearOldTempFiles()
}
}
}
+
+ [Conditional("OUTPUT_SOURCE_CODE_ON_ERROR")]
+ private static void OutputSourceCodeOnError(CodeDomProvider compiler, CodeCompileUnit codeCompileUnit)
+ {
+ using (var file = File.Create(Path.Combine(PathUtil.BaseDirectory, "output.cs")))
+ {
+ using (var sw = new StreamWriter(file))
+ {
+ compiler.GenerateCodeFromCompileUnit(codeCompileUnit, sw, new CodeGeneratorOptions());
+ }
+ }
+ }
}
}
diff --git a/Composite/Data/GeneratedTypes/GeneratedTypesHelper.cs b/Composite/Data/GeneratedTypes/GeneratedTypesHelper.cs
index 0756b2a540..ebd86b1799 100644
--- a/Composite/Data/GeneratedTypes/GeneratedTypesHelper.cs
+++ b/Composite/Data/GeneratedTypes/GeneratedTypesHelper.cs
@@ -11,7 +11,6 @@
using Composite.Data.ProcessControlled;
using Composite.Data.Types;
using Composite.Functions;
-using Microsoft.CSharp;
using Texts = Composite.Core.ResourceSystem.LocalizationFiles.Composite_GeneratedTypes;
@@ -38,7 +37,7 @@ public enum KeyFieldType
private static readonly string[] ReservedNamespaces = { "System", "Composite.Data.GeneratedTypes", "GeneratedTypes" };
- private static readonly string CompositeNamespace = "Composite";
+ private const string CompositeNamespace = "Composite";
private Type _associatedType;
private readonly Type _oldType;
@@ -48,7 +47,7 @@ public enum KeyFieldType
private string _newTypeName;
private string _newTypeNamespace;
private string _newTypeTitle;
- private bool _cachable;
+ private bool _cacheable;
private bool _searchable;
private bool _publishControlled;
private bool _localizedControlled;
@@ -65,19 +64,14 @@ public enum KeyFieldType
private bool _typeCreated;
- private static readonly string IdFieldName = "Id";
- private static readonly string PageReferenceFieldName = "PageId";
- private static readonly string CompositionDescriptionFieldName = "FieldName";
+ private const string IdFieldName = "Id";
+ private const string PageReferenceFieldName = "PageId";
+ private const string CompositionDescriptionFieldName = "FieldName";
//private KeyFieldType _keyFieldType = KeyFieldType.Guid;
-
///
- public GeneratedTypesHelper()
- {
- }
-
-
+ public GeneratedTypesHelper() { }
///
public GeneratedTypesHelper(Type oldType)
@@ -90,8 +84,6 @@ public GeneratedTypesHelper(Type oldType)
Initialize();
}
-
-
///
public GeneratedTypesHelper(DataTypeDescriptor oldDataTypeDescriptor)
{
@@ -103,16 +95,8 @@ public GeneratedTypesHelper(DataTypeDescriptor oldDataTypeDescriptor)
Initialize();
}
-
-
///
- public bool AllowForeignKeyEditing
- {
- get;
- set;
- }
-
-
+ public bool AllowForeignKeyEditing { get; set; }
///
[Obsolete("Use EditableOwnDataFieldDescriptors which does not return inherited fields", true)]
@@ -150,16 +134,17 @@ public IEnumerable NotEditableDataFieldDescriptorNames
Verify.IsNotNull(_oldDataTypeDescriptor, "No old data type specified");
return from field in _oldDataTypeDescriptor.Fields
- where !IsDataFieldBindable(_oldDataTypeDescriptor, field)
- || _oldDataTypeDescriptor.KeyPropertyNames.FirstOrDefault() == field.Name
+ where !IsDataFieldBindable(_oldDataTypeDescriptor, field) || _oldDataTypeDescriptor.KeyPropertyNames.FirstOrDefault() == field.Name
select field.Name;
}
}
-
+ ///
+ [Obsolete("Use IsCacheable")]
+ public bool IsCachable => IsCacheable;
///
- public bool IsCachable
+ public bool IsCacheable
{
get
{
@@ -169,7 +154,6 @@ public bool IsCachable
}
}
-
///
public bool IsSearchable
{
@@ -181,7 +165,6 @@ public bool IsSearchable
}
}
-
///
public bool IsPublishControlled
{
@@ -193,8 +176,6 @@ public bool IsPublishControlled
}
}
-
-
///
public bool IsLocalizedControlled
{
@@ -206,20 +187,10 @@ public bool IsLocalizedControlled
}
}
-
-
///
/// Returns true if the date type is a page meta data type.
///
- public bool IsEditProcessControlledAllowed
- {
- get
- {
- return _pageMetaDataDescriptionForeignKeyDataFieldDescriptor == null;
- }
- }
-
-
+ public bool IsEditProcessControlledAllowed => _pageMetaDataDescriptionForeignKeyDataFieldDescriptor == null;
///
public bool ValidateNewTypeName(string typeName, out string message)
@@ -229,8 +200,6 @@ public bool ValidateNewTypeName(string typeName, out string message)
return NameValidation.TryValidateName(typeName, out message);
}
-
-
///
public bool ValidateNewTypeNamespace(string typeNamespace, out string message)
{
@@ -239,8 +208,6 @@ public bool ValidateNewTypeNamespace(string typeNamespace, out string message)
return NameValidation.TryValidateNamespace(typeNamespace, out message);
}
-
-
///
public bool ValidateNewTypeFullName(string typeName, string typeNamespace, out string message)
{
@@ -255,8 +222,6 @@ public bool ValidateNewTypeFullName(string typeName, string typeNamespace, out s
return false;
}
-
-
if (_oldDataTypeDescriptor != null)
{
if (_oldDataTypeDescriptor.Name == typeName &&
@@ -265,7 +230,7 @@ public bool ValidateNewTypeFullName(string typeName, string typeNamespace, out s
return true;
}
- Type interfaceType = _oldDataTypeDescriptor.GetInterfaceType();
+ var interfaceType = _oldDataTypeDescriptor.GetInterfaceType();
if (interfaceType.GetRefereeTypes().Count > 0)
{
@@ -274,27 +239,28 @@ public bool ValidateNewTypeFullName(string typeName, string typeNamespace, out s
}
}
- string typeFullname = StringExtensionMethods.CreateNamespace(typeNamespace, typeName, '.');
- foreach (DataTypeDescriptor dtd in DataMetaDataFacade.GeneratedTypeDataTypeDescriptors)
+ var typeFullname = StringExtensionMethods.CreateNamespace(typeNamespace, typeName, '.');
+ foreach (var dtd in DataMetaDataFacade.GeneratedTypeDataTypeDescriptors)
{
- string fullname = StringExtensionMethods.CreateNamespace(dtd.Namespace, dtd.Name, '.');
-
+ var fullname = StringExtensionMethods.CreateNamespace(dtd.Namespace, dtd.Name, '.');
if (typeFullname == fullname)
{
message = Texts.TypesNameClash;
+
return false;
}
}
-
- string[] partNames = typeFullname.Split('.');
+ var partNames = typeFullname.Split('.');
var sb = new StringBuilder(partNames[0]);
- for (int i = 1; i < partNames.Length; i++)
+
+ for (var i = 1; i < partNames.Length; i++)
{
- bool exists = TypeManager.HasTypeWithName(sb.ToString());
+ var exists = TypeManager.HasTypeWithName(sb.ToString());
if (exists)
{
message = Texts.NameSpaceIsTypeTypeName(sb.ToString());
+
return false;
}
@@ -305,38 +271,39 @@ public bool ValidateNewTypeFullName(string typeName, string typeNamespace, out s
return true;
}
-
-
///
public bool ValidateByCompile(out string errorMessage)
{
var dataTypeDescriptor = _oldDataTypeDescriptor == null ? CreateNewDataTypeDescriptor() : CreateUpdatedDataTypeDescriptor();
- string classFullName = (dataTypeDescriptor.Namespace + "." + dataTypeDescriptor.Name).Replace(" ", string.Empty);
- string classFullNameWithDot = classFullName + ".";
+ var classFullName = (dataTypeDescriptor.Namespace + "." + dataTypeDescriptor.Name).Replace(" ", string.Empty);
+ var classFullNameWithDot = classFullName + ".";
foreach (var reservedNamespace in ReservedNamespaces)
{
if (classFullNameWithDot.StartsWith(reservedNamespace + ".", StringComparison.InvariantCultureIgnoreCase))
{
errorMessage = Texts.NamespaceIsReserved;
+
return false;
}
}
- foreach (string namePart in classFullName.Split(new[] { '.' }, StringSplitOptions.RemoveEmptyEntries))
+ foreach (var namePart in classFullName.Split(new[] { '.' }, StringSplitOptions.RemoveEmptyEntries))
{
if (!IsCSharpValidIdentifier(namePart))
{
errorMessage = Texts.TypeNameIsInvalidIdentifier(classFullName);
+
return false;
}
}
- foreach (DataFieldDescriptor dataField in dataTypeDescriptor.Fields)
+ foreach (var dataField in dataTypeDescriptor.Fields)
{
if (!IsCSharpValidIdentifier(dataField.Name))
{
errorMessage = Texts.FieldNameCannotBeUsed(dataField.Name);
+
return false;
}
}
@@ -346,34 +313,32 @@ public bool ValidateByCompile(out string errorMessage)
{
foreach (var type in typeof(IData).Assembly.GetTypes())
{
- string typeNameWithDot = type.FullName + ".";
+ var typeNameWithDot = type.FullName + ".";
- if (classFullNameWithDot.StartsWith(typeNameWithDot, StringComparison.InvariantCultureIgnoreCase)
- || typeNameWithDot.StartsWith(classFullNameWithDot, StringComparison.InvariantCultureIgnoreCase))
+ if (classFullNameWithDot.StartsWith(typeNameWithDot, StringComparison.InvariantCultureIgnoreCase) || typeNameWithDot.StartsWith(classFullNameWithDot, StringComparison.InvariantCultureIgnoreCase))
{
errorMessage = Texts.CompileErrorWhileAddingType;
+
return false;
}
}
}
-
- CompatibilityCheckResult compatibilityCheckResult = CodeCompatibilityChecker.CheckCompatibilityWithAppCodeFolder(dataTypeDescriptor);
-
+ var compatibilityCheckResult = CodeCompatibilityChecker.CheckCompatibilityWithAppCodeFolder(dataTypeDescriptor);
if (!compatibilityCheckResult.Successful)
{
errorMessage = _oldDataTypeDescriptor == null ? Texts.CompileErrorWhileAddingType : Texts.CompileErrorWhileChangingType;
errorMessage += compatibilityCheckResult.ErrorMessage;
+
return false;
}
errorMessage = string.Empty;
+
return true;
}
-
-
///
public bool ValidateNewFieldDescriptors(IEnumerable newDataFieldDescriptors, string keyFieldName, out string message)
{
@@ -383,45 +348,41 @@ public bool ValidateNewFieldDescriptors(IEnumerable newData
message = null;
- if (!newDataFieldDescriptors.Any(f => f.Name != keyFieldName))
+ if (newDataFieldDescriptors.All(f => f.Name == keyFieldName))
{
message = Texts.MissingFields;
+
return false;
}
if (keyFieldName != IdFieldName && newDataFieldDescriptors.Any(dfd => dfd.Name == IdFieldName))
{
message = Texts.FieldNameCannotBeUsed(IdFieldName);
+
return false;
}
return true;
}
-
///
public static string GetCompositionDescriptionPropertyName(Type compositionType)
{
return CompositionDescriptionFieldName;
}
-
-
///
public static PropertyInfo GetCompositionDescriptionPropertyInfo(Type compositionType)
{
return compositionType.GetPropertiesRecursively().Single(f => f.Name == CompositionDescriptionFieldName);
}
-
-
///
public static PropertyInfo GetPageReferencePropertyInfo(Type compositionType)
{
return compositionType.GetPropertiesRecursively().Single(f => f.Name == PageReferenceFieldName);
}
-
///
public void SetNewTypeFullName(string typeName, string typeNamespace)
{
@@ -432,8 +393,6 @@ public void SetNewTypeFullName(string typeName, string typeNamespace)
_newTypeNamespace = typeNamespace;
}
-
-
///
public void SetNewTypeTitle(string typeTitle)
{
@@ -442,22 +401,24 @@ public void SetNewTypeTitle(string typeTitle)
_newTypeTitle = typeTitle;
}
-
-
///
public void SetNewInternalUrlPrefix(string internalUrlPrefix)
{
_newInternalUrlPrefix = internalUrlPrefix;
}
-
-
///
- public void SetCachable(bool cachable)
+ [Obsolete("SetCacheable")]
+ public void SetCachable(bool cacheable)
{
- _cachable = cachable;
+ SetCacheable(cacheable);
}
+ ///
+ public void SetCacheable(bool cacheable)
+ {
+ _cacheable = cacheable;
+ }
///
public void SetSearchable(bool searchable)
@@ -465,7 +426,6 @@ public void SetSearchable(bool searchable)
_searchable = searchable;
}
-
///
public void SetPublishControlled(bool isPublishControlled)
{
@@ -474,8 +434,6 @@ public void SetPublishControlled(bool isPublishControlled)
_publishControlled = isPublishControlled;
}
-
-
///
public void SetLocalizedControlled(bool isLocalizedControlled)
{
@@ -484,7 +442,6 @@ public void SetLocalizedControlled(bool isLocalizedControlled)
_localizedControlled = isLocalizedControlled;
}
-
///
[Obsolete("Left for backward compatibility")]
public void SetNewFieldDescriptors(IEnumerable newDataFieldDescriptors, string labelFieldName)
@@ -496,8 +453,6 @@ public void SetNewFieldDescriptors(IEnumerable newDataField
SetNewFieldDescriptors(fields.Concat(newDataFieldDescriptors), IdFieldName, labelFieldName);
}
-
-
///
public void SetNewFieldDescriptors(IEnumerable newDataFieldDescriptors, string keyFieldName, string labelFieldName)
{
@@ -513,68 +468,62 @@ public void SetNewFieldDescriptors(IEnumerable newDataField
}
}
-
-
///
public void SetForeignKeyReference(Type targetDataType, DataAssociationType dataAssociationType)
{
- if (dataAssociationType == DataAssociationType.None) throw new ArgumentException("dataAssociationType");
+ if (dataAssociationType == DataAssociationType.None)
+ {
+ throw new ArgumentException("dataAssociationType");
+ }
- DataTypeDescriptor targetDataTypeDescriptor = DynamicTypeManager.GetDataTypeDescriptor(targetDataType);
+ var targetDataTypeDescriptor = DynamicTypeManager.GetDataTypeDescriptor(targetDataType);
SetForeignKeyReference(targetDataTypeDescriptor, dataAssociationType);
}
-
-
///
public void SetForeignKeyReference(DataTypeDescriptor targetDataTypeDescriptor, DataAssociationType dataAssociationType)
{
- if (dataAssociationType == DataAssociationType.None) throw new ArgumentException("dataAssociationType");
+ if (dataAssociationType == DataAssociationType.None)
+ {
+ throw new ArgumentException("dataAssociationType");
+ }
- if ((dataAssociationType == DataAssociationType.Aggregation || dataAssociationType == DataAssociationType.Composition)
- && _pageMetaDataDescriptionForeignKeyDataFieldDescriptor != null)
+ if ((dataAssociationType == DataAssociationType.Aggregation || dataAssociationType == DataAssociationType.Composition) && _pageMetaDataDescriptionForeignKeyDataFieldDescriptor != null)
{
throw new InvalidOperationException("The type already has a foreign key reference");
}
-
- Type targetType = TypeManager.GetType(targetDataTypeDescriptor.TypeManagerTypeName);
string fieldName = null;
+
+ var targetType = TypeManager.GetType(targetDataTypeDescriptor.TypeManagerTypeName);
if (targetType == typeof(IPage))
{
fieldName = PageReferenceFieldName;
+
_dataAssociationType = dataAssociationType;
}
- string foreignKeyFieldName;
- _foreignKeyDataFieldDescriptor = CreateReferenceDataFieldDescriptor(targetDataTypeDescriptor, out foreignKeyFieldName, fieldName);
+ _foreignKeyDataFieldDescriptor = CreateReferenceDataFieldDescriptor(targetDataTypeDescriptor, out var foreignKeyFieldName, fieldName);
if (dataAssociationType != DataAssociationType.None)
{
- _dataTypeAssociationDescriptor = new DataTypeAssociationDescriptor(
- targetType,
- foreignKeyFieldName,
- dataAssociationType
- );
+ _dataTypeAssociationDescriptor = new DataTypeAssociationDescriptor(targetType, foreignKeyFieldName, dataAssociationType);
}
if (dataAssociationType == DataAssociationType.Composition)
{
- DataTypeDescriptor compositionRuleDataTypeDescriptor = DynamicTypeManager.GetDataTypeDescriptor(typeof(IPageMetaDataDefinition));
+ var compositionRuleDataTypeDescriptor = DynamicTypeManager.GetDataTypeDescriptor(typeof(IPageMetaDataDefinition));
_pageMetaDataDescriptionForeignKeyDataFieldDescriptor = CreateWeakReferenceDataFieldDescriptor(compositionRuleDataTypeDescriptor, compositionRuleDataTypeDescriptor.Fields["Name"], CompositionDescriptionFieldName);
}
}
-
-
///
public bool TryValidateUpdate(bool originalTypeDataExists, out string errorMessage)
{
if (_oldDataTypeDescriptor != null)
{
-
if (_newLabelFieldName == null)
{
_newLabelFieldName = KeyFieldName;
@@ -594,12 +543,13 @@ public bool TryValidateUpdate(bool originalTypeDataExists, out string errorMessa
return ValidateByCompile(out errorMessage);
}
-
-
///
public void CreateType(bool originalTypeHasData)
{
- if (_typeCreated) throw new InvalidOperationException("The type can only be created once");
+ if (_typeCreated)
+ {
+ throw new InvalidOperationException("The type can only be created once");
+ }
try
{
@@ -623,10 +573,7 @@ public void CreateType(bool originalTypeHasData)
}
else
{
- string errorMessage;
-
-
- UpdateOldType(false, originalTypeHasData, out errorMessage);
+ UpdateOldType(false, originalTypeHasData, out _);
}
}
finally
@@ -635,8 +582,6 @@ public void CreateType(bool originalTypeHasData)
}
}
-
-
///
public Type InterfaceType
{
@@ -648,7 +593,6 @@ public Type InterfaceType
}
}
-
///
public static void SetNewIdFieldValue(IData data)
{
@@ -658,8 +602,8 @@ public static void SetNewIdFieldValue(IData data)
foreach (var keyProperty in keyProperties)
{
- bool hasDefaultFieldValueAttribute = keyProperty.GetCustomAttributesRecursively().Any();
- bool hasNewInstanceDefaultFieldValueAttribute = keyProperty.GetCustomAttributesRecursively().Any();
+ var hasDefaultFieldValueAttribute = keyProperty.GetCustomAttributesRecursively().Any();
+ var hasNewInstanceDefaultFieldValueAttribute = keyProperty.GetCustomAttributesRecursively().Any();
if (!hasDefaultFieldValueAttribute && !hasNewInstanceDefaultFieldValueAttribute)
{
@@ -677,25 +621,22 @@ public static void SetNewIdFieldValue(IData data)
}
}
-
-
private void Initialize()
{
if (_oldDataTypeDescriptor.DataAssociations.Count > 0)
{
- DataTypeAssociationDescriptor dataTypeAssociationDescriptor = _oldDataTypeDescriptor.DataAssociations.Single();
+ var dataTypeAssociationDescriptor = _oldDataTypeDescriptor.DataAssociations.Single();
_associatedType = dataTypeAssociationDescriptor.AssociatedInterfaceType;
}
-
- foreach (DataFieldDescriptor dataFieldDescriptor in _oldDataTypeDescriptor.Fields)
+ foreach (var dataFieldDescriptor in _oldDataTypeDescriptor.Fields)
{
if (dataFieldDescriptor.ForeignKeyReferenceTypeName != null)
{
if (_associatedType != null)
{
- string associatedTypeTypeName = TypeManager.SerializeType(_associatedType);
+ var associatedTypeTypeName = TypeManager.SerializeType(_associatedType);
if (dataFieldDescriptor.ForeignKeyReferenceTypeName == associatedTypeTypeName)
{
@@ -711,12 +652,10 @@ private void Initialize()
}
}
- _publishControlled = this.IsPublishControlled;
- _localizedControlled = this.IsLocalizedControlled;
+ _publishControlled = IsPublishControlled;
+ _localizedControlled = IsLocalizedControlled;
}
-
-
private void CreateNewType()
{
_newDataTypeDescriptor = CreateNewDataTypeDescriptor();
@@ -724,12 +663,11 @@ private void CreateNewType()
GeneratedTypesFacade.GenerateNewType(_newDataTypeDescriptor);
}
- private bool IsCSharpValidIdentifier(string name)
+ private static bool IsCSharpValidIdentifier(string name)
{
- return new CSharpCodeProvider().IsValidIdentifier(name);
+ return CSharpCodeProviderFactory.CreateCompiler().IsValidIdentifier(name);
}
-
private bool UpdateOldType(bool validateOnly, bool originalTypeDataExists, out string errorMessage)
{
errorMessage = "";
@@ -752,11 +690,9 @@ private bool UpdateOldType(bool validateOnly, bool originalTypeDataExists, out s
GeneratedTypesFacade.UpdateType(new UpdateDataTypeDescriptor(_oldDataTypeDescriptor, _newDataTypeDescriptor, originalTypeDataExists));
- return true;
+ return true;
}
-
-
private DataTypeDescriptor CreateNewDataTypeDescriptor()
{
return CreateNewDataTypeDescriptor(
@@ -765,7 +701,7 @@ private DataTypeDescriptor CreateNewDataTypeDescriptor()
_newTypeTitle,
_newLabelFieldName,
_newInternalUrlPrefix,
- _cachable,
+ _cacheable,
_searchable,
_publishControlled,
_localizedControlled,
@@ -775,8 +711,6 @@ private DataTypeDescriptor CreateNewDataTypeDescriptor()
_pageMetaDataDescriptionForeignKeyDataFieldDescriptor);
}
-
-
private DataTypeDescriptor CreateNewDataTypeDescriptor(
string typeNamespace,
string typeName,
@@ -792,7 +726,7 @@ private DataTypeDescriptor CreateNewDataTypeDescriptor(
DataTypeAssociationDescriptor dataTypeAssociationDescriptor,
DataFieldDescriptor compositionRuleForeignKeyDataFieldDescriptor)
{
- Guid id = Guid.NewGuid();
+ var id = Guid.NewGuid();
var dataTypeDescriptor = new DataTypeDescriptor(id, typeNamespace, typeName, true)
{
Cachable = cachable,
@@ -835,7 +769,7 @@ private DataTypeDescriptor CreateNewDataTypeDescriptor(
// dataTypeDescriptor.KeyPropertyNames.Add(IdFieldName);
//}
- foreach (DataFieldDescriptor dataFieldDescriptor in dataFieldDescriptors)
+ foreach (var dataFieldDescriptor in dataFieldDescriptors)
{
dataTypeDescriptor.Fields.Add(dataFieldDescriptor);
}
@@ -845,7 +779,7 @@ private DataTypeDescriptor CreateNewDataTypeDescriptor(
dataTypeDescriptor.KeyPropertyNames.Add(_newKeyFieldName);
}
- int position = 100;
+ var position = 100;
if (_foreignKeyDataFieldDescriptor != null)
{
_foreignKeyDataFieldDescriptor.Position = position++;
@@ -857,7 +791,6 @@ private DataTypeDescriptor CreateNewDataTypeDescriptor(
}
}
-
return dataTypeDescriptor;
}
@@ -867,16 +800,15 @@ private DataTypeDescriptor CreateNewDataTypeDescriptor(
///
public static DataFieldDescriptor BuildIdField()
{
- var idFieldDescriptor = new DataFieldDescriptor(Guid.NewGuid(), IdFieldName, StoreFieldType.Guid, typeof (Guid));
- idFieldDescriptor.DataUrlProfile = new DataUrlProfile { Order = 0 };
- return idFieldDescriptor;
- }
+ var idFieldDescriptor = new DataFieldDescriptor(Guid.NewGuid(), IdFieldName, StoreFieldType.Guid, typeof(Guid))
+ {
+ DataUrlProfile = new DataUrlProfile { Order = 0 }
+ };
- private string KeyFieldName
- {
- get { return _newKeyFieldName ?? IdFieldName; }
+ return idFieldDescriptor;
}
+ private string KeyFieldName => _newKeyFieldName ?? IdFieldName;
//private DataFieldDescriptor BuildKeyFieldDescriptor()
//{
@@ -907,23 +839,19 @@ private string KeyFieldName
// return result;
//}
-
private DataTypeDescriptor CreateUpdatedDataTypeDescriptor()
{
- var dataTypeDescriptor = new DataTypeDescriptor(
- _oldDataTypeDescriptor.DataTypeId, _newTypeNamespace, _newTypeName, true)
+ var dataTypeDescriptor = new DataTypeDescriptor(_oldDataTypeDescriptor.DataTypeId, _newTypeNamespace, _newTypeName, true)
{
- Cachable = _cachable,
+ Cachable = _cacheable,
Searchable = _searchable
};
dataTypeDescriptor.DataScopes.Add(DataScopeIdentifier.Public);
-
-
Type[] indirectlyInheritedInterfaces =
{
- typeof(IPublishControlled), typeof(ILocalizedControlled),
+ typeof(IPublishControlled), typeof(ILocalizedControlled),
typeof(IPageData), typeof(IPageFolderData), typeof(IPageMetaData)
};
@@ -936,7 +864,6 @@ private DataTypeDescriptor CreateUpdatedDataTypeDescriptor()
}
}
-
if (_publishControlled && _dataAssociationType != DataAssociationType.Composition)
{
dataTypeDescriptor.AddSuperInterface(typeof(IPublishControlled));
@@ -947,7 +874,6 @@ private DataTypeDescriptor CreateUpdatedDataTypeDescriptor()
dataTypeDescriptor.AddSuperInterface(typeof(ILocalizedControlled));
}
-
if (_oldDataTypeDescriptor.SuperInterfaces.Contains(typeof(IPageFolderData)))
{
dataTypeDescriptor.AddSuperInterface(typeof(IPageData));
@@ -967,12 +893,12 @@ private DataTypeDescriptor CreateUpdatedDataTypeDescriptor()
//dataTypeDescriptor.Fields.Add(idDataFieldDescriptor);
//dataTypeDescriptor.KeyPropertyNames.Add(KeyFieldName);
-
+
}
dataTypeDescriptor.Title = _newTypeTitle;
- foreach (DataFieldDescriptor dataFieldDescriptor in _newDataFieldDescriptors)
+ foreach (var dataFieldDescriptor in _newDataFieldDescriptors)
{
dataTypeDescriptor.Fields.Add(dataFieldDescriptor);
}
@@ -982,13 +908,13 @@ private DataTypeDescriptor CreateUpdatedDataTypeDescriptor()
dataTypeDescriptor.KeyPropertyNames.Add(KeyFieldName);
}
-
dataTypeDescriptor.LabelFieldName = _newLabelFieldName;
dataTypeDescriptor.InternalUrlPrefix = _newInternalUrlPrefix;
dataTypeDescriptor.DataAssociations.AddRange(_oldDataTypeDescriptor.DataAssociations);
- int position = 100;
+ var position = 100;
+
if (_foreignKeyDataFieldDescriptor != null)
{
_foreignKeyDataFieldDescriptor.Position = position++;
@@ -1002,20 +928,13 @@ private DataTypeDescriptor CreateUpdatedDataTypeDescriptor()
return dataTypeDescriptor;
}
-
-
- private DataFieldDescriptor CreateWeakReferenceDataFieldDescriptor(DataTypeDescriptor targetDataTypeDescriptor, DataFieldDescriptor targetDataFieldDescriptor, string fieldName)
+ private static DataFieldDescriptor CreateWeakReferenceDataFieldDescriptor(DataTypeDescriptor targetDataTypeDescriptor, DataFieldDescriptor targetDataFieldDescriptor, string fieldName)
{
TypeManager.GetType(targetDataTypeDescriptor.TypeManagerTypeName);
- WidgetFunctionProvider widgetFunctionProvider = StandardWidgetFunctions.TextBoxWidget;
+ var widgetFunctionProvider = StandardWidgetFunctions.TextBoxWidget;
- return new DataFieldDescriptor(
- Guid.NewGuid(),
- fieldName,
- targetDataFieldDescriptor.StoreType,
- targetDataFieldDescriptor.InstanceType
- )
+ return new DataFieldDescriptor(Guid.NewGuid(), fieldName, targetDataFieldDescriptor.StoreType, targetDataFieldDescriptor.InstanceType)
{
IsNullable = targetDataFieldDescriptor.IsNullable,
DefaultValue = targetDataFieldDescriptor.DefaultValue,
@@ -1029,26 +948,18 @@ private DataFieldDescriptor CreateWeakReferenceDataFieldDescriptor(DataTypeDescr
};
}
-
-
- private DataFieldDescriptor CreateReferenceDataFieldDescriptor(DataTypeDescriptor targetDataTypeDescriptor, out string foreignKeyFieldName, string fieldName = null)
+ private static DataFieldDescriptor CreateReferenceDataFieldDescriptor(DataTypeDescriptor targetDataTypeDescriptor, out string foreignKeyFieldName, string fieldName = null)
{
- Type targetType = TypeManager.GetType(targetDataTypeDescriptor.TypeManagerTypeName);
- string targetKeyFieldName = targetDataTypeDescriptor.KeyPropertyNames.First();
+ var targetType = TypeManager.GetType(targetDataTypeDescriptor.TypeManagerTypeName);
+ var targetKeyFieldName = targetDataTypeDescriptor.KeyPropertyNames.First();
- DataFieldDescriptor targetKeyDataFieldDescriptor = targetDataTypeDescriptor.Fields[targetKeyFieldName];
+ var targetKeyDataFieldDescriptor = targetDataTypeDescriptor.Fields[targetKeyFieldName];
- foreignKeyFieldName = fieldName ??
- $"{targetDataTypeDescriptor.Name}{targetKeyFieldName}ForeignKey";
+ foreignKeyFieldName = fieldName ?? $"{targetDataTypeDescriptor.Name}{targetKeyFieldName}ForeignKey";
var widgetFunctionProvider = StandardWidgetFunctions.GetDataReferenceWidget(targetType);
- return new DataFieldDescriptor(
- Guid.NewGuid(),
- foreignKeyFieldName,
- targetKeyDataFieldDescriptor.StoreType,
- targetKeyDataFieldDescriptor.InstanceType
- )
+ return new DataFieldDescriptor(Guid.NewGuid(), foreignKeyFieldName, targetKeyDataFieldDescriptor.StoreType, targetKeyDataFieldDescriptor.InstanceType)
{
IsNullable = targetKeyDataFieldDescriptor.IsNullable,
DefaultValue = targetKeyDataFieldDescriptor.DefaultValue,
@@ -1063,27 +974,23 @@ private DataFieldDescriptor CreateReferenceDataFieldDescriptor(DataTypeDescripto
};
}
-
-
private bool IsDataFieldBindable(DataTypeDescriptor dataTypeDescriptor, DataFieldDescriptor dataFieldDescriptor)
{
if (dataFieldDescriptor.Inherited)
{
- Type superInterface = dataTypeDescriptor.SuperInterfaces.FirstOrDefault(type => type.GetProperty(dataFieldDescriptor.Name) != null);
-
- if(superInterface != null && superInterface.Assembly == typeof(IData).Assembly)
+ var superInterface = dataTypeDescriptor.SuperInterfaces.FirstOrDefault(type => type.GetProperty(dataFieldDescriptor.Name) != null);
+ if (superInterface != null && superInterface.Assembly == typeof(IData).Assembly)
{
return false;
}
}
- if ((dataFieldDescriptor.Name == IdFieldName || dataFieldDescriptor.Name == CompositionDescriptionFieldName)
- && dataTypeDescriptor.IsPageMetaDataType)
+ if ((dataFieldDescriptor.Name == IdFieldName || dataFieldDescriptor.Name == CompositionDescriptionFieldName) && dataTypeDescriptor.IsPageMetaDataType)
{
return false;
}
- if (PageFolderFacade.GetAllFolderTypes().Contains(this._oldType) && dataFieldDescriptor.Name == PageReferenceFieldName)
+ if (PageFolderFacade.GetAllFolderTypes().Contains(_oldType) && dataFieldDescriptor.Name == PageReferenceFieldName)
{
return false;
}
@@ -1091,11 +998,9 @@ private bool IsDataFieldBindable(DataTypeDescriptor dataTypeDescriptor, DataFiel
if (dataFieldDescriptor.ForeignKeyReferenceTypeName != null)
{
var dataTypeAssociationDescriptor = dataTypeDescriptor.DataAssociations.FirstOrDefault();
-
if (dataTypeAssociationDescriptor != null)
{
- if (!this.AllowForeignKeyEditing &&
- dataFieldDescriptor.Name == dataTypeAssociationDescriptor.ForeignKeyPropertyName)
+ if (!AllowForeignKeyEditing && dataFieldDescriptor.Name == dataTypeAssociationDescriptor.ForeignKeyPropertyName)
{
return false;
}
diff --git a/Composite/Functions/Inline/InlineFunctionHelper.cs b/Composite/Functions/Inline/InlineFunctionHelper.cs
index 51f03eea9e..dc4bed71fa 100644
--- a/Composite/Functions/Inline/InlineFunctionHelper.cs
+++ b/Composite/Functions/Inline/InlineFunctionHelper.cs
@@ -1,11 +1,13 @@
using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
+using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading;
using System.Web.Hosting;
+using Composite.Core;
using Composite.Core.Configuration;
using Composite.Core.Extensions;
using Composite.Core.IO;
@@ -13,25 +15,20 @@
using Composite.Core.Types;
using Composite.Data;
using Composite.Data.Types;
-using Microsoft.CSharp;
-using Composite.Core;
using Texts = Composite.Core.ResourceSystem.LocalizationFiles.Composite_Plugins_MethodBasedFunctionProviderElementProvider;
namespace Composite.Functions.Inline
{
- ///
- ///
+ ///
///
- [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
+ [EditorBrowsable(EditorBrowsableState.Never)]
public static class InlineFunctionHelper
{
- private static readonly string LogTitle = typeof (InlineFunctionHelper).Name;
+ private static readonly string LogTitle = typeof(InlineFunctionHelper).Name;
///
- public static string MethodClassContainerName { get { return "InlineMethodFunction"; } }
-
-
+ public static string MethodClassContainerName => "InlineMethodFunction";
///
public static MethodInfo Create(IInlineFunction function, string code = null, InlineFunctionCreateMethodErrorHandler createMethodErrorHandler = null, List selectedAssemblies = null)
@@ -59,39 +56,40 @@ public static MethodInfo Create(IInlineFunction function, string code = null, In
}
}
- CompilerParameters compilerParameters = new CompilerParameters();
- compilerParameters.GenerateExecutable = false;
- compilerParameters.GenerateInMemory = true;
+ var compilerParameters = new CompilerParameters
+ {
+ GenerateExecutable = false,
+ GenerateInMemory = true
+ };
if (selectedAssemblies == null)
{
- IEnumerable assemblyReferences =
- DataFacade.GetData(f => f.Function == function.Id).Evaluate();
+ IEnumerable assemblyReferences = DataFacade.GetData(f => f.Function == function.Id).Evaluate();
- foreach (IInlineFunctionAssemblyReference assemblyReference in assemblyReferences)
+ foreach (var assemblyReference in assemblyReferences)
{
- string assemblyPath = GetAssemblyFullPath(assemblyReference.Name, assemblyReference.Location);
+ var assemblyPath = GetAssemblyFullPath(assemblyReference.Name, assemblyReference.Location);
+
compilerParameters.ReferencedAssemblies.Add(assemblyPath);
}
}
else
{
- foreach (string reference in selectedAssemblies)
+ foreach (var reference in selectedAssemblies)
{
compilerParameters.ReferencedAssemblies.Add(reference);
}
}
-
- Assembly appCodeAssembly = AssemblyFacade.GetAppCodeAssembly();
+ var appCodeAssembly = AssemblyFacade.GetAppCodeAssembly();
if (appCodeAssembly != null)
{
compilerParameters.ReferencedAssemblies.Add(appCodeAssembly.Location);
}
- CSharpCodeProvider compiler = new CSharpCodeProvider();
- CompilerResults results = compiler.CompileAssemblyFromSource(compilerParameters, code);
+ var compiler = CSharpCodeProviderFactory.CreateCompiler();
+ var results = compiler.CompileAssemblyFromSource(compilerParameters, code);
if (results.Errors.HasErrors)
{
foreach (CompilerError error in results.Errors)
@@ -109,11 +107,10 @@ public static MethodInfo Create(IInlineFunction function, string code = null, In
return null;
}
-
- Type type = results.CompiledAssembly.GetTypes().SingleOrDefault(f => f.Name == MethodClassContainerName);
+ var type = results.CompiledAssembly.GetTypes().SingleOrDefault(f => f.Name == MethodClassContainerName);
if (type == null)
{
- string message = Texts.CSharpInlineFunction_OnMissingContainerType(MethodClassContainerName);
+ var message = Texts.CSharpInlineFunction_OnMissingContainerType(MethodClassContainerName);
if (createMethodErrorHandler != null)
{
@@ -129,7 +126,7 @@ public static MethodInfo Create(IInlineFunction function, string code = null, In
if (type.Namespace != function.Namespace)
{
- string message = Texts.CSharpInlineFunction_OnNamespaceMismatch(type.Namespace, function.Namespace);
+ var message = Texts.CSharpInlineFunction_OnNamespaceMismatch(type.Namespace, function.Namespace);
if (createMethodErrorHandler != null)
{
@@ -143,10 +140,10 @@ public static MethodInfo Create(IInlineFunction function, string code = null, In
return null;
}
- MethodInfo methodInfo = type.GetMethods(BindingFlags.Public | BindingFlags.Static).SingleOrDefault(f => f.Name == function.Name);
+ var methodInfo = type.GetMethods(BindingFlags.Public | BindingFlags.Static).SingleOrDefault(f => f.Name == function.Name);
if (methodInfo == null)
{
- string message = Texts.CSharpInlineFunction_OnMissionMethod(function.Name, MethodClassContainerName);
+ var message = Texts.CSharpInlineFunction_OnMissionMethod(function.Name, MethodClassContainerName);
if (createMethodErrorHandler != null)
{
@@ -163,54 +160,55 @@ public static MethodInfo Create(IInlineFunction function, string code = null, In
return methodInfo;
}
-
private static void LogMessageIfNotShuttingDown(IInlineFunction function, string message)
{
if (!HostingEnvironment.ApplicationHost.ShutdownInitiated())
{
- Log.LogWarning(LogTitle, string.Format("{0}.{1} : {2}", function.Namespace, function.Name, message));
+ Log.LogWarning(LogTitle, $"{function.Namespace}.{function.Name} : {message}");
}
}
-
///
public static IEnumerable DefaultAssemblies
{
get
{
- string systemPath = Path.GetDirectoryName(typeof(String).Assembly.Location);
-
+ var systemPath = Path.GetDirectoryName(typeof(String).Assembly.Location);
- yield return Path.Combine(systemPath, "System.dll");
- yield return Path.Combine(systemPath, "System.Core.dll");
- yield return Path.Combine(systemPath, "System.Xml.dll");
- yield return Path.Combine(systemPath, "System.Xml.Linq.dll");
- yield return Path.Combine(systemPath, "System.Web.dll");
+ yield return Path.Combine(systemPath, "System.dll");
+ yield return Path.Combine(systemPath, "System.Core.dll");
+ yield return Path.Combine(systemPath, "System.Xml.dll");
+ yield return Path.Combine(systemPath, "System.Xml.Linq.dll");
+ yield return Path.Combine(systemPath, "System.Web.dll");
yield return Path.Combine(PathUtil.Resolve(GlobalSettingsFacade.BinDirectory), "Composite.dll");
- string compositeGeneretedPath = Path.Combine(PathUtil.Resolve(GlobalSettingsFacade.BinDirectory), "Composite.Generated.dll");
- if (C1File.Exists(compositeGeneretedPath)) yield return compositeGeneretedPath;
+ var compositeGeneretedPath = Path.Combine(PathUtil.Resolve(GlobalSettingsFacade.BinDirectory), "Composite.Generated.dll");
+ if (C1File.Exists(compositeGeneretedPath))
+ {
+ yield return compositeGeneretedPath;
+ }
- string compositeWorkflowsPath = Path.Combine(PathUtil.Resolve(GlobalSettingsFacade.BinDirectory), "Composite.Workflows.dll");
- if (C1File.Exists(compositeWorkflowsPath)) yield return compositeWorkflowsPath;
+ var compositeWorkflowsPath = Path.Combine(PathUtil.Resolve(GlobalSettingsFacade.BinDirectory), "Composite.Workflows.dll");
+ if (C1File.Exists(compositeWorkflowsPath))
+ {
+ yield return compositeWorkflowsPath;
+ }
}
}
-
internal static string GetSourceFilePath(this IInlineFunction function)
{
return Path.Combine(PathUtil.Resolve(GlobalSettingsFacade.InlineCSharpFunctionDirectory), function.CodePath);
}
-
///
public static string GetFunctionCode(this IInlineFunction function)
{
- string filepath = GetSourceFilePath(function);
+ var filepath = GetSourceFilePath(function);
// Making 5 attempts to read the file
- for (int i = 5; i > 0; i--)
+ for (var i = 5; i > 0; i--)
{
try
{
@@ -230,49 +228,41 @@ public static string GetFunctionCode(this IInlineFunction function)
throw new InvalidOperationException("This line should not be reachable");
}
-
-
///
public static void DeleteFunctionCode(this IInlineFunction function)
{
- string filepath = GetSourceFilePath(function);
+ var filepath = GetSourceFilePath(function);
FileUtils.Delete(filepath);
}
-
-
///
- public static void SetFunctinoCode(this IInlineFunction function, string content)
+ public static void SetFunctionCode(this IInlineFunction function, string content)
{
- string directoryPath = PathUtil.Resolve(GlobalSettingsFacade.InlineCSharpFunctionDirectory);
+ var directoryPath = PathUtil.Resolve(GlobalSettingsFacade.InlineCSharpFunctionDirectory);
if (C1Directory.Exists(directoryPath) == false)
{
C1Directory.CreateDirectory(directoryPath);
}
- string filepath = Path.Combine(directoryPath, function.CodePath);
+ var filepath = Path.Combine(directoryPath, function.CodePath);
C1File.WriteAllText(filepath, content);
}
-
-
///
public static void FunctionRenamed(IInlineFunction newFunction, IInlineFunction oldFunction)
{
newFunction.UpdateCodePath();
- string directoryPath = PathUtil.Resolve(GlobalSettingsFacade.InlineCSharpFunctionDirectory);
+ var directoryPath = PathUtil.Resolve(GlobalSettingsFacade.InlineCSharpFunctionDirectory);
- string oldFilepath = Path.Combine(directoryPath, oldFunction.CodePath);
- string newFilepath = Path.Combine(directoryPath, newFunction.CodePath);
+ var oldFilepath = Path.Combine(directoryPath, oldFunction.CodePath);
+ var newFilepath = Path.Combine(directoryPath, newFunction.CodePath);
C1File.Move(oldFilepath, newFilepath);
}
-
-
///
public static void UpdateCodePath(this IInlineFunction function)
{
@@ -285,36 +275,32 @@ public static void UpdateCodePath(this IInlineFunction function)
function.CodePath += function.Name + ".cs";
}
-
-
///
public static IEnumerable GetReferencableAssemblies()
{
- string path = Path.GetDirectoryName(typeof(String).Assembly.Location);
- foreach (string file in Directory.GetFiles(path, "System*.dll"))
+ var path = Path.GetDirectoryName(typeof(String).Assembly.Location);
+ foreach (var file in Directory.GetFiles(path, "System*.dll"))
{
yield return file;
}
- foreach (string file in AssemblyFacade.GetAssembliesFromBin(true))
+ foreach (var file in AssemblyFacade.GetAssembliesFromBin(true))
{
yield return file;
}
}
-
-
///
public static string GetAssemblyLocation(string fullPath)
{
- string systemPath = Path.GetDirectoryName(typeof(String).Assembly.Location).ToLowerInvariant();
+ var systemPath = Path.GetDirectoryName(typeof(String).Assembly.Location).ToLowerInvariant();
if (fullPath.ToLowerInvariant().StartsWith(systemPath))
{
return "System";
}
- string binPath = PathUtil.Resolve(GlobalSettingsFacade.BinDirectory).ToLowerInvariant();
+ var binPath = PathUtil.Resolve(GlobalSettingsFacade.BinDirectory).ToLowerInvariant();
if (fullPath.ToLowerInvariant().StartsWith(binPath))
{
return "Bin";
@@ -323,8 +309,6 @@ public static string GetAssemblyLocation(string fullPath)
throw new NotImplementedException();
}
-
-
///
public static string GetAssemblyFullPath(string filename, string location)
{