async partial void ConnectToBandClick(UIButton sender)
        {
            if (client == null)
            {
                // get the client
                client = manager.AttachedClients.FirstOrDefault();
                if (client == null)
                {
                    Output("Failed! No Bands attached.");
                }
                else
                {
                    try {
                        Output("Please wait. Connecting to Band...");
                        await manager.ConnectTaskAsync(client);

                        Output("Band connected.");
                    } catch (BandException ex) {
                        Output("Failed to connect to Band:");
                        Output(ex.Message);
                    }
                }
            }
            else
            {
                Output("Please wait. Disconnecting from Band...");
                await manager.DisconnectTaskAsync(client);

                Output("Band disconnected.");
            }
        }
Exemplo n.º 2
0
        async partial void ConnectToBandClick(UIButton sender)
        {
            if (client == null)
            {
                // get the client
                client = manager.AttachedClients.FirstOrDefault();

                if (client == null)
                {
                    Output("Failed! No Bands attached.");
                }
                else
                {
                    // attach event handlers
                    client.ButtonPressed += (_, e) => {
                        Output(string.Format("Button {0} Pressed: {1}", e.TileButtonEvent.ElementId, e.TileButtonEvent.TileName));
                    };
                    client.TileOpened += (_, e) => {
                        Output(string.Format("Tile Opened: {0}", e.TileEvent.TileName));
                    };
                    client.TileClosed += (_, e) => {
                        Output(string.Format("Tile Closed: {0}", e.TileEvent.TileName));
                    };

                    try {
                        Output("Please wait. Connecting to Band...");
                        await manager.ConnectTaskAsync(client);
                    } catch (BandException ex) {
                        Output("Failed to connect to Band:");
                        Output(ex.Message);
                    }
                }
            }
            else
            {
                Output("Please wait. Disconnecting from Band...");
                await manager.DisconnectTaskAsync(client);

                client = null;
            }
        }