Пример #1
0
        public void Process(string userId, string logFilePath)
        {
            OutputLogResult  result;
            OutputLogResult2 result2;
            Guid?            errorId;

            // Process
            Console.WriteLine("Processing file...");
            using (var stream = File.Open(logFilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
            {
                (result, errorId, result2) = reader.LoadFileContent(userId, stream).Result;
            }

            var matchCount  = result.MatchesByDate.Sum(i => i.Info.Count);
            var matchPlural = matchCount == 1 ? "" : "es";
            var totalCards  = result.GetLastCollection().Info
                              .Where(c => dictAllCards[c.Key].type.StartsWith("Basic Land") == false)
                              .Sum(c => c.Value);

            Console.WriteLine($"Processing completed. Found {matchCount} match{matchPlural} and {totalCards} cards in collection");

            // Upload
            Console.WriteLine("Uploading data to server...");
            api.UploadOutputLogResult(userId, result, result2);

            Console.WriteLine("Success! Your data on the server was updated.");
        }
Пример #2
0
        public void Process(string userId, string logFilePath)
        {
            OutputLogResult result;
            Guid?           errorId;

            // Process
            Console.WriteLine("Processing file...");
            using (var stream = File.Open(logFilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
            {
                (result, errorId) = reader.LoadFileContent(userId, stream).Result;
            }

            var matchCount  = result.MatchesByDate.Sum(i => i.Info.Count);
            var matchPlural = matchCount == 1 ? "" : "es";

            Console.WriteLine($"Processing completed. Found {matchCount} match{matchPlural} and {result.CollectionByDate.Sum(i => i.Info.Sum(c => c.Value))} cards in collection");

            // Upload
            Console.WriteLine("Uploading data to server...");
            api.UploadOutputLogResult(userId, result);

            Console.WriteLine("Success! Your data on the server was updated.");
        }
        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();
                }
            });
        }