コード例 #1
0
 private void OnSetExternalStorageInfo(object sender, RoutedEventArgs e)
 {
     ExternalStorageDataContract.DesiredProperties desiredProperties = new ExternalStorageDataContract.DesiredProperties();
     desiredProperties.connectionString = AzureStorageDesiredConnectionString.Text;
     SetDesired(ExternalStorageDataContract.SectionName, desiredProperties.ToJsonString()).FireAndForget();
 }
        /// <summary>
        /// Install a certificate via device twin.
        /// </summary>
        private async void InstallCertButton_ClickAsync(object sender, RoutedEventArgs e)
        {
            if (App.STORAGECONNSTRING.Length == 0)
            {
                _mainPage.ShowDialogAsync("Missing Connection String", "Please enter the Storage Connection String in Settings");
                return;
            }

            string certHashInstall = CertHashInstallInput.Text;
            string certFileName    = CertFileNameInput.Text;

            if (certHashInstall.Length == 0 || certFileName.Length == 0)
            {
                _mainPage.ShowDialogAsync("Invaid Input", "Please enter all fields to Install certificate");
                return;
            }

            ExternalStorageDataContract.DesiredProperties desiredProperties = new ExternalStorageDataContract.DesiredProperties();
            desiredProperties.connectionString = App.STORAGECONNSTRING;

            CertificatesDataContract.CertificateInfo certificateInfo = new CertificatesDataContract.CertificateInfo();
            certificateInfo.Hash            = certHashInstall;
            certificateInfo.StorageFileName = certFileName;
            certificateInfo.State           = CertificatesDataContract.JsonStateInstalled;

            CertificatesDataContract.DesiredProperties certDesiredProperties = new CertificatesDataContract.DesiredProperties();
            switch (CertPathInstallCombobox.SelectedValue)
            {
            case CertificateStore.rootCATrustedCertificates_Root:
                certDesiredProperties.rootCATrustedCertificates_Root.Add(certificateInfo);
                break;

            case CertificateStore.rootCATrustedCertificates_CA:
                certDesiredProperties.rootCATrustedCertificates_CA.Add(certificateInfo);
                break;

            case CertificateStore.rootCATrustedCertificates_TrustedPublisher:
                certDesiredProperties.rootCATrustedCertificates_TrustedPublisher.Add(certificateInfo);
                break;

            case CertificateStore.rootCATrustedCertificates_TrustedPeople:
                certDesiredProperties.rootCATrustedCertificates_TrustedPeople.Add(certificateInfo);
                break;

            case CertificateStore.certificateStore_CA_System:
                certDesiredProperties.certificateStore_CA_System.Add(certificateInfo);
                break;

            case CertificateStore.certificateStore_Root_System:
                certDesiredProperties.certificateStore_Root_System.Add(certificateInfo);
                break;

            case CertificateStore.certificateStore_My_User:
                certDesiredProperties.certificateStore_My_User.Add(certificateInfo);
                break;

            case CertificateStore.certificateStore_My_System:
                certDesiredProperties.certificateStore_My_System.Add(certificateInfo);
                break;

            default:
                break;
            }

            string refreshingValue = "\"refreshing\"";
            string finalValue      = "{" + desiredProperties.ToJsonString() + ", " + certDesiredProperties.ToJsonString() + "}";
            await _mainPage.UpdateTwinData(refreshingValue, finalValue);
        }