Beispiel #1
0
 public ServerFile(FileMetadata entry)
 {
     this.Path           = ServerPath.FromServerPath(entry.PathLower);
     this.Bytes          = (long)entry.Size;
     this.ServerModified = entry.ServerModified;
     this.ClientModified = entry.ClientModified;
 }
Beispiel #2
0
        public async Task HandleDelta(Delta delta)
        {
            var batch = new ServerEventsBatch();

            var entries = delta.Entries;

            var toAdd    = entries.Where(it => it.IsFile).Select(it => it.AsFile).ToList();
            var toDelete = entries.Where(it => it.IsDeleted).Select(it => it.AsDeleted).ToList();

            foreach (var entry in toDelete)
            {
                var fileItem = this.Files.FirstOrDefault(it => it.Path.Value == entry.PathLower);

                if (fileItem != null)
                {
                    this.Files.Remove(fileItem);
                }

                batch.Add(new DropBoxFileDeletedEvent(ServerPath.FromServerPath(entry.PathLower), delta.Cursor));
                Console.WriteLine($"Deleted {fileItem}");
            }

            foreach (var entry in toAdd)
            {
                var fileItem = this.Files.FirstOrDefault(it => it.Path.Value == entry.PathLower);

                if (fileItem == null)
                {
                    var item = new ServerFile(entry);
                    this.Files.Add(item);
                    Console.WriteLine($"Added {item}");
                    batch.Add(new DropBoxFileAddedEvent(item.Path, delta.Cursor));
                }
                else
                {
                    fileItem.Bytes = (long)entry.Size;
                    Console.WriteLine($"Changed {fileItem}");
                    this.Files.Remove(fileItem);
                    this.Files.Add(fileItem);
                    batch.Add(new DropBoxFileChangedEvent(fileItem.Path, delta.Cursor));
                }
            }

            await this.listener.Handle(batch);
        }