Esempio n. 1
0
        Session(SafeSessionHandle handle, NabtoClient owner, string token, string email, string password)
        {
            Log.Write("Session.Session()");

            this.handle   = handle;
            this.owner    = owner;
            this.Token    = token;
            this.Email    = email;
            this.Password = password;
        }
Esempio n. 2
0
        /// <summary>
        /// Create a Session.
        /// </summary>
        /// <param name="owner"></param>
        /// <param name="email"></param>
        /// <param name="password"></param>
        /// <param name="attemptCreateProfile"></param>
        /// <returns></returns>
        internal static Session Create(NabtoClient owner, string email, string password, bool attemptCreateProfile)
        {
            if (email == null)
            {
                throw new ArgumentNullException("email");
            }

            if (password == null)
            {
                throw new ArgumentNullException("password");
            }

            IntPtr nativeHandle;

            try
            {
                PlatformAdapter.Instance.nabtoOpenSession(out nativeHandle, email, password);

                var safeHandle = new SafeSessionHandle(nativeHandle);

                var buffer = new byte[1024];
                int tokenLength;

                PlatformAdapter.Instance.nabtoGetSessionToken(safeHandle.DangerousGetHandle(), buffer, out tokenLength);

                var token = tokenEncoding.GetString(buffer, 0, tokenLength);

                var session = new Session(safeHandle, owner, token, email, password);

                owner.Register(session);

                return(session);
            }
            catch (MissingProfileException)
            {
                if (attemptCreateProfile) // attempt to create the profile
                {
                    owner.CreateProfile(email, password);

                    return(Create(owner, email, password, false));
                }
                else // no go -> fail
                {
                    throw;
                }
            }
        }