Imported Upstream version 4.8.0.459

Former-commit-id: 2a5b9df2014f72665850c7f885e7aed54704a53a
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2017-01-19 14:22:10 +00:00
parent a355c1b831
commit e5cd25ff4f
725 changed files with 1215 additions and 107650 deletions

View File

@@ -1,58 +0,0 @@
//----------------------------------------------------------------
// <copyright company="Microsoft Corporation">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//----------------------------------------------------------------
namespace Microsoft.Activities.Presentation
{
using System.Activities.Expressions;
using System.Activities.Presentation.Expressions;
using System.Activities.Presentation.Model;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.Versioning;
using Microsoft.VisualBasic.Activities;
internal static class ExpressionSettingHelper
{
internal static readonly string VBExpressionLanguageName = (new VisualBasicValue<string>() as ITextExpression).Language;
[SuppressMessage("Reliability", "Reliability101", Justification = "We can't use Fx.Assert here since this is not a framework assembly.")]
internal static string GetRootEditorSetting(ModelTreeManager modelTreeManager, FrameworkName targetFramework)
{
Debug.Assert(modelTreeManager != null, "modelTreeManager is null.");
Debug.Assert(targetFramework != null, "targetFramework is null.");
string globalEditorSetting = null;
if (Is45OrHigher(targetFramework))
{
if (modelTreeManager != null)
{
ModelItem rootItem = modelTreeManager.Root;
if (rootItem != null)
{
object root = rootItem.GetCurrentValue();
globalEditorSetting = ExpressionActivityEditor.GetExpressionActivityEditor(root);
if (string.IsNullOrEmpty(globalEditorSetting))
{
globalEditorSetting = VBExpressionLanguageName;
}
}
}
}
else
{
// When the target framework is less than 4.5, the root setting is ignored and always return VB
globalEditorSetting = VBExpressionLanguageName;
}
return globalEditorSetting;
}
private static bool Is45OrHigher(FrameworkName frameworkName)
{
return frameworkName.Version.Major > 4 || (frameworkName.Version.Major == 4 && frameworkName.Version.Minor >= 5);
}
}
}

View File

@@ -1,21 +0,0 @@
//----------------------------------------------------------------
// <copyright company="Microsoft Corporation">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//----------------------------------------------------------------
namespace Microsoft.Activities.Presentation
{
using System;
using System.Runtime.Versioning;
internal static class FrameworkNameConstants
{
public static readonly FrameworkName NetFramework40 = new FrameworkName(NetFramework, new Version(4, 0));
public static readonly FrameworkName NetFramework45 = new FrameworkName(NetFramework, new Version(4, 5));
internal const string NetFramework = ".NETFramework";
internal const string NetFrameworkWithSpace = ".NET Framework";
internal const string ClientProfileName = "Client";
}
}

View File

@@ -1,46 +0,0 @@
// <copyright>
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
namespace Microsoft.Activities.Presentation
{
using System.Runtime.Versioning;
internal static class FrameworkNameExtensions
{
public static bool Is45OrHigher(this FrameworkName frameworkName)
{
return frameworkName.Version.Major > 4 || (frameworkName.Version.Major == 4 && frameworkName.Version.Minor >= 5);
}
public static bool IsLessThan45(this FrameworkName frameworkName)
{
return frameworkName.Version.Major < 4 || (frameworkName.Version.Major == 4 && frameworkName.Version.Minor < 5);
}
public static bool IsLessThan40(this FrameworkName frameworkName)
{
return frameworkName.Version.Major < 4;
}
public static bool IsProfileSupported(this FrameworkName frameworkName)
{
if (frameworkName.Profile == string.Empty)
{
return true;
}
if (frameworkName.Profile == FrameworkNameConstants.ClientProfileName)
{
return true;
}
return false;
}
public static bool IsFullProfile(this FrameworkName frameworkName)
{
return string.IsNullOrEmpty(frameworkName.Profile);
}
}
}

View File

@@ -1,106 +0,0 @@
//----------------------------------------------------------------
// <copyright company="Microsoft Corporation">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//----------------------------------------------------------------
namespace Microsoft.Activities.Presentation
{
using System;
using System.Globalization;
using System.Text;
using System.Text.RegularExpressions;
internal static class TypeNameHelper
{
// note: does not work for nested type when fullName is true
// eg. Namespace.DeclaringType.NestedType<T> will be displayed
// as Namespace.DeclaringType+NestedType<T>
public static string GetDisplayName(Type type, bool fullName)
{
if (type == null)
{
return string.Empty;
}
if (type.IsGenericParameter)
{
return type.Name;
}
if (!type.IsGenericType && !type.IsArray)
{
if (fullName)
{
return type.FullName;
}
else
{
return type.Name;
}
}
// replace `2 with <Type1, Type2>
Regex regex = new Regex("`[0-9]+");
GenericsMatchEvaluator evaluator = new GenericsMatchEvaluator(type.GetGenericArguments(), fullName);
// Remove [[fullName1, ..., fullNameX]]
string name;
if (fullName)
{
name = type.FullName;
}
else
{
name = type.Name;
}
int start = name.IndexOf("[[", StringComparison.Ordinal);
int end = name.LastIndexOf("]]", StringComparison.Ordinal);
if (start > 0 && end > 0)
{
name = name.Substring(0, start) + name.Substring(end + 2);
}
return regex.Replace(name, evaluator.Evaluate);
}
private class GenericsMatchEvaluator
{
private Type[] generics = null;
private int index;
private bool fullName;
public GenericsMatchEvaluator(Type[] generics, bool fullName)
{
this.generics = generics;
this.index = 0;
this.fullName = fullName;
}
public string Evaluate(Match match)
{
int numberOfParameters = int.Parse(match.Value.Substring(1), CultureInfo.InvariantCulture);
StringBuilder sb = new StringBuilder();
// matched "`N" is replaced by "<Type1, ..., TypeN>"
sb.Append("<");
for (int i = 0; i < numberOfParameters; i++)
{
if (i > 0)
{
sb.Append(", ");
}
sb.Append(TypeNameHelper.GetDisplayName(this.generics[this.index++], this.fullName));
}
sb.Append(">");
return sb.ToString();
}
}
}
}

View File

@@ -1,43 +0,0 @@
// <copyright>
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
namespace Microsoft.Activities.Presentation.Xaml
{
using System;
using System.Activities;
using Microsoft.VisualBasic.Activities;
internal static class ActivityBuilderExtensions
{
internal static DynamicActivity ConvertToDynamicActivity(this ActivityBuilder activityBuilder)
{
DynamicActivity result = new DynamicActivity();
ActivityBuilderExtensions.ConvertActivityBuilderToDynamicActivity(activityBuilder, result);
return result;
}
internal static void ConvertActivityBuilderToDynamicActivity(ActivityBuilder activityBuilder, DynamicActivity bodyPlaceholder)
{
bodyPlaceholder.Name = activityBuilder.Name;
bodyPlaceholder.Implementation = () => activityBuilder.Implementation;
if (activityBuilder.Implementation != null)
{
VisualBasic.SetSettings(bodyPlaceholder, VisualBasic.GetSettings(activityBuilder));
}
bodyPlaceholder.Attributes.Clear();
foreach (Attribute attribute in activityBuilder.Attributes)
{
bodyPlaceholder.Attributes.Add(attribute);
}
bodyPlaceholder.Properties.Clear();
foreach (DynamicActivityProperty property in activityBuilder.Properties)
{
bodyPlaceholder.Properties.Add(property);
}
}
}
}

View File

@@ -1,284 +0,0 @@
// <copyright>
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
namespace Microsoft.Activities.Presentation.Xaml
{
using System;
using System.Activities.Presentation.Toolbox;
using System.Xaml;
// ActivityTemplateFactoryBuilderReader is a XamlReader that support <ActivityTemplateFactory x:Class ...
//
// Think of this class (and any other XamlReader) as a XAML node stream editor
// XAML node are *not* objects, they are represented as this. For example, when the reader encounter a StartObject node, its NodeType will become StartObject, and its Type will become the type of the starting object.
// The writer will then edit the stream and send the nodes to the underlying stream (by calling the methods on the underlying writer)
//
// The editing algorithm goes as follow:
//
// Initially, the first node is read from the underlying reader, if the first node is <ActivityTemplateFactory, then we start buffering nodes, otherwise we simply switch to the Bypass state
// We transform and buffer the transformed nodes until we reach the StartMember of Implementation Node, then we yield the control and switch to the ReadingFromBuffer state.
//
// All the external calls are then delegated to the reader provided by the buffer.
//
// Eventually, the buffer will used up, and we will switch to the Bypass state.
internal sealed class ActivityTemplateFactoryBuilderReader : XamlReader, IXamlLineInfo
{
private XamlSchemaContext schemaContext;
private XamlReader underlyingReader;
private XamlNodeQueue queuedNodes;
private XamlType activityTemplateFactoryBuilderType;
private XamlMember activityTemplateFactoryBuilderImplementationMember;
private XamlMember activityTemplateFactoryBuilderNameMember;
private XamlMember activityTemplateFactoryBuilderTargetTypeMember;
private bool hasLineInfo;
private ActivityTemplateFactoryBuilderReaderStates currentState = ActivityTemplateFactoryBuilderReaderStates.InitialState;
public ActivityTemplateFactoryBuilderReader(XamlReader underlyingReader, XamlSchemaContext schemaContext)
{
this.underlyingReader = underlyingReader;
this.schemaContext = schemaContext;
this.hasLineInfo = this.underlyingReader is IXamlLineInfo;
}
private enum ActivityTemplateFactoryBuilderReaderStates
{
InitialState,
ReadingFromBufferState,
BypassState,
}
public override bool IsEof
{
get
{
if (this.currentState == ActivityTemplateFactoryBuilderReaderStates.ReadingFromBufferState)
{
return false;
}
else
{
return this.underlyingReader.IsEof;
}
}
}
public override XamlMember Member
{
get { return this.CurrentReader.Member; }
}
public override NamespaceDeclaration Namespace
{
get { return this.CurrentReader.Namespace; }
}
public override XamlNodeType NodeType
{
get { return this.CurrentReader.NodeType; }
}
public override XamlSchemaContext SchemaContext
{
get { return this.schemaContext; }
}
public override XamlType Type
{
get { return this.CurrentReader.Type; }
}
public override object Value
{
get { return this.CurrentReader.Value; }
}
public bool HasLineInfo
{
get { return this.hasLineInfo; }
}
public int LineNumber
{
get
{
if (this.HasLineInfo)
{
return this.CurrentLineInfo.LineNumber;
}
else
{
return 0;
}
}
}
public int LinePosition
{
get
{
if (this.HasLineInfo)
{
return this.CurrentLineInfo.LinePosition;
}
else
{
return 0;
}
}
}
private XamlReader CurrentReader
{
get
{
switch (this.currentState)
{
case ActivityTemplateFactoryBuilderReaderStates.InitialState:
case ActivityTemplateFactoryBuilderReaderStates.BypassState:
return this.underlyingReader;
default:
SharedFx.Assert(this.currentState == ActivityTemplateFactoryBuilderReaderStates.ReadingFromBufferState, "This is the only remaining ActivityTemplateFactoryBuilderReaderStates.");
return this.queuedNodes.Reader;
}
}
}
private IXamlLineInfo CurrentLineInfo
{
get { return (IXamlLineInfo)this.CurrentReader; }
}
private XamlType ActivityTemplateFactoryBuilderType
{
get
{
if (this.activityTemplateFactoryBuilderType == null)
{
this.activityTemplateFactoryBuilderType = new XamlType(typeof(ActivityTemplateFactoryBuilder), this.schemaContext);
}
return this.activityTemplateFactoryBuilderType;
}
}
private XamlMember ActivityTemplateFactoryBuilderImplementationMember
{
get
{
if (this.activityTemplateFactoryBuilderImplementationMember == null)
{
this.activityTemplateFactoryBuilderImplementationMember = ActivityTemplateFactoryBuilderXamlMembers.ActivityTemplateFactoryBuilderImplementationMember(this.schemaContext);
}
return this.activityTemplateFactoryBuilderImplementationMember;
}
}
private XamlMember ActivityTemplateFactoryBuilderNameMember
{
get
{
if (this.activityTemplateFactoryBuilderNameMember == null)
{
this.activityTemplateFactoryBuilderNameMember = ActivityTemplateFactoryBuilderXamlMembers.ActivityTemplateFactoryBuilderNameMember(this.schemaContext);
}
return this.activityTemplateFactoryBuilderNameMember;
}
}
private XamlMember ActivityTemplateFactoryBuilderTargetTypeMember
{
get
{
if (this.activityTemplateFactoryBuilderTargetTypeMember == null)
{
this.activityTemplateFactoryBuilderTargetTypeMember = ActivityTemplateFactoryBuilderXamlMembers.ActivityTemplateFactoryBuilderTargetTypeMember(this.schemaContext);
}
return this.activityTemplateFactoryBuilderTargetTypeMember;
}
}
public override bool Read()
{
switch (this.currentState)
{
case ActivityTemplateFactoryBuilderReaderStates.InitialState:
bool hasMoreNodes = this.underlyingReader.Read();
if (this.underlyingReader.NodeType == XamlNodeType.StartObject && IsActivityTemplateFactoryType(this.underlyingReader.Type))
{
Type underlyingType = this.underlyingReader.Type.UnderlyingType;
Type targetType = underlyingType.IsGenericType ? underlyingType.GetGenericArguments()[0] : null;
this.currentState = ActivityTemplateFactoryBuilderReaderStates.ReadingFromBufferState;
this.queuedNodes = new XamlNodeQueue(this.schemaContext);
this.queuedNodes.Writer.WriteStartObject(this.ActivityTemplateFactoryBuilderType, (IXamlLineInfo)this.underlyingReader);
string className;
while (this.underlyingReader.Read())
{
if (this.underlyingReader.NodeType == XamlNodeType.StartMember && this.underlyingReader.Member == XamlLanguage.Class)
{
this.underlyingReader.Read();
className = (string)this.underlyingReader.Value;
this.underlyingReader.Read();
this.queuedNodes.Writer.WriteStartMember(this.ActivityTemplateFactoryBuilderNameMember, (IXamlLineInfo)this.underlyingReader);
this.queuedNodes.Writer.WriteValue(className, (IXamlLineInfo)this.underlyingReader);
this.queuedNodes.Writer.WriteEndMember((IXamlLineInfo)this.underlyingReader);
if (targetType != null)
{
this.queuedNodes.Writer.WriteStartMember(this.ActivityTemplateFactoryBuilderTargetTypeMember, (IXamlLineInfo)this.underlyingReader);
object targetTypeString = targetType;
this.queuedNodes.Writer.WriteValue(targetTypeString);
this.queuedNodes.Writer.WriteEndMember();
}
}
else if (this.underlyingReader.NodeType == XamlNodeType.StartMember && this.IsActivityTemplateFactoryImplementationMember(this.underlyingReader.Member))
{
this.queuedNodes.Writer.WriteStartMember(this.ActivityTemplateFactoryBuilderImplementationMember, (IXamlLineInfo)this.underlyingReader);
return true;
}
}
}
return hasMoreNodes;
case ActivityTemplateFactoryBuilderReaderStates.ReadingFromBufferState:
if (this.queuedNodes.Reader.Read())
{
return true;
}
else
{
this.currentState = ActivityTemplateFactoryBuilderReaderStates.BypassState;
this.queuedNodes = null;
return this.underlyingReader.Read();
}
default:
SharedFx.Assert(this.currentState == ActivityTemplateFactoryBuilderReaderStates.BypassState, "This is the only remaining ActivityTemplateFactoryBuilderReaderStates.");
return this.underlyingReader.Read();
}
}
private static bool IsActivityTemplateFactoryType(XamlType xamlType)
{
if (xamlType.UnderlyingType == null)
{
return false;
}
return xamlType.UnderlyingType == typeof(ActivityTemplateFactory) || (xamlType.UnderlyingType.IsGenericType && xamlType.UnderlyingType.GetGenericTypeDefinition() == typeof(ActivityTemplateFactory<>));
}
private bool IsActivityTemplateFactoryImplementationMember(XamlMember xamlMember)
{
return IsActivityTemplateFactoryType(xamlMember.DeclaringType) && xamlMember == ActivityTemplateFactoryBuilderXamlMembers.ActivityTemplateFactoryImplementationMemberForReader(xamlMember.DeclaringType.UnderlyingType, this.schemaContext);
}
}
}

View File

@@ -1,331 +0,0 @@
// <copyright>
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
namespace Microsoft.Activities.Presentation.Xaml
{
using System;
using System.Activities.Presentation.Toolbox;
using System.Xaml;
// ActivityTemplateFactoryBuilderWriter is a XamlWriter that support <ActivityTemplateFactory x:Class ...
//
// Think of this class (and any other XamlWriter) as a XAML node stream editor
// XAML node are *not* objects, they are represented as method calls. For example, when WriteStartObject is called, a StartObject node is send to this writer.
// The writer will then edit the stream and send the nodes to the underlying stream (by calling the methods on the underlying writer)
//
// The editing algorithm goes as follow:
//
// The system starts as the InitialState. There are five states in total: (InitialState, BufferingState, BufferingNameState, BufferingTargetTypeState, BypassState)
// If the very first StartObject node is ActivityTemplateFactory, then start buffering by going to the buffering state, otherwise simply go to the ByPassState.
//
// In the buffering state, the nodes are buffered in a XamlNodeQueue, until we see the Implementation Node.
// When we reach the Implementation node, we will flush all the nodes transformed to the underlyingWriter, we will also switch to the ByPass state.
//
// During the buffering, it is possible that we encounter the Name/TargetType node - the name node cannot enter the buffer because editing is required, we will use a separate state to track that.
internal sealed class ActivityTemplateFactoryBuilderWriter : XamlWriter
{
private XamlSchemaContext schemaContext;
private XamlWriter underlyingWriter;
private XamlType activityTemplateFactoryType;
private XamlMember activityTemplateFactoryImplementationMember;
private XamlMember activityTemplateFactoryBuilderImplementationMember;
private XamlMember activityTemplateFactoryBuilderNameMember;
private XamlMember activityTemplateFactoryBuilderTargetTypeMember;
// Buffering of nodes before starting the Implementation node
private ActivityTemplateFactoryBuilderWriterStates currentState = ActivityTemplateFactoryBuilderWriterStates.InitialState;
private XamlNodeQueue queuedNodes;
private string className;
private string targetType;
private bool xamlLanguageNamespaceWritten = false;
public ActivityTemplateFactoryBuilderWriter(XamlWriter underlyingWriter, XamlSchemaContext schemaContext)
{
this.schemaContext = schemaContext;
this.underlyingWriter = underlyingWriter;
}
private enum ActivityTemplateFactoryBuilderWriterStates
{
InitialState,
BufferingState,
BufferingNameState,
BufferingTargetTypeState,
BypassState,
}
public override XamlSchemaContext SchemaContext
{
get { return this.schemaContext; }
}
private XamlType ActivityTemplateFactoryType
{
get
{
if (this.activityTemplateFactoryType == null)
{
this.activityTemplateFactoryType = new XamlType(typeof(ActivityTemplateFactory), this.schemaContext);
}
return this.activityTemplateFactoryType;
}
}
private XamlMember ActivityTemplateFactoryImplementationMember
{
get
{
if (this.activityTemplateFactoryImplementationMember == null)
{
this.activityTemplateFactoryImplementationMember = ActivityTemplateFactoryBuilderXamlMembers.ActivityTemplateFactoryImplementationMemberForWriter(this.schemaContext);
}
return this.activityTemplateFactoryImplementationMember;
}
}
private XamlMember ActivityTemplateFactoryBuilderImplementationMember
{
get
{
if (this.activityTemplateFactoryBuilderImplementationMember == null)
{
this.activityTemplateFactoryBuilderImplementationMember = ActivityTemplateFactoryBuilderXamlMembers.ActivityTemplateFactoryBuilderImplementationMember(this.schemaContext);
}
return this.activityTemplateFactoryBuilderImplementationMember;
}
}
private XamlMember ActivityTemplateFactoryBuilderNameMember
{
get
{
if (this.activityTemplateFactoryBuilderNameMember == null)
{
this.activityTemplateFactoryBuilderNameMember = ActivityTemplateFactoryBuilderXamlMembers.ActivityTemplateFactoryBuilderNameMember(this.schemaContext);
}
return this.activityTemplateFactoryBuilderNameMember;
}
}
private XamlMember ActivityTemplateFactoryBuilderTargetTypeMember
{
get
{
if (this.activityTemplateFactoryBuilderTargetTypeMember == null)
{
this.activityTemplateFactoryBuilderTargetTypeMember = ActivityTemplateFactoryBuilderXamlMembers.ActivityTemplateFactoryBuilderTargetTypeMember(this.schemaContext);
}
return this.activityTemplateFactoryBuilderTargetTypeMember;
}
}
public override void WriteNamespace(NamespaceDeclaration namespaceDeclaration)
{
if (namespaceDeclaration.Prefix == "x")
{
this.xamlLanguageNamespaceWritten = true;
}
this.underlyingWriter.WriteNamespace(namespaceDeclaration);
}
public override void WriteStartObject(XamlType type)
{
switch (this.currentState)
{
case ActivityTemplateFactoryBuilderWriterStates.InitialState:
if (type.Equals(new XamlType(typeof(ActivityTemplateFactoryBuilder), this.schemaContext)))
{
this.queuedNodes = new XamlNodeQueue(this.schemaContext);
this.currentState = ActivityTemplateFactoryBuilderWriterStates.BufferingState;
}
else
{
this.currentState = ActivityTemplateFactoryBuilderWriterStates.BypassState;
this.underlyingWriter.WriteStartObject(type);
}
break;
case ActivityTemplateFactoryBuilderWriterStates.BypassState:
this.underlyingWriter.WriteStartObject(type);
break;
default:
SharedFx.Assert(
this.currentState == ActivityTemplateFactoryBuilderWriterStates.BufferingState
|| this.currentState == ActivityTemplateFactoryBuilderWriterStates.BufferingNameState
|| this.currentState == ActivityTemplateFactoryBuilderWriterStates.BufferingTargetTypeState,
"These are the only possible ActivityTemplateFactoryBuilderWriterStates.");
SharedFx.Assert("It is impossible to start any object during the buffering state.");
break;
}
}
public override void WriteEndObject()
{
switch (this.currentState)
{
case ActivityTemplateFactoryBuilderWriterStates.InitialState:
SharedFx.Assert("It is impossible to end an object during InitialState");
break;
case ActivityTemplateFactoryBuilderWriterStates.BufferingState:
this.queuedNodes.Writer.WriteEndObject();
break;
case ActivityTemplateFactoryBuilderWriterStates.BypassState:
this.underlyingWriter.WriteEndObject();
break;
default:
SharedFx.Assert(
this.currentState == ActivityTemplateFactoryBuilderWriterStates.BufferingNameState
|| this.currentState == ActivityTemplateFactoryBuilderWriterStates.BufferingTargetTypeState,
"These are the only possible ActivityTemplateFactoryBuilderWriterStates.");
SharedFx.Assert("It is impossible to end an object when we are buffering the name / targetType.");
break;
}
}
public override void WriteGetObject()
{
switch (this.currentState)
{
case ActivityTemplateFactoryBuilderWriterStates.InitialState:
SharedFx.Assert("It is impossible to end an object during InitialState");
break;
case ActivityTemplateFactoryBuilderWriterStates.BufferingState:
this.queuedNodes.Writer.WriteGetObject();
break;
case ActivityTemplateFactoryBuilderWriterStates.BypassState:
this.underlyingWriter.WriteGetObject();
break;
default:
SharedFx.Assert(
this.currentState == ActivityTemplateFactoryBuilderWriterStates.BufferingNameState
|| this.currentState == ActivityTemplateFactoryBuilderWriterStates.BufferingTargetTypeState,
"These are the only possible ActivityTemplateFactoryBuilderWriterStates.");
SharedFx.Assert("It is impossible to get an object when we are buffering the name / targetType.");
break;
}
}
public override void WriteStartMember(XamlMember xamlMember)
{
switch (this.currentState)
{
case ActivityTemplateFactoryBuilderWriterStates.InitialState:
SharedFx.Assert("It is impossible to start a member during InitialState");
break;
case ActivityTemplateFactoryBuilderWriterStates.BufferingState:
if (xamlMember == this.ActivityTemplateFactoryBuilderImplementationMember)
{
xamlMember = this.ActivityTemplateFactoryImplementationMember;
if (!this.xamlLanguageNamespaceWritten)
{
// Required namespace for XAML x:Class
this.underlyingWriter.WriteNamespace(new NamespaceDeclaration("http://schemas.microsoft.com/winfx/2006/xaml", "x"));
}
this.underlyingWriter.WriteStartObject(this.ActivityTemplateFactoryType);
this.underlyingWriter.WriteStartMember(XamlLanguage.Class);
this.underlyingWriter.WriteValue(this.className);
this.underlyingWriter.WriteEndMember();
this.underlyingWriter.WriteStartMember(XamlLanguage.TypeArguments);
this.underlyingWriter.WriteValue(this.targetType);
this.underlyingWriter.WriteEndMember();
this.Transform(this.queuedNodes.Reader, this.underlyingWriter);
this.underlyingWriter.WriteStartMember(xamlMember);
this.currentState = ActivityTemplateFactoryBuilderWriterStates.BypassState;
}
if (xamlMember == this.ActivityTemplateFactoryBuilderNameMember)
{
this.currentState = ActivityTemplateFactoryBuilderWriterStates.BufferingNameState;
}
else if (xamlMember == this.ActivityTemplateFactoryBuilderTargetTypeMember)
{
this.currentState = ActivityTemplateFactoryBuilderWriterStates.BufferingTargetTypeState;
}
else
{
this.queuedNodes.Writer.WriteStartMember(xamlMember);
}
break;
case ActivityTemplateFactoryBuilderWriterStates.BypassState:
this.underlyingWriter.WriteStartMember(xamlMember);
break;
default:
SharedFx.Assert(
this.currentState == ActivityTemplateFactoryBuilderWriterStates.BufferingNameState
|| this.currentState == ActivityTemplateFactoryBuilderWriterStates.BufferingTargetTypeState,
"These are the only possible ActivityTemplateFactoryBuilderWriterStates.");
SharedFx.Assert("It is impossible to get an object when we are buffering the name / targetType.");
break;
}
}
public override void WriteEndMember()
{
switch (this.currentState)
{
case ActivityTemplateFactoryBuilderWriterStates.InitialState:
SharedFx.Assert("It is impossible to end a member during InitialState");
break;
case ActivityTemplateFactoryBuilderWriterStates.BufferingState:
this.queuedNodes.Writer.WriteEndMember();
break;
case ActivityTemplateFactoryBuilderWriterStates.BypassState:
this.underlyingWriter.WriteEndMember();
break;
default:
SharedFx.Assert(
this.currentState == ActivityTemplateFactoryBuilderWriterStates.BufferingNameState
|| this.currentState == ActivityTemplateFactoryBuilderWriterStates.BufferingTargetTypeState,
"These are the only possible ActivityTemplateFactoryBuilderWriterStates.");
// Intentionally skipped the end member of Name / TargetType node
this.currentState = ActivityTemplateFactoryBuilderWriterStates.BufferingState;
break;
}
}
public override void WriteValue(object value)
{
switch (this.currentState)
{
case ActivityTemplateFactoryBuilderWriterStates.InitialState:
SharedFx.Assert("It is impossible to write a value during InitialState");
break;
case ActivityTemplateFactoryBuilderWriterStates.BufferingState:
this.queuedNodes.Writer.WriteValue(value);
break;
case ActivityTemplateFactoryBuilderWriterStates.BufferingNameState:
this.className = (string)value;
break;
case ActivityTemplateFactoryBuilderWriterStates.BufferingTargetTypeState:
this.targetType = (string)value;
break;
default:
SharedFx.Assert(
this.currentState == ActivityTemplateFactoryBuilderWriterStates.BypassState,
"This is the only possible ActivityTemplateFactoryBuilderWriterStates");
this.underlyingWriter.WriteValue(value);
break;
}
}
private void Transform(XamlReader reader, XamlWriter myWriter)
{
while (!reader.IsEof)
{
reader.Read();
myWriter.WriteNode(reader);
}
}
}
}

View File

@@ -1,51 +0,0 @@
// <copyright>
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
namespace Microsoft.Activities.Presentation.Xaml
{
using System;
using System.Activities.Presentation.Toolbox;
using System.Reflection;
using System.Xaml;
internal static class ActivityTemplateFactoryBuilderXamlMembers
{
private const string ImplementationPropertyName = "Implementation";
private const string NamePropertyName = "Name";
private const string TargetTypePropertyName = "TargetType";
internal static XamlMember ActivityTemplateFactoryImplementationMemberForReader(Type activityTemplateFactoryType, XamlSchemaContext schemaContext)
{
return new XamlMember(ImplementationPropertyName, new XamlType(activityTemplateFactoryType, schemaContext), false);
}
internal static XamlMember ActivityTemplateFactoryImplementationMemberForWriter(XamlSchemaContext schemaContext)
{
PropertyInfo implementationPropertyInfo = typeof(ActivityTemplateFactory).GetProperty(ImplementationPropertyName, BindingFlags.Instance | BindingFlags.NonPublic);
SharedFx.Assert(implementationPropertyInfo != null, "ActivityTemplateFactory.Implementation should be defined as a protected property of ActivityTemplateFactory.");
return new XamlMember(implementationPropertyInfo, schemaContext);
}
internal static XamlMember ActivityTemplateFactoryBuilderNameMember(XamlSchemaContext schemaContext)
{
PropertyInfo namePropertyInfo = typeof(ActivityTemplateFactoryBuilder).GetProperty(NamePropertyName);
SharedFx.Assert(namePropertyInfo != null, "ActivityTemplateFactoryBuilder.Name should be defined as a public property of ActivityTemplateFactoryBuilder.");
return new XamlMember(namePropertyInfo, schemaContext);
}
internal static XamlMember ActivityTemplateFactoryBuilderTargetTypeMember(XamlSchemaContext schemaContext)
{
PropertyInfo namePropertyInfo = typeof(ActivityTemplateFactoryBuilder).GetProperty(TargetTypePropertyName);
SharedFx.Assert(namePropertyInfo != null, "ActivityTemplateFactoryBuilder.TargetType should be defined as a public property of ActivityTemplateFactoryBuilder.");
return new XamlMember(namePropertyInfo, schemaContext);
}
internal static XamlMember ActivityTemplateFactoryBuilderImplementationMember(XamlSchemaContext schemaContext)
{
PropertyInfo implementationPropertyInfo = typeof(ActivityTemplateFactoryBuilder).GetProperty(ImplementationPropertyName);
SharedFx.Assert(implementationPropertyInfo != null, "ActivityTemplateFactoryBuilder.Implementation should be defined as a public property of ActivityTemplateFactoryBuilder.");
return new XamlMember(implementationPropertyInfo, schemaContext);
}
}
}

View File

@@ -1,68 +0,0 @@
// <copyright>
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
namespace Microsoft.Activities.Presentation.Xaml
{
using System;
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design.Serialization;
using System.Globalization;
using System.Reflection;
// AttributeConverter is to convert some XAML-unfriendly attributes (without default ctor) to InstanceDescriptor for XAML serialization
internal class AttributeConverter<TAttribute, TAttributeInfo> : TypeConverter
where TAttribute : Attribute
where TAttributeInfo : AttributeInfo<TAttribute>, new()
{
private static ConstructorInfo attributeConstructor = null;
private TAttributeInfo attributeInfo = new TAttributeInfo();
private ConstructorInfo Constructor
{
get
{
// no need to lock here because every thread will generate the same constructor info even in race condition
// and cost to get the constructor is relative small
if (AttributeConverter<TAttribute, TAttributeInfo>.attributeConstructor == null)
{
AttributeConverter<TAttribute, TAttributeInfo>.attributeConstructor = this.attributeInfo.GetConstructor();
}
return AttributeConverter<TAttribute, TAttributeInfo>.attributeConstructor;
}
}
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
{
if (destinationType == typeof(InstanceDescriptor))
{
return true;
}
return base.CanConvertTo(context, destinationType);
}
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
return false;
}
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
if (destinationType != typeof(InstanceDescriptor))
{
return base.ConvertTo(context, culture, value, destinationType);
}
TAttribute attribute = value as TAttribute;
SharedFx.Assert(value != null, "The usage should be guaranteed by the XAML stack");
ConstructorInfo constructor = this.Constructor;
ICollection arguments = this.attributeInfo.GetConstructorArguments(attribute, ref constructor);
return new InstanceDescriptor(constructor, arguments, this.attributeInfo.IsComplete);
}
}
}

View File

@@ -1,36 +0,0 @@
// <copyright>
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
namespace Microsoft.Activities.Presentation.Xaml
{
using System;
using System.Collections;
using System.Reflection;
using System.Xaml.Schema;
// AttributeInfo is a helper class to provide type specfic info for each Attribute class
internal abstract class AttributeInfo<TAttribute> where TAttribute : Attribute
{
// false if the attribute has additional (mutable) properties that aren't set in the constructor
public virtual bool IsComplete
{
get { return true; }
}
// whether to use argumented-ctor for serialization even when there's default ctor
public virtual bool LookupConstructionRequiresArguments
{
get { return true; }
}
public virtual XamlTypeInvoker Invoker
{
get { return null; }
}
public abstract ConstructorInfo GetConstructor();
public abstract ICollection GetConstructorArguments(TAttribute attribute, ref ConstructorInfo constructor);
}
}

View File

@@ -1,45 +0,0 @@
// <copyright>
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
namespace Microsoft.Activities.Presentation.Xaml
{
using System;
using System.ComponentModel;
using System.Xaml;
using System.Xaml.Schema;
internal class AttributeXamlType<TAttribute, TAttributeInfo> : XamlType
where TAttribute : Attribute
where TAttributeInfo : AttributeInfo<TAttribute>, new()
{
private TAttributeInfo attributeInfo = new TAttributeInfo();
public AttributeXamlType(XamlSchemaContext xamlSchemaContext)
: base(typeof(TAttribute), xamlSchemaContext)
{
}
protected override XamlValueConverter<TypeConverter> LookupTypeConverter()
{
return new XamlValueConverter<TypeConverter>(typeof(AttributeConverter<TAttribute, TAttributeInfo>), this);
}
protected override bool LookupConstructionRequiresArguments()
{
return this.attributeInfo.LookupConstructionRequiresArguments;
}
protected override XamlTypeInvoker LookupInvoker()
{
if (this.attributeInfo.Invoker != null)
{
return this.attributeInfo.Invoker;
}
else
{
return base.LookupInvoker();
}
}
}
}

View File

@@ -1,50 +0,0 @@
// <copyright>
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
namespace Microsoft.Activities.Presentation.Xaml
{
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Reflection;
using System.Xaml.Schema;
internal class DefaultValueAttributeInfo : AttributeInfo<DefaultValueAttribute>
{
public override XamlTypeInvoker Invoker
{
get { return new DefaultValueAttributeInvoker(); }
}
public override ICollection GetConstructorArguments(DefaultValueAttribute attribute, ref ConstructorInfo constructor)
{
return new List<object>() { attribute.Value };
}
public override ConstructorInfo GetConstructor()
{
Type defaultValueAttributeType = typeof(DefaultValueAttribute);
ConstructorInfo constructor = defaultValueAttributeType.GetConstructor(new Type[] { typeof(object) });
SharedFx.Assert(constructor != null, "designerAttribute has a constructor that takes an argument of type System.Object.");
return constructor;
}
private class DefaultValueAttributeInvoker : XamlTypeInvoker
{
public override object CreateInstance(object[] arguments)
{
if (arguments != null && arguments.Length == 1)
{
// This helps to disambiguate the different constructors when arguments[0] is null.
return new DefaultValueAttribute(arguments[0]);
}
else
{
return base.CreateInstance(arguments);
}
}
}
}
}

View File

@@ -1,314 +0,0 @@
// <copyright>
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
namespace Microsoft.Activities.Presentation.Xaml
{
using System;
using System.Activities;
using System.Activities.Debugger.Symbol;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.ServiceModel.Activities;
using System.Xaml;
using System.Xml;
class DesignTimeXamlWriter : XamlXmlWriter
{
//namespaces to ignore (don't load assembilies for) at root node
HashSet<string> namespacesToIgnore;
//namespaces we've seen at root level, we use this to figure out appropriate alias for MC namespace
HashSet<string> rootLevelNamespaces;
// for duplicate namespace filtering (happens if we're using the local assembly to compile itself)
HashSet<string> emittedNamespacesInLocalAssembly;
//For namespace defined in local assembly with assembly info in namespace declaration, we'll strip out the assembly info
//and hold the namespace temporarily. Before writing the start object, we'll check whether the short version gets written
//as a separate declaration, if not, we write it out.
List<NamespaceDeclaration> localNamespacesWithAssemblyInfo;
WorkflowDesignerXamlSchemaContext schemaContext;
int currentDepth;
int debugSymbolDepth;
bool writeDebugSymbol;
bool debugSymbolNamespaceAdded;
bool isWritingElementStyleString;
internal static readonly string EmptyWorkflowSymbol = (new WorkflowSymbol() { FileName = @"C:\Empty.xaml" }).Encode();
private bool shouldWriteDebugSymbol;
public DesignTimeXamlWriter(TextWriter textWriter, WorkflowDesignerXamlSchemaContext context, bool shouldWriteDebugSymbol)
: this(new NamespaceIndentingXmlWriter(textWriter), context, shouldWriteDebugSymbol)
{
}
DesignTimeXamlWriter(NamespaceIndentingXmlWriter underlyingWriter, WorkflowDesignerXamlSchemaContext context, bool shouldWriteDebugSymbol)
: base(underlyingWriter, context,
// Setting AssumeValidInput to true allows to save a document even if it has duplicate members
new XamlXmlWriterSettings { AssumeValidInput = true })
{
underlyingWriter.Parent = this;
this.namespacesToIgnore = new HashSet<string>();
this.rootLevelNamespaces = new HashSet<string>();
this.schemaContext = context;
this.currentDepth = 0;
this.shouldWriteDebugSymbol = shouldWriteDebugSymbol;
}
public override void WriteNamespace(NamespaceDeclaration namespaceDeclaration)
{
if (this.currentDepth == 0)
{
//we need to track every namespace alias appeared in root element to figure out right alias for MC namespace
this.rootLevelNamespaces.Add(namespaceDeclaration.Prefix);
//Remember namespaces needed to be ignored at top level so we will add ignore attribute for them when we write start object
if (NameSpaces.ShouldIgnore(namespaceDeclaration.Namespace))
{
this.namespacesToIgnore.Add(namespaceDeclaration.Prefix);
}
if (namespaceDeclaration.Namespace == NameSpaces.DebugSymbol)
{
debugSymbolNamespaceAdded = true;
}
}
EmitNamespace(namespaceDeclaration);
}
void EmitNamespace(NamespaceDeclaration namespaceDeclaration)
{
// Write the namespace, filtering for duplicates in the local assembly because VS might be using it to compile itself.
if (schemaContext.IsClrNamespaceWithNoAssembly(namespaceDeclaration.Namespace))
{
// Might still need to trim a semicolon, even though it shouldn't strictly be there.
string nonassemblyQualifedNamespace = namespaceDeclaration.Namespace;
if (nonassemblyQualifedNamespace[nonassemblyQualifedNamespace.Length - 1] == ';')
{
nonassemblyQualifedNamespace = nonassemblyQualifedNamespace.Substring(0, nonassemblyQualifedNamespace.Length - 1);
namespaceDeclaration = new NamespaceDeclaration(nonassemblyQualifedNamespace, namespaceDeclaration.Prefix);
}
EmitLocalNamespace(namespaceDeclaration);
}
else if (schemaContext.IsClrNamespaceInLocalAssembly(namespaceDeclaration.Namespace))
{
string nonassemblyQualifedNamespace = schemaContext.TrimLocalAssembly(namespaceDeclaration.Namespace);
namespaceDeclaration = new NamespaceDeclaration(nonassemblyQualifedNamespace, namespaceDeclaration.Prefix);
if (this.localNamespacesWithAssemblyInfo == null)
{
this.localNamespacesWithAssemblyInfo = new List<NamespaceDeclaration>();
}
this.localNamespacesWithAssemblyInfo.Add(namespaceDeclaration);
}
else
{
base.WriteNamespace(namespaceDeclaration);
}
}
void EmitLocalNamespace(NamespaceDeclaration namespaceDeclaration)
{
if (this.emittedNamespacesInLocalAssembly == null) // lazy initialization
{
this.emittedNamespacesInLocalAssembly = new HashSet<string>();
}
// Write the namespace only once. Add() returns false if it was already there.
if (this.emittedNamespacesInLocalAssembly.Add(namespaceDeclaration.Namespace))
{
base.WriteNamespace(namespaceDeclaration);
}
}
public override void WriteStartObject(XamlType type)
{
if (type.UnderlyingType == typeof(string))
{
isWritingElementStyleString = true;
}
// this is the top-level object
if (this.currentDepth == 0)
{
if (!this.debugSymbolNamespaceAdded)
{
string sadsNamespaceAlias = GenerateNamespaceAlias(NameSpaces.DebugSymbolPrefix);
this.WriteNamespace(new NamespaceDeclaration(NameSpaces.DebugSymbol, sadsNamespaceAlias));
this.debugSymbolNamespaceAdded = true;
}
// we need to write MC namespace if any namespaces need to be ignored
if (this.namespacesToIgnore.Count > 0)
{
string mcNamespaceAlias = GenerateNamespaceAlias(NameSpaces.McPrefix);
this.WriteNamespace(new NamespaceDeclaration(NameSpaces.Mc, mcNamespaceAlias));
}
if (this.localNamespacesWithAssemblyInfo != null)
{
foreach (NamespaceDeclaration xamlNamespace in this.localNamespacesWithAssemblyInfo)
{
if ((this.emittedNamespacesInLocalAssembly == null) || (!this.emittedNamespacesInLocalAssembly.Contains(xamlNamespace.Namespace)))
{
base.WriteNamespace(xamlNamespace);
}
}
}
if ((type.UnderlyingType == typeof(Activity)) ||
(type.IsGeneric && type.UnderlyingType != null && type.UnderlyingType.GetGenericTypeDefinition() == typeof(Activity<>)) ||
(type.UnderlyingType == typeof(WorkflowService)))
{ // Exist ActivityBuilder, DebugSymbolObject will be inserted at the depth == 1.
debugSymbolDepth = 1;
}
else
{
debugSymbolDepth = 0;
}
}
if (this.currentDepth == debugSymbolDepth)
{
if (type.UnderlyingType != null && type.UnderlyingType.IsSubclassOf(typeof(Activity)) && this.shouldWriteDebugSymbol)
{
this.writeDebugSymbol = true;
}
}
base.WriteStartObject(type);
if (this.currentDepth == 0)
{
// we need to add Ignore attribute for all namespaces which we don't want to load assemblies for
// this has to be done after WriteStartObject
if (this.namespacesToIgnore.Count > 0)
{
string nsString = null;
foreach (string ns in this.namespacesToIgnore)
{
if (nsString == null)
{
nsString = ns;
}
else
{
nsString += " " + ns;
}
}
XamlDirective ignorable = new XamlDirective(NameSpaces.Mc, "Ignorable");
base.WriteStartMember(ignorable);
base.WriteValue(nsString);
base.WriteEndMember();
this.namespacesToIgnore.Clear();
}
}
++this.currentDepth;
}
public override void WriteGetObject()
{
++this.currentDepth;
base.WriteGetObject();
}
public override void WriteEndObject()
{
--this.currentDepth;
SharedFx.Assert(this.currentDepth >= 0, "Unmatched WriteEndObject");
if (this.currentDepth == this.debugSymbolDepth && this.writeDebugSymbol)
{
base.WriteStartMember(new XamlMember(DebugSymbol.SymbolName.MemberName,
this.SchemaContext.GetXamlType(typeof(DebugSymbol)), true));
base.WriteValue(EmptyWorkflowSymbol);
base.WriteEndMember();
this.writeDebugSymbol = false;
}
base.WriteEndObject();
isWritingElementStyleString = false;
}
string GenerateNamespaceAlias(string prefix)
{
string aliasPostfix = string.Empty;
//try "mc"~"mc1000" first
for (int i = 1; i <= 1000; i++)
{
string mcAlias = prefix + aliasPostfix;
if (!this.rootLevelNamespaces.Contains(mcAlias))
{
return mcAlias;
}
aliasPostfix = i.ToString(CultureInfo.InvariantCulture);
}
//roll the dice
return prefix + Guid.NewGuid().ToString();
}
class NamespaceIndentingXmlWriter : XmlTextWriter
{
int currentDepth;
TextWriter textWriter;
public NamespaceIndentingXmlWriter(TextWriter textWriter)
: base(textWriter)
{
this.textWriter = textWriter;
this.Formatting = Formatting.Indented;
}
public DesignTimeXamlWriter Parent { get; set; }
public override void WriteStartElement(string prefix, string localName, string ns)
{
base.WriteStartElement(prefix, localName, ns);
this.currentDepth++;
}
public override void WriteStartAttribute(string prefix, string localName, string ns)
{
if (prefix == "xmlns" && (this.currentDepth == 1))
{
this.textWriter.Write(new char[] { '\r', '\n' });
}
base.WriteStartAttribute(prefix, localName, ns);
}
public override void WriteEndElement()
{
if (this.Parent.isWritingElementStyleString)
{
base.WriteRaw(string.Empty);
}
base.WriteEndElement();
this.currentDepth--;
}
public override void WriteStartDocument()
{
// No-op to avoid XmlDeclaration from being written.
// Overriding this is equivalent of XmlWriterSettings.OmitXmlDeclaration = true.
}
public override void WriteStartDocument(bool standalone)
{
// No-op to avoid XmlDeclaration from being written.
// Overriding this is equivalent of XmlWriterSettings.OmitXmlDeclaration = true.
}
public override void WriteEndDocument()
{
// No-op to avoid end of XmlDeclaration from being written.
// Overriding this is equivalent of XmlWriterSettings.OmitXmlDeclaration = true.
}
}
}
}

View File

@@ -1,28 +0,0 @@
// <copyright>
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
namespace Microsoft.Activities.Presentation.Xaml
{
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Reflection;
class DesignerAttributeInfo : AttributeInfo<DesignerAttribute>
{
public override ICollection GetConstructorArguments(DesignerAttribute attribute, ref ConstructorInfo constructor)
{
return new List<object>() { Type.GetType(attribute.DesignerTypeName) };
}
public override ConstructorInfo GetConstructor()
{
Type designerAttributeType = typeof(DesignerAttribute);
ConstructorInfo constructor = designerAttributeType.GetConstructor(new Type[] { typeof(Type) });
SharedFx.Assert(constructor != null, "designerAttribute has a constructor that takes an argument of type System.Type.");
return constructor;
}
}
}

View File

@@ -1,28 +0,0 @@
// <copyright>
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
namespace Microsoft.Activities.Presentation.Xaml
{
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Reflection;
class EditorAttributeInfo : AttributeInfo<EditorAttribute>
{
public override ICollection GetConstructorArguments(EditorAttribute attribute, ref ConstructorInfo constructor)
{
return new List<object>() { Type.GetType(attribute.EditorTypeName), Type.GetType(attribute.EditorBaseTypeName) };
}
public override ConstructorInfo GetConstructor()
{
Type editorAttributeType = typeof(EditorAttribute);
ConstructorInfo constructor = editorAttributeType.GetConstructor(new Type[] { typeof(Type), typeof(Type) });
SharedFx.Assert(constructor != null, "designerAttribute has a constructor that takes two argument of type System.Type and System.Type.");
return constructor;
}
}
}

View File

@@ -1,32 +0,0 @@
// <copyright>
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
namespace Microsoft.Activities.Presentation.Xaml
{
using System.Activities.Debugger;
using System.Activities.Debugger.Symbol;
using System.Collections.Generic;
using System.Runtime.Versioning;
internal interface IWorkflowDesignerXamlHelperExecutionContext
{
FrameworkName FrameworkName { get; }
WorkflowDesignerXamlSchemaContext XamlSchemaContext { get; }
ViewStateIdManager IdManager { get; }
WorkflowSymbol LastWorkflowSymbol { get; set; }
string LocalAssemblyName { get; }
void OnSerializationCompleted(Dictionary<object, object> sourceLocationObjectToModelItemObjectMapping);
void OnBeforeDeserialize();
void OnSourceLocationFound(object target, SourceLocation sourceLocation);
void OnAfterDeserialize(Dictionary<string, SourceLocation> viewStateDataSourceLocationMapping);
}
}

View File

@@ -1,90 +0,0 @@
// <copyright>
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
namespace Microsoft.Activities.Presentation.Xaml
{
using System;
using System.Collections;
using System.ComponentModel.Composition;
using System.Reflection;
class ImportAttributeInfo : AttributeInfo<ImportAttribute>
{
static ConstructorInfo nameConstructor;
static ConstructorInfo typeConstructor;
static ConstructorInfo nameAndTypeConstructor;
public override bool IsComplete
{
get { return false; }
}
public override ICollection GetConstructorArguments(ImportAttribute attribute, ref ConstructorInfo constructor)
{
if (attribute.ContractName != null)
{
if (attribute.ContractType != null)
{
constructor = NameAndTypeConstructor;
return new object[] { attribute.ContractName, attribute.ContractType };
}
else
{
constructor = NameConstructor;
return new object[] { attribute.ContractName };
}
}
else if (attribute.ContractType != null)
{
constructor = TypeConstructor;
return new object[] { attribute.ContractType };
}
else
{
return new object[] { };
}
}
public override ConstructorInfo GetConstructor()
{
return typeof(ImportAttribute).GetConstructor(Type.EmptyTypes);
}
static ConstructorInfo NameConstructor
{
get
{
if (nameConstructor == null)
{
nameConstructor = typeof(ImportAttribute).GetConstructor(new Type[] { typeof(string) });
}
return nameConstructor;
}
}
static ConstructorInfo NameAndTypeConstructor
{
get
{
if (nameAndTypeConstructor == null)
{
nameAndTypeConstructor = typeof(ImportAttribute).GetConstructor(new Type[] { typeof(string), typeof(Type) });
}
return nameAndTypeConstructor;
}
}
static ConstructorInfo TypeConstructor
{
get
{
if (typeConstructor == null)
{
typeConstructor = typeof(ImportAttribute).GetConstructor(new Type[] { typeof(Type) });
}
return typeConstructor;
}
}
}
}

View File

@@ -1,93 +0,0 @@
// <copyright>
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
namespace Microsoft.Activities.Presentation.Xaml
{
using System;
using System.Collections;
using System.ComponentModel.Composition;
using System.Reflection;
class ImportManyAttributeInfo : AttributeInfo<ImportManyAttribute>
{
static ConstructorInfo nameConstructor;
static ConstructorInfo typeConstructor;
static ConstructorInfo nameAndTypeConstructor;
public override bool IsComplete
{
get
{
return false;
}
}
public override ICollection GetConstructorArguments(ImportManyAttribute attribute, ref ConstructorInfo constructor)
{
if (attribute.ContractName != null)
{
if (attribute.ContractType != null)
{
constructor = NameAndTypeConstructor;
return new object[] { attribute.ContractName, attribute.ContractType };
}
else
{
constructor = NameConstructor;
return new object[] { attribute.ContractName };
}
}
else if (attribute.ContractType != null)
{
constructor = TypeConstructor;
return new object[] { attribute.ContractType };
}
else
{
return new object[] { };
}
}
public override ConstructorInfo GetConstructor()
{
return typeof(ImportManyAttribute).GetConstructor(Type.EmptyTypes);
}
static ConstructorInfo NameConstructor
{
get
{
if (nameConstructor == null)
{
nameConstructor = typeof(ImportManyAttribute).GetConstructor(new Type[] { typeof(string) });
}
return nameConstructor;
}
}
static ConstructorInfo NameAndTypeConstructor
{
get
{
if (nameAndTypeConstructor == null)
{
nameAndTypeConstructor = typeof(ImportManyAttribute).GetConstructor(new Type[] { typeof(Type) });
}
return nameAndTypeConstructor;
}
}
static ConstructorInfo TypeConstructor
{
get
{
if (typeConstructor == null)
{
typeConstructor = typeof(ImportManyAttribute).GetConstructor(new Type[] { typeof(string), typeof(Type) });
}
return typeConstructor;
}
}
}
}

View File

@@ -1,27 +0,0 @@
// <copyright>
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
namespace Microsoft.Activities.Presentation.Xaml
{
using System;
internal class LineColumnPair : Tuple<int, int>
{
internal LineColumnPair(int item1, int item2)
: base(item1, item2)
{
SharedFx.Assert(item1 > 0 && item2 > 0, "item1 > 0&& item2 > 0");
}
internal int LineNumber
{
get { return this.Item1; }
}
internal int ColumnNumber
{
get { return this.Item2; }
}
}
}

View File

@@ -1,86 +0,0 @@
//----------------------------------------------------------------
// <copyright company="Microsoft Corporation">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//----------------------------------------------------------------
namespace Microsoft.Activities.Presentation.Xaml
{
using System;
using System.Activities.Presentation.Hosting;
using System.Collections.Generic;
using System.Reflection;
using System.Xaml;
internal static class MultiTargetingTypeResolver
{
public static ResolverResult Resolve(MultiTargetingSupportService multiTargetingService, Type type)
{
SharedFx.Assert(multiTargetingService != null, "multiTargetingService should not be null");
SharedFx.Assert(type != null, "type should not be null");
if (!multiTargetingService.IsSupportedType(type))
{
return ResolverResult.Unknown;
}
ResolverResult result;
Type reflectionType = multiTargetingService.GetReflectionType(type);
PropertyInfo[] properties = type.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.SetProperty);
PropertyInfo[] targetProperties = reflectionType.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.SetProperty);
List<string> newProperties = new List<string>();
// Assume we don't remove properties in newer framework
// We only compare property name here
if (properties.Length > targetProperties.Length)
{
foreach (PropertyInfo propertyInfo in properties)
{
bool found = false;
foreach (PropertyInfo targetProperty in targetProperties)
{
if (targetProperty.Name == propertyInfo.Name)
{
found = true;
break;
}
}
if (!found)
{
newProperties.Add(propertyInfo.Name);
}
}
result = new ResolverResult(newProperties);
}
else
{
result = ResolverResult.FullySupported;
}
return result;
}
public static XamlType GetXamlType(ResolverResult resolverResult, XamlType oldXamlType)
{
SharedFx.Assert(oldXamlType != null, "oldXamlType should not be null");
switch (resolverResult.Kind)
{
case XamlTypeKind.FullySupported:
return oldXamlType;
case XamlTypeKind.PartialSupported:
return new XamlTypeWithExtraPropertiesRemoved(oldXamlType.UnderlyingType, oldXamlType.SchemaContext, resolverResult.NewProperties);
default:
SharedFx.Assert(resolverResult.Kind == XamlTypeKind.Unknown, "resolverResult.Kind should be XamlTypeKind.Unknown.");
return null;
}
}
}
}

Some files were not shown because too many files have changed in this diff Show More