You've already forked linux-packaging-mono
Imported Upstream version 4.6.0.125
Former-commit-id: a2155e9bd80020e49e72e86c44da02a8ac0e57a4
This commit is contained in:
parent
a569aebcfd
commit
e79aa3c0ed
@@ -0,0 +1 @@
|
||||
b57073f8b83d9344739071ee173b2007c6b1942d
|
@@ -0,0 +1,82 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
namespace Microsoft.CSharp.Activities
|
||||
{
|
||||
using System;
|
||||
using System.Activities;
|
||||
using System.Activities.Expressions;
|
||||
using System.Activities.XamlIntegration;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Linq.Expressions;
|
||||
using System.Windows.Markup;
|
||||
|
||||
[DebuggerStepThrough]
|
||||
[ContentProperty("ExpressionText")]
|
||||
public class CSharpReference<TResult> : CodeActivity<Location<TResult>>, ITextExpression
|
||||
{
|
||||
CompiledExpressionInvoker invoker;
|
||||
|
||||
public CSharpReference()
|
||||
{
|
||||
this.UseOldFastPath = true;
|
||||
}
|
||||
|
||||
public CSharpReference(string expressionText) :
|
||||
this()
|
||||
{
|
||||
this.ExpressionText = expressionText;
|
||||
}
|
||||
|
||||
public string ExpressionText
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
|
||||
public string Language
|
||||
{
|
||||
get
|
||||
{
|
||||
return "C#";
|
||||
}
|
||||
}
|
||||
|
||||
public bool RequiresCompilation
|
||||
{
|
||||
get
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void CacheMetadata(CodeActivityMetadata metadata)
|
||||
{
|
||||
this.invoker = new CompiledExpressionInvoker(this, true, metadata);
|
||||
}
|
||||
|
||||
protected override Location<TResult> Execute(CodeActivityContext context)
|
||||
{
|
||||
Location<TResult> value = (Location<TResult>)this.invoker.InvokeExpression(context);
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
public Expression GetExpressionTree()
|
||||
{
|
||||
if (this.IsMetadataCached)
|
||||
{
|
||||
return this.invoker.GetExpressionTree();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw FxTrace.Exception.AsError(new InvalidOperationException(SR.ActivityIsUncached));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,82 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
namespace Microsoft.CSharp.Activities
|
||||
{
|
||||
using System;
|
||||
using System.Activities;
|
||||
using System.Activities.Expressions;
|
||||
using System.Activities.Validation;
|
||||
using System.Activities.XamlIntegration;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Linq.Expressions;
|
||||
using System.Reflection;
|
||||
using System.Runtime;
|
||||
using System.Windows.Markup;
|
||||
|
||||
[DebuggerStepThrough]
|
||||
[ContentProperty("ExpressionText")]
|
||||
public class CSharpValue<TResult> : CodeActivity<TResult>, ITextExpression
|
||||
{
|
||||
CompiledExpressionInvoker invoker;
|
||||
|
||||
public CSharpValue()
|
||||
{
|
||||
this.UseOldFastPath = true;
|
||||
}
|
||||
|
||||
public CSharpValue(string expressionText) :
|
||||
this()
|
||||
{
|
||||
this.ExpressionText = expressionText;
|
||||
}
|
||||
|
||||
public string ExpressionText
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
|
||||
public string Language
|
||||
{
|
||||
get
|
||||
{
|
||||
return "C#";
|
||||
}
|
||||
}
|
||||
|
||||
public bool RequiresCompilation
|
||||
{
|
||||
get
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void CacheMetadata(CodeActivityMetadata metadata)
|
||||
{
|
||||
this.invoker = new CompiledExpressionInvoker(this, false, metadata);
|
||||
}
|
||||
|
||||
protected override TResult Execute(CodeActivityContext context)
|
||||
{
|
||||
return (TResult)this.invoker.InvokeExpression(context);
|
||||
}
|
||||
|
||||
public Expression GetExpressionTree()
|
||||
{
|
||||
if (this.IsMetadataCached)
|
||||
{
|
||||
return this.invoker.GetExpressionTree();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw FxTrace.Exception.AsError(new InvalidOperationException(SR.ActivityIsUncached));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,50 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
namespace Microsoft.VisualBasic.Activities
|
||||
{
|
||||
using System;
|
||||
using System.Activities;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Runtime;
|
||||
using System.Xaml;
|
||||
|
||||
[SuppressMessage(FxCop.Category.Naming, FxCop.Rule.TypeNamesShouldNotMatchNamespaces,
|
||||
Justification = "Approved name")]
|
||||
public static class VisualBasic
|
||||
{
|
||||
static AttachableMemberIdentifier settingsPropertyID = new AttachableMemberIdentifier(typeof(VisualBasic), "Settings");
|
||||
|
||||
public static void SetSettings(object target, VisualBasicSettings value)
|
||||
{
|
||||
AttachablePropertyServices.SetProperty(target, settingsPropertyID, value);
|
||||
}
|
||||
|
||||
public static VisualBasicSettings GetSettings(object target)
|
||||
{
|
||||
VisualBasicSettings value;
|
||||
return AttachablePropertyServices.TryGetProperty(target, settingsPropertyID, out value) ? value : null;
|
||||
}
|
||||
|
||||
public static void SetSettingsForImplementation(object target, VisualBasicSettings value)
|
||||
{
|
||||
if (value != null)
|
||||
{
|
||||
value.SuppressXamlSerialization = true;
|
||||
}
|
||||
SetSettings(target, value);
|
||||
}
|
||||
|
||||
public static bool ShouldSerializeSettings(object target)
|
||||
{
|
||||
VisualBasicSettings settings = VisualBasic.GetSettings(target);
|
||||
|
||||
if (settings != null && settings.SuppressXamlSerialization && target is Activity)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,164 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
namespace Microsoft.VisualBasic.Activities
|
||||
{
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Reflection;
|
||||
using System.Activities.Expressions;
|
||||
using System.Xaml;
|
||||
using System.Xml.Linq;
|
||||
|
||||
public class VisualBasicImportReference : IEquatable<VisualBasicImportReference>
|
||||
{
|
||||
static AssemblyNameEqualityComparer equalityComparer = new AssemblyNameEqualityComparer();
|
||||
AssemblyName assemblyName;
|
||||
string assemblyNameString;
|
||||
int hashCode;
|
||||
string import;
|
||||
|
||||
public VisualBasicImportReference()
|
||||
{
|
||||
}
|
||||
|
||||
public string Assembly
|
||||
{
|
||||
get { return this.assemblyNameString; }
|
||||
|
||||
set
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
this.assemblyName = null;
|
||||
this.assemblyNameString = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
// FileLoadException thrown from this ctor indicates invalid assembly name
|
||||
this.assemblyName = new AssemblyName(value);
|
||||
this.assemblyNameString = this.assemblyName.FullName;
|
||||
}
|
||||
this.EarlyBoundAssembly = null;
|
||||
}
|
||||
}
|
||||
|
||||
public string Import
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.import;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value != null)
|
||||
{
|
||||
this.import = value.Trim();
|
||||
this.hashCode = this.import.ToUpperInvariant().GetHashCode();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.import = null;
|
||||
this.hashCode = 0;
|
||||
}
|
||||
this.EarlyBoundAssembly = null;
|
||||
}
|
||||
}
|
||||
|
||||
internal AssemblyName AssemblyName
|
||||
{
|
||||
get { return this.assemblyName; }
|
||||
}
|
||||
|
||||
internal XNamespace Xmlns
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
// for the short-cut assembly resolution
|
||||
// from VBImportReference.AssemblyName ==> System.Reflection.Assembly
|
||||
// this is an internal state that implies the context in which a VB assembly resolution is progressing
|
||||
// once VB extracted this Assembly object to pass onto the compiler,
|
||||
// it must explicitly set this property back to null.
|
||||
// Clone() will also explicitly set this property of the new to null to prevent users from inadvertently
|
||||
// creating a copy of VBImportReference that might not resolve to the assembly of his or her intent.
|
||||
internal Assembly EarlyBoundAssembly
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
internal VisualBasicImportReference Clone()
|
||||
{
|
||||
VisualBasicImportReference toReturn = (VisualBasicImportReference)this.MemberwiseClone();
|
||||
toReturn.EarlyBoundAssembly = null;
|
||||
// Also make a clone of the AssemblyName.
|
||||
toReturn.assemblyName = (AssemblyName) this.assemblyName.Clone();
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return this.hashCode;
|
||||
}
|
||||
|
||||
public bool Equals(VisualBasicImportReference other)
|
||||
{
|
||||
if (other == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Object.ReferenceEquals(this, other))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (this.EarlyBoundAssembly != other.EarlyBoundAssembly)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// VB does case insensitive comparisons for imports
|
||||
if (string.Compare(this.Import, other.Import, StringComparison.OrdinalIgnoreCase) != 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// now compare the assemblies
|
||||
if (this.AssemblyName == null && other.AssemblyName == null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if (this.AssemblyName == null && other.AssemblyName != null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (this.AssemblyName != null && other.AssemblyName == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return equalityComparer.Equals(this.AssemblyName, other.AssemblyName);
|
||||
}
|
||||
|
||||
internal void GenerateXamlNamespace(INamespacePrefixLookup namespaceLookup)
|
||||
{
|
||||
// promote reference to xmlns declaration
|
||||
string xamlNamespace = null;
|
||||
if (this.Xmlns != null && !string.IsNullOrEmpty(this.Xmlns.NamespaceName))
|
||||
{
|
||||
xamlNamespace = this.Xmlns.NamespaceName;
|
||||
}
|
||||
else
|
||||
{
|
||||
xamlNamespace = string.Format(CultureInfo.InvariantCulture, "clr-namespace:{0};assembly={1}", this.Import, this.Assembly);
|
||||
}
|
||||
// we don't need the return value since we just want to register the namespace/assembly pair
|
||||
namespaceLookup.LookupPrefix(xamlNamespace);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,72 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
namespace Microsoft.VisualBasic.Activities
|
||||
{
|
||||
using System;
|
||||
using System.Activities;
|
||||
using System.Activities.Expressions;
|
||||
using System.Activities.Validation;
|
||||
using System.Globalization;
|
||||
using System.Reflection;
|
||||
|
||||
sealed class VisualBasicNameShadowingConstraint : Constraint
|
||||
{
|
||||
protected override void OnExecute(NativeActivityContext context, object objectToValidate, ValidationContext objectToValidateContext)
|
||||
{
|
||||
bool foundMultiple;
|
||||
ActivityWithResult boundExpression;
|
||||
LocationReference locationReference;
|
||||
ActivityWithResult activity = (ActivityWithResult)objectToValidate;
|
||||
|
||||
foreach (RuntimeArgument runtimeArgument in activity.RuntimeArguments)
|
||||
{
|
||||
boundExpression = runtimeArgument.BoundArgument.Expression;
|
||||
|
||||
if (boundExpression != null && boundExpression is ILocationReferenceWrapper)
|
||||
{
|
||||
locationReference = ((ILocationReferenceWrapper)boundExpression).LocationReference;
|
||||
|
||||
if (locationReference != null)
|
||||
{
|
||||
foundMultiple = FindLocationReferencesFromEnvironment(objectToValidateContext.Environment, locationReference.Name);
|
||||
if (foundMultiple)
|
||||
{
|
||||
Constraint.AddValidationError(context, new ValidationError(SR.AmbiguousVBVariableReference(locationReference.Name)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static bool FindLocationReferencesFromEnvironment(LocationReferenceEnvironment environment, string targetName)
|
||||
{
|
||||
LocationReference foundLocationReference = null;
|
||||
LocationReferenceEnvironment currentEnvironment;
|
||||
bool foundMultiple = false;
|
||||
|
||||
currentEnvironment = environment;
|
||||
while (currentEnvironment != null)
|
||||
{
|
||||
foreach (LocationReference reference in currentEnvironment.GetLocationReferences())
|
||||
{
|
||||
if (string.Equals(reference.Name, targetName, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
if (foundLocationReference != null)
|
||||
{
|
||||
foundMultiple = true;
|
||||
return foundMultiple;
|
||||
}
|
||||
|
||||
foundLocationReference = reference;
|
||||
}
|
||||
}
|
||||
|
||||
currentEnvironment = currentEnvironment.Parent;
|
||||
}
|
||||
|
||||
return foundMultiple;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,183 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
namespace Microsoft.VisualBasic.Activities
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Activities;
|
||||
using System.Activities.Expressions;
|
||||
using System.Activities.ExpressionParser;
|
||||
using System.Activities.XamlIntegration;
|
||||
using System.Linq.Expressions;
|
||||
using System.Windows.Markup;
|
||||
using System.ComponentModel;
|
||||
using System.Runtime;
|
||||
|
||||
[DebuggerStepThrough]
|
||||
public sealed class VisualBasicReference<TResult> : CodeActivity<Location<TResult>>, IValueSerializableExpression, IExpressionContainer, ITextExpression
|
||||
{
|
||||
Expression<Func<ActivityContext, TResult>> expressionTree;
|
||||
LocationFactory<TResult> locationFactory;
|
||||
CompiledExpressionInvoker invoker;
|
||||
|
||||
public VisualBasicReference()
|
||||
: base()
|
||||
{
|
||||
this.UseOldFastPath = true;
|
||||
}
|
||||
|
||||
public VisualBasicReference(string expressionText)
|
||||
: this()
|
||||
{
|
||||
this.ExpressionText = expressionText;
|
||||
}
|
||||
|
||||
public string ExpressionText
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
|
||||
public string Language
|
||||
{
|
||||
get
|
||||
{
|
||||
return VisualBasicHelper.Language;
|
||||
}
|
||||
}
|
||||
|
||||
public bool RequiresCompilation
|
||||
{
|
||||
get
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
protected override Location<TResult> Execute(CodeActivityContext context)
|
||||
{
|
||||
if (!this.invoker.IsStaticallyCompiled)
|
||||
{
|
||||
if (this.expressionTree != null)
|
||||
{
|
||||
if (this.locationFactory == null)
|
||||
{
|
||||
this.locationFactory = ExpressionUtilities.CreateLocationFactory<TResult>(this.expressionTree);
|
||||
}
|
||||
|
||||
return this.locationFactory.CreateLocation(context);
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return (Location<TResult>) this.invoker.InvokeExpression(context);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void CacheMetadata(CodeActivityMetadata metadata)
|
||||
{
|
||||
this.expressionTree = null;
|
||||
this.invoker = new CompiledExpressionInvoker(this, true, metadata);
|
||||
if (this.invoker.IsStaticallyCompiled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
string validationError;
|
||||
|
||||
// If ICER is not implemented that means we haven't been compiled
|
||||
CodeActivityPublicEnvironmentAccessor publicAccessor = CodeActivityPublicEnvironmentAccessor.Create(metadata);
|
||||
this.expressionTree = this.CompileLocationExpression(publicAccessor, out validationError);
|
||||
|
||||
if (validationError != null)
|
||||
{
|
||||
metadata.AddValidationError(validationError);
|
||||
}
|
||||
}
|
||||
|
||||
public bool CanConvertToString(IValueSerializerContext context)
|
||||
{
|
||||
// we can always convert to a string
|
||||
return true;
|
||||
}
|
||||
|
||||
public string ConvertToString(IValueSerializerContext context)
|
||||
{
|
||||
// Return our bracket-escaped text
|
||||
return "[" + this.ExpressionText + "]";
|
||||
}
|
||||
|
||||
public Expression GetExpressionTree()
|
||||
{
|
||||
if (this.IsMetadataCached)
|
||||
{
|
||||
if (this.expressionTree == null)
|
||||
{
|
||||
string validationError;
|
||||
|
||||
// it's safe to create this CodeActivityMetadata here,
|
||||
// because we know we are using it only as lookup purpose.
|
||||
CodeActivityMetadata metadata = new CodeActivityMetadata(this, this.GetParentEnvironment(), false);
|
||||
CodeActivityPublicEnvironmentAccessor publicAccessor = CodeActivityPublicEnvironmentAccessor.CreateWithoutArgument(metadata);
|
||||
try
|
||||
{
|
||||
this.expressionTree = this.CompileLocationExpression(publicAccessor, out validationError);
|
||||
|
||||
if (validationError != null)
|
||||
{
|
||||
throw FxTrace.Exception.AsError(new InvalidOperationException(SR.VBExpressionTamperedSinceLastCompiled(validationError)));
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
metadata.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
Fx.Assert(this.expressionTree.NodeType == ExpressionType.Lambda, "Lambda expression required");
|
||||
return ExpressionUtilities.RewriteNonCompiledExpressionTree((LambdaExpression)this.expressionTree);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw FxTrace.Exception.AsError(new InvalidOperationException(SR.ActivityIsUncached));
|
||||
}
|
||||
}
|
||||
|
||||
private Expression<Func<ActivityContext, TResult>> CompileLocationExpression(CodeActivityPublicEnvironmentAccessor publicAccessor, out string validationError)
|
||||
{
|
||||
Expression<Func<ActivityContext, TResult>> expressionTreeToReturn = null;
|
||||
validationError = null;
|
||||
try
|
||||
{
|
||||
expressionTreeToReturn = VisualBasicHelper.Compile<TResult>(this.ExpressionText, publicAccessor, true);
|
||||
// inspect the expressionTree to see if it is a valid location expression(L-value)
|
||||
string extraErrorMessage = null;
|
||||
if (!publicAccessor.ActivityMetadata.HasViolations && (expressionTreeToReturn == null || !ExpressionUtilities.IsLocation(expressionTreeToReturn, typeof(TResult), out extraErrorMessage)))
|
||||
{
|
||||
string errorMessage = SR.InvalidLValueExpression;
|
||||
|
||||
if (extraErrorMessage != null)
|
||||
{
|
||||
errorMessage += ":" + extraErrorMessage;
|
||||
}
|
||||
expressionTreeToReturn = null;
|
||||
validationError = SR.CompilerErrorSpecificExpression(this.ExpressionText, errorMessage);
|
||||
}
|
||||
}
|
||||
catch (SourceExpressionException e)
|
||||
{
|
||||
validationError = e.Message;
|
||||
}
|
||||
|
||||
return expressionTreeToReturn;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,93 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
namespace Microsoft.VisualBasic.Activities
|
||||
{
|
||||
using Microsoft.VisualBasic.Activities.XamlIntegration;
|
||||
using System;
|
||||
using System.Activities;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime;
|
||||
using System.Windows.Markup;
|
||||
using System.Xaml;
|
||||
using System.ComponentModel;
|
||||
using System.Reflection;
|
||||
|
||||
[ValueSerializer(typeof(VisualBasicSettingsValueSerializer))]
|
||||
[TypeConverter(typeof(VisualBasicSettingsConverter))]
|
||||
public class VisualBasicSettings
|
||||
{
|
||||
|
||||
static readonly HashSet<VisualBasicImportReference> defaultImportReferences = new HashSet<VisualBasicImportReference>()
|
||||
{
|
||||
//"mscorlib"
|
||||
new VisualBasicImportReference { Import = "System", Assembly = "mscorlib" },
|
||||
new VisualBasicImportReference { Import = "System.Collections", Assembly = "mscorlib" },
|
||||
new VisualBasicImportReference { Import = "System.Collections.Generic", Assembly = "mscorlib" },
|
||||
//"system"
|
||||
new VisualBasicImportReference { Import = "System", Assembly = "system" },
|
||||
new VisualBasicImportReference { Import = "System.Collections.Generic", Assembly = "system" },
|
||||
//"System.Activities"
|
||||
new VisualBasicImportReference { Import = "System.Activities", Assembly = "System.Activities" },
|
||||
new VisualBasicImportReference { Import = "System.Activities.Statements", Assembly = "System.Activities" },
|
||||
new VisualBasicImportReference { Import = "System.Activities.Expressions", Assembly = "System.Activities" },
|
||||
};
|
||||
|
||||
static VisualBasicSettings defaultSettings = new VisualBasicSettings(defaultImportReferences);
|
||||
|
||||
public VisualBasicSettings()
|
||||
{
|
||||
this.ImportReferences = new HashSet<VisualBasicImportReference>();
|
||||
}
|
||||
|
||||
VisualBasicSettings(HashSet<VisualBasicImportReference> importReferences)
|
||||
{
|
||||
Fx.Assert(importReferences != null, "caller must verify");
|
||||
this.ImportReferences = new HashSet<VisualBasicImportReference>(importReferences);
|
||||
}
|
||||
|
||||
public static VisualBasicSettings Default
|
||||
{
|
||||
get
|
||||
{
|
||||
return defaultSettings;
|
||||
}
|
||||
}
|
||||
|
||||
// hide from XAML since the value serializer can't suppress yet
|
||||
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
|
||||
public ISet<VisualBasicImportReference> ImportReferences
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
internal bool SuppressXamlSerialization
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
internal void GenerateXamlReferences(IValueSerializerContext context)
|
||||
{
|
||||
// promote settings to xmlns declarations
|
||||
INamespacePrefixLookup namespaceLookup = GetService<INamespacePrefixLookup>(context);
|
||||
foreach (VisualBasicImportReference importReference in this.ImportReferences)
|
||||
{
|
||||
importReference.GenerateXamlNamespace(namespaceLookup);
|
||||
}
|
||||
}
|
||||
|
||||
internal static T GetService<T>(ITypeDescriptorContext context) where T : class
|
||||
{
|
||||
T service = (T)context.GetService(typeof(T));
|
||||
if (service == null)
|
||||
{
|
||||
throw FxTrace.Exception.AsError(new InvalidOperationException(SR.InvalidTypeConverterUsage));
|
||||
}
|
||||
|
||||
return service;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,151 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
namespace Microsoft.VisualBasic.Activities
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Activities;
|
||||
using System.Activities.Expressions;
|
||||
using System.Activities.ExpressionParser;
|
||||
using System.Activities.XamlIntegration;
|
||||
using System.Linq.Expressions;
|
||||
using System.Windows.Markup;
|
||||
using System.ComponentModel;
|
||||
using System.Runtime;
|
||||
|
||||
[DebuggerStepThrough]
|
||||
public sealed class VisualBasicValue<TResult> : CodeActivity<TResult>, IValueSerializableExpression, IExpressionContainer, ITextExpression
|
||||
{
|
||||
Expression<Func<ActivityContext, TResult>> expressionTree;
|
||||
Func<ActivityContext, TResult> compiledExpression;
|
||||
CompiledExpressionInvoker invoker;
|
||||
|
||||
public VisualBasicValue()
|
||||
: base()
|
||||
{
|
||||
this.UseOldFastPath = true;
|
||||
}
|
||||
|
||||
public VisualBasicValue(string expressionText)
|
||||
: this()
|
||||
{
|
||||
this.ExpressionText = expressionText;
|
||||
}
|
||||
|
||||
public string ExpressionText
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
|
||||
public string Language
|
||||
{
|
||||
get
|
||||
{
|
||||
return VisualBasicHelper.Language;
|
||||
}
|
||||
}
|
||||
|
||||
public bool RequiresCompilation
|
||||
{
|
||||
get
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
protected override TResult Execute(CodeActivityContext context)
|
||||
{
|
||||
if (!this.invoker.IsStaticallyCompiled)
|
||||
{
|
||||
if (this.expressionTree != null)
|
||||
{
|
||||
if (this.compiledExpression == null)
|
||||
{
|
||||
this.compiledExpression = this.expressionTree.Compile();
|
||||
}
|
||||
return this.compiledExpression(context);
|
||||
}
|
||||
else
|
||||
{
|
||||
return default(TResult);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return (TResult)this.invoker.InvokeExpression(context);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void CacheMetadata(CodeActivityMetadata metadata)
|
||||
{
|
||||
this.expressionTree = null;
|
||||
this.invoker = new CompiledExpressionInvoker(this, false, metadata);
|
||||
if (this.invoker.IsStaticallyCompiled == true)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// If ICER is not implemented that means we haven't been compiled
|
||||
|
||||
CodeActivityPublicEnvironmentAccessor publicAccessor = CodeActivityPublicEnvironmentAccessor.Create(metadata);
|
||||
try
|
||||
{
|
||||
this.expressionTree = VisualBasicHelper.Compile<TResult>(this.ExpressionText, publicAccessor, false);
|
||||
}
|
||||
catch (SourceExpressionException e)
|
||||
{
|
||||
metadata.AddValidationError(e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
public bool CanConvertToString(IValueSerializerContext context)
|
||||
{
|
||||
// we can always convert to a string
|
||||
return true;
|
||||
}
|
||||
|
||||
public string ConvertToString(IValueSerializerContext context)
|
||||
{
|
||||
// Return our bracket-escaped text
|
||||
return "[" + this.ExpressionText + "]";
|
||||
}
|
||||
|
||||
public Expression GetExpressionTree()
|
||||
{
|
||||
if (this.IsMetadataCached)
|
||||
{
|
||||
if (this.expressionTree == null)
|
||||
{
|
||||
// it's safe to create this CodeActivityMetadata here,
|
||||
// because we know we are using it only as lookup purpose.
|
||||
CodeActivityMetadata metadata = new CodeActivityMetadata(this, this.GetParentEnvironment(), false);
|
||||
CodeActivityPublicEnvironmentAccessor publicAccessor = CodeActivityPublicEnvironmentAccessor.CreateWithoutArgument(metadata);
|
||||
try
|
||||
{
|
||||
this.expressionTree = VisualBasicHelper.Compile<TResult>(this.ExpressionText, publicAccessor, false);
|
||||
}
|
||||
catch (SourceExpressionException e)
|
||||
{
|
||||
throw FxTrace.Exception.AsError(new InvalidOperationException(SR.VBExpressionTamperedSinceLastCompiled(e.Message)));
|
||||
}
|
||||
finally
|
||||
{
|
||||
metadata.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
Fx.Assert(this.expressionTree.NodeType == ExpressionType.Lambda, "Lambda expression required");
|
||||
return ExpressionUtilities.RewriteNonCompiledExpressionTree((LambdaExpression)this.expressionTree);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw FxTrace.Exception.AsError(new InvalidOperationException(SR.ActivityIsUncached));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,435 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
namespace Microsoft.VisualBasic.Activities.XamlIntegration
|
||||
{
|
||||
using System;
|
||||
using System.Activities.Expressions;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Reflection;
|
||||
using System.Xml.Linq;
|
||||
using System.ComponentModel;
|
||||
using System.Xaml;
|
||||
using System.Windows.Markup;
|
||||
using System.Security;
|
||||
using System.Security.Permissions;
|
||||
using System.Runtime;
|
||||
using System.Threading;
|
||||
|
||||
static class VisualBasicExpressionConverter
|
||||
{
|
||||
static readonly Regex assemblyQualifiedNamespaceRegex = new Regex(
|
||||
"clr-namespace:(?<namespace>[^;]*);assembly=(?<assembly>.*)", RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
||||
|
||||
public static VisualBasicSettings CollectXmlNamespacesAndAssemblies(ITypeDescriptorContext context)
|
||||
{
|
||||
// access XamlSchemaContext.ReferenceAssemblies
|
||||
// for the Compiled Xaml scenario
|
||||
IList<Assembly> xsCtxReferenceAssemblies = null;
|
||||
IXamlSchemaContextProvider xamlSchemaContextProvider = context.GetService(typeof(IXamlSchemaContextProvider)) as IXamlSchemaContextProvider;
|
||||
if (xamlSchemaContextProvider != null && xamlSchemaContextProvider.SchemaContext != null)
|
||||
{
|
||||
xsCtxReferenceAssemblies = xamlSchemaContextProvider.SchemaContext.ReferenceAssemblies;
|
||||
if (xsCtxReferenceAssemblies != null && xsCtxReferenceAssemblies.Count == 0)
|
||||
{
|
||||
xsCtxReferenceAssemblies = null;
|
||||
}
|
||||
}
|
||||
|
||||
VisualBasicSettings settings = null;
|
||||
IXamlNamespaceResolver namespaceResolver = (IXamlNamespaceResolver)context.GetService(typeof(IXamlNamespaceResolver));
|
||||
|
||||
if (namespaceResolver == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
lock (AssemblyCache.XmlnsMappingsLockObject)
|
||||
{
|
||||
// Fetch xmlnsMappings for the prefixes returned by the namespaceResolver service
|
||||
|
||||
foreach (NamespaceDeclaration prefix in namespaceResolver.GetNamespacePrefixes())
|
||||
{
|
||||
ReadOnlyXmlnsMapping mapping;
|
||||
WrapCachedMapping(prefix, out mapping);
|
||||
if (!mapping.IsEmpty)
|
||||
{
|
||||
if (settings == null)
|
||||
{
|
||||
settings = new VisualBasicSettings();
|
||||
}
|
||||
|
||||
if (!mapping.IsEmpty)
|
||||
{
|
||||
foreach (ReadOnlyVisualBasicImportReference importReference in mapping.ImportReferences)
|
||||
{
|
||||
if (xsCtxReferenceAssemblies != null)
|
||||
{
|
||||
// this is "compiled Xaml"
|
||||
VisualBasicImportReference newImportReference;
|
||||
|
||||
if (importReference.EarlyBoundAssembly != null)
|
||||
{
|
||||
if (xsCtxReferenceAssemblies.Contains(importReference.EarlyBoundAssembly))
|
||||
{
|
||||
newImportReference = importReference.Clone();
|
||||
newImportReference.EarlyBoundAssembly = importReference.EarlyBoundAssembly;
|
||||
settings.ImportReferences.Add(newImportReference);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
for (int i = 0; i < xsCtxReferenceAssemblies.Count; i++)
|
||||
{
|
||||
AssemblyName xsCtxAssemblyName = VisualBasicHelper.GetFastAssemblyName(xsCtxReferenceAssemblies[i]);
|
||||
if (importReference.AssemblySatisfiesReference(xsCtxAssemblyName))
|
||||
{
|
||||
// bind this assembly early to the importReference
|
||||
// so later AssemblyName resolution can be skipped
|
||||
newImportReference = importReference.Clone();
|
||||
newImportReference.EarlyBoundAssembly = xsCtxReferenceAssemblies[i];
|
||||
settings.ImportReferences.Add(newImportReference);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// this is "loose Xaml"
|
||||
VisualBasicImportReference newImportReference = importReference.Clone();
|
||||
if (importReference.EarlyBoundAssembly != null)
|
||||
{
|
||||
// VBImportReference.Clone() method deliberately doesn't copy
|
||||
// its EarlyBoundAssembly to the cloned instance.
|
||||
// we need to explicitly copy the original's EarlyBoundAssembly
|
||||
newImportReference.EarlyBoundAssembly = importReference.EarlyBoundAssembly;
|
||||
}
|
||||
settings.ImportReferences.Add(newImportReference);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return settings;
|
||||
}
|
||||
|
||||
[Fx.Tag.SecurityNote(Critical = "Critical because we are accessing critical member AssemblyCache.XmlnsMappings.",
|
||||
Safe = "Safe because we prevent partial trusted code from manipulating the cache directly by creating a read-only wrapper around the cached XmlnsMapping.")]
|
||||
[SecuritySafeCritical]
|
||||
private static void WrapCachedMapping(NamespaceDeclaration prefix, out ReadOnlyXmlnsMapping readOnlyMapping)
|
||||
{
|
||||
XmlnsMapping mapping = new XmlnsMapping();
|
||||
XNamespace xmlns = XNamespace.Get(prefix.Namespace);
|
||||
|
||||
if (!AssemblyCache.XmlnsMappings.TryGetValue(xmlns, out mapping))
|
||||
{
|
||||
// Match a namespace of the form "clr-namespace:<namespace-name>;assembly=<assembly-name>"
|
||||
|
||||
Match match = assemblyQualifiedNamespaceRegex.Match(prefix.Namespace);
|
||||
|
||||
if (match.Success)
|
||||
{
|
||||
mapping.ImportReferences = new HashSet<VisualBasicImportReference>();
|
||||
mapping.ImportReferences.Add(
|
||||
new VisualBasicImportReference
|
||||
{
|
||||
Assembly = match.Groups["assembly"].Value,
|
||||
Import = match.Groups["namespace"].Value,
|
||||
Xmlns = xmlns
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
mapping.ImportReferences = new HashSet<VisualBasicImportReference>();
|
||||
}
|
||||
AssemblyCache.XmlnsMappings[xmlns] = mapping;
|
||||
}
|
||||
|
||||
// ReadOnlyXmlnsMapping constructor tolerates an empty mapping being passed in.
|
||||
readOnlyMapping = new ReadOnlyXmlnsMapping(mapping);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Static class used to cache assembly metadata.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <list type="bullet">
|
||||
/// <item><description>
|
||||
/// XmlnsMappings for static assemblies are not GC'd. In v4.0 we can assume that all static assemblies
|
||||
/// containing XmlnsDefinition attributes are non-collectible. The CLR will provide no public mechanism
|
||||
/// for unloading a static assembly or specifying that a static assembly is collectible. While there
|
||||
/// may be some small number of assemblies identified by the CLR as collectible, none will contain
|
||||
/// XmlnsDefinition attributes. Should the CLR provide a public mechanism for unloading a static assembly
|
||||
/// or specifying that a static assembly is collectible, we should revisit this decision based on scenarios
|
||||
/// that flow from these mechanisms.
|
||||
/// </description></item>
|
||||
/// <item><description>
|
||||
/// XmlnsMappings for dynamic assemblies are not created. This is because the hosted Visual Basic compiler
|
||||
/// does not support dynamic assembly references. Should support for dynamic assembly references be
|
||||
/// added to the Visual Basic compiler, we should strip away Assembly.IsDynamic checks from this class and
|
||||
/// update the code ensure that VisualBasicImportReference instances are removed in a timely manner.
|
||||
/// </description></item>
|
||||
/// </list>
|
||||
/// </remarks>
|
||||
static class AssemblyCache
|
||||
{
|
||||
static bool initialized = false;
|
||||
|
||||
// This is here so that obtaining the lock is not required to be SecurityCritical.
|
||||
public static object XmlnsMappingsLockObject = new object();
|
||||
|
||||
[Fx.Tag.SecurityNote(Critical = "Critical because we are storing assembly references and if we alloed PT access, they could mess with that.")]
|
||||
[SecurityCritical]
|
||||
static Dictionary<XNamespace, XmlnsMapping> xmlnsMappings;
|
||||
|
||||
public static Dictionary<XNamespace, XmlnsMapping> XmlnsMappings
|
||||
{
|
||||
[Fx.Tag.SecurityNote(Critical = "Critical because providing access to the critical xmlnsMappings dictionary.")]
|
||||
[SecurityCritical]
|
||||
get
|
||||
{
|
||||
EnsureInitialized();
|
||||
return xmlnsMappings;
|
||||
}
|
||||
}
|
||||
|
||||
[Fx.Tag.SecurityNote(Critical = "Critical because we are accessing critical member xmlnsMappings and CacheLoadedAssembly. Only called from CLR.")]
|
||||
[SecurityCritical]
|
||||
static void OnAssemblyLoaded(object sender, AssemblyLoadEventArgs args)
|
||||
{
|
||||
Assembly assembly = args.LoadedAssembly;
|
||||
|
||||
if (assembly.IsDefined(typeof(XmlnsDefinitionAttribute), false) && !assembly.IsDynamic)
|
||||
{
|
||||
lock (XmlnsMappingsLockObject)
|
||||
{
|
||||
CacheLoadedAssembly(assembly);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Fx.Tag.SecurityNote(Critical = "Critical because we are accessing AppDomain.AssemblyLoaded and we are accessing critical member xmlnsMappings.")]
|
||||
[SecurityCritical]
|
||||
static void EnsureInitialized()
|
||||
{
|
||||
if (initialized)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (xmlnsMappings == null)
|
||||
{
|
||||
Interlocked.CompareExchange(ref xmlnsMappings,
|
||||
new Dictionary<XNamespace, XmlnsMapping>(new XNamespaceEqualityComparer()),
|
||||
null);
|
||||
}
|
||||
|
||||
lock (XmlnsMappingsLockObject)
|
||||
{
|
||||
if (AssemblyCache.initialized)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
AppDomain.CurrentDomain.AssemblyLoad += OnAssemblyLoaded;
|
||||
|
||||
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
|
||||
|
||||
for (int i = 0; i < assemblies.Length; ++i)
|
||||
{
|
||||
Assembly assembly = assemblies[i];
|
||||
|
||||
if (assembly.IsDefined(typeof(XmlnsDefinitionAttribute), false) && ! assembly.IsDynamic)
|
||||
{
|
||||
CacheLoadedAssembly(assembly);
|
||||
}
|
||||
}
|
||||
|
||||
initialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
[Fx.Tag.SecurityNote(Critical = "Critical because we are accessing critical member xmlnsMappings.")]
|
||||
[SecurityCritical]
|
||||
static void CacheLoadedAssembly(Assembly assembly)
|
||||
{
|
||||
// this VBImportReference is only used as an entry to the xmlnsMappings cache
|
||||
// and is never meant to be Xaml serialized.
|
||||
// those VBImportReferences that are to be Xaml serialized are created by Clone() method.
|
||||
XmlnsDefinitionAttribute[] attributes = (XmlnsDefinitionAttribute[])assembly.GetCustomAttributes(typeof(XmlnsDefinitionAttribute), false);
|
||||
string assemblyName = assembly.FullName;
|
||||
XmlnsMapping mapping;
|
||||
|
||||
for (int i = 0; i < attributes.Length; ++i)
|
||||
{
|
||||
XNamespace xmlns = XNamespace.Get(attributes[i].XmlNamespace);
|
||||
|
||||
if (!xmlnsMappings.TryGetValue(xmlns, out mapping))
|
||||
{
|
||||
mapping.ImportReferences = new HashSet<VisualBasicImportReference>();
|
||||
xmlnsMappings[xmlns] = mapping;
|
||||
}
|
||||
|
||||
VisualBasicImportReference newImportReference = new VisualBasicImportReference
|
||||
{
|
||||
Assembly = assemblyName,
|
||||
Import = attributes[i].ClrNamespace,
|
||||
Xmlns = xmlns,
|
||||
};
|
||||
// early binding the assembly
|
||||
// this leads to the short-cut, skipping the normal assembly resolution routine
|
||||
newImportReference.EarlyBoundAssembly = assembly;
|
||||
mapping.ImportReferences.Add(newImportReference);
|
||||
}
|
||||
}
|
||||
|
||||
class XNamespaceEqualityComparer : IEqualityComparer<XNamespace>
|
||||
{
|
||||
public XNamespaceEqualityComparer()
|
||||
{ }
|
||||
|
||||
bool IEqualityComparer<XNamespace>.Equals(XNamespace x, XNamespace y)
|
||||
{
|
||||
return x == y;
|
||||
}
|
||||
|
||||
int IEqualityComparer<XNamespace>.GetHashCode(XNamespace x)
|
||||
{
|
||||
return x.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Struct used to cache XML Namespace mappings.
|
||||
/// </summary>
|
||||
struct XmlnsMapping
|
||||
{
|
||||
public HashSet<VisualBasicImportReference> ImportReferences;
|
||||
|
||||
public bool IsEmpty
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.ImportReferences == null || this.ImportReferences.Count == 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Fx.Tag.SecurityNote(Critical = "Critical because we are accessing a XmlnsMapping that is stored in the XmlnsMappings cache, which is SecurityCritical.",
|
||||
Safe = "Safe because we are wrapping the XmlnsMapping and not allowing unsafe code to modify it.")]
|
||||
[SecuritySafeCritical]
|
||||
struct ReadOnlyXmlnsMapping
|
||||
{
|
||||
XmlnsMapping wrappedMapping;
|
||||
|
||||
internal ReadOnlyXmlnsMapping(XmlnsMapping mapping)
|
||||
{
|
||||
this.wrappedMapping = mapping;
|
||||
}
|
||||
|
||||
internal bool IsEmpty
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.wrappedMapping.IsEmpty;
|
||||
}
|
||||
}
|
||||
|
||||
internal IEnumerable<ReadOnlyVisualBasicImportReference> ImportReferences
|
||||
{
|
||||
get
|
||||
{
|
||||
foreach (VisualBasicImportReference wrappedReference in this.wrappedMapping.ImportReferences)
|
||||
{
|
||||
yield return new ReadOnlyVisualBasicImportReference(wrappedReference);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Fx.Tag.SecurityNote(Critical = "Critical because we are accessing a VisualBasicImportReference that is stored in the XmlnsMappings cache, which is SecurityCritical.",
|
||||
Safe = "Safe because we are wrapping the VisualBasicImportReference and not allowing unsafe code to modify it.")]
|
||||
[SecuritySafeCritical]
|
||||
struct ReadOnlyVisualBasicImportReference
|
||||
{
|
||||
readonly VisualBasicImportReference wrappedReference;
|
||||
|
||||
internal ReadOnlyVisualBasicImportReference(VisualBasicImportReference referenceToWrap)
|
||||
{
|
||||
this.wrappedReference = referenceToWrap;
|
||||
}
|
||||
|
||||
// If this is ever needed, uncomment this. It is commented out now to avoid FxCop violation because it is not called.
|
||||
//internal string Assembly
|
||||
//{
|
||||
// get
|
||||
// {
|
||||
// return this.wrappedReference.Assembly;
|
||||
// }
|
||||
//}
|
||||
|
||||
// If this is ever needed, uncomment this. It is commented out now to avoid FxCop violation because it is not called.
|
||||
//internal string Import
|
||||
//{
|
||||
// get
|
||||
// {
|
||||
// return this.wrappedReference.Import;
|
||||
// }
|
||||
//}
|
||||
|
||||
internal Assembly EarlyBoundAssembly
|
||||
{
|
||||
get { return this.wrappedReference.EarlyBoundAssembly; }
|
||||
}
|
||||
|
||||
internal VisualBasicImportReference Clone()
|
||||
{
|
||||
return this.wrappedReference.Clone();
|
||||
}
|
||||
|
||||
// this code is borrowed from XamlSchemaContext
|
||||
internal bool AssemblySatisfiesReference(AssemblyName assemblyName)
|
||||
{
|
||||
if (this.wrappedReference.AssemblyName.Name != assemblyName.Name)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (this.wrappedReference.AssemblyName.Version != null && !this.wrappedReference.AssemblyName.Version.Equals(assemblyName.Version))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (this.wrappedReference.AssemblyName.CultureInfo != null && !this.wrappedReference.AssemblyName.CultureInfo.Equals(assemblyName.CultureInfo))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
byte[] requiredToken = this.wrappedReference.AssemblyName.GetPublicKeyToken();
|
||||
if (requiredToken != null)
|
||||
{
|
||||
byte[] actualToken = assemblyName.GetPublicKeyToken();
|
||||
if (!AssemblyNameEqualityComparer.IsSameKeyToken(requiredToken, actualToken))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return this.wrappedReference.GetHashCode();
|
||||
}
|
||||
|
||||
// If this is ever needed, uncomment this. It is commented out now to avoid FxCop violation because it is not called.
|
||||
//public bool Equals(VisualBasicImportReference other)
|
||||
//{
|
||||
// return this.wrappedReference.Equals(other);
|
||||
//}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,79 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
namespace Microsoft.VisualBasic.Activities.XamlIntegration
|
||||
{
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Runtime;
|
||||
using System.Globalization;
|
||||
using System.Activities;
|
||||
|
||||
// this class is necessary in order for our value serializer to get called by XAML,
|
||||
// even though the functionality is a no-op
|
||||
public sealed class VisualBasicSettingsConverter : TypeConverter
|
||||
{
|
||||
public VisualBasicSettingsConverter()
|
||||
: base()
|
||||
{
|
||||
}
|
||||
|
||||
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
|
||||
{
|
||||
if (sourceType == TypeHelper.StringType)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return base.CanConvertFrom(context, sourceType);
|
||||
}
|
||||
|
||||
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
|
||||
{
|
||||
if (destinationType == TypeHelper.StringType)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return base.CanConvertTo(context, destinationType);
|
||||
}
|
||||
|
||||
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
|
||||
{
|
||||
string sourceString = value as string;
|
||||
if (sourceString != null)
|
||||
{
|
||||
if (sourceString.Equals(VisualBasicSettingsValueSerializer.ImplementationVisualBasicSettingsValue))
|
||||
{
|
||||
// this is the VBSettings for the internal implementation
|
||||
// suppress its Xaml serialization
|
||||
VisualBasicSettings settings = CollectXmlNamespacesAndAssemblies(context);
|
||||
if (settings != null)
|
||||
{
|
||||
settings.SuppressXamlSerialization = true;
|
||||
}
|
||||
return settings;
|
||||
}
|
||||
|
||||
if (!(sourceString.Equals(String.Empty) || sourceString.Equals(VisualBasicSettingsValueSerializer.VisualBasicSettingsValue)))
|
||||
{
|
||||
throw FxTrace.Exception.AsError(new InvalidOperationException(SR.InvalidVisualBasicSettingsValue));
|
||||
}
|
||||
|
||||
return CollectXmlNamespacesAndAssemblies(context);
|
||||
}
|
||||
return base.ConvertFrom(context, culture, value);
|
||||
}
|
||||
|
||||
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
|
||||
{
|
||||
return base.ConvertTo(context, culture, value, destinationType);
|
||||
}
|
||||
|
||||
VisualBasicSettings CollectXmlNamespacesAndAssemblies(ITypeDescriptorContext context)
|
||||
{
|
||||
return VisualBasicExpressionConverter.CollectXmlNamespacesAndAssemblies(context);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,48 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
namespace Microsoft.VisualBasic.Activities.XamlIntegration
|
||||
{
|
||||
using System.Collections.Generic;
|
||||
using System.Windows.Markup;
|
||||
using System.Xaml;
|
||||
|
||||
// this value serializer always returns false for CanConvertToString, but
|
||||
// needs to add namespace declarations to the context
|
||||
//
|
||||
public sealed class VisualBasicSettingsValueSerializer : ValueSerializer
|
||||
{
|
||||
internal const string VisualBasicSettingsValue = "Assembly references and imported namespaces serialized as XML namespaces";
|
||||
internal const string ImplementationVisualBasicSettingsValue = "Assembly references and imported namespaces for internal implementation";
|
||||
|
||||
public VisualBasicSettingsValueSerializer()
|
||||
: base()
|
||||
{
|
||||
}
|
||||
|
||||
public override bool CanConvertToString(object value, IValueSerializerContext context)
|
||||
{
|
||||
VisualBasicSettings settings = value as VisualBasicSettings;
|
||||
|
||||
// promote settings to xmlns declarations
|
||||
if (settings != null)
|
||||
{
|
||||
settings.GenerateXamlReferences(context);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override string ConvertToString(object value, IValueSerializerContext context)
|
||||
{
|
||||
VisualBasicSettings settings = value as VisualBasicSettings;
|
||||
|
||||
if (settings != null && settings.SuppressXamlSerialization)
|
||||
{
|
||||
return ImplementationVisualBasicSettingsValue;
|
||||
}
|
||||
return VisualBasicSettingsValue;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,10 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Runtime;
|
||||
|
||||
// When a resource from SR.resx is only used in an expression, FxCop may issue an AvoidUncalledPrivateCode error
|
||||
[module: SuppressMessage(FxCop.Category.Performance, FxCop.Rule.AvoidUncalledPrivateCode, Scope = "member", Target = "System.Activities.SR.SwitchCaseTypeMismatch(System.Object,System.Object):System.String")]
|
||||
[module: SuppressMessage(FxCop.Category.Performance, FxCop.Rule.AvoidUncalledPrivateCode, Scope = "member", Target = "System.Activities.EtwTrackingParticipantTrackRecords.get_ResourceManager():System.Resources.ResourceManager")]
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,370 @@
|
||||
//----------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//----------------------------------------------------------------
|
||||
|
||||
namespace System.Activities
|
||||
{
|
||||
using System.Activities.Debugger;
|
||||
using System.Activities.Validation;
|
||||
using System.Activities.XamlIntegration;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using System.Runtime;
|
||||
using System.Windows.Markup;
|
||||
using System.Xaml;
|
||||
|
||||
[ContentProperty("Implementation")]
|
||||
public sealed class ActivityBuilder : IDebuggableWorkflowTree
|
||||
{
|
||||
// define attached properties that will identify PropertyReferenceExtension-based
|
||||
// object properties
|
||||
static AttachableMemberIdentifier propertyReferencePropertyID = new AttachableMemberIdentifier(typeof(ActivityBuilder), "PropertyReference");
|
||||
static AttachableMemberIdentifier propertyReferencesPropertyID = new AttachableMemberIdentifier(typeof(ActivityBuilder), "PropertyReferences");
|
||||
|
||||
KeyedCollection<string, DynamicActivityProperty> properties;
|
||||
Collection<Constraint> constraints;
|
||||
Collection<Attribute> attributes;
|
||||
|
||||
public ActivityBuilder()
|
||||
{
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[DependsOn("Name")]
|
||||
public Collection<Attribute> Attributes
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.attributes == null)
|
||||
{
|
||||
this.attributes = new Collection<Attribute>();
|
||||
}
|
||||
return this.attributes;
|
||||
}
|
||||
}
|
||||
|
||||
[Browsable(false)]
|
||||
[DependsOn("Attributes")]
|
||||
public KeyedCollection<string, DynamicActivityProperty> Properties
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.properties == null)
|
||||
{
|
||||
this.properties = new ActivityPropertyCollection();
|
||||
}
|
||||
return this.properties;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[DependsOn("Properties")]
|
||||
[Browsable(false)]
|
||||
public Collection<Constraint> Constraints
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.constraints == null)
|
||||
{
|
||||
this.constraints = new Collection<Constraint>();
|
||||
}
|
||||
return this.constraints;
|
||||
}
|
||||
}
|
||||
|
||||
[TypeConverter(typeof(ImplementationVersionConverter))]
|
||||
[DefaultValue(null)]
|
||||
[DependsOn("Name")]
|
||||
public Version ImplementationVersion
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[DefaultValue(null)]
|
||||
[Browsable(false)]
|
||||
[DependsOn("Constraints")]
|
||||
public Activity Implementation
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
// Back-compat workaround: PropertyReference shipped in 4.0. PropertyReferences is new in 4.5.
|
||||
//
|
||||
// Requirements:
|
||||
// - Runtime compat: Get/SetPropertyReference needs to continue to work, both when set programatically
|
||||
// and when loading a doc which contains only one PropertyReference on an object.
|
||||
// - Serialization compat: If only one PropertyReference was set, we shouldn't serialize PropertyReferences.
|
||||
// (Only affects when ActivityBuilder is used directly with XamlServices, since ActivityXamlServices
|
||||
// will convert ActivityPropertyReference to PropertyReferenceExtension.)
|
||||
// - Usability: To avoid the designer needing to support two separate access methods, we want
|
||||
// the value from SetPropertyReference to also appear in the PropertyReferences collection.
|
||||
|
||||
// <ActivityBuilder.PropertyReference>activity property name</ActivityBuilder.PropertyReference>
|
||||
public static ActivityPropertyReference GetPropertyReference(object target)
|
||||
{
|
||||
return GetPropertyReferenceCollection(target).SingleItem;
|
||||
}
|
||||
|
||||
// <ActivityBuilder.PropertyReference>activity property name</ActivityBuilder.PropertyReference>
|
||||
public static void SetPropertyReference(object target, ActivityPropertyReference value)
|
||||
{
|
||||
GetPropertyReferenceCollection(target).SingleItem = value;
|
||||
}
|
||||
|
||||
public static IList<ActivityPropertyReference> GetPropertyReferences(object target)
|
||||
{
|
||||
return GetPropertyReferenceCollection(target);
|
||||
}
|
||||
|
||||
public static bool ShouldSerializePropertyReference(object target)
|
||||
{
|
||||
PropertyReferenceCollection propertyReferences = GetPropertyReferenceCollection(target);
|
||||
return propertyReferences.Count == 1 && propertyReferences.SingleItem != null;
|
||||
}
|
||||
|
||||
public static bool ShouldSerializePropertyReferences(object target)
|
||||
{
|
||||
PropertyReferenceCollection propertyReferences = GetPropertyReferenceCollection(target);
|
||||
return propertyReferences.Count > 1 || propertyReferences.SingleItem == null;
|
||||
}
|
||||
|
||||
internal static bool HasPropertyReferences(object target)
|
||||
{
|
||||
PropertyReferenceCollection propertyReferences;
|
||||
if (AttachablePropertyServices.TryGetProperty(target, propertyReferencesPropertyID, out propertyReferences))
|
||||
{
|
||||
return propertyReferences.Count > 0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static PropertyReferenceCollection GetPropertyReferenceCollection(object target)
|
||||
{
|
||||
PropertyReferenceCollection propertyReferences;
|
||||
if (!AttachablePropertyServices.TryGetProperty(target, propertyReferencesPropertyID, out propertyReferences))
|
||||
{
|
||||
propertyReferences = new PropertyReferenceCollection(target);
|
||||
AttachablePropertyServices.SetProperty(target, propertyReferencesPropertyID, propertyReferences);
|
||||
}
|
||||
return propertyReferences;
|
||||
|
||||
}
|
||||
|
||||
Activity IDebuggableWorkflowTree.GetWorkflowRoot()
|
||||
{
|
||||
return this.Implementation;
|
||||
}
|
||||
|
||||
internal static KeyedCollection<string, DynamicActivityProperty> CreateActivityPropertyCollection()
|
||||
{
|
||||
return new ActivityPropertyCollection();
|
||||
}
|
||||
|
||||
class ActivityPropertyCollection : KeyedCollection<string, DynamicActivityProperty>
|
||||
{
|
||||
protected override string GetKeyForItem(DynamicActivityProperty item)
|
||||
{
|
||||
return item.Name;
|
||||
}
|
||||
}
|
||||
|
||||
// See back-compat requirements in comment above. Design is:
|
||||
// - First value added to collection when it is empty becomes the single PropertyReference value
|
||||
// - If the single value is removed, then PropertyReference AP is removed
|
||||
// - If PropertyReference AP is set to null, we remove the single value.
|
||||
// - If PropertyReference is set to non-null, we replace the existing single value if there
|
||||
// is one, or else add the new value to the collection.
|
||||
class PropertyReferenceCollection : Collection<ActivityPropertyReference>
|
||||
{
|
||||
WeakReference targetObject;
|
||||
int singleItemIndex = -1;
|
||||
|
||||
public PropertyReferenceCollection(object target)
|
||||
{
|
||||
this.targetObject = new WeakReference(target);
|
||||
}
|
||||
|
||||
public ActivityPropertyReference SingleItem
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.singleItemIndex >= 0 ? this[this.singleItemIndex] : null;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (this.singleItemIndex >= 0)
|
||||
{
|
||||
if (value != null)
|
||||
{
|
||||
SetItem(this.singleItemIndex, value);
|
||||
}
|
||||
else
|
||||
{
|
||||
RemoveItem(this.singleItemIndex);
|
||||
}
|
||||
}
|
||||
else if (value != null)
|
||||
{
|
||||
Add(value);
|
||||
if (Count > 1)
|
||||
{
|
||||
this.singleItemIndex = Count - 1;
|
||||
UpdateAttachedProperty();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void ClearItems()
|
||||
{
|
||||
this.singleItemIndex = -1;
|
||||
UpdateAttachedProperty();
|
||||
}
|
||||
|
||||
protected override void InsertItem(int index, ActivityPropertyReference item)
|
||||
{
|
||||
base.InsertItem(index, item);
|
||||
if (index <= this.singleItemIndex)
|
||||
{
|
||||
this.singleItemIndex++;
|
||||
}
|
||||
else if (Count == 1)
|
||||
{
|
||||
Fx.Assert(this.singleItemIndex < 0, "How did we have an index if we were empty?");
|
||||
this.singleItemIndex = 0;
|
||||
UpdateAttachedProperty();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void RemoveItem(int index)
|
||||
{
|
||||
base.RemoveItem(index);
|
||||
if (index < this.singleItemIndex)
|
||||
{
|
||||
this.singleItemIndex--;
|
||||
}
|
||||
else if (index == this.singleItemIndex)
|
||||
{
|
||||
this.singleItemIndex = -1;
|
||||
UpdateAttachedProperty();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void SetItem(int index, ActivityPropertyReference item)
|
||||
{
|
||||
base.SetItem(index, item);
|
||||
if (index == this.singleItemIndex)
|
||||
{
|
||||
UpdateAttachedProperty();
|
||||
}
|
||||
}
|
||||
|
||||
void UpdateAttachedProperty()
|
||||
{
|
||||
object target = this.targetObject.Target;
|
||||
if (target != null)
|
||||
{
|
||||
if (this.singleItemIndex >= 0)
|
||||
{
|
||||
AttachablePropertyServices.SetProperty(target, propertyReferencePropertyID, this[this.singleItemIndex]);
|
||||
}
|
||||
else
|
||||
{
|
||||
AttachablePropertyServices.RemoveProperty(target, propertyReferencePropertyID);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[ContentProperty("Implementation")]
|
||||
public sealed class ActivityBuilder<TResult> : IDebuggableWorkflowTree
|
||||
{
|
||||
KeyedCollection<string, DynamicActivityProperty> properties;
|
||||
Collection<Constraint> constraints;
|
||||
Collection<Attribute> attributes;
|
||||
|
||||
public ActivityBuilder()
|
||||
{
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[DependsOn("Name")]
|
||||
public Collection<Attribute> Attributes
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.attributes == null)
|
||||
{
|
||||
this.attributes = new Collection<Attribute>();
|
||||
}
|
||||
return this.attributes;
|
||||
}
|
||||
}
|
||||
|
||||
[Browsable(false)]
|
||||
[DependsOn("Attributes")]
|
||||
public KeyedCollection<string, DynamicActivityProperty> Properties
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.properties == null)
|
||||
{
|
||||
this.properties = ActivityBuilder.CreateActivityPropertyCollection();
|
||||
}
|
||||
return this.properties;
|
||||
}
|
||||
}
|
||||
|
||||
[DependsOn("Properties")]
|
||||
[Browsable(false)]
|
||||
public Collection<Constraint> Constraints
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.constraints == null)
|
||||
{
|
||||
this.constraints = new Collection<Constraint>();
|
||||
}
|
||||
return this.constraints;
|
||||
}
|
||||
}
|
||||
|
||||
[TypeConverter(typeof(ImplementationVersionConverter))]
|
||||
[DefaultValue(null)]
|
||||
[DependsOn("Name")]
|
||||
public Version ImplementationVersion
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[DefaultValue(null)]
|
||||
[Browsable(false)]
|
||||
[DependsOn("Constraints")]
|
||||
public Activity Implementation
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
Activity IDebuggableWorkflowTree.GetWorkflowRoot()
|
||||
{
|
||||
return this.Implementation;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,13 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
namespace System.Activities
|
||||
{
|
||||
enum ActivityCollectionType
|
||||
{
|
||||
Public,
|
||||
Imports,
|
||||
Implementation
|
||||
}
|
||||
}
|
@@ -0,0 +1,450 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
namespace System.Activities
|
||||
{
|
||||
using System;
|
||||
using System.Activities.Runtime;
|
||||
using System.Activities.Tracking;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Globalization;
|
||||
using System.Runtime;
|
||||
|
||||
[Fx.Tag.XamlVisible(false)]
|
||||
public class ActivityContext
|
||||
{
|
||||
ActivityInstance instance;
|
||||
ActivityExecutor executor;
|
||||
bool isDisposed;
|
||||
long instanceId;
|
||||
|
||||
// Used by subclasses that are pooled.
|
||||
internal ActivityContext()
|
||||
{
|
||||
}
|
||||
|
||||
// these can only be created by the WF Runtime
|
||||
internal ActivityContext(ActivityInstance instance, ActivityExecutor executor)
|
||||
{
|
||||
Fx.Assert(instance != null, "valid activity instance is required");
|
||||
|
||||
this.instance = instance;
|
||||
this.executor = executor;
|
||||
this.Activity = this.instance.Activity;
|
||||
this.instanceId = instance.InternalId;
|
||||
}
|
||||
|
||||
internal LocationEnvironment Environment
|
||||
{
|
||||
get
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
return this.instance.Environment;
|
||||
}
|
||||
}
|
||||
|
||||
internal bool AllowChainedEnvironmentAccess
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
internal Activity Activity
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
internal ActivityInstance CurrentInstance
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.instance;
|
||||
}
|
||||
}
|
||||
|
||||
internal ActivityExecutor CurrentExecutor
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.executor;
|
||||
}
|
||||
}
|
||||
|
||||
public string ActivityInstanceId
|
||||
{
|
||||
get
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
return this.instanceId.ToString(CultureInfo.InvariantCulture);
|
||||
}
|
||||
}
|
||||
|
||||
public Guid WorkflowInstanceId
|
||||
{
|
||||
get
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
return this.executor.WorkflowInstanceId;
|
||||
}
|
||||
}
|
||||
|
||||
public WorkflowDataContext DataContext
|
||||
{
|
||||
get
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
|
||||
// Argument expressions don't have visbility into public variables at the same scope.
|
||||
// However fast-path expressions use the parent's ActivityInstance instead of
|
||||
// creating their own, so we need to give them a DataContext without variables
|
||||
bool includeLocalVariables = !this.instance.IsResolvingArguments;
|
||||
|
||||
if (this.instance.DataContext == null ||
|
||||
this.instance.DataContext.IncludesLocalVariables != includeLocalVariables)
|
||||
{
|
||||
this.instance.DataContext
|
||||
= new WorkflowDataContext(this.executor, this.instance, includeLocalVariables);
|
||||
}
|
||||
|
||||
return this.instance.DataContext;
|
||||
}
|
||||
}
|
||||
|
||||
internal bool IsDisposed
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.isDisposed;
|
||||
}
|
||||
}
|
||||
|
||||
public T GetExtension<T>()
|
||||
where T : class
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
return this.executor.GetExtension<T>();
|
||||
}
|
||||
|
||||
internal Location GetIgnorableResultLocation(RuntimeArgument resultArgument)
|
||||
{
|
||||
return this.executor.GetIgnorableResultLocation(resultArgument);
|
||||
}
|
||||
|
||||
internal void Reinitialize(ActivityInstance instance, ActivityExecutor executor)
|
||||
{
|
||||
Reinitialize(instance, executor, instance.Activity, instance.InternalId);
|
||||
}
|
||||
|
||||
internal void Reinitialize(ActivityInstance instance, ActivityExecutor executor, Activity activity, long instanceId)
|
||||
{
|
||||
this.isDisposed = false;
|
||||
this.instance = instance;
|
||||
this.executor = executor;
|
||||
this.Activity = activity;
|
||||
this.instanceId = instanceId;
|
||||
}
|
||||
|
||||
// extra insurance against misuse (if someone stashes away the execution context to use later)
|
||||
internal void Dispose()
|
||||
{
|
||||
this.isDisposed = true;
|
||||
this.instance = null;
|
||||
this.executor = null;
|
||||
this.Activity = null;
|
||||
this.instanceId = 0;
|
||||
}
|
||||
|
||||
internal void DisposeDataContext()
|
||||
{
|
||||
if (this.instance.DataContext != null)
|
||||
{
|
||||
this.instance.DataContext.DisposeEnvironment();
|
||||
this.instance.DataContext = null;
|
||||
}
|
||||
}
|
||||
|
||||
// Soft-Link: This method is referenced through reflection by
|
||||
// ExpressionUtilities.TryRewriteLambdaExpression. Update that
|
||||
// file if the signature changes.
|
||||
public Location<T> GetLocation<T>(LocationReference locationReference)
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
|
||||
if (locationReference == null)
|
||||
{
|
||||
throw FxTrace.Exception.ArgumentNull("locationReference");
|
||||
}
|
||||
|
||||
Location location = locationReference.GetLocation(this);
|
||||
|
||||
Location<T> typedLocation = location as Location<T>;
|
||||
|
||||
if (typedLocation != null)
|
||||
{
|
||||
return typedLocation;
|
||||
}
|
||||
else
|
||||
{
|
||||
Fx.Assert(location != null, "The contract of LocationReference is that GetLocation never returns null.");
|
||||
|
||||
if (locationReference.Type == typeof(T))
|
||||
{
|
||||
return new TypedLocationWrapper<T>(location);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw FxTrace.Exception.AsError(new InvalidOperationException(SR.LocationTypeMismatch(locationReference.Name, typeof(T), locationReference.Type)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Soft-Link: This method is referenced through reflection by
|
||||
// ExpressionUtilities.TryRewriteLambdaExpression. Update that
|
||||
// file if the signature changes.
|
||||
public T GetValue<T>(LocationReference locationReference)
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
|
||||
if (locationReference == null)
|
||||
{
|
||||
throw FxTrace.Exception.ArgumentNull("locationReference");
|
||||
}
|
||||
|
||||
return GetValueCore<T>(locationReference);
|
||||
}
|
||||
|
||||
internal T GetValueCore<T>(LocationReference locationReference)
|
||||
{
|
||||
Location location = locationReference.GetLocationForRead(this);
|
||||
|
||||
Location<T> typedLocation = location as Location<T>;
|
||||
|
||||
if (typedLocation != null)
|
||||
{
|
||||
// If we hit this path we can avoid boxing value types
|
||||
return typedLocation.Value;
|
||||
}
|
||||
else
|
||||
{
|
||||
Fx.Assert(location != null, "The contract of LocationReference is that GetLocation never returns null.");
|
||||
|
||||
return TypeHelper.Convert<T>(location.Value);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetValue<T>(LocationReference locationReference, T value)
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
|
||||
if (locationReference == null)
|
||||
{
|
||||
throw FxTrace.Exception.ArgumentNull("locationReference");
|
||||
}
|
||||
|
||||
SetValueCore<T>(locationReference, value);
|
||||
}
|
||||
|
||||
internal void SetValueCore<T>(LocationReference locationReference, T value)
|
||||
{
|
||||
Location location = locationReference.GetLocationForWrite(this);
|
||||
|
||||
Location<T> typedLocation = location as Location<T>;
|
||||
|
||||
if (typedLocation != null)
|
||||
{
|
||||
// If we hit this path we can avoid boxing value types
|
||||
typedLocation.Value = value;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
if (!TypeHelper.AreTypesCompatible(value, locationReference.Type))
|
||||
{
|
||||
throw FxTrace.Exception.AsError(new InvalidOperationException(SR.CannotSetValueToLocation(value != null ? value.GetType() : typeof(T), locationReference.Name, locationReference.Type)));
|
||||
}
|
||||
|
||||
location.Value = value;
|
||||
}
|
||||
}
|
||||
|
||||
// Soft-Link: This method is referenced through reflection by
|
||||
// ExpressionUtilities.TryRewriteLambdaExpression. Update that
|
||||
// file if the signature changes.
|
||||
[SuppressMessage(FxCop.Category.Design, FxCop.Rule.ConsiderPassingBaseTypesAsParameters,
|
||||
Justification = "Generic needed for type inference")]
|
||||
public T GetValue<T>(OutArgument<T> argument)
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
|
||||
if (argument == null)
|
||||
{
|
||||
throw FxTrace.Exception.ArgumentNull("argument");
|
||||
}
|
||||
|
||||
argument.ThrowIfNotInTree();
|
||||
|
||||
return GetValueCore<T>(argument.RuntimeArgument);
|
||||
}
|
||||
|
||||
// Soft-Link: This method is referenced through reflection by
|
||||
// ExpressionUtilities.TryRewriteLambdaExpression. Update that
|
||||
// file if the signature changes.
|
||||
[SuppressMessage(FxCop.Category.Design, FxCop.Rule.ConsiderPassingBaseTypesAsParameters,
|
||||
Justification = "Generic needed for type inference")]
|
||||
public T GetValue<T>(InOutArgument<T> argument)
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
|
||||
if (argument == null)
|
||||
{
|
||||
throw FxTrace.Exception.ArgumentNull("argument");
|
||||
}
|
||||
|
||||
argument.ThrowIfNotInTree();
|
||||
|
||||
return GetValueCore<T>(argument.RuntimeArgument);
|
||||
}
|
||||
|
||||
// Soft-Link: This method is referenced through reflection by
|
||||
// ExpressionUtilities.TryRewriteLambdaExpression. Update that
|
||||
// file if the signature changes.
|
||||
[SuppressMessage(FxCop.Category.Design, FxCop.Rule.ConsiderPassingBaseTypesAsParameters,
|
||||
Justification = "Generic needed for type inference")]
|
||||
public T GetValue<T>(InArgument<T> argument)
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
|
||||
if (argument == null)
|
||||
{
|
||||
throw FxTrace.Exception.ArgumentNull("argument");
|
||||
}
|
||||
|
||||
argument.ThrowIfNotInTree();
|
||||
|
||||
return GetValueCore<T>(argument.RuntimeArgument);
|
||||
}
|
||||
|
||||
// Soft-Link: This method is referenced through reflection by
|
||||
// ExpressionUtilities.TryRewriteLambdaExpression. Update that
|
||||
// file if the signature changes.
|
||||
public object GetValue(Argument argument)
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
|
||||
if (argument == null)
|
||||
{
|
||||
throw FxTrace.Exception.ArgumentNull("argument");
|
||||
}
|
||||
|
||||
argument.ThrowIfNotInTree();
|
||||
|
||||
return GetValueCore<object>(argument.RuntimeArgument);
|
||||
}
|
||||
|
||||
// Soft-Link: This method is referenced through reflection by
|
||||
// ExpressionUtilities.TryRewriteLambdaExpression. Update that
|
||||
// file if the signature changes.
|
||||
[SuppressMessage(FxCop.Category.Design, FxCop.Rule.ConsiderPassingBaseTypesAsParameters,
|
||||
Justification = "We explicitly provide a RuntimeArgument overload to avoid requiring the object type parameter.")]
|
||||
public object GetValue(RuntimeArgument runtimeArgument)
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
|
||||
if (runtimeArgument == null)
|
||||
{
|
||||
throw FxTrace.Exception.ArgumentNull("runtimeArgument");
|
||||
}
|
||||
|
||||
return GetValueCore<object>(runtimeArgument);
|
||||
}
|
||||
|
||||
[SuppressMessage(FxCop.Category.Design, FxCop.Rule.ConsiderPassingBaseTypesAsParameters,
|
||||
Justification = "Generic needed for type inference")]
|
||||
public void SetValue<T>(OutArgument<T> argument, T value)
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
|
||||
if (argument == null)
|
||||
{
|
||||
// We want to shortcut if the argument is null
|
||||
return;
|
||||
}
|
||||
|
||||
argument.ThrowIfNotInTree();
|
||||
|
||||
SetValueCore(argument.RuntimeArgument, value);
|
||||
}
|
||||
|
||||
[SuppressMessage(FxCop.Category.Design, FxCop.Rule.ConsiderPassingBaseTypesAsParameters,
|
||||
Justification = "Generic needed for type inference")]
|
||||
public void SetValue<T>(InOutArgument<T> argument, T value)
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
|
||||
if (argument == null)
|
||||
{
|
||||
// We want to shortcut if the argument is null
|
||||
return;
|
||||
}
|
||||
|
||||
argument.ThrowIfNotInTree();
|
||||
|
||||
SetValueCore(argument.RuntimeArgument, value);
|
||||
}
|
||||
|
||||
[SuppressMessage(FxCop.Category.Design, FxCop.Rule.ConsiderPassingBaseTypesAsParameters,
|
||||
Justification = "Generic needed for type inference")]
|
||||
public void SetValue<T>(InArgument<T> argument, T value)
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
|
||||
if (argument == null)
|
||||
{
|
||||
// We want to shortcut if the argument is null
|
||||
return;
|
||||
}
|
||||
|
||||
argument.ThrowIfNotInTree();
|
||||
|
||||
SetValueCore(argument.RuntimeArgument, value);
|
||||
}
|
||||
|
||||
public void SetValue(Argument argument, object value)
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
|
||||
if (argument == null)
|
||||
{
|
||||
throw FxTrace.Exception.ArgumentNull("argument");
|
||||
}
|
||||
|
||||
argument.ThrowIfNotInTree();
|
||||
|
||||
SetValueCore(argument.RuntimeArgument, value);
|
||||
}
|
||||
|
||||
internal void TrackCore(CustomTrackingRecord record)
|
||||
{
|
||||
Fx.Assert(!this.isDisposed, "not usable if disposed");
|
||||
Fx.Assert(record != null, "expect non-null record");
|
||||
|
||||
if (this.executor.ShouldTrack)
|
||||
{
|
||||
record.Activity = new ActivityInfo(this.instance);
|
||||
record.InstanceId = this.WorkflowInstanceId;
|
||||
this.executor.AddTrackingRecord(record);
|
||||
}
|
||||
}
|
||||
|
||||
internal void ThrowIfDisposed()
|
||||
{
|
||||
if (this.isDisposed)
|
||||
{
|
||||
throw FxTrace.Exception.AsError(
|
||||
new ObjectDisposedException(this.GetType().FullName, SR.AECDisposed));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user