public static void Run([TimerTrigger("0 0 18 * * *")] TimerInfo myTimer, ILogger log)
        {
            var str        = Environment.GetEnvironmentVariable("bloombergsql");
            var securities = new List <SecurityModel>();

            using (SqlConnection conn = new SqlConnection(str))
            {
                conn.Open();
                log.LogInformation("connection success");
                StringBuilder sb = new StringBuilder();
                sb.Append("SELECT * ");
                sb.Append("FROM [dbo].[Securities];");
                String sql = sb.ToString();
                log.LogInformation("query string creation success");

                using (SqlCommand cmd = new SqlCommand(sql, conn))
                {
                    using (SqlDataReader reader = cmd.ExecuteReader())
                    {
                        log.LogInformation("reader success");
                        while (reader.Read())
                        {
                            var security = new SecurityModel(reader.GetInt32(0), reader.GetString(1));
                            securities.Add(security);
                        }
                    }
                }
            }

            BloombergNormalization.getBloombergData(securities, log);
        }
        private static void getBloombergData(List <SecurityModel> securities, ILogger log)
        {
            SessionOptions sessionOptions = new SessionOptions();

            sessionOptions.ServerHost = "localhost";
            sessionOptions.ServerPort = 8194;

            Session session = new Session(sessionOptions);

            if (session.Start() && session.OpenService("//blp/refdata"))
            {
                Service refDataSvc = session.GetService("//blp/refdata");
                if (refDataSvc == null)
                {
                    log.LogInformation("Cannot get service");
                }
                else
                {
                    CorrelationID requestID = new CorrelationID(1);
                    Request       request   = refDataSvc.CreateRequest("ReferenceDataRequest");

                    foreach (SecurityModel security in securities)
                    {
                        log.LogInformation("appending " + security.Name);
                        request.Append("securities", security.Name);
                    }

                    { //append regular fields
                        //include the following simple fields in the result
                        //request.Append("fields", "ZPX_LAST"); //the code treats a field that starts with a "Z" as a bad field
                        request.Append("fields", "PX_LAST");
                        request.Append("fields", "BID");
                        request.Append("fields", "ASK");

                        request.Append("fields", "TICKER");
                        request.Append("fields", "TRADEABLE_DT");  //hard-coded to be treated as a datetime to illustrated datetimes
                        request.Append("fields", "OPT_EXPIRE_DT"); //only stock options have this field

                        request["fields"].AppendValue("TICKER");   //This is another way to append a field
                    }

                    {                                              //append an overridable field
                        //request a field that can be overriden and returns bulk data
                        request.Append("fields", "CHAIN_TICKERS"); //only stocks have this field
                        Element overrides = request["overrides"];

                        //request only puts
                        Element ovrdPutCall = overrides.AppendElement();
                        ovrdPutCall.SetElement("fieldId", "CHAIN_PUT_CALL_TYPE_OVRD");
                        ovrdPutCall.SetElement("value", "P"); //accepts either "C" for calls or "P" for puts

                        //request 5 options in the result
                        Element ovrdNumStrikes = overrides.AppendElement();
                        ovrdNumStrikes.SetElement("fieldId", "CHAIN_POINTS_OVRD");
                        ovrdNumStrikes.SetElement("value", 5); //accepts a positive integer

                        //request options that expire on Dec. 20, 2014
                        Element ovrdDtExps = overrides.AppendElement();
                        ovrdDtExps.SetElement("fieldId", "CHAIN_EXP_DT_OVRD");
                        ovrdDtExps.SetElement("value", "20141220"); //accepts dates in the format yyyyMMdd (this is Dec. 20, 2014)
                    }

                    session.SendRequest(request, requestID);

                    bool continueToLoop = true;
                    while (continueToLoop)
                    {
                        Event eventObj = session.NextEvent();
                        switch (eventObj.Type)
                        {
                        case Event.EventType.RESPONSE:     // final event
                            continueToLoop = false;
                            BloombergNormalization.handleResponseEvent(eventObj, securities, log);
                            break;

                        case Event.EventType.PARTIAL_RESPONSE:
                            BloombergNormalization.handleResponseEvent(eventObj, securities, log);
                            break;

                        default:
                            BloombergNormalization.handleOtherEvent(eventObj, log);
                            break;
                        }
                    }
                }
            }
            else
            {
                log.LogInformation("Cannot connect to server.  Check that the server host is \"localhost\" or \"127.0.0.1\" and that the server port is 8194.");
            }
        }