/*****************************************************************************
    *  Function    : createSession
    *  Description : This function creates a session object and opens the market
    *               bar service.  Returns false on failure of either.
    *  Arguments   : none
    *  Returns     : bool
    *****************************************************************************/
    private bool createSession()
    {
        if (d_session != null)
        {
            d_session.Stop();
        }

        System.Console.WriteLine("Connecting to " + d_sessionOptions.ServerHost +
                                 ":" + d_sessionOptions.ServerPort);
        d_session = new Session(d_sessionOptions, new EventHandler(processEvent));
        if (!d_session.Start())
        {
            System.Console.WriteLine("Failed to start session");
            return(false);
        }
        System.Console.WriteLine("Connected successfully\n");

        if (!d_session.OpenService("//blp/mktbar"))
        {
            System.Console.WriteLine("Failed to open service //blp/mktbar");
            d_session.Stop();
            return(false);
        }

        System.Console.WriteLine("Subscribing...");
        d_session.Subscribe(d_subscriptions);

        return(true);
    }
Exemple #2
0
    /*****************************************************************************
    *  Function    : run
    *  Description : Performs the main functions of the program
    *  Arguments   : string array
    *  Returns     : void
    *****************************************************************************/
    private void run(string[] args)
    {
        try
        {
            if (!parseCommandLine(args))
            {
                return;
            }
            if (!createSession())
            {
                System.Console.WriteLine("Fail to open session");
                return;
            }

            // Authenticate user using Generate Token Request
            if (!GenerateToken(out d_token))
            {
                return;
            }

            //Authorization : pass Token into authorization request. Returns User/Application Identity containing entitlements info.
            if (!IsBPipeAuthorized(d_token, out d_identity))
            {
                return;
            }

            // check if this is a BPS seat type before subscribing to Market Bar data
            if (d_identity.SeatType == SeatType.BPS)
            {
                // subscribe with Identity
                d_session.Subscribe(d_subscriptions, d_identity);

                // wait for enter key to exit application
                System.Console.Read();
            }

            d_session.Stop();
            System.Console.WriteLine("Exiting.");
        }
        catch (Exception ex)
        {
            System.Console.WriteLine("Exception: " + ex.Message);
        }
    }