Пример #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
        public ISubGridCellPassesDataSegment AddNewSegment(IServerLeafSubGrid subGrid,
                                                           ISubGridCellPassesDataSegmentInfo segmentInfo)
        {
            if (segmentInfo == null)
            {
                throw new TRexSubGridProcessingException($"Null segment info passed to AddNewSegment for sub grid {subGrid.Moniker()}");
            }

            if (segmentInfo.Segment != null)
            {
                throw new TRexSubGridProcessingException($"Segment info passed to AddNewSegment for sub grid {subGrid.Moniker()} already contains an allocated segment");
            }

            var Result = new SubGridCellPassesDataSegment
            {
                Owner       = subGrid,
                SegmentInfo = segmentInfo
            };

            segmentInfo.Segment = Result;

            for (int I = 0; I < Count; I++)
            {
                if (segmentInfo.EndTime <= Items[I].SegmentInfo.StartTime)
                {
                    Items.Insert(I, Result);

                    if (_performSegmentAdditionIntegrityChecks)
                    {
                        for (int J = 0; J < Count - 1; J++)
                        {
                            if (Items[J].SegmentInfo.StartTime >= Items[J + 1].SegmentInfo.StartTime)
                            {
                                _log.LogError($"Segment passes list out of order {Items[J].SegmentInfo.StartTime} versus {Items[J + 1].SegmentInfo.StartTime}. Segment count = {Count}");
                                DumpSegmentsToLog();
                                throw new TRexSubGridProcessingException($"Segment passes list out of order {Items[J].SegmentInfo.StartTime} versus {Items[J + 1].SegmentInfo.StartTime}. Segment count = {Count}");
                            }
                        }
                    }

                    return(Result);
                }
            }

            // if we get to here, then the new segment is at the end of the list, so just add it to the end
            Add(Result);

            return(Result);
        }
Пример #3
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);
            }
        }