Ejemplo n.º 1
0
        public void RenameFile(string oldName, string newName, Watcher watcher)
        {
            var fileInfo = new FileInfo(newName);
            var files    = (from file in Files
                            where file.FullName == oldName
                            select file).ToList();

            if (files.Count == 0)
            {
                AddFile(newName, watcher);
                return;
            }
            else if (files.Count == 1)
            {
                var file = files.First();
                file.FullName           = fileInfo.FullName;
                file.Extension          = fileInfo.Extension;
                file.Extension_fts      = fileInfo.Extension.Trim('.');
                file.Name               = fileInfo.Name;
                file.Name_fts           = fileInfo.Name;
                file.Name_tokenized_fts = DBHelpers.TokenizeName(fileInfo);
                file.Thumbnail          = MaybeMakeThumbnail(fileInfo, watcher);
                SaveChanges();
            }
            else
            {
                // Should not be reached.
                throw new Exception("Unique constraint violated.");
            }
        }
Ejemplo n.º 2
0
        private static File MakeFileModel(FileInfo fileInfo, Watcher watcher)
        {
            File newFile = new File
            {
                FullName           = fileInfo.FullName,
                Directory          = fileInfo.DirectoryName,
                Name               = fileInfo.Name,
                FileCreatedTime    = fileInfo.CreationTimeUtc,
                FileModifiedTime   = fileInfo.LastWriteTimeUtc,
                LastChangeTime     = Helpers.LastChangeTime(fileInfo),
                Extension          = fileInfo.Extension,
                Directory_fts      = DBHelpers.TokenizeDirectory(fileInfo, watcher),
                Name_fts           = fileInfo.Name,
                Name_tokenized_fts = DBHelpers.TokenizeName(fileInfo),
                Extension_fts      = fileInfo.Extension.Trim('.'),
                WatcherId          = watcher.Id
            };

            // Fix these when they actually get exceptions.
            newFile.Thumbnail = MaybeMakeThumbnail(fileInfo, watcher);
            updateXMPTagsFromFile(newFile);
            return(newFile);
        }