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 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007
|
//----------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//----------------------------------------------------------------
namespace System.ServiceModel.Activities
{
using System.Activities;
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.Threading;
using System.Transactions;
using SR2 = System.ServiceModel.Activities.SR;
public class WorkflowUpdateableControlClient : ClientBase<IWorkflowUpdateableInstanceManagement>
{
BeginOperationDelegate onBeginAbandonDelegate;
EndOperationDelegate onEndAbandonDelegate;
SendOrPostCallback onAbandonCompleteDelegate;
BeginOperationDelegate onBeginCancelDelegate;
EndOperationDelegate onEndCancelDelegate;
SendOrPostCallback onCancelCompleteDelegate;
BeginOperationDelegate onBeginRunDelegate;
EndOperationDelegate onEndRunDelegate;
SendOrPostCallback onRunCompleteDelegate;
BeginOperationDelegate onBeginSuspendDelegate;
EndOperationDelegate onEndSuspendDelegate;
SendOrPostCallback onSuspendCompleteDelegate;
BeginOperationDelegate onBeginUnsuspendDelegate;
EndOperationDelegate onEndUnsuspendDelegate;
SendOrPostCallback onUnsuspendCompleteDelegate;
BeginOperationDelegate onBeginTerminateDelegate;
EndOperationDelegate onEndTerminateDelegate;
SendOrPostCallback onTerminateCompleteDelegate;
BeginOperationDelegate onBeginUpdateDelegate;
EndOperationDelegate onEndUpdateDelegate;
SendOrPostCallback onUpdateCompleteDelegate;
bool checkedBinding;
bool supportsTransactedInvoke;
public WorkflowUpdateableControlClient()
: base()
{
}
public WorkflowUpdateableControlClient(string endpointConfigurationName)
: base(endpointConfigurationName)
{
}
public WorkflowUpdateableControlClient(string endpointConfigurationName, EndpointAddress remoteAddress)
: base(endpointConfigurationName, remoteAddress)
{
}
public WorkflowUpdateableControlClient(string endpointConfigurationName, string remoteAddress)
: base(endpointConfigurationName, remoteAddress)
{
}
public WorkflowUpdateableControlClient(Binding binding, EndpointAddress remoteAddress)
: base(binding, remoteAddress)
{
}
public WorkflowUpdateableControlClient(WorkflowControlEndpoint workflowEndpoint)
: base(workflowEndpoint.Binding, workflowEndpoint.Address)
{
}
public event EventHandler<AsyncCompletedEventArgs> AbandonCompleted;
public event EventHandler<AsyncCompletedEventArgs> CancelCompleted;
public event EventHandler<AsyncCompletedEventArgs> RunCompleted;
public event EventHandler<AsyncCompletedEventArgs> SuspendCompleted;
public event EventHandler<AsyncCompletedEventArgs> UnsuspendCompleted;
public event EventHandler<AsyncCompletedEventArgs> TerminateCompleted;
public event EventHandler<AsyncCompletedEventArgs> UpdateCompleted;
bool SupportsTransactedInvoke
{
get
{
if (!this.checkedBinding)
{
foreach (BindingElement bindingElement in base.Endpoint.Binding.CreateBindingElements())
{
TransactionFlowBindingElement transactionFlowElement = bindingElement as TransactionFlowBindingElement;
if (transactionFlowElement != null)
{
this.supportsTransactedInvoke = true;
break;
}
}
this.checkedBinding = true;
}
return this.supportsTransactedInvoke;
}
}
bool IsTransactedInvoke
{
get
{
return this.SupportsTransactedInvoke && Transaction.Current != null;
}
}
[Fx.Tag.InheritThrows(FromDeclaringType = typeof(IWorkflowInstanceManagement), From = "Abandon")]
public void Abandon(Guid instanceId)
{
Abandon(instanceId, null);
}
[Fx.Tag.InheritThrows(From = "Abandon")]
public void Abandon(Guid instanceId, string reason)
{
base.Channel.Abandon(instanceId, reason);
}
[Fx.Tag.InheritThrows(From = "Abandon")]
public void AbandonAsync(Guid instanceId)
{
AbandonAsync(instanceId, null, null);
}
[Fx.Tag.InheritThrows(From = "Abandon")]
public void AbandonAsync(Guid instanceId, object userState)
{
AbandonAsync(instanceId, null, userState);
}
[Fx.Tag.InheritThrows(From = "Abandon")]
public void AbandonAsync(Guid instanceId, string reason)
{
AbandonAsync(instanceId, reason, null);
}
[Fx.Tag.InheritThrows(From = "Abandon")]
public void AbandonAsync(Guid instanceId, string reason, object userState)
{
if (this.onBeginAbandonDelegate == null)
{
this.onBeginAbandonDelegate = new BeginOperationDelegate(OnBeginAbandon);
this.onEndAbandonDelegate = new EndOperationDelegate(OnEndAbandon);
this.onAbandonCompleteDelegate = Fx.ThunkCallback(new SendOrPostCallback(OnAbandonCompleted));
}
base.InvokeAsync(this.onBeginAbandonDelegate, new object[] { instanceId, reason },
this.onEndAbandonDelegate, this.onAbandonCompleteDelegate, userState);
}
[Fx.Tag.InheritThrows(FromDeclaringType = typeof(IWorkflowInstanceManagement), From = "Cancel")]
public void Cancel(Guid instanceId)
{
if (this.IsTransactedInvoke)
{
base.Channel.TransactedCancel(instanceId);
}
else
{
base.Channel.Cancel((instanceId));
}
}
[Fx.Tag.InheritThrows(FromDeclaringType = typeof(IWorkflowInstanceManagement), From = "Cancel")]
public void CancelAsync(Guid instanceId)
{
this.CancelAsync(instanceId, null);
}
[Fx.Tag.InheritThrows(FromDeclaringType = typeof(IWorkflowInstanceManagement), From = "Cancel")]
public void CancelAsync(Guid instanceId, object userState)
{
if (this.onBeginCancelDelegate == null)
{
this.onBeginCancelDelegate = new BeginOperationDelegate(OnBeginCancel);
this.onEndCancelDelegate = new EndOperationDelegate(OnEndCancel);
this.onCancelCompleteDelegate = Fx.ThunkCallback(new SendOrPostCallback(OnCancelCompleted));
}
base.InvokeAsync(this.onBeginCancelDelegate, new object[] { instanceId },
this.onEndCancelDelegate, this.onCancelCompleteDelegate, userState);
}
[Fx.Tag.InheritThrows(FromDeclaringType = typeof(IWorkflowInstanceManagement), From = "Run")]
public void Run(Guid instanceId)
{
if (this.IsTransactedInvoke)
{
base.Channel.TransactedRun((instanceId));
}
else
{
base.Channel.Run((instanceId));
}
}
[Fx.Tag.InheritThrows(FromDeclaringType = typeof(IWorkflowInstanceManagement), From = "Run")]
public void RunAsync(Guid instanceId)
{
this.RunAsync(instanceId, null);
}
[Fx.Tag.InheritThrows(FromDeclaringType = typeof(IWorkflowInstanceManagement), From = "Run")]
public void RunAsync(Guid instanceId, object userState)
{
if (this.onBeginRunDelegate == null)
{
this.onBeginRunDelegate = new BeginOperationDelegate(OnBeginRun);
this.onEndRunDelegate = new EndOperationDelegate(OnEndRun);
this.onRunCompleteDelegate = Fx.ThunkCallback(new SendOrPostCallback(OnRunCompleted));
}
base.InvokeAsync(this.onBeginRunDelegate, new object[] { instanceId },
this.onEndRunDelegate, this.onRunCompleteDelegate, userState);
}
[Fx.Tag.InheritThrows(FromDeclaringType = typeof(IWorkflowInstanceManagement), From = "Suspend")]
public void Suspend(Guid instanceId)
{
Suspend(instanceId, SR2.DefaultSuspendReason);
}
[Fx.Tag.InheritThrows(From = "Suspend")]
public void Suspend(Guid instanceId, string reason)
{
if (this.IsTransactedInvoke)
{
base.Channel.TransactedSuspend(instanceId, reason);
}
else
{
base.Channel.Suspend(instanceId, reason);
}
}
[Fx.Tag.InheritThrows(From = "Suspend")]
public void SuspendAsync(Guid instanceId)
{
this.SuspendAsync(instanceId, SR2.DefaultSuspendReason);
}
[Fx.Tag.InheritThrows(From = "Suspend")]
public void SuspendAsync(Guid instanceId, string reason)
{
this.SuspendAsync(instanceId, reason, null);
}
[Fx.Tag.InheritThrows(From = "Suspend")]
public void SuspendAsync(Guid instanceId, object userState)
{
this.SuspendAsync(instanceId, SR2.DefaultSuspendReason, userState);
}
[Fx.Tag.InheritThrows(From = "Suspend")]
public void SuspendAsync(Guid instanceId, string reason, object userState)
{
if (this.onBeginSuspendDelegate == null)
{
this.onEndSuspendDelegate = new EndOperationDelegate(OnEndSuspend);
this.onSuspendCompleteDelegate = Fx.ThunkCallback(new SendOrPostCallback(OnSuspendCompleted));
this.onBeginSuspendDelegate = new BeginOperationDelegate(OnBeginSuspend);
}
base.InvokeAsync(this.onBeginSuspendDelegate, new object[] { instanceId, reason },
this.onEndSuspendDelegate, this.onSuspendCompleteDelegate, userState);
}
[Fx.Tag.InheritThrows(FromDeclaringType = typeof(IWorkflowInstanceManagement), From = "Unsuspend")]
public void Unsuspend(Guid instanceId)
{
if (this.IsTransactedInvoke)
{
base.Channel.TransactedUnsuspend(instanceId);
}
else
{
base.Channel.Unsuspend(instanceId);
}
}
[Fx.Tag.InheritThrows(From = "Unsuspend")]
public void UnsuspendAsync(Guid instanceId)
{
this.UnsuspendAsync(instanceId, null);
}
[Fx.Tag.InheritThrows(From = "Unsuspend")]
public void UnsuspendAsync(Guid instanceId, object userState)
{
if (this.onBeginUnsuspendDelegate == null)
{
this.onBeginUnsuspendDelegate = new BeginOperationDelegate(OnBeginUnsuspend);
this.onEndUnsuspendDelegate = new EndOperationDelegate(OnEndUnsuspend);
this.onUnsuspendCompleteDelegate = Fx.ThunkCallback(new SendOrPostCallback(OnUnsuspendCompleted));
}
base.InvokeAsync(this.onBeginUnsuspendDelegate, new object[] { instanceId },
this.onEndUnsuspendDelegate, this.onUnsuspendCompleteDelegate, userState);
}
[Fx.Tag.InheritThrows(FromDeclaringType = typeof(IWorkflowInstanceManagement), From = "Terminate")]
public void Terminate(Guid instanceId)
{
Terminate(instanceId, SR2.DefaultTerminationReason);
}
[Fx.Tag.InheritThrows(From = "Terminate")]
public void Terminate(Guid instanceId, string reason)
{
if (this.IsTransactedInvoke)
{
base.Channel.TransactedTerminate(instanceId, reason);
}
else
{
base.Channel.Terminate(instanceId, reason);
}
}
[Fx.Tag.InheritThrows(FromDeclaringType = typeof(IWorkflowInstanceManagement), From = "Terminate")]
public void TerminateAsync(Guid instanceId)
{
this.TerminateAsync(instanceId, SR2.DefaultTerminationReason);
}
[Fx.Tag.InheritThrows(From = "Terminate")]
public void TerminateAsync(Guid instanceId, string reason)
{
this.TerminateAsync(instanceId, reason, null);
}
[Fx.Tag.InheritThrows(From = "Terminate")]
public void TerminateAsync(Guid instanceId, object userState)
{
this.TerminateAsync(instanceId, SR2.DefaultTerminationReason, userState);
}
[Fx.Tag.InheritThrows(From = "Terminate")]
public void TerminateAsync(Guid instanceId, string reason, object userState)
{
if (this.onBeginTerminateDelegate == null)
{
this.onEndTerminateDelegate = new EndOperationDelegate(OnEndTerminate);
this.onTerminateCompleteDelegate = Fx.ThunkCallback(new SendOrPostCallback(OnTerminateCompleted));
this.onBeginTerminateDelegate = new BeginOperationDelegate(OnBeginTerminate);
}
base.InvokeAsync(this.onBeginTerminateDelegate, new object[] { instanceId, reason },
this.onEndTerminateDelegate, this.onTerminateCompleteDelegate, userState);
}
[Fx.Tag.InheritThrows(FromDeclaringType = typeof(IWorkflowInstanceManagement), From = "Update")]
public void Update(Guid instanceId, WorkflowIdentity updatedDefinitionIdentity)
{
if (this.IsTransactedInvoke)
{
base.Channel.TransactedUpdate(instanceId, updatedDefinitionIdentity);
}
else
{
base.Channel.Update(instanceId, updatedDefinitionIdentity);
}
}
[Fx.Tag.InheritThrows(FromDeclaringType = typeof(IWorkflowUpdateableInstanceManagement), From = "Update")]
public void UpdateAsync(Guid instanceId, WorkflowIdentity updatedDefinitionIdentity)
{
this.UpdateAsync(instanceId, updatedDefinitionIdentity, null);
}
[Fx.Tag.InheritThrows(FromDeclaringType = typeof(IWorkflowInstanceManagement), From = "Update")]
public void UpdateAsync(Guid instanceId, WorkflowIdentity updatedDefinitionIdentity, object userState)
{
if (this.onBeginUpdateDelegate == null)
{
this.onBeginUpdateDelegate = new BeginOperationDelegate(OnBeginUpdate);
this.onEndUpdateDelegate = new EndOperationDelegate(OnEndUpdate);
this.onUpdateCompleteDelegate = Fx.ThunkCallback(new SendOrPostCallback(OnUpdateCompleted));
}
base.InvokeAsync(this.onBeginUpdateDelegate, new object[] { instanceId, updatedDefinitionIdentity },
this.onEndUpdateDelegate, this.onUpdateCompleteDelegate, userState);
}
[Fx.Tag.InheritThrows(From = "Abandon")]
public IAsyncResult BeginAbandon(Guid instanceId, AsyncCallback callback, object state)
{
return BeginAbandon(instanceId, null, callback, state);
}
[Fx.Tag.InheritThrows(From = "Abandon")]
public IAsyncResult BeginAbandon(Guid instanceId, string reason, AsyncCallback callback, object state)
{
return base.Channel.BeginAbandon(instanceId, reason, callback, state);
}
[Fx.Tag.InheritThrows(From = "Abandon")]
public void EndAbandon(IAsyncResult result)
{
base.Channel.EndAbandon(result);
}
[Fx.Tag.InheritThrows(From = "Cancel")]
public IAsyncResult BeginCancel(Guid instanceId, AsyncCallback callback, object state)
{
return new CancelAsyncResult(base.Channel, this.IsTransactedInvoke, instanceId, callback, state);
}
[Fx.Tag.InheritThrows(From = "Cancel")]
public void EndCancel(IAsyncResult result)
{
CancelAsyncResult.End(result);
}
[Fx.Tag.InheritThrows(From = "Run")]
public IAsyncResult BeginRun(Guid instanceId, AsyncCallback callback, object state)
{
return new RunAsyncResult(base.Channel, this.IsTransactedInvoke, instanceId, callback, state);
}
[Fx.Tag.InheritThrows(From = "Run")]
public void EndRun(IAsyncResult result)
{
RunAsyncResult.End(result);
}
[Fx.Tag.InheritThrows(From = "Suspend")]
public IAsyncResult BeginSuspend(Guid instanceId, AsyncCallback callback, object state)
{
return BeginSuspend(instanceId, SR2.DefaultSuspendReason, callback, state);
}
[Fx.Tag.InheritThrows(From = "Suspend")]
public IAsyncResult BeginSuspend(Guid instanceId, string reason, AsyncCallback callback, object state)
{
return new SuspendAsyncResult(base.Channel, this.IsTransactedInvoke, instanceId, reason, callback, state);
}
[Fx.Tag.InheritThrows(From = "Suspend")]
public void EndSuspend(IAsyncResult result)
{
SuspendAsyncResult.End(result);
}
[Fx.Tag.InheritThrows(From = "Unsuspend")]
public IAsyncResult BeginUnsuspend(Guid instanceId, AsyncCallback callback, object state)
{
return new UnsuspendAsyncResult(base.Channel, this.IsTransactedInvoke, instanceId, callback, state);
}
[Fx.Tag.InheritThrows(From = "Unsuspend")]
public void EndUnsuspend(IAsyncResult result)
{
UnsuspendAsyncResult.End(result);
}
[Fx.Tag.InheritThrows(From = "Terminate")]
public IAsyncResult BeginTerminate(Guid instanceId, AsyncCallback callback, object state)
{
return BeginTerminate(instanceId, SR2.DefaultTerminationReason, callback, state);
}
[Fx.Tag.InheritThrows(From = "Terminate")]
public IAsyncResult BeginTerminate(Guid instanceId, string reason, AsyncCallback callback, object state)
{
return new TerminateAsyncResult(base.Channel, this.IsTransactedInvoke, instanceId, reason, callback, state);
}
[Fx.Tag.InheritThrows(From = "Terminate")]
public void EndTerminate(IAsyncResult result)
{
TerminateAsyncResult.End(result);
}
[Fx.Tag.InheritThrows(From = "Update")]
public IAsyncResult BeginUpdate(Guid instanceId, WorkflowIdentity updatedDefinitionIdentity, AsyncCallback callback, object state)
{
return new UpdateAsyncResult(base.Channel, this.IsTransactedInvoke, instanceId, updatedDefinitionIdentity, callback, state);
}
[Fx.Tag.InheritThrows(From = "Update")]
public void EndUpdate(IAsyncResult result)
{
UpdateAsyncResult.End(result);
}
void OnAbandonCompleted(object state)
{
EventHandler<AsyncCompletedEventArgs> abortCompleted = this.AbandonCompleted;
if (abortCompleted != null)
{
InvokeAsyncCompletedEventArgs e = (InvokeAsyncCompletedEventArgs)state;
abortCompleted(this,
new AsyncCompletedEventArgs(e.Error, e.Cancelled, e.UserState));
}
}
IAsyncResult OnBeginAbandon(object[] inputs, AsyncCallback callback, object state)
{
return this.BeginAbandon((Guid)inputs[0], (string)inputs[1], callback, state);
}
object[] OnEndAbandon(IAsyncResult result)
{
this.EndAbandon(result);
return null;
}
void OnCancelCompleted(object state)
{
EventHandler<AsyncCompletedEventArgs> cancelCompleted = this.CancelCompleted;
if (cancelCompleted != null)
{
InvokeAsyncCompletedEventArgs e = (InvokeAsyncCompletedEventArgs)state;
cancelCompleted(this,
new AsyncCompletedEventArgs(e.Error, e.Cancelled, e.UserState));
}
}
IAsyncResult OnBeginCancel(object[] inputs, AsyncCallback callback, object state)
{
return this.BeginCancel((Guid)inputs[0], callback, state);
}
object[] OnEndCancel(IAsyncResult result)
{
this.EndCancel(result);
return null;
}
void OnRunCompleted(object state)
{
EventHandler<AsyncCompletedEventArgs> runCompleted = this.RunCompleted;
if (runCompleted != null)
{
InvokeAsyncCompletedEventArgs e = (InvokeAsyncCompletedEventArgs)state;
runCompleted(this, new AsyncCompletedEventArgs(e.Error, e.Cancelled, e.UserState));
}
}
IAsyncResult OnBeginRun(object[] inputs, AsyncCallback callback, object state)
{
return this.BeginRun((Guid)inputs[0], callback, state);
}
object[] OnEndRun(IAsyncResult result)
{
this.EndRun(result);
return null;
}
void OnSuspendCompleted(object state)
{
EventHandler<AsyncCompletedEventArgs> suspendCompleted = this.SuspendCompleted;
if (suspendCompleted != null)
{
InvokeAsyncCompletedEventArgs e = (InvokeAsyncCompletedEventArgs)state;
suspendCompleted(this, new AsyncCompletedEventArgs(e.Error, e.Cancelled, e.UserState));
}
}
IAsyncResult OnBeginSuspend(object[] inputs, AsyncCallback callback, object state)
{
return this.BeginSuspend((Guid)inputs[0], (string)inputs[1], callback, state);
}
object[] OnEndSuspend(IAsyncResult result)
{
this.EndSuspend(result);
return null;
}
void OnUnsuspendCompleted(object state)
{
EventHandler<AsyncCompletedEventArgs> unsuspendCompleted = this.UnsuspendCompleted;
if (unsuspendCompleted != null)
{
InvokeAsyncCompletedEventArgs e = (InvokeAsyncCompletedEventArgs)state;
unsuspendCompleted(this, new AsyncCompletedEventArgs(e.Error, e.Cancelled, e.UserState));
}
}
IAsyncResult OnBeginUnsuspend(object[] inputs, AsyncCallback callback, object state)
{
return this.BeginUnsuspend((Guid)inputs[0], callback, state);
}
object[] OnEndUnsuspend(IAsyncResult result)
{
this.EndUnsuspend(result);
return null;
}
void OnTerminateCompleted(object state)
{
EventHandler<AsyncCompletedEventArgs> terminateCompleted = this.TerminateCompleted;
if (terminateCompleted != null)
{
InvokeAsyncCompletedEventArgs e = (InvokeAsyncCompletedEventArgs)state;
terminateCompleted(this, new AsyncCompletedEventArgs(e.Error, e.Cancelled, e.UserState));
}
}
IAsyncResult OnBeginTerminate(object[] inputs, AsyncCallback callback, object state)
{
return this.BeginTerminate((Guid)inputs[0], (string)inputs[1], callback, state);
}
object[] OnEndTerminate(IAsyncResult result)
{
this.EndTerminate(result);
return null;
}
void OnUpdateCompleted(object state)
{
EventHandler<AsyncCompletedEventArgs> updateCompleted = this.UpdateCompleted;
if (updateCompleted != null)
{
InvokeAsyncCompletedEventArgs e = (InvokeAsyncCompletedEventArgs)state;
updateCompleted(this, new AsyncCompletedEventArgs(e.Error, e.Cancelled, e.UserState));
}
}
IAsyncResult OnBeginUpdate(object[] inputs, AsyncCallback callback, object state)
{
return this.BeginUpdate((Guid)inputs[0], (WorkflowIdentity)inputs[1], callback, state);
}
object[] OnEndUpdate(IAsyncResult result)
{
this.EndUpdate(result);
return null;
}
class CancelAsyncResult : AsyncResult
{
static AsyncCompletion handleEndCancel = new AsyncCompletion(HandleEndCancel);
bool isTransacted;
IWorkflowInstanceManagement channel;
public CancelAsyncResult(IWorkflowInstanceManagement channel, bool isTransacted, Guid instanceId,
AsyncCallback callback, object state)
: base(callback, state)
{
this.isTransacted = isTransacted;
this.channel = channel;
if (Cancel(instanceId))
{
this.Complete(true);
}
}
public static void End(IAsyncResult result)
{
AsyncResult.End<CancelAsyncResult>(result);
}
bool Cancel(Guid instanceId)
{
IAsyncResult result;
AsyncCallback callback = this.PrepareAsyncCompletion(handleEndCancel);
if (this.isTransacted)
{
result = this.channel.BeginTransactedCancel(instanceId, callback, this);
}
else
{
result = this.channel.BeginCancel(instanceId, callback, this);
}
if (result.CompletedSynchronously)
{
return HandleEndCancel(result);
}
return false;
}
static bool HandleEndCancel(IAsyncResult result)
{
CancelAsyncResult thisPtr = (CancelAsyncResult)result.AsyncState;
if (thisPtr.isTransacted)
{
thisPtr.channel.EndTransactedCancel(result);
}
else
{
thisPtr.channel.EndCancel(result);
}
return true;
}
}
class RunAsyncResult : AsyncResult
{
static AsyncCompletion handleEndResume = new AsyncCompletion(HandleEndRun);
bool isTransacted;
IWorkflowInstanceManagement channel;
public RunAsyncResult(IWorkflowInstanceManagement channel, bool isTransacted, Guid instanceId,
AsyncCallback callback, object state)
: base(callback, state)
{
this.isTransacted = isTransacted;
this.channel = channel;
if (Run(instanceId))
{
this.Complete(true);
}
}
public static void End(IAsyncResult result)
{
AsyncResult.End<RunAsyncResult>(result);
}
bool Run(Guid instanceId)
{
IAsyncResult result;
AsyncCallback callback = this.PrepareAsyncCompletion(handleEndResume);
if (this.isTransacted)
{
result = this.channel.BeginTransactedRun(instanceId, callback, this);
}
else
{
result = this.channel.BeginRun(instanceId, callback, this);
}
if (result.CompletedSynchronously)
{
return HandleEndRun(result);
}
return false;
}
static bool HandleEndRun(IAsyncResult result)
{
RunAsyncResult thisPtr = (RunAsyncResult)result.AsyncState;
if (thisPtr.isTransacted)
{
thisPtr.channel.EndTransactedRun(result);
}
else
{
thisPtr.channel.EndRun(result);
}
return true;
}
}
class SuspendAsyncResult : AsyncResult
{
static AsyncCompletion handleEndSuspend = new AsyncCompletion(HandleEndSuspend);
bool isTransacted;
IWorkflowInstanceManagement channel;
public SuspendAsyncResult(IWorkflowInstanceManagement channel, bool isTransacted,
Guid instanceId, string reason, AsyncCallback callback, object state)
: base(callback, state)
{
this.isTransacted = isTransacted;
this.channel = channel;
if (Suspend(instanceId, reason))
{
this.Complete(true);
}
}
public static void End(IAsyncResult result)
{
AsyncResult.End<SuspendAsyncResult>(result);
}
bool Suspend(Guid instanceId, string reason)
{
IAsyncResult result;
AsyncCallback callback = this.PrepareAsyncCompletion(handleEndSuspend);
if (this.isTransacted)
{
result = this.channel.BeginTransactedSuspend(instanceId, reason, callback, this);
}
else
{
result = this.channel.BeginSuspend(instanceId, reason, callback, this);
}
if (result.CompletedSynchronously)
{
return HandleEndSuspend(result);
}
return false;
}
static bool HandleEndSuspend(IAsyncResult result)
{
SuspendAsyncResult thisPtr = (SuspendAsyncResult)result.AsyncState;
if (thisPtr.isTransacted)
{
thisPtr.channel.EndTransactedSuspend(result);
}
else
{
thisPtr.channel.EndSuspend(result);
}
return true;
}
}
class UnsuspendAsyncResult : AsyncResult
{
static AsyncCompletion handleEndUnsuspend = new AsyncCompletion(HandleEndUnsuspend);
bool isTransacted;
IWorkflowInstanceManagement channel;
public UnsuspendAsyncResult(IWorkflowInstanceManagement channel, bool isTransacted,
Guid instanceId, AsyncCallback callback, object state)
: base(callback, state)
{
this.isTransacted = isTransacted;
this.channel = channel;
if (Unsuspend(instanceId))
{
this.Complete(true);
}
}
public static void End(IAsyncResult result)
{
AsyncResult.End<UnsuspendAsyncResult>(result);
}
bool Unsuspend(Guid instanceId)
{
IAsyncResult result;
AsyncCallback callback = this.PrepareAsyncCompletion(handleEndUnsuspend);
if (this.isTransacted)
{
result = this.channel.BeginTransactedUnsuspend(instanceId, callback, this);
}
else
{
result = this.channel.BeginUnsuspend(instanceId, callback, this);
}
if (result.CompletedSynchronously)
{
return HandleEndUnsuspend(result);
}
return false;
}
static bool HandleEndUnsuspend(IAsyncResult result)
{
UnsuspendAsyncResult thisPtr = (UnsuspendAsyncResult)result.AsyncState;
if (thisPtr.isTransacted)
{
thisPtr.channel.EndTransactedUnsuspend(result);
}
else
{
thisPtr.channel.EndUnsuspend(result);
}
return true;
}
}
class TerminateAsyncResult : AsyncResult
{
static AsyncCompletion handleEndTerminate = new AsyncCompletion(HandleEndTerminate);
bool isTransacted;
IWorkflowInstanceManagement channel;
public TerminateAsyncResult(IWorkflowInstanceManagement channel, bool isTransacted,
Guid instanceId, string reason, AsyncCallback callback, object state)
: base(callback, state)
{
this.isTransacted = isTransacted;
this.channel = channel;
if (Terminate(instanceId, reason))
{
this.Complete(true);
}
}
public static void End(IAsyncResult result)
{
AsyncResult.End<TerminateAsyncResult>(result);
}
bool Terminate(Guid instanceId, string reason)
{
IAsyncResult result;
AsyncCallback callback = this.PrepareAsyncCompletion(handleEndTerminate);
if (this.isTransacted)
{
result = this.channel.BeginTransactedTerminate(instanceId, reason, callback, this);
}
else
{
result = this.channel.BeginTerminate(instanceId, reason, callback, this);
}
if (result.CompletedSynchronously)
{
return HandleEndTerminate(result);
}
return false;
}
static bool HandleEndTerminate(IAsyncResult result)
{
TerminateAsyncResult thisPtr = (TerminateAsyncResult)result.AsyncState;
if (thisPtr.isTransacted)
{
thisPtr.channel.EndTransactedTerminate(result);
}
else
{
thisPtr.channel.EndTerminate(result);
}
return true;
}
}
class UpdateAsyncResult : AsyncResult
{
static AsyncCompletion handleEndUpdate = new AsyncCompletion(HandleEndUpdate);
bool isTransacted;
IWorkflowUpdateableInstanceManagement channel;
public UpdateAsyncResult(IWorkflowUpdateableInstanceManagement channel, bool isTransacted, Guid instanceId, WorkflowIdentity updatedDefinitionIdentity,
AsyncCallback callback, object state)
: base(callback, state)
{
this.isTransacted = isTransacted;
this.channel = channel;
if (Update(instanceId, updatedDefinitionIdentity))
{
this.Complete(true);
}
}
public static void End(IAsyncResult result)
{
AsyncResult.End<UpdateAsyncResult>(result);
}
bool Update(Guid instanceId, WorkflowIdentity updatedDefinitionIdentity)
{
IAsyncResult result;
AsyncCallback callback = this.PrepareAsyncCompletion(handleEndUpdate);
if (this.isTransacted)
{
result = this.channel.BeginTransactedUpdate(instanceId, updatedDefinitionIdentity, callback, this);
}
else
{
result = this.channel.BeginUpdate(instanceId, updatedDefinitionIdentity, callback, this);
}
if (result.CompletedSynchronously)
{
return HandleEndUpdate(result);
}
return false;
}
static bool HandleEndUpdate(IAsyncResult result)
{
UpdateAsyncResult thisPtr = (UpdateAsyncResult)result.AsyncState;
if (thisPtr.isTransacted)
{
thisPtr.channel.EndTransactedUpdate(result);
}
else
{
thisPtr.channel.EndUpdate(result);
}
return true;
}
}
}
}
|