public void Execute(object parameter) { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Multiselect = true; openFileDialog.Filter = "Images (*.BMP;*.JPG;*.GIF)|*.BMP;*.JPG;*.GIF|All files (*.*)|*.*"; if (openFileDialog.ShowDialog() == true) { foreach (string filename in openFileDialog.FileNames) { MaximoDocLinks maximoDocLinks = new MaximoDocLinks(); maximoDocLinks.ownertable = "WORKORDER"; maximoDocLinks.printthrulink = true; maximoDocLinks.description = "CB REPAIR PHOTO"; maximoDocLinks.urltype = "FILE"; maximoDocLinks.doctype = "PHOTOS-A"; maximoDocLinks.urlname = filename;; maximoDocLinks.documentdata = DocumentUpload(filename); maximoDocLinks.syncronizationStatus = LocalDBLibrary.model.SyncronizationStatus.CREATED; maximoDocLinks.document = System.IO.Path.GetFileName(filename); maximoDocLinks.fileName = System.IO.Path.GetFileName(filename); if (maximoDocLinks.document.Length > 20) { maximoDocLinks.document = maximoDocLinks.document.Substring(0, 20); } maximoDocLinks.path = filename;; WorkOrderDetailVM.Attachments.Add(maximoDocLinks); } } }
public void deleteAttachment(MaximoDocLinks docLink) { String path = generateFileName(docLink.docinfoid, docLink.fileName); try { FileInfo file = new FileInfo(path); file.Delete(); } catch (Exception ex) { AppContext.Log.Error(ex); } }
public string DownloadAttachment(MaximoDocLinks maximoDocLinks, string url) { System.IO.Directory.CreateDirectory("C:\\CatchBasin\\attachments"); string path = $"C:\\CatchBasin\\attachments\\{maximoDocLinks.docinfoid}_{maximoDocLinks.fileName}"; if (!File.Exists(path)) { try { using (var client = new WebClient()) { client.Headers.Add(HttpRequestHeader.Cookie, $"{_jsessionid_Cookie_Name}=sessionId; {_ltpatoken2_Cookie_Name}={token};"); client.DownloadFileAsync(new Uri(url), path); } } catch (Exception e) { AppContext.Log.Warn($"download-attachment-error : {e.ToString()}"); } } return(path); }
public MaximoDocLinks GetMaximoDocLinks(MaximoWorkOrder maximoWorkOrder, string doclinkHref) { char[] spearator = { '/' }; var list = doclinkHref.Split(spearator); var identifier = list.Last(); var request = createRequest("/os/dcw_cb_wo/" + maximoWorkOrder.workorderid + "/doclinks/meta/" + identifier, false); var response = restClient.Execute(request); if (!response.IsSuccessful) { AppContext.Log.Warn("rest-service-error : " + response.StatusCode + " - [" + response.Content + "]"); throw new Exception("rest-service-error : " + response.StatusCode + " - [" + response.Content + "]"); } MaximoDocLinks maximoDocLinksRestResponse = JsonConvert.DeserializeObject <MaximoDocLinks>(response.Content); maximoDocLinksRestResponse.path = DownloadAttachment(maximoDocLinksRestResponse, doclinkHref); return(maximoDocLinksRestResponse); }
public MaximoDocLinks createAttachment(MaximoWorkOrder maximoWorkOrder, MaximoDocLinks doc) { AppContext.Log.Info($"[MX] create attachment : [{maximoWorkOrder.wonum}] - [{maximoWorkOrder.workorderid}]"); var request = createRequest("/os/dcw_cb_wo/" + maximoWorkOrder.workorderid + "/doclinks", false, Method.POST); request.AddHeader("x-document-meta", "Attachments"); request.AddHeader("slug", doc.fileName); request.AddHeader("x-document-description", doc.description); request.AddHeader("custom-encoding", "base64"); request.AddParameter("text/plain", doc.documentdata, ParameterType.RequestBody); var response = restClient.Execute(request); if (!response.IsSuccessful) { AppContext.Log.Error($"[MX] - create attachment Error url : {response.ResponseUri.ToString()}"); AppContext.Log.Error($"[MX] - create attachment Error request body : {request.Parameters.FirstOrDefault(p => p.Type == ParameterType.RequestBody)}"); AppContext.Log.Error($"[MX] - create attachment operation response : [{response.StatusCode}] - [{response.Content}]"); throw new Exception("create-attachment-error : " + response.StatusCode + " - [" + response.Content + "]"); } AppContext.Log.Info($"[MX] successfully create attachment : [{maximoWorkOrder.wonum}] - [{maximoWorkOrder.workorderid}]"); string doclinkHref = null; foreach (var responseHeader in response.Headers) { if (responseHeader.Name.Equals("Location")) { doclinkHref = responseHeader.Value.ToString(); } } return(GetMaximoDocLinks(maximoWorkOrder, doclinkHref)); }