CompositeActivity Windows Workflow

CompositeActivity , , , , . , Activity . . ? Activity , xaml , Uri, , . , Activity - Main, Activity xaml . , :), , xaml , , Activity - HttpGetData. , Activity, Activity.
, , , , Activity , . MS Visual Studio 2010 WCF + WorkFlow + Library + WindowsFormClient, Activity.
1. CompositeActivity.
Activity InputData :
public class InputData
{
public string url{ get; set; }
public string xamlStringExecute { get; set; }
}
2. CompositeActivity.
Activity OutputData :
public class OutputData
{
public string htmlString{ get; set; }
public string error{ get; set; }
}
3. CompositeActivity class Main.
Activity , Activity, Xaml , c Activity.
/* 10.02.2013.
* Activity , . ,
* Activity, , .
* , Activity Uri .
* , Activity Main Activity.
* , Activity "argument2".
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Activities;
using System.Activities.XamlIntegration;
using System.IO;
using System.Xml;
using System.ComponentModel;
using ActivityLibraryProject;
using ClassLibraryProject;

namespace WorkFlowProject
{
public sealed class Main : CodeActivity
{
[RequiredArgument]
[DefaultValue(null)]
public InArgument<InputData> inputArgument{ get; set; }
public OutArgument<OutputData> output{ get; set; }

private InputData inputObject= null;
private OutputData outputObject = null;
private string executeString= string.Empty;
private string uri= string.Empty;

protected override void Execute(CodeActivityContext context)
{
try
{
outputObject = new OutputData();
// Input object
inputObject = inputArgument.Get(context);

// Execute string
executeString = inputObject.xamlStringExecute;
if (String.IsNullOrEmpty(executeString)) throw new ArgumentNullException("Value", "Xaml string is Empty");

// Uri for AsyncHttpGet
uri = inputObject.url;
if (String.IsNullOrEmpty(uri)) throw new ArgumentNullException("Value", "Uri string is Empty");

// Create XmlReader
XmlReader reader = XmlReader.Create(new StringReader(executeString));
// Create dinamic Activity
Activity act = ActivityXamlServices.Load(reader);
// Create input parametet
IDictionary<string, object> input = new Dictionary<string, object>() { { "argument1", uri } };

// Calling child process
IDictionary<string, object> executeChild = WorkflowInvoker.Invoke(act, input);

// Set output data
outputObject.htmlString = (string)executeChild["argument2"];
output.Set(context, outputObject);
}
catch (Exception ex)
{
outputObject.error = ex.ToString();
output.Set(context, outputObject);
}
}
}
}
4. Activity class HttpGetData.
Activity, http .
/* Activity Inside.xaml .
* Uri,
* Html.
* , Activity .
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Activities;
using System.ComponentModel;
using System.IO;
using System.Net;

namespace ActivityLibraryProject
{
public sealed class HttpGetData : AsyncCodeActivity<string>
{
[RequiredArgument]
[DefaultValue(null)]
public InArgument<string> Uri { get; set; }

WebRequest query = null;
string uri = null;

protected override IAsyncResult BeginExecute(AsyncCodeActivityContext context, AsyncCallback callback, object state)
{
uri = Uri.Get(context);
query = HttpWebRequest.Create(uri);
context.UserState = query;
return query.BeginGetResponse(callback, state);
}

protected override string EndExecute(AsyncCodeActivityContext context, IAsyncResult result)
{
try
{
WebRequest query= (WebRequest)context.UserState;
WebResponse answer= query.EndGetResponse(result);
StreamReader StrReader= new StreamReader(answer.GetResponseStream());
return StrReader.ReadToEnd();
}
catch (Exception ex)
{
return ex.ToString();
}
}
}
}
5. CompositeActivity.
string, object InputData . object OutputData .
/* 10.02.2013. CompositeActivity.
* XAML .
* , Uri, .
* HTML , WebBrowser.
*/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using WindowsFormsClient.ServiceReference1;
using System.IO;

namespace WindowsFormsClient
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
try
{
// String containing the text of the application software
string xamlStringExecute = File.ReadAllText(@"G:\Data\\CompositeActiviry\WorkFlowProject\Inside.xaml");

//Create client
ServiceClient client = new ServiceClient();

// References to classes
ServiceReference1.InputDatainputObject= new ServiceReference1.InputData();
ServiceReference1.OutputData outputObject= new ServiceReference1.OutputData();

// Input parameters
inputObject.url = @"http://www.microsoft.com";
inputObject.xamlStringExecute = xamlStringExecute;

// Output parameters
outputObject = client.GetData(inputObject);
if (!string.IsNullOrEmpty(outputObject.error)) throw new Exception("Error Activity ...");
webBrowser1.DocumentText = outputObject.htmlString;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}

Visual Studio 2010 : Activity, Workflow, Windows Form .
C , .
10.02.2013 .

© Argument Ltd, 2017 ,  : 8-921-215-45-70,   e-mail