コード例 #1
0
        private async void Page_Loaded(object sender, RoutedEventArgs e)
        {
            List <Device> devices = await IOTMessages.GetDevicesList();

            foreach (Device device in devices)
            {
                IOTDevice dev = new IOTDevice();

                if (device.Status.Equals(DeviceStatus.Enabled))
                {
                    dev.IsEnabled = true;
                }

                dev.LastExecutionTime  = device.LastActivityTime;
                dev.ConnectionStateIOT = device.ConnectionState.ToString();
                dev.IdIOT = device.Id;

                if (device.Id.Equals(App.deviceIDMobile))
                {
                    dev.IsDeviceHome = "Collapsed";
                }
                else
                {
                    dev.IsDeviceHome = "Visible";
                }

                HubSection   hubSection = new HubSection();
                DataTemplate template   = this.Resources["TemplateGrid"] as DataTemplate;

                TextBlock headerTextBlock = new TextBlock();
                headerTextBlock.Text       = device.Id;
                headerTextBlock.Foreground = new SolidColorBrush(Colors.LightSteelBlue);
                hubSection.Header          = headerTextBlock;
                hubSection.Padding         = new Thickness(40, 30, 150, 44);

                hubSection.DataContext     = dev;
                hubSection.ContentTemplate = template;
                hSettings.Sections.Add(hubSection);
            }
        }
コード例 #2
0
        private async void mainFrame_Loaded(object sender, RoutedEventArgs e)
        {
            if (App.IsMobile.Equals("IoT"))
            {
                spHome.Visibility     = Visibility.Collapsed;
                spAccount.Visibility  = Visibility.Collapsed;
                spLive.Visibility     = Visibility.Collapsed;
                spSettings.Visibility = Visibility.Collapsed;
                spFeedback.Visibility = Visibility.Collapsed;
                spAlert.Visibility    = Visibility.Collapsed;
            }

            while (true)
            {
                deviceClient = DeviceClient.Create(App.IOTUrl, new DeviceAuthenticationWithRegistrySymmetricKey(App.deviceIDMobile, App.deviceKeyMobile));

                Microsoft.Azure.Devices.Client.Message receivedMessage = await deviceClient.ReceiveAsync();

                if (receivedMessage == null)
                {
                    continue;
                }

                if (App.IsMobile.Equals("IoT"))
                {
                    txtMainMessages.Text = txtMainMessages.Text + "\n" + Encoding.ASCII.GetString(receivedMessage.GetBytes());
                }
                else
                {
                    alertDialog(Encoding.ASCII.GetString(receivedMessage.GetBytes()));
                }

                if (App.IsMobile.Equals("IoT"))
                {
                    await IOTMessages.SendCloudToDeviceMessageAsync("Windows10Desktop", "SPYCameraIOT > Ping received from " + App.deviceIDMobile + " on " + System.DateTime.Now.ToString());
                }

                await deviceClient.CompleteAsync(receivedMessage);
            }
        }
コード例 #3
0
 private async void btnPing_Click(object sender, RoutedEventArgs e)
 {
     await IOTMessages.SendCloudToDeviceMessageAsync(((Button)sender).Tag.ToString(), "SPYCameraIOT > Ping test from " + App.deviceIDMobile + " requested on " + System.DateTime.Now.ToString() + ".");
 }