當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。