public static BlobInfo BlobInfoFromSource(string connectionString, string containerAndFile) { string[] sourceParts = containerAndFile.Split('\\'); if (sourceParts.Length != 2) { throw new Exception("container name is missing in: " + containerAndFile); } IoTDMClient.BlobInfo info = new IoTDMClient.BlobInfo(); info.ConnectionString = connectionString; info.ContainerName = sourceParts[0]; info.BlobName = sourceParts[1]; return(info); }
private static async Task DownloadCertificates(DeviceManagementClient client, string connectionString, string containerName, HashSet <string> certificateFilesSet) { // ToDo: since our cache is temporary, we might have to download those files everytime to verify the hashes. Debug.Assert(certificateFilesSet != null); foreach (string fileName in certificateFilesSet) { IoTDMClient.BlobInfo blobInfo = new IoTDMClient.BlobInfo(); blobInfo.ConnectionString = connectionString; blobInfo.ContainerName = containerName; blobInfo.BlobName = fileName; Debug.WriteLine("Downloading " + blobInfo.BlobName); await blobInfo.DownloadToTempAsync(client); } }
public static BlobInfo BlobInfoFromSource(string connectionString, string containerAndFile) { char[] separators = { '\\', '/' }; int separatorIndex = containerAndFile.IndexOfAny(separators); if (separatorIndex == -1 || separatorIndex == 0 || separatorIndex == containerAndFile.Length - 1) { throw new Exception("unexpected container/blob name: " + containerAndFile); } IoTDMClient.BlobInfo info = new IoTDMClient.BlobInfo(); info.ConnectionString = connectionString; info.ContainerName = containerAndFile.Substring(0, separatorIndex); info.BlobName = containerAndFile.Substring(separatorIndex + 1); return(info); }
private static async Task DownloadCertificates(ISystemConfiguratorProxy systemConfiguratorProxy, string connectionString, HashSet <string> certificateFilesSet) { // ToDo: since our cache is temporary, we might have to download those files everytime to verify the hashes. Debug.Assert(certificateFilesSet != null); foreach (string fileName in certificateFilesSet) { string [] fileNameParts = fileName.Split('\\'); if (fileNameParts.Length != 2) { throw new Exception("Incorrect azure storage specification! The format should be containerName\\blobName."); } IoTDMClient.BlobInfo blobInfo = new IoTDMClient.BlobInfo(); blobInfo.ConnectionString = connectionString; blobInfo.ContainerName = fileNameParts[0]; blobInfo.BlobName = fileNameParts[1]; Debug.WriteLine("Downloading " + blobInfo.BlobName); await blobInfo.DownloadToTempAsync(systemConfiguratorProxy); } }
private async Task InstallAppFromAzureAsync(AppInfo currentState, string connectionString, AppxManagementDataContract.AppDesiredState desiredState, bool selfUpdate) { // Is this a fresh installation? if (currentState == null) { currentState = new AppInfo(); currentState.PackageFamilyName = desiredState.packageFamilyName; currentState.Version = AppxManagementDataContract.VersionNotInstalled; currentState.InstallDate = ""; } AppxManagementDataContract.AppReportedState reportedState = null; try { Logger.Log("-> installing " + desiredState.packageFamilyName + " from " + desiredState.appxSource, LoggingLevel.Verbose); if (String.IsNullOrEmpty(desiredState.appxSource)) { throw new Error(ErrorCodes.INVALID_DESIRED_APPX_SRC, "Cannot install appx without a source."); } var requestData = new AppInstallRequestData(); requestData.PackageFamilyName = desiredState.packageFamilyName; requestData.StartUp = AppUtils.StartUpTypeToMessage(desiredState.startUp); // Downloading dependencies... Logger.Log(DateTime.Now.ToString("HH:mm:ss") + " Downloading...", LoggingLevel.Verbose); if (!String.IsNullOrEmpty(desiredState.depsSources)) { string[] depsSources = desiredState.depsSources.Split(';'); for (int i = 0; i < depsSources.Length; ++i) { IoTDMClient.BlobInfo dependencyBlob = IoTDMClient.BlobInfo.BlobInfoFromSource(connectionString, depsSources[i]); Logger.Log(DateTime.Now.ToString("HH:mm:ss") + " Downloading " + dependencyBlob.BlobName, LoggingLevel.Verbose); var dependencyPath = await dependencyBlob.DownloadToTempAsync(this._systemConfiguratorProxy); Logger.Log(dependencyPath, LoggingLevel.Verbose); requestData.Dependencies.Add(dependencyPath); } } // Downloading certificates... Logger.Log(DateTime.Now.ToString("HH:mm:ss") + " Downloading appx certificate...", LoggingLevel.Verbose); IoTDMClient.BlobInfo certificateBlob = IoTDMClient.BlobInfo.BlobInfoFromSource(connectionString, desiredState.certSource); requestData.CertFile = await certificateBlob.DownloadToTempAsync(this._systemConfiguratorProxy); requestData.CertStore = desiredState.certStore; // Downloading appx... Logger.Log(DateTime.Now.ToString("HH:mm:ss") + " Downloading appx...", LoggingLevel.Verbose); IoTDMClient.BlobInfo appxBlob = IoTDMClient.BlobInfo.BlobInfoFromSource(connectionString, desiredState.appxSource); requestData.AppxPath = await appxBlob.DownloadToTempAsync(this._systemConfiguratorProxy); requestData.IsDMSelfUpdate = selfUpdate; // Installing appx... Logger.Log(DateTime.Now.ToString("HH:mm:ss") + " Installing appx...", LoggingLevel.Verbose); AppInstallResponse response = await InstallAppAsync(requestData); if (response.data.pending) { Logger.Log(DateTime.Now.ToString("HH:mm:ss") + " Installing appx is pending...", LoggingLevel.Verbose); Debug.Assert(selfUpdate); reportedState = new AppxManagementDataContract.AppReportedState(desiredState.packageFamilyId, desiredState.packageFamilyName, CommonDataContract.JsonPending, AppUtils.StartUpTypeFromMessage(response.data.startUp), response.data.installDate, 0, null, JsonReport.Report); _stateToReport[desiredState.packageFamilyId] = reportedState; return; } else { Logger.Log(DateTime.Now.ToString("HH:mm:ss") + " Done installing appx...", LoggingLevel.Verbose); Error e = null; if (desiredState.version.ToString() != response.data.version) { if (currentState.Version == response.data.version) { e = new Error(ErrorCodes.INVALID_INSTALLED_APP_VERSION_UNCHANGED, "Installating the supplied appx succeeded, but the new app version is not the desired version, and is the same as the old app version."); } else { e = new Error(ErrorCodes.INVALID_INSTALLED_APP_VERSION_UNEXPECTED, "Installating the supplied appx succeeded, but the new app version is not the desired version."); } } reportedState = new AppxManagementDataContract.AppReportedState(desiredState.packageFamilyId, desiredState.packageFamilyName, response.data.version, AppUtils.StartUpTypeFromMessage(response.data.startUp), response.data.installDate, (e != null? e.HResult : 0), (e != null ? e.Message : null), JsonReport.Report); _stateToReport[desiredState.packageFamilyId] = reportedState; return; } } catch (Error e) { reportedState = new AppxManagementDataContract.AppReportedState(desiredState.packageFamilyId, desiredState.packageFamilyName, currentState.Version, AppUtils.StartUpTypeFromMessage(currentState.StartUp), currentState.InstallDate, // install date e.HResult, e.Message, JsonReport.Report); } catch (Exception e) { reportedState = new AppxManagementDataContract.AppReportedState(desiredState.packageFamilyId, desiredState.packageFamilyName, currentState.Version, AppUtils.StartUpTypeFromMessage(currentState.StartUp), currentState.InstallDate, // install date e.HResult, e.Message, JsonReport.Report); } _stateToReport[desiredState.packageFamilyId] = reportedState; throw new Exception("Failed to install " + desiredState.packageFamilyName); }