Пример #1
0
 /// <summary>
 /// Writes a QuoteData to XML format
 /// </summary>
 /// <param name="writer">The used XML writer</param>
 /// <param name="quote">The used QuoteData</param>
 /// <param name="properties">The used properties of the quotes</param>
 /// <param name="culture">The used culture for formating dates and numbers. If parameter value is null/Nothing, default Culture will be used.</param>
 /// <remarks></remarks>
 public static void FromQuoteData(System.Xml.XmlWriter writer, QuotesData quote, IEnumerable <QuoteProperty> properties, System.Globalization.CultureInfo culture = null)
 {
     System.Globalization.CultureInfo ci = System.Globalization.CultureInfo.CurrentCulture;
     if (culture != null)
     {
         ci = culture;
     }
     writer.WriteStartElement("Quote");
     if (quote[QuoteProperty.Symbol] != null)
     {
         writer.WriteAttributeString("ID", quote[QuoteProperty.Symbol].ToString());
     }
     QuoteProperty[] prps = FinanceHelper.CheckPropertiesOfQuotesData(new QuotesData[] { quote }, properties);
     foreach (QuoteProperty qp in prps)
     {
         writer.WriteStartElement(qp.ToString());
         writer.WriteValue(MyHelper.ObjectToString(quote[qp], ci));
         writer.WriteEndElement();
     }
     writer.WriteEndElement();
 }
Пример #2
0
        /// <summary>
        /// Converts a list of quote data to a CSV formatted text
        /// </summary>
        /// <param name="quotes">The list of quote values</param>
        /// <param name="delimiter">The delimiter of the CSV text</param>
        /// <param name="properties">The used properties of the items</param>
        /// <param name="culture">The used culture for formating dates and numbers. If parameter value is null/Nothing, default Culture will be used.</param>
        /// <returns>The converted data string in CSV format</returns>
        /// <remarks></remarks>
        public static string FromQuotesData(IEnumerable <QuotesData> quotes, char delimiter, IEnumerable <QuoteProperty> properties, System.Globalization.CultureInfo culture = null)
        {
            if (quotes != null)
            {
                System.Globalization.CultureInfo ci = System.Globalization.CultureInfo.CurrentCulture;
                if (culture != null)
                {
                    ci = culture;
                }

                QuoteProperty[]           prpts = FinanceHelper.CheckPropertiesOfQuotesData(quotes, properties);
                System.Text.StringBuilder sb    = new System.Text.StringBuilder();

                foreach (QuoteProperty qp in prpts)
                {
                    sb.Append(qp.ToString());
                    sb.Append(delimiter);
                }
                sb.Remove(sb.Length - 1, 1);
                sb.AppendLine();

                foreach (QuotesData q in quotes)
                {
                    if (q != null)
                    {
                        System.Text.StringBuilder sbQ = new System.Text.StringBuilder();
                        foreach (QuoteProperty qp in prpts)
                        {
                            object o = MyHelper.ObjectToString(q[qp], ci);
                            if (o is string)
                            {
                                if (o.ToString() == string.Empty)
                                {
                                    sbQ.Append("\"N/A\"");
                                }
                                else
                                {
                                    sbQ.Append("\"");
                                    sbQ.Append(q[qp].ToString().Replace("\"", "\"\""));
                                    sbQ.Append("\"");
                                }
                            }
                            else
                            {
                                sbQ.Append(MyHelper.ObjectToString(q[qp], ci));
                            }
                            sbQ.Append(delimiter);
                        }
                        if (sbQ.Length > 0)
                        {
                            sbQ.Remove(sbQ.Length - 1, 1);
                        }
                        sb.AppendLine(sbQ.ToString());
                    }
                }
                return(sb.ToString());
            }
            else
            {
                return(string.Empty);
            }
        }