コード例 #1
0
        private void UploadInfoToServer(bool isLive, string logToSend, Action callbackOnError = null)
        {
            if (MainWindowVM.CanUpload == false)
            {
                callbackOnError?.Invoke();
                return;
            }

            //RefreshAccessToken();

            FileMonitor.ResetStringBuilder();
            Task.Factory.StartNew(() =>
            {
                try
                {
                    LogSplitter.GetLastUploadHash(logToSend);
                    //if (api.IsSameLastUploadHash(vm.Account.MtgaHelperUserId, uploadHash))
                    //{
                    //    vm.WrapNetworkStatus(NetworkStatusEnum.UpToDate, () => Task.Delay(5000).Wait());
                    //    return;
                    //}

                    OutputLogResult result = null;
                    Guid?errorId           = null;
                    using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(logToSend ?? "")))
                    {
                        try
                        {
                            MainWindowVM.WrapNetworkStatus(NetworkStatusEnum.ProcessingLogFile, () =>
                            {
                                (result, errorId) = Reader.LoadFileContent(MainWindowVM.Account.MtgaHelperUserId, ms).Result;
                            });

                            if (result.CollectionByDate.Any(i => i.DateTime == default))
                            {
                                Api.LogErrorRemoteFile(MainWindowVM.Account.MtgaHelperUserId, logToSend, $"_NODATE_outputlog_{DateTime.Now:yyyyMMddHHmmss}.zip");
                            }

                            if (errorId.HasValue)
                            {
                                Api.LogErrorRemoteFile(MainWindowVM.Account.MtgaHelperUserId, logToSend, $"_parsererror_{errorId}_{DateTime.Now:yyyyMMddHHmmss}.zip");
                            }
                        }
                        catch (Exception ex)
                        {
                            if (logToSend != null)
                            {
                                Log.Error(ex, "Problem processing log piece ({logSize})", logToSend.Length);

                                Api.LogErrorRemoteFile(MainWindowVM.Account.MtgaHelperUserId, logToSend,
                                                       $"_unknownError{DateTime.Now:yyyyMMddHHmmss}.zip");
                            }
                        }
                    }

                    MainWindowVM.WrapNetworkStatus(NetworkStatusEnum.Uploading, () =>
                    {
                        CollectionResponse collection = Api.UploadOutputLogResult(MainWindowVM.Account.MtgaHelperUserId, result);
                        MainWindowVM.SetCollection(collection);
                        RefreshRareDraftingInfo();
                    });
                }
                catch (HttpRequestException ex)
                {
                    callbackOnError?.Invoke();
                    Log.Error(ex, "Error:");
                    MainWindowVM.SetProblemServerUnavailable();
                }
            });
        }