public string GetNote()
        {
            string s = "";

            if (Type == NoticeType.UploadDone)
            {
                s = string.Format("{0}: {1}", FullPath, Note);
            }
            if (Type == NoticeType.AddFileDone)
            {
                s = string.Format("{0}: {1} files added.", FullPath, JobDone);
            }
            if (Type == NoticeType.UploadException || Type == NoticeType.Exception)
            {
                s = string.Format("{0}: {1}", FullPath, Note);
            }

            if (Type == NoticeType.Upload)
            {
                s = string.Format("{0}: {1} {2}/{3} - {4}%", FullPath, Note, JobDone, JobTotal, Percentage);
            }

            if (Type == NoticeType.AddFile)
            {
                s = string.Format("{0}: {1} files", FullPath, JobDone);
            }

            if (Type == NoticeType.DownloadDone)
            {
                s = string.Format("{0}: {1}", FullPath, Note);
            }

            s = Datetime.ToString() + " " + s;
            return(s);
        }
Ejemplo n.º 2
0
 public new string ToString()
 {
     var datetime = Datetime.ToString("yyyy-MM-dd HH:mm:ss.fff");
     return $"{datetime} {Type,-12}{Text}";
 }
Ejemplo n.º 3
0
 public string Ident(bool utc)
 {
     return(StarSystem + ":" + StationName + " on " + ((utc) ? Datetime.ToString() : Datetime.ToLocalTime().ToString()));
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Get Message to string
 /// </summary>
 /// <returns></returns>
 public new string ToString()
 {
     return(string.Format("{0}\t {1}\n", Datetime.ToString(CultureInfo.InvariantCulture), Text));
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Get Message to string
 /// </summary>
 /// <returns></returns>
 public new string ToString()
 {
     return(Datetime.ToString(CultureInfo.InvariantCulture) + "\t" + Text + "\n");
 }
        private static void handleResponseEvent(Event eventObj, List <SecurityModel> securities, ILogger log)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("INSERT INTO [dbo].[Prices] ");
            sb.Append("(security_id, ask, bid, px_last, date_time) VALUES");

            log.LogInformation("EventType =" + eventObj.Type);
            foreach (Message message in eventObj.GetMessages())
            {
                log.LogInformation("correlationID=" + message.CorrelationID);
                log.LogInformation("messageType =" + message.MessageType);

                Element elmSecurityDataArray = message["securityData"];

                for (int valueIndex = 0; valueIndex < elmSecurityDataArray.NumValues; valueIndex++)
                {
                    Element elmSecurityData = elmSecurityDataArray.GetValueAsElement(valueIndex);

                    string security = elmSecurityData.GetElementAsString("security");
                    log.LogInformation("about to log security");
                    log.LogInformation(security);

                    bool hasFieldErrors = elmSecurityData.HasElement("fieldExceptions", true);
                    if (hasFieldErrors)
                    {
                        Element elmFieldErrors = elmSecurityData["fieldExceptions"];
                        for (int errorIndex = 0; errorIndex < elmFieldErrors.NumValues; errorIndex++)
                        {
                            Element fieldError = elmFieldErrors.GetValueAsElement(errorIndex);
                            string  fieldId    = fieldError.GetElementAsString("fieldId");

                            Element errorInfo   = fieldError["errorInfo"];
                            string  source      = errorInfo.GetElementAsString("source");
                            int     code        = errorInfo.GetElementAsInt32("code");
                            string  category    = errorInfo.GetElementAsString("category");
                            string  strMessage  = errorInfo.GetElementAsString("message");
                            string  subCategory = errorInfo.GetElementAsString("subcategory");

                            log.LogInformation("\tfield error: " + security);
                            log.LogInformation(string.Format("\tfieldId = {0}", fieldId));
                            log.LogInformation(string.Format("\tsource = {0}", source));
                            log.LogInformation(string.Format("\tcode = {0}", code));
                            log.LogInformation(string.Format("\tcategory = {0}", category));
                            log.LogInformation(string.Format("\terrorMessage = {0}", strMessage));
                            log.LogInformation(string.Format("\tsubCategory = {0}", subCategory));
                        }
                    }

                    bool isSecurityError = elmSecurityData.HasElement("securityError", true);
                    if (isSecurityError)
                    {
                        Element secError     = elmSecurityData["securityError"];
                        string  source       = secError.GetElementAsString("source");
                        int     code         = secError.GetElementAsInt32("code");
                        string  category     = secError.GetElementAsString("category");
                        string  errorMessage = secError.GetElementAsString("message");
                        string  subCategory  = secError.GetElementAsString("subcategory");

                        log.LogInformation("\tsecurity error");
                        log.LogInformation(string.Format("\tsource = {0}", source));
                        log.LogInformation(string.Format("\tcode = {0}", code));
                        log.LogInformation(string.Format("\tcategory = {0}", category));
                        log.LogInformation(string.Format("\terrorMessage = {0}", errorMessage));
                        log.LogInformation(string.Format("\tsubCategory = {0}", subCategory));
                    }
                    else
                    {
                        Element elmFieldData = elmSecurityData["fieldData"];

                        double pxLast = elmFieldData.GetElementAsFloat64("PX_LAST");
                        double bid    = elmFieldData.GetElementAsFloat64("BID");
                        double ask    = elmFieldData.GetElementAsFloat64("ASK");
                        string ticker = elmFieldData.GetElementAsString("TICKER");

                        log.LogInformation("\tPX_LAST = " + pxLast.ToString());
                        log.LogInformation("\tBID = " + bid.ToString());
                        log.LogInformation("\tASK = " + ask.ToString());

                        if (elmFieldData.HasElement("TRADEABLE_DT", true))
                        {
                            Datetime trDate       = elmFieldData.GetElementAsDatetime("TRADEABLE_DT");
                            DateTime trDateSystem = elmFieldData.GetElementAsDatetime("TRADEABLE_DT").ToSystemDateTime(); //convenient conversion to C# DateTime object
                            log.LogInformation("\tTRADEABLE_DT = " + trDate.ToString());
                        }

                        SecurityModel bloombergSecurity = securities.Find(s => s.Name == security);
                        log.LogInformation("bloomberg security id");
                        log.LogInformation(bloombergSecurity.Id.ToString());
                        if (bloombergSecurity.Id > 0)
                        {
                            var dbDateTime = DateTime.Now;
                            sb.Append(" (" + bloombergSecurity.Id.ToString() + ", " + ask.ToString() + ", " + bid.ToString() + ", " + pxLast.ToString() + ", '" + dbDateTime.ToString() + "')");
                            if (valueIndex == elmSecurityDataArray.NumValues - 1)
                            {
                                sb.Append(";");
                            }
                            else
                            {
                                sb.Append(",");
                            }
                        }

                        //TRADEABLE_DT

                        bool excludeNullElements = true;
                        if (elmFieldData.HasElement("CHAIN_TICKERS", excludeNullElements)) //be careful, the excludeNullElements argument is false by default
                        {
                            Element chainTickers = elmFieldData["CHAIN_TICKERS"];
                            for (int chainTickerValueIndex = 0; chainTickerValueIndex < chainTickers.NumValues; chainTickerValueIndex++)
                            {
                                Element chainTicker    = chainTickers.GetValueAsElement(chainTickerValueIndex);
                                string  strChainTicker = chainTicker.GetElementAsString("Ticker");

                                log.LogInformation("\tCHAIN_TICKER = " + strChainTicker.ToString());
                            }
                        }
                        else
                        {
                            log.LogInformation("\tNo CHAIN_TICKER information");
                        }
                    }
                }
            }

            var    str = Environment.GetEnvironmentVariable("bloombergsql");
            String sql = sb.ToString();

            log.LogInformation("here is my sql query string");
            log.LogInformation(sql);

            using (SqlConnection conn = new SqlConnection(str))
            {
                conn.Open();
                SqlCommand command = new SqlCommand(sql, conn);
                command.ExecuteNonQuery();
                log.LogInformation("all done");
            }
        }
Ejemplo n.º 7
0
        private static void handleResponseEvent(Event eventObj)
        {
            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine("EventType =" + eventObj.Type);
            foreach (Message message in eventObj.GetMessages())
            {
                Console.WriteLine();
                Console.WriteLine();
                Console.WriteLine("correlationID=" + message.CorrelationID);
                Console.WriteLine("messageType =" + message.MessageType);

                Element elmSecurityDataArray = message["securityData"];

                for (int valueIndex = 0; valueIndex < elmSecurityDataArray.NumValues; valueIndex++)
                {
                    Element elmSecurityData = elmSecurityDataArray.GetValueAsElement(valueIndex);

                    string security = elmSecurityData.GetElementAsString("security");
                    Console.WriteLine(security);

                    bool hasFieldErrors = elmSecurityData.HasElement("fieldExceptions", true);
                    if (hasFieldErrors)
                    {
                        Element elmFieldErrors = elmSecurityData["fieldExceptions"];
                        for (int errorIndex = 0; errorIndex < elmFieldErrors.NumValues; errorIndex++)
                        {
                            Element fieldError = elmFieldErrors.GetValueAsElement(errorIndex);
                            string  fieldId    = fieldError.GetElementAsString("fieldId");

                            Element errorInfo   = fieldError["errorInfo"];
                            string  source      = errorInfo.GetElementAsString("source");
                            int     code        = errorInfo.GetElementAsInt32("code");
                            string  category    = errorInfo.GetElementAsString("category");
                            string  strMessage  = errorInfo.GetElementAsString("message");
                            string  subCategory = errorInfo.GetElementAsString("subcategory");

                            Console.Error.WriteLine();
                            Console.Error.WriteLine();
                            Console.Error.WriteLine("\tfield error: " + security);
                            Console.Error.WriteLine(string.Format("\tfieldId = {0}", fieldId));
                            Console.Error.WriteLine(string.Format("\tsource = {0}", source));
                            Console.Error.WriteLine(string.Format("\tcode = {0}", code));
                            Console.Error.WriteLine(string.Format("\tcategory = {0}", category));
                            Console.Error.WriteLine(string.Format("\terrorMessage = {0}", strMessage));
                            Console.Error.WriteLine(string.Format("\tsubCategory = {0}", subCategory));
                        }
                    }

                    bool isSecurityError = elmSecurityData.HasElement("securityError", true);
                    if (isSecurityError)
                    {
                        Element secError     = elmSecurityData["securityError"];
                        string  source       = secError.GetElementAsString("source");
                        int     code         = secError.GetElementAsInt32("code");
                        string  category     = secError.GetElementAsString("category");
                        string  errorMessage = secError.GetElementAsString("message");
                        string  subCategory  = secError.GetElementAsString("subcategory");

                        Console.Error.WriteLine();
                        Console.Error.WriteLine();
                        Console.Error.WriteLine("\tsecurity error");
                        Console.Error.WriteLine(string.Format("\tsource = {0}", source));
                        Console.Error.WriteLine(string.Format("\tcode = {0}", code));
                        Console.Error.WriteLine(string.Format("\tcategory = {0}", category));
                        Console.Error.WriteLine(string.Format("\terrorMessage = {0}", errorMessage));
                        Console.Error.WriteLine(string.Format("\tsubCategory = {0}", subCategory));
                    }
                    else
                    {
                        Element elmFieldData = elmSecurityData["fieldData"];

                        double pxLast = elmFieldData.GetElementAsFloat64("PX_LAST");
                        double bid    = elmFieldData.GetElementAsFloat64("BID");
                        double ask    = elmFieldData.GetElementAsFloat64("ASK");
                        string ticker = elmFieldData.GetElementAsString("TICKER");

                        Console.WriteLine();
                        Console.WriteLine();
                        Console.WriteLine("\tPX_LAST = " + pxLast.ToString());
                        Console.WriteLine("\tBID = " + bid.ToString());
                        Console.WriteLine("\tASK = " + ask.ToString());
                        Console.WriteLine("\tTICKER = " + ticker.ToString());

                        if (elmFieldData.HasElement("TRADEABLE_DT", true))
                        {
                            Datetime trDate       = elmFieldData.GetElementAsDatetime("TRADEABLE_DT");
                            DateTime trDateSystem = elmFieldData.GetElementAsDatetime("TRADEABLE_DT").ToSystemDateTime(); //convenient conversion to C# DateTime object
                            Console.WriteLine("\tTRADEABLE_DT = " + trDate.ToString());
                        }

                        //TRADEABLE_DT

                        bool excludeNullElements = true;
                        if (elmFieldData.HasElement("CHAIN_TICKERS", excludeNullElements)) //be careful, the excludeNullElements argument is false by default
                        {
                            Element chainTickers = elmFieldData["CHAIN_TICKERS"];
                            for (int chainTickerValueIndex = 0; chainTickerValueIndex < chainTickers.NumValues; chainTickerValueIndex++)
                            {
                                Element chainTicker    = chainTickers.GetValueAsElement(chainTickerValueIndex);
                                string  strChainTicker = chainTicker.GetElementAsString("Ticker");

                                Console.WriteLine("\tCHAIN_TICKER = " + strChainTicker.ToString());
                            }
                        }
                        else
                        {
                            Console.WriteLine("\tNo CHAIN_TICKER information");
                        }
                    }
                }
            }
        }