Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / WF / RunTime / Hosting / WorkflowPersistenceService.cs / 1305376 / WorkflowPersistenceService.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
using System;
using System.IO;
using System.IO.Compression;
using System.Workflow.Runtime;
using System.Workflow.ComponentModel;
using System.Diagnostics;
namespace System.Workflow.Runtime.Hosting
{
/// Service for saving engine state.
public abstract class WorkflowPersistenceService : WorkflowRuntimeService
{
/// Saves the state of a workflow instance.
/// The workflow instance state to save
internal protected abstract void SaveWorkflowInstanceState(Activity rootActivity, bool unlock);
///
///
internal protected abstract void UnlockWorkflowInstanceState(Activity rootActivity);
/// Loads the state of a workflow instance.
/// The unique ID of the instance to load
/// The workflow instance state
internal protected abstract Activity LoadWorkflowInstanceState(Guid instanceId);
/// Saves the state of a completed scope.
/// The completed scope to save
internal protected abstract void SaveCompletedContextActivity(Activity activity);
/// Loads the state of a completed scope
/// The unique identifier of the completed scope
/// The completed scope or null
internal protected abstract Activity LoadCompletedContextActivity(Guid scopeId, Activity outerActivity);
///
///
/// The value of the "UnloadOnIdle" flag
internal protected abstract bool UnloadOnIdle(Activity activity);
static protected byte[] GetDefaultSerializedForm(Activity activity)
{
DateTime startTime = DateTime.Now;
Byte[] result;
Debug.Assert(activity != null, "Null activity");
using (MemoryStream stream = new MemoryStream(10240))
{
stream.Position = 0;
activity.Save(stream);
using (MemoryStream compressedStream = new MemoryStream((int)stream.Length))
{
using (GZipStream gzs = new GZipStream(compressedStream, CompressionMode.Compress, true))
{
gzs.Write(stream.GetBuffer(), 0, (int)stream.Length);
}
ActivityExecutionContextInfo executionContextInfo = (ActivityExecutionContextInfo)activity.GetValue(Activity.ActivityExecutionContextInfoProperty);
TimeSpan timeElapsed = DateTime.Now - startTime;
WorkflowTrace.Host.TraceEvent(TraceEventType.Information, 0,
"Serialized a {0} with id {1} to length {2}. Took {3}.",
executionContextInfo, executionContextInfo.ContextGuid, compressedStream.Length, timeElapsed);
result = compressedStream.GetBuffer();
Array.Resize(ref result, Convert.ToInt32(compressedStream.Length));
}
}
return result;
}
static protected Activity RestoreFromDefaultSerializedForm(Byte[] activityBytes, Activity outerActivity)
{
DateTime startTime = DateTime.Now;
Activity state;
MemoryStream stream = new MemoryStream(activityBytes);
stream.Position = 0;
using (GZipStream gzs = new GZipStream(stream, CompressionMode.Decompress, true))
{
state = Activity.Load(gzs, outerActivity);
}
Debug.Assert(state != null, "invalid state recovered");
TimeSpan timeElapsed = DateTime.Now - startTime;
WorkflowTrace.Host.TraceEvent(TraceEventType.Information, 0,
"Deserialized a {0} to length {1}. Took {2}.",
state, stream.Length, timeElapsed);
return state;
}
static protected internal bool GetIsBlocked(Activity rootActivity)
{
return (bool)rootActivity.GetValue(WorkflowExecutor.IsBlockedProperty);
}
static protected internal string GetSuspendOrTerminateInfo(Activity rootActivity)
{
return (string)rootActivity.GetValue(WorkflowExecutor.SuspendOrTerminateInfoProperty);
}
static protected internal WorkflowStatus GetWorkflowStatus(Activity rootActivity)
{
return (WorkflowStatus)rootActivity.GetValue(WorkflowExecutor.WorkflowStatusProperty);
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
using System;
using System.IO;
using System.IO.Compression;
using System.Workflow.Runtime;
using System.Workflow.ComponentModel;
using System.Diagnostics;
namespace System.Workflow.Runtime.Hosting
{
/// Service for saving engine state.
public abstract class WorkflowPersistenceService : WorkflowRuntimeService
{
/// Saves the state of a workflow instance.
/// The workflow instance state to save
internal protected abstract void SaveWorkflowInstanceState(Activity rootActivity, bool unlock);
///
///
internal protected abstract void UnlockWorkflowInstanceState(Activity rootActivity);
/// Loads the state of a workflow instance.
/// The unique ID of the instance to load
/// The workflow instance state
internal protected abstract Activity LoadWorkflowInstanceState(Guid instanceId);
/// Saves the state of a completed scope.
/// The completed scope to save
internal protected abstract void SaveCompletedContextActivity(Activity activity);
/// Loads the state of a completed scope
/// The unique identifier of the completed scope
/// The completed scope or null
internal protected abstract Activity LoadCompletedContextActivity(Guid scopeId, Activity outerActivity);
///
///
/// The value of the "UnloadOnIdle" flag
internal protected abstract bool UnloadOnIdle(Activity activity);
static protected byte[] GetDefaultSerializedForm(Activity activity)
{
DateTime startTime = DateTime.Now;
Byte[] result;
Debug.Assert(activity != null, "Null activity");
using (MemoryStream stream = new MemoryStream(10240))
{
stream.Position = 0;
activity.Save(stream);
using (MemoryStream compressedStream = new MemoryStream((int)stream.Length))
{
using (GZipStream gzs = new GZipStream(compressedStream, CompressionMode.Compress, true))
{
gzs.Write(stream.GetBuffer(), 0, (int)stream.Length);
}
ActivityExecutionContextInfo executionContextInfo = (ActivityExecutionContextInfo)activity.GetValue(Activity.ActivityExecutionContextInfoProperty);
TimeSpan timeElapsed = DateTime.Now - startTime;
WorkflowTrace.Host.TraceEvent(TraceEventType.Information, 0,
"Serialized a {0} with id {1} to length {2}. Took {3}.",
executionContextInfo, executionContextInfo.ContextGuid, compressedStream.Length, timeElapsed);
result = compressedStream.GetBuffer();
Array.Resize(ref result, Convert.ToInt32(compressedStream.Length));
}
}
return result;
}
static protected Activity RestoreFromDefaultSerializedForm(Byte[] activityBytes, Activity outerActivity)
{
DateTime startTime = DateTime.Now;
Activity state;
MemoryStream stream = new MemoryStream(activityBytes);
stream.Position = 0;
using (GZipStream gzs = new GZipStream(stream, CompressionMode.Decompress, true))
{
state = Activity.Load(gzs, outerActivity);
}
Debug.Assert(state != null, "invalid state recovered");
TimeSpan timeElapsed = DateTime.Now - startTime;
WorkflowTrace.Host.TraceEvent(TraceEventType.Information, 0,
"Deserialized a {0} to length {1}. Took {2}.",
state, stream.Length, timeElapsed);
return state;
}
static protected internal bool GetIsBlocked(Activity rootActivity)
{
return (bool)rootActivity.GetValue(WorkflowExecutor.IsBlockedProperty);
}
static protected internal string GetSuspendOrTerminateInfo(Activity rootActivity)
{
return (string)rootActivity.GetValue(WorkflowExecutor.SuspendOrTerminateInfoProperty);
}
static protected internal WorkflowStatus GetWorkflowStatus(Activity rootActivity)
{
return (WorkflowStatus)rootActivity.GetValue(WorkflowExecutor.WorkflowStatusProperty);
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- WinFormsSpinner.cs
- GACIdentityPermission.cs
- RegexCompilationInfo.cs
- ArgumentValidation.cs
- WindowsMenu.cs
- DesignerAttributeInfo.cs
- DelayDesigner.cs
- XmlSignificantWhitespace.cs
- SingleAnimationUsingKeyFrames.cs
- RootBrowserWindow.cs
- TimeStampChecker.cs
- DesigntimeLicenseContext.cs
- LicenseContext.cs
- VBIdentifierTrimConverter.cs
- UriTemplateEquivalenceComparer.cs
- DataSourceProvider.cs
- FontStyle.cs
- AlgoModule.cs
- Polyline.cs
- Predicate.cs
- cookiecontainer.cs
- CompositeActivityTypeDescriptor.cs
- CacheDependency.cs
- HuffmanTree.cs
- DateTimeConstantAttribute.cs
- SHA1.cs
- SessionPageStateSection.cs
- CodeTypeParameter.cs
- PropertyValue.cs
- MarshalDirectiveException.cs
- TextBlock.cs
- EntityWrapperFactory.cs
- DocumentPageTextView.cs
- GridViewColumn.cs
- AliasGenerator.cs
- DataBoundControlHelper.cs
- Message.cs
- BinaryKeyIdentifierClause.cs
- TextDataBindingHandler.cs
- IncrementalReadDecoders.cs
- OptimisticConcurrencyException.cs
- TextDecorationCollection.cs
- RepeaterCommandEventArgs.cs
- FolderBrowserDialog.cs
- ValueTypeFixupInfo.cs
- ServiceSecurityContext.cs
- XhtmlBasicValidatorAdapter.cs
- PackWebRequestFactory.cs
- ApplyImportsAction.cs
- XmlAnyElementAttribute.cs
- DateTimeSerializationSection.cs
- AssociationSetEnd.cs
- ReadWriteObjectLock.cs
- FormViewUpdateEventArgs.cs
- WebHeaderCollection.cs
- RelationshipSet.cs
- EncryptedHeader.cs
- RectAnimationClockResource.cs
- ColorConverter.cs
- SubMenuStyleCollection.cs
- GeneralTransform3DGroup.cs
- _NegotiateClient.cs
- Int32RectConverter.cs
- CompositeKey.cs
- UrlEncodedParameterWriter.cs
- HtmlTableRowCollection.cs
- xmlsaver.cs
- BinaryCommonClasses.cs
- bidPrivateBase.cs
- RtfToXamlLexer.cs
- ExtensionSimplifierMarkupObject.cs
- SelectionProviderWrapper.cs
- WindowsFormsHelpers.cs
- SafeHandle.cs
- SafeRightsManagementSessionHandle.cs
- ObjectTokenCategory.cs
- BindToObject.cs
- DataGridViewCheckBoxCell.cs
- ModelVisual3D.cs
- VisualBrush.cs
- dbdatarecord.cs
- NeutralResourcesLanguageAttribute.cs
- TdsParserSafeHandles.cs
- WebBrowserNavigatedEventHandler.cs
- DataViewSettingCollection.cs
- LocalizationComments.cs
- ObjectView.cs
- DocumentPageView.cs
- PackageRelationshipSelector.cs
- MenuItemBinding.cs
- _BasicClient.cs
- NavigatorOutput.cs
- XmlSchemaSequence.cs
- StrongNameHelpers.cs
- SqlUserDefinedTypeAttribute.cs
- activationcontext.cs
- ListViewUpdateEventArgs.cs
- CursorInteropHelper.cs
- AccessText.cs
- ChildrenQuery.cs