예제 #1
0
        public static async Task <Device> PowerOnAsync(string liveId, int times = 5, int delay = 1000, string addressOrHostname = "")
        {
            var messageTransport = new MessageTransport();

            if (!string.IsNullOrEmpty(addressOrHostname))
            {
                messageTransport = new MessageTransport(addressOrHostname);
            }

            using (messageTransport)
            {
                var poweronRequestMessage = new PowerOnMessage {
                    LiveId = liveId
                };

                for (var i = 0; i < times; i++)
                {
                    await messageTransport.SendAsync(poweronRequestMessage);

                    await Task.Delay(delay);
                }

                var presenceRequestMessage = new PresenceRequestMessage();

                var response = await TaskExtensions.WithRetries(() =>
                                                                messageTransport.WaitForMessageAsync <PresenceResponseMessage>(pingTimeout,
                                                                                                                               () => messageTransport.SendAsync(presenceRequestMessage).Wait()),
                                                                pingRetries);

                return(new Device(response));
            }
        }
예제 #2
0
        public static async Task <Device> PingAsync(string addressOrHostname)
        {
            using (var messageTransport = new MessageTransport(addressOrHostname))
            {
                var requestMessage = new PresenceRequestMessage();

                var response = await TaskExtensions.WithRetries(() =>
                                                                messageTransport.WaitForMessageAsync <PresenceResponseMessage>(pingTimeout,
                                                                                                                               () => messageTransport.SendAsync(requestMessage).Wait()),
                                                                pingRetries);

                return(new Device(response));
            }
        }
예제 #3
0
        public static async Task <SmartGlassClient> ConnectAsync(
            string addressOrHostname, string xboxLiveUserHash, string xboxLiveAuthorization)
        {
            var device = await Device.PingAsync(addressOrHostname);

            var cryptoContext = new CryptoContext(device.Certificate);

            using (var transport = new MessageTransport(device.Address.ToString(), cryptoContext))
            {
                var deviceId       = Guid.NewGuid();
                var sequenceNumber = 0u;

                var initVector = CryptoContext.GenerateRandomInitVector();

                Func <Task> connectFunc = async() =>
                {
                    var requestMessage = new ConnectRequestMessage();

                    requestMessage.InitVector = initVector;

                    requestMessage.DeviceId = deviceId;

                    requestMessage.UserHash      = xboxLiveUserHash;
                    requestMessage.Authorization = xboxLiveAuthorization;

                    requestMessage.SequenceNumber = sequenceNumber;
                    requestMessage.SequenceBegin  = sequenceNumber + 1;
                    requestMessage.SequenceEnd    = sequenceNumber + 1;

                    sequenceNumber += 2;

                    await transport.SendAsync(requestMessage);
                };

                var response = await TaskExtensions.WithRetries(() =>
                                                                transport.WaitForMessageAsync <ConnectResponseMessage>(
                                                                    connectTimeout,
                                                                    () => connectFunc().Wait()),
                                                                connectRetries);

                return(new SmartGlassClient(
                           device,
                           response,
                           cryptoContext));
            }
        }