Ejemplo n.º 1
0
        public int SpinDelay = 1000; //in miliseconds

        public bool StartPair(string frontendUrl, string redirectUri, NodeConfig conf, string selfUrl, NodePairingBackend.OnPairedDelegate OnPairedcb, NodePairingBackend.OnPairingFailedDelegate OnPairingFailedCB)
        {
            this.conf = conf;

            //pairing backend
            var    backend = new NodePairingBackend(frontendUrl, conf, OnPairedcb, OnPairingFailedCB);
            string token2  = backend.pairGetTokens(redirectUri);

            pairingURI = backend.pairingPostUrl + "/" + API.Plegma.NodePairing.NodePairingConstants.UserConfirmPageURI + "?token2=" + token2;

            if (UriCustomLauncher != null)
            {
                UriCustomLauncher(pairingURI);
            }
            else
            {
#if NETFX
                Process.Start(pairingURI);
#else
                Windows.System.Launcher.LaunchUriAsync(new Uri(pairingURI)).AsTask();
#endif
            }

            //wait for finish
            Task.Delay(1000).Wait();
            Task.Run(() =>
            {
                while (true)
                {
                    var keys = backend.pairGetKeys();
                    if (keys != null)
                    {
                        if (keys.Item1.IsValid && keys.Item2 != null && keys.Item3 == System.Net.HttpStatusCode.OK)
                        {
                            return(true);
                        }

                        if (keys.Item3 == System.Net.HttpStatusCode.Forbidden ||
                            keys.Item3 == System.Net.HttpStatusCode.BadRequest)
                        {
                            return(false);
                        }

                        Task.Delay(SpinDelay).Wait();
                    }
                }
            });
            return(true);
        }
Ejemplo n.º 2
0
        public bool StartPair(string frontendUrl, string redirectUrl, NodeConfig conf, string selfUrl, NodePairingBackend.OnPairedDelegate OnPairedcb, NodePairingBackend.OnPairingFailedDelegate OnPairingFailedCb)
        {
            lock (this)
            {
                //pairing already in progress
                if (host != null || NancyPairingModule.backend != null)
                {
                    return(false);
                }

                //sanity checks
                if (string.IsNullOrWhiteSpace(selfUrl))
                {
                    return(false);
                }

                this.conf = conf;

                //pairing backend
                NancyPairingModule.backend = new Yodiwo.NodeLibrary.Pairing.NodePairingBackend(frontendUrl, conf, OnPairedcb, OnPairingFailedCb);
                startHttpServer(selfUrl);
                return(true);
            }
        }