private bool getValueFromCols(string[] rows, int index, out string value)
        {
            try
            {
                string[] cols = rows[index].Split(',');
                MovimentacaoBDDTO bdDTO = new MovimentacaoBDDTO();
                bdDTO.data = DateTime.Parse(cols[0]);
                bdDTO.data.AddHours(18);
                bdDTO.valor = float.Parse(cols[4].Replace('.', ','));
                bdDTO.volume = long.Parse(cols[5]);
                value = this.parseHistoricoValue(bdDTO, this.idAcao);
                if (bdDTO.data < DateTime.Now && bdDTO.data > minLimitDate)
                {
                    return true;
                }
                else
                {
                    return false;
                }

            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e.Message);
            }
            value = "";
            return false;
        }
 protected string parseHistoricoValue(MovimentacaoBDDTO dto,int idAcao)
 {
     return String.Format("({0},{1},{2},{3})", this.formatDate(dto.data), idAcao, dto.valor.ToString().Replace(',', '.'), dto.volume);
 }
        private void parseResponse(string response)
        {
            dtoBD = new MovimentacaoBDDTO();
            continuetoSend = false;
            // Create an XmlReader
            Log("Movimentacao Encontrada. Verificando se é nova");
            using (XmlReader reader = XmlReader.Create(new StringReader(response)))
            {
                XmlWriterSettings ws = new XmlWriterSettings();
                ws.Indent = true;
                string[] datas,horario;
                int horas;
                // Parse the file and display each of the nodes.
                while (reader.Read())
                {
                    if (reader.NodeType == XmlNodeType.Element)
                    {
                        //writer.WriteStartElement(reader.Name);

                            try
                            {
                                switch (reader.Name)
                                {
                                    case "Bid":
                                        reader.Read();
                                        dtoBD.valor = float.Parse(reader.Value.Replace('.', ','));
                                        break;
                                    case "LastTradeDate":
                                        reader.Read();
                                        datas = reader.Value.Split('/');
                                        reader.Read(); //end lasttradedate
                                        reader.Read(); //lasttradetime
                                        reader.Read();
                                        horario = reader.Value.Split(':');
                                        horas = int.Parse(horario[0]);
                                        if (horario[1][2] == 'p' && horas != 12)
                                        {
                                            horas += 12;
                                        }
                                        dtoBD.data = new DateTime(int.Parse(datas[2]), int.Parse(datas[0]), int.Parse(datas[1]), horas, int.Parse(horario[1].Substring(0, 2)), 0);
                                        continuetoSend = dtoBD.data > this.lastTime;
                                        if (dtoBD.data < DateTime.Now.Subtract(TimeSpan.FromDays(30)) && dtoBD.data > minUsefulDateTime)
                                        {
                                            continuetoSend = false;
                                        }
                                        break;
                                    case "Volume":
                                        reader.Read();
                                        dtoBD.volume = long.Parse(reader.Value);
                                        break;
                                }
                            }// end switch
                            catch (Exception e)
                            {
                                System.Diagnostics.Debug.WriteLine(e.Message);
                            }// end try

                    } //end if element
                } // end while
            } //end using
            if (continuetoSend)
            {
                Log("É nova. Mandando pro banco de dados");
                sendCollectedData(dtoBD);
                this.lastTime = dtoBD.data;
                this.threadSleepTime /= 2;
                if (this.threadSleepTime < minSleepTime)
                {
                    this.threadSleepTime = minSleepTime;
                }
            }
            else
            {
                Log("Não é");
                this.threadSleepTime *= 2;
                if (this.threadSleepTime > maxSleepTime)
                {
                    this.threadSleepTime = maxSleepTime;
                }
            }
        }
 private void sendCollectedData(MovimentacaoBDDTO dto)
 {
     long timestamp = this.formatDate(dto.data);
     using (MySqlConnection connection = new MySqlConnection(connstring))
     {
         try
         {
             connection.Open();
             string value = this.parseHistoricoValue(dto,idAcao);
             Log(String.Format("Dado a ser inserido: {0}", value, dto.volume));
             Log("Inserindo novo dado no historico");
             MySqlCommand commandInsert = new MySqlCommand(String.Format("INSERT INTO HistoricoMovimentacao VALUES {0}", value), connection);
             commandInsert.ExecuteNonQuery();
             Log("Atualizando acao");
             MySqlCommand commandUpdate = new MySqlCommand(String.Format("UPDATE Acao SET ultimaVerificacao = {0}", timestamp), connection);
             commandUpdate.ExecuteNonQuery();
             connection.Close();
         }
         catch (Exception e)
         {
             Log(e.Message);
         }
     }
 }