ReadBoolean() public method

public ReadBoolean ( ) : bool
return bool
Ejemplo n.º 1
0
        private async void OnRead(Object sender, RoutedEventArgs e)
        {
            StorageFolder local = ApplicationData.Current.LocalFolder;

            StorageFile file = await local.GetFileAsync("demo.dat");
            if(file != null)
            {
                string strres = "读到的内容:\n";
                using(IRandomAccessStream stream = await file.OpenReadAsync())
                {
                    DataReader dr = new DataReader(stream);
                    dr.UnicodeEncoding = UnicodeEncoding.Utf8;
                    await dr.LoadAsync((uint)stream.Size);
                    bool b = dr.ReadBoolean();
                    strres += b.ToString() + "\n";
                    DateTimeOffset dt = dr.ReadDateTime();
                    strres += dt.ToString("yyyy-M-d") + "\n";
                    uint len = dr.ReadUInt32();
                    if(len > 0)
                    {
                        strres += dr.ReadString(len);
                    }
                    dr.Dispose();
                }
                tbResult.Text = strres;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Send the data of the test to the server.
        /// </summary>
        /// <param name="testResultImage">The image to send.</param>
        public static async Task<bool> SendImageAsync(TestResultImage testResultImage)
        {
            if (!Connect())
                throw new InvalidOperationException("Could not connect to image comparer server");
			
            try
            {
                if (testResultImage.TestName == null && NUnit.Framework.TestContext.CurrentContext != null)
                {
                    testResultImage.TestName = NUnit.Framework.TestContext.CurrentContext.Test.FullName;
                }

                // Send initial parameters
                using (var memoryStream = new MemoryStream())
                {
                    var binaryWriter = new BinaryWriter(memoryStream);

                    // Header
                    binaryWriter.Write((int)ImageServerMessageType.SendImage);
                    TestGameBase.TestGameLogger.Info(@"Sending image information...");
                    testResultImage.Write(binaryWriter);

                    var dataWriter = new DataWriter(imageComparisonServer.OutputStream);
                    dataWriter.WriteBytes(memoryStream.ToArray());
                    await dataWriter.StoreAsync();
                    await dataWriter.FlushAsync();
                    dataWriter.DetachStream();
                }

                var dataReader = new DataReader(imageComparisonServer.InputStream);
                await dataReader.LoadAsync(1);
                var result = dataReader.ReadBoolean();
                dataReader.DetachStream();

                return result;
            }
            catch (Exception)
            {
                throw;
            }
        }
Ejemplo n.º 3
0
        private async Task<bool> ReadStatus()
        {
            bool state = false;
            try
            {
                StorageFolder storageFolder = ApplicationData.Current.LocalFolder;
                StorageFile file = await storageFolder.GetFileAsync("status.txt");

                var stream = await file.OpenAsync(FileAccessMode.ReadWrite);
                ulong size = stream.Size;

                using (var inputStream = stream.GetInputStreamAt(0))
                {
                    using (var dataReader = new DataReader(inputStream))
                    {
                        uint numBytesLoaded = await dataReader.LoadAsync((uint)size);
                        state = dataReader.ReadBoolean();
                    }
                }
                stream.Dispose();
            }
            catch (Exception) {}
            return state;
        }