当前位置: 首页>>代码示例>>C#>>正文


C# Streams.DataWriter类代码示例

本文整理汇总了C#中Windows.Storage.Streams.DataWriter的典型用法代码示例。如果您正苦于以下问题:C# DataWriter类的具体用法?C# DataWriter怎么用?C# DataWriter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


DataWriter类属于Windows.Storage.Streams命名空间,在下文中一共展示了DataWriter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ConnectAsync

        public static async Task<bool> ConnectAsync()
        {
            if (imageComparisonServer != null)
                return true;
			
            try
            {
                imageComparisonServer = new StreamSocket();
                await imageComparisonServer.ConnectAsync(new HostName(ParadoxImageServerHost), ParadoxImageServerPort.ToString());
			
                // Send initial parameters
                using (var memoryStream = new MemoryStream())
                {
                    var binaryWriter = new BinaryWriter(memoryStream);
                    ImageTestResultConnection.Write(binaryWriter);

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

                return true;
            }
            catch (Exception)
            {
                imageComparisonServer = null;
			
                return false;
            }
        }
开发者ID:Powerino73,项目名称:paradox,代码行数:32,代码来源:ImageTester.Runtime.cs

示例2: Convert

        public object Convert(object value, Type targetType, object parameter, string language)
        {
            if (value != null)
            {

                byte[] bytes = (byte[])value;
                BitmapImage myBitmapImage = new BitmapImage();
                if (bytes.Count() > 0)
                {


                    InMemoryRandomAccessStream stream = new InMemoryRandomAccessStream();
                    DataWriter writer = new DataWriter(stream.GetOutputStreamAt(0));

                    writer.WriteBytes(bytes);
                    writer.StoreAsync().GetResults();
                    myBitmapImage.SetSource(stream);
                }
                else
                {
                    myBitmapImage.UriSource = new Uri("ms-appx:///Assets/firstBackgroundImage.jpg");
                }

                return myBitmapImage;
            }
            else
            {
                return new BitmapImage();
            }
        }
开发者ID:garicchi,项目名称:Neuronia,代码行数:30,代码来源:ByteToBitmapConverterForBackground.cs

示例3: ButtonAction2_Click

        private async void ButtonAction2_Click(object sender, RoutedEventArgs e)
        {
            DevicesInformation = string.Empty;
            foreach (var rsCharacteristic in _dicCharacteristics)
            {
                DevicesInformation += $"  Try to write to {rsCharacteristic.Value.CharName}{Environment.NewLine}";
                bool writeOk = true;
                try
                {
                    var charToTest = rsCharacteristic.Value.Characteristic;
                    byte[] arr = { 4, 1, 2, 0, 1, 0 };
                    var writer = new DataWriter();
                    writer.WriteBytes(arr);
                    await charToTest.WriteClientCharacteristicConfigurationDescriptorAsync(GattClientCharacteristicConfigurationDescriptorValue.Indicate);
                    await charToTest.WriteValueAsync(writer.DetachBuffer());
                    DevicesInformation += $"  - OK{Environment.NewLine}";
                }
                catch
                {
                    DevicesInformation += $"  - ERROR{Environment.NewLine}";
                    writeOk = false;
                }

                var msg = $"{rsCharacteristic.Value.CharName}, {writeOk}, {rsCharacteristic.Value.Characteristic.CharacteristicProperties}, {rsCharacteristic.Value.Characteristic.Uuid}";
                Debug.WriteLine(msg);

                await Task.Delay(TimeSpan.FromMilliseconds(100));
            }
        }
开发者ID:modulexcite,项目名称:events,代码行数:29,代码来源:MainPage.xaml.cs

示例4: Base64ToBitmapImage

        public async Task<BitmapImage> Base64ToBitmapImage(string base64String)
        {

            BitmapImage img = new BitmapImage();
            if (string.IsNullOrEmpty(base64String))
                return img;

            using (var ims = new InMemoryRandomAccessStream())
            {
                byte[] bytes = Convert.FromBase64String(base64String);
                base64String = "";

                using (DataWriter dataWriter = new DataWriter(ims))
                {
                    dataWriter.WriteBytes(bytes);
                    bytes = null;
                    await dataWriter.StoreAsync();
                                 

                ims.Seek(0);

              
               await img.SetSourceAsync(ims); //not in RC
               
               
                return img;
                }
            }

        }
开发者ID:bdecori,项目名称:win8,代码行数:30,代码来源:Utility.cs

示例5: ProccesImage

        public async void ProccesImage(StorageFile imageFile)
        {
            var data = await FileIO.ReadBufferAsync(imageFile);

            // create a stream from the file
            var ms = new InMemoryRandomAccessStream();
            var dw = new DataWriter(ms);
            dw.WriteBuffer(data);
            await dw.StoreAsync();
            ms.Seek(0);

            // find out how big the image is, don't need this if you already know
            var bm = new BitmapImage();
            await bm.SetSourceAsync(ms);

            // create a writable bitmap of the right size
            var wb = new WriteableBitmap(bm.PixelWidth, bm.PixelHeight);
            ms.Seek(0);

            // load the writable bitpamp from the stream
            await wb.SetSourceAsync(ms);

            Bitmap bmp = (Bitmap)wb;

            //var filter1 = Grayscale.CommonAlgorithms.BT709;

            //bmp = filter1.Apply(bmp);

            wb = (WriteableBitmap)bmp;

            var file = await this.WriteableBitmapToStorageFile(wb, FileFormat.Jpeg);
        }
开发者ID:epustovit,项目名称:Scanner,代码行数:32,代码来源:ImageProccesing.cs

示例6: HandleSensorControlPoint

        // Write function for adding control points to a server
        private async Task HandleSensorControlPoint(string data)
        {
            if (!string.IsNullOrEmpty(data))
            {
                // Get current service from base class.
                var service = await GetService();
                // Get current characteristic from current service using the selected values from the base class.
                var characteristic = service.GetCharacteristics(this.SelectedService.Guid)[this.SelectedIndex];

                //Create an instance of a data writer which will write to the relevent buffer.
                DataWriter writer = new DataWriter();
                byte[] toWrite = System.Text.Encoding.UTF8.GetBytes(data);
                writer.WriteBytes(toWrite);

                // Attempt to write the data to the device, and whist doing so get the status.
                GattCommunicationStatus status = await characteristic.WriteValueAsync(writer.DetachBuffer());

                // Displays a message box to tell user if the write operation was successful or not.
                if (status == GattCommunicationStatus.Success)
                {
                    MessageHelper.DisplayBasicMessage("Sensor control point has been written.");
                }
                else
                {
                    MessageHelper.DisplayBasicMessage("There was a problem writing the sensor control value, Please try again later.");
                }
            }
        }
开发者ID:mwarren571,项目名称:GestureControlWristband,代码行数:29,代码来源:HeartRateMonitorDevice.cs

示例7: SocketHandler

        public SocketHandler(StreamSocket socket)
        {
            this.socket = socket;

            this.reader = new DataReader(this.socket.InputStream);
            this.writer = new DataWriter(this.socket.OutputStream);
        }
开发者ID:philipp2500,项目名称:Remote-Content-Show,代码行数:7,代码来源:SocketHandler.cs

示例8: OnLoadingFile

        private async void OnLoadingFile(object sender, GestureEventArgs e)
        {
            var city = new City
            {
                Name = "Leipzig",
                State = "Saxony",
                Country = "Germany",
                Population = 550000
            };

            string json = JsonConvert.SerializeObject(city);

            var cityFile = 
              await ApplicationData.Current
                                   .LocalFolder.CreateFileAsync(
                                     "leipzig.city",
                                     CreationCollisionOption.ReplaceExisting);

            using (var stream = await cityFile.OpenAsync(FileAccessMode.ReadWrite))
            {
                using (var writer = new DataWriter(stream))
                {
                    writer.WriteString(json);
                    await writer.StoreAsync();
                }
            }

            Launcher.LaunchFileAsync(cityFile);
        }
开发者ID:GregOnNet,项目名称:WP8BookSamples,代码行数:29,代码来源:MainPage.xaml.cs

示例9: Connect

		public async Task Connect()
		{
			if (!_isLoggedIn)
				throw new DiscordException(ExceptionList.NotLoggedIn);

			_socket = new MessageWebSocket();
			_writer = new DataWriter(_socket.OutputStream) { UnicodeEncoding = UnicodeEncoding.Utf8 };

			_socket.Control.MessageType = SocketMessageType.Utf8;
			_socket.MessageReceived += socket_MessageReceived;

			string gatewayUrl = await GetGateway();

			await _socket.ConnectAsync(new Uri(gatewayUrl));

			JsonObject request = new JsonObject
			{
				{ "op", JsonValue.CreateNumberValue(2) },
				{ "d", new JsonObject
					{
						{ "token", JsonValue.CreateStringValue(_token) },
						{ "v", JsonValue.CreateNumberValue(3) },
						{ "properties", new JsonObject
						{
							{ "$os", JsonValue.CreateStringValue("Windows") }
						}},
						{ "large_threshold", JsonValue.CreateNumberValue(0) }
					}
				}
			};

			await WriteToSocket(request.Stringify());
		}
开发者ID:romgerman,项目名称:DiscordUWP8,代码行数:33,代码来源:Client.cs

示例10: ConnectToDevice

 public async Task ConnectToDevice(DeviceInformation device)
 {
     this.State = ConnectionState.Connecting;
     try
     {
         serialConnection = await SerialDevice.FromIdAsync(device.Id);
         if (serialConnection != null)
         {
             serialConnection.BaudRate = 115200;
             serialConnection.DataBits = 8;
             serialConnection.Parity = SerialParity.None;
             writer = new DataWriter(serialConnection.OutputStream);
             reader = new DataReader(serialConnection.InputStream);
             Task listen = ListenForMessagesAsync();
             this.State = ConnectionState.Connected;
         }
         else {
             Debugger.ReportToDebugger(this, "Unable to create service.\nMake sure that the 'serialcommunication' capability is declared with a function of type 'name:serialPort' in Package.appxmanifest.", Debugger.Device.Pc);
             this.State = ConnectionState.Failure;
         }
     }
     catch (TaskCanceledException ex)
     {
         this.State = ConnectionState.Failure;
         Debugger.ReportToDebugger(this, ex.Message, Debugger.Device.Pc);
     }
     catch (Exception ex)
     {
         this.State = ConnectionState.Failure;
         Debugger.ReportToDebugger(this, ex.Message, Debugger.Device.Pc);
     }
 }
开发者ID:AliceTheCat,项目名称:LightTable,代码行数:32,代码来源:SerialConnection.cs

示例11: Convert

        public object Convert(object value, Type targetType, object parameter, string language)
        {
            if (value != null && value is byte[])
            {

                //WriteableBitmap bitmap = new WriteableBitmap(100, 100);

                //System.IO.Stream bitmapStream = null;
                //bitmapStream = bitmap.PixelBuffer.AsStream();
                //bitmapStream.Position = 0;
                //bitmapStream.Write(value as byte[], 0, (value as byte[]).Length);

                //bitmapStream.Flush();

                InMemoryRandomAccessStream randomAccessStream = new InMemoryRandomAccessStream();
                DataWriter writer = new DataWriter(randomAccessStream.GetOutputStreamAt(0));
                writer.WriteBytes(value as byte[]);
                var x = writer.StoreAsync().AsTask().Result;
                BitmapImage image = new BitmapImage();
                image.SetSource(randomAccessStream);

                return image;
            }

            return null;
        }
开发者ID:garymedina,项目名称:MyEvents,代码行数:26,代码来源:ByteToImageConverter.cs

示例12: connect

 //Connects to server
 public async Task connect(string address, int port)
 {
     if (!this.connected)
     {
         try
         {
             this.socket = new StreamSocket();
             this.hostname = new HostName(address);
             this.port = port;
             await this.socket.ConnectAsync(this.hostname, port.ToString());
             this.writer = new DataWriter(this.socket.OutputStream);
             this.reader = new DataReader(this.socket.InputStream);
             this.reader.InputStreamOptions = InputStreamOptions.Partial;
             connected = true;
         }
         catch (Exception e)
         {
             connected = false;
             Debug.WriteLine(e.Message);
         }
     }
     else
     {
         await new MessageDialog("Already connected", "Information").ShowAsync();
         connected = true;
         
     }
 }
开发者ID:HaavardM,项目名称:havissIoT-WindowsApp,代码行数:29,代码来源:HavissIoTClient.cs

示例13: Init

 public async Task<bool> Init()
 {
     var res = true;
     ClearExceptions();
     for (int i = 0; i < 20; i++)
     {
         try
         {
             var value = new byte[3];
             value[0] = 0x1;
             value[1] = (byte)(i + 1);
             value[2] = (byte)(i + 1);
             var buffer = new DataWriter();
             buffer.WriteBytes(value);
             await _initCount1To20Char.WriteValueAsync(buffer.DetachBuffer(), GattWriteOption.WriteWithoutResponse);
             await Sleep(50);
         }
         catch (Exception exception)
         {
             res = false;
             AddException(exception);
         }
     }
     return res;
 }
开发者ID:modulexcite,项目名称:events,代码行数:25,代码来源:TourTheStairs.cs

示例14: OnShareTargetActivated

 protected override async void OnShareTargetActivated(ShareTargetActivatedEventArgs args)
 {
     if (args.ShareOperation.Data.Contains(StandardDataFormats.WebLink))
     {
         Uri uri = await args.ShareOperation.Data.GetWebLinkAsync();
         if (null != uri)
         try
         {
             using (var socket = new MessageWebSocket())
             {
                 socket.Control.MessageType = SocketMessageType.Utf8;
                 await socket.ConnectAsync(new Uri("ws://" + settings["Host"].ToString() + ":" + settings["Port"].ToString()));
                 using (var writer = new DataWriter(socket.OutputStream))
                 {
                     writer.WriteString(uri.AbsoluteUri);
                     await writer.StoreAsync();
                     args.ShareOperation.ReportCompleted();
                 }
             }
         }
         catch
         {
             show();
         }
     }
 }
开发者ID:undwad,项目名称:2Desktop,代码行数:26,代码来源:App.xaml.cs

示例15: WriteToSerialPort

 public async void WriteToSerialPort(string message)
 {
     var writer = new DataWriter(_realDevice.OutputStream);
     writer.WriteString(AddNewLine(message));
     await writer.StoreAsync().AsTask();
     writer.DetachStream();
 }
开发者ID:Quantzo,项目名称:IotRouter,代码行数:7,代码来源:SerialBridge.cs


注:本文中的Windows.Storage.Streams.DataWriter类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。