예제 #1
0
        /// <summary>
        /// Saves a current post to the draft file.
        /// </summary>
        /// <param name="title"></param>
        /// <param name="urlOrText"></param>
        /// <param name="isSelfText"></param>
        /// <param name="subreddit"></param>
        public async Task<bool> SavePostSubmissionDraft(PostSubmissionDraftData data)
        {
            try
            {
                // Get the folder and file.
                StorageFolder folder = Windows.Storage.ApplicationData.Current.LocalFolder;
                StorageFile file = await folder.CreateFileAsync(c_postDraftFile, CreationCollisionOption.ReplaceExisting);

                // Serialize the data
                string fileData = JsonConvert.SerializeObject(data);

                // Write to the file
                await Windows.Storage.FileIO.WriteTextAsync(file, fileData);
            }
            catch(Exception e)
            {
                m_baconMan.MessageMan.DebugDia("failed to write draft", e);
                m_baconMan.TelemetryMan.ReportUnexpectedEvent(this, "FailedToWriteDraftFile",e);
                return false;
            }
            return true;
        }
예제 #2
0
        /// <summary>
        /// Saves a current post to the draft file.
        /// </summary>
        /// <param name="data"></param>
        public async Task <bool> SavePostSubmissionDraft(PostSubmissionDraftData data)
        {
            try
            {
                // Get the folder and file.
                var folder = ApplicationData.Current.LocalFolder;
                var file   = await folder.CreateFileAsync(PostDraftFile, CreationCollisionOption.ReplaceExisting);

                // Serialize the data
                var fileData = JsonConvert.SerializeObject(data);

                // Write to the file
                await FileIO.WriteTextAsync(file, fileData);
            }
            catch (Exception e)
            {
                _baconMan.MessageMan.DebugDia("failed to write draft", e);
                TelemetryManager.ReportUnexpectedEvent(this, "FailedToWriteDraftFile", e);
                return(false);
            }
            return(true);
        }
예제 #3
0
        /// <summary>
        /// Will save a draft of what the user currently has.
        /// </summary>
        private async Task SaveDraft()
        {
            // If we have nothing to save don't
            if(!HasInfoToDraft())
            {
                return;
            }

            // Make the data
            PostSubmissionDraftData data = new PostSubmissionDraftData()
            {
                Title = ui_postTitleTextBox.Text,
                UrlOrText = ui_postUrlTextBox.Text,
                isSelfText = ui_isSelfPostCheckBox.IsChecked.Value,
                Subreddit = ui_subredditSuggestBox.Text
            };

            // Save the data
            bool success = await App.BaconMan.DraftMan.SavePostSubmissionDraft(data);

            // Print the last save time
            if(success)
            {
                ui_lastDraftSaveTime.Text = "Saved at " + DateTime.Now.ToString("hh:mm:ss");
            }
        }