public void Execute(FileModel fileModel, Stream stream)
        {
            if (fileModel == null)
            {
                throw new ArgumentNullException(nameof(fileModel));
            }
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }

            var dialog = new ProtocolDialogClient(stream);

            dialog.InitiateDialog(new ProtocolDialogData
            {
                FileAction       = fileModel.FileAction,
                Version          = 1,
                RelativeFilePath = fileModel.RelativePath,
                FileType         = fileModel.FileType
            });

            var renameFileModel = (RenameFileModel)fileModel;

            dialog.SendBytes(BitConverter.GetBytes(renameFileModel.NewFileName.Length));
            dialog.SendBytes(Encoding.GetEncoding("UTF-8").GetBytes(renameFileModel.NewFileName));
        }
示例#2
0
        public virtual void Execute(FileModel fileModel, Stream stream)
        {
            if (fileModel == null)
            {
                throw new ArgumentNullException(nameof(fileModel));
            }
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }

            var dialog = new ProtocolDialogClient(stream);

            dialog.InitiateDialog(new ProtocolDialogData
            {
                FileAction       = fileModel.FileAction,
                Version          = 1,
                RelativeFilePath = fileModel.RelativePath,
                FileType         = fileModel.FileType
            });

            if (fileModel.FileType == FileType.Directory)
            {
                return;
            }

            using (var sourceStream = _fileSystem.File.OpenRead(fileModel.FullPath))
            {
                var fileHash = _hash.ComputeHash(sourceStream);
                dialog.SendBytes(fileHash);
                sourceStream.Seek(0, SeekOrigin.Begin);

                if (dialog.ActionIsNeeded())
                {
                    int    readedBytes;
                    byte[] buffer = new byte[int.Parse(_configuration["segment-size"])];
                    while ((readedBytes = sourceStream.Read(buffer, 0, buffer.Length)) != 0)
                    {
                        SendSegment(dialog, buffer, readedBytes);
                    }
                }
            }
        }