예제 #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);
                }
            }
        }
        private void AddAggregationEntry(IFileRecordInfo recordInfo, ISession session)
        {
            if (recordInfo == null)
            {
                return;
            }

            if (_fileRecordInfoList.Any())
            {
                if (!_fileRecordInfoList.All(info => info.ProcessName == recordInfo.ProcessName))
                {
                    return;
                }
            }

            _fileRecordInfoList.Add(recordInfo);

            session = session ?? _recordManager.LoadData(recordInfo.FullPath);
            var frametimes = session.Runs.SelectMany(r => r.CaptureData.MsBetweenPresents).ToList();

            var metricAnalysis = _statisticProvider
                                 .GetMetricAnalysis(frametimes, SelectedSecondMetric.ConvertToString(),
                                                    SelectedThirdMetric.ConvertToString());

            AggregationEntries.Add(new AggregationEntry()
            {
                GameName          = recordInfo.GameName,
                CreationDate      = recordInfo.CreationDate,
                CreationTime      = recordInfo.CreationTime,
                AverageValue      = metricAnalysis.Average,
                SecondMetricValue = metricAnalysis.Second,
                ThirdMetricValue  = metricAnalysis.Third,
                MetricAnalysis    = metricAnalysis,
                FileRecordInfo    = recordInfo
            });
        }