protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { Response.Clear(); Response.AddHeader("Cache-Control", "no-cache"); Response.Expires = 0; Response.Cache.SetNoStore(); Response.AddHeader("Pragma", "no-cache"); ReadConfig(); if (Request.QueryString["source"] != null) { config.source = Request.QueryString["source"]; } else { config.source = (string)((JArray)config.config["sources"])[0]; } if (Request.QueryString["request"] == "list") { Response.Write(List()); } else if (Request.QueryString["request"] == "download") { Response.Write(Download()); DownloadTools.ClearTempFolder(config.GetConfigInt("tempFilesLifeTime", 20)); } else if (Request.QueryString["request"] == "config") { Response.Write(GetClientConfig()); } else if (Request.QueryString["request"] == "delete") { Response.Write(Delete()); } else if (Request.QueryString["request"] == "space") { Response.Write(GetFreeDiskSpace()); } else if (Request.QueryString["request"] == "backupSpace") { Response.Write(GetFreeDiskSpace("backupDrive")); } else if (Request.QueryString["request"] == "savedesc") { Response.Write(SaveDesc()); } else { return; } Response.End(); } }
protected string Download() { string fname = DownloadTools.Download(config, Request.QueryString["patient"], Request.QueryString["study"], Request.QueryString["radiant"] == "true"); if (fname.Length == 0) { return("{\"error\":\"failed\"}"); } return("{\"path\":\"" + DownloadTools.GetTempUrl() + fname + "\"}"); }
protected string Delete() { string res = "{\"error\":\"failed\"}"; if (!IsAdmin()) { return("{\"error\":\"permissions\"}"); } Log.WriteLog("Delete operation has been requested: " + (Request.QueryString["patient"] == "true" ? "patient " : "study ") + Request.QueryString["id"] + " " + Request.UserHostAddress); try { //check time List <JObject> studies = new List <JObject>(); if (Request.QueryString["patient"] == "true") { JObject jpatient = JObject.Parse(DownloadTools.GetJSON(config.GetConfigSourceOption("resthost"), "patients", Request.QueryString["id"])); JArray jstudies = (JArray)jpatient["Studies"]; foreach (string study in jstudies) { studies.Add(JObject.Parse(DownloadTools.GetJSON(config.GetConfigSourceOption("resthost"), "studies", study))); } } else { studies.Add(JObject.Parse(DownloadTools.GetJSON(config.GetConfigSourceOption("resthost"), "studies", Request.QueryString["id"]))); } CultureInfo provider = CultureInfo.InvariantCulture; foreach (JObject study in studies) { TimeSpan ts = DateTime.Now - DateTime.ParseExact((string)study["MainDicomTags"]["StudyDate"], "yyyyMMdd", provider); if (ts.TotalHours > config.GetConfigInt("deleteTime", 36)) { res = "{\"error\":\"expired\"}"; Log.WriteLog("Delete operation time has been expired: " + (Request.QueryString["patient"] == "true" ? "patient " : "study ") + Request.QueryString["id"]); return(res); } } Log.WriteLog("Delete operation has been started: " + (Request.QueryString["patient"] == "true" ? "patient " : "study ") + Request.QueryString["id"]); //delete HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(config.GetConfigSourceOption("resthost") + (Request.QueryString["patient"] == "true" ? "patients/" : "studies/") + Request.QueryString["id"]); request.Timeout = config.GetConfigInt("restTimeout", 300000); request.Method = "DELETE"; HttpWebResponse response = (HttpWebResponse)request.GetResponse(); if (response.StatusCode == HttpStatusCode.OK) { res = "{\"ok\":\"done\"}"; } Log.WriteLog("Delete operation has been completed: " + (Request.QueryString["patient"] == "true" ? "patient " : "study ") + Request.QueryString["id"]); } catch { Log.WriteLog("Failed to delete " + (Request.QueryString["patient"] == "true" ? "patient " : "study ") + Request.QueryString["id"]); } return(res); }