/// <summary> /// Downloads the latest configuration for a plugin /// </summary> /// <param name="pluginInfo">The plugin info.</param> /// <param name="path">The path.</param> /// <returns>Task.</returns> private async Task DownloadPluginConfiguration(PluginInfo pluginInfo, string path) { _logger.Info("Downloading {0} Configuration", pluginInfo.Name); // First download to a MemoryStream. This way if the download is cut off, we won't be left with a partial file using (var stream = await _apiClient.GetPluginConfigurationFileAsync(pluginInfo.Id).ConfigureAwait(false)) { using (var memoryStream = new MemoryStream()) { await stream.CopyToAsync(memoryStream).ConfigureAwait(false); memoryStream.Position = 0; using (var fs = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.Read, StreamDefaults.DefaultFileStreamBufferSize, true)) { await memoryStream.CopyToAsync(fs).ConfigureAwait(false); } } } File.SetLastWriteTimeUtc(path, pluginInfo.ConfigurationDateLastModified); }
/// <summary> /// Downloads a plugin assembly from the server /// </summary> /// <param name="plugin">The plugin.</param> /// <returns>Task.</returns> private async Task DownloadPlugin(PluginInfo plugin) { _logger.Info("Downloading {0} Plugin", plugin.Name); var path = Path.Combine(_appPaths.PluginsPath, plugin.AssemblyFileName); // First download to a MemoryStream. This way if the download is cut off, we won't be left with a partial file using (var memoryStream = new MemoryStream()) { var assemblyStream = await _apiClient.GetPluginAssemblyAsync(plugin).ConfigureAwait(false); await assemblyStream.CopyToAsync(memoryStream).ConfigureAwait(false); memoryStream.Position = 0; using (var fileStream = new FileStream(path, FileMode.Create)) { await memoryStream.CopyToAsync(fileStream).ConfigureAwait(false); } } }