string ISendJobG8Command.SendApplication(ICommunicationUser user, JobAdEntry jobAd, string resumeFileName, FileContents resumeContents, InternalApplication application, IEnumerable <ApplicationAnswer> answers) { var request = new UploadRequestMessage { Body = new UploadRequestBody { ApplicationXml = Serialize(CreateApplicationResponse(user, jobAd, resumeFileName, resumeContents, application, answers)) } }; string result; var service = _serviceManager.Create(); try { var response = service.Send(request); result = response.Body.Result; } catch (Exception) { _serviceManager.Abort(service); throw; } _serviceManager.Close(service); return(result); }
UploadResponseMessage IMockJobG8Server.Send(UploadRequestMessage request) { Requests.Add(request); return(new UploadResponseMessage { Body = new UploadResponseBody { Result = "SUCCESS" } }); }
/// <summary> /// Uploads the passed in diagnostics data from the calling client. /// </summary> /// <param name="request">The request.</param> /// <returns>UploadResponseMessage.</returns> public UploadResponseMessage UploadDiagnosticsData(UploadRequestMessage request) { var rtnVal = new UploadResponseMessage { Success = false, Reason = "Unknown" }; if (request == null) { Logger.Warn("No request message sent"); rtnVal.Reason = "No request message"; return(rtnVal); } if (string.IsNullOrWhiteSpace(request.FileName) || request.DataStream == null) { Logger.Warn("Request message sent with invalid file name or data stream"); rtnVal.Reason = "Invalid request message either file name or data is invalid"; return(rtnVal); } Logger.Info($"Received diagnostics upload request {request.FileName}"); try { var diagnosticDir = Settings.Default.DiagnosticPackagePath; Directory.CreateDirectory(diagnosticDir); var pathToForFile = Path.Combine(diagnosticDir, request.FileName); byte[] buffer = new byte[BufferSize]; using (var strm = new FileStream(pathToForFile, FileMode.Create, FileAccess.Write)) { var bytesRead = request.DataStream.Read(buffer, 0, BufferSize); while (bytesRead > 0) { strm.Write(buffer, 0, bytesRead); bytesRead = request.DataStream.Read(buffer, 0, BufferSize); } strm.Close(); } rtnVal.Success = true; rtnVal.Reason = "Success"; } catch (Exception exp) { Logger.Error($"Could not save off data stream for '{request.FileName}'", exp); rtnVal.Reason = exp.Message; } return(rtnVal); }
private UploadResponseMessage ValidateFile(UploadRequestMessage requestMessage) { UploadResponseMessage response = new UploadResponseMessage(); if (requestMessage == null) { ErrorLogManager.WriteLog(response, "TestFile", "002", "Request message should not be empty."); } else { if (string.IsNullOrEmpty(requestMessage.LoginName)) { ErrorLogManager.WriteLog(response, "TestFile", "003", "Login name is mandatory."); } if (string.IsNullOrEmpty(requestMessage.Password)) { ErrorLogManager.WriteLog(response, "TestFile", "004", "Password is mandatory."); } if (requestMessage.gpxFiles == null) { ErrorLogManager.WriteLog(response, "TestFile", "005", "File list should not be empty."); } else { //var item = requestMessage.FileList; foreach (var item in requestMessage.gpxFiles) { if (string.IsNullOrEmpty(item.FileName)) { ErrorLogManager.WriteLog(response, item.FileName, "006", "File name is mandatory."); } if (item.FileData == null) { ErrorLogManager.WriteLog(response, item.FileName, "007", "File data should not be empty."); } if (item.FileData != null && item.FileData.Length == 0) { ErrorLogManager.WriteLog(response, item.FileName, "007", "File data should not be empty."); } } } } return(response); }
public UploadResponseMessage UploadFile(UploadRequestMessage requestMessage, string filePath = "") { UploadResponseMessage response = new UploadResponseMessage(); try { response = ValidateFile(requestMessage); if (response != null && response.Log == null) { uploadFileDataProvider = new UploadDataProvider(); response = uploadFileDataProvider.UploadFile(requestMessage, filePath); } } catch (Exception ex) { ErrorLogManager.WriteLog(response, "TestFile", "999", ex.Message, true, ex: ex); } return(response); }
string ISendJobG8Command.SendApplication(ICommunicationUser user, JobAdEntry jobAd, string resumeFileName, FileContents resumeContents, InternalApplication application, IEnumerable <ApplicationAnswer> answers) { var request = new UploadRequestMessage { Body = new UploadRequestBody { ApplicationXml = Serialize(CreateApplicationResponse(user, jobAd, resumeFileName, resumeContents, application, answers)) } }; var service = _factory.CreateChannel(new EndpointAddress(jobAd.Integration.ExternalApplyApiUrl)); var channel = service as IClientChannel; if (channel != null) { channel.Open(); } try { var response = service.UploadApplication(request); if (channel != null) { channel.Close(); } return(response.Body.Result); } catch (Exception) { if (channel != null) { channel.Abort(); } throw; } }
public HttpResponseMessage UploadFile([FromBody] UploadRequestMessage requestMessage) { string filepath = System.Web.Hosting.HostingEnvironment.MapPath("~\\FileUpload\\"); uploadBusinessProvider = new UploadFileBusinessAccessLayer(filepath); UploadResponseMessage response = uploadBusinessProvider.UploadFile(requestMessage, filepath); //string jsStartTag="{Log:["; //string jsEndTag = "]}"; //StringBuilder jsString = new StringBuilder(); //if (response!=null) //{ // jsString.Append(jsStartTag); // for (int i = 0; i < response.Log.Count; i++) // { // jsString.Append(@"{""FileName:" + response.Log[i].FileName+@"""-"); // jsString.Append(@"""Code:" + response.Log[i].Code + @"""-"); // jsString.Append(@"""Message:" + response.Log[i].Message + @"""-"); // jsString.Append(@"""Status:" + response.Log[i].Status.ToString() + @"""}"); // if (i < response.Log.Count - 1) jsString.Append(","); // } // //foreach (var item in response.Log) // //{ // // jsString.Append(@"{\" + "FileName" + @"\" + @":\" + item.FileName+@"\-"); // // jsString.Append(@"\" + "Code" + @"\" + @":\" + item.Code + @"\-"); // // jsString.Append(@"\" + "Message" + @"\" + @":\" + item.Message + @"\-"); // // jsString.Append(@"\" + "Status" + @"\" + @":\" + item.Status.ToString() + @"\}"); // //} // jsString.Append(jsEndTag); //} //string responsResult = jsString.ToString(); HttpResponseMessage tempResponse = Request.CreateResponse(HttpStatusCode.OK, response); ParseResponse(tempResponse); return(tempResponse); }
UploadResponseMessage IMockJobG8Service.Send(UploadRequestMessage request) { return(JobG8Server.Send(request)); }
public UploadResponseMessage UploadFile(UploadRequestMessage requestMessage, string filePath = "") { UploadResponseMessage response = new UploadResponseMessage(); response.Log = new List <UploadFileStatus>(); try { StringBuilder sqlString = new StringBuilder(); sqlString.Append("select * from LoginDtls where LoginName='"); sqlString.Append(requestMessage.LoginName); sqlString.Append("' and cast(Password as varbinary(20))=cast('"); sqlString.Append(requestMessage.Password); sqlString.Append("' as varbinary(50)) and IsActive=1"); var login = DataAccessLayer.ReturnDataTable(sqlString.ToString()); if (login != null && login.Rows != null && login.Rows.Count > 0) { UserRoleId = Convert.ToInt32(login.Rows[0]["RoleId"]); UserId = Convert.ToInt32(login.Rows[0]["LoginId"]); UserName = Convert.ToString(login.Rows[0]["LoginName"]); if (UserRoleId == 5) { sqlString = new StringBuilder(); sqlString.Append("Select * FROM StudentMaster Where LoginId = "); sqlString.Append(UserId); var student = DataAccessLayer.ReturnDataTable(sqlString.ToString()); if (student != null && student.Rows.Count > 0) { schoolId = Convert.ToInt32(student.Rows[0]["SchoolId"]); classId = Convert.ToInt32(student.Rows[0]["ClassId"]); cityId = Convert.ToInt32(student.Rows[0]["CityId"]); studentId = Convert.ToInt32(student.Rows[0]["StudentId"]); } } else { ErrorLogManager.WriteLog(response, "TestFile", "013", "Only Student can upload file."); return(response); } //throw new Exception("To Verify the Error log file writting"); //var item = requestMessage.FileData; foreach (var item in requestMessage.gpxFiles) { Upload(item, response, filePath); } } else { ErrorLogManager.WriteLog(response, "TestFile", "000", "Unable to find user."); } } catch (Exception ex) { ErrorLogManager.WriteLog(response, "TestFile", "999", ex.Message, ex: ex); } return(response); }