예제 #1
0
        public void UpdateFile(FileDatabaseRecord fileRecord)
        {
            Tracer.Trace("Updating '{0}'", fileRecord.Url);

            var tempFileName = Path.Combine(_tempDirectory, fileRecord.FileName.Replace('\\', '_'));

            var webHeaders = DownloadFile(fileRecord.Url, tempFileName);

            if (webHeaders.ContentLength != new FileInfo(tempFileName).Length)
            {
                throw new Exception("Wrong file size");
            }

            var fileName = Path.Combine(_baseDirectory, fileRecord.FileName);
            EnsureDirectoryExists(Path.GetDirectoryName(fileName));

            if (File.Exists(fileName))
            {
                File.Delete(fileName);
            }

            File.Move(tempFileName, fileName);
            File.SetLastWriteTimeUtc(fileName, webHeaders.LastModified);

            fileRecord.Modify(webHeaders.LastModified, webHeaders.ContentLength, webHeaders.ContentType, "", true, false);
            _fileDatabase.AddOrReplaceFile(fileRecord);
        }
예제 #2
0
        public void UpdateFile(FileDatabaseRecord fileRecord)
        {
            Tracer.Trace("Updating '{0}'", fileRecord.Url);

            var tempFileName = Path.Combine(_tempDirectory, fileRecord.FileName.Replace('\\', '_'));

            var webHeaders = DownloadFile(fileRecord.Url, tempFileName);

            if (webHeaders.ContentLength != new FileInfo(tempFileName).Length)
            {
                throw new Exception("Wrong file size");
            }

            var fileName = Path.Combine(_baseDirectory, fileRecord.FileName);

            EnsureDirectoryExists(Path.GetDirectoryName(fileName));

            if (File.Exists(fileName))
            {
                File.Delete(fileName);
            }

            File.Move(tempFileName, fileName);
            File.SetLastWriteTimeUtc(fileName, webHeaders.LastModified);

            fileRecord.Modify(webHeaders.LastModified, webHeaders.ContentLength, webHeaders.ContentType, "", true, false);
            _fileDatabase.AddOrReplaceFile(fileRecord);
        }
예제 #3
0
        public void AddFile(String url, String fileName)
        {
            Tracer.Trace("Adding '{0}'", url);

            var fileRecord = new FileDatabaseRecord(url, fileName);

            _fileDatabase.AddOrReplaceFile(fileRecord);
        }
예제 #4
0
        public void AddFile(String url, String fileName)
        {
            Tracer.Trace("Adding '{0}'", url);

            var fileRecord = new FileDatabaseRecord(url, fileName);

            _fileDatabase.AddOrReplaceFile(fileRecord);
        }
예제 #5
0
        public void AddOrReplaceFile(FileDatabaseRecord fileDatabaseRecord)
        {
            var commandText = String.Format("INSERT OR REPLACE INTO files (url, filename, modified, size, type, checksum, available, outofdate) VALUES ('{0}', '{1}', '{2:O}', {3}, '{4}', '{5}', {6}, {7})",
                                            fileDatabaseRecord.Url, fileDatabaseRecord.FileName, fileDatabaseRecord.Modified, fileDatabaseRecord.Size, fileDatabaseRecord.Type,
                                            fileDatabaseRecord.Checksum, fileDatabaseRecord.Available ? 1 : 0, fileDatabaseRecord.OutOfDate ? 1 : 0);

            using (var connection = new SQLiteConnection(_connectionString))
            {
                connection.Open();

                using (var command = new SQLiteCommand(commandText, connection))
                {
                    command.ExecuteNonQuery();
                }
            }
        }
예제 #6
0
        public void AddOrReplaceFile(FileDatabaseRecord fileDatabaseRecord)
        {
            var commandText = String.Format("INSERT OR REPLACE INTO files (url, filename, modified, size, type, checksum, available, outofdate) VALUES ('{0}', '{1}', '{2:O}', {3}, '{4}', '{5}', {6}, {7})",
                fileDatabaseRecord.Url, fileDatabaseRecord.FileName, fileDatabaseRecord.Modified, fileDatabaseRecord.Size, fileDatabaseRecord.Type,
                fileDatabaseRecord.Checksum, fileDatabaseRecord.Available ? 1 : 0, fileDatabaseRecord.OutOfDate ? 1 : 0);

            using (var connection = new SQLiteConnection(_connectionString))
            {
                connection.Open();

                using (var command = new SQLiteCommand(commandText, connection))
                {
                    command.ExecuteNonQuery();
                }
            }
        }