Getting the Generated Classes to work in Silverlight - Part 4
Dernier message 15 janv. 2009 12:47 par solheim. 0 Réponses.
Version imprimable
Tri:
RetourRetour SuivantSuivant
Vous n'etes pas autorisé a poster une réponse.
Auteur Messages
solheim
New Member
New Member
Posts:11

--
15 janv. 2009 12:47  
For Each BL NameValueList File change the factory methods:

#region "Factory Methods"
#if !SILVERLIGHT

The existing factory methods with no modifications

#else

public static BLCodeItemTypeNameValueList GetList(EventHandler<DataPortalResult<BLCodeItemTypeNameValueList>> handler)

public BLCodeItemTypeNameValueList()

Moved the following method outside the #if #endif section so it is included for both.

public static void InvalidateCache()

Created new method so you can set the cache from the outside after the aSynch GetList method is finished:

public static void CreateCache(BLCodeItemTypeNameValueList listForCaching)
{
mList = listForCaching;
}

Changed the Default() method to only return values from the Cache for Silverlight.
public static System.Int32 DefaultItem()
{
#if !SILVERLIGHT
BLCodeItemTypeNameValueList list = GetList();
#else
BLCodeItemTypeNameValueList list = mList;
#endif

This is so far just a shortcut to get the code to compile in Silverlight.
The idea is that the method handling the FetchCompleted can use the CreateCache() method
to create the cache for the NameValueList, I don't know if this makes any sense yet.


Modified The ApplicationPrincipal and ApplicationIdentity Classes:

ApplicationIdentity:

I changed the class to inherit from CslaIdentity
and removed some properties and methods which already exists in CslaIdentity.

public partial class ApplicationIdentity : CslaIdentity
{
#region "Private Variables"
private string _name = string.Empty;
private List<string> _roles = new List<string>();
#endregion

#region "Factory Methods"

#if !SILVERLIGHT
private ApplicationIdentity()
{ /* require use of factory methods */ }

public static bool GetIdentity(string username, string password, string roles)
{
return GetCslaIdentity<ApplicationIdentity>(new Criteria(username, password)).IsAuthenticated;
}
//<end_overwrite>
#else
public ApplicationIdentity()
{ /* required public constructor for SL */ }

public static void GetIdentity(string username, string password, EventHandler<DataPortalResult<ApplicationIdentity>> handler)
{
GetCslaIdentity<ApplicationIdentity>(handler, new Criteria(username, password));
}
#endif

#endregion

#region "Data Access"

[Serializable()]
private class Criteria : CriteriaBase
{
public Criteria() { }

private string _username;
public string Username
{
get { return _username; }
}

private string _password;
public string Password
{
get { return _password; }
}

public Criteria(string username, string password)
: base(typeof(Criteria))
{
_username = username;
_password = password;
}

protected override void OnGetState(Csla.Serialization.Mobile.SerializationInfo info, StateMode mode)
{
info.AddValue("_username", _username);
info.AddValue("_password", _password);
base.OnGetState(info, mode);
}

protected override void OnSetState(Csla.Serialization.Mobile.SerializationInfo info, StateMode mode)
{
_username = (string)info.Values["_username"].Value;
_password = (string)info.Values["_password"].Value;
base.OnSetState(info, mode);
}
}

#if !SILVERLIGHT
private void DataPortal_Fetch(Criteria criteria)
{

....

#endif

ApplicationPrincipal:

#if !SILVERLIGHT

private ApplicationPrincipal()
{
}

public static bool Login(string username, string password, string roles)
{
return ApplicationIdentity.GetIdentity(username, password, roles);
}
//<end_overwrite>

#else

public ApplicationPrincipal()
{
}

public static void Login(string username, string password, EventHandler<EventArgs> completed)
{
ApplicationIdentity.GetIdentity(username, password, (o, e) =>
{
if (e.Object == null)
{
SetPrincipal(ApplicationIdentity.UnauthenticatedIdentity());
}
else
{
SetPrincipal(e.Object);
}
completed(null, EventArgs.Empty);
});
}
//<end_overwrite>

#endif

Added new method SetPrincipal:

private static void SetPrincipal(Csla.Security.CslaIdentity identity)
{
ApplicationPrincipal principal = new ApplicationPrincipal(identity);
Csla.ApplicationContext.User = principal;
}

End of Part 4.

Paul Solheim
www.faktnet.com
Vous n'etes pas autorisé a poster une réponse.

Active Forums 4.1
NOT LICENSED FOR PRODUCTION USE
www.activemodules.com
Connexion / Inscription