示例#1
0
        public Stream GetFileStream(int tag, int level, int x, int y)
        {
            entry = new DirectoryEntry(tag, level, x, y, 0, 0);

            UInt32 index = entry.ComputeHash() % (UInt32)(header.HashBuckets);

            long hep = GetHashEntryPosition(index);

            DirectoryEntry de;

            while (hep != 0)
            {
                de = GetDirectoryEntry(hep);

                if ((de.x == x) && (de.y == y) && ((de.tag == tag) || (tag == -1)) && (de.level == level))
                {
                    return(StreamSlice.Create(dataStream, de.location, de.size));
                }
                else
                {
                    hep = de.NextEntryInChain;
                }
            }

            return(null);
        }
示例#2
0
        public static async Task <Stream> GetImageStreamAsync(Stream f, int level, int x, int y, CancellationToken token)
        {
            var offset = GetFileIndexOffset(level, x, y);

            f.Seek(offset, SeekOrigin.Begin);

            var(start, length) = await GetNodeInfoAsync(f, offset, token).ConfigureAwait(false);

            return(StreamSlice.Create(f, start, length));
        }
示例#3
0
        public void SanityTest()
        {
            // Arrange
            var bytes = _fixture.CreateMany<byte>().ToArray();
            var offset = 1;
            var length = bytes.Length - 2;

            var subset = bytes.Skip(offset).Take(length);

            // Act
            using var ms = new MemoryStream(bytes);
            using var sub = new StreamSlice(ms, offset, length);

            // Assert
            Assert.Equal(length, sub.Length);
            Assert.Equal(offset, ms.Position);
            Assert.Equal(sub.ToArray(), subset);
        }
        void StreamSliceSample()
        {
            Database db     = GetDatabase();
            Editor   editor = GetEditor();

            editor.WriteMessage("* StreamSlice *\n");
            editor.WriteMessage("StreamSlice slices bodies with a plane.\n");
            editor.WriteMessage("Pick some objects in the current drawing to be sliced and then pick three points to define the plane. The result profile will be highlighted.\n");
            ObjectIdCollection ids = PickObjectSet("Please pick the bodies need to be sliced");

            if (ids.Count == 0)
            {
                editor.WriteMessage("No object is picked\n");
                return;
            }

            editor.WriteMessage("Now you need to pick 3 points from the screen to define the slicing plane.\n");
            Plane plane = PromptPlane();

            if (plane == null)
            {
                return;
            }

            StreamSlice stream = new StreamSlice(db, plane);

            TransactionManager tm = db.TransactionManager;

            using (Transaction trans = tm.StartTransaction())
            {
                stream.PushDisplayParameters(DictionaryDisplayConfiguration.GetStandardDisplayConfiguration(db), trans);

                foreach (ObjectId id in ids)
                {
                    Entity ent = trans.GetObject(id, OpenMode.ForRead) as Entity;
                    stream.Stream(ent);
                }

                stream.PopDisplayParameters();
                trans.Commit();
            }

            HighlightProfile(stream.GetProfile(), plane);
        }
示例#5
0
        public void ReallyLongStream(int offset, int length)
        {
            // Arrange
            var bytes = new byte[1024 * 1024];

            for (int i = 0; i < bytes.Length; i++)
            {
                bytes[i] = (byte)i;
            }

            var subset = bytes.Skip(offset).Take(length);

            // Act
            using var ms = new MemoryStream(bytes);
            using var sub = new StreamSlice(ms, offset, length);

            // Assert
            Assert.Equal(length, sub.Length);
            Assert.Equal(offset, ms.Position);
            Assert.Equal(0, sub.Position);
            Assert.Equal(sub.ToArray(), subset);
        }