Monday, July 20, 2009

Configurable low level datastore filtering provider module for Xaf

This one is hard to explain so I would start with one scenario that can be implemented with ease.

You have a request to create a windows form application that the data should be filtered according to the active skin, also the request says that Customers should be shared through skins.

Another request for the same project is application data to be filtered according to the active user but customers to be shared across all users

For such scenarios that are: Filter data at a low level so any logic above this level to still function (see validation rules) I have develop FilterDataStore module and I am going to release it as part of eXpand 0.0.0.7

To configure the module one have to add a filter provider at its application configuration file (see A practical guide to decoupling .NET 2.0 applications).

I am going to release 3 projects

eXpand.ExpressApp.FilterDataStore
Contains the filtering implementation and any providers that are not platform specific. It is  very easy to create a custom provider you just have to inherit FilterProviderBase class and implemented the required methods. Look for eg. the UserFilterProvider bellow I think is self described

public class UserFilterProvider:FilterProviderBase
{
    public override object FilterValue
    {
        get {
            if (SecuritySystem.CurrentUser != null)
                return ((XPBaseObject)SecuritySystem.CurrentUser).ClassInfo.KeyProperty.GetValue(SecuritySystem.CurrentUser);
            return null;
        }
    }

    public override string FilterMemberName
    {
        get { return "User"; }
    }

    public override int FilterMemberSize
    {
        get { return SizeAttribute.DefaultStringMappingFieldSize; }
    }

    public override bool FilterMemberIndexed
    {
        get { return true; }
    }

    public override bool UseFilterValueWhenNull
    {
        get { return false; }
    }

    public override Type FilterMemberType
    {
        get { return typeof(Guid); }
    }
}

eXpand.ExpressApp.FilterDataStore.Win
This one will contain any windows specific classes. For the moment it will contain the SkinFilterProvider

public class SkinFilterProvider:FilterProviderBase
{
    public override object FilterValue
    {
        get { return UserLookAndFeel.Default.ActiveSkinName; }
    }

    public override string FilterMemberName
    {
        get { return "Skin"; }
    }

    public override int FilterMemberSize
    {
        get { return SizeAttribute.DefaultStringMappingFieldSize; }
    }

    public override bool FilterMemberIndexed
    {
        get { return true; }
    }

    public override bool UseFilterValueWhenNull
    {
        get { return false; }
    }

    public override Type FilterMemberType
    {
        get { return typeof(string); }
    }
}

FilterDataStore has been preconfigured to disable filtering for the following system database tables

AuditDataItemPersistent
AuditedObjectWeakReference
ModuleInfo
PersistentPermission
Role
User
UserUsers_RoleRoles
XPObjectType
XpoModelDictionaryDifferenceStore
XpoRoleModelDictionaryDifferenceStore
XpoRoleModelDictionaryDifferenceStoreXpoRoleModelDictionaryDifferenceStores_RolesRole
XpoUserModelDictionaryDifferenceStore
XPWeakReference

see how

image

In Order to use FilterDataStore Module we have to do what I say in the video bellow but instead of using DictionaryDifferenceStore Module we should use FilterDataStore module

assuming you have setup your references see how you can setup your filtering providers. So your application configuration file should look like

image

Latest version of eXpand can be found at http://code.google.com/p/expandframework/


Technorati Tags: ,,

Subscribe to XAF feed
Subscribe to community feed

DiggIt!

0 comments:

Post a Comment