Example #1
0
            public async Task AddCache()
            {
                await DropTable(@"Cache");
                await CreateTable(@"Cache");

                OpenConnection();
                try
                {
                    if (!Directory.Exists(@"Cache"))
                    {
                        return;
                    }
                    var filesnames = Directory.GetFiles(@"Cache").ToList();
                    foreach (var item in filesnames)
                    {
                        using (var sr = new StreamReader(item))
                        {
                            var line      = sr.ReadToEnd();
                            var lineBytes = ByteConverters.ObjectToByteArray(line);
                            var sql       = "INSERT INTO Cache ('filename', 'file') VALUES (@filename, @file)";
                            var command   = new SQLiteCommand(sql, Connection);
                            command.Parameters.AddWithValue("@filename", item);
                            command.Parameters.Add("@file", DbType.Binary, lineBytes.Length);
                            command.Parameters["@file"].Value = lineBytes;
                            await command.ExecuteNonQueryAsync();
                        }
                    }
                }
                catch (Exception e)
                {
                    LoggingService.Log(e);
                }

                CloseConnection();
            }