コード例 #1
0
ファイル: LogCSVManager.cs プロジェクト: pvena/apps-monitor
        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; }
        }