Ejemplo n.º 1
0
        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);
                }
            }
        }
Ejemplo n.º 2
0
        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
            });
        }
Ejemplo n.º 3
0
 private void OnClearTable()
 {
     CloudEntries.Clear();
     _fileRecordInfoList.Clear();
 }
Ejemplo n.º 4
0
 private void OnCloudEntriesChanged()
 {
     ShowHelpText = !CloudEntries.Any();
     ShowUploadDescriptionTextBox = CloudEntries.Any();
     EnableClearAndUploadButton   = CloudEntries.Any();
 }
Ejemplo n.º 5
0
 public void RemoveCloudEntry(ICloudEntry entry)
 {
     _fileRecordInfoList.Remove(entry.FileRecordInfo);
     CloudEntries.Remove(entry);
 }