using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml;
namespace Neo.Afx.Services.Workflows.Entities
{
///
/// Workflow Instance Route class definition
///
public class WorkflowInstanceRoute
{
private List _steps;
///
/// Initializes a new instance of the class.
///
/// The XML.
public WorkflowInstanceRoute(XmlDocument xml)
{
_steps = new List();
var routeLayout = xml.SelectSingleNode("/WorkflowRoute/WorkflowLayout");
if (routeLayout != null)
{
RouteLayout = new WorkflowRouteLayout(routeLayout);
}
var steps = xml.SelectNodes("/WorkflowRoute/Steps/Step");
if(steps != null)
{
foreach(XmlNode step in steps)
{
var s = new WorkflowRouteStep()
{
Number = Convert.ToInt32(step.Attributes["Number"].Value),
Status = step.Attributes["WorkflowTemplateStepStatus"].Value,
Users = new List(),
WorkflowTemplateStepID = Convert.ToInt32(step.Attributes["WorkflowTemplateStepID"].Value),
ParticipantRoles = step.Attributes["ParticipantRoles"].Value,
Duration = step.Attributes["Duration"].Value,
};
s.StepTitle = WorkflowInstanceRoute.GetStepTitle(s.Number, RouteLayout);
var users = step.SelectNodes("./ToBeAssignedTo/User");
if(users != null)
{
foreach(XmlNode user in users)
{
var u = new WorkflowRouteUser()
{
UserID = Convert.ToInt32(user.Attributes["ID"].Value),
KnownAs = user.Attributes["KnownAs"].Value
};
s.Users.Add(u);
}
}
_steps.Add(s);
}
}
}
public static string GetStepTitle(long number, WorkflowRouteLayout layout)
{
if (layout != null && layout.Steps != null)
{
foreach (var s in layout.Steps)
{
if (s.Number == number)
{
return s.Title + " - " + s.Description;
}
}
}
return "Step description not found";
}
///
/// Gets or sets the route layout.
///
///
/// The route layout.
///
public WorkflowRouteLayout RouteLayout
{
get;
set;
}
///
/// Gets or sets the steps.
///
///
/// The steps.
///
public List Steps
{
get
{
if (_steps != null)
{
return _steps.OrderBy(a => a.Number).ToList();
}
else {
return new List();
}
}
}
}
///
/// Class used for drawing the Route Indicater
/// Route Indicater requires a serializable object from an XML source
///
public class WorkflowRouteLayout
{
///
/// Initializes a new instance of the class.
///
/// The layout.
public WorkflowRouteLayout(XmlNode layout)
{
this.MaxColumns = Int32.Parse(layout.Attributes["MaxColumns"].Value);
this.MaxRows = Int32.Parse(layout.Attributes["MaxRows"].Value);
this.Steps = new List();
this.Links = new List();
var steps = layout.SelectNodes("Steps/Step");
if(steps != null)
{
foreach(XmlNode step in steps)
{
var rootLayoutStep = new WorkflowRouteLayout.Step()
{
Column = Int32.Parse(step.Attributes["Column"].Value),
Description = step.Attributes["Description"].Value,
Number = Int32.Parse(step.Attributes["Number"].Value),
Row = Int32.Parse(step.Attributes["Row"].Value),
Title = step.Attributes["Title"].Value
};
this.Steps.Add(rootLayoutStep);
}
}
var links = layout.SelectNodes("Links/Link");
if(links != null)
{
foreach(XmlNode link in links)
{
var routeLink = new WorkflowRouteLayout.Link()
{
FromStep = Int32.Parse(link.Attributes["FromStep"].Value),
ToStep = Int32.Parse(link.Attributes["ToStep"].Value)
};
this.Links.Add(routeLink);
}
}
}
///
/// Gets or sets the max columns.
///
///
/// The max columns.
///
public int MaxColumns
{
get;
set;
}
///
/// Gets or sets the max rows.
///
///
/// The max rows.
///
public int MaxRows
{
get;
set;
}
///
/// Gets or sets the steps.
///
///
/// The steps.
///
public List Steps
{
get;
set;
}
///
/// Gets or sets the links.
///
///
/// The links.
///
public List Links
{
get;
set;
}
///
/// Route workflow step custom class definition
///
public class Step
{
///
/// Gets or sets the number.
///
///
/// The number.
///
public int Number
{
get;
set;
}
///
/// Gets or sets the title.
///
///
/// The title.
///
public string Title
{
get;
set;
}
///
/// Gets or sets the description.
///
///
/// The description.
///
public string Description
{
get;
set;
}
///
/// Gets or sets the row.
///
///
/// The row.
///
public int Row
{
get;
set;
}
///
/// Gets or sets the column.
///
///
/// The column.
///
public int Column
{
get;
set;
}
}
///
/// Route workflow link custom class definition
///
public class Link
{
///
/// Gets or sets from step.
///
///
/// From step.
///
public int FromStep
{
get;
set;
}
///
/// Gets or sets to step.
///
///
/// To step.
///
public int ToStep
{
get;
set;
}
}
}
///
/// Workflow Route Step class definition
///
public class WorkflowRouteStep
{
///
/// Gets or sets the workflow template step ID.
///
///
/// The workflow template step ID.
///
public long WorkflowTemplateStepID
{
get;
set;
}
///
/// Gets or sets the number.
///
///
/// The number.
///
public long Number
{
get;
set;
}
///
/// Gets or sets the duration.
///
///
/// The duration.
///
public string Duration
{
get;
set;
}
///
/// Gets or sets the status.
///
///
/// The status.
///
public string Status
{
get;
set;
}
///
/// Gets or sets the users.
///
///
/// The users.
///
public List Users
{
get;
set;
}
///
/// Gets or sets the participant roles.
///
///
/// The participant roles.
///
public string ParticipantRoles
{
get;
set;
}
///
/// Gets or sets the step title
///
public string StepTitle { get; set; }
}
///
/// Workflow Route User class definition
///
public class WorkflowRouteUser
{
///
/// Gets or sets the user ID.
///
///
/// The user ID.
///
public long UserID
{
get;
set;
}
///
/// Gets or sets the known as.
///
///
/// The known as.
///
public string KnownAs
{
get;
set;
}
}
}