Пример #1
0
        public void SubmitGameSaveToServer(Game game, LocalGameSave localSave)
        {
            AddNewSaveTransfer(game);

            var progressStream = LoadSaveIntoProgressStream(localSave);
            progressStream.BytesRead += (sender, args) => OnGameSaveUploadBytesRead(game.Id, args);

            App.GameHub.UploadSave(progressStream)
                .ContinueWith(t =>
                {
                    var saveTransfer = CurrentSaveTransfers.FirstOrDefault(st => st.GameId == game.Id);
                    if (saveTransfer != null)
                    {
                        if (t.IsFaulted)
                        {
                            Log.Error($"Uploading save for game #{game.Id}", t.Exception);
                            saveTransfer.IsFailed = true;
                            RetrySaveTransferAfterWait(saveTransfer, () => SubmitGameSaveToServer(game, localSave));
                        }
                        else
                        {
                            UpdateSaveTransfer(saveTransfer, 100);

                            _localSaveManager.ArchiveFile(localSave);

                            SaveUploadResult uploadResult = t.Result;
                            if (uploadResult != null)
                            {
                                App.ToastMaker.ShowToast("Error Submitting Turn", uploadResult.Message);
                            }
                        }
                    }
                });
        }
Пример #2
0
        private static ProgressStream LoadSaveIntoProgressStream(LocalGameSave localSave)
        {
            var memStream = new MemoryStream();
            localSave.GameSave.Save(memStream);
            memStream.Position = 0;

            var progressStream = new ProgressStream(memStream);
            return progressStream;
        }
 public NewGameSaveDetectedArgs(int gameId, LocalGameSave save)
 {
     GameId = gameId;
     Save = save;
 }
        public void ArchiveFile(LocalGameSave localSave)
        {
            if (App.SyncedSettings.ArchiveSubmittedFiles && File.Exists(localSave.LocalFilePath))
            {
                try
                {
                    using (var tmpStream = FileOpenUtil.TryGetStream(localSave.LocalFilePath, FileAccess.Write))
                    {
                        tmpStream.Close();
                    }

                    string archiveFileName = string.Format(
                        "MR-{0}_{1}{2}",
                        localSave.GameSave.Name,
                        DateTime.Now.ToString("MMddyy-hhmmss"),
                        GameManager.SavedGameExtension);

                    var archiveFilePath = Path.Combine(GetArchiveFolderPath(), archiveFileName);
                    File.Move(localSave.LocalFilePath, archiveFilePath);
                }
                catch (Exception exc)
                {
                    Log.Debug("Archiving file.", exc);
                }
            }
        }