Top

Administration CreateUser method never returns (C#)

Répondu

Commentaires

5 commentaires

  • Christophe IRLES

    Hi,

    The callback is always used on success or on error.
    But as the callback signature suggests ( => "Action<SdkResult<Contact>>") the result is provided asyncronously so on a different thread.

    I suppose you are using "contactId" and  "Jid" incorrectly.
    Could you share more source code to check this part ?

    0
    Actions pour les commentaires Permalien
  • Rick LUPPINO

    Hi Christophe, 

    Thanks for your quick reply. 'contactId' and 'jId' are declared as local variables just before the call to CreateUser (see below). There are log messages in each branch of the callback but none of them ever appear. The code prior to the CreateUser call i.e. to log in as the admin user, is handled in the same was as CreateUser (as per the original code block above) and we always get a return from that callback.

    var contactId = "";
    var jId = "";
    0
    Actions pour les commentaires Permalien
  • Christophe IRLES

    Login process is also asynchronous ...
    1) Are you waiting the end of this aysnchronous call (i.e Login) before to continue ?
    2) Did you respect this guide line: https://hub.openrainbow.com/#/documentation/doc/sdk/csharp/guides/030_connect_to_rainbow

     

    0
    Actions pour les commentaires Permalien
  • Christophe IRLES

    Did you find a solution of your problem ?

    I share with you a little example . It demonstrates how to deal with aysnchronous methods in a synchromous way:

    // Define ManualResetEvent object used in Login/Authentication process
    private ManualResetEvent manualResetInitialization = new ManualResetEvent(false);

    // Define another ManualResetEvent
    private ManualResetEvent manualResetEvent = new ManualResetEvent(false);

    // Define objects from the C# SDK
    private Rainbow.Application rbApplication;
    private Rainbow.Administration rbAdministration;

    ...


    // Create SDK Objects
    rbApplication = new Rainbow.Application("./");
    rbAdministration = rbApplication.GetAdministration();

    // Since we are doing provisioning we don't need to create a event pipe with the server
    rbApplication.Restrictions.EventMode = Restrictions.SDKEventMode.NONE;

    // Set a timeout to 10 seconds (it's huge - to ajoust according your environment)
    rbApplication.SetTimeout(10000);

    // Define application info and the server to use
    rbApplication.SetApplicationInfo(ApplicationInfo.APP_ID, ApplicationInfo.APP_SECRET_KEY);
    rbApplication.SetHostInfo(ApplicationInfo.HOST_NAME);

    // We have to deal with several events of the SDK - it's the mandatory ones
    rbApplication.ConnectionStateChanged += RbApplication_ConnectionStateChanged;
    rbApplication.InitializationPerformed += RbApplication_InitializationPerformed;

    ...

    // We login to RB
    manualResetInitialization.Reset(); // We need to ensure to reset Manual Reset Event used in lgin / ahtnication process

    // Start login (it's asynchronous)
    rbApplication.Login(CompanyAdmin.Email, CompanyAdmin.Password, callback =>
    {
    if (!callback.Result.Success)
    {
    // Something wrong happened !
    message = Util.SerializeSdkError(callback.Result);
    }
    });

    // Login step is a asynchronous call - we need to wait event "InitializationPerformed" or "ConnectionStateChanged" ( with a disconnected state)
    manualResetInitialization.WaitOne();

    // Here we have finished authentication process
    // If all has been done corretly:
    // - the event "ConnectionStateChanged" has been raised twice: "connecting" then "connected"
    // - the event "InitializationPerformed" has been raised once

    if (!rbApplication.IsInitialized())
    {
    // Something wrong happened !
    // TO MANAGE
    }

    // Create a user:
    manualResetEvent.Reset();// We need to ensure to reset Manual Reset Event used
    admin.CreateUser(userEmailAddress, userPassword, firstName, lastName, firstName, <company ID>, true, false, callback =>
    {
    if (!callback.Result.Success)
    {
    // Something wrong happened !
    message = Util.SerializeSdkError(callback.Result);
    }

    // We inform the end of the CreateUser call
    manualResetEvent.Set();
    }
    // We wait the end of the asynchronous call to CreateUser
    manualResetEvent.WaitOne();

    ...


    // Manage events "ConnectionStateChanged" and "InitializationPerformed"
    private void RbApplication_InitializationPerformed(object sender, EventArgs e)
    {
    // The init has been done successfully - so we set "manualResetInitialization"
    manualResetInitialization.Set();
    }

    private void RbApplication_ConnectionStateChanged(object sender, Rainbow.Events.ConnectionStateEventArgs e)
    {
    // If the connection is lost we need also to be informed - so we set "manualResetInitialization"
    if (e.State == Rainbow.Model.ConnectionState.Disconnected)
    manualResetInitialization.Set();
    }
    0
    Actions pour les commentaires Permalien
  • Rick LUPPINO

    Hi Christophe, 

    Thanks for the sample code. I had modified our code to handle the asynchronous calls better and got it working reliably but your example has helped me to improve that even further.

    Thanks.

    1
    Actions pour les commentaires Permalien

Vous devez vous connecter pour laisser un commentaire.

Vous n'avez pas trouvé ce que vous cherchez?

  • Contactez-nous

    Vous avez des questions? Laissez-nous un message pour obtenir plus d'informations.

    Contactez-nous
  • Demandez à la Communauté

    Vous avez besoin d'aide? Posez vos questions à la Communauté et obtenez des réponses d'autres utilisateurs Rainbow.

    Poster un message