static private void DownloadPdf(JsonMetadataObject standard, string path) { using (WebClient wClient = new WebClient()) { wClient.DownloadFile(standard.Pdf, path); } }
static public void UpdateStandard(JsonMetadataObject standard) { string basePath = ConfigurationManager.AppSettings["PdfDownloadDirectory"]; string path = string.Concat(basePath, "\\", standard.PdfFileName, ".pdf"); DownloadPdf(standard, path); var doc = CreateDocument(standard, path); var status = _client.Update <MyDocument, object>(u => u .Id(standard.Id) .Doc(doc) .RetryOnConflict(3) .Refresh() ); }
static public MyDocument CreateDocument(JsonMetadataObject standard, string path) { var attachment = new Attachment { Content = Convert.ToBase64String(File.ReadAllBytes(path)), ContentType = "application/pdf", Name = standard.PdfFileName }; var doc = new MyDocument() { StandardId = standard.Id, Title = standard.Title, NotionalEndLevel = standard.NotionalEndLevel, PdfFileName = standard.PdfFileName, PdfUrl = standard.Pdf, File = attachment }; return(doc); }
static public List <JsonMetadataObject> GetStandards() { var standardsJsonBaseRoute = ConfigurationManager.AppSettings["JsonDirectory"]; var standardsList = new List <JsonMetadataObject>(); if (Directory.Exists(standardsJsonBaseRoute)) { var directory = new DirectoryInfo(standardsJsonBaseRoute); var files = directory.GetFiles(); foreach (var fileInfo in files) { using (StreamReader file = File.OpenText(fileInfo.FullName)) { JsonSerializer serializer = new JsonSerializer(); JsonMetadataObject standard = (JsonMetadataObject)serializer.Deserialize(file, typeof(JsonMetadataObject)); standardsList.Add(standard); } } } return(standardsList); }