Esempio n. 1
0
        public void InvalidateReputationsFromFiles(IEnumerable <string> files)
        {
            lvLoadedDocuments.Items.Clear();
            lbTotalFiles.Text = TotalFormatter.FormatTotalFiles(0);
            rcGiven.Clear();
            rcReceived.Clear();
            rcDifference.Clear();

            var parsed = files.
                         Select(f => PageParser.Parse(f, PageReadType.FromFile));

            foreach (var page in parsed)
            {
                if (page.Type == TransactionType.Unknown)
                {
                    continue;
                }

                lvLoadedDocuments.Items.Add(page.ToPageViewItem());

                switch (page.Type)
                {
                case TransactionType.Given:
                    rcGiven.AddRange(page.Reputations);
                    break;

                case TransactionType.Received:
                    rcReceived.AddRange(page.Reputations);
                    break;
                }
            }

            rcDifference.AddRange(Differentiator.Differenciate(rcGiven.Reputations, rcReceived.Reputations).ToArray());
            lbTotalFiles.Text = TotalFormatter.FormatTotalFiles(lvLoadedDocuments.Items.Count);
        }
Esempio n. 2
0
		private PooledSocket(Socket socket, SocketPool pool, TotalFormatter formatter)
		{
		    this.formatter = formatter;
			messageStream = new MemoryStream();
			this.socket = socket;
			writeLock = new object();
			this.pool = pool;
			socket.SendTimeout = 1000; //1 seconds :| is it okie?
			socket.NoDelay = true;
			socket.DontFragment = true;
			socket.LingerState.Enabled = false;
			ReadBuffer(4, HEADER);
		}
Esempio n. 3
0
 private PooledSocket(Socket socket, SocketPool pool, TotalFormatter formatter)
 {
     this.formatter             = formatter;
     messageStream              = new MemoryStream();
     this.socket                = socket;
     writeLock                  = new object();
     this.pool                  = pool;
     socket.SendTimeout         = 1000;     //1 seconds :| is it okie?
     socket.NoDelay             = true;
     socket.DontFragment        = true;
     socket.LingerState.Enabled = false;
     ReadBuffer(4, HEADER);
 }
Esempio n. 4
0
 public SocketPool(ServiceContainer container, EndPoint endPoint)
 {
     formatter           = new TotalFormatter(1000);
     container.Pool      = this;
     poolSize            = Int32.Parse(ConfigurationManager.AppSettings["NTS_MIN_POOL_SIZE"]);
     pooledSockets       = new List <PooledSocket>(poolSize);
     this.container      = container;
     endpoint            = endPoint;
     NetworkListener     = new NetworkListner();
     waitingCallback     = new Dictionary <long, WaitCallback>();
     waitingContext      = new Dictionary <long, object>();
     waitingCallbackLock = new ReaderWriterLockSlim();
     waitHandles         = new Dictionary <long, SynchResult>();
     waitHandlesLock     = new ReaderWriterLockSlim();
     pooledSocketsLock   = new ReaderWriterLockSlim();
     Connect();
 }
Esempio n. 5
0
 internal SocketPool(ServiceContainer container, Socket socket)
 {
     formatter           = new TotalFormatter(1000);
     container.Pool      = this;
     connected           = true;
     poolSize            = 1;
     this.container      = container;
     endpoint            = socket.RemoteEndPoint;
     NetworkListener     = new NetworkListner();
     waitingCallback     = new Dictionary <long, WaitCallback>();
     waitingContext      = new Dictionary <long, object>();
     waitingCallbackLock = new ReaderWriterLockSlim();
     waitHandles         = new Dictionary <long, SynchResult>();
     waitHandlesLock     = new ReaderWriterLockSlim();
     pooledSocketsLock   = new ReaderWriterLockSlim();
     pooledSockets       = new List <PooledSocket>(poolSize)
     {
         PooledSocket.CreateNewSocket(socket, this, formatter)
     };
 }
Esempio n. 6
0
 public SocketPool(int poolSize, ServiceContainer owner, string host)
 {
     formatter     = new TotalFormatter(1000);
     owner.Pool    = this;
     this.poolSize = poolSize;
     pooledSockets = new List <PooledSocket>(poolSize);
     container     = owner;
     if (host != null)
     {
         endpoint = GetEndPoint(host);
     }
     else
     {
         throw new ArgumentNullException("Host cannot be null.");
     }
     NetworkListener     = new NetworkListner();
     waitingCallback     = new Dictionary <long, WaitCallback>();
     waitingContext      = new Dictionary <long, object>();
     waitHandles         = new Dictionary <long, SynchResult>();
     waitingCallbackLock = new ReaderWriterLockSlim();
     pooledSocketsLock   = new ReaderWriterLockSlim();
     waitHandlesLock     = new ReaderWriterLockSlim();
     Connect();
 }
 private void InvalidateLabel()
 {
     lbTotal.Text = TotalFormatter.FormatTotalTransaction(_reputations, _type);
 }
Esempio n. 8
0
 public static PooledSocket CreateNewSocket(Socket socket, SocketPool pool, TotalFormatter formatter)
 {
     return(new PooledSocket(socket, pool, formatter));
 }
Esempio n. 9
0
 public static PooledSocket CreateNewSocket(string host, int port, SocketPool pool, TotalFormatter formatter)
 {
     try
     {
         var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
         socket.Connect(host, port);
         return(new PooledSocket(socket, pool, formatter));
     }
     catch
     {
         return(null);
     }
 }
Esempio n. 10
0
		public static PooledSocket CreateNewSocket(Socket socket, SocketPool pool, TotalFormatter formatter)
		{
			return new PooledSocket(socket, pool, formatter);
		}
Esempio n. 11
0
		public static PooledSocket CreateNewSocket(string host, int port, SocketPool pool, TotalFormatter formatter)
		{
			try
			{
				var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
				socket.Connect(host, port);
				return new PooledSocket(socket, pool, formatter);
			}
			catch
			{
				return null;
			}
		}