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


C# DataWriter.DetachStream方法代码示例

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


在下文中一共展示了DataWriter.DetachStream方法的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: SaveAsync

        /// <summary>
        /// Writes a string to a text file.
        /// </summary>
        /// <param name="text">The text to write.</param>
        /// <param name="fileName">Name of the file.</param>
        /// <param name="folder">The folder.</param>
        /// <param name="options">
        /// The enum value that determines how responds if the fileName is the same
        /// as the name of an existing file in the current folder. Defaults to ReplaceExisting.
        /// </param>
        /// <returns></returns>
        public static async Task SaveAsync(
            this string text,
            string fileName,
            StorageFolder folder = null,
            CreationCollisionOption options = CreationCollisionOption.ReplaceExisting)
        {
            folder = folder ?? ApplicationData.Current.LocalFolder;
            var file = await folder.CreateFileAsync(
                fileName,
                options);
            using (var fs = await file.OpenAsync(FileAccessMode.ReadWrite))
            {
                using (var outStream = fs.GetOutputStreamAt(0))
                {
                    using (var dataWriter = new DataWriter(outStream))
                    {
                        if (text != null)
                            dataWriter.WriteString(text);

                        await dataWriter.StoreAsync();
                        dataWriter.DetachStream();
                    }

                    await outStream.FlushAsync();
                }
            }
        }
开发者ID:xyzzer,项目名称:WinRTXamlToolkit,代码行数:38,代码来源:StringIOExtensions.cs

示例3: DoCommand

 private async Task<string> DoCommand(string command)
 {
     StringBuilder strBuilder = new StringBuilder();
     using (StreamSocket clientSocket = new StreamSocket())
     {
         await clientSocket.ConnectAsync(new HostName("192.168.9.108"),  "9001");
         using (DataWriter writer = new DataWriter(clientSocket.OutputStream))
         {
             writer.WriteString(command);
             await writer.StoreAsync();
             writer.DetachStream();
         }
         using (DataReader reader = new DataReader(clientSocket.InputStream))
         {
             reader.InputStreamOptions = InputStreamOptions.Partial;
             await reader.LoadAsync(8192);
             while (reader.UnconsumedBufferLength > 0)
             {
                 strBuilder.Append(reader.ReadString(reader.UnconsumedBufferLength));
                 await reader.LoadAsync(8192);
             }
             reader.DetachStream();
         }
     }
     return (strBuilder.ToString());
 }
开发者ID:mderoode,项目名称:OVCClient,代码行数:26,代码来源:SocketConnection.xaml.cs

示例4: OnWrite

 private async void OnWrite(Object sender, RoutedEventArgs e)
 {
     // 获取本地目录的引用
     StorageFolder local = ApplicationData.Current.LocalFolder;
     // 创建新文件
     StorageFile newFIle = await local.CreateFileAsync("demo.dat", CreationCollisionOption.ReplaceExisting);
     // 打开文件流
     using(IRandomAccessStream stream = await newFIle.OpenAsync(FileAccessMode.ReadWrite))
     {
         // 实例化 DataWriter
         DataWriter dw = new DataWriter(stream);
         // 设置默认编码格式
         dw.UnicodeEncoding = UnicodeEncoding.Utf8;
         // 写入 bool 值
         dw.WriteBoolean(true);
         // 写入日期值
         DateTime dt = new DateTime(2010, 8, 21);
         dw.WriteDateTime(dt);
         // 写入字符串
         string str = "测试文本";
         // 计算字符串长度
         uint len = dw.MeasureString(str);
         // 先写入字符串的长的
         dw.WriteUInt32(len);
         // 再写入字符串
         dw.WriteString(str);
         // 以下方法必须调用
         await dw.StoreAsync();
         // 解除 DataWriter 与流的关联
         dw.DetachStream();
         dw.Dispose();
     }
     MessageDialog msgDlg = new MessageDialog("保存成功。");
     await msgDlg.ShowAsync();
 }
开发者ID:forehalo,项目名称:UWP-dev,代码行数:35,代码来源:_DataWriter.xaml.cs

示例5: 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

示例6: 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

示例7: 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);
			}
		}
开发者ID:0xdeafcafe,项目名称:SnapDotNet,代码行数:25,代码来源:IsolatedStorage.cs

示例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;
				}
			}
		}
开发者ID:kungfubozo,项目名称:UnityPorting,代码行数:27,代码来源:TcpClient.cs

示例9: SendAsync

 public async Task SendAsync(string text)
 {
     var dataWriteObject = new DataWriter(_serialPort.OutputStream);
     dataWriteObject.WriteString(text);
     var task = dataWriteObject.StoreAsync().AsTask(_cancellation.Token);
     await task;
     dataWriteObject.DetachStream();
 }
开发者ID:Smartasses,项目名称:IoT-CloudBrew,代码行数:8,代码来源:SerialCommunication.cs

示例10: WriteLine

		public static async Task WriteLine(this IOutputStream outputStream, string line)
		{
			using (var dataWriter = new DataWriter(outputStream))
			{
				dataWriter.WriteString(line);
				await dataWriter.StoreAsync();
				dataWriter.DetachStream();
			}
		}
开发者ID:ababilone,项目名称:maxmanager,代码行数:9,代码来源:StreamUtils.cs

示例11: InitStreamInfo

        async void InitStreamInfo()
        {
            _stream = new InMemoryRandomAccessStream();

            DataWriter writer = new DataWriter(_stream);
            writer.WriteString(_jsonValue);

            var data = await writer.StoreAsync();
            writer.DetachStream();
        }
开发者ID:brookshi,项目名称:XPHttp,代码行数:10,代码来源:HttpJsonContent.cs

示例12: SendAsync

 private async Task<bool> SendAsync(string data, string ok = "", string err = "")
 {
     if (serialPort == null)
     {
         if (!await Open())
             return false;
     }
     try
     {
         using (var writer = new DataWriter(serialPort.OutputStream))
         {
             writer.WriteString(data);
             await writer.StoreAsync();
             writer.DetachStream();
         }
     }
     catch (OperationCanceledException ex)
     {
         return false;
     }
     catch (Exception ex)
     {
         return false;
     }
     try
     {
         var buffer = string.Empty;
         using (var reader = new DataReader(serialPort.InputStream))
         {
             reader.InputStreamOptions = InputStreamOptions.ReadAhead;
             if (await reader.LoadAsync(1024) > 0)
                 buffer = reader.ReadString(reader.UnconsumedBufferLength);
             reader.DetachStream();
         }
         if (!string.IsNullOrEmpty(ok) && buffer.Contains(ok))
         {
             return true;
         }
         else if (!string.IsNullOrEmpty(err) && buffer.Contains(err))
         {
             return false;
         }
     }
     catch (OperationCanceledException ex)
     {
         return false;
     }
     catch (Exception ex)
     {
         return false;
     }
     return false;
 }
开发者ID:danvy,项目名称:iot-toolkit,代码行数:53,代码来源:RPISigfox.cs

示例13: Send

 async Task Send(FayeObject o) {
     if (o is FayeRequest) 
         (o as FayeRequest).ClientID = ClientID;
     using (var writer = new DataWriter(_socket.OutputStream)) {
         writer.UnicodeEncoding = UnicodeEncoding.Utf8;
         var stringd = await Helpers.SerializeAsync(o);
         writer.WriteString(stringd);
         await writer.StoreAsync();
         await writer.FlushAsync();
         writer.DetachStream();
     }
 }
开发者ID:Connorcpu,项目名称:MetroFayeClient,代码行数:12,代码来源:FayeConnector_Messages.cs

示例14: Run

 public async void Run(IBackgroundTaskInstance taskInstance)
 {
     var deferral = taskInstance.GetDeferral();
     try
     {
         var details = taskInstance.TriggerDetails as SocketActivityTriggerDetails;
         var socketInformation = details.SocketInformation;
         switch (details.Reason)
         {
             case SocketActivityTriggerReason.SocketActivity:
                 var socket = socketInformation.StreamSocket;
                 DataReader reader = new DataReader(socket.InputStream);
                 reader.InputStreamOptions = InputStreamOptions.Partial;
                 await reader.LoadAsync(250);
                 var dataString = reader.ReadString(reader.UnconsumedBufferLength);
                 ShowToast(dataString);
                 socket.TransferOwnership(socketInformation.Id);
                 break;
             case SocketActivityTriggerReason.KeepAliveTimerExpired:
                 socket = socketInformation.StreamSocket;
                 DataWriter writer = new DataWriter(socket.OutputStream);
                 writer.WriteBytes(Encoding.UTF8.GetBytes("Keep alive"));
                 await writer.StoreAsync();
                 writer.DetachStream();
                 writer.Dispose();
                 socket.TransferOwnership(socketInformation.Id);
                 break;
             case SocketActivityTriggerReason.SocketClosed:
                 socket = new StreamSocket();
                 socket.EnableTransferOwnership(taskInstance.Task.TaskId, SocketActivityConnectedStandbyAction.Wake);
                 if (ApplicationData.Current.LocalSettings.Values["hostname"] == null)
                 {
                     break;
                 }
                 var hostname = (String)ApplicationData.Current.LocalSettings.Values["hostname"];
                 var port = (String)ApplicationData.Current.LocalSettings.Values["port"];
                 await socket.ConnectAsync(new HostName(hostname), port);
                 socket.TransferOwnership(socketId);
                 break;
             default:
                 break;
         }
         deferral.Complete();
     }
     catch (Exception exception)
     {
         ShowToast(exception.Message);
         deferral.Complete();
     }
 }
开发者ID:C-C-D-I,项目名称:Windows-universal-samples,代码行数:50,代码来源:SocketActivityTask.cs

示例15: SendButton_Click

 private async void SendButton_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         DataWriter writer = new DataWriter(connectedSocket.OutputStream);
         writer.WriteBytes(Encoding.UTF8.GetBytes(SendMessageTextBox.Text));
         await writer.StoreAsync();
         writer.DetachStream();
         writer.Dispose();
     }
     catch(Exception exception)
     {
         rootPage.NotifyUser(exception.Message, NotifyType.ErrorMessage);
     }
 }
开发者ID:t-angma,项目名称:Windows-universal-samples,代码行数:15,代码来源:scenario1_send.xaml.cs


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