Ejemplo n.º 1
0
        public void Run(ClientCommandArgs args)
        {
            var receivedContent = Serializer.Deserialize <MessageContent>(args.Message);

            if (receivedContent.File == null)
            {
                throw new ArgumentNullException("file");
            }

            if (string.IsNullOrEmpty(receivedContent.RoomName))
            {
                throw new ArgumentException("roomName");
            }

            using (var client = ClientModel.Get())
            {
                var downloadFiles = client.DownloadingFiles.Where((dFile) => dFile.File.Equals(receivedContent.File));

                foreach (var file in downloadFiles)
                {
                    file.Dispose();
                }
            }

            var downloadEventArgs = new FileDownloadEventArgs
            {
                File     = receivedContent.File,
                Progress = 0,
                RoomName = receivedContent.RoomName,
            };

            ClientModel.Notifier.PostedFileDeleted(downloadEventArgs);
        }
        protected override void OnRun(MessageContent content, ClientCommandArgs args)
        {
            if (content.File == null)
            {
                throw new ArgumentNullException("file");
            }

            if (string.IsNullOrEmpty(content.RoomName))
            {
                throw new ArgumentException("roomName");
            }

            using (var client = ClientModel.Get())
            {
                var downloadFiles = client.DownloadingFiles.Where((dFile) => dFile.File.Equals(content.File));

                foreach (var file in downloadFiles)
                {
                    file.Dispose();
                }
            }

            var downloadEventArgs = new FileDownloadEventArgs
            {
                File     = content.File,
                Progress = 0,
                RoomName = content.RoomName,
            };

            ClientModel.Notifier.PostedFileDeleted(downloadEventArgs);
        }
Ejemplo n.º 3
0
        private void ClientPostedFileDeleted(FileDownloadEventArgs e)
        {
            if (e.RoomName != parentRoom.Name || e.FileId != fileId)
            {
                return;
            }

            Progress = 0;
            fileId   = null;
        }
Ejemplo n.º 4
0
        private void ClientPostedFileDeleted(object sender, FileDownloadEventArgs e)
        {
            roomViewModel.MainViewModel.Dispatcher.BeginInvoke(new Action <FileDownloadEventArgs>(args =>
            {
                if (args.RoomName != roomViewModel.Name || !args.File.Equals(File))
                {
                    return;
                }

                Progress = 0;
                File     = null;
            }), e);
        }
Ejemplo n.º 5
0
        private void ClientDownloadProgress(object sender, FileDownloadEventArgs e)
        {
            roomViewModel.MainViewModel.Dispatcher.BeginInvoke(new Action <FileDownloadEventArgs>(args =>
            {
                if (args.RoomName != roomViewModel.Name || !args.File.Equals(File))
                {
                    return;
                }

                if (args.Progress < 100)
                {
                    Progress = args.Progress;
                }
                else
                {
                    Progress = 0;
                    roomViewModel.AddSystemMessage(string.Format("Загрузка файла \"{0}\" завершена.", args.File.Name));
                }
            }), e);
        }
Ejemplo n.º 6
0
        public override bool RemoveFile(FileId fileId)
        {
            var result = base.RemoveFile(fileId);

            if (result)
            {
                var chat = ClientGuard.CurrentChat;

                // Remove downloading
                if (chat.IsFileDownloading(fileId))
                {
                    chat.RemoveFileDownload(fileId);
                }

                // Notify
                var downloadEventArgs = new FileDownloadEventArgs(Name, fileId, 0);
                ClientModel.Notifier.PostedFileDeleted(downloadEventArgs);
            }
            return(result);
        }
Ejemplo n.º 7
0
        private void ClientDownloadProgress(FileDownloadEventArgs e)
        {
            if (e.RoomName != parentRoom.Name || e.FileId != fileId || Progress == e.Progress)
            {
                return;
            }

            using (var client = ClientModel.Get())
            {
                var file = GetFile(client, fileId.Value);

                if (e.Progress < 100)
                {
                    Progress = e.Progress;
                }
                else
                {
                    Progress = 0;
                    parentRoom.AddSystemMessage(Localizer.Instance.Localize(FileDownloadedKey, file.Name));
                }
            }
        }
Ejemplo n.º 8
0
        public void ClosePostedFile(ClientGuard client, string roomName, FileId fileId)
        {
            // Remove file from room
            Room room;

            if (client.Rooms.TryGetValue(roomName, out room))
            {
                room.Files.RemoveAll(f => f.Id == fileId);
            }

            // Remove downloading files
            var closing = new List <DownloadingFile>();

            client.DownloadingFiles.RemoveAll(f =>
            {
                if (f.File.Id == fileId)
                {
                    closing.Add(f);
                    return(true);
                }
                return(false);
            });

            foreach (var file in closing)
            {
                file.Dispose();
            }

            // Notify
            var downloadEventArgs = new FileDownloadEventArgs
            {
                RoomName = roomName,
                FileId   = fileId,
                Progress = 0
            };

            ClientModel.Notifier.PostedFileDeleted(downloadEventArgs);
        }
Ejemplo n.º 9
0
 private void FileStorage_FileDownloadUpdated(object sender, FileDownloadEventArgs e)
 {
     return;
 }
Ejemplo n.º 10
0
        protected override void OnRun(MessageContent content, ClientCommandArgs args)
        {
            if (content.File == null)
            {
                throw new ArgumentNullException("File");
            }

            if (content.Part == null)
            {
                throw new ArgumentNullException("Part");
            }

            if (content.StartPartPosition < 0)
            {
                throw new ArgumentException("StartPartPosition < 0");
            }

            if (string.IsNullOrEmpty(content.RoomName))
            {
                throw new ArgumentException("roomName");
            }

            var downloadEventArgs = new FileDownloadEventArgs
            {
                RoomName = content.RoomName,
                File     = content.File,
            };

            using (var client = ClientModel.Get())
            {
                var downloadingFile = client.DownloadingFiles.FirstOrDefault((current) => current.File.Equals(content.File));
                if (downloadingFile == null)
                {
                    return;
                }

                if (downloadingFile.WriteStream == null)
                {
                    downloadingFile.WriteStream = File.Create(downloadingFile.FullName);
                }

                if (downloadingFile.WriteStream.Position == content.StartPartPosition)
                {
                    downloadingFile.WriteStream.Write(content.Part, 0, content.Part.Length);
                }

                downloadingFile.File = content.File;

                if (downloadingFile.WriteStream.Position >= content.File.Size)
                {
                    client.DownloadingFiles.Remove(downloadingFile);
                    downloadingFile.WriteStream.Dispose();
                    downloadEventArgs.Progress = 100;
                }
                else
                {
                    var sendingContent = new ClientReadFilePartCommand.MessageContent
                    {
                        File              = content.File,
                        Length            = AsyncClient.DefaultFilePartSize,
                        RoomName          = content.RoomName,
                        StartPartPosition = downloadingFile.WriteStream.Position,
                    };

                    ClientModel.Peer.SendMessage(args.PeerConnectionId, ClientReadFilePartCommand.CommandId, sendingContent);
                    downloadEventArgs.Progress = (int)((downloadingFile.WriteStream.Position * 100) / content.File.Size);
                }
            }

            ClientModel.Notifier.DownloadProgress(downloadEventArgs);
        }
Ejemplo n.º 11
0
 private void WebBrower_FileDownloadExStart(object sender, FileDownloadEventArgs e)
 {
 }
Ejemplo n.º 12
0
 internal void OnFileDownloadUpdated(object sender, FileDownloadEventArgs args)
 {
     FileDownloadUpdated.Raise(sender, args);
 }
Ejemplo n.º 13
0
 public void OnError(FileDownloadEventArgs e)
 {
     throw new NotImplementedException();
 }