public void AddFile(SyncItem item, string objectId, DateTime? serverSideModificationDate,
Dictionary<string, string[]> metadata, byte[] filehash)
{
Logger.Debug("Starting database file addition for file: " + item.LocalPath);
string checksum = ChecksumToString(filehash);
// Make sure that the modification date is always UTC, because sqlite has no concept of Time-Zones
// See http://www.sqlite.org/datatype3.html
if (null != serverSideModificationDate)
{
serverSideModificationDate = ((DateTime)serverSideModificationDate).ToUniversalTime();
}
if (String.IsNullOrEmpty(checksum))
{
// Calculate file checksum.
try
{
checksum = Checksum(item);
}
catch (IOException e)
{
Logger.Warn("IOException while calculating checksum of " + item.LocalPath
+ " , The file was removed while reading. Just skip it, as it does not need to be added anymore. ", e);
}
}
if (String.IsNullOrEmpty(checksum))
{
Logger.Warn("Bad checksum for " + item.LocalPath);
return;
}
// Insert into database.
string command =
@"INSERT OR REPLACE INTO files (path, localPath, id, serverSideModificationDate, metadata, checksum)
VALUES (@path, @localPath, @id, @serverSideModificationDate, @metadata, @checksum)";
Dictionary<string, object> parameters = new Dictionary<string, object>();
parameters.Add("path", item.RemoteRelativePath);
parameters.Add("localPath", item.LocalRelativePath);
parameters.Add("id", objectId);
parameters.Add("serverSideModificationDate", serverSideModificationDate);
parameters.Add("metadata", Json(metadata));
parameters.Add("checksum", checksum);
ExecuteSQLAction(command, parameters);
Logger.Debug("Completed database file addition for file: " + item.LocalPath);
}