Ejemplo n.º 1
0
        static bool uploadFile(HttpRequestMessageProperty httpRequest, string jobID, string fileRefID, string FileContent)
        {
            try
            {
                FileTransferServicePortClient client = new FileTransferServicePortClient(FTconfigName);
                using (OperationContextScope scope = new OperationContextScope(client.InnerChannel))
                {

                    OperationContext.Current.OutgoingMessageProperties.Add(HttpRequestMessageProperty.Name, httpRequest);

                    UploadFileRequest uploadReq = new UploadFileRequest();

                    uploadReq.fileAttachment = getFileAttachment(FileContent);
                    uploadReq.fileReferenceId = fileRefID;
                    uploadReq.taskReferenceId = jobID;
                    uploadReq.fileFormat = "gzip";

                    UploadFileResponse uploadResponse = client.uploadFile(uploadReq);

                    if (uploadResponse.ack.ToString().Equals("Success"))
                    {
                        LMSMessage += Environment.NewLine + " request file uploaded successfully";
                        return true;
                    }
                    else
                    {
                        throw new Exception(uploadResponse.errorMessage[0].message);
                        return false;
                    }

                }
            }
            catch (Exception ex)
            {
                LMSMessage += Environment.NewLine + " uploadFile:" + ex.Message;
                return false;
            }
        }
Ejemplo n.º 2
0
        private bool uploadFile(frmLMSMain sender, HttpRequestMessageProperty httpRequest, string jobID, string fileRefID, string fileName)
        {
            sender.UploadStatus += "\n\nUploading the request file.\n";
                try
                {
                    FileTransferServicePortClient client = new FileTransferServicePortClient(FTconfigName);
                    using (OperationContextScope scope = new OperationContextScope(client.InnerChannel))
                    {

                        OperationContext.Current.OutgoingMessageProperties.Add(HttpRequestMessageProperty.Name, httpRequest);

                        UploadFileRequest uploadReq = new UploadFileRequest();

                        uploadReq.fileAttachment = getFileAttachment(fileName);
                        uploadReq.fileReferenceId = fileRefID;
                        uploadReq.taskReferenceId = jobID;
                        uploadReq.fileFormat = "gzip";

                        UploadFileResponse uploadResponse = client.uploadFile(uploadReq);

                        if (uploadResponse.ack.ToString().Equals("Success"))
                        {
                            sender.UploadStatus += uploadResponse.timestamp + " :: " + fileName + " has been successfully uploaded to the server.\n";
                            return true;
                        }
                        else
                        {
                            sender.UploadStatus += uploadResponse.timestamp + " :: " + "Could not upload file to Server\n";

                            if (uploadResponse.errorMessage != null)
                            {
                                ErrorAdmin.updateResponseStatus(uploadResponse, sender, true);
                            }
                            return false;
                        }

                    }
                }
                catch (Exception ex)
                {
                    sender.UploadStatus += ex + "\n";
                    return false;
                }
        }