Пример #1
0
        /// <summary>
        /// Adds the provided session to the package
        /// </summary>
        /// <param name="sessionStream"></param>
        public void AddSession(Stream sessionStream)
        {
            using (GLFReader glfReader = new GLFReader(sessionStream)) // This will dispose the stream when it is disposed.
            {
                if (!glfReader.IsSessionStream)
                {
                    throw new GibraltarException("The data stream provided is not a valid session data stream.");
                }

                if (!Log.SilentMode)
                {
                    Log.Write(LogMessageSeverity.Verbose, LogCategory, "Stream is session file, attempting to load", null);
                }

                lock (m_Lock)
                {
                    //Add this stream to our zip archive
                    string fileName = glfReader.SessionHeader.HasFileInfo ? string.Format("{0}~{1}.{2}", glfReader.SessionHeader.Id, glfReader.SessionHeader.FileId, Log.LogExtension)
                                          : string.Format("{0}.{1}", glfReader.SessionHeader.Id, Log.LogExtension);

                    string zipFilePath = GenerateFragmentPath(glfReader.SessionHeader.FileId);

                    ZipArchiveEntry fragmentEntry;
                    if (m_Archive.Mode == ZipArchiveMode.Update)
                    {
                        fragmentEntry = m_Archive.GetEntry(zipFilePath);
                        if (fragmentEntry != null)
                        {
                            fragmentEntry.Delete(); //wipe out any existing entry
                        }
                    }

                    fragmentEntry = m_Archive.CreateEntry(FragmentsFolder + "\\" + fileName, CompressionLevel.NoCompression); //session files are already highly compressed, no reason to waste effort.

                    using (var zipStream = fragmentEntry.Open())
                    {
                        FileSystemTools.StreamContentCopy(sessionStream, zipStream, false); // Copy the stream into our package's temp directory.
                    }

                    IsDirty = true;
                }
            }
        }