private async Task UploadRecords() { ShowUploadDescriptionTextBox = false; ShowUploadInfo = true; ShareUrl = string.Empty; EnableClearAndUploadButton = false; var sessions = CloudEntries.Select(ce => _recordManager.LoadData(ce.FileRecordInfo.FullPath)); var contentAsJson = JsonConvert.SerializeObject(sessions); using (var client = new HttpClient() { BaseAddress = new Uri(ConfigurationManager.AppSettings["WebserviceUri"]) }) { client.DefaultRequestHeaders.AddCXClientUserAgent(); if (_loginManager.State?.Token != null) { try { await _loginManager.RefreshTokenIfNeeded(); if (_loginManager.State.IsSigned) { client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", _loginManager.State.Token.AccessToken); } } catch (Exception e) { _logger.LogWarning(e, "Something went wrong while Refreshing the Accesstoken. Using Guest Mode"); } } var content = new StringContent(contentAsJson); content.Headers.ContentType.MediaType = "application/json"; var response = await client.PostAsync($@"SessionCollections?description={UploadDescription}", content); if (response.IsSuccessStatusCode) { ShareUrl = response.Headers.Location.ToString(); ShowUploadInfo = false; UploadDescription = string.Empty; _logger.LogInformation("Successfully uploaded Captures. ShareUrl is {shareUrl}", response.Headers.Location); } else { var responseBody = await response.Content.ReadAsStringAsync(); _logger.LogError("Upload of Captures failed. {error}", responseBody); } } }
private void AddCloudEntry(IFileRecordInfo recordInfo, ISession session) { if (recordInfo != null) { _fileRecordInfoList.Add(recordInfo); } else { return; } ShareUrl = string.Empty; CloudEntries.Add(new CloudEntry() { GameName = recordInfo.GameName, CreationDate = recordInfo.CreationDate, CreationTime = recordInfo.CreationTime, Comment = recordInfo.Comment, FileRecordInfo = recordInfo }); }
private void OnClearTable() { CloudEntries.Clear(); _fileRecordInfoList.Clear(); }
private void OnCloudEntriesChanged() { ShowHelpText = !CloudEntries.Any(); ShowUploadDescriptionTextBox = CloudEntries.Any(); EnableClearAndUploadButton = CloudEntries.Any(); }
public void RemoveCloudEntry(ICloudEntry entry) { _fileRecordInfoList.Remove(entry.FileRecordInfo); CloudEntries.Remove(entry); }