/// <summary> /// </summary> public void Close() { if (IsClosed) { return; } IsClosed = true; StreamClosed?.Invoke(this, new StreamClosedEventArgs()); }
/// <summary> /// Closes the stream reader. /// </summary> public void Close() { if (IsClosed) { return; } IsClosed = true; _currentCall?.Dispose(); StreamClosed?.Invoke(this, new StreamClosedEventArgs()); }
private void ReceiveLoop(CancellationToken ct) { while (!ct.IsCancellationRequested) { string msg = GetNextMessage(); if (msg == "") { continue; } XmlDocument doc = new XmlDocument(); XmlSchema schema = new XmlSchema(); schema.Namespaces.Add("stream", "http://etherx.jabber.org/streams"); doc.Schemas.Add(schema); //quit if the stream has been closed if (msg.IndexOf("</stream:stream>") != -1) { StreamClosed?.Invoke(); return; } bool wtf = false; // Correct XML errors: stream opening should be the only case in which there is an open tag if (msg.IndexOf("<stream:stream") != -1) { msg += "</stream:stream>"; wtf = true; } else { msg = GetStreamHeader() + msg + "</stream:stream>"; } doc.LoadXml(msg); XmlNodeList nodes = null; if (wtf) { nodes = doc.ChildNodes; } else { nodes = doc.LastChild.ChildNodes; } foreach (XmlNode node in nodes) { NewData?.Invoke(node); if (node.Name.Equals("iq")) { NewIq?.Invoke(node); } } } }
public void CloseStream() { RunScript("net", "stop NvContainerLocalSystem"); StreamClosed?.Invoke(this, EventArgs.Empty); }
/// <summary> /// Reads the bytes from the stream. /// </summary> private async Task Read() { try { while (true) { // Read type int type = await ReadByte(); // Read if the message is associated with an id bool hasId = await ReadBoolean(); byte[] id = null; if (hasId) { // The Id is a 128-bit guid id = await ReadBytesAsync(IdLength); } // Is this a partial reception ? bool isBuffered = await ReadBoolean(); // Read the size of the data int length = await ReadInt(); if (isBuffered) { // If it's a partial packet read the packet info PartialPacket partialPacket = await ReadPartialPacket(length); // todo property control if (!partialPacket.IsEnd) { _partialPacketBuffer.Add(partialPacket); if (_partialPacketBuffer.Count == 0) { _logger.Trace($"Received first packet: {partialPacket.Type}, total size: {partialPacket.TotalDataSize}."); } } else { // This is the last packet // Concat all data _partialPacketBuffer.Add(partialPacket); byte[] allData = ByteArrayHelpers.Combine(_partialPacketBuffer.Select(pp => pp.Data).ToArray()); _logger.Trace($"Received last packet: {_partialPacketBuffer.Count}, total length: {allData.Length}."); // Clear the buffer for the next partial to receive _partialPacketBuffer.Clear(); Message message; if (hasId) { message = new Message { Type = type, HasId = true, Id = id, Length = allData.Length, Payload = allData }; } else { message = new Message { Type = type, HasId = false, Length = allData.Length, Payload = allData }; } FireMessageReceivedEvent(message); } } else { // If it's not a partial packet the next "length" bytes should be // the entire data byte[] packetData = await ReadBytesAsync(length); Message message; if (hasId) { message = new Message { Type = type, HasId = true, Id = id, Length = length, Payload = packetData }; } else { message = new Message { Type = type, HasId = false, Length = length, Payload = packetData }; } FireMessageReceivedEvent(message); } } } catch (PeerDisconnectedException) { StreamClosed?.Invoke(this, EventArgs.Empty); Close(); } catch (Exception e) { if (!IsConnected && e is IOException) { // If the stream fails while the connection is logically closed (call to Close()) // we simply return - the StreamClosed event will no be closed. return; } Close(); StreamClosed?.Invoke(this, EventArgs.Empty); } }
protected void OnStreamClosed(String md5, Int64 length) { StreamClosed?.Invoke(this, new FileSystemBlobStoreWritableStreamClosedEventArgs(md5, length)); }
public void Logout() { // Close stream ! _stream?.Dispose(); StreamClosed?.Invoke(); }
void StreamProcessor_Closed(object sender, EventArgs e) { DebugUtil.Log("StreamClosed. Finish MovieStreamHelper"); Finish(); StreamClosed?.Invoke(sender, e); }
protected void OnStreamClosed() { StreamClosed?.Invoke(this, EventArgs.Empty); }