Beispiel #1
0
        void UpdateSkypeTimer_Elapsed(object sender, ElapsedEventArgs e)
        {
            if (_DB == null || !_DB.isOpen())
            {
                return;
            }

            if (LastSeenMessageTimestamp == -1)
            {
                SkypeDBRow lastMessageX = _DB.GetCustom("Messages", new String[] { "timestamp" }, null, "timestamp DESC").FirstOrDefault();
                Message    msgX         = SkypeClassConverter.ConvertTo <Message>(lastMessageX);
                LastSeenMessageTimestamp = msgX.timestampLong;
            }

            SkypeDBRow[] lastMessages = _DB.GetCustom("Messages", new String[] { "*" }, "timestamp > " + LastSeenMessageTimestamp + " AND author != '" + Username + "'", "timestamp ASC");

            if (lastMessages.Length > 0)
            {
                foreach (SkypeDBRow row in lastMessages)
                {
                    Message msg = SkypeClassConverter.ConvertTo <Message>(row);
                    OnMessageSeen(msg);
                }

                LastSeenMessageTimestamp = SkypeClassConverter.ConvertTo <Message>(lastMessages.Last()).timestampLong;
            }
        }
Beispiel #2
0
        public SkypeDBRow[] GetCustom(String tableName, String[] Fields, String whereClause = null, String orderByClause = null)
        {
            List <SkypeDBRow> data = new List <SkypeDBRow>();

            try
            {
                //PRAGMA table_info('messages')

                String FieldsStr = String.Join(",", Fields);

                if (!String.IsNullOrEmpty(whereClause))
                {
                    whereClause = "WHERE " + whereClause;
                }
                else
                {
                    whereClause = "";
                }

                if (!String.IsNullOrEmpty(orderByClause))
                {
                    orderByClause = "ORDER BY " + orderByClause;
                }
                else
                {
                    orderByClause = "";
                }

                SQLiteCommand    cmd    = new SQLiteCommand("SELECT " + FieldsStr + " FROM " + tableName + " " + whereClause + " " + orderByClause, _conn);
                SQLiteDataReader reader = cmd.ExecuteReader();

                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        SkypeDBRow xData = new SkypeDBRow();
                        for (int i = 0; i < reader.FieldCount; i++)
                        {
                            String fieldName = reader.GetName(i);
                            Object value     = reader[i];
                            xData.Data.Add(fieldName, value);
                        }

                        data.Add(xData);
                    }
                }

                reader.Dispose();
                cmd.Dispose();
            }
            catch (SQLiteException sex)
            {
                Console.WriteLine(sex.Message);
            }


            return(data.ToArray());
        }
Beispiel #3
0
        public SkypeDBRow[] GetCustom(String tableName, String[] Fields, String whereClause = null, String orderByClause = null)
        {
            List<SkypeDBRow> data = new List<SkypeDBRow>();

            try
            {
                //PRAGMA table_info('messages')

                String FieldsStr = String.Join(",", Fields);

                if (!String.IsNullOrEmpty(whereClause))
                    whereClause = "WHERE " + whereClause;
                else
                    whereClause = "";

                if (!String.IsNullOrEmpty(orderByClause))
                    orderByClause = "ORDER BY " + orderByClause;
                else
                    orderByClause = "";

                SQLiteCommand cmd = new SQLiteCommand("SELECT " + FieldsStr + " FROM " + tableName + " " + whereClause + " " + orderByClause, _conn);
                SQLiteDataReader reader = cmd.ExecuteReader();

                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        SkypeDBRow xData = new SkypeDBRow();
                        for (int i = 0; i < reader.FieldCount; i++)
                        {
                            String fieldName = reader.GetName(i);
                            Object value = reader[i];
                            xData.Data.Add(fieldName, value);
                        }

                        data.Add(xData);
                    }
                }

                reader.Dispose();
                cmd.Dispose();
            }
            catch (SQLiteException sex)
            {
                Console.WriteLine(sex.Message);
            }

            return data.ToArray();
        }
        public static T ConvertTo <T>(SkypeDBRow data)
        {
            try
            {
                Type chatType = typeof(T);

                var Obj = typeof(T).InvokeMember("", BindingFlags.CreateInstance, null, null, new Object[0]);

                foreach (String key in data.Data.Keys)
                {
                    Object    X  = Obj.GetType().InvokeMember(key, BindingFlags.GetField, null, Obj, new Object[0]);
                    FieldInfo fi = Obj.GetType().GetField(key, BindingFlags.GetField | BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.DeclaredOnly | BindingFlags.Instance);
                    if (fi != null)
                    {
                        if (fi.FieldType == typeof(int))
                        {
                            int val;
                            if (int.TryParse(data[key].ToString(), out val))
                            {
                                fi.SetValue(Obj, val);
                            }
                        }
                        else if (fi.FieldType == typeof(String))
                        {
                            fi.SetValue(Obj, data[key].ToString());
                        }
                        else if (fi.FieldType == typeof(DateTime))
                        {
                            long timestamp;
                            if (long.TryParse(data[key].ToString(), out timestamp))
                            {
                                DateTime dateTime = UnixTimeStampToDateTime(timestamp);
                                fi.SetValue(Obj, dateTime);

                                FieldInfo longFI = Obj.GetType().GetField(key + "Long", BindingFlags.GetField | BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.DeclaredOnly | BindingFlags.Instance);
                                if (longFI != null)
                                {
                                    longFI.SetValue(Obj, timestamp);
                                }
                            }
                        }
                        else if (fi.FieldType == typeof(Object))
                        {
                            fi.SetValue(Obj, data[key]);
                        }
                    }
                    else
                    {
                        Console.WriteLine("Missing Field " + key + " in " + chatType.Name);
                    }
                }

                return((T)Obj);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            return(default(T));
        }