1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
|
//-----------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
namespace System.Activities
{
using System;
using System.Runtime;
using System.Runtime.Serialization;
using System.Runtime.DurableInstancing;
[DataContract]
public sealed class BookmarkScopeHandle : Handle
{
BookmarkScope bookmarkScope;
static BookmarkScopeHandle defaultBookmarkScopeHandle = new BookmarkScopeHandle(BookmarkScope.Default);
public BookmarkScopeHandle()
{
}
internal BookmarkScopeHandle(BookmarkScope bookmarkScope)
{
this.bookmarkScope = bookmarkScope;
if (bookmarkScope != null)
{
this.bookmarkScope.IncrementHandleReferenceCount();
}
}
public static BookmarkScopeHandle Default
{
get
{
return defaultBookmarkScopeHandle;
}
}
public BookmarkScope BookmarkScope
{
get
{
return this.bookmarkScope;
}
}
[DataMember(EmitDefaultValue = false, Name = "bookmarkScope")]
internal BookmarkScope SerializedBookmarkScope
{
get { return this.bookmarkScope; }
set
{
this.bookmarkScope = value;
if (this.bookmarkScope != null)
{
this.bookmarkScope.IncrementHandleReferenceCount();
}
}
}
//To be called from public APIs that need to verify the passed in context
void ThrowIfContextIsNullOrDisposed(NativeActivityContext context)
{
if (context == null)
{
throw FxTrace.Exception.ArgumentNull("context");
}
context.ThrowIfDisposed();
}
public void CreateBookmarkScope(NativeActivityContext context)
{
this.ThrowIfContextIsNullOrDisposed(context);
if (this.bookmarkScope != null)
{
throw FxTrace.Exception.AsError(new InvalidOperationException(SR.CreateBookmarkScopeFailed));
}
this.ThrowIfUninitialized();
this.bookmarkScope = context.CreateBookmarkScope(Guid.Empty, this);
this.bookmarkScope.IncrementHandleReferenceCount();
}
public void CreateBookmarkScope(NativeActivityContext context, Guid scopeId)
{
this.ThrowIfContextIsNullOrDisposed(context);
if (this.bookmarkScope != null)
{
throw FxTrace.Exception.AsError(new InvalidOperationException(SR.CreateBookmarkScopeFailed));
}
this.ThrowIfUninitialized();
this.bookmarkScope = context.CreateBookmarkScope(scopeId, this);
this.bookmarkScope.IncrementHandleReferenceCount();
}
public void Initialize(NativeActivityContext context, Guid scope)
{
this.ThrowIfContextIsNullOrDisposed(context);
this.ThrowIfUninitialized();
this.bookmarkScope.Initialize(context, scope);
}
protected override void OnUninitialize(HandleInitializationContext context)
{
if (this.bookmarkScope != null)
{
int scopeRefCount = this.bookmarkScope.DecrementHandleReferenceCount();
DisassociateInstanceKeysExtension extension = context.GetExtension<DisassociateInstanceKeysExtension>();
// We only unregister the BookmarkScope if the extension exists and is enabled and if we had the last reference to it.
if ((extension != null) && extension.AutomaticDisassociationEnabled && (scopeRefCount == 0))
{
context.UnregisterBookmarkScope(this.bookmarkScope);
}
}
base.OnUninitialize(context);
}
}
}
|