示例#1
0
 /// <summary>
 /// Determines whether [is on new day automatic save required] [the specified automatic save].
 /// </summary>
 /// <param name="autoSave">The automatic save.</param>
 /// <param name="fHeader">The f header.</param>
 /// <param name="dt">The dt.</param>
 /// <returns></returns>
 static public Boolean IsOnNewDayAutoSaveRequired(RIAutoSaveInfo autoSave, RIFileHeader fHeader, DateTime dt)
 {
     // see if this message's time stamp exceeds next day,
     // if so, force an auto save condition is SaveOnNewDay was set
     return(autoSave.SaveOnNewDay && fHeader.FInitDateTime != DateTime.MinValue &&
            (dt.ToLocalTime().Date.Subtract(fHeader.FInitDateTime.ToLocalTime().Date).TotalDays >= 1));
 }
示例#2
0
        /// <summary>
        /// Shoulds the automatic save.
        /// </summary>
        /// <param name="fileHeader">The file header.</param>
        /// <param name="autoSave">The automatic save.</param>
        /// <param name="stream">The stream.</param>
        /// <param name="onFileSize">Size of the on file.</param>
        /// <param name="messageDateTime">The message date time.</param>
        /// <param name="messageLength">Length of the message.</param>
        /// <returns></returns>
        static public Boolean ShouldAutoSave(RIFileHeader fileHeader, RIAutoSaveInfo autoSave, Stream stream, Int64 onFileSize, DateTime messageDateTime, Int32 messageLength)
        {
            Boolean save = false;

            if (FileHelper.IsOnNewDayAutoSaveRequired(autoSave, fileHeader, messageDateTime) ||
                fileHeader.FMessageCount >= autoSave.SaveOnMsgLimit ||
                (fileHeader.FMessageCount > 0 && onFileSize > 0 && (messageLength + stream.Length) > onFileSize))
            {
                save = true;
            }

            return(save);
        }
示例#3
0
        /// <summary>
        /// Recycles the name of the and get next file.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <param name="sInfo">The s information.</param>
        /// <param name="fileHeader">The file header.</param>
        /// <returns></returns>
        static public String RecycleAndGetNextFileName(String path, RIAutoSaveInfo sInfo, RIFileHeader fileHeader)
        {
            DateTime lastDate;

            if (fileHeader.FLastDateTime == DateTime.MinValue)
            {
                lastDate = DateTime.Now;
            }
            else
            {
                lastDate = fileHeader.FLastDateTime;
            }

            if (sInfo.RecycleFilesEvery > 0)
            {
                String fDir  = Path.GetDirectoryName(path);
                String fExt  = Path.GetExtension(path);
                String fName = Path.GetFileName(path).Replace(fExt, String.Empty);
                String fSpec = String.Format(@"{0}.*.*{1}", fName, fExt);

                String[] files = Directory.GetFiles(fDir, fSpec, SearchOption.TopDirectoryOnly);
                if (files.Length >= sInfo.RecycleFilesEvery)
                {
                    StringBuilder sbFile = new StringBuilder();
                    SortedDictionary <UInt64, String> sortedFiles = new SortedDictionary <UInt64, String>();

                    foreach (String file in files)
                    {
                        sbFile.Length = 0;
                        sbFile.Append(file);
                        sbFile.Replace(fDir, String.Empty).Replace(fExt, String.Empty).Replace(fName, String.Empty).Replace(".", String.Empty).Replace(@"\", String.Empty);

                        UInt64 key = UInt64.Parse(sbFile.ToString());
                        sortedFiles[key] = file;
                    }

                    foreach (UInt64 key in sortedFiles.Keys.ToArray())
                    {
                        File.Delete(sortedFiles[key]);
                        sortedFiles.Remove(key);

                        if (sortedFiles.Count <= sInfo.RecycleFilesEvery)
                        {
                            break;
                        }
                    }
                }
            }

            return(GetNextFileName(path, lastDate));
        }