<commit_before>using System;
using System.Linq;
using System.Collections.Generic;

using CDS.Common;

namespace CDS.Remote
{
	public class CDSRemoteAgent : CDSAgent
	{
		List<SentOp> SentOps = new List<SentOp>();
		//the side which initiated the channel (sends operations to remote agent)
		//parsing responses, sending commands
		public int ChannelID;
		public override void OnReceiveCDSMessage (byte Op, string TgtNode, int OpID, byte[] Body)
		{
			SentOp ToRemove = null;
			//Response to earilier request
			foreach(SentOp Sent in SentOps)
			{
				if (Sent.OpID == OpID) 
				{
					Sent.response = (CDSResponses)Op;
					Sent.Reply = Body;
					Sent.OnReply (Sent);
					ToRemove = Sent;
					break;
				}
			}
			SentOps.Remove (ToRemove);
		}
		public SentOp SendRequest(CDSOperations Op, string TgtNode, byte[] Body)
		{
			SentOp ret = null;
			SendRequest (Op, TgtNode, Body, (SentOp s) => { ret = s; });
			while (ret == null)	System.Threading.Thread.Sleep (10);
			return ret;
		}
		public void SendRequest(CDSOperations Op, string TgtNode, byte[] Body, Reply OnReply)
		{
			int OpID = 0;
			foreach (SentOp o in SentOps)
				OpID = Math.Max (OpID, o.OpID + 1);
			SentOp NewSentOp = new SentOp(){ OpID = OpID };
			NewSentOp.OnReply += OnReply;
			SentOps.Add (NewSentOp);
			CDSHandler.SendMessage (ChannelID, (byte)Op, TgtNode, OpID, Body);
		}
		public RemoteNode Root
		{
			get
			{
				return new RemoteNode (this, "");
			}
		}
	}
}<commit_msg>added checks to see if connection is closed in RemoteAgent<commit_after>using System;
using System.Linq;
using System.Collections.Generic;

using CDS.Common;

namespace CDS.Remote
{
	public class CDSRemoteAgent : CDSAgent
	{
		List<SentOp> SentOps = new List<SentOp>();
		//the side which initiated the channel (sends operations to remote agent)
		//parsing responses, sending commands
		public int ChannelID;
		public override void OnReceiveCDSMessage (byte Op, string TgtNode, int OpID, byte[] Body)
		{
			SentOp ToRemove = null;
			//Response to earilier request
			foreach(SentOp Sent in SentOps)
			{
				if (Sent.OpID == OpID) 
				{
					Sent.response = (CDSResponses)Op;
					Sent.Reply = Body;
					Sent.OnReply (Sent);
					ToRemove = Sent;
					break;
				}
			}
			SentOps.Remove (ToRemove);
		}
		public SentOp SendRequest(CDSOperations Op, string TgtNode, byte[] Body)
		{
            if (CDSHandler.Alive)
            {
                SentOp ret = null;
                SendRequest(Op, TgtNode, Body, (SentOp s) => { ret = s; });
                while (ret == null) System.Threading.Thread.Sleep(10);
                return ret;
            }
            else 
            {
                throw new Exception("connection closed");
            }
		}
		public void SendRequest(CDSOperations Op, string TgtNode, byte[] Body, Reply OnReply)
		{
            if (CDSHandler.Alive)
            {
                int OpID = 0;
                foreach (SentOp o in SentOps)
                    OpID = Math.Max(OpID, o.OpID + 1);
                SentOp NewSentOp = new SentOp() { OpID = OpID };
                NewSentOp.OnReply += OnReply;
                SentOps.Add(NewSentOp);
                CDSHandler.SendMessage(ChannelID, (byte)Op, TgtNode, OpID, Body);
            }
            else
            {
                throw new Exception("connection closed");
            }
		}
		public RemoteNode Root
		{
			get
			{
				return new RemoteNode (this, "");
			}
		}
	}
}
{'fraction_non_alphanumeric': 0.1037079953650058, 'fraction_numerical': 0.002317497103128621, 'mean_word_length': 2.291706387035272, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5259663', 'n_tokens_mistral': 1285, 'n_tokens_neox': 1101, 'n_words': 310}