QuoteReplyTopic: EntityManager Authenticated+ DynamicXAP Posted: 07-Jul-2011 at 9:59am
Thank for help Robert.
I do not want to run the method LoginAsync again, I just wanted to load another XAP and stay connected, so I created the class Managers, for not creating new instance and using same instance aways.(if you tell me otherwise). it is possible to stay connected?
Now the issue of code. if I instantiate a new EntityManager I need to remove the code, CompositionHost.Add if I did not remove show the same error (3), if I remove the code I can login, but when I run a query to populate the datagrid shows this error :
Type 'IdeaBlade.EntityModel.EntityQueryProxy`1[[SilverlightProject.Customer, SilverlightProject.Processing, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]' is not known to the serializer. The following probe assemblies were found during initialization: SilverlightProject. Make sure that the assemblies holding your entity model and other known types are in this list. Check that your CompositionHost.SearchPatterns are correct. Also see the debug log to check for assembly load errors.
after code downloadXAP just this code (obs: I REMOVE CODE (CompositionHost.Add))
Based on what I'm looking at, I don't think that the error you're getting has anything to do with the multiple .xaps, but with the very convoluted way you're attempting to retrieve the data in that second .xap. You don't get the same error message if you simply create your em and log it in, do you?
private void button1_Click(object sender, RoutedEventArgs e) { EntitiesTest em = new EntitiesTest(Managers.Instance); em.LoginAsync(new LoginCredential("c", "c", ""), args => { if (args.CompletedSuccessfully) { // doing nothing here
} else MessageBox.Show(args.Error.Message); }); }
What are you trying to accomplish with the Managers class?
I would use the same credentials for login. (I would like to stay conected if possible, but if not possible then can be separately);
I use IEntityLoginManager :
public class LoginManager : IEntityLoginManager
{
public IPrincipal Login(ILoginCredential credential, EntityManager entityManager)
{
if (credential == null)
{
throw new LoginException(LoginExceptionType.NoCredentials, "No credentials were supplied");
}
UserPerson user = UserPerson.getUserByUserName(credential.UserName, entityManager);
if (usuario == null)
{
throw new LoginException(LoginExceptionType.Other, "Error creating user login, try again.");
}
if (usuario.EntityAspect.IsNullEntity)
{
throw new LoginException(LoginExceptionType.InvalidUserName, "Invalid password and user name");
}
if (credential.Password != user.Password)
{
throw new LoginException(LoginExceptionType.InvalidPassword, "Invalid password and user name");
}
if (user.Active != "S")
{
throw new LoginException(LoginExceptionType.Other, "inactive User");
}
return user;
}
public void Logout(IPrincipal principal, EntityManager entityManager)
{
}
}
// IPrincipal
public partial class PersonUser : IbEm.Entity, IPrincipal
{
public static PersonUser getUserByUserName(String UserName, EntityManager entityManager)
{
EntitiesTest _em = new EntitiesTest(entityManager);
void DoDownload(string xapName)
{
var xap = new DynamicXap(new Uri(xapName, UriKind.Relative));
xap.Loaded += (o, args) =>
{
if (args.HasError)
MessageBox.Show(args.Error.Message);
else
{
var dzap = o as DynamicXap;
IdeaBlade.Core.Composition.CompositionHost.Add(dzap);
1- i create class Managers and first login I get EM and set in Managers.Instance = EM, then i using here for create the new
EntitiesTest em = new EntitiesTest(Managers.Instance); and execute my query with em.Customer.ExecuteAsync(); OK. this not show error but dont show data. then i click button
again for load data, then throw my exception( throw new LoginException(LoginExceptionType.NoCredentials, "No credentials were supplied"); )
2- now i picked up directly from the class Managers.Instance and execute the query Managers.Instance.Customer.ExecuteAsync(); here show same exception
( throw new LoginException(LoginExceptionType.NoCredentials, "No credentials were supplied"); ) So i debug project Managers.Instance is null, but if i use EntitiesTest em = new Entities(Managers.Instance); <= my Instance not null;
3- I try loginAsync() after execute query, using Manager.Instance.LoginAsync(); or EntitiesTest em = new EntitiesTest(); em,LoginAsync(); ERROR
( Type 'SilverlightProject.Customer' cannot be added to list of known types since another type 'SilverlightProject.Customer' with the same data contract name 'http://schemas.datacontract.org/2004/07/SilverlightProject:Customer' is already present. )
here my class Managers
public class Managers
{
private static EntitiesTest _instance;
public static EntitiesTest Instance
{
get
{
if (_instance == null)
_instance = new EntitiesTest();
return Managers._instance;
}
set { Managers._instance = value; }
}
You should be able to login separately in all three xaps with LoginAsync(), using the same credentials or individual credentials. Could you provide some more of your code? Are you really using the IEntityLoginManager implementation you posted above? Could I see how you're authenticating in your first xap (which works) and then your next xap (which is not)?
What block of code is actually creating the error you posted?
I implemented for authentication (IEntityLoginManager)
public class LoginManager : IEntityLoginManager
{
public IPrincipal Login(ILoginCredential credential, EntityManager entityManager)
{
//TODO
}
}
I have a project with three XAPs, when do I load the first XAP I call the pair LoginAsync, then I want to stay connected when the next XAP is loaded, but my EntityManager is null; then try to LoginAsync() again. but error below :
Type 'SilverlightProject.Customer' cannot be added to list of known types since another type 'SilverlightProject.Customer' with the same data contract name 'http://schemas.datacontract.org/2004/07/SilverlightProject:Customer' is already present.
it is possible to stay connected when I switch XAP ? or need LoginAsync again?
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum