本文整理汇总了C#中Windows.Storage.Streams.DataWriter.WriteBytes方法的典型用法代码示例。如果您正苦于以下问题:C# DataWriter.WriteBytes方法的具体用法?C# DataWriter.WriteBytes怎么用?C# DataWriter.WriteBytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Windows.Storage.Streams.DataWriter
的用法示例。
在下文中一共展示了DataWriter.WriteBytes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: iBeaconSetAdvertisement
public static void iBeaconSetAdvertisement(this BluetoothLEAdvertisement Advertisment, iBeaconData data)
{
BluetoothLEManufacturerData manufacturerData = new BluetoothLEManufacturerData();
// Set Apple as the manufacturer data
manufacturerData.CompanyId = 76;
var writer = new DataWriter();
writer.WriteUInt16(0x0215); //bytes 0 and 1 of the iBeacon advertisment indicator
if (data!=null& data.UUID!= Guid.Empty)
{
//If UUID is null scanning for all iBeacons
writer.WriteBytes( data.UUID.ToByteArray());
if (data.Major!=0)
{
//If Major not null searching with UUID and Major
writer.WriteBytes(BitConverter.GetBytes(data.Major).Reverse().ToArray());
if (data.Minor != 0)
{
//If Minor not null we are looking for a specific beacon not a class of beacons
writer.WriteBytes(BitConverter.GetBytes(data.Minor).Reverse().ToArray());
if (data.TxPower != 0)
writer.WriteBytes(BitConverter.GetBytes(data.TxPower));
}
}
}
manufacturerData.Data = writer.DetachBuffer();
Advertisment.ManufacturerData.Clear();
Advertisment.ManufacturerData.Add(manufacturerData);
}
示例2: GetDataIn
private static byte[] GetDataIn(byte serviceCount, byte[] serviceCodeList, byte blockCount, byte[] blockList)
{
DataWriter dataWriter = new DataWriter();
dataWriter.WriteByte(serviceCount);
dataWriter.WriteBytes(serviceCodeList);
dataWriter.WriteByte(blockCount);
dataWriter.WriteBytes(blockList);
return dataWriter.DetachBuffer().ToArray();
}
示例3: Send
public void Send(string message)
{
var ostream = this.streamSocket.OutputStream;
var dataWriter = new DataWriter(ostream);
byte[] msgByteArray = Helpers.stringToByteArray(message);
byte[] msgSizeByteArray = Helpers.intToByteArray(msgByteArray.Length);
dataWriter.WriteBytes(msgSizeByteArray);
dataWriter.WriteBytes(msgByteArray);
dataWriter.StoreAsync().AsTask().Wait();
dataWriter.FlushAsync().AsTask().Wait();
}
示例4: WriteFileAsync
public static async Task WriteFileAsync(string fileName, byte[] content)
{
try
{
var file = await ApplicationData.Current.LocalFolder.CreateFileAsync(fileName, CreationCollisionOption.ReplaceExisting);
using (var fileStream = await file.OpenAsync(FileAccessMode.ReadWrite))
{
using (var outputStream = fileStream.GetOutputStreamAt(0))
{
using (var dataWriter = new DataWriter(outputStream))
{
dataWriter.WriteBytes(content);
await dataWriter.StoreAsync();
dataWriter.DetachStream();
}
await outputStream.FlushAsync();
}
}
}
catch (Exception exception)
{
SnazzyDebug.WriteLine(exception);
}
}
示例5: BeginReadCCTV
async void BeginReadCCTV()
{
IsBeginRead = true;
ISExit = false;
tblCCTV cctvinfo=null;
await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,
() =>
{
cctvinfo = this.DataContext as tblCCTV;
});
// client=new HttpClient();
while (!ISExit)
{
try
{
Uri uri = new Uri("http://192.192.161.3/" + cctvinfo.REF_CCTV_ID.Trim() + ".jpg?" + rnd.Next(), UriKind.Absolute);
using (httpClient = new HttpClient())
{
httpClient.Timeout = TimeSpan.FromSeconds(0.5);
var contentBytes = await httpClient.GetByteArrayAsync(uri);
var ims = new InMemoryRandomAccessStream();
var dataWriter = new DataWriter(ims);
dataWriter.WriteBytes(contentBytes);
await dataWriter.StoreAsync();
//ims.seak 0
ims.Seek(0 );
await Dispatcher.RunAsync( Windows.UI.Core.CoreDispatcherPriority.Normal,()=>
{
BitmapImage bitmap = new BitmapImage();
bitmap.SetSource(ims );
this.imgCCTV.Source = bitmap;
imginx = (imginx + 1) % 90000;
this.RunFrameRate.Text = imginx.ToString();
});
}
}
catch (Exception ex)
{
// this.textBlock1.Text = ex.Message;
}
// BitmapImage img = new BitmapImage();
// img.SetSource(stream);
}
}
示例6: Convert
public object Convert(object value, Type targetType, object parameter, string language)
{
if (!(value is byte[]))
{
return null;
}
using (InMemoryRandomAccessStream ms = new InMemoryRandomAccessStream())
{
// Writes the image byte array in an InMemoryRandomAccessStream
// that is needed to set the source of BitmapImage.
using (DataWriter writer = new DataWriter(ms.GetOutputStreamAt(0)))
{
writer.WriteBytes((byte[])value);
// The GetResults here forces to wait until the operation completes
// (i.e., it is executed synchronously), so this call can block the UI.
writer.StoreAsync().GetResults();
}
var image = new BitmapImage();
image.SetSource(ms);
return image;
}
}
示例7: Update
private async void Update()
{
var writer1 = new BarcodeWriter
{
Format = BarcodeFormat.QR_CODE,
Options = new ZXing.Common.EncodingOptions
{
Height = 200,
Width = 200
},
};
var image = writer1.Write(Text);//Write(text);
using (InMemoryRandomAccessStream ms = new InMemoryRandomAccessStream())
{
using (DataWriter writer = new DataWriter(ms.GetOutputStreamAt(0)))
{
writer.WriteBytes(image);
await writer.StoreAsync();
}
var output = new BitmapImage();
await output.SetSourceAsync(ms);
ImageSource = output;
}
}
示例8: WriteToOutputStreamAsync
private async Task WriteToOutputStreamAsync(byte[] bytes)
{
if (_socket == null) return;
_writer = new DataWriter(_socket.OutputStream);
_writer.WriteBytes(bytes);
var debugString = UTF8Encoding.UTF8.GetString(bytes, 0, bytes.Length);
try
{
await _writer.StoreAsync();
await _socket.OutputStream.FlushAsync();
_writer.DetachStream();
_writer.Dispose();
}
catch (Exception exception)
{
// If this is an unknown status it means that the error if fatal and retry will likely fail.
if (global::Windows.Networking.Sockets.SocketError.GetStatus(exception.HResult) == global::Windows.Networking.Sockets.SocketErrorStatus.Unknown)
{
// TODO abort any retry attempts on Unity side
throw;
}
}
}
示例9: Download
private async Task Download(string url,StorageFile file,bool cover)
{
var http = new HttpClient();
byte[] response = { };
string betterUrl = url;
if(cover)
{
var pos = betterUrl.IndexOf(".jpg");
if (pos != -1)
betterUrl = betterUrl.Insert(pos, "l");
}
//get bytes
try
{
await Task.Run(async () => response = await http.GetByteArrayAsync(betterUrl));
}
catch (Exception)
{
await Task.Run(async () => response = await http.GetByteArrayAsync(url));
}
var fs = await file.OpenStreamForWriteAsync(); //get stream
var writer = new DataWriter(fs.AsOutputStream());
writer.WriteBytes(response); //write
await writer.StoreAsync();
await writer.FlushAsync();
writer.Dispose();
}
示例10: GetNetworkTimeAsync
/// <summary>
/// Gets accurate time using the NTP protocol with default timeout of 45 seconds.
/// </summary>
/// <param name="timeout">Operation timeout.</param>
/// <returns>Network accurate <see cref="DateTime"/> value.</returns>
public async Task<DateTime> GetNetworkTimeAsync(TimeSpan timeout)
{
using (var socket = new DatagramSocket())
using (var ct = new CancellationTokenSource(timeout))
{
ct.Token.Register(() => _resultCompletionSource.TrySetCanceled());
socket.MessageReceived += OnSocketMessageReceived;
//The UDP port number assigned to NTP is 123
await socket.ConnectAsync(new HostName("pool.ntp.org"), "123");
using (var writer = new DataWriter(socket.OutputStream))
{
// NTP message size is 16 bytes of the digest (RFC 2030)
var ntpBuffer = new byte[48];
// Setting the Leap Indicator,
// Version Number and Mode values
// LI = 0 (no warning)
// VN = 3 (IPv4 only)
// Mode = 3 (Client Mode)
ntpBuffer[0] = 0x1B;
writer.WriteBytes(ntpBuffer);
await writer.StoreAsync();
var result = await _resultCompletionSource.Task;
return result;
}
}
}
示例11: GetImageSize
public async static void GetImageSize(this Stream imageStream)
{
var image = new BitmapImage();
byte[] imageBytes = Convert.FromBase64String(imageStream.ToBase64String());
MemoryStream ms = new MemoryStream(imageBytes, 0, imageBytes.Length);
ms.Write(imageBytes, 0, imageBytes.Length);
using (InMemoryRandomAccessStream stream = new InMemoryRandomAccessStream())
{
using (DataWriter writer = new DataWriter(stream.GetOutputStreamAt(0)))
{
try
{
writer.WriteBytes(imageBytes);
await writer.StoreAsync();
}
catch (Exception)
{
// ignored
}
}
try
{
await image.SetSourceAsync(stream);
}
catch (Exception)
{
// ignored
}
}
ImageSize = new Size(image.PixelWidth, image.PixelHeight);
}
示例12: 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));
}
}
示例13: 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.");
}
}
}
示例14: 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();
}
}
示例15: 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;
}
}
}