Exemplo n.º 1
0
 public void Save(Quiz quiz)
 {
     Quiz        = quiz;
     LastUpdated = DateTime.Now;
     AtomicIO.AtomicWrite(RecoveryFilePath, JsonConvert.SerializeObject(this, Formatting.Indented));
 }
Exemplo n.º 2
0
        private bool SaveQuiz(bool saveAs = false, string customPath = null)
        {
            string path = null;

            if (customPath == null)
            {
                if (QuizPath == null || saveAs)
                {
                    sfd_quiz.InitialDirectory = ConfigManager.Config.StorageConfig.DefaultQuizSaveFolder;
                    int untitledCounter = 1;
                    path = $"Untitled{ untitledCounter }.steelquiz";
                    while (File.Exists(Path.Combine(QuizCore.QUIZ_FOLDER_DEFAULT, path)))
                    {
                        ++untitledCounter;
                        path = $"Untitled{ untitledCounter }.steelquiz";
                    }

                    var sfd = sfd_quiz.ShowDialog();
                    if (sfd != DialogResult.OK)
                    {
                        return(false);
                    }

                    if (QuizPath != sfd_quiz.FileName)
                    {
                        QuizGuid = Guid.NewGuid(); // create new guid if path is not the same
                    }
                    path = sfd_quiz.FileName;
                }
                else
                {
                    path = QuizPath;
                }
            }
            else
            {
                path = customPath;
            }

            UseWaitCursor = true;

            var quiz = ConstructQuiz();

            AtomicIO.AtomicWrite(path, JsonConvert.SerializeObject(quiz, Formatting.Indented));

            if (customPath == null)
            {
                QuizPath             = path;
                ChangedSinceLastSave = false;
            }

            QuizCore.LoadQuizAccessData();

            QuizCore.QuizIdentities[quiz.GUID]  = new QuizIdentity(quiz.GUID, QuizPath);
            QuizCore.QuizAccessTimes[quiz.GUID] = DateTime.Now;

            QuizCore.SaveQuizAccessData();

            UseWaitCursor = false;

            ShowNotification("Quiz has been saved", 3000);
            return(true);
        }