Пример #1
0
        private static void AddorUpdateClientsSqliteNew(ref detectionrun ds, int i, ref int clienttotal, ref int clientnew, ref int clientseen)
        {
            SQLiteConnectionStringBuilder builder = new SQLiteConnectionStringBuilder();
            builder.DataSource = string.Format("{0}\\kismetdata.db", Application.StartupPath);
            builder.SyncMode = SynchronizationModes.Off;
            builder.CacheSize = 5000;

            SQLiteConnection connection = new SQLiteConnection(builder.ToString());
            //SQLiteCommand command = connection.CreateCommand();
            connection.Open();
            SQLiteCommand insertclients = connection.CreateCommand();
            SQLiteCommand updateclients = connection.CreateCommand();
            insertclients.CommandText = "Insert into clients values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
            updateclients.CommandText=@"UPDATE [Clients] SET
                [Clientipaddress]=?,
                [oui]=?,
                [clientencryption]=?,
                [clientfirsttime]=?,
                [clientgpsminlat]=?,
                [clientgpsminlon]=?,
                [clientgpsmaxlat]=?,
                [clientgpsmaxlon]=?,
                [clientgpsminalt]=?,
                [clientgpsmaxalt]=?,
                [clientgpsminspeed]=?,
                [clientgpsmaxspeed]=?,
                [clientdatasize]=?,
                [clientmaxrate]=?,
                [clientmaxseenrate]=?,
                [clientlasttime]=?,
                [clientpacketscrypt]=?,
                [clientpacketsdata]=?,
                [clientpacketsweak]=?,
                [Number]=?,
                [Type]=?,
                [wep]=?
            WHERE
                [bssid]=? AND
                [clientmac]=?";
            SQLiteParameter Clientipaddress = insertclients.CreateParameter();
            SQLiteParameter updateClientipaddress = updateclients.CreateParameter();
            SQLiteParameter insertoui = insertclients.CreateParameter();
            SQLiteParameter updateoui = updateclients.CreateParameter();
            SQLiteParameter bssid = insertclients.CreateParameter();

            SQLiteParameter clientmac = insertclients.CreateParameter();

            SQLiteParameter clientencryption = insertclients.CreateParameter();
            SQLiteParameter updateclientencryption = updateclients.CreateParameter();
            SQLiteParameter clientfirsttime = insertclients.CreateParameter();
            SQLiteParameter updateclientfirsttime = updateclients.CreateParameter();
            SQLiteParameter clientgpsminlat=insertclients.CreateParameter();
            SQLiteParameter clientgpsminlon=insertclients.CreateParameter();
            SQLiteParameter clientgpsmaxlat=insertclients.CreateParameter();
            SQLiteParameter clientgpsmaxlon=insertclients.CreateParameter();
            SQLiteParameter clientgpsminalt=insertclients.CreateParameter();
            SQLiteParameter clientgpsmaxalt=insertclients.CreateParameter();
            SQLiteParameter clientgpsminspeed=insertclients.CreateParameter();
            SQLiteParameter clientgpsmaxspeed=insertclients.CreateParameter();
            SQLiteParameter clientdatasize=insertclients.CreateParameter();
            SQLiteParameter clientmaxrate=insertclients.CreateParameter();
            SQLiteParameter clientmaxseenrate=insertclients.CreateParameter();
            SQLiteParameter clientlasttime=insertclients.CreateParameter();
            SQLiteParameter clientpacketscrypt=insertclients.CreateParameter();
            SQLiteParameter clientpacketsdata=insertclients.CreateParameter();
            SQLiteParameter clientpacketsweak=insertclients.CreateParameter();
            SQLiteParameter Number=insertclients.CreateParameter();
            SQLiteParameter Type=insertclients.CreateParameter();
            SQLiteParameter wep = insertclients.CreateParameter();

            SQLiteParameter updateclientgpsminlat = updateclients.CreateParameter();
            SQLiteParameter updateclientgpsminlon = updateclients.CreateParameter();
            SQLiteParameter updateclientgpsmaxlat = updateclients.CreateParameter();
            SQLiteParameter updateclientgpsmaxlon = updateclients.CreateParameter();
            SQLiteParameter updateclientgpsminalt = updateclients.CreateParameter();
            SQLiteParameter updateclientgpsmaxalt = updateclients.CreateParameter();
            SQLiteParameter updateclientgpsminspeed = updateclients.CreateParameter();
            SQLiteParameter updateclientgpsmaxspeed = updateclients.CreateParameter();
            SQLiteParameter updateclientdatasize = updateclients.CreateParameter();
            SQLiteParameter updateclientmaxrate = updateclients.CreateParameter();
            SQLiteParameter updateclientmaxseenrate = updateclients.CreateParameter();
            SQLiteParameter updateclientlasttime = updateclients.CreateParameter();
            SQLiteParameter updateclientpacketscrypt = updateclients.CreateParameter();
            SQLiteParameter updateclientpacketsdata = updateclients.CreateParameter();
            SQLiteParameter updateclientpacketsweak = updateclients.CreateParameter();
            SQLiteParameter updateNumber = updateclients.CreateParameter();
            SQLiteParameter updateType = updateclients.CreateParameter();
            SQLiteParameter updatewep = updateclients.CreateParameter();
            SQLiteParameter updatebssid = insertclients.CreateParameter();
            SQLiteParameter updateclientmac = updateclients.CreateParameter();

            insertclients.Parameters.Add(Clientipaddress);
                insertclients.Parameters.Add(insertoui);
                insertclients.Parameters.Add(bssid);
                insertclients.Parameters.Add(clientmac);
            insertclients.Parameters.Add(clientencryption);
            insertclients.Parameters.Add(clientfirsttime);
                insertclients.Parameters.Add(clientgpsminlat);
                insertclients.Parameters.Add(clientgpsminlon);
                insertclients.Parameters.Add(clientgpsmaxlat);
                insertclients.Parameters.Add(clientgpsmaxlon);
                insertclients.Parameters.Add(clientgpsminalt);
                insertclients.Parameters.Add(clientgpsmaxalt);
                insertclients.Parameters.Add(clientgpsminspeed);
                insertclients.Parameters.Add(clientgpsmaxspeed);
                insertclients.Parameters.Add(clientdatasize);
                insertclients.Parameters.Add(clientmaxrate);
                insertclients.Parameters.Add(clientmaxseenrate);
                insertclients.Parameters.Add(clientlasttime);
                insertclients.Parameters.Add(clientpacketscrypt);
                insertclients.Parameters.Add(clientpacketsdata);
                insertclients.Parameters.Add(clientpacketsweak);
                insertclients.Parameters.Add(Number);
                insertclients.Parameters.Add(Type);
            insertclients.Parameters.Add(wep);

            updateclients.Parameters.Add(updateClientipaddress);
            updateclients.Parameters.Add(updateoui);

            updateclients.Parameters.Add(updateclientencryption);
            updateclients.Parameters.Add(updateclientfirsttime);
            updateclients.Parameters.Add(updateclientgpsminlat);
            updateclients.Parameters.Add(updateclientgpsminlon);
            updateclients.Parameters.Add(updateclientgpsmaxlat);
            updateclients.Parameters.Add(updateclientgpsmaxlon);
            updateclients.Parameters.Add(updateclientgpsminalt);
            updateclients.Parameters.Add(updateclientgpsmaxalt);
            updateclients.Parameters.Add(updateclientgpsminspeed);
            updateclients.Parameters.Add(updateclientgpsmaxspeed);
            updateclients.Parameters.Add(updateclientdatasize);
            updateclients.Parameters.Add(updateclientmaxrate);
            updateclients.Parameters.Add(updateclientmaxseenrate);
            updateclients.Parameters.Add(updateclientlasttime);
            updateclients.Parameters.Add(updateclientpacketscrypt);
            updateclients.Parameters.Add(updateclientpacketsdata);
            updateclients.Parameters.Add(updateclientpacketsweak);
            updateclients.Parameters.Add(updateNumber);
            updateclients.Parameters.Add(updateType);
            updateclients.Parameters.Add(updatewep);
            updateclients.Parameters.Add(updatebssid);
            updateclients.Parameters.Add(updateclientmac);
            ClientsTableAdapter theclientstableadaptor = new ClientsTableAdapter();
            DataTable t;
            clienttotal += ds.wirelessnetwork[i].wirelessclient.Length;
            for (int j = 0; j < ds.wirelessnetwork[i].wirelessclient.Length; j++)
            {
                t=theclientstableadaptor.GetDataByClientBssid(ds.wirelessnetwork[i].wirelessclient[j].clientmac, ds.wirelessnetwork[i].BSSID);
                if(t.Rows.Count == 0)
                {
                    //theClientData.AddNew();
                    //Console.WriteLine("Client Add");
                    clientnew++;
                    bssid.Value = ds.wirelessnetwork[i].BSSID;
                    insertoui.Value = LookupOuiData(ds.wirelessnetwork[i].wirelessclient[j].clientmac);
                    clientmac.Value = ds.wirelessnetwork[i].wirelessclient[j].clientmac;
                    clientdatasize.Value = ds.wirelessnetwork[i].wirelessclient[j].clientdatasize;
                    clientencryption.Value = ds.wirelessnetwork[i].wirelessclient[j].clientencryption;
                    clientfirsttime.Value = ds.wirelessnetwork[i].wirelessclient[j].firsttime;
                    clientlasttime.Value = ds.wirelessnetwork[i].wirelessclient[j].lasttime;
                    if (ds.wirelessnetwork[i].wirelessclient[j].clientgpsinfo != null)
                    {
                        clientgpsmaxalt.Value = ds.wirelessnetwork[i].wirelessclient[j].clientgpsinfo.clientmaxalt;
                        clientgpsmaxlat.Value = ds.wirelessnetwork[i].wirelessclient[j].clientgpsinfo.clientmaxlat;
                        clientgpsmaxlon.Value = ds.wirelessnetwork[i].wirelessclient[j].clientgpsinfo.clientmaxlon;
                        clientgpsminalt.Value = ds.wirelessnetwork[i].wirelessclient[j].clientgpsinfo.clientminalt;
                        clientgpsminlat.Value = ds.wirelessnetwork[i].wirelessclient[j].clientgpsinfo.clientminlat;
                        clientgpsminlon.Value = ds.wirelessnetwork[i].wirelessclient[j].clientgpsinfo.clientminlon;
                    }
                    clientmaxrate.Value = ds.wirelessnetwork[i].wirelessclient[j].clientmaxrate;
                    if (ds.wirelessnetwork[i].wirelessclient[j].clientipaddress != null)
                    {
                        Clientipaddress.Value = ds.wirelessnetwork[i].wirelessclient[j].clientipaddress;
                    }
                    clientmaxseenrate.Value = ds.wirelessnetwork[i].wirelessclient[j].clientmaxseenrate;
                    clientpacketscrypt.Value = ds.wirelessnetwork[i].wirelessclient[j].clientpackets.clientcrypt;
                    clientpacketsdata.Value = ds.wirelessnetwork[i].wirelessclient[j].clientpackets.clientdata;
                    clientpacketsweak.Value = ds.wirelessnetwork[i].wirelessclient[j].clientpackets.clientweak;

                    insertclients.ExecuteNonQuery();

                    //theClientData.Save();
                }
                else
                {
                    clientseen++;
                    DataTableReader thereader = t.CreateDataReader();
                    thereader.Read();
                    //Console.WriteLine("Client Update");
                    updateoui.Value = LookupOuiData(ds.wirelessnetwork[i].wirelessclient[j].clientmac);
                    updateclientdatasize.Value = Convert.ToInt32(thereader["clientdatasize"]) + ds.wirelessnetwork[i].wirelessclient[j].clientdatasize;
                    updateclientencryption.Value = ds.wirelessnetwork[i].wirelessclient[j].clientencryption;
                    IFormatProvider format = new CultureInfo("en-US");
                    string[] expectedformats = { "ddd MMM  d HH:mm:ss yyyy", "ddd MMM d HH:mm:ss yyyy" };
                    string firsttime = thereader["clientfirsttime"].ToString();
                    string lasttime = thereader["clientlasttime"].ToString();
                    DateTime dbfirsttime;
                    DateTime xmlfirsttime;
                    DateTime dblasttime;
                    DateTime xmllasttime;
                    // Wed Mar 29 14:52:56 2006
                        dbfirsttime = DateTime.ParseExact(firsttime, expectedformats, format, DateTimeStyles.AllowWhiteSpaces);
                        xmlfirsttime = DateTime.ParseExact(ds.wirelessnetwork[i].wirelessclient[j].firsttime, expectedformats, format, DateTimeStyles.AllowWhiteSpaces);
                        dblasttime = DateTime.ParseExact(lasttime, expectedformats, format, DateTimeStyles.AllowWhiteSpaces);
                        xmllasttime = DateTime.ParseExact(ds.wirelessnetwork[i].wirelessclient[j].lasttime, expectedformats, format, DateTimeStyles.AllowWhiteSpaces);

                    if (xmlfirsttime < dbfirsttime)
                    {
                        updateclientfirsttime.Value = ds.wirelessnetwork[i].firsttime;
                    }
                    else
                    {
                        updateclientfirsttime.Value = thereader["clientfirsttime"];
                    }
                    if (xmllasttime > dblasttime)
                    {
                        updateclientlasttime.Value = ds.wirelessnetwork[i].lasttime;
                    }
                    else
                    {
                        updateclientlasttime.Value = thereader["clientlasttime"];
                    }

                    //theClientData.Clientfirsttime = ds.wirelessnetwork[i].wirelessclient[j].firsttime;
                    //theClientData.Clientlasttime = ds.wirelessnetwork[i].wirelessclient[j].lasttime;
                    if (ds.wirelessnetwork[i].wirelessclient[j].clientgpsinfo != null)
                    {
                        updateclientgpsmaxalt.Value = ds.wirelessnetwork[i].wirelessclient[j].clientgpsinfo.clientmaxalt;
                        updateclientgpsmaxlat.Value = ds.wirelessnetwork[i].wirelessclient[j].clientgpsinfo.clientmaxlat;
                        updateclientgpsmaxlon.Value = ds.wirelessnetwork[i].wirelessclient[j].clientgpsinfo.clientmaxlon;
                        updateclientgpsminalt.Value = ds.wirelessnetwork[i].wirelessclient[j].clientgpsinfo.clientminalt;
                        updateclientgpsminlat.Value = ds.wirelessnetwork[i].wirelessclient[j].clientgpsinfo.clientminlat;
                        updateclientgpsminlon.Value = ds.wirelessnetwork[i].wirelessclient[j].clientgpsinfo.clientminlon;
                    }
                    updateclientmaxrate.Value = ds.wirelessnetwork[i].wirelessclient[j].clientmaxrate;
                    if (ds.wirelessnetwork[i].wirelessclient[j].clientipaddress != null)
                    {
                        updateClientipaddress.Value = ds.wirelessnetwork[i].wirelessclient[j].clientipaddress;
                    }
                    updateclientmaxseenrate.Value = ds.wirelessnetwork[i].wirelessclient[j].clientmaxseenrate;
                    updateclientpacketscrypt.Value = Convert.ToInt32(thereader["clientpacketscrypt"])+ ds.wirelessnetwork[i].wirelessclient[j].clientpackets.clientcrypt;
                    updateclientpacketsdata.Value = Convert.ToInt32(thereader["clientpacketsdata"])+ ds.wirelessnetwork[i].wirelessclient[j].clientpackets.clientdata;
                    updateclientpacketsweak.Value = Convert.ToInt32(thereader["clientpacketsweak"])+ds.wirelessnetwork[i].wirelessclient[j].clientpackets.clientweak;
                    //theClientData.Save();
                    updateclients.ExecuteNonQuery();

                    thereader.Close();
                }

            }
        }
Пример #2
0
        /*
        private static void ProcessXMLFiles(string theconnectionstring, DirectoryInfo dir)
        {
            SQLiteConnectionStringBuilder builder = new SQLiteConnectionStringBuilder();
            builder.DataSource = string.Format("{0}\\kismetdata.db", Application.StartupPath);
            builder.SyncMode = SynchronizationModes.Off;
            builder.CacheSize = 5000;
            //DataTable t;
            FilesTableAdapter thegpsfilesadaptor = new FilesTableAdapter();
            SQLiteConnection connection = new SQLiteConnection(builder.ToString());
            //SQLiteCommand command = connection.CreateCommand();
            connection.Open();
            gpsfiles thegpsfiles = new gpsfiles();
            clientdata theClientData = new clientdata();
            thedata Kisdata = new thedata();
            ssidchanges thessidchanges = new ssidchanges();
            thessidchanges.ConnectionString = theconnectionstring;
            Kisdata.ConnectionString=theconnectionstring;
            theClientData.ConnectionString=theconnectionstring;
            thegpsfiles.ConnectionString=theconnectionstring;
            SQLiteCommand insertssidchanges = connection.CreateCommand();

            SQLiteCommand adddatacmd = connection.CreateCommand();
            SQLiteCommand updatedatacmd = connection.CreateCommand();
            XmlSerializer xs = new XmlSerializer(typeof(detectionrun));

            //ObjectContainer db = Db4o.OpenFile("c:\\testdb.db");
            foreach (FileInfo f in dir.GetFiles("Kismet*.xml"))
            {
                DataTable t;

                    t = thegpsfilesadaptor.GetDataByFilename(f.Name);
                if (t.Rows.Count == 0)
                    {

                    //thegpsfiles.AddNew();
                    //thegpsfiles.Filename=f.Name;
                    //thegpsfiles.Save();
                    InsertFilename(thegpsfilesadaptor, f);
                    Console.WriteLine("Processing " + f.Name);
                    FileStream fs = new FileStream(f.DirectoryName + "\\"+ f.Name, FileMode.Open);
                    try
                    {
                        detectionrun ds;
                        ds=(detectionrun) xs.Deserialize(fs);
                        DateTime dbfirsttime = new DateTime();
                        DateTime xmlfirsttime = new DateTime();
                        DateTime dblasttime = new DateTime();
                        DateTime xmllasttime= new DateTime();
                        //clientdata theClientData = new clientdata();
                        //thedata Kisdata = new thedata();
                        //Kisdata.ConnectionString=theconnectionstring;
                        //theClientData.ConnectionString=theconnectionstring;
                        int thedatalength;
                        thedatalength=ds.wirelessnetwork.Length;

                        for(int i=0; i<thedatalength; i++)
                        {

                            //Network network1=new Network(ds.wirelessnetwork[i].BSSID, ds.wirelessnetwork[i].SSID);
                            //db.Set(network1);
                            if(Kisdata.LoadByPrimaryKey(ds.wirelessnetwork[i].BSSID))
                            {

                                IFormatProvider format =new CultureInfo("en-US");
                                string [] expectedformats= {"ddd MMM  d HH:mm:ss yyyy", "ddd MMM d HH:mm:ss yyyy"};

                                // Wed Mar 29 14:52:56 2006
                                try
                                {
                                    dbfirsttime=DateTime.ParseExact(Kisdata.FirstTime,expectedformats,format, DateTimeStyles.AllowWhiteSpaces);
                                    xmlfirsttime=DateTime.ParseExact(ds.wirelessnetwork[i].firsttime, expectedformats,format, DateTimeStyles.AllowWhiteSpaces);
                                    dblasttime=DateTime.ParseExact(Kisdata.LastTime,expectedformats,format,DateTimeStyles.AllowWhiteSpaces);
                                    xmllasttime=DateTime.ParseExact(ds.wirelessnetwork[i].lasttime, expectedformats,format, DateTimeStyles.AllowWhiteSpaces);
                                }
                                catch(FormatException ex)
                                {
                                    Console.WriteLine(ex);
                                }
                                if ((Kisdata.ESSID != ds.wirelessnetwork[i].SSID && ds.wirelessnetwork[i].SSID != null) )
                                {
                                    Console.WriteLine("Old SSID " + Kisdata.ESSID + " New SSID " + ds.wirelessnetwork[i].SSID);
                                    thessidchanges.AddNew();
                                    thessidchanges.Bssid = Kisdata.BSSID;
                                    thessidchanges.Oldname = Kisdata.ESSID;
                                    thessidchanges.Newname = ds.wirelessnetwork[i].SSID;
                                    thessidchanges.Date = ds.wirelessnetwork[i].lasttime;
                                    thessidchanges.Save();

                                    Kisdata.ESSID = ds.wirelessnetwork[i].SSID;
                                }
                                else
                                {
                                }
                                Kisdata.Totalpacketscrypt+=ds.wirelessnetwork[i].packets.crypt;
                                Kisdata.Totalpacketsdata+=ds.wirelessnetwork[i].packets.data;
                                Kisdata.Totalpacketsdupeiv+=ds.wirelessnetwork[i].packets.dupeiv;
                                Kisdata.Totalpacketsllc+=ds.wirelessnetwork[i].packets.LLC;
                                Kisdata.Totalpacketstotal+=ds.wirelessnetwork[i].packets.total;
                                Kisdata.Totalpacketsweak+=ds.wirelessnetwork[i].packets.weak;
                                Kisdata.Cloaked=ds.wirelessnetwork[i].cloaked;
                                if (Kisdata.GPSMaxLat > ds.wirelessnetwork[i].gpsinfo.maxlat)
                                    Kisdata.GPSMaxLat = ds.wirelessnetwork[i].gpsinfo.maxlat;
                                if (Kisdata.GPSMaxLon > ds.wirelessnetwork[i].gpsinfo.maxlon)
                                    Kisdata.GPSMaxLon=ds.wirelessnetwork[i].gpsinfo.maxlon;
                                if(Kisdata.GPSMinLat < ds.wirelessnetwork[i].gpsinfo.minlat)
                                    Kisdata.GPSMinLat=ds.wirelessnetwork[i].gpsinfo.minlat;
                                if(Kisdata.GPSMinLon < ds.wirelessnetwork[i].gpsinfo.minlon)
                                    Kisdata.GPSMinLon=ds.wirelessnetwork[i].gpsinfo.minlon;
                                if(xmlfirsttime  < dbfirsttime)
                                {
                                    Kisdata.FirstTime=ds.wirelessnetwork[i].firsttime;
                                }
                                if(xmllasttime > dblasttime)
                                {
                                    Kisdata.LastTime=ds.wirelessnetwork[i].lasttime;
                                }

                                //if(ds.wirelessnetwork[i].wirelessclient != null)
                                //{
                                //AddorUpdateClientsSqlite(ds, i, theClientData);
                                //}
                                Kisdata.Save();
                            }
                            else
                            {
                                AddDataTableSqlite(Kisdata, ds, i);

                                //if(ds.wirelessnetwork[i].wirelessclient != null)
                                //{
                                //AddorUpdateClientsSqlite(ds, i, theClientData);
                                //}
                                //Kisdata.Save();
                            }
                            if(ds.wirelessnetwork[i].wirelessclient != null)
                            {
                                AddorUpdateClientsSqlite(ds, i, theClientData);
                                //AddorUpdateClientsSqliteNew(ds, i, theClientData);

                            }
                            Kisdata.Save();

                        }
                    }
                    catch(Exception ex)
                    {
                        Console.WriteLine(ex);
                    }

                }

            }
            //db.Close();
        }
         */
        private static void ProcessXMLFilesNew(DirectoryInfo dir)
        {
            SQLiteConnectionStringBuilder builder = new SQLiteConnectionStringBuilder();
            builder.DataSource = string.Format("{0}\\kismetdata.db", Application.StartupPath);
            builder.SyncMode = SynchronizationModes.Off;
            builder.CacheSize = 5000;
            //DataTable t;

            FilesTableAdapter thegpsfilesadaptor = new FilesTableAdapter();
            DatanewTableAdapter thedatanewtableadaptor = new DatanewTableAdapter();
            statsTableAdapter thestatsadaptor = new statsTableAdapter();
            ClientsTableAdapter theclientstableadaptor = new ClientsTableAdapter();
            SQLiteConnection connection = new SQLiteConnection(builder.ToString());
            //SQLiteCommand command = connection.CreateCommand();
            connection.Open();
            //gpsfiles thegpsfiles = new gpsfiles();
            //clientdata theClientData = new clientdata();
            //thedata Kisdata = new thedata();
            //ssidchanges thessidchanges = new ssidchanges();
            //thessidchanges.ConnectionString = theconnectionstring;
            //Kisdata.ConnectionString = theconnectionstring;
            //theClientData.ConnectionString = theconnectionstring;
            //thegpsfiles.ConnectionString = theconnectionstring;
            SQLiteCommand insertssidchanges = connection.CreateCommand();
            int networknew = 0;
            int networkseen = 0;
            int clientnew = 0;
            int clientseen = 0;
            int networktotal = 0;
            int clienttotal = 0;
            SQLiteCommand insertdatacmd = connection.CreateCommand();
            SQLiteCommand updatedatacmd = connection.CreateCommand();

            insertssidchanges.CommandText = "Insert into ssidchanges values(?,?,?,?)";
            insertdatacmd.CommandText =
                "Insert into data values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
            updatedatacmd.CommandText =
                @"UPDATE [Data] SET
                [oui]=?,
                [totalpacketsweak]=?,
                [totalpacketstotal]=?,
                [totalpacketsllc]=?,
                [totalpacketsdupeiv]=?,
                [totalpacketsdata]=?,
                [totalpacketscrypt]=?,
                [Network]=?,
                [NetType]=?,
                [ESSID]=?,
                [Info]=?,
                [Channel]=?,
                [Cloaked]=?,
                [Encryption]=?,
                [Decrypted]=?,
                [MaxRate]=?,
                [MaxSeenRate]=?,
                [Beacon]=?,
                [LLC]=?,
                [Data]=?,
                [Crypt]=?,
                [Weak]=?,
                [Total]=?,
                [Carrier]=?,
                [Encoding]=?,
                [FirstTime]=?,
                [LastTime]=?,
                [BestQuality]=?,
                [BestSignal]=?,
                [BestNoise]=?,
                [GPSMinLat]=?,
                [GPSMinLon]=?,
                [GPSMinAlt]=?,
                [GPSMinSpd]=?,
                [GPSMaxLat]=?,
                [GPSMaxLon]=?,
                [GPSMaxAlt]=?,
                [GPSMaxSpd]=?,
                [GPSBestLat]=?,
                [GPSBestLon]=?,
                [GPSBestAlt]=?,
                [Datasize]=?,
                [IPType]=?,
                [IP]=?
            WHERE
                [BSSID]=?";

            SQLiteParameter ssidbssid = insertssidchanges.CreateParameter();
            SQLiteParameter ssiddate = insertssidchanges.CreateParameter();
            SQLiteParameter ssidoldname = insertssidchanges.CreateParameter();
            SQLiteParameter ssidnewname = insertssidchanges.CreateParameter();
            insertssidchanges.Parameters.Add(ssidbssid);
            insertssidchanges.Parameters.Add(ssiddate);
            insertssidchanges.Parameters.Add(ssidoldname);
            insertssidchanges.Parameters.Add(ssidnewname);

            SQLiteParameter dataoui = insertdatacmd.CreateParameter();
            SQLiteParameter updateoui = updatedatacmd.CreateParameter();
            insertdatacmd.Parameters.Add(dataoui);
            updatedatacmd.Parameters.Add(updateoui);
            SQLiteParameter Totalpacketsweak = insertdatacmd.CreateParameter();
            SQLiteParameter updateTotalpacketsweak = updatedatacmd.CreateParameter();
            insertdatacmd.Parameters.Add(Totalpacketsweak);
            updatedatacmd.Parameters.Add(updateTotalpacketsweak);
            SQLiteParameter Totalpacketstotal = insertdatacmd.CreateParameter();
            SQLiteParameter updateTotalpacketstotal = updatedatacmd.CreateParameter();
            insertdatacmd.Parameters.Add(Totalpacketstotal);
            updatedatacmd.Parameters.Add(updateTotalpacketstotal);
            SQLiteParameter Totalpacketsllc = insertdatacmd.CreateParameter();
            SQLiteParameter updateTotalpacketsllc = updatedatacmd.CreateParameter();
            insertdatacmd.Parameters.Add(Totalpacketsllc);
            updatedatacmd.Parameters.Add(updateTotalpacketsllc);
            SQLiteParameter Totalpacketsdupeiv = insertdatacmd.CreateParameter();
            SQLiteParameter updateTotalpacketsdupeiv = updatedatacmd.CreateParameter();
            insertdatacmd.Parameters.Add(Totalpacketsdupeiv);
            updatedatacmd.Parameters.Add(updateTotalpacketsdupeiv);
            SQLiteParameter Totalpacketsdata = insertdatacmd.CreateParameter();
            SQLiteParameter updateTotalpacketsdata = updatedatacmd.CreateParameter();
            insertdatacmd.Parameters.Add(Totalpacketsdata);
            updatedatacmd.Parameters.Add(updateTotalpacketsdata);
            SQLiteParameter Totalpacketscrypt = insertdatacmd.CreateParameter();
            SQLiteParameter updateTotalpacketscrypt = updatedatacmd.CreateParameter();
            insertdatacmd.Parameters.Add(Totalpacketscrypt);
            updatedatacmd.Parameters.Add(updateTotalpacketscrypt);
            SQLiteParameter Network = insertdatacmd.CreateParameter();
            SQLiteParameter updateNetwork = updatedatacmd.CreateParameter();
            insertdatacmd.Parameters.Add(Network);
            updatedatacmd.Parameters.Add(updateNetwork);
            SQLiteParameter updateNetType = updatedatacmd.CreateParameter();
            SQLiteParameter NetType = insertdatacmd.CreateParameter();
            insertdatacmd.Parameters.Add(NetType);
            updatedatacmd.Parameters.Add(updateNetType);
            SQLiteParameter ESSID = insertdatacmd.CreateParameter();
            SQLiteParameter updateESSID = updatedatacmd.CreateParameter();
            insertdatacmd.Parameters.Add(ESSID);
            updatedatacmd.Parameters.Add(updateESSID);
            SQLiteParameter BSSID = insertdatacmd.CreateParameter();

            insertdatacmd.Parameters.Add(BSSID);
            SQLiteParameter Info = insertdatacmd.CreateParameter();
            SQLiteParameter updateInfo = updatedatacmd.CreateParameter();
            insertdatacmd.Parameters.Add(Info);
            updatedatacmd.Parameters.Add(updateInfo);
            SQLiteParameter Channel = insertdatacmd.CreateParameter();
            SQLiteParameter updateChannel = updatedatacmd.CreateParameter();
            insertdatacmd.Parameters.Add(Channel);
            updatedatacmd.Parameters.Add(updateChannel);
            SQLiteParameter updateCloaked = updatedatacmd.CreateParameter();
            SQLiteParameter Cloaked = insertdatacmd.CreateParameter();
            insertdatacmd.Parameters.Add(Cloaked);
            updatedatacmd.Parameters.Add(updateCloaked);
            SQLiteParameter Encryption = insertdatacmd.CreateParameter();
            SQLiteParameter updateEncryption = updatedatacmd.CreateParameter();
            insertdatacmd.Parameters.Add(Encryption);
            updatedatacmd.Parameters.Add(updateEncryption);
            SQLiteParameter updateDecrypted = updatedatacmd.CreateParameter();
            SQLiteParameter Decrypted = insertdatacmd.CreateParameter();
            insertdatacmd.Parameters.Add(Decrypted);
            updatedatacmd.Parameters.Add(updateDecrypted);
            SQLiteParameter MaxRate = insertdatacmd.CreateParameter();
            SQLiteParameter updateMaxRate = updatedatacmd.CreateParameter();
            insertdatacmd.Parameters.Add(MaxRate);
            updatedatacmd.Parameters.Add(updateMaxRate);
            SQLiteParameter MaxSeenRate = insertdatacmd.CreateParameter();
            SQLiteParameter updateMaxSeenRate = updatedatacmd.CreateParameter();
            insertdatacmd.Parameters.Add(MaxSeenRate);
            updatedatacmd.Parameters.Add(updateMaxSeenRate);
            SQLiteParameter Beacon = insertdatacmd.CreateParameter();
            SQLiteParameter updateBeacon = updatedatacmd.CreateParameter();
            insertdatacmd.Parameters.Add(Beacon);
            updatedatacmd.Parameters.Add(updateBeacon);
            SQLiteParameter LLC = insertdatacmd.CreateParameter();
            SQLiteParameter updateLLC = updatedatacmd.CreateParameter();
            insertdatacmd.Parameters.Add(LLC);
            updatedatacmd.Parameters.Add(updateLLC);
            SQLiteParameter Data = insertdatacmd.CreateParameter();
            SQLiteParameter updateData = updatedatacmd.CreateParameter();

            insertdatacmd.Parameters.Add(Data);
            updatedatacmd.Parameters.Add(updateData);
            SQLiteParameter Crypt = insertdatacmd.CreateParameter();
            SQLiteParameter updateCrypt = updatedatacmd.CreateParameter();
            insertdatacmd.Parameters.Add(Crypt);
            updatedatacmd.Parameters.Add(updateCrypt);
            SQLiteParameter Weak = insertdatacmd.CreateParameter();
            SQLiteParameter updateWeak = updatedatacmd.CreateParameter();
            insertdatacmd.Parameters.Add(Weak);
            updatedatacmd.Parameters.Add(updateWeak);
            SQLiteParameter Total = insertdatacmd.CreateParameter();
            SQLiteParameter updateTotal = updatedatacmd.CreateParameter();
            insertdatacmd.Parameters.Add(Total);
            updatedatacmd.Parameters.Add(updateTotal);
            SQLiteParameter Carrier = insertdatacmd.CreateParameter();
            SQLiteParameter updateCarrier = updatedatacmd.CreateParameter();
            insertdatacmd.Parameters.Add(Carrier);
            updatedatacmd.Parameters.Add(updateCarrier);
            SQLiteParameter Encoding = insertdatacmd.CreateParameter();
            SQLiteParameter updateEncoding = updatedatacmd.CreateParameter();
            insertdatacmd.Parameters.Add(Encoding);
            updatedatacmd.Parameters.Add(updateEncoding);
            SQLiteParameter FirstTime = insertdatacmd.CreateParameter();
            SQLiteParameter updateFirstTime = updatedatacmd.CreateParameter();
            insertdatacmd.Parameters.Add(FirstTime);
            updatedatacmd.Parameters.Add(updateFirstTime);
            SQLiteParameter LastTime = insertdatacmd.CreateParameter();
            SQLiteParameter updateLastTime = updatedatacmd.CreateParameter();
            insertdatacmd.Parameters.Add(LastTime);
            updatedatacmd.Parameters.Add(updateLastTime);
            SQLiteParameter BestQuality = insertdatacmd.CreateParameter();
            SQLiteParameter updateBestQuality = updatedatacmd.CreateParameter();
            insertdatacmd.Parameters.Add(BestQuality);
            updatedatacmd.Parameters.Add(updateBestQuality);
            SQLiteParameter BestSignal = insertdatacmd.CreateParameter();
            SQLiteParameter updateBestSignal = updatedatacmd.CreateParameter();
            insertdatacmd.Parameters.Add(BestSignal);
            updatedatacmd.Parameters.Add(updateBestSignal);
            SQLiteParameter BestNoise = insertdatacmd.CreateParameter();
            SQLiteParameter updateBestNoise = updatedatacmd.CreateParameter();
            insertdatacmd.Parameters.Add(BestNoise);
            updatedatacmd.Parameters.Add(updateBestNoise);
            SQLiteParameter GPSMinLat = insertdatacmd.CreateParameter();
            SQLiteParameter updateGPSMinLat = updatedatacmd.CreateParameter();
            insertdatacmd.Parameters.Add(GPSMinLat);
            updatedatacmd.Parameters.Add(updateGPSMinLat);
            SQLiteParameter GPSMinLon = insertdatacmd.CreateParameter();
            SQLiteParameter updateGPSMinLon = updatedatacmd.CreateParameter();
            insertdatacmd.Parameters.Add(GPSMinLon);
            updatedatacmd.Parameters.Add(updateGPSMinLon);
            SQLiteParameter GPSMinAlt = insertdatacmd.CreateParameter();
            SQLiteParameter updateGPSMinAlt = updatedatacmd.CreateParameter();

            insertdatacmd.Parameters.Add(GPSMinAlt);
            updatedatacmd.Parameters.Add(updateGPSMinAlt);
            SQLiteParameter GPSMinSpd = insertdatacmd.CreateParameter();
            SQLiteParameter updateGPSMinSpd = updatedatacmd.CreateParameter();
            insertdatacmd.Parameters.Add(GPSMinSpd);
            updatedatacmd.Parameters.Add(updateGPSMinSpd);
            SQLiteParameter GPSMaxLat = insertdatacmd.CreateParameter();
            SQLiteParameter updateGPSMaxLat = updatedatacmd.CreateParameter();
            insertdatacmd.Parameters.Add(GPSMaxLat);
            updatedatacmd.Parameters.Add(updateGPSMaxLat);
            SQLiteParameter GPSMaxLon = insertdatacmd.CreateParameter();
            SQLiteParameter updateGPSMaxLon = updatedatacmd.CreateParameter();
            insertdatacmd.Parameters.Add(GPSMaxLon);
            updatedatacmd.Parameters.Add(updateGPSMaxLon);
            SQLiteParameter GPSMaxAlt = insertdatacmd.CreateParameter();
            SQLiteParameter updateGPSMaxAlt = updatedatacmd.CreateParameter();
            insertdatacmd.Parameters.Add(GPSMaxAlt);
            updatedatacmd.Parameters.Add(updateGPSMaxAlt);
            SQLiteParameter GPSMaxSpd = insertdatacmd.CreateParameter();
            SQLiteParameter updateGPSMaxSpd = updatedatacmd.CreateParameter();
            insertdatacmd.Parameters.Add(GPSMaxSpd);
            updatedatacmd.Parameters.Add(updateGPSMaxSpd);
            SQLiteParameter GPSBestLat = insertdatacmd.CreateParameter();
            SQLiteParameter updateGPSBestLat = updatedatacmd.CreateParameter();

            insertdatacmd.Parameters.Add(GPSBestLat);
            updatedatacmd.Parameters.Add(updateGPSBestLat);
            SQLiteParameter GPSBestLon = insertdatacmd.CreateParameter();
            SQLiteParameter updateGPSBestLon = updatedatacmd.CreateParameter();
            insertdatacmd.Parameters.Add(GPSBestLon);
            updatedatacmd.Parameters.Add(updateGPSBestLon);
            SQLiteParameter GPSBestAlt = insertdatacmd.CreateParameter();
            SQLiteParameter updateGPSBestAlt = updatedatacmd.CreateParameter();
            insertdatacmd.Parameters.Add(GPSBestAlt);
            updatedatacmd.Parameters.Add(updateGPSBestAlt);
            SQLiteParameter Datasize = insertdatacmd.CreateParameter();
            SQLiteParameter updateDatasize = updatedatacmd.CreateParameter();
            insertdatacmd.Parameters.Add(Datasize);
            updatedatacmd.Parameters.Add(updateDatasize);
            SQLiteParameter IPType = insertdatacmd.CreateParameter();
            SQLiteParameter updateIPType = updatedatacmd.CreateParameter();
            insertdatacmd.Parameters.Add(IPType);
            updatedatacmd.Parameters.Add(updateIPType);
            SQLiteParameter IP = insertdatacmd.CreateParameter();
            SQLiteParameter updateIP = updatedatacmd.CreateParameter();
            insertdatacmd.Parameters.Add(IP);
            updatedatacmd.Parameters.Add(updateIP);

            SQLiteParameter updateBSSID = updatedatacmd.CreateParameter();
            updatedatacmd.Parameters.Add(updateBSSID);

            SQLiteCommand insertclients = connection.CreateCommand();
            SQLiteCommand updateclients = connection.CreateCommand();
            insertclients.CommandText = "Insert into clients values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
            updateclients.CommandText =
                @"UPDATE [Clients] SET
                [Clientipaddress]=?,
                [oui]=?,
                [clientencryption]=?,
                [clientfirsttime]=?,
                [clientgpsminlat]=?,
                [clientgpsminlon]=?,
                [clientgpsmaxlat]=?,
                [clientgpsmaxlon]=?,
                [clientgpsminalt]=?,
                [clientgpsmaxalt]=?,
                [clientgpsminspeed]=?,
                [clientgpsmaxspeed]=?,
                [clientdatasize]=?,
                [clientmaxrate]=?,
                [clientmaxseenrate]=?,
                [clientlasttime]=?,
                [clientpacketscrypt]=?,
                [clientpacketsdata]=?,
                [clientpacketsweak]=?,
                [Number]=?,
                [Type]=?,
                [wep]=?
            WHERE
                [bssid]=? AND
                [clientmac]=?";
            SQLiteParameter Clientipaddress = insertclients.CreateParameter();
            SQLiteParameter updateClientipaddress = updateclients.CreateParameter();
            SQLiteParameter insertoui = insertclients.CreateParameter();
            SQLiteParameter clientupdateoui = updateclients.CreateParameter();
            SQLiteParameter bssid = insertclients.CreateParameter();

            SQLiteParameter clientmac = insertclients.CreateParameter();

            SQLiteParameter clientencryption = insertclients.CreateParameter();
            SQLiteParameter updateclientencryption = updateclients.CreateParameter();
            SQLiteParameter clientfirsttime = insertclients.CreateParameter();
            SQLiteParameter updateclientfirsttime = updateclients.CreateParameter();
            SQLiteParameter clientgpsminlat = insertclients.CreateParameter();
            SQLiteParameter clientgpsminlon = insertclients.CreateParameter();
            SQLiteParameter clientgpsmaxlat = insertclients.CreateParameter();
            SQLiteParameter clientgpsmaxlon = insertclients.CreateParameter();
            SQLiteParameter clientgpsminalt = insertclients.CreateParameter();
            SQLiteParameter clientgpsmaxalt = insertclients.CreateParameter();
            SQLiteParameter clientgpsminspeed = insertclients.CreateParameter();
            SQLiteParameter clientgpsmaxspeed = insertclients.CreateParameter();
            SQLiteParameter clientdatasize = insertclients.CreateParameter();
            SQLiteParameter clientmaxrate = insertclients.CreateParameter();
            SQLiteParameter clientmaxseenrate = insertclients.CreateParameter();
            SQLiteParameter clientlasttime = insertclients.CreateParameter();
            SQLiteParameter clientpacketscrypt = insertclients.CreateParameter();
            SQLiteParameter clientpacketsdata = insertclients.CreateParameter();
            SQLiteParameter clientpacketsweak = insertclients.CreateParameter();
            SQLiteParameter Number = insertclients.CreateParameter();
            SQLiteParameter Type = insertclients.CreateParameter();
            SQLiteParameter wep = insertclients.CreateParameter();

            SQLiteParameter updateclientgpsminlat = updateclients.CreateParameter();
            SQLiteParameter updateclientgpsminlon = updateclients.CreateParameter();
            SQLiteParameter updateclientgpsmaxlat = updateclients.CreateParameter();
            SQLiteParameter updateclientgpsmaxlon = updateclients.CreateParameter();
            SQLiteParameter updateclientgpsminalt = updateclients.CreateParameter();
            SQLiteParameter updateclientgpsmaxalt = updateclients.CreateParameter();
            SQLiteParameter updateclientgpsminspeed = updateclients.CreateParameter();
            SQLiteParameter updateclientgpsmaxspeed = updateclients.CreateParameter();
            SQLiteParameter updateclientdatasize = updateclients.CreateParameter();
            SQLiteParameter updateclientmaxrate = updateclients.CreateParameter();
            SQLiteParameter updateclientmaxseenrate = updateclients.CreateParameter();
            SQLiteParameter updateclientlasttime = updateclients.CreateParameter();
            SQLiteParameter updateclientpacketscrypt = updateclients.CreateParameter();
            SQLiteParameter updateclientpacketsdata = updateclients.CreateParameter();
            SQLiteParameter updateclientpacketsweak = updateclients.CreateParameter();
            SQLiteParameter updateNumber = updateclients.CreateParameter();
            SQLiteParameter updateType = updateclients.CreateParameter();
            SQLiteParameter updatewep = updateclients.CreateParameter();
            SQLiteParameter updatebssid = insertclients.CreateParameter();
            SQLiteParameter updateclientmac = updateclients.CreateParameter();

            insertclients.Parameters.Add(Clientipaddress);
            insertclients.Parameters.Add(insertoui);
            insertclients.Parameters.Add(bssid);
            insertclients.Parameters.Add(clientmac);
            insertclients.Parameters.Add(clientencryption);
            insertclients.Parameters.Add(clientfirsttime);
            insertclients.Parameters.Add(clientgpsminlat);
            insertclients.Parameters.Add(clientgpsminlon);
            insertclients.Parameters.Add(clientgpsmaxlat);
            insertclients.Parameters.Add(clientgpsmaxlon);
            insertclients.Parameters.Add(clientgpsminalt);
            insertclients.Parameters.Add(clientgpsmaxalt);
            insertclients.Parameters.Add(clientgpsminspeed);
            insertclients.Parameters.Add(clientgpsmaxspeed);
            insertclients.Parameters.Add(clientdatasize);
            insertclients.Parameters.Add(clientmaxrate);
            insertclients.Parameters.Add(clientmaxseenrate);
            insertclients.Parameters.Add(clientlasttime);
            insertclients.Parameters.Add(clientpacketscrypt);
            insertclients.Parameters.Add(clientpacketsdata);
            insertclients.Parameters.Add(clientpacketsweak);
            insertclients.Parameters.Add(Number);
            insertclients.Parameters.Add(Type);
            insertclients.Parameters.Add(wep);

            updateclients.Parameters.Add(updateClientipaddress);
            updateclients.Parameters.Add(clientupdateoui);

            updateclients.Parameters.Add(updateclientencryption);
            updateclients.Parameters.Add(updateclientfirsttime);
            updateclients.Parameters.Add(updateclientgpsminlat);
            updateclients.Parameters.Add(updateclientgpsminlon);
            updateclients.Parameters.Add(updateclientgpsmaxlat);
            updateclients.Parameters.Add(updateclientgpsmaxlon);
            updateclients.Parameters.Add(updateclientgpsminalt);
            updateclients.Parameters.Add(updateclientgpsmaxalt);
            updateclients.Parameters.Add(updateclientgpsminspeed);
            updateclients.Parameters.Add(updateclientgpsmaxspeed);
            updateclients.Parameters.Add(updateclientdatasize);
            updateclients.Parameters.Add(updateclientmaxrate);
            updateclients.Parameters.Add(updateclientmaxseenrate);
            updateclients.Parameters.Add(updateclientlasttime);
            updateclients.Parameters.Add(updateclientpacketscrypt);
            updateclients.Parameters.Add(updateclientpacketsdata);
            updateclients.Parameters.Add(updateclientpacketsweak);
            updateclients.Parameters.Add(updateNumber);
            updateclients.Parameters.Add(updateType);
            updateclients.Parameters.Add(updatewep);
            updateclients.Parameters.Add(updatebssid);
            updateclients.Parameters.Add(updateclientmac);

            XmlSerializer xs = new XmlSerializer(typeof (detectionrun));

            //ObjectContainer db = Db4o.OpenFile("c:\\testdb.db");
            DataTable t;
            DateTime dbfirsttime = new DateTime();
            DateTime xmlfirsttime = new DateTime();
            DateTime dblasttime = new DateTime();
            DateTime xmllasttime = new DateTime();
            FileInfo[] fis = dir.GetFiles("Kismet*.xml");
            Array.Sort(fis, new CompareFileTime());

            detectionrun ds;
            //for (int ij = 0; ij < fis.Length; ij++)
            //{
            foreach (FileInfo f in dir.GetFiles("Kismet*.xml"))
            {
                //FileInfo f = fis[ij];
                t = thegpsfilesadaptor.GetDataByFilename(f.Name);
                if (t.Rows.Count == 0)
                {
                    //thegpsfiles.AddNew();
                    //thegpsfiles.Filename=f.Name;
                    //thegpsfiles.Save();
                    InsertFilename(thegpsfilesadaptor, f);
                    Console.WriteLine("Processing " + f.Name);
                    FileStream fs = new FileStream(f.DirectoryName + "\\" + f.Name, FileMode.Open);
                    try
                    {
                        ds = (detectionrun) xs.Deserialize(fs);
                        //clientdata theClientData = new clientdata();
                        //thedata Kisdata = new thedata();
                        //Kisdata.ConnectionString=theconnectionstring;
                        //theClientData.ConnectionString=theconnectionstring;
                        int thedatalength;
                        thedatalength = ds.wirelessnetwork.Length;
                        networktotal = thedatalength;
                        //IFormatProvider format = new CultureInfo("en-US");
                        for (int i = 0; i < thedatalength; i++)
                        {
                            //Network network1=new Network(ds.wirelessnetwork[i].BSSID, ds.wirelessnetwork[i].SSID);
                            //db.Set(network1);
                            t = thedatanewtableadaptor.GetDataByBssid(ds.wirelessnetwork[i].BSSID);

                            if (t.Rows.Count != 0)
                            {
                                networkseen++;
                                DataTableReader thereader = t.CreateDataReader();
                                thereader.Read();

                                string firsttime = thereader["firsttime"].ToString();
                                string lasttime = thereader["lasttime"].ToString();

                                //string[] expectedformats = {"ddd MMM  d HH:mm:ss yyyy", "ddd MMM d HH:mm:ss yyyy"};
                                //string[] expectedformats = {"YYYY-MM-DD HH:mm:ss"};

                                // Wed Mar 29 14:52:56 2006
                                try
                                {
                                    DateTime.TryParse(firsttime, out dbfirsttime);
                                    DateTime.TryParse(GetNewtime(ds.wirelessnetwork[i].firsttime), out xmlfirsttime);
                                    DateTime.TryParse(lasttime, out dblasttime);
                                    DateTime.TryParse(GetNewtime(ds.wirelessnetwork[i].lasttime), out xmllasttime);

                                }
                                catch (FormatException ex)
                                {
                                    Console.WriteLine(ex.ToString());
                                    Console.WriteLine(firsttime);
                                    Console.WriteLine(xmlfirsttime);
                                    Console.WriteLine(dblasttime);
                                    Console.WriteLine(xmllasttime);
                                }
                                if ((thereader["essid"].ToString() != ds.wirelessnetwork[i].SSID) &&
                                    ds.wirelessnetwork[i].SSID != null)
                                {
                                    Console.WriteLine("Old SSID " + thereader["essid"] + " New SSID " +
                                                      ds.wirelessnetwork[i].SSID);
                                    ssidbssid.Value = thereader["bssid"];
                                    //thessidchanges.AddNew();
                                    ssiddate.Value = xmllasttime;
                                    ssidoldname.Value = thereader["essid"].ToString();
                                    ssidnewname.Value = ds.wirelessnetwork[i].SSID;
                                    insertssidchanges.ExecuteNonQuery();

                                    updateESSID.Value = ds.wirelessnetwork[i].SSID;

                                    //Kisdata.ESSID = ds.wirelessnetwork[i].SSID;
                                }
                                else
                                {
                                    updateESSID.Value = thereader["ESSID"];
                                }
                                updateTotalpacketscrypt.Value =
                                    Convert.ToInt32(thereader["Totalpacketscrypt"]) +
                                    ds.wirelessnetwork[i].packets.crypt;
                                updateTotalpacketsdata.Value = Convert.ToInt32(thereader["Totalpacketsdata"]) +
                                                               ds.wirelessnetwork[i].packets.data;
                                updateTotalpacketsdupeiv.Value = Convert.ToInt32(thereader["Totalpacketsdupeiv"]) +
                                                                 ds.wirelessnetwork[i].packets.dupeiv;
                                updateTotalpacketsllc.Value = Convert.ToInt32(thereader["Totalpacketsllc"]) +
                                                              ds.wirelessnetwork[i].packets.LLC;
                                updateTotalpacketstotal.Value = Convert.ToInt32(thereader["Totalpacketstotal"]) +
                                                                ds.wirelessnetwork[i].packets.total;
                                updateTotalpacketsweak.Value = Convert.ToInt32(thereader["Totalpacketsweak"]) +
                                                               ds.wirelessnetwork[i].packets.weak;
                                updateCloaked.Value = ds.wirelessnetwork[i].cloaked;
                                updateoui.Value = thereader["oui"];
                                updateNetwork.Value = thereader["Network"];
                                //updateEncryption.Value = thereader["Encryption"];
                                updateEncryption.Value = enchash[ds.wirelessnetwork[i].BSSID];
                                updateNetType.Value = thereader["NetType"];
                                updateMaxRate.Value = ds.wirelessnetwork[i].maxrate;
                                updateMaxSeenRate.Value = ds.wirelessnetwork[i].maxseenrate;
                                if (Convert.ToInt16(thereader["GPSMaxLat"]) > ds.wirelessnetwork[i].gpsinfo.maxlat)
                                {
                                    updateGPSMaxLat.Value = ds.wirelessnetwork[i].gpsinfo.maxlat;
                                }
                                else
                                {
                                    updateGPSMaxLat.Value = thereader["GPSMaxLat"];
                                }
                                if (Convert.ToInt16(thereader["GPSMaxLon"]) > ds.wirelessnetwork[i].gpsinfo.maxlon)
                                {
                                    updateGPSMaxLon.Value = ds.wirelessnetwork[i].gpsinfo.maxlon;
                                }
                                else
                                {
                                    updateGPSMaxLon.Value = thereader["GPSMaxLon"];
                                }
                                if (Convert.ToInt16(thereader["GPSMinLat"]) < ds.wirelessnetwork[i].gpsinfo.minlat)
                                {
                                    updateGPSMinLat.Value = ds.wirelessnetwork[i].gpsinfo.minlat;
                                }
                                else
                                {
                                    updateGPSMinLat.Value = thereader["GPSMinLat"];
                                }
                                updateGPSMinLon.Value = Convert.ToInt16(thereader["GPSMinLon"]) <
                                                        ds.wirelessnetwork[i].gpsinfo.minlon
                                                            ? ds.wirelessnetwork[i].gpsinfo.minlon
                                                            : thereader["GPSMinLon"];
                                if (xmlfirsttime < dbfirsttime)
                                {
                                    updateFirstTime.Value = xmlfirsttime;
                                }
                                else
                                {
                                    updateFirstTime.Value = dbfirsttime;
                                }
                                if (xmllasttime > dblasttime)
                                {
                                    updateLastTime.Value = xmllasttime;
                                }
                                else
                                {
                                    updateLastTime.Value = dblasttime;
                                }
                                updateBSSID.Value = ds.wirelessnetwork[i].BSSID;

                                //{"The database file is locked\r\nUnable to close due to unfinalised statements"}
                                //updateESSID.Value=thereader["ESSID"];
                                //if(ds.wirelessnetwork[i].wirelessclient != null)
                                //{
                                //AddorUpdateClientsSqlite(ds, i, theClientData);
                                //}
                                thereader.Close();
                                try
                                {
                                    updatedatacmd.ExecuteNonQuery();
                                }
                                catch (Exception ex)
                                {
                                    Console.WriteLine(ex.ToString());
                                }
                            }
                            else
                            {
                                //AddDataTableSqlite(Kisdata, ds, i);
                                networknew++;
                                //AddDataTableNew(ds, i, insertdatacmd);
                                dataoui.Value = LookupOuiData(ds.wirelessnetwork[i].BSSID);
                                Cloaked.Value = ds.wirelessnetwork[i].cloaked;
                                FirstTime.Value = GetNewtime(ds.wirelessnetwork[i].firsttime);
                                LastTime.Value = GetNewtime(ds.wirelessnetwork[i].lasttime);
                                BSSID.Value = ds.wirelessnetwork[i].BSSID;
                                Network.Value = ds.wirelessnetwork[i].number;
                                NetType.Value = ds.wirelessnetwork[i].type;
                                Channel.Value = ds.wirelessnetwork[i].channel;
                                Encryption.Value = enchash[ds.wirelessnetwork[i].BSSID];
                                Totalpacketscrypt.Value = ds.wirelessnetwork[i].packets.crypt;
                                Totalpacketsdata.Value = ds.wirelessnetwork[i].packets.data;
                                Totalpacketsdupeiv.Value = ds.wirelessnetwork[i].packets.dupeiv;
                                Totalpacketsllc.Value = ds.wirelessnetwork[i].packets.LLC;
                                Totalpacketstotal.Value = ds.wirelessnetwork[i].packets.total;
                                Totalpacketsweak.Value = ds.wirelessnetwork[i].packets.weak;
                                MaxRate.Value = ds.wirelessnetwork[i].maxrate;
                                MaxSeenRate.Value = ds.wirelessnetwork[i].maxseenrate;
                                ESSID.Value = ds.wirelessnetwork[i].SSID ?? "no ssid";
                                GPSMaxLat.Value = ds.wirelessnetwork[i].gpsinfo.maxlat;
                                GPSMaxLon.Value = ds.wirelessnetwork[i].gpsinfo.maxlon;
                                GPSMinLat.Value = ds.wirelessnetwork[i].gpsinfo.minlat;
                                GPSMinLon.Value = ds.wirelessnetwork[i].gpsinfo.minlon;
                                insertdatacmd.ExecuteNonQuery();

                                //00:0D:3A:28:24:E9
                                //if(ds.wirelessnetwork[i].wirelessclient != null)
                                //{
                                //AddorUpdateClientsSqlite(ds, i, theClientData);
                                //}
                                //Kisdata.Save();
                            }
                            if (ds.wirelessnetwork[i].wirelessclient != null)
                            {
                                //AddorUpdateClientsSqlite(ds, i, theClientData);
                                //AddorUpdateClientsSqliteNew(ref ds, i, ref clienttotal, ref clientnew, ref clientseen);

                                //DataTable t;
                                clienttotal += ds.wirelessnetwork[i].wirelessclient.Length;
                                for (int j = 0; j < ds.wirelessnetwork[i].wirelessclient.Length; j++)
                                {
                                    t =
                                        theclientstableadaptor.GetDataByClientBssid(
                                            ds.wirelessnetwork[i].wirelessclient[j].clientmac,
                                            ds.wirelessnetwork[i].BSSID);
                                    if (t.Rows.Count == 0)
                                    {
                                        //theClientData.AddNew();
                                        //Console.WriteLine("Client Add");
                                        clientnew++;
                                        bssid.Value = ds.wirelessnetwork[i].BSSID;
                                        insertoui.Value =
                                            LookupOuiData(ds.wirelessnetwork[i].wirelessclient[j].clientmac);
                                        clientmac.Value = ds.wirelessnetwork[i].wirelessclient[j].clientmac;
                                        clientdatasize.Value = ds.wirelessnetwork[i].wirelessclient[j].clientdatasize;
                                        clientencryption.Value =
                                            ds.wirelessnetwork[i].wirelessclient[j].clientencryption;
                                        clientfirsttime.Value = GetNewtime(ds.wirelessnetwork[i].wirelessclient[j].firsttime);
                                        clientlasttime.Value = GetNewtime(ds.wirelessnetwork[i].wirelessclient[j].lasttime);
                                        if (ds.wirelessnetwork[i].wirelessclient[j].clientgpsinfo != null)
                                        {
                                            clientgpsmaxalt.Value =
                                                ds.wirelessnetwork[i].wirelessclient[j].clientgpsinfo.clientmaxalt;
                                            clientgpsmaxlat.Value =
                                                ds.wirelessnetwork[i].wirelessclient[j].clientgpsinfo.clientmaxlat;
                                            clientgpsmaxlon.Value =
                                                ds.wirelessnetwork[i].wirelessclient[j].clientgpsinfo.clientmaxlon;
                                            clientgpsminalt.Value =
                                                ds.wirelessnetwork[i].wirelessclient[j].clientgpsinfo.clientminalt;
                                            clientgpsminlat.Value =
                                                ds.wirelessnetwork[i].wirelessclient[j].clientgpsinfo.clientminlat;
                                            clientgpsminlon.Value =
                                                ds.wirelessnetwork[i].wirelessclient[j].clientgpsinfo.clientminlon;
                                        }
                                        clientmaxrate.Value = ds.wirelessnetwork[i].wirelessclient[j].clientmaxrate;
                                        if (ds.wirelessnetwork[i].wirelessclient[j].clientipaddress != null)
                                        {
                                            Clientipaddress.Value =
                                                ds.wirelessnetwork[i].wirelessclient[j].clientipaddress;
                                        }
                                        clientmaxseenrate.Value =
                                            ds.wirelessnetwork[i].wirelessclient[j].clientmaxseenrate;
                                        clientpacketscrypt.Value =
                                            ds.wirelessnetwork[i].wirelessclient[j].clientpackets.clientcrypt;
                                        clientpacketsdata.Value =
                                            ds.wirelessnetwork[i].wirelessclient[j].clientpackets.clientdata;
                                        clientpacketsweak.Value =
                                            ds.wirelessnetwork[i].wirelessclient[j].clientpackets.clientweak;

                                        insertclients.ExecuteNonQuery();

                                        //theClientData.Save();
                                    }
                                    else
                                    {
                                        clientseen++;
                                        DataTableReader thereader = t.CreateDataReader();
                                        thereader.Read();
                                        //Console.WriteLine("Client Update");
                                        updateclientdatasize.Value = Convert.ToInt32(thereader["clientdatasize"]) +
                                                                     ds.wirelessnetwork[i].wirelessclient[j].
                                                                         clientdatasize;
                                        updateoui.Value = LookupOuiData(ds.wirelessnetwork[i].wirelessclient[j].clientmac);
                                        updateclientencryption.Value = ds.wirelessnetwork[i].wirelessclient[j].clientencryption;
                                        //IFormatProvider format = new CultureInfo("en-US");

                                        string firsttime = thereader["clientfirsttime"].ToString();
                                        string lasttime = thereader["clientlasttime"].ToString();
                                        //DateTime dbfirsttime;
                                        //DateTime xmlfirsttime;
                                        //DateTime dblasttime;
                                        //DateTime xmllasttime;
                                        // Wed Mar 29 14:52:56 2006
                                        DateTime.TryParse(firsttime, out dbfirsttime);
                                        DateTime.TryParse(GetNewtime(ds.wirelessnetwork[i].wirelessclient[j].firsttime), out xmlfirsttime);
                                        DateTime.TryParse(lasttime, out dblasttime);
                                        DateTime.TryParse(GetNewtime(ds.wirelessnetwork[i].wirelessclient[j].lasttime), out xmllasttime);

                                        if (xmlfirsttime < dbfirsttime)
                                        {
                                            updateclientfirsttime.Value = xmlfirsttime;
                                        }
                                        else
                                        {
                                            updateclientfirsttime.Value = dbfirsttime;
                                        }
                                        if (xmllasttime > dblasttime)
                                        {
                                            updateclientlasttime.Value = xmllasttime;
                                        }
                                        else
                                        {
                                            updateclientlasttime.Value = dblasttime;
                                        }

                                        //theClientData.Clientfirsttime = ds.wirelessnetwork[i].wirelessclient[j].firsttime;
                                        //theClientData.Clientlasttime = ds.wirelessnetwork[i].wirelessclient[j].lasttime;
                                        if (ds.wirelessnetwork[i].wirelessclient[j].clientgpsinfo != null)
                                        {
                                            updateclientgpsmaxalt.Value =
                                                ds.wirelessnetwork[i].wirelessclient[j].clientgpsinfo.clientmaxalt;
                                            updateclientgpsmaxlat.Value =
                                                ds.wirelessnetwork[i].wirelessclient[j].clientgpsinfo.clientmaxlat;
                                            updateclientgpsmaxlon.Value =
                                                ds.wirelessnetwork[i].wirelessclient[j].clientgpsinfo.clientmaxlon;
                                            updateclientgpsminalt.Value =
                                                ds.wirelessnetwork[i].wirelessclient[j].clientgpsinfo.clientminalt;
                                            updateclientgpsminlat.Value =
                                                ds.wirelessnetwork[i].wirelessclient[j].clientgpsinfo.clientminlat;
                                            updateclientgpsminlon.Value =
                                                ds.wirelessnetwork[i].wirelessclient[j].clientgpsinfo.clientminlon;
                                        }
                                        updateclientmaxrate.Value =
                                            ds.wirelessnetwork[i].wirelessclient[j].clientmaxrate;
                                        if (ds.wirelessnetwork[i].wirelessclient[j].clientipaddress != null)
                                        {
                                            updateClientipaddress.Value =
                                                ds.wirelessnetwork[i].wirelessclient[j].clientipaddress;
                                        }
                                        updateclientmaxseenrate.Value =
                                            ds.wirelessnetwork[i].wirelessclient[j].clientmaxseenrate;
                                        updateclientpacketscrypt.Value =
                                            Convert.ToInt32(thereader["clientpacketscrypt"]) +
                                            ds.wirelessnetwork[i].wirelessclient[j].clientpackets.clientcrypt;
                                        updateclientpacketsdata.Value =
                                            Convert.ToInt32(thereader["clientpacketsdata"]) +
                                            ds.wirelessnetwork[i].wirelessclient[j].clientpackets.clientdata;
                                        updateclientpacketsweak.Value =
                                            Convert.ToInt32(thereader["clientpacketsweak"]) +
                                            ds.wirelessnetwork[i].wirelessclient[j].clientpackets.clientweak;
                                        //theClientData.Save();
                                        updateclients.ExecuteNonQuery();
                                        t = null;
                                        thereader.Close();
                                    }
                                }
                            }
                            //Kisdata.Save();
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex);
                    }

                    thestatsadaptor.InsertQuery(f.Name, networktotal, networknew, networkseen, clienttotal, clientnew,
                                                clientseen);

                    networknew = 0;
                    networkseen = 0;
                    networktotal = 0;
                    clienttotal = 0;
                    clientnew = 0;
                    clientseen = 0;
                    fs.Close();
                }
            }

            connection.Close();
        }