Get() public method

Get a dictionary for a session
public Get ( SessionID sessionID ) : Dictionary
sessionID SessionID the ID of the session
return Dictionary
コード例 #1
0
ファイル: ATRunner.cs プロジェクト: RemiGaudin/quickfixn
        static void Main(string[] args)
        {
            if (args.Length != 1)
            {
                System.Console.WriteLine("usage: AcceptanceTest CONFIG_FILENAME");
                System.Environment.Exit(2);
            }

            FileLog debugLog = new FileLog("log", new SessionID("AT", "Application", "Debug")); 
            ThreadedSocketAcceptor acceptor = null;
            try
            {
                ATApplication testApp = new ATApplication(debugLog);
                testApp.StopMeEvent += new System.Action(delegate() { _stopMe = true; });
                
                SessionSettings settings = new SessionSettings(args[0]);
                IMessageStoreFactory storeFactory = new FileStoreFactory(settings);
                ILogFactory logFactory = null;
                if (settings.Get().Has("Verbose") && settings.Get().GetBool("Verbose"))
                    logFactory = new FileLogFactory(settings);
                acceptor = new ThreadedSocketAcceptor(testApp, storeFactory, settings, logFactory);

                acceptor.Start();
                while (true)
                {
                    System.Console.WriteLine("o hai "+System.DateTime.Now.ToString());
                    System.Threading.Thread.Sleep(1000);

                    // for tests of logout
                    if (_stopMe)
                    {
                        // this doesn't seem to work
                        // after stop, it doesn't seem to start up again
                        /*
                        acceptor.Stop();
                        Thread.Sleep(5 * 1000);
                        _stopMe = false;
                        acceptor.Start();
                         */
                    }
                }
            }
            catch (System.Exception e)
            {
                debugLog.OnEvent(e.ToString());
            }

            finally
            {
                if(acceptor != null)
                    acceptor.Stop();
            }
            
        }
コード例 #2
0
        public AbstractInitiator(SessionFactory factory, SessionSettings settings)
        {
            settings_ = settings;

            HashSet<SessionID> definedSessions = settings.GetSessions();
            if (0 == definedSessions.Count)
                throw new ConfigError("No sessions defined");

            foreach (SessionID sessionID in definedSessions)
            {
                Dictionary dict = settings.Get(sessionID);
                if ("initiator".Equals(dict.GetString(SessionSettings.CONNECTION_TYPE)))
                {
                    sessionIDs_.Add(sessionID);
                    sessions_[sessionID] = factory.Create(sessionID, dict);
                    SetDisconnected(sessionID);
                }
            }

            if (0 == sessions_.Count)
                throw new ConfigError("No sessions defined for initiator");
        }
コード例 #3
0
        private void CreateSessions(SessionSettings settings, SessionFactory sessionFactory)
        {
            sessionFactory_ = sessionFactory;
            settings_ = settings;
            foreach (SessionID sessionID in settings.GetSessions())
            {
                QuickFix.Dictionary dict = settings.Get(sessionID);
                CreateSession(sessionID, dict);
            }

            if (0 == socketDescriptorForAddress_.Count)
                throw new ConfigError("No acceptor sessions found in SessionSettings.");
        }
コード例 #4
0
        private AcceptorSocketDescriptor GetAcceptorSocketDescriptor(SessionSettings settings, SessionID sessionID)
        {
            QuickFix.Dictionary dict = settings.Get(sessionID);
            int port = System.Convert.ToInt32(dict.GetLong(SessionSettings.SOCKET_ACCEPT_PORT));
            SocketSettings socketSettings = new SocketSettings();

            IPEndPoint socketEndPoint;
            if (dict.Has(SessionSettings.SOCKET_ACCEPT_HOST))
            {
                string host = dict.GetString(SessionSettings.SOCKET_ACCEPT_HOST);
                IPAddress[] addrs = Dns.GetHostAddresses(host);
                socketEndPoint = new IPEndPoint(addrs[0], port);
            }
            else
            {
                socketEndPoint = new IPEndPoint(IPAddress.Any, port);
            }

            if (dict.Has(SessionSettings.SOCKET_NODELAY))
            {
                socketSettings.SocketNodelay = dict.GetBool(SessionSettings.SOCKET_NODELAY);
            }

            AcceptorSocketDescriptor descriptor;
            if (!socketDescriptorForAddress_.TryGetValue(socketEndPoint, out descriptor))
            {
                descriptor = new AcceptorSocketDescriptor(socketEndPoint, socketSettings, dict);
                socketDescriptorForAddress_[socketEndPoint] = descriptor;
            }

            return descriptor;
        }
コード例 #5
0
        private void CreateSessions(SessionSettings settings, SessionFactory sessionFactory)
        {
            foreach (SessionID sessionID in settings.GetSessions())
            {
                QuickFix.Dictionary dict = settings.Get(sessionID);
                string connectionType = dict.GetString(SessionSettings.CONNECTION_TYPE);

                if ("acceptor".Equals(connectionType))
                {
                    AcceptorSocketDescriptor descriptor = GetAcceptorSocketDescriptor(settings, sessionID);
                    Session session = sessionFactory.Create(sessionID, dict);
                    descriptor.AcceptSession(session);
                    sessions_[sessionID] = session;
                }
            }

            if (0 == socketDescriptorForAddress_.Count)
                throw new ConfigError("No acceptor sessions found in SessionSettings.");
        }
コード例 #6
0
        public void Load()
        {
            string configuration = new System.Text.StringBuilder()
                .AppendLine("[DEFAULT]")
                .AppendLine("ConnectionType=initiator")
                .AppendLine("BeginString=FIX.4.0")
                .AppendLine("Value=4")
                .AppendLine("Empty=")
                .AppendLine(partialConfiguration.ToString())
                .ToString();
            SessionSettings settings = new SessionSettings(new System.IO.StringReader(configuration));

            SessionID session1 = new SessionID("FIX.4.2", "ISLD", "TW");
            SessionID session2 = new SessionID("FIX.4.1", "ISLD", "WT");
            SessionID session3 = new SessionID("FIX.4.0", "ARCA", "TW");
            SessionID session4 = new SessionID("FIX.4.0", "ARCA", "WT");
            SessionID session5 = new SessionID("FIX.4.0", "NYSE", "TW", "QUAL1");
            SessionID session6 = new SessionID("FIX.4.0", "NYSE", "TW", "QUAL2");

            Assert.That(settings.Get().GetString( "Empty" ), Is.EqualTo("") );

            Assert.That(settings.Get().GetLong( "Value" ), Is.EqualTo(4) );
            Assert.That(settings.Get(session1).GetLong("Value"), Is.EqualTo(1));
            Assert.That(settings.Get(session2).GetLong("Value"), Is.EqualTo(2));
            Assert.That(settings.Get(session3).GetLong("Value"), Is.EqualTo(3));
            Assert.That(settings.Get(session4).GetLong("Value"), Is.EqualTo(4));
            Assert.That(settings.Get(session5).GetLong("Value"), Is.EqualTo(5));
            Assert.That(settings.Get(session6).GetLong("Value"), Is.EqualTo(6));

            // case insensitivity
            Assert.That(settings.Get().GetLong("value"), Is.EqualTo(4));
            Assert.That(settings.Get(session1).GetLong("value"), Is.EqualTo(1));
            Assert.That(settings.Get(session2).GetLong("value"), Is.EqualTo(2));
            Assert.That(settings.Get(session3).GetLong("value"), Is.EqualTo(3));
            Assert.That(settings.Get(session4).GetLong("value"), Is.EqualTo(4));
            Assert.That(settings.Get(session5).GetLong("value"), Is.EqualTo(5));
            Assert.That(settings.Get(session6).GetLong("value"), Is.EqualTo(6));

            Assert.That(settings.Get().GetLong("VALUE"), Is.EqualTo(4));
            Assert.That(settings.Get(session1).GetLong("VALUE"), Is.EqualTo(1));
            Assert.That(settings.Get(session2).GetLong("VALUE"), Is.EqualTo(2));
            Assert.That(settings.Get(session3).GetLong("VALUE"), Is.EqualTo(3));
            Assert.That(settings.Get(session4).GetLong("VALUE"), Is.EqualTo(4));
            Assert.That(settings.Get(session5).GetLong("VALUE"), Is.EqualTo(5));
            Assert.That(settings.Get(session6).GetLong("VALUE"), Is.EqualTo(6));
        }
コード例 #7
0
        public void testExtendedSettings()
        {
            string settingsString = new System.Text.StringBuilder()
                .AppendLine("[DEFAULT]")
                .AppendLine("ConnectionType=initiator")
                .AppendLine("HeartBtInt=60")
                .AppendLine("[SESSION]")
                .AppendLine("BeginString=FIX.4.2")
                .AppendLine("SenderCompID=Company")
                .AppendLine("SenderSubID=FixedIncome")
                .AppendLine("SenderLocationID=HongKong")
                .AppendLine("TargetCompID=CLIENT1")
                .AppendLine("TargetSubID=HedgeFund")
                .AppendLine("TargetLocationID=NYC")
                .AppendLine("SendRedundantResendRequests=Y")
                .AppendLine("MillisecondsInTimeStamp=Y")
                .AppendLine("EnableLastMsgSeqNumProcessed=Y")
                .AppendLine("MaxMessagesInResendRequest=2500")
                .AppendLine("StartTime=06:00:00")
                .AppendLine("EndTime=05:59:00")
                .ToString();

            SessionSettings settings = new SessionSettings(new System.IO.StringReader(settingsString));

            SessionID id = new SessionID("FIX.4.2", "Company", "FixedIncome", "HongKong", "CLIENT1", "HedgeFund", "NYC");
            Assert.That(settings.Get(id).GetString("HeartBtInt"), Is.EqualTo("60"));
            Assert.That(settings.Get(id).GetString("BeginString"), Is.EqualTo("FIX.4.2"));
            Assert.That(settings.Get(id).GetString("SenderCompID"), Is.EqualTo("Company"));
            Assert.That(settings.Get(id).GetString("SenderSubID"), Is.EqualTo("FixedIncome"));
            Assert.That(settings.Get(id).GetString("SenderLocationID"), Is.EqualTo("HongKong"));
            Assert.That(settings.Get(id).GetString("TargetCompID"), Is.EqualTo("CLIENT1"));
            Assert.That(settings.Get(id).GetString("TargetSubID"), Is.EqualTo("HedgeFund"));
            Assert.That(settings.Get(id).GetString("TargetLocationID"), Is.EqualTo("NYC"));
            Assert.That(settings.Get(id).GetString("SendRedundantResendRequests"), Is.EqualTo("Y"));
            Assert.That(settings.Get(id).GetString("MillisecondsInTimeStamp"), Is.EqualTo("Y"));
            Assert.That(settings.Get(id).GetString("EnableLastMsgSeqNumProcessed"), Is.EqualTo("Y"));
            Assert.That(settings.Get(id).GetString("MaxMessagesInResendRequest"), Is.EqualTo("2500"));
            Assert.That(settings.Get(id).GetString("StartTime"), Is.EqualTo("06:00:00"));
            Assert.That(settings.Get(id).GetString("EndTime"), Is.EqualTo("05:59:00"));
            id = null;
            foreach(SessionID sid in settings.GetSessions())
            {
                id = sid;
                break;
            }
            Assert.NotNull(id);
            Assert.That(id.BeginString, Is.EqualTo("FIX.4.2"));
            Assert.That(id.SenderCompID, Is.EqualTo("Company"));
            Assert.That(id.SenderSubID, Is.EqualTo("FixedIncome"));
            Assert.That(id.SenderLocationID, Is.EqualTo("HongKong"));
            Assert.That(id.TargetCompID, Is.EqualTo("CLIENT1"));
            Assert.That(id.TargetSubID, Is.EqualTo("HedgeFund"));
            Assert.That(id.TargetLocationID, Is.EqualTo("NYC"));
        }
コード例 #8
0
        public void StripSpaces()
        {
            string configuration = new System.Text.StringBuilder()
                    .AppendLine("[ DEFAULT ]")
                    .AppendLine(" ConnectionType = initiator")
                    .AppendLine("  [  SESSION  ]  ")
                    .AppendLine("BeginString=FIX.4.2 ")
                    .AppendLine(" SenderCompID =ISLD")
                    .AppendLine("  TargetCompID  =  TW  ")
                    .AppendLine("  Long  =  123  ")
                    .AppendLine("  Double  =  1.23  ")
                    .AppendLine("  Bool  =  N  ")
                    .ToString();
            SessionSettings settings = new SessionSettings(new System.IO.StringReader(configuration));

            Assert.That(settings.Get().GetString("ConnectionType"), Is.EqualTo("initiator"));

            SessionID session = new SessionID("FIX.4.2", "ISLD", "TW");
            Assert.That(settings.Get(session).GetString("ConnectionType"), Is.EqualTo("initiator"));
            Assert.That(settings.Get(session).GetString("BeginString"), Is.EqualTo("FIX.4.2"));
            Assert.That(settings.Get(session).GetString("SenderCompID"), Is.EqualTo("ISLD"));
            Assert.That(settings.Get(session).GetString("TargetCompID"), Is.EqualTo("TW"));
            Assert.That(settings.Get(session).GetLong("Long"), Is.EqualTo(123));
            Assert.That(settings.Get(session).GetDouble("Double"), Is.EqualTo(1.23));
            Assert.That(settings.Get(session).GetBool("Bool"), Is.False);
        }
コード例 #9
0
        public void CaseInsensitiveSectionName()
        {
            string configuration = @"[dEfAuLt]
ConnectionType=initiator
[sEsSiOn]
BeginString=FIX.4.2
SenderCompID=ISLD
TargetCompID=TW";
            SessionSettings settings = new SessionSettings(new System.IO.StringReader(configuration));

            Assert.That(settings.Get().GetString("ConnectionType"), Is.EqualTo("initiator"));

            SessionID session = new SessionID("FIX.4.2", "ISLD", "TW");
            Assert.That(settings.Get(session).GetString("ConnectionType"), Is.EqualTo("initiator"));
            Assert.That(settings.Get(session).GetString("BeginString"), Is.EqualTo("FIX.4.2"));
        }
コード例 #10
0
        private AcceptorSocketDescriptor GetAcceptorSocketDescriptor(SessionSettings settings, SessionID sessionID)
        {
            QuickFix.Dictionary dict = settings.Get(sessionID);
            int port = System.Convert.ToInt32(dict.GetLong(SessionSettings.SOCKET_ACCEPT_PORT));
            SocketSettings socketSettings = new SocketSettings();

            IPEndPoint socketEndPoint;
            if (dict.Has(SessionSettings.SOCKET_ACCEPT_HOST))
            {
                string host = dict.GetString(SessionSettings.SOCKET_ACCEPT_HOST);
                IPAddress[] addrs = Dns.GetHostAddresses(host);
                socketEndPoint = new IPEndPoint(addrs[0], port);
                // Set hostname (if it is not already configured)
                socketSettings.ServerCommonName = socketSettings.ServerCommonName ?? host;
            }
            else
            {
                socketEndPoint = new IPEndPoint(IPAddress.Any, port);
            }

            socketSettings.Configure(dict);

            AcceptorSocketDescriptor descriptor;
            if (!socketDescriptorForAddress_.TryGetValue(socketEndPoint, out descriptor))
            {
                descriptor = new AcceptorSocketDescriptor(socketEndPoint, socketSettings, dict);
                socketDescriptorForAddress_[socketEndPoint] = descriptor;
            }

            return descriptor;
        }