CmisSync.Lib.Database.Database.AddFile C# (CSharp) Метод

AddFile() публичный Метод

Add a file to the database. If checksum is not null, it will be used for the database entry
public AddFile ( SyncItem item, string objectId, System.DateTime serverSideModificationDate, string[]>.Dictionary metadata, byte filehash ) : void
item SyncItem
objectId string
serverSideModificationDate System.DateTime
metadata string[]>.Dictionary
filehash byte
Результат void
        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);
        }