Пример #1
0
        /// <summary>
        /// Load the specified session
        /// </summary>
        /// <returns>The loaded session.  If no session can be found with the specified Id an ArgumentOutOfRangeException will be thrown.</returns>
        public Session GetSession(Guid sessionId, Guid?fileId = null)
        {
            Session requestedSession = null;

            lock (m_Lock)
            {
                SessionFileInfo <ZipArchiveEntry> sessionFileInfo;
                if (m_Sessions.TryGetValue(sessionId, out sessionFileInfo) == false)
                {
                    throw new ArgumentOutOfRangeException(nameof(sessionId), "There is no session in the package with the provided id");
                }

                //now load up all of the session fragments.
                var loadingCollection = new SessionCollection();

                foreach (var fragment in sessionFileInfo.Fragments)
                {
                    //we need a seek-able stream - so we'll extract the fragment into a temp file and go with that.
                    if (fileId != null)
                    {
                        //we need to check the file Id to see if it's what they requested
                        using (var reader = new GLFReader(FileSystemTools.GetTempFileStreamCopy(fragment.Open())))
                        {
                            if (reader.SessionHeader.FileId != fileId.Value)
                            {
                                continue;
                            }
                        }
                    }

                    requestedSession = loadingCollection.Add(FileSystemTools.GetTempFileStreamCopy(fragment.Open()), true);
                }
            }

            if (requestedSession == null)
            {
                throw new ArgumentOutOfRangeException(nameof(fileId), "There is no session file in the package with the provided file id");
            }

            return(requestedSession);
        }
Пример #2
0
        /// <summary>
        /// Add a session from the provided GLF File stream
        /// </summary>
        /// <param name="fileStream">A file stream of a GLF File to read.</param>
        /// <param name="useOriginalStream">If true, the caller no longer owns the stream and must not further use or dispose
        /// it. If false, the method will copy the contents of the stream before returning and will restore its Position,
        /// so the caller is responsible for eventually disposing it.</param>
        /// <returns>The session object that was affected.</returns>
        public Session Add(Stream fileStream, bool useOriginalStream)
        {
            if (fileStream == null)
            {
                throw new ArgumentNullException(nameof(fileStream));
            }

            long originalPosition = fileStream.Position;

            if (GLFReader.IsGLF(fileStream) == false) // This also throws an exception if the stream is not seekable.
            {
                fileStream.Position = originalPosition;
                throw new ArgumentException("The provided data stream is not a valid GLF session stream.", nameof(fileStream));
            }

            Stream newStream;

            if (useOriginalStream == false)
            {
                // Uh-oh, the caller wants to keep the stream themselves.  We need to punt a copy from the original stream.
                fileStream.Position = 0;                                                 // Reset its position to the start of the file to copy from the start.
                newStream           = FileSystemTools.GetTempFileStreamCopy(fileStream); // Get a delete-on-close temp file copied from it.
                newStream.Position  = originalPosition;                                  // Should it do this?

                fileStream.Position = originalPosition;                                  // And set it back where it had been.
            }
            else
            {
                // Otherwise, they're saying the file will stick around for us.  We own it now.  Or rather, the GLFReader will.
                newStream = fileStream;
            }

            GLFReader glfReader = new GLFReader(newStream);

            //now forward to our GLF Reader add which is shared with other things
            Session newSession = Add(glfReader);

            return(newSession);
        }
Пример #3
0
        /// <summary>
        /// Retrieve the ids of the sessions files known locally for the specified session
        /// </summary>
        /// <param name="sessionId"></param>
        /// <returns></returns>
        public IList <Guid> GetSessionFileIds(Guid sessionId)
        {
            lock (m_Lock)
            {
                SessionFileInfo <ZipArchiveEntry> sessionFileInfo;
                if (m_Sessions.TryGetValue(sessionId, out sessionFileInfo) == false)
                {
                    throw new ArgumentOutOfRangeException(nameof(sessionId), "There is no session in the package with the provided id");
                }

                var fileIds = new List <Guid>();
                foreach (var fragment in sessionFileInfo.Fragments)
                {
                    //this is kinda crappy - we have to make a copy of the whole fragment to get a seekable stream to read the id.
                    using (var reader = new GLFReader(FileSystemTools.GetTempFileStreamCopy(fragment.Open())))
                    {
                        fileIds.Add(reader.SessionHeader.FileId);
                    }
                }

                return(fileIds);
            }
        }