Print Page | Close Window

Login while Disconnected

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2009
Forum Discription: For .NET 3.5
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=1845
Printed Date: 23-Apr-2024 at 4:31am


Topic: Login while Disconnected
Posted By: mlens
Subject: Login while Disconnected
Date Posted: 25-May-2010 at 10:44pm
Hi there,

VS2008
Silverlight 3

We've implemented IEntityLoginManager which works as expected while connected. Problem is we need to provide a login mechanism for users when disconnected. What we were hoping to achieve was;

1. Attempt to login Asychronously
2. If login fails due to being disconnected, attempt to authenticate the user credentials against Entity Manager cache. (The manager is loaded at startup with an IsolatedStorageFile if it exists).

Problem is, once you implement IEntityLoginManager, you can no longer query the cache unless first logged in? (We think)

Is there a way to work disconnected once IEntityLoginManager is implemented?

Thanks



Replies:
Posted By: GregD
Date Posted: 26-May-2010 at 2:06pm
It is the EntityServer to which you are denied access if not logged in. You can query the cache.


Posted By: mlens
Date Posted: 26-May-2010 at 4:11pm
Thanks Greg for the answer. That is what I thought I was doing with the following statements;

            IEntityQuery<User> qry = _manager.Users.Where(u => u.LogonName == LoginName);
            qry.QueryStrategy = QueryStrategy.CacheOnly;
            IEnumerable users = qry.Execute();

However, users only returns records when the application has successfully logged on.

Am I querying the cache incorrectly?

Regards


Posted By: GregD
Date Posted: 28-May-2010 at 12:56pm
mlens:

Are you sure you have some User entities in the cache when you run your query?

i just tested a cache-only query using the following method (having previously saved some Employees to the Data.bin file):


    private void TestLoginManager(){
      _mgr.CacheStateManager.RestoreCacheState("Data.bin");
      List<Employee> employees = _mgr.Employees.With(QueryStrategy.CacheOnly).ToList();
      // List<Employee> employees = _mgr.Employees.ToList();
      Console.WriteLine("Retrieved {0} Employees from cache", employees.Count);
      //_mgr.CacheStateManager.SaveCacheState("Data.bin");
      PromptToContinue();
    }


LoginManagerRequired was set to true in the exe project's app.config. LoginManager as follows:


  class LoginManager:IEntityLoginManager {
    #region IEntityLoginManager Members

    public System.Security.Principal.IPrincipal Login(ILoginCredential credential, EntityManager entityManager) {
      throw new NotImplementedException();
      //return new WindowsPrincipal(WindowsIdentity.GetCurrent());
    }

    public void Logout(System.Security.Principal.IPrincipal principal, EntityManager entityManager) {
      throw new NotImplementedException();
    }

    #endregion
  }


Login() is called in this LoginManager if DevForce tries to access the EntityServer.  (You can verify this by substituting the version of the query with no call to With(QueryStrategy.CacheOnly).  It throws an exception.)

The above test method, in the form shown, successfully reports 9 Employees in the list.




Print Page | Close Window