コード例 #1
0
        protected override IConnectFuture Connect(Int32 port, IoHandler handler)
        {
            IoConnector connector = new LoopbackConnector();

            connector.Handler = handler;
            return(connector.Connect(new LoopbackEndPoint(port)));
        }
コード例 #2
0
        internal void BeginConnect(IoHandler ioHandler)
        {
            if (mTcp != null)
            {
                ForceDisconnect();
            }
            IPAddress[] address = Dns.GetHostAddresses(ip);
            if (address[0].AddressFamily == AddressFamily.InterNetworkV6)
            {
                mTcp = new TcpClient(AddressFamily.InterNetworkV6);
            }
            else
            {
                mTcp = new TcpClient(AddressFamily.InterNetwork);
            }
            IPAddress ipAddr = null;

            if (!IPAddress.TryParse(ip, out ipAddr))
            {
                IPHostEntry entry = Dns.GetHostEntry(ip);
                if (entry.AddressList.Length > 0)
                {
                    ipAddr = entry.AddressList[0];
                }
            }
            if (ipAddr == null)
            {
                throw new Exception("IP Address error.");
            }
            Object[] args = new Object[2];
            args[0] = ioHandler;
            args[1] = mTcp;
            mTcp.BeginConnect(ipAddr, port, new AsyncCallback(ConnectCallback), args);
        }
コード例 #3
0
        public void Initialise(IoHandler ioHandler, string prefix)
        {
            ProxyInstance = ProxyGenerator.CreateInterfaceProxyWithoutTarget(ResultBaseType,
                                                                             new ConfigurationInterceptor(ResultBaseType, ioHandler, prefix));

            IsInitialised = true;
        }
コード例 #4
0
        public override Genome Start()
        {
            int    cursorPosition = Console.CursorTop;
            int    i         = 0;
            int    lastFound = 0;
            Genome lastBest  = new Genome(null);

            RandomPopulation();
            Console.Write(i + " iteration. Current best: ");
            Program.PrintParameters(BestGenome.Genes);
            Console.Write("with fitness: " + BestGenome.Fitness.ToString("G10"));
            while (BestGenome.Fitness > Settings.MinError && lastFound < Settings.MaxNoChange && i++ < Settings.MaxIter)
            {
                lastBest.Copy(BestGenome);
                _tempPopulation[0].Copy(BestGenome);
                double unused = CalculateFitness();
                Parallel.For(1, Settings.PopulationSize, SingleThread);
                SwapBuffers();
                DeterminePopulationFitness();
                if (!(BestGenome.Fitness < lastBest.Fitness))
                {
                    continue;
                }
                lastFound = i;
                IoHandler.ClearCurrentConsoleLine(cursorPosition);
                Console.Write(i + " iteration. Current best: ");
                Program.PrintParameters(BestGenome.Genes);
                Console.Write("with fitness: " + BestGenome.Fitness.ToString("G10"));
            }
            return(BestGenome);
        }
コード例 #5
0
ファイル: Gui.cs プロジェクト: Bangsadrengur/Teikniforrit
    // Constructor
    public Gui()
    {
        Application.Init();

        ioh = new IoHandler();
        win = new Window("Drawing lines");
        darea = new  DrawingArea();
        painter = new DrawShape(DrawLine);
        listenOnMouse = false; // Við hlustum ekki á mús við núllstöðu.

        // Aukum viðburðasett teikniborðs með ,möskum'.
        darea.AddEvents(
                (int)Gdk.EventMask.PointerMotionMask
                | (int)Gdk.EventMask.ButtonPressMask
                | (int)Gdk.EventMask.ButtonReleaseMask);

        // Úthlutum virkni á viðburði.
        win.Hidden += delegate {Application.Quit();};
        win.KeyPressEvent += onKeyboardPressed;
        darea.ExposeEvent += onDrawingAreaExposed;
        darea.ButtonPressEvent += onMouseClicked;
        darea.ButtonReleaseEvent += onMouseReleased;
        darea.MotionNotifyEvent += onMouseMotion;

        // Grunnstillum stærð glugga.
        win.SetDefaultSize(500,500);

        // Lokasamantekt til að virkja glugga.
        win.Add(darea);
        win.ShowAll();
        Application.Run();
    }
コード例 #6
0
        public override Genome Start()
        {
            int    cursorPosition = Console.CursorTop;
            int    i           = 0;
            int    lastFound   = 0;
            int    howManyDies = (int)(Settings.Mortality * Settings.PopulationSize);
            Genome lastBest    = new Genome(null);

            RandomPopulation();
            Console.Write(i + " iteration. Current best: ");
            Program.PrintParameters(BestGenome.Genes);
            Console.Write("with fitness: " + BestGenome.Fitness.ToString("G10"));

            while (BestGenome.Fitness > Settings.MinError && i++ - lastFound < Settings.MaxNoChange && i < Settings.MaxIter)
            {
                lastBest.Copy(BestGenome);
                for (int j = 0; j < howManyDies; j++)
                {
                    ThreeTournament(j);
                }
                //Parallel.For(0, howManyDies, ThreeTournament);
                DetermineBestFitness();
                if (!(BestGenome.Fitness < lastBest.Fitness))
                {
                    continue;
                }
                lastFound = i;
                IoHandler.ClearCurrentConsoleLine(cursorPosition);
                Console.Write(i + " iteration. Current best: ");
                Program.PrintParameters(BestGenome.Genes);
                Console.Write("with fitness: " + BestGenome.Fitness.ToString("G10"));
            }
            return(BestGenome);
        }
コード例 #7
0
        private void ConnectCallback(IAsyncResult ar)
        {
            Object[]  args      = (Object[])ar.AsyncState;
            IoHandler ioHandler = (IoHandler)args[0];
            TcpClient mTcp      = (TcpClient)args[1];

            try
            {
                if (mTcp.Connected == true)
                {
                    mTcp.EndConnect(ar);
                    mTcp.Client.NoDelay     = true;
                    mTcp.Client.LingerState = new LingerOption(true, 0);
                    Session session = new Session(this);
                    session.IoHandler = ioHandler;
                    ioHandler.ConnectReturn(session);
                }
                else
                {
                    ioHandler.ConnectReturn(null);
                }
            }
            catch (Exception e)
            {
                logReport.OnWarningReport("ConnectCallback fail:" + e.StackTrace);
                ioHandler.ConnectReturn(null);
            }
        }
コード例 #8
0
        protected override IConnectFuture Connect(Int32 port, IoHandler handler)
        {
            IoConnector connector = new AsyncSocketConnector();

            connector.Handler = handler;
            return(connector.Connect(new IPEndPoint(IPAddress.Loopback, port)));
        }
コード例 #9
0
        public void InitialiseAt(int index, IoHandler ioHandler, string prefix)
        {
            object instance = ProxyGenerator.CreateInterfaceProxyWithoutTarget(ResultBaseType,
                                                                               new InterfaceInterceptor(ResultBaseType, ioHandler, prefix));

            _indexToProxyInstance[index] = instance;
        }
コード例 #10
0
        /// <summary>
        /// Creates an instance of the configuration interface
        /// </summary>
        /// <returns></returns>
        public T Build()
        {
            var handler = new IoHandler(_stores, _cacheInterval);

            T instance = _generator.CreateInterfaceProxyWithoutTarget <T>(new ConfigurationInterceptor <T>(handler));

            return(instance);
        }
コード例 #11
0
        public override void Fire()
        {
            IoHandler ioHandler = session.IoHandler;

            if (ioHandler != null)
            {
                ioHandler.Closed(session);
            }
        }
コード例 #12
0
        /// <summary>
        /// Creates an instance of the configuration interface
        /// </summary>
        /// <returns></returns>
        public T Build()
        {
            var valueHandler = new ValueHandler(_customParsers);
            var ioHandler    = new IoHandler(_stores, valueHandler, _cacheInterval);

            T instance = _generator.CreateInterfaceProxyWithoutTarget <T>(new InterfaceInterceptor(typeof(T), ioHandler));

            return(instance);
        }
コード例 #13
0
ファイル: TimeOutEvent.cs プロジェクト: Pasdedeux/LTool
        public override void Fire()
        {
            IoHandler ioHandler = session.IoHandler;

            if (ioHandler != null)
            {
                ioHandler.OnTimeOut(session, msg);
            }
        }
コード例 #14
0
ファイル: SendTimeOutFilter.cs プロジェクト: Pasdedeux/Moba
        private void TimeOutProc(Msg msg, params Object[] args)
        {
            Session   session   = args[0] as Session;
            IoHandler ioHandler = session.IoHandler;

            if (ioHandler != null)
            {
                ioHandler.Trigger(new RevEvent(session, msg));
            }
            logReport.OnWarningReport("msg:" + msg.Cmd + " is timeout,runtime:" + session.cmdDelegate.Runtime);
        }
コード例 #15
0
ファイル: BrokenEvent.cs プロジェクト: Pasdedeux/LTool
        public override void Fire()
        {
            acceptor.OnBroken(acceptor, session);
            IoHandler ioHandler = session.IoHandler;

            if (ioHandler != null)
            {
                ioHandler.Close(session);
            }
            logReport.OnWarningReport("connect is broken,notic to acceptor,sessionid:" + session.Id);
        }
コード例 #16
0
ファイル: LoopbackSession.cs プロジェクト: xlg210/Mina.NET
 /// <summary>
 /// Constructor for client-side session.
 /// </summary>
 public LoopbackSession(IoService service, LoopbackEndPoint localEP,
                        IoHandler handler, LoopbackPipe remoteEntry)
     : base(service)
 {
     Config                = new DefaultLoopbackSessionConfig();
     _lock                 = new Byte[0];
     _localEP              = localEP;
     _remoteEP             = remoteEntry.Endpoint;
     _filterChain          = new LoopbackFilterChain(this);
     _receivedMessageQueue = new ConcurrentQueue <Object>();
     _remoteSession        = new LoopbackSession(this, remoteEntry);
 }
コード例 #17
0
ファイル: LoopbackSession.cs プロジェクト: zhangf911/Mina.NET
 /// <summary>
 /// Constructor for client-side session.
 /// </summary>
 public LoopbackSession(IoService service, LoopbackEndPoint localEP,
     IoHandler handler, LoopbackPipe remoteEntry)
     : base(service)
 {
     Config = new DefaultLoopbackSessionConfig();
     _lock = new Byte[0];
     _localEP = localEP;
     _remoteEP = remoteEntry.Endpoint;
     _filterChain = new LoopbackFilterChain(this);
     _receivedMessageQueue = new ConcurrentQueue<Object>();
     _remoteSession = new LoopbackSession(this, remoteEntry);
 }
コード例 #18
0
 private void CloseBrokerConnection()
 {
     if (_ioHandler != null)
     {
         _ioHandler.Dispose();
         _ioHandler = null;
     }
     if (_connector != null)
     {
         _connector.Dispose();
         _connector = null;
     }
 }
コード例 #19
0
ファイル: AbstractIoSession.cs プロジェクト: xlg210/Mina.NET
        /// <summary>
        /// </summary>
        protected AbstractIoSession(IoService service)
        {
            _service = service;
            _handler = service.Handler;

            _creationTime = DateTime.Now;
            _lastThroughputCalculationTime = _creationTime;
            _lastReadTime = _lastWriteTime = _creationTime;

            _id = Interlocked.Increment(ref idGenerator);

            _closeFuture           = new DefaultCloseFuture(this);
            _closeFuture.Complete += ResetCounter;
        }
コード例 #20
0
      /// <summary>
      /// Connect to the specified broker
      /// </summary>
      /// <param name="broker">The broker to connect to</param>
      /// <param name="connection">The AMQ connection</param>
      public void Connect(IBrokerInfo broker, AMQConnection connection)
      {
         _stopEvent = new ManualResetEvent(false);
         _protocolListener = connection.ProtocolListener;

         _ioHandler = MakeBrokerConnection(broker, connection);
         // todo: get default read size from config!

         IProtocolDecoderOutput decoderOutput =
            new ProtocolDecoderOutput(_protocolListener);
         _amqpChannel = 
            new AmqpChannel(new ByteChannel(_ioHandler), decoderOutput);

         // post an initial async read
         _amqpChannel.BeginRead(new AsyncCallback(OnAsyncReadDone), this);
      }
コード例 #21
0
        /// <summary>
        /// Connect to the specified broker
        /// </summary>
        /// <param name="broker">The broker to connect to</param>
        /// <param name="connection">The AMQ connection</param>
        public void Connect(IBrokerInfo broker, AMQConnection connection)
        {
            _stopEvent        = new ManualResetEvent(false);
            _protocolListener = connection.ProtocolListener;

            _ioHandler = MakeBrokerConnection(broker, connection);
            // todo: get default read size from config!

            IProtocolDecoderOutput decoderOutput =
                new ProtocolDecoderOutput(_protocolListener);

            _amqpChannel =
                new AmqpChannel(new ByteChannel(_ioHandler), decoderOutput);

            // post an initial async read
            _amqpChannel.BeginRead(new AsyncCallback(OnAsyncReadDone), this);
        }
コード例 #22
0
        private static void Solve(string[] args)
        {
            IIoHandler inputManager = new IoHandler();
            var        data         = inputManager.GetParameters(args);
            IParser    parser       = new Parser(data);
            Instance   instance     = parser.ParseData();

            if (data.ExecuteAlgorithm)
            {
                GaSettings settings  = parser.ParseSettings();
                IAlgorithm algorithm = new Algorithm(instance, data.Time, settings);
                Solution   solution  = algorithm.Solve(true);
                parser.FormatAndSaveResult(solution);
            }
            else
            {
                ConsoleHandler.CheckResources(instance);
            }
        }
コード例 #23
0
        static Genome Start(string[] args)
        {
            InputData inputData = IoHandler.GetParameters(args);

            FileHandler.ParseLines(inputData.FileName, out float[][] inputParams, out float[] desiredOutput);
            Ga algorithm = null;

            switch (inputData.Type)
            {
            case AlgorithmType.Generation:
                algorithm = new GenerationGa(inputParams, desiredOutput, inputData);
                break;

            case AlgorithmType.Elimination:
                algorithm = new EliminationGa(inputParams, desiredOutput, inputData);
                break;
            }
            Genome bestSolution = algorithm?.Start();

            return(bestSolution);
        }
コード例 #24
0
 internal static KclProcess Create(IRecordProcessor recordProcessor, IoHandler ioHandler)
 {
     return new DefaultKclProcess(recordProcessor, ioHandler);
 }
コード例 #25
0
 public WSProtocolCodec(IoHandler ioHandler, ISocketClient socketClient)
 {
     this.ioHandler    = ioHandler;
     this.socketClient = socketClient;
 }
コード例 #26
0
ファイル: Connector.cs プロジェクト: dongzhiqiang/Jumper
 //设置上层处理的回调
 public void setHandler(IoHandler handler)
 {
     m_handle = handler;
 }
コード例 #27
0
ファイル: DummySession.cs プロジェクト: xlg210/Mina.NET
 /// <summary>
 /// </summary>
 public void SetHandler(IoHandler handler)
 {
     _handler = handler;
 }
コード例 #28
0
 protected abstract IConnectFuture Connect(Int32 port, IoHandler handler);
コード例 #29
0
 protected abstract IConnectFuture Connect(Int32 port, IoHandler handler);
コード例 #30
0
ファイル: AbstractIoService.cs プロジェクト: wxjwz/Mina.NET
 /// <summary>
 /// </summary>
 protected AbstractIoService(IoSessionConfig sessionConfig)
 {
     _sessionConfig = sessionConfig;
     _handler       = new InnerHandler(this);
     _stats         = new IoServiceStatistics(this);
 }
コード例 #31
0
 internal static KclProcess Create(IShardRecordProcessor recordProcessor, IoHandler ioHandler)
 {
     return(new DefaultKclProcess(recordProcessor, ioHandler));
 }
コード例 #32
0
 public Repl(IScriptEngine scriptEngine, IoHandler ioHandler)
 {
     this.scriptEngine = scriptEngine;
     this.ioHandler    = ioHandler;
 }
コード例 #33
0
ファイル: LoopbackPipe.cs プロジェクト: zhangf911/Mina.NET
 public LoopbackPipe(LoopbackAcceptor acceptor, LoopbackEndPoint endpoint, IoHandler handler)
 {
     _acceptor = acceptor;
     _endpoint = endpoint;
     _handler = handler;
 }
コード例 #34
0
 /// <summary>
 /// 2
 /// </summary>
 /// <param name="handler"></param>
 public void setHandler(IoHandler handler)
 {
     this._handler = handler;
 }
コード例 #35
0
 private void CloseBrokerConnection()
 {
    if ( _ioHandler != null )
    {
       _ioHandler.Dispose();
       _ioHandler = null;
    }
    if ( _connector != null )
    {
       _connector.Dispose();
       _connector = null;
    }
 }
コード例 #36
0
 /// <summary>
 /// 2
 /// </summary>
 /// <param name="handler"></param>        
 public void setHandler(IoHandler handler)
 {
     this._handler = handler;
 }
コード例 #37
0
 protected override IConnectFuture Connect(Int32 port, IoHandler handler)
 {
     IoConnector connector = new LoopbackConnector();
     connector.Handler = handler;
     return connector.Connect(new LoopbackEndPoint(port));
 }
コード例 #38
0
 protected override IConnectFuture Connect(Int32 port, IoHandler handler)
 {
     IoConnector connector = new AsyncDatagramConnector();
     connector.Handler = handler;
     return connector.Connect(new IPEndPoint(IPAddress.Loopback, port));
 }
コード例 #39
0
ファイル: ProtocolCodec.cs プロジェクト: ly774508966/GTLib
 /// <summary>
 ///
 /// </summary>
 /// <param name="ioHandler"></param>
 /// <param name="bitSwarm"></param>
 public ProtocolCodec(IoHandler ioHandler, BitSwarmClient bitSwarm)
 {
     this.ioHandler = ioHandler;
     this.log       = bitSwarm.Log;
     this.bitSwarm  = bitSwarm;
 }
コード例 #40
0
ファイル: Repl.cs プロジェクト: jthelin/SparkCLR
 public Repl(IScriptEngine scriptEngine, IoHandler ioHandler)
 {
     this.scriptEngine = scriptEngine;
     this.ioHandler = ioHandler;
 }
コード例 #41
0
 public SFSProtocolCodec(IoHandler ioHandler, ISocketClient bitSwarm)
 {
     this.ioHandler = ioHandler;
     log            = bitSwarm.Log;
     this.bitSwarm  = bitSwarm;
 }