Exemple #1
0
        public void AddEntry(FileIndexEntry entry)
        {
            Require.NotNull(entry, "entry");

            lock (_lock)
            {
                var entries = ReadEntries();
                entries.Add(entry);
                File.WriteAllText(Path, JsonConvert.SerializeObject(entries));
            }
        }
        public void AddFile(string directoryVirtualPath, FileIndexEntry file)
        {
            var directoryPath = GetPhysicalPath(directoryVirtualPath);
            if (!Directory.Exists(directoryPath))
            {
                Directory.CreateDirectory(directoryPath);
            }

            var metaPath = System.IO.Path.Combine(directoryPath, "meta.config");
            var metaFile = new DirectoryMetaFile(metaPath);
            metaFile.AddEntry(file);
        }
Exemple #3
0
        public void UpdateEntry(FileIndexEntry entry)
        {
            Require.NotNull(entry, "entry");

            lock (_lock)
            {
                var entries = ReadEntries();

                for (var i = 0; i < entries.Count; i++)
                {
                    if (entries[i].Name.Equals(entry.Name, StringComparison.OrdinalIgnoreCase))
                    {
                        entries[i] = entry;
                        break;
                    }
                }

                File.WriteAllText(Path, JsonConvert.SerializeObject(entries));
            }
        }
Exemple #4
0
        public IFile CreateFile(string fileName)
        {
            var indexEntry = new FileIndexEntry
            {
                Name = fileName,
                CreationTimeUtc = DateTime.UtcNow,
                LastWriteTimeUtc = DateTime.UtcNow
            };

            Index.AddFile(VirtualPath, indexEntry);

            return new QiniuFile(UrlUtil.Combine(VirtualPath, fileName), indexEntry, FileSystem);
        }
Exemple #5
0
 public QiniuFile(string virtualPath, FileIndexEntry indexEntry, QiniuFileSystem fileSystem)
 {
     VirtualPath = virtualPath;
     FileSystem = fileSystem;
     _indexEntry = indexEntry;
 }
        public void UpdateFile(string directoryVirtualPath, FileIndexEntry file)
        {
            var directoryPath = GetPhysicalPath(directoryVirtualPath);
            if (!Directory.Exists(directoryPath))
                throw new FileNotFoundException("File not exists.");

            var metaPath = System.IO.Path.Combine(directoryPath, "meta.config");
            var metaFile = new DirectoryMetaFile(metaPath);
            metaFile.UpdateEntry(file);
        }