コード例 #1
0
        /// <summary>
        /// Process override field data returned
        /// </summary>
        /// <param name="msg"></param>
        private void processOverrides(Bloomberglp.Blpapi.Message msg)
        {
            string[] elementList     = new string[] { "mnemonic", "description", "categoryName" };
            object[] fieldDataValues = null;

            if (msg.MessageType.Equals(Bloomberglp.Blpapi.Name.GetName("fieldResponse")))
            {
                // process response
                Element fieldDataArray = msg.GetElement("fieldData");
                int     numberOfFields = fieldDataArray.NumValues;
                // start table update
                overrideTable.BeginLoadData();
                overrideFieldsTempTable.BeginLoadData();
                for (int index = 0; index < numberOfFields; index++)
                {
                    // process field element
                    fieldDataValues = new object[4];
                    Element fieldElement = fieldDataArray.GetValueAsElement(index);
                    Element fieldData    = fieldElement.GetElement("fieldInfo");
                    try
                    {
                        // get field id
                        string fieldId = d_fieldIds[index];
                        // get override for field id
                        string    selectCriteria = "id = '" + fieldId + "'";
                        DataRow[] ovrRows        = overrideTable.Select(selectCriteria);
                        DataRow[] fields         = overrideFieldsTempTable.Select(selectCriteria);
                        if (fields.Length > 0)
                        {
                            // process override fields
                            int dataIndex = 1;
                            foreach (string item in elementList)
                            {
                                // field property
                                Element dataElement = fieldData.GetElement(item);
                                if (dataElement.IsArray)
                                {
                                    // process array data
                                    switch (item)
                                    {
                                    case "categoryName":
                                        // process categoryName here
                                        break;

                                    case "overrides":
                                        // process categoryName here
                                        break;
                                    }
                                }
                                else
                                {
                                    // process element data
                                    switch (item)
                                    {
                                    case "documentation":
                                        // process documentation here
                                        break;

                                    default:
                                        fields[0][dataIndex] = dataElement.GetValueAsString();
                                        break;
                                    }
                                }
                                dataIndex++;
                            }

                            if (ovrRows.Length > 0)
                            {
                                // update override field properties
                                foreach (DataRow ovrRow in ovrRows)
                                {
                                    ovrRow["mnemonic"]    = fields[0]["mnemonic"];
                                    ovrRow["description"] = fields[0]["description"];
                                }
                            }
                        }
                    }
                    catch
                    {
                        // field property not in response
                    }
                }
                // end of table update
                overrideTable.BeginLoadData();
                overrideTable.AcceptChanges();
                overrideFieldsTempTable.BeginLoadData();
                overrideFieldsTempTable.AcceptChanges();
            }
        }
コード例 #2
0
        /// <summary>
        /// Process categorized field search response
        /// </summary>
        /// <param name="msg"></param>
        private void processCategorizedFieldData(Bloomberglp.Blpapi.Message msg)
        {
            string message = string.Empty;

            string[] elementList = new string[] { "mnemonic", "description",
                                                  "categoryName", "documentation", "overrides" };
            object[] fieldDataValues = null;

            // process message
            toolStripStatusLabel1.Text = "Processing data...";

            if (msg.MessageType.Equals(Bloomberglp.Blpapi.Name.GetName("categorizedFieldResponse")))
            {
                if (msg.HasElement("categorizedFieldSearchError"))
                {
                    // process field search error
                    Element reason = msg.GetElement("categorizedFieldSearchError");
                    message = string.Concat("Error: Source-", reason.GetElementAsString("source"),
                                            ", Code-", reason.GetElementAsString("code"), ", category-",
                                            reason.GetElementAsString("category"),
                                            ", desc-", reason.GetElementAsString("message"));
                }
                else
                {
                    if (msg.HasElement("category"))
                    {
                        // process category
                        Element categories         = msg.GetElement("category");
                        int     numberOfCategories = categories.NumValues;
                        for (int categoryIndex = 0; categoryIndex < numberOfCategories; categoryIndex++)
                        {
                            // process category data
                            Element category       = categories.GetValueAsElement(categoryIndex);
                            Element fieldDataArray = category.GetElement("fieldData");
                            int     numberOfFields = fieldDataArray.NumValues;
                            // start table update
                            fieldTable.BeginLoadData();
                            propertyTable.BeginLoadData();
                            overrideTable.BeginLoadData();
                            for (int index = 0; index < numberOfFields; index++)
                            {
                                // process field data
                                fieldDataValues = new object[4];
                                Element fieldElement = fieldDataArray.GetValueAsElement(index);
                                Element fieldData    = fieldElement.GetElement("fieldInfo");
                                // get field id
                                string fieldId = fieldElement.GetElementAsString("id");
                                fieldDataValues[0] = fieldId;
                                try
                                {
                                    String dataValue = string.Empty;
                                    int    dataIndex = 1;
                                    foreach (string item in elementList)
                                    {
                                        // get field property
                                        Element dataElement = fieldData.GetElement(item);
                                        if (dataElement.IsArray)
                                        {
                                            // process array data
                                            switch (item)
                                            {
                                            case "categoryName":
                                                fieldDataValues[dataIndex] = category.GetElementAsString("categoryName");
                                                break;

                                            case "overrides":
                                                for (int overrideIndex = 0; overrideIndex < dataElement.NumValues; overrideIndex++)
                                                {
                                                    if (overrideTable.Select("parentId = '" + fieldId + "' AND id = '" +
                                                                             dataElement[overrideIndex].ToString() + "'").Length == 0)
                                                    {
                                                        overrideTable.Rows.Add(new object[] { fieldId, dataElement[overrideIndex].ToString(),
                                                                                              DBNull.Value, DBNull.Value });
                                                    }
                                                }
                                                break;
                                            }
                                        }
                                        else
                                        {
                                            // process element data
                                            switch (item)
                                            {
                                            case "documentation":
                                                // add documentation row
                                                propertyTable.Rows.Add(new object[] { fieldId, dataElement.GetValue() });
                                                break;

                                            default:
                                                fieldDataValues[dataIndex] = dataElement.GetValueAsString();
                                                break;
                                            }
                                        }
                                        dataIndex++;
                                    }
                                    // add field to table
                                    fieldTable.Rows.Add(fieldDataValues);
                                }
                                catch
                                {
                                    // field property not in response
                                }
                            }
                        }
                    }
                    // end of table update
                    fieldTable.EndLoadData();
                    propertyTable.EndLoadData();
                    overrideTable.EndLoadData();
                    d_data.AcceptChanges();
                    if (fieldTable.Rows.Count > 0)
                    {
                        richTextBoxDocumentation.Tag = string.Empty;
                        // trigger event to update override grid
                        dataGridViewDataView_RowEnter(this, new DataGridViewCellEventArgs(1, 0));
                    }
                }
            }
            if (message != string.Empty)
            {
                toolStripStatusLabel1.Text = "Request error: " + message;
            }
        }