Пример #1
0
        public static List <HistoryRow> ObtenerHistorial()
        {
            List <HistoryRow> rows = new List <HistoryRow>();

            if (File.Exists("history.sqlite"))
            {
                try
                {
                    SQLiteConnection m_dbConnection;
                    m_dbConnection = new SQLiteConnection("Data Source=history.sqlite;Version=3;");
                    m_dbConnection.Open();
                    //creando tablas
                    string sql = "select * from history ORDER BY datetime(dt) desc limit 20";

                    SQLiteCommand command = new SQLiteCommand(sql, m_dbConnection);

                    SQLiteDataReader reader = command.ExecuteReader();

                    while (reader.Read())
                    {
                        HistoryRow row = new HistoryRow();
                        row.ID     = Convert.ToInt32(reader["id"]);
                        row.URL    = reader["url"].ToString();
                        row.Method = reader["method"].ToString();
                        row.Body   = reader["body"].ToString();

                        try
                        {
                            String headers = reader["readers"].ToString();

                            foreach (String header in headers.Split('|'))
                            {
                                Header head = new Header();
                                head.Key   = header.Split(',')[0];
                                head.Value = header.Split(',')[1];
                                row.Headers.Add(head);
                            }
                        }
                        catch { }
                        row.isChanged      = false;
                        row.ActivarEventos = true;
                        rows.Add(row);
                    }

                    m_dbConnection.Close();
                }
                catch (Exception ex)
                {
                    throw new Exception("Error trying get history.", ex);
                }
            }
            return(rows);
        }
Пример #2
0
        void cmbUrl_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            HistoryRow row = (HistoryRow)cmbUrl.SelectedItem;

            if (row != null)
            {
                //grdPrincipal.DataContext = row;
                //cmbUrl.Text = row.URL;
                if (objActual != row)
                {
                    objActual = row;
                    CargaDatos();
                }
            }
        }
Пример #3
0
        public static void InsertarHistorialPorURL(HistoryRow row)
        {
            if (File.Exists("history.sqlite") && row.isChanged)
            {
                try
                {
                    row.isChanged = false;
                    SQLiteConnection m_dbConnection;
                    m_dbConnection = new SQLiteConnection("Data Source=history.sqlite;Version=3;");
                    m_dbConnection.Open();
                    //creando tablas
                    string sql = "";


                    String headers = "";
                    if (row.Headers != null)
                    {
                        sql = "insert into history (url, method, headers, body) values ('@url', '@method', '@headers', '@body')";
                        foreach (Header header in row.Headers)
                        {
                            headers += header.Key + "," + header.Value + "|";
                        }
                        headers = headers.Substring(0, headers.Length - 1);
                        sql     = sql.Replace("@headers", headers);
                    }
                    else
                    {
                        sql = "insert into history (url, method, body) values ('@url', '@method', '@body')";
                    }

                    sql = sql.Replace("@url", row.URL);
                    sql = sql.Replace("@method", row.Method);
                    sql = sql.Replace("@body", row.Body);
                    SQLiteCommand command = new SQLiteCommand(sql, m_dbConnection);
                    command.ExecuteNonQuery();
                    m_dbConnection.Close();
                }
                catch (Exception ex)
                {
                    throw new Exception("Error trying create history database.", ex);
                }
            }
            else
            {
                ActualizarHistorialPorURL(row);
            }
        }
Пример #4
0
        void x_EVT_CambioURL(HistoryRow anterior, String nuevaURL)
        {
            HistoryRow row = new HistoryRow();

            row.URL       = nuevaURL;
            row.Method    = anterior.Method;
            row.Body      = anterior.Body;
            row.isChanged = true;
            ((List <HistoryRow>)cmbUrl.ItemsSource).Insert(0, row);
            cmbUrl.Items.Refresh();
            cmbUrl.SelectedItem = ((List <HistoryRow>)cmbUrl.ItemsSource)[0];
            row.ActivarEventos  = true;
            row.EVT_CambioURL  -= new HistoryRow._EVT_CambioURL(x_EVT_CambioURL);
            row.EVT_CambioURL  += new HistoryRow._EVT_CambioURL(x_EVT_CambioURL);
            objActual           = row;
            //grdPrincipal.DataContext = objActual;
        }
Пример #5
0
        public static void ActualizarHistorialPorURL(HistoryRow row)
        {
            if (File.Exists("history.sqlite"))
            {
                try
                {
                    row.isChanged = false;
                    SQLiteConnection m_dbConnection;
                    m_dbConnection = new SQLiteConnection("Data Source=history.sqlite;Version=3;");
                    m_dbConnection.Open();
                    //creando tablas
                    string sql = "update history set dt = datetime('now','localtime') where id = " + row.ID;

                    SQLiteCommand command = new SQLiteCommand(sql, m_dbConnection);
                    command.ExecuteNonQuery();
                    m_dbConnection.Close();
                }
                catch (Exception ex)
                {
                    throw new Exception("Error trying create history database.", ex);
                }
            }
        }
Пример #6
0
        private void ActualizaCombo()
        {
            cmbUrl.SelectionChanged -= new SelectionChangedEventHandler(cmbUrl_SelectionChanged);
            List <HistoryRow> historial = SQLiteHelper.ObtenerHistorial();//.OrderByDescending(x => x.ID).ToList();

            historial.ForEach(x => x.EVT_CambioURL -= new HistoryRow._EVT_CambioURL(x_EVT_CambioURL));
            historial.ForEach(x => x.EVT_CambioURL += new HistoryRow._EVT_CambioURL(x_EVT_CambioURL));

            if (historial.Count == 0)
            {
                objActual = new HistoryRow();
                historial.Add(objActual);
            }
            else
            {
                objActual = historial[0];
            }
            CargaDatos();
            cmbUrl.ItemsSource  = historial;
            cmbUrl.SelectedItem = historial[0];
            cmbUrl.Items.Refresh();
            cmbUrl.SelectionChanged += new SelectionChangedEventHandler(cmbUrl_SelectionChanged);
            //grdPrincipal.DataContext = cmbUrl.SelectedItem;
        }