public static bool DownloadDocument(DocumentView document, string saveAs) { var req = archiveManager.GetDocumentParams(document.id); var result = archiveManager.GetDocument(req, saveAs); return(result); }
public static bool GenerateProcuratoryFile(IDataManager dataManager, ArchiveManager archiveManager, List <Procuratory> procuratories, string saveTo, bool autoCounting = false) { var procuratory = procuratories.First(); if (procuratory == null) { return(false); } var auction = dataManager.GetAuction((int)procuratory.auctionId); if (auction == null) { return(false); } var supplierOrder = dataManager.GetSupplierOrder(auction.Id, procuratory.SupplierId); if (supplierOrder == null) { return(false); } var supplierJournal = dataManager.GetSupplierJournal(supplierOrder.brokerid, procuratory.SupplierId); if (supplierJournal == null) { return(false); } var templateRequisite = archiveManager.GetTemplateRequisite((MarketPlaceEnum)auction.SiteId, DocumentTemplateEnum.Procuratory); if (templateRequisite == null) { return(false); } archiveManager.GetDocument(templateRequisite, saveTo); supplierOrder.Code = supplierJournal.code; var order = new Order(); order.Auction = auction; order.Auction.SupplierOrders.Clear(); order.Auction.SupplierOrders.Add(supplierOrder); order.Auction.Procuratories.Clear(); procuratories.ForEach(p => order.Auction.Procuratories.Add(p)); DocumentFormation.ProcuratoriesService.FormateProcuratory(saveTo, order, autoCounting: autoCounting); return(true); }
//Парсин и формирование Заявки на Каспи private void createOrder(int[] id) { var procuratoryRequisite = ArchiveManager.GetDocumentParams(id[0]); var techSpecRequisite = ArchiveManager.GetDocumentParams(id[1]); var procuratoryPath = procuratoryRequisite.GenerateFilePath(); var techSpecPath = techSpecRequisite.GenerateFilePath(); if (ArchiveManager.GetDocument(procuratoryRequisite, procuratoryPath) && ArchiveManager.GetDocument(techSpecRequisite, techSpecPath)) { var order = ProcuratoryWithTechSpecService.ParseKaspiProcuratory(procuratoryPath); var techSpec = ProcuratoryWithTechSpecService.ParseKaspiTechSpec(techSpecPath); order.Auction.Lots[0].LotsExtended = techSpec; } else { throw new IOException(); } }
public HttpResponseMessage GetFile(int id) { HttpResponseMessage result = null; var docReq = ArchiveManager.GetDocumentParams(id); if (docReq != null) { var f = ArchiveManager.GetDocument(docReq); if (f != null) { result = new HttpResponseMessage(HttpStatusCode.OK); result.Content = new StreamContent(f); result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment"); result.Content.Headers.ContentDisposition.FileNameStar = docReq.fileName; result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream"); result.Content.Headers.ContentType.CharSet = "UTF-8"; result.Content.Headers.ContentLength = f.Length; return(result); } } return(Request.CreateResponse(HttpStatusCode.NotFound)); }
public HttpStatusCode PutFilesInSupplierOrder(int auctionId) { if (!Request.Content.IsMimeMultipartContent()) { throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType); } if (ArchiveManager == null) { throw new HttpResponseException(HttpStatusCode.InternalServerError); } var files = HttpContext.Current.Request.Files; var supplierOrder = DataManager.GetSupplierOrder(auctionId, CurrentUser.SupplierId); if (supplierOrder == null) { throw new HttpResponseException(HttpStatusCode.NotFound); } var auction = DataManager.GetAuction(auctionId); var qualifications = DataManager.GetQualifications(auctionId); if (files.Get("supplierOrderScan") == null || files.Count < 1) { throw new HttpResponseException(HttpStatusCode.BadRequest); } JavaScriptSerializer json_serializer = new JavaScriptSerializer(); Dictionary <string, object> routes_list = (Dictionary <string, object>)json_serializer.DeserializeObject(HttpContext.Current.Request.Form["form"]); var dictionaryFiles = new Dictionary <DocumentRequisite, Stream>(); dictionaryFiles.Add(new DocumentRequisite() { date = auction.Date, market = (MarketPlaceEnum)auction.SiteId, filesListId = supplierOrder.fileListId, number = auction.Number, fileName = files.Get("supplierOrderScan").FileName, section = DocumentSectionEnum.Auction, type = DocumentTypeEnum.SupplierOrder }, files.Get("supplierOrderScan").InputStream); foreach (var qualification in qualifications.Where(q => q.file).ToList()) { if (routes_list[qualification.id.ToString()] != null) { var docReq = ArchiveManager.GetDocumentParams(int.Parse(routes_list[qualification.id.ToString()].ToString())); var streamFile = ArchiveManager.GetDocument(docReq); if (docReq == null || streamFile == null) { throw new HttpResponseException(HttpStatusCode.BadRequest); } dictionaryFiles.Add(docReq, streamFile); } else { var file = files.Get(String.Format("{0}", qualification.id)); if (file == null) { throw new HttpResponseException(HttpStatusCode.BadRequest); } dictionaryFiles.Add(new DocumentRequisite() { date = auction.Date, market = (MarketPlaceEnum)auction.SiteId, filesListId = supplierOrder.fileListId, number = auction.Number, fileName = String.Format("{0}_{1}_{2}.{3}", CurrentUser.SupplierId, qualification.id, qualification.name, Regex.Replace(file.FileName, @"^.*\.", "", RegexOptions.None)), section = DocumentSectionEnum.Auction, type = DocumentTypeEnum.Other }, file.InputStream); } } foreach (var item in dictionaryFiles) { if (ArchiveManager.PutDocument(item.Value, item.Key) < 1) { throw new HttpResponseException(HttpStatusCode.InternalServerError); } } DataManager.UpdateStatusOnSupplierOrder(supplierOrder.Id, 5); return(HttpStatusCode.OK); }
public static string LoadTemplateToLocalStorage(this ArchiveManager archiveManager, DocumentRequisite requisite) { var localPath = GenerateFilePath(requisite); return(archiveManager.GetDocument(requisite, localPath) ? localPath : null); }
public HttpResponseMessage DonwloadZip([FromUri] List <int> list, [FromUri] List <int> docsType) { if ((list == null && (list.Count == 0 || list.Count > MAX_FILE_LIST_UPDALODED)) && (docsType == null && docsType.Count == 0)) { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } var tempFolderArchive = HttpContext.Current.Server.MapPath(string.Format("~/App_Data/{0}", Guid.NewGuid())); var zipFileName = string.Format("{0}.zip", tempFolderArchive); var acrhive = new ArchiveManager(DataManager); int countFilesFound = 0; foreach (int listId in list) { var descriptionList = ArchiveManager.GetFileListDescription(listId); if (string.IsNullOrEmpty(descriptionList)) { descriptionList = string.Format("Папка № {0}", listId); } var files = ArchiveManager.GetFilesFromList(listId); foreach (var docReq in files) { if (!docsType.Any(d => d == (int)docReq.type)) { continue; } using (var file = ArchiveManager.GetDocument(docReq)) { if (file == null) { continue; } var dir = Directory.CreateDirectory(string.Format("{0}/{1}", tempFolderArchive, descriptionList.Replace("/", "_"))); if (dir != null) { using (var f = File.Open(string.Format("{0}/{1}", dir.FullName, docReq.fileName.Replace("/", "_")), FileMode.Create)) { file.CopyTo(f); countFilesFound++; } } } } } if (countFilesFound == 0) { return(new HttpResponseMessage(HttpStatusCode.NotFound)); } ZipFile.CreateFromDirectory(tempFolderArchive, zipFileName); var result = new HttpResponseMessage(HttpStatusCode.OK); Stream stream = File.OpenRead(zipFileName); result.Content = new StreamContent(stream); result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment"); result.Content.Headers.ContentDisposition.FileNameStar = string.Format("Архив файлов({0}).zip", DateTime.Now.ToShortDateString()); result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream"); result.Content.Headers.ContentType.CharSet = "UTF-8"; result.Content.Headers.ContentLength = stream.Length; Directory.Delete(tempFolderArchive, true); tempArhiveFiles.Add(zipFileName); return(result); }