Ejemplo n.º 1
0
        public void TransferPackageFile(StitchGroupName groupName, string toNodeId, string filePath, string fileName, InstanceAdaptorDetails adaptor, string jobId, string taskId)
        {
            // TODO: More validation and error handling
            // TODO: We need to get more sophisticated about this, such as doing the transfer in chunks and allowing restarts
            if (!groupName.IsValid() || !groupName.IsVersionGroup())
            {
                throw new Exception("Must use a valid version name for a package upload file");
            }
            if (adaptor == null)
            {
                throw new Exception("Adaptor details must be provided");
            }

            var bytes    = File.ReadAllBytes(filePath);
            var envelope = new FileTransferEnvelope
            {
                Contents             = bytes,
                GroupName            = groupName.VersionString,
                JobId                = jobId,
                TaskId               = taskId,
                PacketNumber         = 1,
                TotalNumberOfPackets = 1,
                FileName             = fileName,
                Adaptor              = adaptor
            };
            var message = new ClusterMessageBuilder()
                          .ToNode(toNodeId)
                          .FromNode()
                          .WithInternalObjectPayload(envelope)
                          .Build();

            Send(message);
        }
Ejemplo n.º 2
0
        private void ReceiveFileTransferRequest(ClusterMessage envelope, FileTransferEnvelope request)
        {
            using (var stream = new MemoryStream(request.Contents))
            {
                // TODO: Get more sophisticated with chunking, restart/retry, checksums, etc
                var response = _messageBus.Request <PackageFileUploadRequest, PackageFileUploadResponse>(PackageFileUploadRequest.ChannelFromRemote, new PackageFileUploadRequest
                {
                    Contents  = stream,
                    FileName  = request.FileName,
                    GroupName = new StitchGroupName(request.GroupName),
                    LocalOnly = true,
                    Adaptor   = request.Adaptor
                });

                var outEnvelope = new ClusterMessageBuilder()
                                  .FromNode()
                                  .ToNode(envelope.Header.FromNetworkId)
                                  .WithObjectPayload(new CommandReceipt
                {
                    Success       = response.IsSuccess,
                    ReplyToJobId  = request.JobId,
                    ReplyToTaskId = request.TaskId
                })
                                  .Build();
                _backplane.Send(outEnvelope);
            }
        }