本文整理汇总了C#中System.Activities.WorkflowApplication.ResumeBookmark方法的典型用法代码示例。如果您正苦于以下问题:C# WorkflowApplication.ResumeBookmark方法的具体用法?C# WorkflowApplication.ResumeBookmark怎么用?C# WorkflowApplication.ResumeBookmark使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Activities.WorkflowApplication
的用法示例。
在下文中一共展示了WorkflowApplication.ResumeBookmark方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
AutoResetEvent syncEvent = new AutoResetEvent(false);
// create the workflow app and add handlers for the Idle and Completed actions
WorkflowApplication app = new WorkflowApplication(new Sequence1());
app.Idle = delegate(WorkflowApplicationIdleEventArgs e)
{
syncEvent.Set();
};
app.Completed = delegate(WorkflowApplicationCompletedEventArgs e)
{
syncEvent.Set();
};
// start the application
app.Run();
syncEvent.WaitOne();
// read some text from the console and resume the readText bookmark (created in the first WaitForInput activity)
string text = Console.ReadLine();
app.ResumeBookmark("readText", text);
syncEvent.WaitOne();
// read some text from the console, convert it to number, and resume the readNumber bookmark (created in the second WaitForInput activity)
int number = ReadNumberFromConsole();
app.ResumeBookmark("readNumber", number);
syncEvent.WaitOne();
Console.WriteLine("");
Console.WriteLine("Press [ENTER] to exit...");
Console.ReadLine();
}
示例2: Interact
// single interaction with the user. The user enters a string in the console and that
// string is used to resume the ReadLine activity bookmark
static void Interact(WorkflowApplication application, AutoResetEvent resetEvent)
{
Console.WriteLine("Workflow is ready for input");
Console.WriteLine("Special commands: 'unload', 'exit'");
bool done = false;
while (!done)
{
Console.Write("> ");
string s = Console.ReadLine();
if (s.Equals("unload"))
{
try
{
// attempt to unload will fail if the workflow is idle within a NoPersistZone
application.Unload(TimeSpan.FromSeconds(5));
done = true;
}
catch (TimeoutException e)
{
Console.WriteLine(e.Message);
}
}
else if (s.Equals("exit"))
{
application.ResumeBookmark("inputBookmark", s);
done = true;
}
else
{
application.ResumeBookmark("inputBookmark", s);
}
}
resetEvent.WaitOne();
}
示例3: Main
static void Main(string[] args)
{
_event = new AutoResetEvent(false);
bool more = true;
int result = 0;
var activity = new AccumulatorActivity();
var accumulator = new WorkflowApplication(activity);
accumulator.Completed = new Action<WorkflowApplicationCompletedEventArgs>((e) =>
{
result = (int)e.Outputs["Sum"];
more = false;
_event.Set();
});
accumulator.Extensions.Add(new Notification(NotifySum));
accumulator.Run();
while (more)
{
Console.Write("Enter number: ");
int number = int.Parse(Console.ReadLine());
accumulator.ResumeBookmark("GetNumber", number);
_event.WaitOne();
}
Console.WriteLine("Result is " + result);
}
示例4: Interact
static void Interact(WorkflowApplication application)
{
IList<BookmarkInfo> bookmarks = application.GetBookmarks();
while (true)
{
Console.Write("Bookmarks:");
foreach (BookmarkInfo info in bookmarks)
{
Console.Write(" '" + info.BookmarkName + "'");
}
Console.WriteLine();
Console.WriteLine("Enter the name of the bookmark to resume");
string bookmarkName = Console.ReadLine();
if (bookmarkName != null && !bookmarkName.Equals(string.Empty))
{
Console.WriteLine("Enter the payload for the bookmark '{0}'", bookmarkName);
string bookmarkPayload = Console.ReadLine();
BookmarkResumptionResult result = application.ResumeBookmark(bookmarkName, bookmarkPayload);
if (result == BookmarkResumptionResult.Success)
{
return;
}
else
{
Console.WriteLine("BookmarkResumptionResult: " + result);
}
}
}
}
示例5: Main
private static void Main(string[] args)
{
const int workflowCompleted = 0;
const int workflowIdle = 1;
var syncEvents = new[]
{
new AutoResetEvent(false),
new AutoResetEvent(false),
};
var wfApp = new WorkflowApplication(new TestReadLine());
string bookmarkName = string.Empty;
bool workflowComplete = false;
// Signal the main thread we are done
wfApp.Completed = (e) => syncEvents[workflowCompleted].Set();
// When the host detects an idle
wfApp.Idle = (e) =>
{
// Search the bookmarks
foreach (
var bi in
e.Bookmarks.Where(
bi => bi.BookmarkName == "FirstName" || bi.BookmarkName == "LastName"))
{
Console.WriteLine("Found bookmark {0}", bi.BookmarkName);
// For FirstName or LastName bookmarks prompt with a readline
bookmarkName = bi.BookmarkName;
syncEvents[workflowIdle].Set();
}
};
wfApp.Run();
while (!workflowComplete)
{
// Wait for events
switch (WaitHandle.WaitAny(syncEvents, TimeSpan.FromSeconds(5)))
{
case WaitHandle.WaitTimeout:
Console.WriteLine("Sorry you took too long");
wfApp.Terminate("Timeout");
break;
case workflowCompleted:
workflowComplete = true;
break;
case workflowIdle:
Console.WriteLine("Reading response for bookmark {0}", bookmarkName);
// Resume with the response from the user
wfApp.ResumeBookmark(bookmarkName, Console.ReadLine());
break;
}
}
Console.WriteLine("Sample Completed - press any key to exit");
Console.ReadKey(true);
}
示例6: LoadAndCompleteInstance
static void LoadAndCompleteInstance()
{
string input = Console.ReadLine();
WorkflowApplication application = new WorkflowApplication(activity);
application.InstanceStore = instanceStore;
application.Completed = (workflowApplicationCompletedEventArgs) =>
{
Console.WriteLine("\nWorkflowApplication has Completed in the {0} state.", workflowApplicationCompletedEventArgs.CompletionState);
};
application.Unloaded = (workflowApplicationEventArgs) =>
{
Console.WriteLine("WorkflowApplication has Unloaded\n");
instanceUnloaded.Set();
};
application.Load(id);
//this resumes the bookmark setup by readline
application.ResumeBookmark(readLineBookmark, input);
instanceUnloaded.WaitOne();
}
示例7: Main
static void Main(string[] args)
{
AutoResetEvent syncEvent = new AutoResetEvent(false);
AutoResetEvent idleEvent = new AutoResetEvent(false);
Dictionary<string, object> input = new Dictionary<string, object> { { "MaxNumber", 100 } };
WorkflowApplication app = new WorkflowApplication(new SequentialNumberGuessWorkflow(), input);
app.Completed = delegate(WorkflowApplicationCompletedEventArgs e)
{
int Turns = Convert.ToInt32(e.Outputs["Turns"]);
Console.WriteLine("Congratulations, you guessed the number in {0} turns", Turns);
syncEvent.Set();
};
app.Aborted = delegate(WorkflowApplicationAbortedEventArgs e)
{
Console.WriteLine(e.Reason);
syncEvent.Set();
};
app.OnUnhandledException = delegate(WorkflowApplicationUnhandledExceptionEventArgs e)
{
Console.WriteLine(e.UnhandledException.ToString());
syncEvent.Set();
return UnhandledExceptionAction.Abort;
};
app.Idle = delegate(WorkflowApplicationIdleEventArgs e)
{
idleEvent.Set();
};
app.Run();
// Loop until the workflow completes.
WaitHandle[] handles = new WaitHandle[] { syncEvent, idleEvent };
while (WaitHandle.WaitAny(handles) != 0)
{
// Gather the user input and resume the bookmark.
bool validEntry = false;
while (!validEntry)
{
int Guess;
if (!Int32.TryParse(Console.ReadLine(), out Guess))
{
Console.WriteLine("Please enter an integer.");
}
else
{
validEntry = true;
app.ResumeBookmark("EnterGuess", Guess);
}
}
}
}
示例8: Main
static void Main(string[] args)
{
ManualResetEvent workflowCompleted = new ManualResetEvent(false);
ManualResetEvent workflowIdled = new ManualResetEvent(false);
Activity activity;
using (Stream stream = File.OpenRead("Program.xaml"))
{
activity = ActivityXamlServices.Load(stream);
stream.Close();
}
//create the WorkflowApplication using the Activity loaded from Program.xaml
WorkflowApplication application = new WorkflowApplication(activity);
//set up the Completed and Idle callbacks
application.Completed = workflowCompletedEventArgs => workflowCompleted.Set();
application.Idle = (e) =>
{
workflowIdled.Set();
};
//run the program
application.Run();
while (true)
{
string input = Console.ReadLine();
workflowIdled.Reset();
//provide the Console input to the Workflow
application.ResumeBookmark("PromptBookmark", input);
//wait for either the Idle or the Completion signal
int signalled = WaitHandle.WaitAny(new WaitHandle[] { workflowCompleted, workflowIdled });
//if completion was signalled, then we are done.
if (signalled == 0)
{
break;
}
}
Console.WriteLine();
Console.WriteLine("Press [ENTER] to exit.");
Console.ReadLine();
}
示例9: Load
/// <summary>
/// 加载工作流
/// </summary>
/// <param name="id">工作流的唯一标示</param>
/// <param name="bookMark">标签名称</param>
/// <param name="ids">恢复指定名称的书签的时候,传入的参数</param>
/// <returns>工作流的加载的状态</returns>
public string Load(string id, object inputs = null)
{
_instanceStore = new SqlWorkflowInstanceStore(connectionString);
InstanceView view = _instanceStore.Execute
(_instanceStore.CreateInstanceHandle(),
new CreateWorkflowOwnerCommand(),
TimeSpan.FromSeconds(30));
_instanceStore.DefaultInstanceOwner = view.InstanceOwner;
WorkflowApplication i = new WorkflowApplication(ActivityXamlServices.Load(path));
i.InstanceStore = _instanceStore;
i.PersistableIdle = (waiea) => PersistableIdleAction.Unload;
i.Load(new Guid(id));
return i.ResumeBookmark(bookMark, inputs).GetString();
}
示例10: Main
static void Main(string[] args)
{
AutoResetEvent syncEvent = new AutoResetEvent(false);
WorkflowApplication myApplication = new WorkflowApplication(new Sequence1());
myApplication.Completed = delegate(WorkflowApplicationCompletedEventArgs e)
{
syncEvent.Set();
};
myApplication.OnUnhandledException = delegate(WorkflowApplicationUnhandledExceptionEventArgs e)
{
Console.WriteLine(e.UnhandledException.ToString());
syncEvent.Set();
return UnhandledExceptionAction.Terminate;
};
myApplication.Aborted = delegate(WorkflowApplicationAbortedEventArgs e)
{
Console.WriteLine(e.Reason);
syncEvent.Set();
};
myApplication.Run();
while (true)
{
if (myApplication.GetBookmarks().Count > 0)
{
string bookmarkName = myApplication.GetBookmarks()[0].BookmarkName;
string input = Console.ReadLine().Trim();
myApplication.ResumeBookmark(bookmarkName, input);
// Exit out of this loop only when the user has entered a non-empty string.
if (!String.IsNullOrEmpty(input))
{
break;
}
}
}
syncEvent.WaitOne();
System.Console.WriteLine("The program has ended. Please press [ENTER] to exit...");
System.Console.ReadLine();
}
示例11: Main
static void Main(string[] args)
{
AutoResetEvent syncEvent = new AutoResetEvent(false);
string bookmarkName = "GreetingBookmark";
WorkflowApplication wfApp = new WorkflowApplication(new Workflow1()
{
BookmarkNameInArg = bookmarkName
});
wfApp.Completed = delegate(
WorkflowApplicationCompletedEventArgs e)
{
syncEvent.Set();
};
wfApp.Run();
wfApp.ResumeBookmark(bookmarkName, Console.ReadLine());
syncEvent.WaitOne();
}
示例12: Main
static void Main(string[] args)
{
bool running = true;
// create the workflow application and start its execution
AutoResetEvent syncEvent = new AutoResetEvent(false);
WorkflowApplication application = new WorkflowApplication(new GuessingGameWF());
application.Completed = delegate(WorkflowApplicationCompletedEventArgs e) { running = false; syncEvent.Set(); };
application.Idle = delegate(WorkflowApplicationIdleEventArgs e)
{
syncEvent.Set();
};
application.Run();
// main loop (manages bookmarks)
while (running)
{
if (!syncEvent.WaitOne(10, false))
{
if (running)
{
// if there are pending bookmarks...
if (HasPendingBookmarks(application))
{
// get the name of the bookmark
string bookmarkName = application.GetBookmarks()[0].BookmarkName;
// resume the bookmark (passing the data read from the console)
application.ResumeBookmark(bookmarkName, Console.ReadLine());
syncEvent.WaitOne();
}
}
}
}
// wait for user input
Console.WriteLine("Press enter to exit.");
Console.ReadLine();
}
示例13: Main
static void Main(string[] args)
{
AutoResetEvent syncEvent =
new AutoResetEvent(false);
string bookmarkName = "HostGreeting";
WorkflowApplication wfApp =
new WorkflowApplication(new Workflow1()
{
BookmarkNameInArg = bookmarkName
});
/*
* To clean up the persistence database to have a fresh database, run the scripts in:
%WINDIR%\Microsoft.NET\Framework\v4.xxx\SQL\EN in the following order.
SqlWorkflowInstanceStoreSchema.sql
SqlWorkflowInstanceStoreLogic.sql
* */
string connectionString = "Server=.\\SQLSERVER14;Initial Catalog=Persistence45;Integrated Security=SSPI";
Console.WriteLine("Workflow ID: " + wfApp.Id);
wfApp.InstanceStore = (InstanceStore)new SqlWorkflowInstanceStore(connectionString);
wfApp.PersistableIdle = delegate(WorkflowApplicationIdleEventArgs e)
{
syncEvent.Set();
Console.WriteLine("Persisting..");
return PersistableIdleAction.Persist;
};
wfApp.Completed = delegate(
WorkflowApplicationCompletedEventArgs e)
{
syncEvent.Set();
Console.WriteLine("Completing..");
};
wfApp.Run();
wfApp.ResumeBookmark(bookmarkName,
Console.ReadLine());
syncEvent.WaitOne();
syncEvent.WaitOne();
}
示例14: Run
static void Run()
{
AutoResetEvent applicationUnloaded = new AutoResetEvent(false);
WorkflowApplication application = new WorkflowApplication(workflow);
application.InstanceStore = instanceStore;
SetupApplication(application, applicationUnloaded);
StepCountExtension stepCountExtension = new StepCountExtension();
application.Extensions.Add(stepCountExtension);
application.Run();
Guid id = application.Id;
applicationUnloaded.WaitOne();
while (stepCountExtension.CurrentCount < totalSteps)
{
application = new WorkflowApplication(workflow);
application.InstanceStore = instanceStore;
SetupApplication(application, applicationUnloaded);
stepCountExtension = new StepCountExtension();
application.Extensions.Add(stepCountExtension);
application.Load(id);
string input = Console.ReadLine();
application.ResumeBookmark(echoPromptBookmark, input);
applicationUnloaded.WaitOne();
}
}
示例15: RunInstance
private static void RunInstance(Guid guid, string bookmark, Activity activity, object args)
{
SqlWorkflowInstanceStore instanceStore = new SqlWorkflowInstanceStore(ConnectString);
WorkflowApplication application = new WorkflowApplication(activity);
application.InstanceStore = instanceStore;
application.PersistableIdle = (e) =>
{
return PersistableIdleAction.Unload;
};
application.Load(guid);
application.ResumeBookmark(bookmark, args);
}