Beispiel #1
0
        public static Hashtable Load(string path)
        {
            Hashtable ht = new Hashtable();

            try
            {
                string[] files = Directory.GetFiles(path + dir);
                foreach (string file in files)
                {
                    lock (locker)
                    {
                        try
                        {
                            string fname  = Path.GetFileName(file);
                            IDDesc iddesc = new IDDesc();
                            //iddesc.id = Encoding.ASCII.GetString(Convert.FromBase64String(fname));
                            iddesc.id   = fname;
                            iddesc.desc = File.ReadAllText(path + dir + "\\" + fname);
                            ht.Add(iddesc.id, iddesc.desc);
                        }
                        catch
                        {
                        }
                    }
                }
            }
            catch
            {
                Log.WriteLog("Failed to load id descriptions");
            }
            return(ht);
        }
Beispiel #2
0
        protected string SaveDesc()
        {
            string res = "{\"error\":\"failed\"}";

            if (!IsAdmin())
            {
                return("{\"error\":\"permissions\"}");
            }

            IDDesc iddesc = new IDDesc();

            iddesc.id   = Request.QueryString["id"];
            iddesc.desc = Request.QueryString["desc"];
            if (iddesc.Save(config.GetConfigSourceOption("dataDrive") + "\\"))
            {
                res = "{\"ok\":\"done\"}";
            }

            return(res);
        }
Beispiel #3
0
        protected string StudiesList(string host)
        {
            int simultaneousNum = config.GetConfigInt("simultaneousThreads", 10);
            int period          = 0;

            try
            {
                period = int.Parse(Request.QueryString["period"]);
            }
            catch
            {
            }

            string[] studyIDs = new string[0];
            try
            {
                studyIDs = JArray.Parse(Study.GetStudiesIDs(host, period)).ToObject <string[]>();
            }
            catch
            {
                Log.WriteLog("Failed to get studies' IDs");
            }

            Semaphore semaphore = new Semaphore(simultaneousNum, simultaneousNum);

            List <Study>  list    = new List <Study>(studyIDs.Length);
            List <Thread> threads = new List <Thread>(studyIDs.Length);

            foreach (string item in studyIDs)
            {
                try
                {
                    AsyncData ad = new AsyncData();
                    ad.semaphore = semaphore;
                    ad.url       = host + "studies/" + item;
                    ad.studies   = list;
                    ad.index     = -1;

                    Thread thread = new Thread(Study.DataThread);
                    threads.Add(thread);
                    thread.Start(ad);
                }
                catch (Exception e)
                {
                    Log.WriteLog("Failed to get study " + item + ": " + e.Message);
                }
            }

            bool allDone = false;

            while (!allDone)
            {
                bool join = true;
                foreach (Thread thread in threads)
                {
                    join = thread.Join(30);
                    if (!join)
                    {
                        break;
                    }
                }
                allDone = join;
            }
            threads.Clear();

            semaphore = new Semaphore(simultaneousNum, simultaneousNum);

            threads = new List <Thread>(studyIDs.Length);
            for (int i = 0; i < list.Count; i++)
            {
                string parent = "";
                try
                {
                    AsyncData ad = new AsyncData();
                    ad.semaphore = semaphore;
                    parent       = (string)JObject.Parse(list[i].study)["ParentPatient"];
                    ad.url       = host + "patients/" + parent;
                    ad.studies   = list;
                    ad.index     = i;

                    Thread thread = new Thread(Study.DataThread);
                    threads.Add(thread);
                    thread.Start(ad);
                }
                catch (Exception e)
                {
                    Log.WriteLog("Failed to get study's parent patient " + parent + ": " + e.Message);
                }
            }

            allDone = false;
            while (!allDone)
            {
                bool join = true;
                foreach (Thread thread in threads)
                {
                    join = thread.Join(30);
                    if (!join)
                    {
                        break;
                    }
                }
                allDone = join;
            }

            //append description
            Hashtable ht = IDDesc.Load(config.GetConfigSourceOption("dataDrive") + "\\");

            try
            {
                for (int i = 0; i < list.Count; i++)
                {
                    try
                    {
                        JObject jpatient = JObject.Parse(list[i].patient);
                        //string id = (string)jpatient["MainDicomTags"]["PatientID"];
                        string id = (string)jpatient["ID"];
                        if (ht.ContainsKey(id))
                        {
                            string escid = JsonConvert.ToString(ht[id]);
                            list[i].patient = list[i].patient.Insert(list[i].patient.LastIndexOf('}'), ",\"iddesc\":" + escid);
                        }
                    }
                    catch
                    {
                    }
                }
            }
            catch
            {
            }

            StringBuilder json = new StringBuilder();

            json.Append("[");
            if (list.Count > 0)
            {
                json.Append(list[0].GetJSON());
            }
            for (int i = 1; i < list.Count; i++)
            {
                json.Append("," + list[i].GetJSON());
            }
            json.Append("]");

            return(json.ToString());
        }