Monday, August 29, 2011

Profiling medium trust web applications

Our profiler uses WCF in order to communicate with the client application. One of the benefits of the XPOProfiler is that it supports 2 binding types. Both binding types have their advantages however in this situation only one allows us the flexibility we require.

NetTcpBinding

This option provides a secure and reliable binding environment for .Net to .Net cross machine communication. By default it creates a communication stack using WS-ReliableMessaging protocol, TCP for message delivery and windows security for message and authentication at run time.

image

One drawback is that in shared host environments there is no way to open a port neither to use Mutexes. Our second option allows us to overcome this by creating a WCF service and hosting it with our web application. 

WSHttpBinding

  • Defines a secure, reliable, interoperable binding suitable for non-duplex service contracts,
  • Supports WS-* functionality and distributed transactions with reliable and secure sessions using SOAP security,
  • Uses HTTP and HTTPS transport for communication,
  • Reliable sessions are disabled by default

image

We have already identified limitations when profiling medium trust web applications, now we must look at modifying our application in order to overcome them.

The first step is to add the new service using VS add new Item context menu.

image

This action will add the following items to the project;

  • IMyLogService.cs - the communication interface description,
  • MyLogService.svc.cs - the communication service class declaration

Furthermore the Web.config file will be modified by adding <system.serviceModel> section. I am using .NET3.5 right now, be aware that this step may vary according to the .NET version you are using.

The next step is to remove the IMyLogService.cs from the project.

image

Then we are going to modify the MyLogService.svc.cs as  follows;

[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
public class MyLogService : LogService {
    public MyLogService()
        : base(Logger) {
        if (Logger != null) LogManager.SetTransport(Logger);
    }

    private static LoggerBase Logger {
        get { return new LoggerBase(); }
    }
}

The final step is to change the name of the communication contract in <system.serviceModel> section of Web.config file from WebApplicationToProfile.IMyLogService to DevExpress.Xpo.Logger.Transport.ILogSource.

image

After that we are ready to run the XPOProfiler and create a new connection to our medium hosted XPO web application.

image

Note: Version 11.2 will allow us to carry out all the above processes.

Happy profiling!

Related Links
Blog posts
Videos

Subscribe to XAF feed
Subscribe to community feed

DiggIt!

Wednesday, August 24, 2011

XAF Workflow persistence storage

The .NET Framework 4 ships with the SQL Workflow Instance Store which allows workflows to persist state information about workflow instances in a SQL Server 2005 or SQL Server 2008 database. However its implementation is based on stored procedures which can be a bit scary if you are not familiar with them. In addition our customers may follow different standards (Oracle, Firebird, VistaDB, MySQL, PostgreSQL etc.) and it’s unrealistic to hire more people to support SQL Server infrastructure.

Usually when dealing with these issues the first thing we do is to carry out a Google search for storage solutions. Surprisingly there is no such solution out there! Moreover there is very little useful code or samples available. Luckily XAF provides us with an easier route!

XAF is the perfect workflow modeling environment. It provides a ready made solution for creating and deploying a server that will execute workflows as described here.  In order to start modeling workflows we can use VS design time along with our re-hosted runtime Workflow designer and custom WF4 activities. XAF also gives us increased control over our workflows for example through the ability to manually start workflows. Finally since XAF uses XPO to access data we can easily support 16 different database systems simply by providing a connection string!

XPO Data Store Adapter XPO Data Store Adapter's Assembly Name Database Provider Assembly
AccessConnectionProvider DevExpress.Xpo.vXXX System.Data.dll
AdvantageConnectionProvider DevExpress.Xpo.vXXX.Providers Advantage.Data.Provider.dll 9.10.2.0
AsaConnectionProvider DevExpress.Xpo.vXXX.Providers iAnywhere.Data.SQLAnywhere.dll 11.0.0.12642
AseConnectionProvider DevExpress.Xpo.vXXX.Providers Sybase.Data.AseClient.dll 1.15.50.0
DB2ConnectionProvider DevExpress.Xpo.vXXX.Providers IBM.Data.DB2.dll 9.5.2.2
FirebirdConnectionProvider DevExpress.Xpo.vXXX.Providers FirebirdSql.Data.Firebird.dll 1.7.1.0
FirebirdSql.Data.FirebirdClient.dll 2.5.1.0
MSSqlConnectionProvider DevExpress.Xpo.vXXX System.Data.dll
MSSqlCEConnectionProvider DevExpress.Xpo.vXXX.Providers System.Data.SqlServerCe.dll 3.5.0
System.Data.SqlServerCe.dll 4.0.8482.1
MySqlConnectionProvider DevExpress.Xpo.vXXX.Providers MySql.Data.dll 5.2.5.0
OracleConnectionProvider DevExpress.Xpo.vXXX.Providers System.Data.OracleClient.dll 2.0.0.0
Oracle.DataAccess.dll 9.2.0.700
ODPConnectionProvider DevExpress.Xpo.vXXX.Providers Oracle.DataAccess.dll 10.1.0.200
PervasiveSqlConnectionProvider DevExpress.Xpo.vXXX.Providers Pervasive.Data.SqlClient.dll 2.10.0.15
PostgreSqlConnectionProvider DevExpress.Xpo.vXXX.Providers Npgsql.dll 2.0.11.0
SQLiteConnectionProvider DevExpress.Xpo.vXXX.Providers System.Data.SQLite.dll 1.0.61.0
VistaDBConnectionProvider DevExpress.Xpo.vXXX.Providers VistaDB.4.dll 4.0.0.0

More info @ Database Systems Supported by XPO

This is only one example of what XAF can do for us. XAF provides a comprehensive set of solutions that allow you to outsource all of the mundane programming tasks leaving you to focus purely on your business needs. For more info consult our docs, blogs, code central and support center.

Happy Workflowing!

Related Links
Blog posts
Online documentation

Videos

Subscribe to XAF feed
Subscribe to community feed

DiggIt!

Monday, August 8, 2011

Creating a State Machine module for eXpandFramework – Part 1

Let me describe for a moment how we at DX work. We build and sell software which means that we only sell and provide support for products that have been built and tested by us! However I am here as a framework evangelist and huge XAF fan. This makes it my duty to spread the word as much as I can and make XAF even bigger. To this end through collaboration within the XAF community, we have been building and supporting eXpand. This framework follows XAF to the letter and takes things even further. eXpand gets its inspiration from real life situations and bases itself on examples from DX SUPPORT CENTER. eXpand is the first open source project based on the DevExpress eXpressApp Framework (XAF). More info is available at www.expandframework.com and our very existence relies on your efforts! Anyone is welcome to contribute and enjoy the rewards. It is not necessary to be a XAF guru, we can all manage to create a behavior taken from DevExpress code central. Let’s work together to enhance our beloved XAF!

Today we are going to deal with creating a reusable module for eXpandFramework. This new module will host State Machine logic therefore we are going to name it Xpand.ExpressApp.StateMachine. A Security logic similar to this is going to be the first resident however we are going to use permissions rather than manually writing the custom function criteria operator to the TargetObjectCriteria. This module can be used as a standalone without the need of eXpandFramwork for the moment. However keeping it under the eXpand umbrella will help us to share features/processes within the framework in the future.

First we need to create a new VS project that shares characteristics with the rest of the eXpand modules. Currently eXpand only provides a new Solution VS template. This means that we need to do things the old fashioned way, i.e. copying and pasting an existing module. Our behavior is platform independent thus it’s a good idea to choose a module that is also platform independent such as Xpand.ExpressApp.ViewVariants.

The next step is to open the cloned project, rename it and set its references to those shown in the pic below. It is important to leave all Xpand core references as they are.

image

It is advisable to register the original StateMachine module to avoid having to register it later.

image

XpandSystemModule is already registered since we used the Xpand.ExpressApp.ViewVarians project as a template.

We want (with the help of the existing XAF Security permissions system) to be able to assign special types of permissions to a role. We can then use these permissions to control the transition to certain states. The State Machine module uses XpoStateMachine and XpoState persistent classes. These classes can be linked to a permission by name. As a result a permission having 2 properties StateMachineName and StateName would be sufficient.

[NonPersistent]

public class StateMachineTransitionPermission : PermissionBase {

public override IPermission Copy() {

return new StateMachineTransitionPermission(Modifier, StateCaption, StateMachineName);

}

public StateMachineTransitionPermission() {

}

public override SecurityElement ToXml() {

SecurityElement result = base.ToXml();

result.AddAttribute("modifier", Modifier.ToString());

result.AddAttribute("stateMachineName", StateMachineName);

result.AddAttribute("stateCaption", StateCaption);

return result;

}

public override void FromXml(SecurityElement e) {

base.FromXml(e);

Modifier =

(StateMachineTransitionModifier)

Enum.Parse(typeof(StateMachineTransitionModifier), e.Attributes["modifier"].ToString());

StateCaption = e.Attributes["stateCaption"].ToString();

StateMachineName = e.Attributes["stateMachineName"].ToString();

}

public StateMachineTransitionPermission(StateMachineTransitionModifier modifier, string stateCaption, string stateMachineName) {

Modifier = modifier;

StateCaption = stateCaption;

StateMachineName = stateMachineName;

}

public override bool IsSubsetOf(IPermission target) {

var isSubsetOf = base.IsSubsetOf(target);

if (isSubsetOf) {

var stateMachineTransitionPermission = ((StateMachineTransitionPermission)target);

return stateMachineTransitionPermission.StateCaption == StateCaption &&

stateMachineTransitionPermission.StateMachineName == StateMachineName;

}

return false;

}

public StateMachineTransitionModifier Modifier { get; set; }

public string StateMachineName { get; set; }

public string StateCaption { get; set; }

}

A Modifier property can be used to disable our permission, moreover the SecuritySystem is going to grant the permission by calling the IsSubsetOf method.

Finally, we are going to create a controller and check if a permission with the same state and statemachine name has been granted to our system. If not we are going to throw an

exception

public class StatePermissionController : ViewController, IModelExtender {

void IModelExtender.ExtendModelInterfaces(ModelInterfaceExtenders extenders) {

extenders.Add<IModelOptions, IModelOptionsStateMachine>();

}

protected override void OnActivated() {

base.OnActivated();

var stateMachineController = Frame.GetController<StateMachineController>();

stateMachineController.TransitionExecuting += OnTransitionExecuting;

}

void OnTransitionExecuting(object sender, ExecuteTransitionEventArgs executeTransitionEventArgs) {

var states = executeTransitionEventArgs.StateMachine.States.OfType<XpoState>();

foreach (var state in states) {

if (IsNotGranted(state))

throw new UserFriendlyException("Permissions are not granted for transitioning to the " + state.Caption);

}

}

bool IsNotGranted(XpoState state) {

return IsNotGranted(new StateMachineTransitionPermission(StateMachineTransitionModifier.Deny, state.Caption, state.StateMachine.Name));

}

static bool IsNotGranted(IPermission permission) {

var securityComplex = ((SecurityBase)SecuritySystem.Instance);

bool isGrantedForNonExistentPermission = securityComplex.IsGrantedForNonExistentPermission;

securityComplex.IsGrantedForNonExistentPermission = true;

bool granted = SecuritySystem.IsGranted(permission);

securityComplex.IsGrantedForNonExistentPermission = isGrantedForNonExistentPermission;

return granted;

}

}

During the writing of this post M. Brekhof asked if it is possible to hide the transition in the UI if there are no permissions. This is a certainly a useful feature to include in the new module. To implement it we can subscribe to the ItemsChanged event of the ChangeStateAction and use the IsGranted method there.

image

Using the model to control the above allows us more flexibility as we can choose whether to include these improvements or not. In order to do so we need to define and register a model extender.

image

It should be clear that this is a rapid development! In a few short minutes we have created a module which can be used as often as necessary to enhance the functionality of our applications. This is another fine example of getting the job done the XAF way!

So far we have not discussed how to create lookups for our StateMachineTransitionPermission StateMachineName,StateName properties. Don’t worry all of this will be featured in part 2. In the meantime if any of you need any other information please let me know so that I can cover it too.

Happy eXpanding!

eXpand is the first open source project based on the DevExpress eXpressApp Framework (XAF). More info is available at www.expandframework.com

Subscribe to XAF feed
Subscribe to community feed

DiggIt!

Wednesday, August 3, 2011

Manually starting workflows – the best choice

Prerequisites
Manually starting workflows

In the first post of the series we saw how to start a workflow using a WCF service. Furthermore we also discussed doing this using the module’s out of the box mechanisms. So far however, we haven’t had time to analyze the reasons for choosing one method or the other. This post aims to clarify the situation.

WCF Solution

As Dennis likes to say, “There is no need to light a cigar with a nuclear reactor”. This is certainly true when it comes to the WCF solution as it can be somewhat unwieldy. In addition we have to come to terms with more technology as it requires configuration for even the smallest task. For example, the client always needs to know the WCF service address. It is also very difficult to work with WF instances because in order to accomplish common tasks (view, track status, generate reports, measure client service reply time) we need to introduce a system of persistent classes which will help to simulate the out of the box behavior. A third issue arises when modifying the solution because there is often a need for changes to occur in many places at the same time. For example when introducing additional properties we have to change client code and Receive contracts.

This option is only recommended when we have a large system (>10000 WF instances). Only then will we notice a gain in performance. This is because one WCF request can start a workflow which costs nothing compared to multiple Sql Queries. In all other cases we are fortunate that XAF allows us to take the easy road as usual!

Out of the box

Take our usual product ordering task; a client simply creates a new OrderRequest business object and fills the necessary members. A workflow with  an AutoStartWhenObjectIsCreated condition will start when the object is saved. After that we can access all the information in the workflow algorithm. This method allows us to,

Note that a similar process is described in Working with CRUD activities – Short Transactions

We would appreciate your feedback on this post. Has it been useful to you? Feel free to contact us  with any further questions

Related Links
Blog posts
Online documentation

Subscribe to XAF feed
Subscribe to community feed

DiggIt!

Monday, August 1, 2011

How to use an eXpand module with an existing XAF application

Let me describe for a moment how we at DX work. We build and sell software which means that we only sell and provide support for products that have been built and tested by us! However I am here as a framework evangelist and huge XAF fan. This makes it my duty to spread the word as much as I can and make XAF even bigger. To this end through collaboration within the XAF community, we have been building and supporting eXpand. This framework follows XAF to the letter and takes things even further. eXpand gets its inspiration from real life situations and bases itself on examples from DX SUPPORT CENTER. eXpand is the first open source project based on the DevExpress eXpressApp Framework (XAF). More info is available at www.expandframework.com and our very existence relies on your efforts! Anyone is welcome to contribute and enjoy the rewards. It is not necessary to be a XAF guru, we can all manage to create a behavior taken from DevExpress code central. Let’s work together to enhance our beloved XAF!
Using an eXpand module with an existing XAF application is an issue that is being raised a lot recently and I am sure it deserves a post and a place in Xpand Wiki. The following information applies to any Xpand module. Note that installing an Xpand module is almost as easy as using a XAF one.
Introduction
Firstly, as a base type for our application components it is imperative to use XpandWinApplication or XpandWebApplication. Therefore we need to reference Xpand.ExpressApp.Win or Xpand.ExpressApp.Web assemblies from our application projects and replace their components’ base types accordingly,
image
Additionally we need to reference Xpand.Persistent.BaseImpl. Having similar architecture with XAF, eXpand modules use interfaces and their implementations are hosted in the BaseImpl assembly. Xpand modules know how to locate the Business Objects they require so this is all we need to do at this point.
Note; BaseImpl assembly has no references to DX BaseImpl and it is possible to use a replace it with a custom one .
Registering in Toolbox
Now, unless we are a XAF guru, we have to register the assemblies in the VS toolbox. I suggest creating the toolbox items within a new Xpand Tab as shown. At this point we don’t have the resources to create our own ToolBoxCreator utility. If any VS IDE guru wants to contribute such a tool, we owe him one!
image image
Registration
Registering and using a module is as easy as dragging and dropping it into the Application Designer. The designer will then add all required references and modules for us.
image
Give us your feedback
Was this post useful to you? Do you want to learn more about Xpand framework? We would love to hear your feedback!


Updated:19/12/2012

Under folder Demos/Modules there is a set of solutions that can guide you how to install each module seperately

Happy eXpanding!

Subscribe to XAF feed
Subscribe to community feed

DiggIt!