Esempio n. 1
0
        private void processFile(string phoneId, string path, DBManager dbm)
        {
            string fileName = Path.GetFileName(path);

            if (!dbm.isFileProcess(phoneId, fileName, false))
            {
                dbm.saveFile(phoneId, fileName, false, false, new FileInfo(path).Length);

                try
                {
                    dbm.beginTransaction(phoneId + fileName);
                    string date = Path.GetFileNameWithoutExtension(path).Substring(0, 8);

                    StreamReader sr = new StreamReader(path);

                    while (!sr.EndOfStream)
                        this.processLine(sr.ReadLine(), fileName, date, dbm);

                    sr.Close();
                    dbm.saveFile(phoneId, fileName, true, false, new FileInfo(path).Length);
                    dbm.endTransaction(phoneId + fileName,true);
                }
                catch (Exception ex)
                {
                    dbm.endTransaction(phoneId + fileName, false);
                }
            }
        }
Esempio n. 2
0
        public void execute(string phoneId,string zipPath,string pass)
        {
            DBManager dbm = new DBManager();

            try
            {
                string res = dbm.saveFile(phoneId, Path.GetFileName(zipPath), false, true, new FileInfo(zipPath).Length);

                if (res == "OK.")
                {

                    ZipManager zm = new ZipManager();
                    zm.descomprimirDir(zipPath, pass, Path.GetDirectoryName(zipPath), new ZipLog());

                    string[] files = Directory.GetFiles(Path.GetDirectoryName(zipPath), "*.txt", SearchOption.TopDirectoryOnly);

                    for (int i = 0; (i < files.Length) && (res == "OK."); i++)
                    {
                        this.processFile(phoneId, files[i], dbm);
                        File.Delete(files[i]);
                    }

                    if (res == "OK.")
                        dbm.saveFile(phoneId, Path.GetFileName(zipPath), true, true, new FileInfo(zipPath).Length);
                }
            }
            catch (Exception ex)
            {
                dbm.saveFile(phoneId, Path.GetFileName(zipPath), false, true, new FileInfo(zipPath).Length);
            }
        }
Esempio n. 3
0
 public string RegisterUser(string phoneId,string name,string version,string phoneModel)
 {
     try
     {
         DBManager mDB = new DBManager();
         return mDB.saveUser(phoneId, name, version, phoneModel);
     }
     catch(Exception ex)
     {
         return "Problem.";
     }
 }
Esempio n. 4
0
        public bool execute(string phoneId, DateTime from, DateTime to, string propNames, string path)
        {
            try
            {
                DBManager dbm = new DBManager();

                DataTable data = dbm.getCsvData(phoneId, from, to, propNames);

                //======================Obtengo los nombres de las properties================================
                SortedDictionary<string, string> values = new SortedDictionary<string,string>();
                foreach (DataRow dr in data.Rows)
                    if (!values.ContainsKey((string)dr["FullName"]))
                        values.Add((string)dr["FullName"], "?");

                string[] properties = values.Keys.ToArray<string>();

                //======================Obtengo la primer fecha==============================================
                DateTime date = (data.Rows.Count > 0) ? (DateTime)data.Rows[0]["date"] : DateTime.Now;

                string line = "";

                StreamWriter file = new StreamWriter(path, true);
                file.WriteLine("@RELATION Tesis");

                this.saveAtributes(file, data);

                file.WriteLine("@data");

                foreach (DataRow r in data.Rows)
                {
                    DateTime current = (DateTime)r["date"];
                    if (date != current)
                    {
                        date = current;
                        line = "";
                        for (int i = 0; i < properties.Length; i++)
                            line += (string)values[properties[i]] + ",";
                        file.WriteLine(line.Substring(0, line.Length - 1));
                    }
                    this.setPropertyValue(values, (string)r["FullName"], (string)r["PropValue"]);
                }
                file.Flush();
                file.Close();

                return true;
            }
            catch (Exception ex)
            { return false; }
        }
Esempio n. 5
0
 public List<LocationGroup> getLocationGroups(string phoneId, DBManager dbm)
 {
     DataTable dt = dbm.getLocationGroups(phoneId);
     List<LocationGroup> list = new List<LocationGroup>();
     foreach (DataRow r in dt.Rows)
     {
         LocationGroup lg = new LocationGroup();
         lg.Id = (int)r["idLocationGroup"];
         lg.Name = (string)r["name"];
         lg.Longitud = Convert.ToDecimal(r["longitud"]);
         lg.Latitud = Convert.ToDecimal(r["latitud"]);
         lg.Count = (int)r["count"];
         list.Add(lg);
     }
     return list;
 }
Esempio n. 6
0
        public void execute(string phoneId)
        {
            try
            {
                DBManager dbm = new DBManager();
                List<LocationGroup> groups = this.getLocationGroups(phoneId, dbm);
                List<Location> locations = this.getLocations(phoneId, dbm);

                foreach (Location l in locations)
                {
                    bool find = false;
                    for (int i = 0; (i < groups.Count) && !find; i++)
                    {
                        LocationGroup lg = groups[i];
                        if (this.GetDistance(lg.Longitud, lg.Latitud, l.Longitud, l.Latitud) < this.minDistance)
                        {
                            find = true;
                            lg.Latitud = ((lg.Latitud * lg.Count) + l.Latitud) / (lg.Count + 1);
                            lg.Longitud = ((lg.Longitud * lg.Count) + l.Longitud) / (lg.Count + 1);
                            lg.Count++;
                        }
                    }
                    if (!find)
                    {
                        LocationGroup lg = new LocationGroup();
                        lg.Name = "Group_" + (groups.Count + 1);
                        lg.Longitud = l.Longitud;
                        lg.Latitud = l.Latitud;
                        lg.Count = 1;
                        groups.Add(lg);
                    }
                }
                foreach (LocationGroup lg in groups)
                    dbm.saveLocationGroup(phoneId, lg);
            }
            catch (Exception ex) { }
        }
Esempio n. 7
0
 public void resetLocationGroups(string phoneId)
 {
     DBManager dbm = new DBManager();
     dbm.deleteLocationGroup(phoneId);
     this.execute(phoneId);
 }
Esempio n. 8
0
 private List<Location> getLocations(string phoneId, DBManager dbm)
 {
     DataTable dt = dbm.getLocations(phoneId);
     List<Location> list = new List<Location>();
     foreach (DataRow r in dt.Rows)
     {
         Location l = new Location();
         l.Longitud = Convert.ToDecimal(r["longitud"]);
         l.Latitud = Convert.ToDecimal(r["latitud"]);
         list.Add(l);
     }
     return list;
 }
Esempio n. 9
0
        private void processLine(string line,string fileName, string date,DBManager dbm)
        {
            string[] parts = line.Split(LogConstants.CATSEP.ToCharArray());

            DateTime dTime = this.getDatetime(date, parts[0]);
            string type = parts[1].Substring(1, parts[1].Length - 2);

            for (int i = 2; i < parts.Length; i++)
            {
                parts[i] = parts[i].Substring(1, parts[i].Length - 2);
                this.processProperties(parts[i], fileName, type, dTime, dbm);
            }
        }
Esempio n. 10
0
        private void processProperty(string property,string fileName, string type, DateTime dt,DBManager dbm)
        {
            string[] pValue = property.Split(LogConstants.SEP.ToCharArray());

            string prop = pValue[0];
            string value = pValue[pValue.Length-1];

            dbm.saveLog(fileName, dt, type, prop, value);
        }
Esempio n. 11
0
 private void processProperties(string properties, string fileName, string type, DateTime dt, DBManager dbm)
 {
     string[] values = properties.Split(LogConstants.PSEP.ToCharArray());
     for (int i = 0; i < values.Length; i++)
     {
         this.processProperty(values[i], fileName ,type, dt, dbm);
     }
 }