Exemple #1
0
 public void InsertBinaryFile(BinaryFile f, string type)
 {
     string sql = "INSERT INTO FileTable (FileId, PageId, Tag, Path, Filename, TypeDesc, FileContents) "
         + " VALUES (@FileId, @PageId, @Tag, @Path, @Filename, @TypeDesc, @FileContents);";
     try
     {
         using (MySqlCommand c = new MySqlCommand(sql, client))
         {
             c.Parameters.AddWithValue("@FileId", Guid.NewGuid());
             c.Parameters.AddWithValue("@PageId", f.PageId.ToString());
             c.Parameters.AddWithValue("@Tag", f.Tag);
             c.Parameters.AddWithValue("@Path", f.Url.GetFullPath(false));
             c.Parameters.AddWithValue("@Filename", f.Url.Path.Last());
             c.Parameters.AddWithValue("@TypeDesc", type);
             f.Contents.Position = 0;
             c.Parameters.AddWithValue("@FileContents", f.Contents.ToArray());
             c.ExecuteNonQuery();
         }
         Console.WriteLine("File persisted: " + f.Url.GetFullPath(false));
     }
     catch (Exception e)
     {
         log.Error("Inserting file failed", e);
         // throw;
     }
 }
 public void InsertBinaryFile(BinaryFile f, string type)
 {
     var database = Client.GetDatabase("webdb");
     var collection = database.GetCollection<BsonDocument>("files");
     collection.InsertOne(new BsonDocument
     {
         {"FileId", Guid.NewGuid() },
         {"PageId", f.PageId.ToString() },
         {"Tag", f.Tag },
         {"Path", f.Url.GetFullPath(false) },
         {"Filename", f.Url.Path.Last() },
         {"AggregatedDateTime", DateTime.Now }
         //{"Contents", f.Contents.ToArray() }
     });
 }