Exemplo n.º 1
0
 /// <summary>
 /// Validates the filer header.
 /// </summary>
 /// <param name="fHeader">The f header.</param>
 /// <param name="filePath">The file path.</param>
 /// <exception cref="ReflectInsightException"></exception>
 static private void ValidateFilerHeader(RIFileHeader fHeader, String filePath)
 {
     if (!IsFileSignatureValid(fHeader))
     {
         throw new ReflectInsightException(String.Format(CultureInfo.CurrentCulture, "Incorrect file format for '{0}'", filePath));
     }
 }
Exemplo n.º 2
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));
 }
Exemplo n.º 3
0
 /// <summary>
 /// Writes the header.
 /// </summary>
 /// <param name="fStream">The f stream.</param>
 /// <param name="header">The header.</param>
 static public void WriteHeader(Stream fStream, RIFileHeader header)
 {
     fStream.Seek(0, SeekOrigin.Begin);
     using (var pool = FastFormatterPool.Pool.Container())
     {
         pool.Instance.Serialize(fStream, header);
     }
 }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
0
        public Object Clone()
        {
            RIFileHeader rValue = new RIFileHeader();

            rValue.FVersion        = FVersion;
            rValue.Signature       = Signature;
            rValue.Id              = Id;
            rValue.FInitDateTime   = FInitDateTime;
            rValue.FFirstDateTime  = FFirstDateTime;
            rValue.FLastDateTime   = FLastDateTime;
            rValue.FNextSequenceId = FNextSequenceId;
            rValue.FMessageCount   = FMessageCount;
            rValue.FExtraData      = CloneExtraData();

            return(rValue);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Reads the header.
        /// </summary>
        /// <param name="fStream">The f stream.</param>
        /// <param name="filePath">The file path.</param>
        /// <param name="onNewExtraData">The on new extra data.</param>
        /// <returns></returns>
        /// <exception cref="ReflectInsightException"></exception>
        static public RIFileHeader ReadHeader(Stream fStream, String filePath, Dictionary <Int32, FastSerializerObjectData> onNewExtraData)
        {
            RIFileHeader header = null;

            fStream.Seek(0, SeekOrigin.Begin);
            if (fStream.Length != 0)
            {
                try
                {
                    // reset the file pointer and read file header
                    fStream.Seek(0, SeekOrigin.Begin);
                    using (var pool = FastFormatterPool.Pool.Container())
                    {
                        header = pool.Instance.Deserialize <RIFileHeader>(fStream);
                    }

                    ValidateFilerHeader(header, filePath);
                }
                catch (ReflectInsightException)
                {
                    throw;
                }
                catch (Exception ex)
                {
                    throw new ReflectInsightException(String.Format(CultureInfo.CurrentCulture, "Incorrect file format for '{0}'", filePath), ex);
                }
            }
            else
            {
                header = new RIFileHeader();
                if (onNewExtraData != null)
                {
                    header.CopyExtraData(onNewExtraData);
                }

                using (var pool = FastFormatterPool.Pool.Container())
                {
                    pool.Instance.Serialize(fStream, header);
                }
            }

            return(header);
        }
Exemplo n.º 7
0
 /// <summary>
 /// Determines whether [is file signature valid] [the specified f header].
 /// </summary>
 /// <param name="fHeader">The f header.</param>
 /// <returns></returns>
 static public Boolean IsFileSignatureValid(RIFileHeader fHeader)
 {
     return(ArrayConverter.ByteArraysEqual(FileSignature, fHeader.Signature));
 }
Exemplo n.º 8
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));
        }