Beispiel #1
0
        private static void ProcessCSVFilesNew(DirectoryInfo dir, Hashtable enchash)
        {
            if (enchash == null) throw new ArgumentNullException("enchash");
            encchanges theencchanges = new encchanges();
            DataTable t;
            FilesTableAdapter thefilesadaptor = new FilesTableAdapter();
            SQLiteConnectionStringBuilder builder = new SQLiteConnectionStringBuilder();
            builder.DataSource = string.Format("{0}\\kismetdata.db", Application.StartupPath);
            builder.SyncMode = SynchronizationModes.Off;
            builder.CacheSize = 5000;
            //DataTable t;
            SQLiteConnection connection = new SQLiteConnection(builder.ToString());
            //SQLiteCommand command = connection.CreateCommand();
            connection.Open();
            SQLiteCommand addcmd = connection.CreateCommand();
                        //DbCommand updatecmd = connection.CreateCommand();
            string theaddcmd;
            theaddcmd = "INSERT INTO encchanges values (?, ?, ?, ?)";
            //updatecmd.CommandText="Update [GPSData] set [source]= @thesource, [timesec]=@thetimesec, [timeusec]=@thetimeusec, [lat] = @thelat, [lon] = @thelon, [alt] = @thealt, [speed] = @thespeed, [heading] = @theheading, [fix] = @thefix, [signal] = @thesignal, [quality] = @thequality, [noise] = @thenoise where [bssid]=@thebssid";
            addcmd.CommandText = theaddcmd;
            SQLiteParameter bssid = addcmd.CreateParameter();
            SQLiteParameter date = addcmd.CreateParameter();
            SQLiteParameter oldenc = addcmd.CreateParameter();
            SQLiteParameter newenc = addcmd.CreateParameter();

            addcmd.Parameters.Add(bssid);
            addcmd.Parameters.Add(date);
            addcmd.Parameters.Add(oldenc);
            addcmd.Parameters.Add(newenc);

            foreach (FileInfo f in dir.GetFiles("Kismet*.csv"))
            {
                t = thefilesadaptor.GetDataByFilename(f.Name);
                if (t.Rows.Count == 0)
                {

                    //thegpsfiles.AddNew();
                    //thegpsfiles.Filename=f.Name;
                    //thegpsfiles.Save();
                    thefilesadaptor.InsertQuery(f.Name, 0, "None", 0, 0);
                    StreamReader sr = File.OpenText(Application.StartupPath + "\\logs\\" + f.Name);
                    string input;
                    Console.WriteLine(f.Name);
                    //string aoui = "";

                    //string[] theoui;
                    //string thecompany = "";
                    sr.ReadLine();
                    using (DbTransaction dbtrans = connection.BeginTransaction())
                    {
                    while ((input = sr.ReadLine()) != null)
                    {
                        if (input.Length != 0)
                        {
                            //Console.WriteLine(input);
                            string[] thestrings;
                            thestrings = input.Split(new char[] { ';' });
                            //Console.WriteLine(thestrings.Length);
                            if (!enchash.ContainsKey(thestrings[3]))
                            {
                                enchash.Add(thestrings[3], thestrings[7]);
                            }
                            else
                            {
                                string temp = enchash[thestrings[3]].ToString();

                                if (temp != thestrings[7])
                                {
                                    enchash.Remove(thestrings[3]);

                                    bssid.Value = thestrings[3];
                                    date.Value = thestrings[20];
                                    oldenc.Value = temp;
                                    newenc.Value = thestrings[7];

                                    addcmd.ExecuteNonQuery();
                                    enchash.Add(thestrings[3], thestrings[7]);

                                }
                            }
                        }

                    }
                    dbtrans.Commit();
                }
            }

            }
        }
Beispiel #2
0
        private static void InsertFilename(FilesTableAdapter thegpsfilesadaptor, FileSystemInfo f)
        {
            try
            {
                string[] split = null;
                split = f.Name.Split(new char[] {'-'});
                string temp = split[4].Substring(0, (split[4].Length - 4));
                int thenumber = Convert.ToInt16(temp);

                thegpsfilesadaptor.InsertQuery(f.Name, Convert.ToInt16(split[3]), split[1],
                                               Convert.ToInt16(split[2]), thenumber);
            }
            catch(Exception)
            {
                thegpsfilesadaptor.InsertQuery(f.Name, 0, "None", 0, 0);
            }
        }