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


C# DataWriter.FlushAsync方法代码示例

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


在下文中一共展示了DataWriter.FlushAsync方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SendAsync

        public async Task SendAsync(string text)
        {
            try
            {
                // DataWriter to send message to client
                var writer = new DataWriter(_socket.OutputStream);
                //Encrypt message
                byte[] data = Cryptographic.Encrypt(text, "123");

                //Write Lenght message in buffer
                writer.WriteInt32(data.Length);
                //Write message in buffer
                writer.WriteBytes(data);

                //Send buffer
                await writer.StoreAsync();
                //Clear buffer
                await writer.FlushAsync();

            }
            catch (Exception e)
            {
                InvokeOnError(e.Message);
            }
        }
开发者ID:lillo42,项目名称:IoT,代码行数:25,代码来源:ServerTcp.cs

示例2: 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();
                }
            }
        }
开发者ID:tomasmcguinness,项目名称:BeCharming,代码行数:30,代码来源:ShareTargetsManager.cs

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

示例4: 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();
        }
开发者ID:Mordonus,项目名称:MALClient,代码行数:31,代码来源:ImageDownloaderService.cs

示例5: ExecuteDiscoveryTask

		private async Task ExecuteDiscoveryTask()
		{
			int repeatTime = EndpointController.REPEAT_DISCOVERY_TASK / 2;

			while (running)
			{
				Debug.WriteLine("#> [DiscoveryCloudletMulticast]: Started Cloudlet Discovery using Multicast UDP");
				retry = 0;

				DatagramSocket socketSent = null;
				DatagramSocket socketReplay = null;
				try
				{
					socketSent = new DatagramSocket();
					await socketSent.BindEndpointAsync(null, string.Empty);
					socketSent.JoinMulticastGroup(ip);

					socketReplay = new DatagramSocket();
					socketReplay.MessageReceived += SocketOnMessageReceived;
					await socketReplay.BindServiceNameAsync(replyCloudletPort.ToString());

					using (DataWriter writer = new DataWriter(await socketSent.GetOutputStreamAsync(ip, multicastPort.ToString())))
					{
						while (retry < 60 && running)
						{
							writer.WriteString("mpos_cloudlet_req");
							await writer.StoreAsync();
							await writer.FlushAsync();

							await Task.Delay(500);
							retry++;
						}
					}
				}
				catch (IOException e)
				{
					Debug.WriteLine("## [DiscoveryCloudletMulticast]: Any problem with i/o in multicast system!\n" + e.ToString());
				}
				finally
				{
					socketSent.Dispose();
					socketReplay.Dispose();

					socketSent = null;
					socketReplay = null;
				}

				if (running)
				{
					Debug.WriteLine(">> [DiscoveryCloudletMulticast]: Retry Discovery Cloudlet, in " + repeatTime + " ms");
					await Task.Delay(repeatTime);
				}
				else
				{
					Debug.WriteLine("#> [DiscoveryCloudletMulticast]: Finished Discovery Cloudlet");
				}
			}
		}
开发者ID:sergiosilvajr,项目名称:mpos,代码行数:58,代码来源:DiscoveryCloudletMulticast.cs

示例6: SendMagicPacket

        /// <summary>
        /// Attempts to send a magic packet to the desination hostname, on the specified port with the specified MAC address.
        /// </summary>
        /// <param name="destination">Destination hostname or IP address.</param>
        /// <param name="destinationPort">Destination port number.</param>
        /// <param name="targetMac">Destination MAC address. Bytes can be separated by colons, dashes, or nothing.</param>
        /// <returns>True if magic packet is sent successfully, false otherwise.</returns>
        public async Task<bool> SendMagicPacket(Windows.Networking.HostName destination, uint destinationPort, string targetMac)
        {
            try
            {
                DatagramSocket _socket = new DatagramSocket();               

                using (var stream = await _socket.GetOutputStreamAsync(destination, destinationPort.ToString()))
                {
                    //Split on common MAC separators
                    char? splitChar = null;
                    if (targetMac.Contains('-'))
                        splitChar = '-';
                    else if (targetMac.Contains(':'))
                        splitChar = ':';
                    else if (targetMac.Contains(' '))
                        splitChar = ' ';

                    //Turn MAC into array of bytes
                    byte[] macAsArray;
                    if (splitChar != null)
                    {
                        macAsArray = targetMac.Split((char)splitChar)
                            .Select(b => Convert.ToByte(b, 16))
                            .ToArray<byte>();
                    }
                    else
                    {
                        //Jump through MAC-string, reading 2 chars at a time
                        macAsArray = Enumerable.Range(0, targetMac.Length)
                            .Where(x => x % 2 == 0)
                            .Select(x => Convert.ToByte(targetMac.Substring(x, 2), 16)) //16 = hexadecimal
                            .ToArray();
                    }

                    List<byte> magicPacket = new List<byte> { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };

                    //A WoLAN magic packet is just FF FF FF FF FF FF, then the target MAC adress repeated 16 times.
                    for (int i = 0; i < 16; i++)
                    {
                        magicPacket = magicPacket.Concat(macAsArray).ToList();
                    }

                    using (DataWriter writer = new DataWriter(stream))
                    {
                        writer.WriteBytes(magicPacket.ToArray<byte>());
                        await writer.StoreAsync();
                        await writer.FlushAsync();
                        return true;
                    }
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
                return false;
            }
        }       
开发者ID:gh0std4ncer,项目名称:magic-packet-windows,代码行数:64,代码来源:MagicPacketSender.cs

示例7: GetStreamForByteArray

 private static async Task<IInputStream> GetStreamForByteArray(string content2)
 {
     var ras = new InMemoryRandomAccessStream();
     var datawriter = new DataWriter(ras);
     datawriter.WriteString(content2);
     //datawriter.WriteBytes(content2);
     await datawriter.StoreAsync();
     await datawriter.FlushAsync();
     return ras.GetInputStreamAt(0);
 }
开发者ID:startewho,项目名称:CnBetaUWA,代码行数:10,代码来源:WebViewHelper.cs

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

示例9: GetAsync

        /// <summary>
        /// Gets intent and entities from a text string
        /// </summary>
        /// <returns>Unprocessed result from a server</returns>
        public async Task<string> GetAsync()
        {
            return await Task.Run<string>(async () =>
            {
                try
                {
                    var socket = new StreamSocket();

                    var writer = new DataWriter(socket.OutputStream);
                    var reader = new DataReader(socket.InputStream);
                    reader.InputStreamOptions = InputStreamOptions.Partial;

                    StringBuilder stringBuilder = new StringBuilder();
                    stringBuilder.AppendLine(String.Format("GET /message?q={0} HTTP/1.1", HttpUtility.UrlEncode(message)));
                    stringBuilder.AppendLine("Host: api.wit.ai");
                    stringBuilder.AppendLine(String.Format("Authorization: Bearer {0}", accessToken));
                    stringBuilder.AppendLine("");
                    string headers = stringBuilder.ToString();
                    byte[] headersPayload = Encoding.UTF8.GetBytes(headers);

                    await socket.ConnectAsync(new HostName("wit.ai"), "443", SocketProtectionLevel.SslAllowNullEncryption);

                    writer.WriteBytes(headersPayload);

                    WitLog.Log("Sending text...");

                    await writer.StoreAsync();
                    await writer.FlushAsync();

                    var count = await reader.LoadAsync(UInt16.MaxValue);
                    string response = reader.ReadString(count);

                    int bodyStartIndex = response.IndexOf("\r\n\r\n");

                    if (bodyStartIndex != -1)
                    {
                        string body = response.Substring(bodyStartIndex + 4);

                        WitLog.Log(body);

                        return body;
                    }
                    else
                    {
                        return null;
                    }
                }
                catch
                {
                    return null;
                }
            });
        }
开发者ID:carriercomm,项目名称:wit-windowsphone-sdk,代码行数:57,代码来源:WitMessageRequestTask.cs

示例10: 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();
        }
开发者ID:OkayX6,项目名称:BroadcastConsole,代码行数:13,代码来源:TcpConnection.cs

示例11: SaveAsync

        public async Task SaveAsync(string filePath, byte[] content)
        {
            StorageFile file = await GetFileAsync(filePath);

            using (IRandomAccessStream writeStream = await file.OpenAsync(FileAccessMode.ReadWrite))
            {
                using (DataWriter dataWriter = new DataWriter(writeStream))
                {
                    dataWriter.WriteBytes(content);
                    await dataWriter.StoreAsync();
                    await dataWriter.FlushAsync();
                }
            }
        }
开发者ID:stonemonkey,项目名称:WhereAmI,代码行数:14,代码来源:ApplicationFileManager.cs

示例12: ConvertToRandomAccessStream

        private async Task<IRandomAccessStream> ConvertToRandomAccessStream(byte[] bytes)
        {
            var randomAccessStream = new InMemoryRandomAccessStream();
            using (var writer = new DataWriter(randomAccessStream))
            {
                writer.WriteBytes(bytes);
                await writer.StoreAsync();
                await writer.FlushAsync();
                writer.DetachStream();
                writer.Dispose();
            }
            randomAccessStream.Seek(0);

            return randomAccessStream;
        }
开发者ID:Romaxaqaz,项目名称:Onliner,代码行数:15,代码来源:ImageUrlConverter.cs

示例13: DownloadFileAsync

        /// <summary>
        /// Use for small assets
        /// </summary>
        /// <param name="url"></param>
        /// <param name="cancelToken"></param>
        /// <returns></returns>
        public static async Task<IRandomAccessStream> DownloadFileAsync(LibrelioUrl url, CancellationToken cancelToken = default(CancellationToken))
        {
            var stream = new InMemoryRandomAccessStream();

            using(var response = await new HttpClient().GetAsync(url.AbsoluteUrl))
            {
                var buffer = await response.Content.ReadAsStringAsync();
                var dataWriter = new DataWriter(stream.GetOutputStreamAt(0));
                dataWriter.WriteString(buffer);
                await dataWriter.StoreAsync();
                await dataWriter.FlushAsync();
            }

            return stream;
        }
开发者ID:umairsheikh,项目名称:windows8,代码行数:21,代码来源:DownloadManager.cs

示例14: OnResponse

		protected override async void OnResponse(object sender, XmlRpcResponseEventArgs e)
		{
			string fname = string.Format("{0}/{1}-{2:0000}-response-{3}.xml",
			  _directory, DateTime.Now.Ticks, e.RequestNum, e.ProxyID);
			var file = await Directory.CreateFileAsync(fname, CreationCollisionOption.ReplaceExisting);
			using (var str = await file.OpenAsync(FileAccessMode.ReadWrite))
			{
				using (var dw = new DataWriter(str))
				{
					await e.ResponseStream.CopyToAsync(str.AsStreamForWrite());
					await dw.FlushAsync();
					dw.DetachStream();
				}
			}
		}
开发者ID:danielgary,项目名称:xmlrpc-universal,代码行数:15,代码来源:RequestResponseLogger.cs

示例15: SendRawMessage

 async public void SendRawMessage(string message)
 {
     if (!_connected) return;
     var writer = new DataWriter(_clientSocket.OutputStream);
     byte[] header = BitConverter.GetBytes(message.Length);
     if (BitConverter.IsLittleEndian)
         Array.Reverse(header);
     writer.WriteBytes(header);
     writer.WriteString(message);
     await writer.StoreAsync();
     await writer.FlushAsync();
     System.Diagnostics.Debug.WriteLine("Sent : header = " + BitConverter.ToString(header) + " | body = " + message);
     writer.DetachStream();
     //_clientSocket.Dispose();
     //_connected = false;
 }
开发者ID:patel-pragnesh,项目名称:PowerMonitor,代码行数:16,代码来源:Socket.cs


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