예제 #1
0
        /// <summary>
        /// Converts a sub grid segment into its immutable form, using the source object
        /// </summary>
        /// <param name="source"></param>
        /// <param name="immutableStream"></param>
        /// <returns></returns>
        private bool ConvertSubGridSegmentToImmutable(object source, out MemoryStream immutableStream)
        {
            try
            {
                var originSource = (ISubGridCellPassesDataSegment)source;

                // create a copy and compress the latestPasses(and ensure the global latest cells is the mutable variety)
                using (var segment = new SubGridCellPassesDataSegment(ConvertLatestPassesToImmutable(originSource.LatestPasses, SegmentLatestPassesContext.Segment),
                                                                      subGridCellSegmentPassesDataWrapperFactory.NewImmutableWrapper())
                {
                    StartTime = originSource.SegmentInfo.StartTime,
                    EndTime = originSource.SegmentInfo.EndTime
                })
                {
                    segment.PassesData.SetState(originSource.PassesData.GetState());

                    // Write out the segment to the immutable stream
                    immutableStream = RecyclableMemoryStreamManagerHelper.Manager.GetStream();
                    using (var writer = new BinaryWriter(immutableStream, Encoding.UTF8, true))
                    {
                        segment.Write(writer);
                    }
                }

                return(true);
            }
            catch (Exception e)
            {
                immutableStream = null;

                Log.LogError(e, "Exception in conversion of sub grid segment mutable data to immutable schema");
                return(false);
            }
        }
예제 #2
0
        /// <summary>
        /// Converts a sub grid segment into its immutable form, using a cached stream
        /// </summary>
        /// <param name="mutableStream"></param>
        /// <param name="immutableStream"></param>
        /// <returns></returns>
        private bool ConvertSubGridSegmentToImmutable(MemoryStream mutableStream, out MemoryStream immutableStream)
        {
            try
            {
                // Read in the sub grid segment from the mutable stream
                using (var segment = new SubGridCellPassesDataSegment(subGridCellLatestPassesDataWrapperFactory.NewMutableWrapper_Segment(),
                                                                      subGridCellSegmentPassesDataWrapperFactory.NewMutableWrapper()))
                {
                    mutableStream.Position = 0;
                    using (var reader = new BinaryReader(mutableStream, Encoding.UTF8, true))
                    {
                        segment.Read(reader, true, true);
                    }

                    // Convert to the immutable form
                    using (var mutableLatestPasses = segment.LatestPasses)
                    {
                        segment.LatestPasses = ConvertLatestPassesToImmutable(mutableLatestPasses, SegmentLatestPassesContext.Segment);
                    }

                    using (var mutablePasses = segment.PassesData)
                    {
                        segment.PassesData = subGridCellSegmentPassesDataWrapperFactory.NewImmutableWrapper();
                        segment.PassesData.SetState(mutablePasses.GetState());
                    }

                    // Write out the segment to the immutable stream
                    immutableStream = RecyclableMemoryStreamManagerHelper.Manager.GetStream();
                    using (var writer = new BinaryWriter(immutableStream, Encoding.UTF8, true))
                    {
                        segment.Write(writer);
                    }
                }

                return(true);
            }
            catch (Exception e)
            {
                immutableStream = null;

                Log.LogError(e, "Exception in conversion of sub grid segment mutable data to immutable schema");
                return(false);
            }
        }