Imported Upstream version 4.0.0~alpha1

Former-commit-id: 806294f5ded97629b74c85c09952f2a74fe182d9
This commit is contained in:
Jo Shields
2015-04-07 09:35:12 +01:00
parent 283343f570
commit 3c1f479b9d
22469 changed files with 2931443 additions and 869343 deletions

View File

@@ -0,0 +1,30 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Security;
using System;
using System.Security.Permissions;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("3C5386D5-54BD-49dc-AFCC-A46EAE3545DB")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
// Friend assemblies
// Partial Trust :

View File

@@ -0,0 +1,246 @@
//----------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//----------------------------------------------------------------
namespace System.Activities.DurableInstancing
{
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Runtime;
sealed class BinaryHeap<TKey, TValue> where TKey : IComparable<TKey>
{
const int defaultCapacity = 128;
readonly KeyValuePair<TKey, TValue> EmptyItem = new KeyValuePair<TKey, TValue>();
KeyValuePair<TKey, TValue>[] items;
int itemCount;
public BinaryHeap() :
this(defaultCapacity)
{
}
public BinaryHeap(int capacity)
{
Fx.Assert(capacity > 0, "Capacity must be a positive value.");
this.items = new KeyValuePair<TKey, TValue>[capacity];
}
public int Count
{
get { return this.itemCount; }
}
public bool IsEmpty
{
get { return this.itemCount == 0; }
}
public void Clear()
{
this.itemCount = 0;
this.items = new KeyValuePair<TKey, TValue>[defaultCapacity];
}
public bool Enqueue(TKey key, TValue item)
{
if (this.itemCount == this.items.Length)
{
ResizeItemStore(this.items.Length * 2);
}
this.items[this.itemCount++] = new KeyValuePair<TKey, TValue>(key, item);
int position = this.BubbleUp(this.itemCount - 1);
return (position == 0);
}
public KeyValuePair<TKey, TValue> Dequeue()
{
return Dequeue(true);
}
KeyValuePair<TKey, TValue> Dequeue(bool shrink)
{
Fx.Assert(this.itemCount > 0, "Cannot dequeue empty queue.");
KeyValuePair<TKey, TValue> result = items[0];
if (this.itemCount == 1)
{
this.itemCount = 0;
this.items[0] = this.EmptyItem;
}
else
{
--this.itemCount;
this.items[0] = this.items[itemCount];
this.items[itemCount] = this.EmptyItem;
// Keep the structure of the heap valid.
this.BubbleDown(0);
}
if (shrink)
{
ShrinkStore();
}
return result;
}
public KeyValuePair<TKey, TValue> Peek()
{
Fx.Assert(this.itemCount > 0, "Cannot peek at empty queue.");
return this.items[0];
}
[SuppressMessage(FxCop.Category.Design, "CA1006:DoNotNestGenericTypesInMemberSignatures",
Justification = "This is an internal only API.")]
[SuppressMessage(FxCop.Category.MSInternal, "CA908:UseApprovedGenericsForPrecompiledAssemblies")]
public ICollection<KeyValuePair<TKey, TValue>> RemoveAll(Predicate<KeyValuePair<TKey, TValue>> func)
{
ICollection<KeyValuePair<TKey, TValue>> result = new List<KeyValuePair<TKey, TValue>>();
for (int position = 0; position < this.itemCount; position++)
{
while (func(this.items[position]) && position < this.itemCount)
{
result.Add(this.items[position]);
int lastItem = this.itemCount - 1;
while (func(this.items[lastItem]) && position < lastItem)
{
result.Add(this.items[lastItem]);
this.items[lastItem] = EmptyItem;
--lastItem;
}
this.items[position] = this.items[lastItem];
this.items[lastItem] = EmptyItem;
this.itemCount = lastItem;
if (position < lastItem)
{
this.BubbleDown(this.BubbleUp(position));
}
}
}
this.ShrinkStore();
return result;
}
void ShrinkStore()
{
// If we are under half capacity and above default capacity size down.
if (this.items.Length > defaultCapacity && this.itemCount < (this.items.Length >> 1))
{
int newSize = Math.Max(
defaultCapacity, (((this.itemCount / defaultCapacity) + 1) * defaultCapacity));
this.ResizeItemStore(newSize);
}
}
[SuppressMessage("Microsoft.MSInternal", "CA908:UseApprovedGenericsForPrecompiledAssemblies")]
[SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures",
Justification = "This is an internal only API.")]
public ICollection<KeyValuePair<TKey, TValue>> TakeWhile(Predicate<TKey> func)
{
ICollection<KeyValuePair<TKey, TValue>> result = new List<KeyValuePair<TKey, TValue>>();
while (!this.IsEmpty && func(this.Peek().Key))
{
result.Add(this.Dequeue(false));
}
ShrinkStore();
return result;
}
void ResizeItemStore(int newSize)
{
Fx.Assert(itemCount < newSize, "Shrinking now will lose data.");
Fx.Assert(defaultCapacity <= newSize, "Can not shrink below the default capacity.");
KeyValuePair<TKey, TValue>[] temp = new KeyValuePair<TKey, TValue>[newSize];
Array.Copy(this.items, 0, temp, 0, this.itemCount);
this.items = temp;
}
void BubbleDown(int startIndex)
{
int currentPosition = startIndex;
int swapPosition = startIndex;
while (true)
{
int leftChildPosition = (currentPosition << 1) + 1;
int rightChildPosition = leftChildPosition + 1;
if (leftChildPosition < itemCount)
{
if (this.items[currentPosition].Key.CompareTo(this.items[leftChildPosition].Key) > 0)
{
swapPosition = leftChildPosition;
}
}
else
{
break;
}
if (rightChildPosition < itemCount)
{
if (this.items[swapPosition].Key.CompareTo(this.items[rightChildPosition].Key) > 0)
{
swapPosition = rightChildPosition;
}
}
if (currentPosition != swapPosition)
{
KeyValuePair<TKey, TValue> temp = this.items[currentPosition];
this.items[currentPosition] = this.items[swapPosition];
this.items[swapPosition] = temp;
}
else
{
break;
}
currentPosition = swapPosition;
}
}
int BubbleUp(int startIndex)
{
while (startIndex > 0)
{
int parent = (startIndex - 1) >> 1;
if (this.items[parent].Key.CompareTo(this.items[startIndex].Key) > 0)
{
KeyValuePair<TKey, TValue> temp = this.items[startIndex];
this.items[startIndex] = this.items[parent];
this.items[parent] = temp;
}
else
{
break;
}
startIndex = parent;
}
return startIndex;
}
}
}

View File

@@ -0,0 +1,26 @@
//-----------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
namespace System.Activities.DurableInstancing
{
enum CommandResult
{
Success = 0,
InstanceNotFound = 1,
InstanceLockNotAcquired = 2,
KeyAlreadyExists = 3,
KeyNotFound = 4,
InstanceAlreadyExists = 5,
InstanceLockLost = 6,
InstanceCompleted = 7,
KeyDisassociated = 8,
StaleInstanceVersion = 10,
HostLockExpired = 11,
HostLockNotFound = 12,
CleanupInProgress = 13,
InstanceAlreadyLockedToOwner = 14,
IdentityNotFound = 15,
Unknown = 99
};
}

View File

@@ -0,0 +1,98 @@
//-----------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
namespace System.Activities.DurableInstancing
{
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Runtime;
using System.Xml;
using System.Xml.Linq;
using System.Xml.Serialization;
using System.Runtime.DurableInstancing;
sealed class CorrelationKey
{
public CorrelationKey(Guid keyId)
: this(keyId, null, InstanceEncodingOption.None)
{
}
public CorrelationKey(Guid keyId, IDictionary<XName, InstanceValue> keyMetadata, InstanceEncodingOption encodingOption)
{
this.KeyId = keyId;
this.BinaryData = SerializationUtilities.SerializeKeyMetadata(keyMetadata, encodingOption);
}
public Guid KeyId
{
get;
set;
}
public long StartPosition
{
get;
set;
}
public ArraySegment<byte> BinaryData
{
get;
set;
}
public void SerializeToXmlElement(XmlWriter xmlWriter)
{
xmlWriter.WriteStartElement("CorrelationKey");
xmlWriter.WriteAttributeString("KeyId", this.KeyId.ToString());
if (this.BinaryData.Array != null)
{
xmlWriter.WriteAttributeString("StartPosition", this.StartPosition.ToString(CultureInfo.InvariantCulture));
xmlWriter.WriteAttributeString("BinaryLength", this.BinaryData.Count.ToString(CultureInfo.InvariantCulture));
}
xmlWriter.WriteEndElement();
}
public static List<CorrelationKey> BuildKeyList(ICollection<Guid> keys)
{
List<CorrelationKey> result = null;
if (keys != null)
{
result = new List<CorrelationKey>(keys.Count);
foreach (Guid guid in keys)
{
result.Add(new CorrelationKey(guid));
}
}
else
{
result = new List<CorrelationKey>();
}
return result;
}
public static List<CorrelationKey> BuildKeyList(IDictionary<Guid, IDictionary<XName, InstanceValue>> keys, InstanceEncodingOption encodingOption)
{
List<CorrelationKey> result = new List<CorrelationKey>();
if (keys != null)
{
foreach (KeyValuePair<Guid, IDictionary<XName, InstanceValue>> keyValuePair in keys)
{
result.Add(new CorrelationKey(keyValuePair.Key, keyValuePair.Value, encodingOption));
}
}
return result;
}
}
}

View File

@@ -0,0 +1,178 @@
//-----------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
namespace System.Activities.DurableInstancing
{
using System.Activities.Persistence;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Data;
using System.Data.SqlClient;
using System.Globalization;
using System.Linq;
using System.Runtime;
using System.Runtime.DurableInstancing;
using System.Security.Cryptography;
using System.Text;
using System.Transactions;
using System.Xml.Linq;
sealed class CreateWorkflowOwnerAsyncResult : WorkflowOwnerAsyncResult
{
static readonly string commandText = string.Format(CultureInfo.InvariantCulture, "{0}.[CreateLockOwner]", SqlWorkflowInstanceStoreConstants.DefaultSchema);
bool fireActivatableInstancesEvent;
bool fireRunnableInstancesEvent;
Guid lockOwnerId;
public CreateWorkflowOwnerAsyncResult
(
InstancePersistenceContext context,
InstancePersistenceCommand command,
SqlWorkflowInstanceStore store,
SqlWorkflowInstanceStoreLock storeLock,
Transaction currentTransaction,
TimeSpan timeout,
AsyncCallback callback,
object state
) :
base(context, command, store, storeLock, currentTransaction, timeout, callback, state)
{
}
protected override string ConnectionString
{
get
{
// by making CreateWorkflowOwnerAsyncResult to use the same Connection Pool as the PersistenceTasks(LockRenewalTask, etc),
// we can prevent unbound bloating of new threads created for task dispatching blocked on the busy Connection Pool.
// If the Connection Pool is too busy to handle pending tasks, then any incoming CreateWorkflowOwnerAsyncResult will also block on the Connection Pool too.
SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(base.Store.CachedConnectionString);
builder.ApplicationName = SqlWorkflowInstanceStore.CommonConnectionPoolName;
return builder.ToString();
}
}
protected override void GenerateSqlCommand(SqlCommand sqlCommand)
{
base.GenerateSqlCommand(sqlCommand);
if (base.StoreLock.IsValid)
{
throw FxTrace.Exception.AsError(new InstancePersistenceCommandException(SR.MultipleLockOwnersNotSupported));
}
bool withIdentity;
IDictionary<XName, InstanceValue> commandMetadata = GetCommandMetadata(out withIdentity);
SqlParameterCollection parameters = sqlCommand.Parameters;
double lockTimeout = base.Store.BufferedHostLockRenewalPeriod.TotalSeconds;
this.lockOwnerId = Guid.NewGuid();
ExtractWorkflowHostType(commandMetadata);
InstanceValue instanceValue;
if (commandMetadata.TryGetValue(PersistenceMetadataNamespace.ActivationType, out instanceValue))
{
if (withIdentity)
{
throw FxTrace.Exception.AsError(new InstancePersistenceCommandException(SR.IdentityNotSupportedWithActivation));
}
if (!PersistenceMetadataNamespace.ActivationTypes.WAS.Equals(instanceValue.Value))
{
throw FxTrace.Exception.AsError(new InstancePersistenceCommandException(SR.NonWASActivationNotSupported));
}
this.fireActivatableInstancesEvent = true;
}
ArraySegment<byte>[] properties = SerializationUtilities.SerializePropertyBag(commandMetadata, base.Store.InstanceEncodingOption);
parameters.Add(new SqlParameter { ParameterName = "@lockTimeout", SqlDbType = SqlDbType.Int, Value = lockTimeout });
parameters.Add(new SqlParameter { ParameterName = "@lockOwnerId", SqlDbType = SqlDbType.UniqueIdentifier, Value = this.lockOwnerId });
parameters.Add(new SqlParameter { ParameterName = "@workflowHostType", SqlDbType = SqlDbType.UniqueIdentifier, Value = (base.Store.WorkflowHostType != Guid.Empty) ? base.Store.WorkflowHostType : (object) DBNull.Value });
parameters.Add(new SqlParameter { ParameterName = "@enqueueCommand", SqlDbType = SqlDbType.Bit, Value = base.Store.EnqueueRunCommands });
parameters.Add(new SqlParameter { ParameterName = "@deleteInstanceOnCompletion", SqlDbType = SqlDbType.Bit, Value = (base.Store.InstanceCompletionAction == InstanceCompletionAction.DeleteAll) });
parameters.Add(new SqlParameter { ParameterName = "@primitiveLockOwnerData", SqlDbType = SqlDbType.VarBinary, Size = properties[0].Count, Value = (object)(properties[0].Array) ?? DBNull.Value });
parameters.Add(new SqlParameter { ParameterName = "@complexLockOwnerData", SqlDbType = SqlDbType.VarBinary, Size = properties[1].Count, Value = (object)(properties[1].Array) ?? DBNull.Value });
parameters.Add(new SqlParameter { ParameterName = "@writeOnlyPrimitiveLockOwnerData", SqlDbType = SqlDbType.VarBinary, Size = properties[2].Count, Value = (object)(properties[2].Array) ?? DBNull.Value });
parameters.Add(new SqlParameter { ParameterName = "@writeOnlyComplexLockOwnerData", SqlDbType = SqlDbType.VarBinary, Size = properties[3].Count, Value = (object)(properties[3].Array) ?? DBNull.Value });
parameters.Add(new SqlParameter { ParameterName = "@encodingOption", SqlDbType = SqlDbType.TinyInt, Value = base.Store.InstanceEncodingOption });
parameters.Add(new SqlParameter { ParameterName = "@machineName", SqlDbType = SqlDbType.NVarChar, Value = SqlWorkflowInstanceStoreConstants.MachineName });
if (withIdentity)
{
Fx.Assert(base.Store.DatabaseVersion >= StoreUtilities.Version45, "Should never get here if the db version isn't 4.5 or higher");
string identityMetadataXml = SerializationUtilities.GetIdentityMetadataXml(base.InstancePersistenceCommand);
parameters.Add(new SqlParameter { ParameterName = "@identityMetadata", SqlDbType = SqlDbType.Xml, Value = identityMetadataXml });
}
}
protected override string GetSqlCommandText()
{
return CreateWorkflowOwnerAsyncResult.commandText;
}
protected override CommandType GetSqlCommandType()
{
return CommandType.StoredProcedure;
}
protected override Exception ProcessSqlResult(SqlDataReader reader)
{
Exception exception = StoreUtilities.GetNextResultSet(this.InstancePersistenceCommand.Name, reader);
if (exception == null)
{
base.InstancePersistenceContext.BindInstanceOwner(this.lockOwnerId, this.lockOwnerId);
long surrogateLockOwnerId = reader.GetInt64(1);
// Activatable takes precendence over Runnable. (Activation owners cannot run instances.)
if (this.fireActivatableInstancesEvent)
{
base.InstancePersistenceContext.BindEvent(HasActivatableWorkflowEvent.Value);
}
else if (this.fireRunnableInstancesEvent)
{
base.InstancePersistenceContext.BindEvent(HasRunnableWorkflowEvent.Value);
}
base.StoreLock.MarkInstanceOwnerCreated(this.lockOwnerId, surrogateLockOwnerId, base.InstancePersistenceContext.InstanceHandle, this.fireRunnableInstancesEvent, this.fireActivatableInstancesEvent);
}
return exception;
}
void ExtractWorkflowHostType(IDictionary<XName, InstanceValue> commandMetadata)
{
InstanceValue instanceValue;
if (commandMetadata.TryGetValue(WorkflowNamespace.WorkflowHostType, out instanceValue))
{
XName workflowHostType = instanceValue.Value as XName;
if (workflowHostType == null)
{
throw FxTrace.Exception.AsError(new InstancePersistenceCommandException(SR.InvalidMetadataValue(WorkflowNamespace.WorkflowHostType, typeof(XName).Name)));
}
byte[] workflowHostTypeBuffer = Encoding.Unicode.GetBytes(workflowHostType.ToString());
base.Store.WorkflowHostType = new Guid(HashHelper.ComputeHash(workflowHostTypeBuffer));
this.fireRunnableInstancesEvent = true;
}
}
IDictionary<XName, InstanceValue> GetCommandMetadata(out bool withIdentity)
{
CreateWorkflowOwnerWithIdentityCommand createOwnerWithIdentityCommand = base.InstancePersistenceCommand as CreateWorkflowOwnerWithIdentityCommand;
if (createOwnerWithIdentityCommand != null)
{
withIdentity = true;
return createOwnerWithIdentityCommand.InstanceOwnerMetadata;
}
else
{
CreateWorkflowOwnerCommand createOwnerCommand = (CreateWorkflowOwnerCommand)base.InstancePersistenceCommand;
withIdentity = false;
return createOwnerCommand.InstanceOwnerMetadata;
}
}
}
}

View File

@@ -0,0 +1,113 @@
//-----------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
namespace System.Activities.DurableInstancing
{
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Runtime.Serialization;
using System.Xml;
using System.Xml.Linq;
using System.Xml.Serialization;
class DefaultObjectSerializer : IObjectSerializer
{
NetDataContractSerializer serializer;
public DefaultObjectSerializer()
{
this.serializer = new NetDataContractSerializer();
}
public Dictionary<XName, object> DeserializePropertyBag(byte[] serializedValue)
{
using (MemoryStream memoryStream = new MemoryStream(serializedValue))
{
return this.DeserializePropertyBag(memoryStream);
}
}
public object DeserializeValue(byte[] serializedValue)
{
using (MemoryStream memoryStream = new MemoryStream(serializedValue))
{
return this.DeserializeValue(memoryStream);
}
}
public ArraySegment<byte> SerializePropertyBag(Dictionary<XName, object> value)
{
using (MemoryStream memoryStream = new MemoryStream(4096))
{
this.SerializePropertyBag(memoryStream, value);
return new ArraySegment<byte>(memoryStream.GetBuffer(), 0, Convert.ToInt32(memoryStream.Length));
}
}
public ArraySegment<byte> SerializeValue(object value)
{
using (MemoryStream memoryStream = new MemoryStream(4096))
{
this.SerializeValue(memoryStream, value);
return new ArraySegment<byte>(memoryStream.GetBuffer(), 0, Convert.ToInt32(memoryStream.Length));
}
}
protected virtual Dictionary<XName, object> DeserializePropertyBag(Stream stream)
{
using (XmlDictionaryReader dictionaryReader = XmlDictionaryReader.CreateBinaryReader(stream, XmlDictionaryReaderQuotas.Max))
{
Dictionary<XName, object> propertyBag = new Dictionary<XName, object>();
if (dictionaryReader.ReadToDescendant("Property"))
{
do
{
dictionaryReader.Read();
KeyValuePair<XName, object> property = (KeyValuePair<XName, object>) this.serializer.ReadObject(dictionaryReader);
propertyBag.Add(property.Key, property.Value);
}
while (dictionaryReader.ReadToNextSibling("Property"));
}
return propertyBag;
}
}
protected virtual object DeserializeValue(Stream stream)
{
using (XmlDictionaryReader dictionaryReader = XmlDictionaryReader.CreateBinaryReader(stream, XmlDictionaryReaderQuotas.Max))
{
return this.serializer.ReadObject(dictionaryReader);
}
}
protected virtual void SerializePropertyBag(Stream stream, Dictionary<XName, object> propertyBag)
{
using (XmlDictionaryWriter dictionaryWriter = XmlDictionaryWriter.CreateBinaryWriter(stream, null, null, false))
{
dictionaryWriter.WriteStartElement("Properties");
foreach (KeyValuePair<XName, object> property in propertyBag)
{
dictionaryWriter.WriteStartElement("Property");
this.serializer.WriteObject(dictionaryWriter, property);
dictionaryWriter.WriteEndElement();
}
dictionaryWriter.WriteEndElement();
}
}
protected virtual void SerializeValue(Stream stream, object value)
{
using (XmlDictionaryWriter dictionaryWriter = XmlDictionaryWriter.CreateBinaryWriter(stream, null, null, false))
{
this.serializer.WriteObject(dictionaryWriter, value);
}
}
}
}

View File

@@ -0,0 +1,65 @@
//-----------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
namespace System.Activities.DurableInstancing
{
using System.Data;
using System.Data.SqlClient;
using System.Globalization;
using System.Runtime.DurableInstancing;
using System.Transactions;
sealed class DeleteWorkflowOwnerAsyncResult : WorkflowOwnerAsyncResult
{
static string commandText = string.Format(CultureInfo.InvariantCulture, "{0}.[DeleteLockOwner]", SqlWorkflowInstanceStoreConstants.DefaultSchema);
long surrogateLockOwnerId;
public DeleteWorkflowOwnerAsyncResult
(
InstancePersistenceContext context,
InstancePersistenceCommand command,
SqlWorkflowInstanceStore store,
SqlWorkflowInstanceStoreLock storeLock,
Transaction currentTransaction,
TimeSpan timeout,
AsyncCallback callback,
object state
) :
base(context, command, store, storeLock, currentTransaction, timeout, callback, state)
{
}
protected override void GenerateSqlCommand(SqlCommand sqlCommand)
{
base.GenerateSqlCommand(sqlCommand);
this.surrogateLockOwnerId = base.StoreLock.SurrogateLockOwnerId;
sqlCommand.Parameters.Add(new SqlParameter { ParameterName = "@surrogateLockOwnerId", SqlDbType = SqlDbType.BigInt, Value = this.surrogateLockOwnerId });
}
protected override string GetSqlCommandText()
{
return DeleteWorkflowOwnerAsyncResult.commandText;
}
protected override CommandType GetSqlCommandType()
{
return CommandType.StoredProcedure;
}
protected override Exception ProcessSqlResult(SqlDataReader reader)
{
Exception exception = null;
exception = StoreUtilities.CheckRemainingResultSetForErrors(base.InstancePersistenceCommand.Name, reader);
if (exception == null)
{
base.InstancePersistenceContext.InstanceHandle.Free();
base.StoreLock.MarkInstanceOwnerLost(this.surrogateLockOwnerId, true);
}
return exception;
}
}
}

View File

@@ -0,0 +1,11 @@
//-----------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
namespace System.Activities.DurableInstancing
{
[Serializable]
struct DeletedMetadataValue
{
}
}

View File

@@ -0,0 +1,81 @@
//-----------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
namespace System.Activities.DurableInstancing
{
using System.Data;
using System.Data.SqlClient;
using System.Globalization;
using System.Runtime.DurableInstancing;
using System.Transactions;
using System.Xml.Linq;
using System.Runtime;
class DetectActivatableWorkflowsAsyncResult : SqlWorkflowInstanceStoreAsyncResult
{
static readonly string commandText = string.Format(CultureInfo.InvariantCulture, "{0}.[GetActivatableWorkflowsActivationParameters]", SqlWorkflowInstanceStoreConstants.DefaultSchema);
public DetectActivatableWorkflowsAsyncResult
(
InstancePersistenceContext context,
InstancePersistenceCommand command,
SqlWorkflowInstanceStore store,
SqlWorkflowInstanceStoreLock storeLock,
Transaction currentTransaction,
TimeSpan timeout,
AsyncCallback callback,
object state
) :
base(context, command, store, storeLock, currentTransaction, timeout, callback, state)
{
}
protected override string ConnectionString
{
get
{
SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(base.Store.CachedConnectionString);
builder.ApplicationName = SqlWorkflowInstanceStore.CommonConnectionPoolName;
return builder.ToString();
}
}
protected override void GenerateSqlCommand(SqlCommand sqlCommand)
{
sqlCommand.Parameters.Add(new SqlParameter { ParameterName = "@machineName", SqlDbType = SqlDbType.NVarChar, Value = SqlWorkflowInstanceStoreConstants.MachineName });
}
protected override string GetSqlCommandText()
{
return DetectActivatableWorkflowsAsyncResult.commandText;
}
protected override CommandType GetSqlCommandType()
{
return CommandType.StoredProcedure;
}
protected override Exception ProcessSqlResult(SqlDataReader reader)
{
Exception exception = StoreUtilities.GetNextResultSet(base.InstancePersistenceCommand.Name, reader);
if (exception == null)
{
bool signalEvent = false;
reader.NextResult();
signalEvent = reader.Read(); //The result set contains activatable workflows
if (signalEvent)
{
base.Store.UpdateEventStatus(true, HasActivatableWorkflowEvent.Value);
}
else
{
base.Store.UpdateEventStatus(false, HasActivatableWorkflowEvent.Value);
base.StoreLock.InstanceDetectionTask.ResetTimer(false);
}
}
return exception;
}
}
}

View File

@@ -0,0 +1,16 @@
//-----------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
namespace System.Activities.DurableInstancing
{
using System.Runtime.DurableInstancing;
sealed class DetectActivatableWorkflowsCommand : InstancePersistenceCommand
{
public DetectActivatableWorkflowsCommand() :
base(SqlWorkflowInstanceStoreConstants.DurableInstancingNamespace.GetName("DetectActivatableWorkflows"))
{
}
}
}

View File

@@ -0,0 +1,36 @@
//----------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//----------------------------------------------------------------
namespace System.Activities.DurableInstancing
{
using System;
using System.Runtime.DurableInstancing;
class DetectActivatableWorkflowsTask : PersistenceTask
{
public DetectActivatableWorkflowsTask(SqlWorkflowInstanceStore store, SqlWorkflowInstanceStoreLock storeLock, TimeSpan taskInterval)
: base(store, storeLock, new DetectActivatableWorkflowsCommand(), taskInterval, SqlWorkflowInstanceStoreConstants.DefaultTaskTimeout, false)
{
}
public override void ResetTimer(bool fireImmediately, TimeSpan? taskIntervalOverride)
{
InstanceOwner instanceOwner;
if (base.Store.FindEvent(HasActivatableWorkflowEvent.Value, out instanceOwner) != null)
{
base.ResetTimer(fireImmediately, taskIntervalOverride);
}
}
protected override void HandleError(Exception exception)
{
if (TD.RunnableInstancesDetectionErrorIsEnabled())
{
TD.RunnableInstancesDetectionError(exception);
}
this.ResetTimer(false);
}
}
}

View File

@@ -0,0 +1,100 @@
//-----------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
namespace System.Activities.DurableInstancing
{
using System.Data;
using System.Data.SqlClient;
using System.Globalization;
using System.Runtime.DurableInstancing;
using System.Transactions;
using System.Xml.Linq;
using System.Runtime;
sealed class DetectRunnableInstancesAsyncResult : SqlWorkflowInstanceStoreAsyncResult
{
static readonly string commandText = string.Format(CultureInfo.InvariantCulture, "{0}.[DetectRunnableInstances]", SqlWorkflowInstanceStoreConstants.DefaultSchema);
public DetectRunnableInstancesAsyncResult
(
InstancePersistenceContext context,
InstancePersistenceCommand command,
SqlWorkflowInstanceStore store,
SqlWorkflowInstanceStoreLock storeLock,
Transaction currentTransaction,
TimeSpan timeout,
AsyncCallback callback,
object state
) :
base(context, command, store, storeLock, currentTransaction, timeout, callback, state)
{
}
protected override string ConnectionString
{
get
{
SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(base.Store.CachedConnectionString);
builder.ApplicationName = SqlWorkflowInstanceStore.CommonConnectionPoolName;
return builder.ToString();
}
}
protected override void GenerateSqlCommand(SqlCommand sqlCommand)
{
sqlCommand.Parameters.Add(new SqlParameter { ParameterName = "@workflowHostType", SqlDbType = SqlDbType.UniqueIdentifier, Value = base.Store.WorkflowHostType });
if (base.Store.DatabaseVersion >= StoreUtilities.Version45)
{
sqlCommand.Parameters.Add(new SqlParameter { ParameterName = "@surrogateLockOwnerId", SqlDbType = SqlDbType.BigInt, Value = base.StoreLock.SurrogateLockOwnerId });
}
}
protected override string GetSqlCommandText()
{
return DetectRunnableInstancesAsyncResult.commandText;
}
protected override CommandType GetSqlCommandType()
{
return CommandType.StoredProcedure;
}
protected override Exception ProcessSqlResult(SqlDataReader reader)
{
Exception exception = StoreUtilities.GetNextResultSet(base.InstancePersistenceCommand.Name, reader);
if (exception == null)
{
bool instancesExist = !reader.IsDBNull(1);
TimeSpan? timeTillNextPoll = null;
bool instancesReadyToRun = false;
if (instancesExist)
{
DateTime expirationTime = reader.GetDateTime(1);
DateTime utcNow = reader.GetDateTime(2);
if (expirationTime <= utcNow)
{
instancesReadyToRun = true;
}
else
{
timeTillNextPoll = expirationTime.Subtract(utcNow);
}
}
if (instancesReadyToRun)
{
base.Store.UpdateEventStatus(true, HasRunnableWorkflowEvent.Value);
}
else
{
base.Store.UpdateEventStatus(false, HasRunnableWorkflowEvent.Value);
base.StoreLock.InstanceDetectionTask.ResetTimer(false, timeTillNextPoll);
}
}
return exception;
}
}
}

View File

@@ -0,0 +1,16 @@
//-----------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
namespace System.Activities.DurableInstancing
{
using System.Runtime.DurableInstancing;
sealed class DetectRunnableInstancesCommand : InstancePersistenceCommand
{
public DetectRunnableInstancesCommand() :
base(SqlWorkflowInstanceStoreConstants.DurableInstancingNamespace.GetName("DetectRunnableInstances"))
{
}
}
}

View File

@@ -0,0 +1,36 @@
//----------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//----------------------------------------------------------------
namespace System.Activities.DurableInstancing
{
using System;
using System.Runtime.DurableInstancing;
class DetectRunnableInstancesTask : PersistenceTask
{
public DetectRunnableInstancesTask(SqlWorkflowInstanceStore store, SqlWorkflowInstanceStoreLock storeLock, TimeSpan taskInterval)
: base(store, storeLock, new DetectRunnableInstancesCommand(), taskInterval, SqlWorkflowInstanceStoreConstants.DefaultTaskTimeout, false)
{
}
public override void ResetTimer(bool fireImmediately, TimeSpan? taskIntervalOverride)
{
InstanceOwner instanceOwner;
if (base.Store.FindEvent(HasRunnableWorkflowEvent.Value, out instanceOwner) != null)
{
base.ResetTimer(fireImmediately, taskIntervalOverride);
}
}
protected override void HandleError(Exception exception)
{
if (TD.RunnableInstancesDetectionErrorIsEnabled())
{
TD.RunnableInstancesDetectionError(exception);
}
this.ResetTimer(false);
}
}
}

View File

@@ -0,0 +1,67 @@
//-----------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
namespace System.Activities.DurableInstancing
{
using System.Data;
using System.Data.SqlClient;
using System.Globalization;
using System.Runtime.DurableInstancing;
using System.Transactions;
using System.Xml.Linq;
sealed class ExtendLockAsyncResult : SqlWorkflowInstanceStoreAsyncResult
{
static readonly string commandText = string.Format(CultureInfo.InvariantCulture, "{0}.[ExtendLock]", SqlWorkflowInstanceStoreConstants.DefaultSchema);
public ExtendLockAsyncResult
(
InstancePersistenceContext context,
InstancePersistenceCommand command,
SqlWorkflowInstanceStore store,
SqlWorkflowInstanceStoreLock storeLock,
Transaction currentTransaction,
TimeSpan timeout,
AsyncCallback callback,
object state
) :
base(context, command, store, storeLock, currentTransaction, timeout, int.MaxValue, callback, state)
{
}
protected override string ConnectionString
{
get
{
SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(base.Store.CachedConnectionString);
builder.ApplicationName = SqlWorkflowInstanceStore.CommonConnectionPoolName;
return builder.ToString();
}
}
protected override void GenerateSqlCommand(SqlCommand sqlCommand)
{
long surrogateOwnerId = base.StoreLock.SurrogateLockOwnerId;
double lockTimeout = base.Store.BufferedHostLockRenewalPeriod.TotalSeconds;
sqlCommand.Parameters.Add(new SqlParameter { ParameterName = "@surrogateLockOwnerId", SqlDbType = SqlDbType.BigInt, Value = surrogateOwnerId });
sqlCommand.Parameters.Add(new SqlParameter { ParameterName = "@lockTimeout", SqlDbType = SqlDbType.Int, Value = lockTimeout });
}
protected override string GetSqlCommandText()
{
return ExtendLockAsyncResult.commandText;
}
protected override CommandType GetSqlCommandType()
{
return CommandType.StoredProcedure;
}
protected override Exception ProcessSqlResult(SqlDataReader reader)
{
return StoreUtilities.CheckRemainingResultSetForErrors(base.InstancePersistenceCommand.Name, reader);
}
}
}

View File

@@ -0,0 +1,16 @@
//-----------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
namespace System.Activities.DurableInstancing
{
using System.Runtime.DurableInstancing;
sealed class ExtendLockCommand : InstancePersistenceCommand
{
public ExtendLockCommand() :
base(SqlWorkflowInstanceStoreConstants.DurableInstancingNamespace.GetName("ExtendLock"))
{
}
}
}

View File

@@ -0,0 +1,45 @@
//-----------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
namespace System.Activities.DurableInstancing
{
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Xml.Linq;
sealed class GZipObjectSerializer : DefaultObjectSerializer
{
protected override Dictionary<XName, object> DeserializePropertyBag(Stream stream)
{
using (GZipStream gzip = new GZipStream(stream, CompressionMode.Decompress, true))
{
return base.DeserializePropertyBag(gzip);
}
}
protected override object DeserializeValue(Stream stream)
{
using (GZipStream gzip = new GZipStream(stream, CompressionMode.Decompress, true))
{
return base.DeserializeValue(gzip);
}
}
protected override void SerializePropertyBag(Stream stream, Dictionary<XName, object> propertyBag)
{
using (GZipStream gzip = new GZipStream(stream, CompressionLevel.Fastest, true))
{
base.SerializePropertyBag(gzip, propertyBag);
}
}
protected override void SerializeValue(Stream stream, object value)
{
using (GZipStream gzip = new GZipStream(stream, CompressionLevel.Fastest, true))
{
base.SerializeValue(gzip, value);
}
}
}
}

View File

@@ -0,0 +1,13 @@
//-----------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
namespace System.Activities.DurableInstancing
{
using System;
interface ILoadRetryStrategy
{
TimeSpan RetryDelay(int retryAttempt);
}
}

View File

@@ -0,0 +1,17 @@
//-----------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
namespace System.Activities.DurableInstancing
{
using System.Collections.Generic;
using System.Xml.Linq;
interface IObjectSerializer
{
object DeserializeValue(byte[] bytes);
Dictionary<XName, object> DeserializePropertyBag(byte[] bytes);
ArraySegment<byte> SerializeValue(object value);
ArraySegment<byte> SerializePropertyBag(Dictionary<XName, object> value);
}
}

View File

@@ -0,0 +1,27 @@
//-----------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
namespace System.Activities.DurableInstancing
{
using System.Runtime.DurableInstancing;
using System.Runtime.Serialization;
using System.Security;
using System.Xml.Linq;
[Serializable]
class InstanceAlreadyLockedToOwnerException : InstancePersistenceCommandException
{
public InstanceAlreadyLockedToOwnerException(XName commandName, Guid instanceId, long instanceVersion)
: base(commandName, instanceId)
{
this.InstanceVersion = instanceVersion;
}
public long InstanceVersion
{
get;
private set;
}
}
}

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