예제 #1
0
        /// <summary>
        /// Creates an instance of a BitmapContext, with specified ReadWriteMode
        /// </summary>
        /// <param name="writeableBitmap"></param>
        /// <param name="mode"></param>
        public BitmapContext(WriteableBitmap writeableBitmap, ReadWriteMode mode)
        {
            _writeableBitmap = writeableBitmap;
            _mode            = mode;

            _pixelWidth  = _writeableBitmap.PixelSize.Width;
            _pixelHeight = _writeableBitmap.PixelSize.Height;

            // Ensure the bitmap is in the dictionary of mapped Instances
            if (!UpdateCountByBmp.ContainsKey(_writeableBitmap))
            {
                // Set UpdateCount to 1 for this bitmap
                UpdateCountByBmp.Add(_writeableBitmap, 1);
                length = _writeableBitmap.PixelSize.Width * _writeableBitmap.PixelSize.Height;
                pixels = new int[length];
                CopyPixels();
                PixelCacheByBmp.Add(_writeableBitmap, pixels);
            }
            else
            {
                // For previously contextualized bitmaps increment the update count
                IncrementRefCount(_writeableBitmap);
                pixels = PixelCacheByBmp[_writeableBitmap];
                length = pixels.Length;
            }
        }
예제 #2
0
        internal static async Task <int> ReadAsync(ReadWriteMode mode, Stream stream, byte[] buffer, int offset, int count, CancellationToken cancellationToken = default)
        {
            if (mode == ReadWriteMode.SyncByte)
            {
                if (count > 0)
                {
                    int b = stream.ReadByte();
                    if (b != -1)
                    {
                        buffer[offset] = (byte)b;
                        return(1);
                    }
                }

                return(0);
            }

            return(mode switch
            {
                ReadWriteMode.SyncArray => stream.Read(buffer, offset, count),
                ReadWriteMode.SyncSpan => stream.Read(buffer.AsSpan(offset, count)),
                ReadWriteMode.AsyncArray => await stream.ReadAsync(buffer, offset, count, cancellationToken),
                ReadWriteMode.AsyncMemory => await stream.ReadAsync(buffer.AsMemory(offset, count), cancellationToken),
                ReadWriteMode.SyncAPM => stream.EndRead(stream.BeginRead(buffer, offset, count, null, null)),
                ReadWriteMode.AsyncAPM => await Task.Factory.FromAsync(stream.BeginRead, stream.EndRead, buffer, offset, count, null),
                _ => throw new Exception($"Unknown mode: {mode}"),
            });
예제 #3
0
        /// <summary>
        /// Given a MemoryStream of compressed data and a byte array of desired output, decompresses
        /// the stream and validates that it is equal to the expected array.
        /// </summary>
        private async Task ReadAndValidateCompressedData(ReadWriteMode readWriteMode, bool useGzip, int chunkSize, MemoryStream compressed, byte[] expected)
        {
            using (MemoryStream decompressed = new MemoryStream())
                using (Stream decompressor = useGzip ? (Stream) new GZipStream(compressed, CompressionMode.Decompress, true) : new DeflateStream(compressed, CompressionMode.Decompress, true))
                {
                    int bytesRead;
                    var buffer = new byte[chunkSize];
                    switch (readWriteMode)
                    {
                    case ReadWriteMode.SyncSpan:
                        while ((bytesRead = decompressor.Read(new Span <byte>(buffer))) != 0)
                        {
                            decompressed.Write(buffer, 0, bytesRead);
                        }
                        break;

                    case ReadWriteMode.SyncArray:
                        while ((bytesRead = decompressor.Read(buffer, 0, buffer.Length)) != 0)
                        {
                            decompressed.Write(buffer, 0, bytesRead);
                        }
                        break;

                    case ReadWriteMode.AsyncArray:
                        while ((bytesRead = await decompressor.ReadAsync(buffer, 0, buffer.Length)) != 0)
                        {
                            decompressed.Write(buffer, 0, bytesRead);
                        }
                        break;
                    }
                    Assert.Equal <byte>(expected, decompressed.ToArray());
                }
        }
예제 #4
0
        public async Task RoundtripCompressDecompress(ReadWriteMode readWriteMode, bool useGzip, int chunkSize, int totalSize, CompressionLevel level)
        {
            byte[] data = new byte[totalSize];
            new Random(42).NextBytes(data);

            var compressed = new MemoryStream();

            using (var compressor = useGzip ? (Stream) new GZipStream(compressed, level, true) : new DeflateStream(compressed, level, true))
            {
                for (int i = 0; i < data.Length; i += chunkSize) // not using CopyTo{Async} due to optimizations in MemoryStream's implementation that avoid what we're trying to test
                {
                    switch (readWriteMode)
                    {
                    case ReadWriteMode.AsyncArray:
                        await compressor.WriteAsync(data, i, chunkSize);

                        break;

                    case ReadWriteMode.SyncArray:
                        compressor.Write(data, i, chunkSize);
                        break;

                    case ReadWriteMode.SyncSpan:
                        compressor.Write(new ReadOnlySpan <byte>(data, i, chunkSize));
                        break;
                    }
                }
            }
            compressed.Position = 0;
            await ReadAndValidateCompressedData(readWriteMode, useGzip, chunkSize, compressed, data);

            compressed.Dispose();
        }
예제 #5
0
        public async Task NoDataIsLostWhenWritingToFile(ReadWriteMode mode)
        {
            string      filePath;
            List <byte> writtenBytes = new List <byte>();

            using (FileStream stream = (FileStream)await CreateWriteOnlyStreamCore(Array.Empty <byte>()))
            {
                filePath = stream.Name;

                // the following buffer fits into internal FileStream buffer
                byte[] small = Enumerable.Repeat(byte.MinValue, BufferSize - 1).ToArray();
                // the following buffer does not fit into internal FileStream buffer
                byte[] big = Enumerable.Repeat(byte.MaxValue, BufferSize + 1).ToArray();
                // in this test we are selecting a random buffer and write it to file
                // the goal is to cover all possible scenarios for the internal buffering logic
                Random random = new Random(12345);
                for (int i = 0; i < 1000; i++)
                {
                    byte[] bytes = random.Next() % 2 == 0 ? small : big;

                    await WriteAsync(mode, stream, bytes, 0, bytes.Length);

                    writtenBytes.AddRange(bytes);
                    Assert.Equal(writtenBytes.Count, stream.Length);
                    Assert.Equal(stream.Length, stream.Position);
                }
            }

            byte[] allBytes = File.ReadAllBytes(filePath);
            Assert.Equal(writtenBytes.ToArray(), allBytes);
        }
예제 #6
0
        public void RemoteWrite(object value)
        {
            var server = Parent.Parent as OpcServer;

            Debug.Assert(server != null);

            try
            {
                if (server.RunMode != RunMode.Release)
                {
                    throw new InvalidOperationException(GlobalId + "只能在发布模式下写入远程数据");
                }

                if (!ReadWriteMode.HasFlag(ReadWriteMode.Write))
                {
                    throw new InvalidOperationException(GlobalId + "读写模式不具备远程数据写入权限");
                }

                _item?.Write(value);
            }
            catch (InvalidOperationException e)
            {
                this.ErrorFailWithReason(e);
            }
            catch (Exception e)
            {
                //其他原因写入失败,表示Opc通讯故障
                LocalWrite(null);

                this.ErrorFailWithReason(e);
            }
        }
예제 #7
0
        public async Task WriteAsyncStartsWherePreviousReadAsyncHasFinished(ReadWriteMode mode)
        {
            if (mode == ReadWriteMode.SyncByte)
            {
                // it reads a single byte even if buffer.Length > 1
                return;
            }

            byte[] initialData = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
            byte[] readBuffer  = new byte[initialData.Length * 2]; // the edge case: reading more than available
            byte[] writeBuffer = new byte[] { 10, 11, 12, 13, 14, 15 };
            string filePath;

            using (FileStream stream = (FileStream)await CreateReadWriteStreamCore(initialData))
            {
                filePath = stream.Name;

                int bytesRead = await ReadAsync(mode, stream, readBuffer, 0, readBuffer.Length);

                Assert.Equal(bytesRead, initialData.Length);
                Assert.Equal(initialData.Length, stream.Position);
                Assert.Equal(stream.Position, stream.Length);

                await WriteAsync(mode, stream, writeBuffer, 0, writeBuffer.Length);

                Assert.Equal(initialData.Length + writeBuffer.Length, stream.Position);
                Assert.Equal(stream.Position, stream.Length);
            }

            byte[] allBytes = File.ReadAllBytes(filePath);
            Assert.Equal(initialData.Concat(writeBuffer), allBytes);
        }
예제 #8
0
        /// <summary>
        /// Creates an instance of a BitmapContext, with specified ReadWriteMode
        /// </summary>
        /// <param name="writeableBitmap"></param>
        /// <param name="mode"></param>
        public BitmapContext(WriteableBitmap writeableBitmap, ReadWriteMode mode)
            : this(writeableBitmap)
        {
#if WPF
            // We only care about mode in Wpf
            this.mode = mode;
#endif
        }
예제 #9
0
        /// <summary>
        /// Creates an instance of a BitmapContext, with specified ReadWriteMode
        /// </summary>
        /// <param name="writeableBitmap"></param>
        /// <param name="mode"></param>
        public BitmapContext(BitmapBuffer writeableBitmap, ReadWriteMode mode)
        {
            _writeableBitmap = writeableBitmap;
            _mode            = mode;

            _pixelWidth  = _writeableBitmap.PixelWidth;
            _pixelHeight = _writeableBitmap.PixelHeight;
        }
예제 #10
0
        public async Task WriteAfterFlushing(ReadWriteMode readWriteMode, bool useGzip, int chunkSize, int totalSize, CompressionLevel level)
        {
            byte[]      data     = new byte[totalSize];
            List <byte> expected = new List <byte>();

            new Random(42).NextBytes(data);

            using (var compressed = new MemoryStream())
                using (var compressor = useGzip ? (Stream) new GZipStream(compressed, level, true) : new DeflateStream(compressed, level, true))
                {
                    for (int i = 0; i < data.Length; i += chunkSize) // not using CopyTo{Async} due to optimizations in MemoryStream's implementation that avoid what we're trying to test
                    {
                        switch (readWriteMode)
                        {
                        case ReadWriteMode.AsyncArray:
                            await compressor.WriteAsync(data, i, chunkSize);

                            break;

                        case ReadWriteMode.SyncArray:
                            compressor.Write(data, i, chunkSize);
                            break;

                        case ReadWriteMode.SyncSpan:
                            compressor.Write(new ReadOnlySpan <byte>(data, i, chunkSize));
                            break;

                        case ReadWriteMode.AsyncMemory:
                            await compressor.WriteAsync(new ReadOnlyMemory <byte>(data, i, chunkSize));

                            break;
                        }
                        for (int j = i; j < i + chunkSize; j++)
                        {
                            expected.Insert(j, data[j]);
                        }

                        switch (readWriteMode)
                        {
                        case ReadWriteMode.AsyncArray:
                        case ReadWriteMode.AsyncMemory:
                            await compressor.FlushAsync();

                            break;

                        case ReadWriteMode.SyncSpan:
                        case ReadWriteMode.SyncArray:
                            compressor.Flush();
                            break;
                        }

                        MemoryStream partiallyCompressed = new MemoryStream(compressed.ToArray());
                        partiallyCompressed.Position = 0;
                        await ReadAndValidateCompressedData(readWriteMode, useGzip, chunkSize, partiallyCompressed, expected.ToArray());
                    }
                }
        }
예제 #11
0
        /// <summary>
        /// Creates an instance of a BitmapContext, with specified ReadWriteMode
        /// </summary>
        /// <param name="writeableBitmap"></param>
        /// <param name="mode"></param>
        public BitmapContext(WriteableBitmap writeableBitmap, ReadWriteMode mode)
        {
            _writeableBitmap = writeableBitmap;
            _mode            = mode;

            _pixelWidth  = _writeableBitmap.PixelWidth;
            _pixelHeight = _writeableBitmap.PixelHeight;
#if WPF
            //// Check if it's the Pbgra32 pixel format
            //if (writeableBitmap.Format != PixelFormats.Pbgra32)
            //{
            //   throw new ArgumentException("The input WriteableBitmap needs to have the Pbgra32 pixel format. Use the BitmapFactory.ConvertToPbgra32Format method to automatically convert any input BitmapSource to the right format accepted by this class.", "writeableBitmap");
            //}

            double width = _writeableBitmap.BackBufferStride / WriteableBitmapExtensions.SizeOfArgb;
            _length = (int)(width * _pixelHeight);

            lock (UpdateCountByBmp)
            {
                // Ensure the bitmap is in the dictionary of mapped Instances
                if (!UpdateCountByBmp.ContainsKey(writeableBitmap))
                {
                    // Set UpdateCount to 1 for this bitmap
                    UpdateCountByBmp.Add(writeableBitmap, 1);

                    // Lock the bitmap
                    writeableBitmap.Lock();
                }
                else
                {
                    // For previously contextualized bitmaps increment the update count
                    IncrementRefCount(writeableBitmap);
                }
            }

            _backBuffer = (int *)writeableBitmap.BackBuffer;
#elif NETFX_CORE
            // Ensure the bitmap is in the dictionary of mapped Instances
            if (!UpdateCountByBmp.ContainsKey(_writeableBitmap))
            {
                // Set UpdateCount to 1 for this bitmap
                UpdateCountByBmp.Add(_writeableBitmap, 1);
                length = _writeableBitmap.PixelWidth * _writeableBitmap.PixelHeight;
                pixels = new int[length];
                CopyPixels();
                PixelCacheByBmp.Add(_writeableBitmap, pixels);
            }
            else
            {
                // For previously contextualized bitmaps increment the update count
                IncrementRefCount(_writeableBitmap);
                pixels = PixelCacheByBmp[_writeableBitmap];
                length = pixels.Length;
            }
#endif
        }
예제 #12
0
        /// <summary>
        /// コンストラクタ
        /// </summary>
        /// <param name="config">リストビューの設定</param>
        /// <param name="extensions">拡張機能の配列</param>
        /// <param name="extnensions_dir">拡張機能のファイルパス</param>
        public UMAListViewTpl( UMAListView.Config config, ReadWriteMode mode, WP7_2012ULV.Setting.ExtensionSetting.Command[] extensions, String extnensions_dir )
        {
            this.ListViewConfig = config;
            this.ExtensionsDir = extnensions_dir;
            this.Extensions = extensions;
            this.Mode = mode;

            this.InitializeComponent();
            this.ListView1_Setup();
            this.ContextMenu_Setup();
        }
예제 #13
0
        public OpcItem(string id         = "", string address = "",
                       TypeCode typeCode = TypeCode.Int32, ReadWriteMode readWriteMode = ReadWriteMode.None)
            : base(id)
        {
            Address       = address;
            TypeCode      = typeCode;
            ReadWriteMode = readWriteMode;

            Data       = null;
            UpdateTime = DateTime.MinValue;
        }
예제 #14
0
        /// <summary>
        /// Creates an instance of a BitmapContext, with specified ReadWriteMode
        /// </summary>
        /// <param name="writeableBitmap"></param>
        /// <param name="mode"></param>
        public BitmapContext(WriteableBitmap writeableBitmap, ReadWriteMode mode)
        {
            _writeableBitmap = writeableBitmap;
            _mode            = mode;

            //// Check if it's the Pbgra32 pixel format
            //if (writeableBitmap.Format != PixelFormats.Pbgra32)
            //{
            //   throw new ArgumentException("The input WriteableBitmap needs to have the Pbgra32 pixel format. Use the BitmapFactory.ConvertToPbgra32Format method to automatically convert any input BitmapSource to the right format accepted by this class.", "writeableBitmap");
            //}

            BitmapContextBitmapProperties bitmapProperties;

            lock (UpdateCountByBmp)
            {
                // Ensure the bitmap is in the dictionary of mapped Instances
                if (!UpdateCountByBmp.ContainsKey(writeableBitmap))
                {
                    // Set UpdateCount to 1 for this bitmap
                    UpdateCountByBmp.Add(writeableBitmap, 1);

                    // Lock the bitmap
                    writeableBitmap.Lock();

                    bitmapProperties = new BitmapContextBitmapProperties()
                    {
                        BackBufferStride = writeableBitmap.BackBufferStride,
                        Pixels           = (int *)writeableBitmap.BackBuffer,
                        Width            = writeableBitmap.PixelWidth,
                        Height           = writeableBitmap.PixelHeight,
                        Format           = writeableBitmap.Format
                    };
                    BitmapPropertiesByBmp.Add(
                        writeableBitmap,
                        bitmapProperties);
                }
                else
                {
                    // For previously contextualized bitmaps increment the update count
                    IncrementRefCount(writeableBitmap);
                    bitmapProperties = BitmapPropertiesByBmp[writeableBitmap];
                }

                _backBufferStride = bitmapProperties.BackBufferStride;
                _pixelWidth       = bitmapProperties.Width;
                _pixelHeight      = bitmapProperties.Height;
                _format           = bitmapProperties.Format;
                _backBuffer       = bitmapProperties.Pixels;

                double width = _backBufferStride / WriteableBitmapExtensions.SizeOfArgb;
                _length = (int)(width * _pixelHeight);
            }
        }
예제 #15
0
        internal static async Task ReadWrite_Success(ReadWriteMode mode, int writeSize, bool startWithFlush)
        {
            foreach (CancellationToken nonCanceledToken in new[] { CancellationToken.None, new CancellationTokenSource().Token })
            {
                using StreamPair streams = await CreateConnectedStreamsAsync();

                foreach ((Stream writeable, Stream readable) in GetReadWritePairs(streams))
                {
                    if (startWithFlush)
                    {
                        await FlushAsync(mode, writeable, nonCanceledToken);
                    }

                    byte[] writerBytes = RandomNumberGenerator.GetBytes(writeSize);
                    var    readerBytes = new byte[writerBytes.Length];

                    Task writes = Task.Run(async() =>
                    {
                        await WriteAsync(mode, writeable, writerBytes, 0, writerBytes.Length, nonCanceledToken);

                        if (FlushRequiredToWriteData)
                        {
                            if (FlushGuaranteesAllDataWritten)
                            {
                                await writeable.FlushAsync();
                            }
                            else
                            {
                                await writeable.DisposeAsync();
                            }
                        }
                    });

                    int n = 0;
                    while (n < readerBytes.Length)
                    {
                        int r = await ReadAsync(mode, readable, readerBytes, n, readerBytes.Length - n);

                        n += r;
                    }

                    await writes;

                    if (!FlushGuaranteesAllDataWritten)
                    {
                        break;
                    }
                }
            }
        }
예제 #16
0
        /// <summary>
        /// Creates an instance of a BitmapContext, with default mode = ReadWrite
        /// </summary>
        /// <param name="writeableBitmap"></param>
        public BitmapContext(WriteableBitmap writeableBitmap)
        {
            this.writeableBitmap = writeableBitmap;

#if WPF
            // Check if it's the Pbgra32 pixel format
            if (writeableBitmap.Format != PixelFormats.Pbgra32)
            {
                throw new ArgumentException("The input WriteableBitmap needs to have the Pbgra32 pixel format. Use the BitmapFactory.ConvertToPbgra32Format method to automatically convert any input BitmapSource to the right format accepted by this class.", "writeableBitmap");
            }

            // Mode is used to invalidate the bmp at the end of the update if mode==ReadWrite
            mode = ReadWriteMode.ReadWrite;

            // Ensure the bitmap is in the dictionary of mapped Instances
            if (!UpdateCountByBmp.ContainsKey(writeableBitmap))
            {
                // Set UpdateCount to 1 for this bitmap
                UpdateCountByBmp.Add(writeableBitmap, 1);

                // Lock the bitmap
                writeableBitmap.Lock();
            }
            else
            {
                // For previously contextualized bitmaps increment the update count
                IncrementRefCount(writeableBitmap);
            }

            backBuffer = (int *)writeableBitmap.BackBuffer;
#elif NETFX_CORE
            // Ensure the bitmap is in the dictionary of mapped Instances
            if (!UpdateCountByBmp.ContainsKey(writeableBitmap))
            {
                // Set UpdateCount to 1 for this bitmap
                UpdateCountByBmp.Add(writeableBitmap, 1);
                length = writeableBitmap.PixelWidth * writeableBitmap.PixelHeight;
                pixels = new int[length];
                CopyPixels();
                PixelCacheByBmp.Add(writeableBitmap, pixels);
            }
            else
            {
                // For previously contextualized bitmaps increment the update count
                IncrementRefCount(writeableBitmap);
                pixels = PixelCacheByBmp[writeableBitmap];
                length = pixels.Length;
            }
#endif
        }
예제 #17
0
        public ReadWriteLock(ReaderWriterLockSlim ReaderWriterLockSlim1, ReadWriteMode ReadWriteMode1)
        {
            this.readerWriterLockSlim = ReaderWriterLockSlim1;
            this.readWriteMode        = ReadWriteMode1;



            if (this.readWriteMode == ReadWriteMode.Read)
            {
                this.readerWriterLockSlim.EnterReadLock();
            }
            else
            {
                this.readerWriterLockSlim.EnterWriteLock();
            }
        }
예제 #18
0
        internal static async Task WriteAsync(ReadWriteMode mode, Stream stream, byte[] buffer, int offset, int count, CancellationToken cancellationToken = default)
        {
            switch (mode)
            {
            case ReadWriteMode.SyncByte:
                for (int i = offset; i < offset + count; i++)
                {
                    stream.WriteByte(buffer[i]);
                }
                break;

            case ReadWriteMode.SyncArray:
                stream.Write(buffer, offset, count);
                break;

            case ReadWriteMode.SyncSpan:
                stream.Write(buffer.AsSpan(offset, count));
                break;

            case ReadWriteMode.AsyncArray:
                await stream.WriteAsync(buffer, offset, count, cancellationToken);

                break;

            case ReadWriteMode.AsyncMemory:
                await stream.WriteAsync(buffer.AsMemory(offset, count), cancellationToken);

                break;

            case ReadWriteMode.SyncAPM:
                stream.EndWrite(stream.BeginWrite(buffer, offset, count, null, null));
                break;

            case ReadWriteMode.AsyncAPM:
                await Task.Factory.FromAsync(stream.BeginWrite, stream.EndWrite, buffer, offset, count, null);

                break;

            default:
                throw new Exception($"Unknown mode: {mode}");
            }
        }
예제 #19
0
        internal static async Task FlushAsync(ReadWriteMode mode, Stream stream, CancellationToken cancellationToken = default)
        {
            switch (mode)
            {
            case ReadWriteMode.SyncByte:
            case ReadWriteMode.SyncArray:
            case ReadWriteMode.SyncSpan:
            case ReadWriteMode.SyncAPM:
                stream.Flush();
                break;

            case ReadWriteMode.AsyncArray:
            case ReadWriteMode.AsyncMemory:
            case ReadWriteMode.AsyncAPM:
                await stream.FlushAsync(cancellationToken);

                break;

            default:
                throw new Exception($"Unknown mode: {mode}");
            }
        }
 public override Task ReadWrite_Success_Large(ReadWriteMode mode, int writeSize, bool startWithFlush) => base.ReadWrite_Success_Large(mode, writeSize, startWithFlush);
 public override Task ZeroByteRead_BlocksUntilDataAvailableOrNops(ReadWriteMode mode) => base.ZeroByteRead_BlocksUntilDataAvailableOrNops(mode);
 public override Task ZeroByteWrite_OtherDataReceivedSuccessfully(ReadWriteMode mode) => base.ZeroByteWrite_OtherDataReceivedSuccessfully(mode);
 public override Task Read_DataStoredAtDesiredOffset(ReadWriteMode mode) => base.Read_DataStoredAtDesiredOffset(mode);
예제 #24
0
        public async Task FileOffsetIsPreservedWhenFileStreamIsCreatedFromSafeFileHandle_Writes(ReadWriteMode mode)
        {
            using FileStream stream = (FileStream) await CreateWriteOnlyStreamCore(Array.Empty <byte>());

            byte[] buffer = new byte[] { 0, 1, 2, 3, 4 };
            await WriteAsync(mode, stream, buffer, 0, buffer.Length);

            Assert.Equal(buffer.Length, stream.Position);

            using FileStream createdFromHandle = new FileStream(stream.SafeFileHandle, FileAccess.Write);

            Assert.Equal(buffer.Length, stream.Position);
            Assert.Equal(stream.Position, createdFromHandle.Position);
        }
예제 #25
0
 /// <summary>
 /// コンストラクタ
 /// </summary>
 /// <param name="config"></param>
 /// <param name="extensions"></param>
 /// <param name="extnensions_dir"></param>
 public BreedingToSireListView( UMAListView.Config config, ReadWriteMode mode, WP7_2012ULV.Setting.ExtensionSetting.Command[] extensions, String extnensions_dir )
     : base(config, mode, extensions, extnensions_dir)
 {
     // pass
 }
예제 #26
0
 public HorseDamListView( UMAListView.Config config, ReadWriteMode mode, Setting.ExtensionSetting.Command[] extensions, String extnensions_dir )
     : base(config, mode, extensions, extnensions_dir)
 {
     // pass
 }
 /// <summary>
 /// Gets a BitmapContext within which to perform nested IO operations on the bitmap
 /// </summary>
 /// <remarks>For WPF the BitmapContext will lock the bitmap. Call Dispose on the context to unlock</remarks>
 /// <param name="bmp">The bitmap.</param>
 /// <param name="mode">The ReadWriteMode. If set to ReadOnly, the bitmap will not be invalidated on dispose of the context, else it will</param>
 /// <returns></returns>
 public static BitmapContext GetBitmapContext(this WriteableBitmap bmp, ReadWriteMode mode)
 {
    return new BitmapContext(bmp, mode);
 }
 /// <summary>
 /// Gets a BitmapContext within which to perform nested IO operations on the bitmap
 /// </summary>
 /// <remarks>For WPF the BitmapContext will lock the bitmap. Call Dispose on the context to unlock</remarks>
 /// <param name="bmp">The bitmap.</param>
 /// <param name="mode">The ReadWriteMode. If set to ReadOnly, the bitmap will not be invalidated on dispose of the context, else it will</param>
 /// <returns></returns>
 public static BitmapContext GetBitmapContext(this WriteableBitmap bmp, ReadWriteMode mode)
 {
     return(new BitmapContext(bmp, mode));
 }
예제 #29
0
파일: WP7.cs 프로젝트: hinovana/libwp7n2012
 /// <summary>
 /// コンストラクタ
 /// </summary>
 /// <param name="process_name">ウイニングポスト7のプロセス名</param>
 /// <param name="config">プロセスメモリのメモリアドレスなどの設定</param>
 /// <param name="mode">読み書きモード</param>
 public WP7( String process_name, ConfigurationInterface config, ReadWriteMode mode )
 {
     this.process_name_ = process_name;
     this.config_ = config;
     this.Transaction( mode );
 }
예제 #30
0
파일: WP7.cs 프로젝트: hinovana/libwp7n2012
 /// <summary>
 /// コンストラクタ
 /// </summary>
 /// <param name="config">プロセスメモリのメモリアドレスなどの設定</param>
 /// <param name="mode">読み書きモード</param>
 public WP7( ConfigurationInterface config, ReadWriteMode mode )
     : this(config.ProcessName, config, mode)
 {
 }
예제 #31
0
파일: WP7.cs 프로젝트: hinovana/libwp7n2012
        /// <summary>
        /// トランザクションを開始します
        /// </summary>
        private void Transaction( ReadWriteMode mode )
        {
            this.pm_ = new KOEI.WP7_2012.Helper.ProcessMemory( this.process_name_, mode );

            this.transaction_week_number_ = this.GetCurrentWeekNumber();

            this.name_table_ = new KOEI.WP7_2012.MemoryTable.HorseNameTable(
                this.pm_,
                this.config_
            );
            this.h_shizitsu_name_table_ = new KOEI.WP7_2012.MemoryTable.ProcessMemoryTable(
                this.pm_,
                this.config_.HorseShizitsuNameTable
            );

            this.h_abl_table_ = new KOEI.WP7_2012.MemoryTable.HorseAblDataTable(
                this.pm_,
                this.config_.HorseAbilityTable
            );
            this.h_family_line_table_ = new KOEI.WP7_2012.MemoryTable.HorseFamilyLineTable(
                this.pm_,
                this.config_.HorseFamilyLineTable
            );
            this.h_blood_table_ = new KOEI.WP7_2012.MemoryTable.HorseBloodTable(
                this.pm_,
                this.config_.HorseBloodTable
            );
            this.h_race_table_ = new KOEI.WP7_2012.MemoryTable.HorseRaceTable(
                this.pm_,
                this.config_.HorseRaceTable
            );
            this.h_sire_table_ = new KOEI.WP7_2012.MemoryTable.HorseSireTable(
                this.pm_,
                this.config_.HorseSireTable
            );
            this.h_dam_table_ = new KOEI.WP7_2012.MemoryTable.HorseDamTable(
                this.pm_,
                this.config_.HorseDamTable
            );
            this.h_child_table_ = new KOEI.WP7_2012.MemoryTable.HorseChildTable(
                this.pm_,
                this.config_.HorseChildTable
            );
            this.h_ownership_race_table_ = new KOEI.WP7_2012.MemoryTable.HorseOwnershipRaceTable(
                this.pm_,
                this.config_.HorseOwnershipRaceTable
            );
            this.h_ownership_child_table_ = new KOEI.WP7_2012.MemoryTable.HorseOwnershipChildTable(
                this.pm_,
                this.config_.HorseOwnershipChildTable
            );
            this.r_name_table_ = new KOEI.WP7_2012.MemoryTable.RaceNameTable(
                this.pm_,
                this.config_
            );
            this.r_data_table_ = new KOEI.WP7_2012.MemoryTable.RaceDataTable(
                this.pm_,
                this.config_.RaceDataTable
            );
            this.r_program_table_ = new KOEI.WP7_2012.MemoryTable.RaceProgramTable(
                this.pm_,
                this.config_.RaceProgramTable
            );
        }
예제 #32
0
 /// <summary>
 /// Gets a BitmapContext within which to perform nested IO operations on the bitmap
 /// </summary>
 /// <remarks>For WPF the BitmapContext will lock the bitmap. Call Dispose on the context to unlock</remarks>
 /// <param name="bmp">The bitmap.</param>
 /// <param name="mode">The ReadWriteMode. If set to ReadOnly, the bitmap will not be invalidated on dispose of the context, else it will</param>
 /// <returns></returns>
 public static BitmapContext GetBitmapContext(this BitmapBuffer bmp, ReadWriteMode mode)
 {
     return(new BitmapContext(bmp, mode));
 }
 public override Task Read_Eof_Returns0(ReadWriteMode mode, bool dataAvailableFirst) => base.Read_Eof_Returns0(mode, dataAvailableFirst);
예제 #34
0
        public async Task FileOffsetIsPreservedWhenFileStreamIsCreatedFromSafeFileHandle_Reads(ReadWriteMode mode)
        {
            byte[] initialData = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
            using FileStream stream = (FileStream) await CreateReadOnlyStreamCore(initialData);

            byte[] buffer    = new byte[5];
            int    bytesRead = await ReadAsync(mode, stream, buffer, 0, buffer.Length);

            Assert.Equal(bytesRead, stream.Position);

            using FileStream createdFromHandle = new FileStream(stream.SafeFileHandle, FileAccess.Read);

            Assert.Equal(bytesRead, stream.Position);                  // accessing SafeFileHandle must not change the position
            Assert.Equal(stream.Position, createdFromHandle.Position); // but it should sync the offset with OS
        }
 public override Task Write_DataReadFromDesiredOffset(ReadWriteMode mode) => base.Write_DataReadFromDesiredOffset(mode);
예제 #36
0
 public BitmapContext(WriteableBitmap writeableBitmap, ReadWriteMode mode)
 {
     this = new BitmapContext(writeableBitmap);
 }
예제 #37
0
        public async Task SequentialReadsOnMemoryStream_Return_SameBytes(ReadWriteMode readWriteMode, bool derived)
        {
            byte[] data = new byte[1024 * 10];
            new Random(42).NextBytes(data);

            var compressed = new MemoryStream();

            using (var compressor = derived ?
                                    new DerivedDeflateStream(compressed, CompressionMode.Compress, true) :
                                    new DeflateStream(compressed, CompressionMode.Compress, true))
            {
                for (int i = 0; i < data.Length; i += 1024)
                {
                    switch (readWriteMode)
                    {
                    case ReadWriteMode.SyncArray: compressor.Write(data, i, 1024); break;

                    case ReadWriteMode.AsyncArray: await compressor.WriteAsync(data, i, 1024); break;

                    case ReadWriteMode.SyncSpan: compressor.Write(new Span <byte>(data, i, 1024)); break;

                    case ReadWriteMode.AsyncMemory: await compressor.WriteAsync(new ReadOnlyMemory <byte>(data, i, 1024)); break;
                    }
                }

                Assert.Equal(
                    derived && (readWriteMode == ReadWriteMode.SyncArray || readWriteMode == ReadWriteMode.SyncSpan),
                    compressor is DerivedDeflateStream dds && dds.WriteArrayInvoked);
            }
            compressed.Position = 0;

            using (var decompressor = derived ?
                                      new DerivedDeflateStream(compressed, CompressionMode.Decompress, true) :
                                      new DeflateStream(compressed, CompressionMode.Decompress, true))
            {
                int    i, j;
                byte[] array  = new byte[100];
                byte[] array2 = new byte[100];

                // only read in the first 100 bytes
                switch (readWriteMode)
                {
                case ReadWriteMode.SyncArray: decompressor.Read(array, 0, array.Length); break;

                case ReadWriteMode.AsyncArray: await decompressor.ReadAsync(array, 0, array.Length); break;

                case ReadWriteMode.SyncSpan: decompressor.Read(new Span <byte>(array)); break;

                case ReadWriteMode.AsyncMemory: await decompressor.ReadAsync(new Memory <byte>(array)); break;
                }
                for (i = 0; i < array.Length; i++)
                {
                    Assert.Equal(data[i], array[i]);
                }

                // read in the next 100 bytes and make sure nothing is missing
                switch (readWriteMode)
                {
                case ReadWriteMode.SyncArray: decompressor.Read(array2, 0, array2.Length); break;

                case ReadWriteMode.AsyncArray: await decompressor.ReadAsync(array2, 0, array2.Length); break;

                case ReadWriteMode.SyncSpan: decompressor.Read(new Span <byte>(array2)); break;

                case ReadWriteMode.AsyncMemory: await decompressor.ReadAsync(new Memory <byte>(array2)); break;
                }
                for (j = 0; j < array2.Length; j++)
                {
                    Assert.Equal(data[j], array[j]);
                }

                Assert.Equal(
                    derived && (readWriteMode == ReadWriteMode.SyncArray || readWriteMode == ReadWriteMode.SyncSpan),
                    decompressor is DerivedDeflateStream dds && dds.ReadArrayInvoked);
            }
        }