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