本文整理汇总了C#中Windows.Storage.Streams.DataWriter.StoreAsync方法的典型用法代码示例。如果您正苦于以下问题:C# DataWriter.StoreAsync方法的具体用法?C# DataWriter.StoreAsync怎么用?C# DataWriter.StoreAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Windows.Storage.Streams.DataWriter
的用法示例。
在下文中一共展示了DataWriter.StoreAsync方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
}
}
示例2: 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);
}
示例3: Start
public override async void Start()
{
if (_Started)
return;
_SequenceNumber = 1;
try
{
// Connect to the Drone
udpClient = new DatagramSocket();
await udpClient.BindServiceNameAsync(_ServiceName);
await udpClient.ConnectAsync(new HostName(DroneClient.Host), _ServiceName);
udpWriter = new DataWriter(udpClient.OutputStream);
udpWriter.WriteByte(1);
await udpWriter.StoreAsync();
_Timer = ThreadPoolTimer.CreatePeriodicTimer(new TimerElapsedHandler(timerElapsedHandler), TimeSpan.FromMilliseconds(25));
_Started = true;
}
catch (Exception)
{
Stop();
}
}
示例4: datagramSocket_MessageReceived
async void datagramSocket_MessageReceived(DatagramSocket sender, DatagramSocketMessageReceivedEventArgs args)
{
i++;
DataReader dataReader = args.GetDataReader();
uint length = dataReader.UnconsumedBufferLength;
string content = dataReader.ReadString(length);
Deployment.Current.Dispatcher.BeginInvoke(() =>
msgList.Children.Add(new TextBlock { Text = "服务器收到的消息:" + content }));
//HostName hostName = new HostName("localhost");
//DatagramSocket datagramSocket = new DatagramSocket();
//IOutputStream outputStream = await datagramSocket.GetOutputStreamAsync(hostName, "22112");
DataWriter writer = new DataWriter(sender.OutputStream);
writer.WriteString(content + "|" + i);
try
{
await writer.StoreAsync();
msgList.Children.Add(new TextBlock { Text = "服务器发送的消息:" + content + "|" + i });
}
catch (Exception err)
{
if (SocketError.GetStatus(err.HResult) == SocketErrorStatus.AddressAlreadyInUse)
{
}
}
}
示例5: init
public static async void init(TiSettings settings) {
if (!settings.ContainsKey("logToken") || settings["logToken"].Length == 0) {
return;
}
logToken = settings["logToken"];
multicastSocket = new DatagramSocket();
multicastSocket.MessageReceived += multicastSocket_MessageReceived;
HostName hostname = new HostName("239.6.6.6");
try {
await multicastSocket.BindServiceNameAsync("8666");
multicastSocket.JoinMulticastGroup(hostname);
IOutputStream stream = await multicastSocket.GetOutputStreamAsync(hostname, "8666");
DataWriter writer = new DataWriter(stream);
writer.WriteString("TI_WP8_LOGGER");
await writer.StoreAsync();
writer.DetachStream();
stream.Dispose();
} catch (Exception ex) {
if (SocketError.GetStatus(ex.HResult) == SocketErrorStatus.Unknown) {
throw;
}
Debug.WriteLine(ex.ToString());
}
}
示例6: 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;
}
示例7: SendMessage
public async void SendMessage(string msg)
{
HostName hostName;
try
{
hostName = new HostName("localhost");
}
catch (ArgumentException)
{
return;
}
StreamSocket socket;
try
{
using (socket = new StreamSocket())
{
await socket.ConnectAsync(hostName, port2);
//CoreApplication.Properties.Add("connected", null);
DataWriter dw = new DataWriter(socket.OutputStream);
dw.WriteString(msg);
await dw.StoreAsync();
}
}
catch
{
//break;
}
}
示例8: 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);
}
}
示例9: 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;
}
}
}
示例10: 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);
}
}
示例11: PerformPeerDiscovery
public async void PerformPeerDiscovery()
{
timer.Interval = new TimeSpan(0, 0, 5);
timer.Start();
if (socket == null)
{
socket = new DatagramSocket();
socket.MessageReceived += socket_MessageReceived;
try
{
await socket.BindEndpointAsync(null, "22002");
}
catch
{
// Swallow any already bound exceptions!
}
}
using (var outputStream = await socket.GetOutputStreamAsync(new HostName("230.0.0.1"), "22003"))
{
using (DataWriter wr = new DataWriter(outputStream))
{
wr.WriteString("**BECHARMING DISCOVERY**");
await wr.FlushAsync();
await wr.StoreAsync();
}
}
}
示例12: 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;
}
}
示例13: Send
public async Task Send(WemosMessage msg)
{
if (msg != null)
{
var str = msg.ToDto();
if (!string.IsNullOrEmpty(str))
{
try
{
// GetOutputStreamAsync can be called multiple times on a single DatagramSocket instance to obtain
// IOutputStreams pointing to various different remote endpoints. The remote hostname given to
// GetOutputStreamAsync can be a unicast, multicast or broadcast address.
IOutputStream outputStream = await listenerSocket.GetOutputStreamAsync(new HostName(remoteMulticastAddress), remoteService);
DataWriter writer = new DataWriter(outputStream);
writer.WriteString(str);
await writer.StoreAsync();
}
catch (Exception exception)
{
// If this is an unknown status it means that the error is fatal and retry will likely fail.
if (SocketError.GetStatus(exception.HResult) == SocketErrorStatus.Unknown)
throw;
//rootPage.NotifyUser("Send failed with error: " + exception.Message, NotifyType.ErrorMessage);
}
}
}
}
示例14: 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;
}
}
示例15: 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;
}
}