ActivityRest Windows Workflow Activity

ActivityRest. Activity , , REST, WCF, WorkFlow. , WCF, , WorkFlow, ActivityRest, , REST, URI - . , .
MS Visual Studio 2010 WCF + WorkFlow + REST + WindowsFormClient, Activity.
1. ActivityRest.
Activity InputArgument :
public class InputArgument
{
public string UrlString{ get; set; }
public string CustomerID{ get; set; }
}
2. ActivityRest.
. , Activity. Linq - IEnumerable<Order>.
protected override IEnumerable<Order> EndExecute(AsyncCodeActivityContext context, IAsyncResult result)
{
try
{
3. ActivityRest.
, Activity , :
  • BeginExecute;
  • EndExecute.

, , , REST HTTP, , . ActivityRest Linq , URI: http://services.odata.org/Northwind/Northwind.svc/

/* 10.01.2013. Activity. ,
Uri . , ,
頠 Uri: http://services.odata.org/Northwind/Northwind.svc/
. WCF WorkFlow.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Activities;
using WorkFlowRest.ServiceReference1;
using System.Data.Services.Client;
using ClassLibrary;
using System.ComponentModel;

namespace WorkFlowRest
{
public sealed class CodeActivityRest : AsyncCodeActivity<IEnumerable<Order>>
{
[RequiredArgument]
[DefaultValue(null)]
public InArgument<InputArgument> inputArguments { get; set; }

NorthwindEntities entityContext= null;
DataServiceQuery<Order> entityQuery= null;

// Temporary variable for input arguments
private InputArgument inputObject= null;
private string uri= null;
private string customerId= null;

protected override IAsyncResult BeginExecute(AsyncCodeActivityContext context, AsyncCallback callback, object state)
{
try
{
// Input Object
inputObject = inputArguments.Get(context);

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

// Filter for Data
customerId = inputObject.CustomerID;
if (customerId == null) throw new ArgumentNullException("Value", "CustomerID string is null");

// Set EntityContext
entityContext = new NorthwindEntities(new Uri(uri));

// Create entityQuery
entityQuery = (DataServiceQuery<Order>)
from obj in entityContext.Orders
where obj.Customer.CustomerID.Contains(customerId)
select obj;

context.UserState = entityQuery;
return entityQuery.BeginExecute(callback, state);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message.ToString());
return null;
}
}

protected override IEnumerable<Order> EndExecute(AsyncCodeActivityContext context, IAsyncResult result)
{
try
{
// Get context.UserState
entityQuery = context.UserState as DataServiceQuery<Order>;

// Return entityQuery.
return entityQuery.EndExecute(result);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message.ToString());
return null;
}
}
}
}
4. ActivityRest
, URI ActivityRest InputArgument., , , Linq . CustomerID. Linq ComboBox .
/* 10.03.2012. AcnivityRest.
Uri .
. , Linq
( ActivityRect).
Linq
DataSource ComboBox.
*/
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.ServiceReference2;
using ClassLibrary;

namespace WindowsFormsClient
{
public partial class FormClient : Form
{
// Link for Service Client
ServiceClient client = null;
// Input Class
private ClassLibrary.InputArgument input = null;

public FormClient()
{
InitializeComponent();
// Create Objects and set parameters
client = new ServiceClient();
input = new InputArgument();
input.CustomerID = string.Empty;
input.UrlString = @"http://services.odata.org/Northwind/Northwind.svc/";
}

// Event click button for clean filter
private void button1_Click(object sender, EventArgs e)
{
// Empty Filter comboBox1
comboBox1.Text = "";
input.CustomerID = string.Empty;
//Call Form1_Load
FormClient_Load(sender, e);
}

// Load Data
private void FormClient_Load(object sender, EventArgs e)
{
try
{
// Send and Get Data
var order = client.GetData(input);
// Too Query
var groupCustomerID = from row in order
// orderby row.CustomerID ascending
group row by row.CustomerID into grouping
orderby grouping.Key ascending
select grouping.Key;

foreach (var item in groupCustomerID) comboBox1.Items.Add(item.ToString());

// Exception is order == null
if (order == null) { throw new ArgumentNullException("Value", "Order is null"); }

// Set DataSource
dataGridView1.DataSource = order;
label3.Text = order.Count<Order>().ToString();
}
catch (Exception ex)
{
MessageBox.Show(" Error: " + ex.ToString());
}
}

// Change CustomerID in ComboBox
private void comboBox1_TextChanged(object sender, EventArgs e)
{
try
{
input.CustomerID = (string)comboBox1.SelectedItem;
// Send and Get Data
var order = client.GetData(input);
// Exception
if (order == null) { throw new ArgumentNullException("Value", "Order is null"); }
// Set DataSource
dataGridView1.DataSource = order;
label3.Text = order.Count<Order>().ToString();
}
catch (Exception ex)
{
MessageBox.Show(" Error: " + ex.ToString());
}
}
}
}

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

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