public HttpResponseMessage GetDocument(string oid) { try { var info = new DocumentInfo { OidDocument = Guid.Parse(oid), Version = 1 }; if (!string.IsNullOrWhiteSpace(oid)) { DocsDocument.DownloadDocument(info, ConfigHelper.DownloadLocation, DocumentDownloadMode.LastVersion); } var result = new HttpResponseMessage(HttpStatusCode.OK); var stream = new FileStream(info.DocumentName, FileMode.Open); result.Content = new StreamContent(stream); result.Content.Headers.ContentType = new MediaTypeHeaderValue(MimeType.GetMimeType(info.DocumentName)); result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = Path.GetFileName(info.DocumentName) }; return(result); } catch (Exception ex) { return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex)); } }
/// <summary> /// Get Attached Documents /// </summary> /// <param name="taskOid">TaskOid</param> /// <returns>List of DocumentModel</returns> private IEnumerable <DocumentModel> GetAttachedDocuments(Guid taskOid) { var properties = TasksService.GetPropertiesForTask( new GetPropertiesForTaskRequest { TaskOid = taskOid }); var docs = new List <DocumentModel>(); var oids = new List <Guid>(); foreach (var prop in properties.Properties) { if (prop.Type == PropertyType.FlowDoc.ToString()) { oids.Add(Guid.Parse(prop.Value)); } } var res = DocsDocument.DocumentInfos(oids.ToArray()); return(res.Select(d => new DocumentModel { DocumentOid = d.OidDocument.ToString(), DocumentName = d.DocumentName }).ToList()); }
[HttpPost] // load file xamlx in server public ActionResult LoadWorkflow(string fname) { if (ModelState.IsValid) { var sketches = TasksService.GetSketchForFilter(new GetSketchForFilterRequest { Name = fname, Statuses = new[] { SketchStatusType.Saved, SketchStatusType.SentToSketch } }); if (sketches.Sketches.Count > 0) { string path = "/SketchWorkFlows/"; string fileName = fname + ".xamlx"; DocsDocument.DownloadDocument(new DocumentInfo { OidDocument = sketches.Sketches[0].XamlxOid, DocumentName = fileName, Path = path }, ConfigHelper.DownloadLocation, DocumentDownloadMode.LastVersion); XmlDocument xamlx = new XmlDocument(); xamlx.Load(Path.Combine(ConfigHelper.DownloadLocation, fileName)); //convert xml to json String json = Newtonsoft.Json.JsonConvert.SerializeXmlNode(xamlx); return(Json(json)); } return(Json("Error")); } return(Json("Error")); }
public string Get(string fname) { try { //return "loading: " + fname; if (fname.Equals("_empty_")) { string path = HostingEnvironment.MapPath("~/WorkFlows/template/" + FDEFAULT); if (File.Exists(path)) { XmlDocument form = new XmlDocument(); form.Load(path); string json = Newtonsoft.Json.JsonConvert.SerializeXmlNode(form); return(json); } } else { var sketches = TasksService.GetSketchForFilter(new GetSketchForFilterRequest { Name = fname, Statuses = new[] { SketchStatusType.Saved, SketchStatusType.SentToSketch } }); if (sketches.Sketches.Count > 0) { string path = "/SketchWorkFlows/"; string fileName = fname + ".xamlx"; DocsDocument.DownloadDocument( new DocumentInfo { OidDocument = sketches.Sketches[0].XamlxOid, DocumentName = fileName, Path = path }, ConfigHelper.DownloadLocation, DocumentDownloadMode.LastVersion); XmlDocument xamlx = new XmlDocument(); xamlx.Load(Path.Combine(ConfigHelper.DownloadLocation, fileName)); //convert xml to json string json = Newtonsoft.Json.JsonConvert.SerializeXmlNode(xamlx); return(json); } } var result = Request.CreateResponse(HttpStatusCode.NotFound); throw new HttpResponseException(result); } catch (Exception ex) { var result = Request.CreateResponse(HttpStatusCode.InternalServerError, ex); throw new HttpResponseException(result); } }
public ActionResult UploadFile(string completeTask, FormCollection values, HttpPostedFileBase workflowFile) { // Custom computation var oldOid = GetDocumentOid(values["TaskOid"]); if (completeTask == DEPLOY) { string msg = string.Empty; CopyFile(workflowFile, values["TaskParameterSketchWorkflowPath"], ref msg); var workflowFullFileName = GetFullPath(workflowFile, values["TaskParameterSketchWorkflowPath"]); var newOid = DocsDocument.UploadDocument(new DocumentInfo { Owner = User.Identity.Name, DocumentName = Path.GetFileName(workflowFullFileName), Description = "Sketch Workflow", OidDocument = Guid.Parse(oldOid), Path = "/SketchWorkFlows/" }, GetFullPath(workflowFile, values["TaskParameterSketchWorkflowPath"]), DocumentUploadMode.Overwrite ); TasksService.AddWorkflow(new AddWorkflowRequest { WorkflowCode = values["TaskParameterSketchWorkflowCode"].ToString(), ServiceUrl = values["TaskParameterSketchWorkflowUrl"].ToString() + Path.GetFileName(workflowFile.FileName), BindingConfiguration = "BasicHttpBinding_FlowTasks" }); TasksService.SketchWorkflow(new SketchWorkflowRequest { Name = values["TaskParameterSketchWorkflowCode"].ToString(), ChangedBy = User.Identity.Name, Status = SketchStatusType.DeployedProd, XamlxOid = newOid.ToString() }); } else if (completeTask == SEND_BACK) { TasksService.SketchWorkflow(new SketchWorkflowRequest { Name = values["TaskParameterSketchWorkflowCode"].ToString(), ChangedBy = User.Identity.Name, Status = SketchStatusType.SentToSketch, XamlxOid = oldOid }); } // Exit from this area and go back to main control return(RedirectFromArea(completeTask, values)); }
public HttpResponseMessage Save(string fname, [FromBody] string content) { try { //return new HttpResponseMessage(HttpStatusCode.Created); content = content.Replace("\\n", "
").Replace("< ", "<").Replace(" >", ">"); var newOid = DocsDocument.UploadDocument(new DocumentInfo { Owner = User.Identity.Name, DocumentName = fname + ".xamlx", Description = "Sketch Workflow", Path = "/SketchWorkFlows/" }, Encoding.ASCII.GetBytes(content), DocumentUploadMode.Overwrite ); var sketches = TasksService.GetSketchForFilter(new GetSketchForFilterRequest { Name = fname, Statuses = new[] { SketchStatusType.SentToSketch } }); SketchStatusType sketchStatus = sketches.Sketches.Count() > 0 ? SketchStatusType.SentToSketch : SketchStatusType.Saved; TasksService.SketchWorkflow(new SketchWorkflowRequest { Name = fname, ChangedBy = User.Identity.Name, Status = sketchStatus, XamlxOid = newOid.ToString() }); return(new HttpResponseMessage(HttpStatusCode.Created)); } catch (Exception ex) { return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex)); } }
[HttpPost] // public ActionResult SaveWorkflow(string fname, string content) { if (ModelState.IsValid) { content = content.Replace("\\n", "
").Replace("< ", "<").Replace(" >", ">"); var newOid = DocsDocument.UploadDocument(new DocumentInfo { Owner = User.Identity.Name, DocumentName = fname + ".xamlx", Description = "Sketch Workflow", Path = "/SketchWorkFlows/" }, Encoding.ASCII.GetBytes(content), DocumentUploadMode.Overwrite ); var sketches = TasksService.GetSketchForFilter(new GetSketchForFilterRequest { Name = fname, Statuses = new[] { SketchStatusType.SentToSketch } }); SketchStatusType sketchStatus = sketches.Sketches.Count() > 0 ? SketchStatusType.SentToSketch : SketchStatusType.Saved; TasksService.SketchWorkflow(new SketchWorkflowRequest { Name = fname, ChangedBy = User.Identity.Name, Status = sketchStatus, XamlxOid = newOid.ToString() }); return(Json("WorkFlow Saved!")); } return(Json("Error")); }