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

@ -45,6 +45,9 @@
/* Disable support for huge assemblies */
#undef DISABLE_LARGE_CODE
/* Disable support code for the LLDB plugin. */
#undef DISABLE_LLDB
/* Disable support debug logging */
#undef DISABLE_LOGGING

View File

@ -1 +1 @@
c1a14b2d46acd778f29ac790455f1f801e55f675
5ee52c595af4a754ddf1cc4e287415421e543537

View File

@ -1 +1 @@
e39a33a545310609f476581bdc2ee0c419270987
c6c1d89ecade1efd48abd44c9cb42126f11dacff

View File

@ -159,17 +159,20 @@ namespace Mono.Cecil.Cil {
void ReadScope (ScopeDebugInformation scope)
{
scope.Start = new InstructionOffset (GetInstruction (scope.Start.Offset));
var start_instruction = GetInstruction (scope.Start.Offset);
if (start_instruction != null)
scope.Start = new InstructionOffset (start_instruction);
var end_instruction = GetInstruction (scope.End.Offset);
scope.End = end_instruction == null
? new InstructionOffset ()
: new InstructionOffset (end_instruction);
if (end_instruction != null)
scope.End = new InstructionOffset (end_instruction);
if (!scope.variables.IsNullOrEmpty ()) {
for (int i = 0; i < scope.variables.Count; i++) {
var variable = scope.variables [i];
variable.index = new VariableIndex (GetVariable (variable.Index));
var variable_info = scope.variables [i];
var variable = GetVariable (variable_info.Index);
if (variable != null)
variable_info.index = new VariableIndex (variable);
}
}

View File

@ -204,7 +204,7 @@ namespace Mono.Cecil.Cil {
directory = new ImageDebugDirectory () {
MajorVersion = 256,
MinorVersion = 20577,
MinorVersion = 20557,
Type = 2,
};
@ -255,6 +255,7 @@ namespace Mono.Cecil.Cil {
writer.WriteMetadataHeader ();
writer.WriteMetadata ();
writer.Flush ();
writer.stream.Dispose ();
}

View File

@ -678,6 +678,7 @@ namespace Mono.Cecil.PE {
WriteRsrc ();
if (reloc != null)
WriteReloc ();
Flush ();
}
void BuildTextMap ()

View File

@ -2,7 +2,7 @@
<package xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<metadata xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<id>Mono.Cecil</id>
<version>0.10.0.0-beta1-v2</version>
<version>0.10.0.0-beta2</version>
<title>Mono.Cecil</title>
<authors>Jb Evain</authors>
<owners>Jb Evain</owners>

View File

@ -2558,6 +2558,17 @@ namespace Mono.Cecil {
return (int) size;
}
public IEnumerable<CustomAttribute> GetCustomAttributes ()
{
InitializeTypeDefinitions ();
var length = image.TableHeap [Table.CustomAttribute].Length;
var custom_attributes = new Collection<CustomAttribute> ((int) length);
ReadCustomAttributeRange (new Range (1, length), custom_attributes);
return custom_attributes;
}
public byte [] ReadCustomAttributeBlob (uint signature)
{
return ReadBlob (signature);
@ -3739,7 +3750,9 @@ namespace Mono.Cecil {
if (i > 0 && separator != 0)
builder.Append (separator);
builder.Append (reader.ReadUTF8StringBlob (ReadCompressedUInt32 ()));
uint part = ReadCompressedUInt32 ();
if (part != 0)
builder.Append (reader.ReadUTF8StringBlob (part));
}
return builder.ToString ();

View File

@ -85,6 +85,9 @@ namespace Mono.Cecil {
module.MetadataSystem.Clear ();
if (module.symbol_reader != null)
module.symbol_reader.Dispose ();
var name = module.assembly != null ? module.assembly.Name : null;
var fq_name = stream.value.GetFileName ();
var symbol_writer_provider = parameters.SymbolWriterProvider;
@ -105,9 +108,6 @@ namespace Mono.Cecil {
BuildMetadata (module, metadata);
if (module.symbol_reader != null)
module.symbol_reader.Dispose ();
var writer = ImageWriter.CreateWriter (module, metadata, stream);
writer.WriteImage ();
@ -2257,7 +2257,7 @@ namespace Mono.Cecil {
{
var rid = local_scope_table.AddRow (new LocalScopeRow (
method_info.Method.MetadataToken.RID,
AddImportScope (scope.Import),
scope.import != null ? AddImportScope (scope.import) : 0,
local_variable_rid,
local_constant_rid,
(uint) scope.Start.Offset,
@ -2273,9 +2273,6 @@ namespace Mono.Cecil {
if (scope.HasConstants)
AddLocalConstants (scope);
if (scope.Import != null)
AddImportScope (scope.Import);
for (int i = 0; i < scope.Scopes.Count; i++)
AddLocalScope (method_info, scope.Scopes [i]);
}
@ -2516,10 +2513,13 @@ namespace Mono.Cecil {
}
signature.WriteByte ((byte) separator);
var parts = name.Split (new [] { separator }, StringSplitOptions.RemoveEmptyEntries);
for (int i = 0; i < parts.Length; i++)
var parts = name.Split (new [] { separator });
for (int i = 0; i < parts.Length; i++) {
if (parts [i] == String.Empty)
signature.WriteCompressedUInt32 (0);
else
signature.WriteCompressedUInt32 (GetUTF8StringBlobIndex (parts [i]));
}
return signature;
}

View File

@ -122,6 +122,9 @@ namespace Mono.Cecil {
if (this.ReturnType.ContainsGenericParameter || base.ContainsGenericParameter)
return true;
if (!HasParameters)
return false;
var parameters = this.Parameters;
for (int i = 0; i < parameters.Count; i++)

View File

@ -48,6 +48,11 @@ namespace Mono.Cecil {
set { Parameter.Attributes = value; }
}
public string Name {
get { return Parameter.Name; }
set { Parameter.Name = value; }
}
public bool HasCustomAttributes {
get { return parameter != null && parameter.HasCustomAttributes; }
}

View File

@ -661,6 +661,14 @@ namespace Mono.Cecil {
return Read (this, (_, reader) => reader.GetMemberReferences ());
}
public IEnumerable<CustomAttribute> GetCustomAttributes ()
{
if (!HasImage)
return Empty<CustomAttribute>.Array;
return Read (this, (_, reader) => reader.GetCustomAttributes ());
}
public TypeReference GetType (string fullName, bool runtimeName)
{
return runtimeName

View File

@ -19,4 +19,4 @@ using System.Runtime.InteropServices;
[assembly: AssemblyVersion ("0.10.0.0")]
[assembly: AssemblyFileVersion ("0.10.0.0")]
[assembly: AssemblyInformationalVersion ("0.10.0.0-beta1")]
[assembly: AssemblyInformationalVersion ("0.10.0.0-beta2")]

View File

@ -1,23 +1,4 @@
Cecil
=====
Mono.Cecil is a library to generate and inspect programs and libraries in the ECMA CIL form.
To put it simply, you can use Cecil to:
* Analyze .NET binaries using a simple and powerful object model, without having to load assemblies to use Reflection.
* Modify .NET binaries, add new metadata structures and alter the IL code.
Cecil has been around since 2004 and is [widely used](https://github.com/jbevain/cecil/wiki/Users) in the .NET community.
The best way to learn how to use Cecil is to dive into the [Cecil.Samples](https://github.com/jbevain/cecil.samples) repository. It's a growing collection of samples with the goal of showing how to get things done using Cecil, as IL manipulation can sometime get tricky.
Read about the Cecil development on the [development log](http://cecil.pe).
To discuss Cecil, the best place is the [mono-cecil](https://groups.google.com/group/mono-cecil) Google Group.
Cecil is a project under the benevolent umbrella of the [.NET Foundation](http://www.dotnetfoundation.org/).
[![.NET build status](https://ci.appveyor.com/api/projects/status/fmhutmhidy1fahl4?svg=true)](https://ci.appveyor.com/project/jbevain/cecil)
[![Mono build status](https://travis-ci.org/jbevain/cecil.svg?branch=master)](https://travis-ci.org/jbevain/cecil)
[![Join the chat at https://gitter.im/jbevain/cecil](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/jbevain/cecil?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
This is a fork of [Cecil](https://github.com/jbevain/cecil) library. Please do any pull requests in the original repository before they are merged into Mono fork.

View File

@ -351,5 +351,21 @@ namespace Mono.Cecil.Tests {
Assert.IsTrue (module.HasSymbols);
}, symbolReaderProvider: typeof (PortablePdbReaderProvider), symbolWriterProvider: typeof (PortablePdbWriterProvider));
}
[Test]
public void PortablePdbLineInfo ()
{
TestModule ("line.exe", module => {
var type = module.GetType ("Tests");
var main = type.GetMethod ("Main");
AssertCode (@"
.locals ()
.line 4,4:42,43 '/foo/bar.cs'
IL_0000: nop
.line 5,5:2,3 '/foo/bar.cs'
IL_0001: ret", main);
}, symbolReaderProvider: typeof (PortablePdbReaderProvider), symbolWriterProvider: typeof (PortablePdbWriterProvider));
}
}
}

Binary file not shown.

View File

@ -174,6 +174,29 @@ namespace Mono.Cecil.Rocks {
instruction.Operand = null;
}
public static void Optimize (this MethodBody self)
{
if (self == null)
throw new ArgumentNullException ("self");
OptimizeLongs (self);
OptimizeMacros (self);
}
static void OptimizeLongs (this MethodBody self)
{
for (var i = 0; i < self.Instructions.Count; i++) {
var instruction = self.Instructions [i];
if (instruction.OpCode.Code != Code.Ldc_I8)
continue;
var l = (long)instruction.Operand;
if (l >= uint.MaxValue)
continue;
ExpandMacro (instruction, OpCodes.Ldc_I4, (uint)l);
self.Instructions.Insert (++i, Instruction.Create (OpCodes.Conv_I8));
}
}
public static void OptimizeMacros (this MethodBody self)
{
if (self == null)

View File

@ -79,7 +79,6 @@ namespace Mono.Cecil.Tests {
foreach (var sp in info.SequencePoints)
Assert.AreEqual(@"C:\tmp\repropartial\BreakpointTest.Portable\TestService.cs", sp.Document.Url);
}, symbolReaderProvider: typeof(MdbReaderProvider), symbolWriterProvider: typeof(MdbWriterProvider));
}
}

View File

@ -59,7 +59,7 @@ namespace Mono.Cecil.Pdb {
static bool IsPortablePdb (string fileName)
{
using (var file = new FileStream (fileName, FileMode.Open, FileAccess.Read, FileShare.None))
using (var file = new FileStream (fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
return IsPortablePdb (file);
}

View File

@ -104,11 +104,17 @@ namespace Mono.Cecil.Pdb {
ReadSequencePoints (function, symbol);
if (function.scopes.Length > 1)
throw new NotSupportedException ();
else if (function.scopes.Length == 1)
if (!function.scopes.IsNullOrEmpty())
symbol.scope = ReadScopeAndLocals (function.scopes [0], symbol);
if (function.scopes.Length > 1) {
for (int i = 1; i < function.scopes.Length; i++) {
var s = ReadScopeAndLocals (function.scopes [i], symbol);
if (!AddScope (symbol.scope.Scopes, s))
symbol.scope.Scopes.Add (s);
}
}
return symbol;
}
@ -133,6 +139,9 @@ namespace Mono.Cecil.Pdb {
parent.variables = new Collection<VariableDebugInformation> (scope.slots.Length);
foreach (PdbSlot slot in scope.slots) {
if (slot.flags == 1) // parameter names
continue;
var index = (int) slot.slot;
var variable = new VariableDebugInformation (index, slot.name);
if (slot.flags == 4)
@ -157,6 +166,21 @@ namespace Mono.Cecil.Pdb {
return parent;
}
static bool AddScope (Collection<ScopeDebugInformation> scopes, ScopeDebugInformation scope)
{
foreach (var sub_scope in scopes) {
if (sub_scope.HasScopes && AddScope (sub_scope.Scopes, scope))
return true;
if (scope.Start.Offset >= sub_scope.Start.Offset && scope.End.Offset <= sub_scope.End.Offset) {
sub_scope.Scopes.Add (scope);
return true;
}
}
return false;
}
void ReadSequencePoints (PdbFunction function, MethodDebugInformation info)
{
if (function.lines == null)

View File

@ -45,6 +45,7 @@ namespace Mono.Cecil.Pdb {
writer.OpenMethod (sym_token);
if (!info.sequence_points.IsNullOrEmpty ())
DefineSequencePoints (info.sequence_points);
if (info.scope != null)

View File

@ -147,6 +147,13 @@ namespace Mono.Cecil.Tests {
}, readOnly: Platform.OnMono, symbolReaderProvider: typeof(PdbReaderProvider), symbolWriterProvider: typeof(PdbWriterProvider));
}
[Test]
public void EmptyEnumerable ()
{
TestModule ("empty-iterator.dll", module => {
}, readOnly: Platform.OnMono, symbolReaderProvider: typeof (PdbReaderProvider), symbolWriterProvider: typeof (PdbWriterProvider));
}
[Test]
public void CreateMethodFromScratch ()
{

View File

@ -165,13 +165,13 @@ namespace Mono.Security.Interface
#region Obsolete APIs
[Obsolete]
[Obsolete ("Use GetProvider() instead.")]
public static MonoTlsProvider GetDefaultProvider ()
{
return GetProvider ();
}
[Obsolete]
[Obsolete ("Use Initialize(string provider) instead.")]
public static void SetDefaultProvider (string name)
{
Initialize (name);

View File

@ -387,7 +387,7 @@ namespace Mono.Security.X509 {
if (!CheckStore (path, false))
return coll; // empty collection
string[] files = Directory.GetFiles (path, "*.cer");
string[] files = Directory.GetFiles (path, _newFormat ? "*.0" : "*.cer");
if ((files != null) && (files.Length > 0)) {
foreach (string file in files) {
try {

View File

@ -27,7 +27,7 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if !MOBILE
#if !MOBILE && !MONOMAC
using System;
using System.Configuration;

View File

@ -32,7 +32,7 @@ using System.Data.Common;
using System.Data.SqlClient;
/*--For Bug 853 Test Begin--*/
#if !MOBILE
#if !MOBILE && !MONOMAC
using Mono.Data.Sqlite;
#endif
/*--For Bug 853 Test End--*/
@ -189,7 +189,7 @@ namespace MonoTests.System.Data.Common
Assert.IsNotNull (ex.Message, "#4");
}
}
#if !MOBILE
#if !MOBILE && !MONOMAC
[Test]
[Category ("NotWorking")] // Requires newer sqlite than is on wrench
public void XimarinBugzillaBug853Test()

View File

@ -27,7 +27,7 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if !MOBILE
#if !MOBILE && !MONOMAC
using System.IO;
using System.Xml;

View File

@ -28,7 +28,7 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if !MOBILE
#if !MOBILE && !MONOMAC
using System;
using System.CodeDom;

View File

@ -1,4 +1,4 @@
#if !MOBILE
#if !MOBILE && !MONOMAC
using System;
using System.Runtime.Serialization;

View File

@ -24,7 +24,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#if !MOBILE
#if !MOBILE && !MONOMAC
using System;
using System.IO;

View File

@ -24,7 +24,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#if !MOBILE
#if !MOBILE && !MONOMAC
using System;
using System.CodeDom;

View File

@ -24,7 +24,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#if !MOBILE
#if !MOBILE && !MONOMAC
using System;
using System.CodeDom;

View File

@ -1,4 +1,4 @@
#if !MOBILE
#if !MOBILE && !MONOMAC
using System;
using System.ServiceModel;

View File

@ -1,4 +1,4 @@
#if !MOBILE
#if !MOBILE && !MONOMAC
using System;
using System.IO;
using System.ServiceModel;

View File

@ -1,4 +1,4 @@
#if !MOBILE
#if !MOBILE && !MONOMAC
using System;
using System.ServiceModel.Configuration;
using NUnit.Framework;

View File

@ -74,7 +74,7 @@ namespace MonoTests.System.ServiceModel.Description
Assert.AreEqual (0, pl.Count, "#1");
}
#if !MOBILE
#if !MOBILE && !MONOMAC
[Test]
public void ApplyDispatchBehavior ()
{

View File

@ -1,4 +1,4 @@
#if !MOBILE
#if !MOBILE && !MONOMAC
using System;
using System.IO;
using System.Runtime.Serialization;

View File

@ -25,7 +25,7 @@
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if !MOBILE
#if !MOBILE && !MONOMAC
using System;
using System.Net;
using System.Runtime.Serialization;

View File

@ -26,7 +26,7 @@
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if !MOBILE
#if !MOBILE && !MONOMAC
using System;
using System.Globalization;
using System.Runtime.Serialization;

View File

@ -74,7 +74,7 @@ namespace MonoTests.System.ServiceModel.Web
ch.Close ();
}
#if !MOBILE
#if !MOBILE && !MONOMAC
[Test]
public void CreateAtom10Response ()
{

View File

@ -25,7 +25,7 @@
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if !MOBILE
#if !MOBILE && !MONOMAC
using System;
using System.Collections.Generic;
using System.Linq;

View File

@ -16,7 +16,7 @@ namespace MonoTests.System.ServiceModel
Assert.AreEqual ("http", b.Scheme, "#1");
Assert.AreEqual (Encoding.UTF8, b.WriteEncoding, "#2");
Assert.AreEqual (0x10000, b.MaxBufferSize, "#3");
#if !MOBILE
#if !MOBILE && !MONOMAC
Assert.AreEqual (0x80000, b.MaxBufferPoolSize, "#4");
#endif
Assert.AreEqual (0x10000, b.MaxReceivedMessageSize, "#5");

View File

@ -7,7 +7,7 @@
// Copyright (C) 2007 Novell, Inc.
//
#if !MOBILE
#if !MOBILE && !MONOMAC
using NUnit.Framework;

View File

@ -10,7 +10,7 @@
//
#if !MOBILE
#if !MOBILE && !MONOMAC
using NUnit.Framework;
using System;

View File

@ -24,6 +24,7 @@ namespace MonoTests.System.Web.Services.Description
public class ServiceDescriptionTest
{
[Test]
[Category ("MacNotWorking")] // https://bugzilla.xamarin.com/show_bug.cgi?id=51254
public void SimpleWrite ()
{
ServiceDescription sd = new ServiceDescription ();

View File

@ -7,7 +7,7 @@
// Copyright (C) 2006 Novell, Inc.
//
#if !MOBILE
#if !MOBILE && !MONOMAC
using NUnit.Framework;

View File

@ -7,7 +7,7 @@
// Copyright (C) 2008 Novell, Inc.
//
#if !MOBILE
#if !MOBILE && !MONOMAC
using NUnit.Framework;

View File

@ -6,7 +6,7 @@
//
// Copyright (C) 2007 Novell, Inc.
//
#if !MOBILE
#if !MOBILE && !MONOMAC
using NUnit.Framework;
using System;

View File

@ -6,7 +6,7 @@
//
// Copyright (C) 2007 Novell, Inc.
//
#if !MOBILE
#if !MOBILE && !MONOMAC
using NUnit.Framework;
using System;

View File

@ -7,7 +7,7 @@
// Copyright (C) 2007 Novell, Inc.
//
#if !MOBILE
#if !MOBILE && !MONOMAC
using NUnit.Framework;
using System;
using System.Web.Services;

View File

@ -8,7 +8,7 @@
// (C) 2006 Novell
//
#if !MOBILE
#if !MOBILE && !MONOMAC
using System;
using System.CodeDom;

View File

@ -136,7 +136,7 @@ namespace MonoTests.System.Xml
Assert.AreEqual ("file", resolved.Scheme);
var task = sr.GetEntityAsync (resolved, null, typeof (Stream));
Assert.That (task.Wait (3000));
Assert.IsInstanceOfType (typeof (Stream), task.Result);
Assert.IsTrue (task.Result is Stream, "Unexpected type: " + task.Result.GetType());
}
}

View File

@ -220,8 +220,8 @@ namespace MonoTests.System.Xml.Schema
}
}
Assert.GreaterOrEqual (afterNoOfAttributes, beforeNoOfAttributes, "newAttributes");
Assert.GreaterOrEqual (afterNoOfElements, beforeNoOfElements, "newElements");
Assert.IsTrue (afterNoOfAttributes >= beforeNoOfAttributes, "newAttributes");
Assert.IsTrue (afterNoOfElements >= beforeNoOfElements, "newElements");
}
/*

View File

@ -74,7 +74,6 @@ using System.Runtime.InteropServices;
[assembly: StringFreezing]
[assembly: DefaultDependency (LoadHint.Always)]
[assembly: InternalsVisibleTo ("btls-cert-sync, PublicKey=002400000480000094000000060200000024000052534131000400000100010079159977d2d03a8e6bea7a2e74e8d1afcc93e8851974952bb480a12c9134474d04062447c37e0e68c080536fcf3c3fbe2ff9c979ce998475e506e8ce82dd5b0f350dc10e93bf2eeecf874b24770c5081dbea7447fddafa277b22de47d6ffea449674a4f9fccf84d15069089380284dbdd35f46cdff12a1bd78e4ef0065d016df")]
[assembly: InternalsVisibleTo ("Mono.Btls.Interface, PublicKey=002400000480000094000000060200000024000052534131000400000100010079159977d2d03a8e6bea7a2e74e8d1afcc93e8851974952bb480a12c9134474d04062447c37e0e68c080536fcf3c3fbe2ff9c979ce998475e506e8ce82dd5b0f350dc10e93bf2eeecf874b24770c5081dbea7447fddafa277b22de47d6ffea449674a4f9fccf84d15069089380284dbdd35f46cdff12a1bd78e4ef0065d016df")]
[assembly: InternalsVisibleTo ("Mono.Security, PublicKey=002400000480000094000000060200000024000052534131000400000100010079159977d2d03a8e6bea7a2e74e8d1afcc93e8851974952bb480a12c9134474d04062447c37e0e68c080536fcf3c3fbe2ff9c979ce998475e506e8ce82dd5b0f350dc10e93bf2eeecf874b24770c5081dbea7447fddafa277b22de47d6ffea449674a4f9fccf84d15069089380284dbdd35f46cdff12a1bd78e4ef0065d016df")]

View File

@ -48,6 +48,10 @@ namespace Mono.Btls
}
}
[DllImport (BTLS_DYLIB)]
extern static IntPtr mono_btls_key_new ();
[DllImport (BTLS_DYLIB)]
extern static void mono_btls_key_free (IntPtr handle);
@ -63,6 +67,9 @@ namespace Mono.Btls
[DllImport (BTLS_DYLIB)]
extern static int mono_btls_key_is_rsa (IntPtr handle);
[DllImport (BTLS_DYLIB)]
extern static int mono_btls_key_assign_rsa_private_key (IntPtr handle, byte[] der, int der_length);
new internal BoringKeyHandle Handle {
get { return (BoringKeyHandle)base.Handle; }
}
@ -99,6 +106,18 @@ namespace Mono.Btls
CheckError (copy != IntPtr.Zero);
return new MonoBtlsKey (new BoringKeyHandle (copy));
}
public static MonoBtlsKey CreateFromRSAPrivateKey (System.Security.Cryptography.RSA privateKey)
{
var keyData = Mono.Security.Cryptography.PKCS8.PrivateKeyInfo.Encode (privateKey);
var key = new MonoBtlsKey (new BoringKeyHandle (mono_btls_key_new ()));
var ret = mono_btls_key_assign_rsa_private_key (key.Handle.DangerousGetHandle (), keyData, keyData.Length);
if (ret == 0)
throw new MonoBtlsException ("Assigning private key failed.");
return key;
}
}
}
#endif

View File

@ -218,12 +218,10 @@ namespace Mono.Btls
public static string GetSystemStoreLocation ()
{
#if ANDROID
#if MONODROID
return "/system/etc/security/cacerts";
#else
var appData = Environment.GetFolderPath (Environment.SpecialFolder.ApplicationData);
var path = Path.Combine (appData, ".mono", "certs", "NewTrust");
return path;
return MonoBtlsX509StoreManager.GetStorePath (MonoBtlsX509StoreType.MachineTrustedRoots);
#endif
}

View File

@ -45,7 +45,7 @@ namespace Mono.Btls
static class MonoBtlsX509StoreManager
{
static bool initialized;
#if !ANDROID
#if !MONODROID
static string machineTrustedRootPath;
static string machineIntermediateCAPath;
static string machineUntrustedPath;
@ -70,7 +70,7 @@ namespace Mono.Btls
static void DoInitialize ()
{
#if !ANDROID
#if !MONODROID
var userPath = MX.X509StoreManager.NewCurrentUserPath;
userTrustedRootPath = Path.Combine (userPath, MX.X509Stores.Names.TrustedRoot);
userIntermediateCAPath = Path.Combine (userPath, MX.X509Stores.Names.IntermediateCA);
@ -85,7 +85,7 @@ namespace Mono.Btls
public static bool HasStore (MonoBtlsX509StoreType type)
{
#if ANDROID
#if MONODROID
return false;
#else
var path = GetStorePath (type);
@ -95,7 +95,7 @@ namespace Mono.Btls
public static string GetStorePath (MonoBtlsX509StoreType type)
{
#if ANDROID
#if MONODROID
throw new NotSupportedException ();
#else
Initialize ();

View File

@ -47,7 +47,7 @@ namespace Mono.Btls
class X509CertificateImplBtls : X509Certificate2Impl
{
MonoBtlsX509 x509;
MonoBtlsKey privateKey;
MonoBtlsKey nativePrivateKey;
X500DistinguishedName subjectName;
X500DistinguishedName issuerName;
X509CertificateImplCollection intermediateCerts;
@ -70,7 +70,8 @@ namespace Mono.Btls
{
disallowFallback = other.disallowFallback;
x509 = other.x509 != null ? other.x509.Copy () : null;
privateKey = other.privateKey != null ? other.privateKey.Copy () : null;
nativePrivateKey = other.nativePrivateKey != null ? other.nativePrivateKey.Copy () : null;
fallback = other.fallback != null ? (X509Certificate2Impl)other.fallback.Clone () : null;
if (other.intermediateCerts != null)
intermediateCerts = other.intermediateCerts.Clone ();
}
@ -104,7 +105,13 @@ namespace Mono.Btls
internal MonoBtlsKey NativePrivateKey {
get {
ThrowIfContextInvalid ();
return privateKey;
if (nativePrivateKey == null && FallbackImpl.HasPrivateKey) {
var key = FallbackImpl.PrivateKey as RSA;
if (key == null)
throw new NotSupportedException ("Currently only supports RSA private keys.");
nativePrivateKey = MonoBtlsKey.CreateFromRSAPrivateKey (key);
}
return nativePrivateKey;
}
}
@ -270,7 +277,7 @@ namespace Mono.Btls
}
public override bool HasPrivateKey {
get { return privateKey != null; }
get { return nativePrivateKey != null || FallbackImpl.HasPrivateKey; }
}
public override X500DistinguishedName IssuerName {
@ -290,12 +297,15 @@ namespace Mono.Btls
public override AsymmetricAlgorithm PrivateKey {
get {
if (privateKey == null || !privateKey.IsRsa)
return null;
var bytes = privateKey.GetBytes (true);
if (nativePrivateKey == null || !nativePrivateKey.IsRsa)
return FallbackImpl.PrivateKey;
var bytes = nativePrivateKey.GetBytes (true);
return PKCS8.PrivateKeyInfo.DecodeRSA (bytes);
}
set { FallbackImpl.PrivateKey = value; }
set {
nativePrivateKey = null;
FallbackImpl.PrivateKey = value;
}
}
public override PublicKey PublicKey {
@ -343,6 +353,7 @@ namespace Mono.Btls
public override void Import (byte[] data, string password, X509KeyStorageFlags keyStorageFlags)
{
Reset ();
if (password == null) {
try {
Import (data);
@ -399,7 +410,7 @@ namespace Mono.Btls
x509 = pkcs12.GetCertificate (0);
if (pkcs12.HasPrivateKey)
privateKey = pkcs12.GetPrivateKey ();
nativePrivateKey = pkcs12.GetPrivateKey ();
if (pkcs12.Count > 1) {
intermediateCerts = new X509CertificateImplCollection ();
for (int i = 0; i < pkcs12.Count; i++) {
@ -476,9 +487,8 @@ namespace Mono.Btls
x509.Dispose ();
x509 = null;
}
if (privateKey != null) {
privateKey = null;
privateKey = null;
if (nativePrivateKey != null) {
nativePrivateKey = null;
}
subjectName = null;
issuerName = null;

View File

@ -23,6 +23,7 @@ using System.IO;
using System.Net;
using System.Net.Security;
using System.Globalization;
using System.Runtime.ExceptionServices;
using System.Threading;
using System.Threading.Tasks;
using System.Security.Cryptography.X509Certificates;
@ -214,7 +215,7 @@ namespace Mono.Net.Security
try {
asyncRequest.StartOperation (ProcessHandshake);
} catch (Exception ex) {
throw SetException (ex);
ExceptionDispatchInfo.Capture (SetException (ex)).Throw ();
}
} finally {
if (lazyResult == null || lastException != null) {
@ -241,7 +242,7 @@ namespace Mono.Net.Security
var e = lazyResult.Result as Exception;
if (e != null)
throw SetException (e);
ExceptionDispatchInfo.Capture (SetException (e)).Throw ();
}
internal void ValidateCreateContext (bool serverMode, string targetHost, SslProtocols enabledProtocols, X509Certificate serverCertificate, X509CertificateCollection clientCertificates, bool clientCertRequired)

View File

@ -54,7 +54,33 @@ namespace System.Net.NetworkInformation {
{
throw new NotImplementedException ();
}
#if MONODROID
[DllImport ("__Internal")]
static extern int _monodroid_get_dns_servers (out IntPtr dns_servers_array);
void GetDNSServersFromOS ()
{
IntPtr dsa;
int len = _monodroid_get_dns_servers (out dsa);
if (len <= 0)
return;
var servers = new IntPtr [len];
Marshal.Copy (dsa, servers, 0, len);
dns_servers = new IPAddressCollection ();
foreach (IntPtr s in servers) {
string server_ip = Marshal.PtrToStringAnsi (s);
Marshal.FreeHGlobal (s);
IPAddress addr;
if (!IPAddress.TryParse (server_ip, out addr))
continue;
dns_servers.InternalAdd (addr);
}
Marshal.FreeHGlobal (dsa);
}
#else
static Regex ns = new Regex (@"\s*nameserver\s+(?<address>.*)");
static Regex search = new Regex (@"\s*search\s+(?<domain>.*)");
void ParseResolvConf ()
@ -95,7 +121,7 @@ namespace System.Net.NetworkInformation {
} catch {
}
}
#endif
public override IPAddressInformationCollection AnycastAddresses {
get {
var c = new IPAddressInformationCollection ();
@ -119,15 +145,23 @@ namespace System.Net.NetworkInformation {
public override IPAddressCollection DnsAddresses {
get {
#if MONODROID
GetDNSServersFromOS ();
#else
ParseResolvConf ();
#endif
return dns_servers;
}
}
public override string DnsSuffix {
get {
#if MONODROID
return String.Empty;
#else
ParseResolvConf ();
return dns_suffix;
#endif
}
}

View File

@ -16,7 +16,7 @@ using System.ComponentModel.Design;
using System.Globalization;
using System.Reflection;
using System.Runtime.InteropServices;
#if !MOBILE
#if !MOBILE && !MONOMAC
using System.Drawing.Design;
#endif
using NUnit.Framework;
@ -1053,7 +1053,7 @@ namespace MonoTests.System.ComponentModel
return attr;
return null;
}
#if !MOBILE
#if !MOBILE && !MONOMAC
class GetEditor_test
{
[Editor (typeof (UIEditor), typeof (UITypeEditor))]

View File

@ -16,7 +16,7 @@ namespace MonoTests.System.ComponentModel
[TestFixture]
public class ToolboxItemAttributeTests
{
#if !MOBILE
#if !MOBILE && !MONOMAC
[Test]
public void DefaultType ()
{

View File

@ -53,7 +53,7 @@ namespace MonoTests.System.Diagnostics
public void ConstructorNullName ()
{
SourceSwitch s = new SourceSwitch (null);
Assert.IsEmpty (s.DisplayName);
Assert.AreEqual (s.DisplayName.Length, 0);
}
[Test]

View File

@ -11,7 +11,7 @@
// (C) 2003 Martin Willemoes Hansen
//
#if !MOBILE
#if !MOBILE && !MONOMAC
using NUnit.Framework;
using System;

View File

@ -29,7 +29,7 @@
// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
//
#if !MOBILE
#if !MOBILE && !MONOMAC
using System;
using System.Configuration;

View File

@ -7,7 +7,7 @@
// (C) 2005 Novell
//
#if !MOBILE
#if !MOBILE && !MONOMAC
using System.Net.Configuration;

View File

@ -29,7 +29,7 @@
// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
//
#if !MOBILE
#if !MOBILE && !MONOMAC
using System;
using System.Configuration;

View File

@ -1 +1 @@
a597b4cd0a240dd08b9f9f2e1722d4a28bcc6754
80be0e4eb94d37e9482b76b02caba36592ba91b1

View File

@ -823,6 +823,7 @@ namespace MonoTests.System.Runtime.InteropServices
);
#endif
#if !MOBILE_STATIC
[StructLayout( LayoutKind.Sequential, Pack = 1 )]
public class FourByteStruct
{
@ -967,6 +968,7 @@ namespace MonoTests.System.Runtime.InteropServices
return objResult;
}
#endif
}
#if !MOBILE
[ComImport()]

View File

@ -28,7 +28,7 @@
//
// MOBILE profile lacks some (of the few) CAS features required to execute those tests
#if !MOBILE
#if !MOBILE && !MONOMAC
using NUnit.Framework;
using System;

View File

@ -93,7 +93,7 @@ namespace MonoTests.System.Security {
Assert.IsNotNull (e, "PolicyHierarchy");
}
#if !MOBILE
#if !MOBILE && !MONOMAC
private void ResolveEvidenceHost (SecurityZone zone, bool unrestricted, bool empty)
{
string prefix = zone.ToString () + "-";

View File

@ -448,6 +448,7 @@ namespace MonoTests.System.Threading.Tasks
}
[Test]
[Category ("MacNotWorking")] // Randomly fails - https://bugzilla.xamarin.com/show_bug.cgi?id=51255
public void FromAsync_Completed ()
{
var completed = new CompletedAsyncResult ();
@ -571,6 +572,7 @@ namespace MonoTests.System.Threading.Tasks
}
[Test]
[Category ("MacNotWorking")] // Randomly fails - https://bugzilla.xamarin.com/show_bug.cgi?id=51255
public void FromAsync_BeginCallback ()
{
bool called = false;

View File

@ -513,7 +513,7 @@ namespace MonoTests.System {
null, null);
}
#if !MONOTOUCH && !MOBILE_STATIC
#if !MONOTOUCH && !MOBILE_STATIC && !MONOMAC
[Test]
public void CreateInstanceCustomDomain ()
{

View File

@ -1 +1 @@
34874b1f81f0bae8977486ef067eec0eceac7e71
61e6a764534426216122856dba783860e8915efe

View File

@ -1 +1 @@
e275634bc2c909abbe355a3fe2f75b1a08b25558
3b59d6b952aa1995bae24cea0f13675747fc7848

View File

@ -1 +1 @@
888a60f83ef20a418c92152c4aa04334e35ca797
87cdef5c41826c8ad40a46a9f662234769f1a596

View File

@ -1 +1 @@
76e2f81fd4a9717c4a69a495cc31a486008065b1
1b02069d31f86ebdd8652df6da8516f39b4d9c66

View File

@ -1 +1 @@
8ae0a08f19dd0b517b5c8c706e3f11044ba7440c
1f23dd85def924073ad388e7604387b143d0f06b

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;
}
}
}
}

View File

@ -1,22 +0,0 @@
// <copyright>
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
internal static class NameSpaces
{
public const string Mc = "http://schemas.openxmlformats.org/markup-compatibility/2006";
public const string Design = "http://schemas.microsoft.com/netfx/2009/xaml/activities/presentation";
public const string Design2010 = "http://schemas.microsoft.com/netfx/2010/xaml/activities/presentation";
public const string Toolbox = "http://schemas.microsoft.com/netfx/2010/xaml/activities/presentation/toolbox";
public const string Activities = "http://schemas.microsoft.com/netfx/2009/xaml/activities";
public const string DebugSymbol = "http://schemas.microsoft.com/netfx/2010/xaml/activities/debugger";
public const string DesignPrefix = "sap";
public const string Design2010Prefix = "sap2010";
public const string McPrefix = "mc";
public const string DebugSymbolPrefix = "sads";
public static bool ShouldIgnore(string ns)
{
return ns == Design2010 || ns == DebugSymbol || ns == Design;
}
}

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