예제 #1
0
        [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"));
        }
예제 #2
0
        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));
            }
        }
예제 #3
0
        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);
            }
        }