public async Task <JsonResult <object> > putSnapshot(int projectId, int pkTime) { try { HttpContent requestContent = Request.Content; Stream stream = await requestContent.ReadAsStreamAsync(); StreamReader streamReader = new StreamReader(stream); object data = new object(); //List<ResponseValue> values = new List<ResponseValue>(); BinaryFormatter binFormatter = new BinaryFormatter(); string sStream = streamReader.ReadToEnd(); if (sStream != "[]" || sStream != null || sStream != "") { data = sStream + " has been received"; List <RequestValue> list = new List <RequestValue>(); stream.Position = 0; data = binFormatter.Deserialize(stream); if (data is List <RequestValue> ) { list = (List <RequestValue>)data;//binFormatter.Deserialize(stream); } else { data = "TypeMismatch via loading from request stream-Verfy structure-" + DateTime.Now.ToString(); Error.toFile("TypeMismatch via loading from request stream - Verfy structure", "ApiSchemesPutSnaschot"); } if (list.Count != 0) { NewSchemesHandler schemesHandler = new NewSchemesHandler(); object returnedObject = schemesHandler.putSnapshotDataIntoFile(list, projectId, pkTime); Error.toFile("We have successfully saved snapshot into file.", "ApiDiagnosticLog"); schemesHandler.SaveSnapshot(list, projectId, pkTime); return(Json(returnedObject)); } } else { data = "Error: Zero data sent stop sending no data requests"; return(Json(data)); } data = true; return(Json(data)); } catch (Exception e) { object data = new object(); data = e; Error.toFile(e.Message + e.InnerException + e.StackTrace, "ApiSchemesPutSnaschot"); return(Json(data)); } }
// GET: SvgScheme /// <summary> /// Action to view new schemes /// </summary> /// <returns>View with path to svg in </returns> public ActionResult Index() { string pathToSvg = null, pathToCfg = null; List <SvgElement> elements = new List <SvgElement>(); NewSchemesHandler schemesHandler = new NewSchemesHandler(); //first get all needed session data getConfigPath(ref pathToSvg, ref pathToCfg); //read xml config SvgConfig svgConfig = schemesHandler.readSchemeConfig(pathToCfg); //get all values for svg scheme List <ResponseValue> responses = schemesHandler.readData(svgConfig, svgConfig.BindingTags, (int)Session["id"]); //set values from responses SvgDocument svg = schemesHandler.setValue(responses, svgConfig, pathToSvg); /* * if (svgConfig != null) * //read all dynamic members * elements = schemesHandler.readScheme(pathToSvg, svgConfig); */ if (!pathToSvg.Contains(PathDef.PhysicalPath)) { pathToSvg = PathDef.PhysicalPath + pathToSvg; } string pathToNewSvg = pathToSvg + "_scheme_" + DateTime.Now.Ticks + ".png"; //System.IO.File.Create(pathToNewSvg); /*svg.Write(pathToNewSvg); * * SvgDocument newSvg = SvgDocument.Open(pathToNewSvg); */ //var bitmap = svg.Draw(); //bitmap.Save(pathToNewSvg, ImageFormat.Png); ViewBag.SvgXml = svg.GetXML(); return(View()); }
public async Task <JsonResult <object> > getSchemeSnapshot([FromBody] Stream stream, [FromUri] int projectId, string schmeName) { StreamReader streamReader = new StreamReader(stream); object data = new object(); List <ResponseValue> values = new List <ResponseValue>(); string json = streamReader.ReadToEnd(); if (json != "[]" || json != null || json != "") { List <SchemeValue> list = new JavaScriptSerializer().Deserialize <List <SchemeValue> >(json); if (list.Count != 0) { NewSchemesHandler schemesHandler = new NewSchemesHandler(); //data = await schemesHandler.putSnapshotDataIntoFile(values, list, projectId); } return(Json(data)); } else { return(Json(data)); } }
// GET: SchemeEditor public ActionResult Index() { List <string> valuesforView = new List <string>(); List <string> pathesToCfg = new List <string>(); string pathSvgCfg = null; string dynValuesCfg = null; string ageBarsCfgPath = null; string pathToSvg = null; string bindingTagsCfg = null; string absPathToSvg = null; List <string> subGraphicDir = new List <string>(); List <string> pathGraphicCfg = new List <string>(); List <AgeBar> ageBarList = new List <AgeBar>(); List <DynValue> values = new List <DynValue>(); List <Textlist> textLists = new List <Textlist>(); List <Graphiclist> graphicLists = new List <Graphiclist>(); List <SchemeValue> bindingTagList = new List <SchemeValue>(); getConfigPathes(pathesToCfg, ref pathSvgCfg, ref dynValuesCfg, ref bindingTagsCfg, ref ageBarsCfgPath, ref pathToSvg, subGraphicDir, pathGraphicCfg); SchemeEditor model = new SchemeEditor(); if (dynValuesCfg != null || ageBarsCfgPath != null || pathGraphicCfg != null) { System.IO.File.Delete(pathSvgCfg); if (dynValuesCfg != null) { SchemeEditorHandler.getDynValues(pathSvgCfg, dynValuesCfg, values); model.SchemeTags = values; } if (bindingTagsCfg != null) { SchemeEditorHandler.getBindingTags(pathSvgCfg, bindingTagsCfg, bindingTagList); model.BindingTags = bindingTagList; } // Important ageBar age is not included in agegBar config if (ageBarsCfgPath != null) { SchemeEditorHandler.getAgeBar(pathSvgCfg, ageBarsCfgPath, ageBarList); model.SchemeAgeBars = ageBarList; } else { Session["tempforview"] += "Config files pathes are not present in bakery config"; } if (pathGraphicCfg != null && subGraphicDir != null && pathGraphicCfg != null) { SchemeEditorHandler.getGraphicLists(pathSvgCfg, subGraphicDir, pathGraphicCfg, graphicLists); model.SchemeGraphicsList = graphicLists; } else { Session["tempforview"] += "Config files pathes are not present in bakery config"; } if (pathSvgCfg != null && pathesToCfg != null) { SchemeEditorHandler.getTextlists(pathesToCfg, pathSvgCfg, textLists); model.SchemeTextlist = textLists; } else { Session["tempforview"] += "Config files pathes are not present in bakery config"; } if (pathToSvg != null) { //pathToSvg = pathToSvg.Replace(@"\", @"/"); if (pathToSvg.IndexOf(@"\") == 0) { pathToSvg = pathToSvg.Substring(1); } //write whole SchemeEditor model to xml SchemeEditorHandler.writeToXML(pathSvgCfg, model); if (System.IO.File.Exists(pathSvgCfg)) { NewSchemesHandler newSchemesHandler = new NewSchemesHandler(); newSchemesHandler.readSchemeConfig(pathSvgCfg); } if (pathToSvg.Contains(PathDef.PhysicalPath)) { absPathToSvg = pathToSvg; } else { absPathToSvg = PathDef.PhysicalPath + pathToSvg; } string readText = System.IO.File.ReadAllText(absPathToSvg); svg = SvgDocument.Open(absPathToSvg); model.relativePath = pathToSvg; model.SvgFile = svg; string SvgXml = System.IO.File.ReadAllText(absPathToSvg); string ConfigXml = System.IO.File.ReadAllText(pathSvgCfg); string sXmlDef = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"; ConfigXml = ConfigXml.Replace(sXmlDef, ""); SvgDocument newSvg = new SvgDocument();/* * int indexFirst = (SvgXml.IndexOf("<config") - 5); * int indexSecond = (SvgXml.IndexOf("</defs>") + 7); * string firstSvgPart = SvgXml.Substring(0, indexFirst); * string secondSvgPart = SvgXml.Substring(indexSecond); * string svgFileContent = firstSvgPart + "<config>" + ConfigXml + "</config>" + secondSvgPart;*/ System.IO.File.Move(absPathToSvg, absPathToSvg + "_old_" + DateTime.Now.Ticks + ".svg"); string svgFileContent = SvgXml.Replace("</defs>", ConfigXml + "</defs>"); System.IO.File.WriteAllText(PathDef.PhysicalPath + pathToSvg, svgFileContent); } else { //write whole SchemeEditor model to xml SchemeEditorHandler.writeToXML(pathSvgCfg, model); Session["tempforview"] = "Problem with finding this svg"; return(RedirectToAction("Index", "Menu")); } return(View(model)); } else { return(View("form", model)); } }