Exemplo n.º 1
0
        public virtual object Clone()
        {
            QuotesData cln = new QuotesData();

            foreach (QuoteProperty qp in Enum.GetValues(typeof(QuoteProperty)))
            {
                if (this[qp] is object[])
                {
                    object[] obj    = (object[])this[qp];
                    object[] newObj = new object[obj.Length];
                    if (obj.Length > 0)
                    {
                        for (int i = 0; i <= obj.Length - 1; i++)
                        {
                            newObj[i] = obj[i];
                        }
                    }
                    cln[qp] = newObj;
                }
                else
                {
                    cln[qp] = this[qp];
                }
            }
            return(cln);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Tries to read a QuoteData from XML
 /// </summary>
 /// <param name="node">The XML node of a QuoteData</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 quote data or Nothing</returns>
 /// <remarks></remarks>
 public static QuotesData ToQuoteData(XElement node, System.Globalization.CultureInfo culture = null)
 {
     if (node != null && node.Name.LocalName.ToLower() == "quote")
     {
         System.Globalization.CultureInfo ci = System.Globalization.CultureInfo.CurrentCulture;
         if (culture != null)
         {
             ci = culture;
         }
         QuotesData quote = new QuotesData();
         foreach (XElement propertyNode in node.Elements())
         {
             foreach (QuoteProperty qp in Enum.GetValues(typeof(QuoteProperty)))
             {
                 if (propertyNode.Name.LocalName == qp.ToString())
                 {
                     quote[qp] = MyHelper.StringToObject(propertyNode.Value, ci);
                     break; // TODO: might not be correct. Was : Exit For
                 }
             }
         }
         return(quote);
     }
     else
     {
         return(null);
     }
 }
Exemplo n.º 3
0
        internal static QuotesData[] ToQuotesData(string csvText, char delimiter, QuoteProperty[] properties, System.Globalization.CultureInfo culture, bool hasHeader = false)
        {
            List <QuotesData> quotes = new List <QuotesData>();

            if (csvText != string.Empty & culture != null & (properties != null && properties.Length > 0))
            {
                if (properties.Length > 0)
                {
                    string[][] table = MyHelper.CsvTextToStringTable(csvText, delimiter);
                    int        start = 0;
                    if (hasHeader)
                    {
                        start = 1;
                    }

                    if (table.Length > 0)
                    {
                        if (!(table[0].Length == properties.Length))
                        {
                            String[][] semicolTable = MyHelper.CsvTextToStringTable(csvText, Convert.ToChar((delimiter == ';' ? ',' : ';')));
                            if (semicolTable[0].Length == properties.Length)
                            {
                                table = semicolTable;
                            }
                        }
                        if (table.Length > 0 && table.Length > start)
                        {
                            for (int i = start; i <= table.Length - 1; i++)
                            {
                                QuotesData qd = CsvArrayToQuoteData(table[i], properties, culture);
                                if (qd != null)
                                {
                                    quotes.Add(qd);
                                }
                            }
                        }
                    }
                }
            }
            return(quotes.ToArray());
        }
Exemplo n.º 4
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();
 }
Exemplo n.º 5
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="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, System.Globalization.CultureInfo culture = null)
 {
     FromQuoteData(writer, quote, null, culture);
 }
Exemplo n.º 6
0
        private static QuotesData CsvArrayToQuoteData(string[] rowItems, QuoteProperty[] properties, System.Globalization.CultureInfo culture)
        {
            if (rowItems.Length > 0)
            {
                QuotesData quote = null;
                if (rowItems.Length == properties.Length)
                {
                    quote = new QuotesData();
                    for (int i = 0; i <= properties.Length - 1; i++)
                    {
                        quote[properties[i]] = QuoteStringToObject(rowItems[i], properties[i], culture);
                    }
                }
                else
                {
                    if (rowItems.Length > 1)
                    {
                        List <QuoteProperty> alternateProperties = new List <QuoteProperty>();
                        foreach (QuoteProperty qp in properties)
                        {
                            foreach (QuoteProperty q in mAlternateQuoteProperties)
                            {
                                if (qp == q)
                                {
                                    alternateProperties.Add(qp);
                                    break;
                                }
                            }
                        }


                        if (alternateProperties.Count > 0)
                        {
                            List <KeyValuePair <QuoteProperty, int>[]> lst = new List <KeyValuePair <QuoteProperty, int>[]>();
                            int[][] permutations = MaxThreePerm(alternateProperties.Count, Math.Min(rowItems.Length - properties.Length + 1, 3));
                            foreach (int[] perm in permutations)
                            {
                                List <KeyValuePair <QuoteProperty, int> > lst2 = new List <KeyValuePair <QuoteProperty, int> >();
                                for (int i = 0; i <= alternateProperties.Count - 1; i++)
                                {
                                    lst2.Add(new KeyValuePair <QuoteProperty, int>(alternateProperties[i], perm[i]));
                                }
                                lst.Add(lst2.ToArray());
                            }

                            foreach (KeyValuePair <QuoteProperty, int>[] combination in lst)
                            {
                                String[] newRowItems = CsvNewRowItems(rowItems, properties, combination);

                                try
                                {
                                    if (newRowItems.Length > 0)
                                    {
                                        quote = new QuotesData();
                                        for (int i = 0; i <= properties.Length - 1; i++)
                                        {
                                            quote[properties[i]] = QuoteStringToObject(rowItems[i], properties[i], culture);
                                        }
                                        break;
                                    }
                                }
                                catch (Exception ex)
                                {
                                    System.Diagnostics.Debug.WriteLine(ex.Message);
                                }
                            }
                        }
                    }
                }
                return(quote);
            }
            else
            {
                return(null);
            }
        }