Пример #1
0
        //--------------------------------------------------------------------------------------------------------------------
        #endregion

        #region Functions
        //--------------------------------------------------------------------------------------------------------------------
        public string pairGetTokens(string redirectUri)
        {
            var req = new PairingNodeGetTokensRequest()
            {
                uuid        = this.conf.uuid,
                name        = this.conf.Name,
                image       = this.conf.Image,
                description = this.conf.Description,
                pathcss     = this.conf.Pathcss,
                PairingCompletionInstructions = this.conf.Pairing_CompletionInstructions,
                NoUUIDAuthentication          = this.conf.Pairing_NoUUIDAuthentication,
                RedirectUri = redirectUri,
            };
            var uri = this.pairingPostUrl + "/" + NodePairingConstants.s_GetTokensRequest;
            PairingServerTokensResponse resp = (PairingServerTokensResponse)jsonPost(uri, req, typeof(PairingServerTokensResponse));

            if (resp != null)
            {
                this.token1 = resp.token1;
                this.token2 = resp.token2;
                if (this.token1 != null && this.token2 != null)
                {
                    pairingState = PairingStates.TokensSentToNode;
                    return(this.token2);
                }
            }
            return(null);
        }
Пример #2
0
        //--------------------------------------------------------------------------------------------------------------------
        #endregion

        #region Functions
        //--------------------------------------------------------------------------------------------------------------------
        public string pairGetTokens(string redirectUri)
        {
            var req = new PairingNodeGetTokensRequest()
            {
                uuid        = this.conf.uuid,
                name        = this.conf.Name,
                image       = this.conf.Image,
                description = this.conf.Description,
                pathcss     = this.conf.Pathcss,
                PairingCompletionInstructions = this.conf.Pairing_CompletionInstructions,
                NoUUIDAuthentication          = this.conf.Pairing_NoUUIDAuthentication,
                RedirectUri = redirectUri,
            };

            try
            {
                var response = Yodiwo.Tools.Http.RequestPost(this.pairingPostUrl + "/" + NodePairingConstants.s_GetTokensRequest,
                                                             req.ToJSON(),
                                                             HttpRequestDataFormat.Json,
                                                             null);

                if (response.StatusCode != HttpStatusCode.OK)
                {
                    onPairingFailed("HTTP Request for tokens failed with " + response.StatusCode);
                    return(null);
                }
                if (string.IsNullOrWhiteSpace(response.ResponseBodyText))
                {
                    onPairingFailed("HTTP Request for tokens returned empty body");
                    return(null);
                }
                var resp = response.ResponseBodyText.FromJSON <PairingServerTokensResponse>();
                if (resp != null)
                {
                    this.token1 = resp.token1;
                    this.token2 = resp.token2;
                    if (this.token1 != null && this.token2 != null)
                    {
                        pairingState = PairingStates.TokensSentToNode;
                        return(this.token2);
                    }
                }
            }
            catch (Exception ex)
            {
                DebugEx.TraceErrorException(ex);
            }
            return(null);
        }