public override bool SaveFile(PostFileModel postFileData) { bool result = base.SaveFile(postFileData); AuthToken userAuthToken = postFileData.UserAuthToken; // Add the user oAuthToken to the database. if (!string.IsNullOrEmpty(userAuthToken.AccessToken)) { postFileData.UserAuthToken = this.userService.AddUpdateAuthToken(postFileData.UserAuthToken); } return result; }
public virtual bool SaveFile(PostFileModel postFileData) { Check.IsNotNull(postFileData, "postFileData"); // get the curent file object var file = this.GetFileByFileId(postFileData.FileId); file.ModifiedOn = DateTime.UtcNow; file.RepositoryId = postFileData.SelectedRepositoryId; // update the file var status = this.UpdateFile(file); // commit the above changes before calling the update metadata sheet this.UnitOfWork.Commit(); return status; }
public HttpResponseMessage Publish() { string message = string.Empty; HttpStatusCode status = HttpStatusCode.OK; PostFileModel dataDetail = new PostFileModel(); try { diagnostics.WriteInformationTrace(TraceEventId.Flow, "Into publish"); if (HttpContext.Current.Request["PostFileData"] != null) { var postFileString = HttpContext.Current.Request["PostFileData"]; if (postFileString != null) { //diagnostics.WriteInformationTrace(TraceEventId.Flow, "Into publishing3"); /**************************************************** * TODO: Try catch block below is required to handle the case where the * clients send post request with JSON payload as plain text. * The API needs to be refactored to take the model as input * and have the MVC framework resolve/deserialize the payload * into model object. * **************************************************/ PostFileModel postFileData = default(PostFileModel); try { postFileData = Helper.DeSerializeObject<PostFileModel>(postFileString.DecodeFrom64(), "postFile"); } catch (Exception) { // If the data is not base 64 encoded using (MemoryStream stream = new MemoryStream(Encoding.Unicode.GetBytes(postFileString))) { DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer(typeof(PostFileModel)); postFileData = (PostFileModel)jsonSerializer.ReadObject(stream); } } DM.Repository repository = repositoryService.GetRepositoryById(postFileData.SelectedRepositoryId); this.fileService = this.fileServiceFactory.GetFileService(repository.BaseRepository.Name); // Get the AuthToken from the request. TODO need to move below code to SkyDriveFileController. AuthToken userAuthToken = postFileData.UserAuthToken; userAuthToken.UserId = this.user.UserId; userAuthToken.RespositoryId = repository.RepositoryId; // Save the file details to db and publish logic this.fileService.SaveFile(postFileData); return Request.CreateResponse<OperationStatus>(HttpStatusCode.OK, OperationStatus.CreateSuccessStatus()); } } } catch (ArgumentNullException ane) { diagnostics.WriteErrorTrace(TraceEventId.Exception, ane); status = HttpStatusCode.BadRequest; if (ane.ParamName.Equals("fileService")) { message = MessageStrings.File_Service_Is_Null; } else { message = ane.Message + ane.StackTrace + ane.GetType().ToString(); } } catch (Exception ex) { diagnostics.WriteErrorTrace(TraceEventId.Exception, ex); message = ex.Message + ex.StackTrace + ex.GetType().ToString(); if (null != ex.InnerException) { message += ex.InnerException.Message + ex.InnerException.StackTrace + ex.InnerException.GetType().ToString(); } status = HttpStatusCode.InternalServerError; } return Request.CreateErrorResponse(status, message); }