public FileResult DownloadFile(int fileId, string mimeType, string fileName) { Check.IsNotEmptyOrWhiteSpace(mimeType, "mimeType"); Check.IsNotEmptyOrWhiteSpace(fileName, "fileName"); Stream fileStream = null; // create the object of HttpWeb Request Manager webRequestManager = new HttpWebRequestManager(); // set the request details webRequestManager.SetRequestDetails (new RequestParams() { RequestURL = string.Concat(BaseController.BaseBlobApiPath, "?fileId=" + fileId), TimeOut = (BaseController.PostFileTimeOutMinutes * 60 * 1000) } ); HttpWebResponse response = webRequestManager.HttpWebRequest.GetResponse() as HttpWebResponse; // In case of CSV change the mime type as zip since the csv will have the metadata as a sepearte file if (Path.GetExtension(fileName) == FileService.Constants.CSVFileExtension) { mimeType = Helpers.Constants.APPLICATION_XZIP; fileName = fileName.Replace(Path.GetExtension(fileName), ".zip"); } fileStream = response.GetResponseStream(); return File(fileStream, mimeType, fileName); }
private ManageReopsitoryViewModel GetSelectedViewModel(int repositoryId) { ManageReopsitoryViewModel viewModel = new ManageReopsitoryViewModel(); try { JavaScriptSerializer jsSerializer = new JavaScriptSerializer(); jsSerializer.MaxJsonLength = int.MaxValue; // create the object of HttpWeb Request Manager webRequestManager = new HttpWebRequestManager(); // set the request details to get repostiry list webRequestManager.SetRequestDetails(new RequestParams() { RequestURL = string.Concat(BaseController.BaseWebApiRepositoryTypesPath), }); string repositoryTypeList = webRequestManager.RetrieveWebResponse(); var lstRepositoryType = jsSerializer.Deserialize<IList<BaseRepository>>(repositoryTypeList); if (repositoryId > 0) { // set the request details to get file list webRequestManager.SetRequestDetails(new RequestParams() { RequestURL = string.Concat(BaseController.BaseWebApiRepositoryPath + repositoryId), }); string selRepositoryStr = webRequestManager.RetrieveWebResponse(); var selRepository = jsSerializer.Deserialize<Repository>(selRepositoryStr); viewModel.SetValuesFrom(selRepository); } else { // Add default metadata viewModel.AddDefaultMetaData(); } Session[Constants.REPOSITORYVIEWMODEL] = viewModel; viewModel.RepositoryTypes = new SelectList(lstRepositoryType, Constants.BASEREPOSITORYID, Constants.NAMESTRING); } catch { viewModel = null; } return viewModel; }
/// <summary> /// Method will validate the user and if the user exists returns true else false /// </summary> /// <returns>returns true on success else false</returns> private bool ValidateAndSetUser() { // create the object of HttpWeb Request Manager webRequestManager = new HttpWebRequestManager(); // set the request details webRequestManager.SetRequestDetails(new RequestParams() { RequestURL = BaseWebApiUserPath, TimeOut = (BaseController.PostFileTimeOutMinutes * 60 * 1000) } ); string responseData = string.Empty; try { responseData = webRequestManager.RetrieveWebResponse(); JavaScriptSerializer js = new JavaScriptSerializer(); js.MaxJsonLength = int.MaxValue; // set the data to base class UserData = js.Deserialize<User>(responseData); } catch (WebException we) { HttpWebResponse response = we.Response as HttpWebResponse; if (response.StatusCode.Equals(HttpStatusCode.NotFound)) { return false; } } return true; }
/// <summary> /// Private method to get the repository view model list. /// </summary> /// <returns>Repository view model collection.</returns> private IList<RepositoryViewModel> GetRepositoryViewModel() { string repositoryList = string.Empty; IList<RepositoryViewModel> lstRepViewModel = new List<RepositoryViewModel>(); try { // create the object of HttpWeb Request Manager webRequestManager = new HttpWebRequestManager(); // set the request details to get repostiry list webRequestManager.SetRequestDetails(new RequestParams() { RequestURL = string.Concat(BaseController.BaseWebApiRepositoryPath), }); repositoryList = webRequestManager.RetrieveWebResponse(); JavaScriptSerializer jsSerializer = new JavaScriptSerializer(); jsSerializer.MaxJsonLength = int.MaxValue; var lstRepository = jsSerializer.Deserialize<IList<RepositoryDataModel>>(repositoryList); foreach (var repositoryModel in lstRepository) { RepositoryViewModel repModel = new RepositoryViewModel(); repModel.SetValuesFrom(repositoryModel); lstRepViewModel.Add(repModel); } } catch { lstRepViewModel = null; } return lstRepViewModel; }
/// <summary> /// Method reurns list of document meta data types /// </summary> /// <returns></returns> private static List<MetaDataTypeViewModel> GetMetaDataTypes() { List<MetaDataTypeViewModel> documentMetadataTypes = new List<MetaDataTypeViewModel>(); HttpWebRequestManager webRequestManager = new HttpWebRequestManager(); webRequestManager.SetRequestDetails(new RequestParams() { RequestURL = string.Concat(BaseController.BaseWebApiFilePath, "?type=METADATATYPES"), }); string columnTypeJson = webRequestManager.RetrieveWebResponse(); var metaDataTypes = new JavaScriptSerializer().Deserialize<IEnumerable<MetadataType>>(columnTypeJson); if (metaDataTypes != null) { foreach (var item in metaDataTypes) { documentMetadataTypes.Add(new MetaDataTypeViewModel() { Id = item.MetadataTypeId.ToString(), Name = item.Name }); } } return documentMetadataTypes; }
/// <summary> /// Action method to save the repository data to the database. /// </summary> /// <param name="repositoryViewModel">Repository viewmodel.</param> /// <returns>Json result with the status.</returns> public ActionResult SaveRepository(ManageReopsitoryViewModel repositoryViewModel) { string message = string.Empty; string status = "success"; JavaScriptSerializer jsSerializer = new JavaScriptSerializer(); try { if (repositoryViewModel != null) { Repository repModel = new Repository(); repModel = repositoryViewModel.SetValuesTo(repModel); // serlize the data file before passing to API string repositoryData = repModel.SerializeObject<Repository>("repositoryModel"); // create the object of HttpWeb Request Manager webRequestManager = new HttpWebRequestManager(); webClientManager = new WebClientRequestManager(); webRequestManager.SetRequestDetails(new RequestParams() { RequestURL = string.Concat(BaseController.BaseWebApiRepositoryPath + "?repositoryName=" + repModel.Name), }); string repositoryIdResult = webRequestManager.RetrieveWebResponse(); int repositoryResult = jsSerializer.Deserialize<int>(repositoryIdResult); if (repositoryResult == 0 || repModel.RepositoryId == repositoryResult) { NameValueCollection values = new NameValueCollection(); values.Add("repositoryModel", repositoryData.EncodeTo64()); string responseString = webClientManager.UploadValues(new RequestParams() { RequestURL = string.Concat(BaseController.BaseWebApiRepositoryPath), RequestMode = RequestMode.POST, AllowAutoRedirect = false, Values = values }); if (!string.IsNullOrEmpty(webClientManager.RedirectionURL)) { status = "redirect"; message = webClientManager.RedirectionURL; return Json(new { Status = status, Message = message }); } bool postResult = jsSerializer.Deserialize<bool>(responseString); if (postResult) { status = "success"; // after updating the repostory metadata field,delete the repository metadata field that are marked for deletion if (repositoryViewModel.DeletedMetaDataFieldIds != null && repositoryViewModel.DeletedMetaDataFieldIds.Length > 0) { string deleteResponseString = webClientManager.UploadValues(new RequestParams() { RequestURL = string.Concat(BaseController.BaseWebApiRepositoryPath, "?repositorId=", repositoryViewModel.RepositoryId, "&repositoryMetadataFields=", repositoryViewModel.DeletedMetaDataFieldIds), RequestMode = RequestMode.DELETE }); jsSerializer = new JavaScriptSerializer(); jsSerializer.Deserialize<bool>(deleteResponseString); } } else { ViewBag.ErrorMessage = Messages.RepositoryErrMsg; status = "error"; message = Messages.RepositoryErrMsg; } } else { status = "error"; message = Messages.DuplicateRepositoryMsg; } } else { status = "error"; message = Messages.RepositoryErrMsg; } } catch (WebException webException) { using (Stream stream = webException.Response.GetResponseStream()) { using (StreamReader reader = new StreamReader(stream)) { status = "error"; message = reader.ReadToEnd(); jsSerializer = new JavaScriptSerializer(); var data = jsSerializer.Deserialize<Dictionary<string,object>>(message); message = (string)data.First(m=>m.Key == "Message").Value; } } } catch (Exception exception) { message = exception.Message; } return Json(new { Status = status, Message = message }); }
/// <summary> /// Helper method to get the single rule view model. /// </summary> /// <param name="id">Quality check id.</param> /// <returns>Quality check rule view model.</returns> private QCRuleViewModel GetQCRuleViewModel(int id) { QCRuleViewModel ruleModel = new QCRuleViewModel(); // create the object of HttpWeb Request Manager webRequestManager = new HttpWebRequestManager(); // set the request details to get repostiry list webRequestManager.SetRequestDetails(new RequestParams() { RequestURL = string.Concat(BaseController.BaseWebApiFilePath, "?type=QCCOLUMNTYPES"), }); string columnTypeJson = webRequestManager.RetrieveWebResponse(); JavaScriptSerializer jsSerializer = new JavaScriptSerializer(); jsSerializer.MaxJsonLength = int.MaxValue; var lstQCColumnTypes = jsSerializer.Deserialize<IEnumerable<QualityCheckColumnType>>(columnTypeJson); if (id > 0) { // set the request details to get file list webRequestManager.SetRequestDetails(new RequestParams() { RequestURL = string.Concat(BaseController.BaseWebApiQCPath + id), }); string qcRuleList = webRequestManager.RetrieveWebResponse(); var qualityCheckData = jsSerializer.Deserialize<QualityCheckModel>(qcRuleList); ruleModel.SetValuesFrom(qualityCheckData, lstQCColumnTypes); } else { QCHeaderViewModel headerModel = new QCHeaderViewModel(); headerModel.QCColumnTypes = new SelectList(lstQCColumnTypes, "QualityCheckColumnTypeId", "Name"); headerModel.Order = 1; ruleModel.LstHeaderNames.Add(headerModel); } return ruleModel; }
/// <summary> /// Method to get the quality check view model. /// </summary> /// <returns></returns> private QualityCheckViewModel GetQualityCheckViewModel() { QualityCheckViewModel viewModel = new QualityCheckViewModel(); // create the object of HttpWeb Request Manager webRequestManager = new HttpWebRequestManager(); // set the request details to get file list webRequestManager.SetRequestDetails(new RequestParams() { RequestURL = string.Concat(BaseController.BaseWebApiQCPath), }); string qcRulesList = webRequestManager.RetrieveWebResponse(); // set the request details to get repostiry list webRequestManager.SetRequestDetails(new RequestParams() { RequestURL = string.Concat(BaseController.BaseWebApiFilePath, "?type=QCCOLUMNTYPES"), }); string columnTypeJson = webRequestManager.RetrieveWebResponse(); JavaScriptSerializer jsSerializer = new JavaScriptSerializer(); jsSerializer.MaxJsonLength = int.MaxValue; var lstQCRules = jsSerializer.Deserialize<IList<QualityCheckModel>>(qcRulesList); lstQCRules = lstQCRules.OrderByDescending(rul => rul.QualityCheckData.CreatedOn).ToList(); var lstQCColumnTypes = jsSerializer.Deserialize<IEnumerable<QualityCheckColumnType>>(columnTypeJson); foreach (var qcObj in lstQCRules) { QCRuleViewModel rule = new QCRuleViewModel(); rule.SetValuesFrom(qcObj, lstQCColumnTypes); viewModel.QualityCheckRules.Add(rule); } return viewModel; }