예제 #1
0
        /// <summary>
        /// Adds or updates a <see cref="RecentFile"/> entity into the database.
        /// </summary>
        /// <param name="fileSave">The <see cref="FileSave"/> entity to use for a recent file data.</param>
        /// <returns><c>true</c> if the operation was successful, <c>false</c> otherwise.</returns>
        public static bool AddOrUpdateRecentFile(FileSave fileSave)
        {
            try
            {
                var dbContext  = ScriptNotepadDbContext.DbContext;
                var recentFile = dbContext.RecentFiles.FirstOrDefault(f =>
                                                                      f.FileNameFull == fileSave.FileNameFull && f.Session.SessionName == fileSave.Session.SessionName);

                if (recentFile != null)
                {
                    recentFile.ClosedDateTime = DateTime.Now;
                    recentFile.SetEncoding(fileSave.GetEncoding());
                }
                else
                {
                    dbContext.RecentFiles.Add(new RecentFile
                    {
                        FileNameFull     = fileSave.FileNameFull,
                        Session          = fileSave.Session,
                        EncodingAsString = EncodingData.EncodingToString(fileSave.GetEncoding()),
                        ClosedDateTime   = DateTime.Now,
                        FileName         = fileSave.FileName,
                        FilePath         = fileSave.FilePath,
                    });
                }

                dbContext.SaveChanges();
                return(true);
            }
            catch (Exception ex)
            {
                // log the exception..
                ErrorHandlingBase.ExceptionLogAction?.Invoke(ex);
                return(false);
            }
        }
예제 #2
0
 /// <summary>
 /// Gets the encoding of the recent file.
 /// </summary>
 /// <param name="recentFile">The <see cref="RecentFile"/> instance.</param>
 /// <param name="value">The encoding to set for the recent file.</param>
 public static void SetEncoding(this RecentFile recentFile, Encoding value)
 {
     recentFile.EncodingAsString = EncodingData.EncodingToString(value);
 }