本文整理汇总了C#中Windows.Storage.Streams.DataWriter类的典型用法代码示例。如果您正苦于以下问题:C# DataWriter类的具体用法?C# DataWriter怎么用?C# DataWriter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DataWriter类属于Windows.Storage.Streams命名空间,在下文中一共展示了DataWriter类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: 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;
}
}
开发者ID:ballance,项目名称:MetroTorrent,代码行数:28,代码来源:ServerCommunicator.cs
示例17: 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());
}
}
开发者ID:88to,项目名称:titanium_mobile,代码行数:29,代码来源:Logger.cs
示例18: WriteToStreamButton_Click
private async void WriteToStreamButton_Click(object sender, RoutedEventArgs e)
{
try
{
rootPage.ResetScenarioOutput(OutputTextBlock);
StorageFile file = rootPage.sampleFile;
if (file != null)
{
string userContent = InputTextBox.Text;
if (!String.IsNullOrEmpty(userContent))
{
using (StorageStreamTransaction transaction = await file.OpenTransactedWriteAsync())
{
using (DataWriter dataWriter = new DataWriter(transaction.Stream))
{
dataWriter.WriteString(userContent);
transaction.Stream.Size = await dataWriter.StoreAsync(); // reset stream size to override the file
await transaction.CommitAsync();
OutputTextBlock.Text = "The following text was written to '" + file.Name + "' using a stream:" + Environment.NewLine + Environment.NewLine + userContent;
}
}
}
else
{
OutputTextBlock.Text = "The text box is empty, please write something and then click 'Write' again.";
}
}
}
catch (FileNotFoundException)
{
rootPage.NotifyUserFileNotExist();
}
}
开发者ID:mac10688,项目名称:PublicWorkspace,代码行数:33,代码来源:Scenario4.xaml.cs
示例19: Connect
public static void Connect(string address, string port)
{
if (!connected)
{
clientSocket = new StreamSocket();
try
{
serverHost = new HostName(address);
serverPort = port;
serverHostnameString = address;
writer = new DataWriter(clientSocket.OutputStream);
clientSocket.ConnectAsync(serverHost, serverPort);
connected = true;
}
catch (Exception)
{
clientSocket.Dispose();
clientSocket = null;
throw new ConnectionErrorException();
}
}
else
{
clientSocket.Dispose();
clientSocket = null;
connected = false;
GamepadClient.Connect(address, port);
}
}
开发者ID:GudoshnikovaAnna,项目名称:qreal,代码行数:33,代码来源:SocketClient.cs
示例20: TransparentExchangeAsync
/// <summary>
/// Extension method to SmartCardConnection class to perform a transparent exchange to the ICC
/// </summary>
/// <param name="connection">
/// SmartCardConnection object
/// </param>
/// <param name="commandData">
/// Command object to send to the ICC
/// </param>
/// <returns>Response received from the ICC</returns>
public static async Task<byte[]> TransparentExchangeAsync(this SmartCardConnection connection, byte[] commandData)
{
byte[] responseData = null;
ManageSessionResponse apduRes = await TransceiveAsync(connection, new ManageSession(new byte[2] { (byte)ManageSession.DataObjectType.StartTransparentSession, 0x00 })) as ManageSessionResponse;
if (!apduRes.Succeeded)
{
throw new Exception("Failure to start transparent session, " + apduRes.ToString());
}
using (DataWriter dataWriter = new DataWriter())
{
dataWriter.WriteByte((byte)TransparentExchange.DataObjectType.Transceive);
dataWriter.WriteByte((byte)commandData.Length);
dataWriter.WriteBytes(commandData);
TransparentExchangeResponse apduRes1 = await TransceiveAsync(connection, new TransparentExchange(dataWriter.DetachBuffer().ToArray())) as TransparentExchangeResponse;
if (!apduRes1.Succeeded)
{
throw new Exception("Failure transceive with card, " + apduRes1.ToString());
}
responseData = apduRes1.IccResponse;
}
ManageSessionResponse apduRes2 = await TransceiveAsync(connection, new ManageSession(new byte[2] { (byte)ManageSession.DataObjectType.EndTransparentSession, 0x00 })) as ManageSessionResponse;
if (!apduRes2.Succeeded)
{
throw new Exception("Failure to end transparent session, " + apduRes2.ToString());
}
return responseData;
}
开发者ID:mhdubose,项目名称:Windows-universal-samples,代码行数:45,代码来源:PcscUtils.cs
注:本文中的Windows.Storage.Streams.DataWriter类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论