Exemple #1
0
        public static void FileThread(object obj)
        {
            AsyncData adata = obj as AsyncData;

            adata.semaphore.WaitOne();

            try
            {
                SaveFile(adata.url, adata.path + string.Format("{0:D4}.dcm", adata.index));
            }
            catch (Exception e)
            {
                Log.WriteLog(e.Message);
            }

            adata.semaphore.Release();
        }
Exemple #2
0
        public static void DataThread(object obj)
        {
            AsyncData adata = obj as AsyncData;

            adata.semaphore.WaitOne();

            try
            {
                adata.arr[adata.index] = GetObject(adata.url + "/" + (string)adata.arr[adata.index]);
            }
            catch (Exception e)
            {
                Log.WriteLog(e.Message);
            }

            adata.semaphore.Release();
        }
Exemple #3
0
        public static JArray GetObjectsArr(JArray arrIDs, string url, Config config)
        {
            int           simultaneousNum = config.GetConfigInt("simultaneousThreads", 10);
            Semaphore     semaphore       = new Semaphore(simultaneousNum, simultaneousNum);
            List <Thread> threads         = new List <Thread>(arrIDs.Count);

            for (int i = 0; i < arrIDs.Count; i++)
            {
                try
                {
                    AsyncData ad = new AsyncData();
                    ad.semaphore = semaphore;
                    ad.url       = url;
                    ad.arr       = arrIDs;
                    ad.index     = i;

                    Thread thread = new Thread(DataThread);
                    threads.Add(thread);
                    thread.Start(ad);
                }
                catch (Exception e)
                {
                    Log.WriteLog("Failed to get data: " + 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();

            return(arrIDs);
        }
Exemple #4
0
        public static void SaveInstances(JArray instances, string path, Config config)
        {
            string        host            = config.GetConfigString("resthost", "http://127.0.0.1:8042/");
            int           simultaneousNum = config.GetConfigInt("simultaneousThreads", 10);
            Semaphore     semaphore       = new Semaphore(simultaneousNum, simultaneousNum);
            List <Thread> threads         = new List <Thread>(instances.Count);

            foreach (JObject instance in instances)
            {
                try
                {
                    AsyncData ad = new AsyncData();
                    ad.semaphore = semaphore;
                    ad.url       = host + "instances/" + instance["ID"] + "/file";
                    ad.path      = path;
                    ad.index     = (int)instance["IndexInSeries"];

                    Thread thread = new Thread(FileThread);
                    threads.Add(thread);
                    thread.Start(ad);
                }
                catch (Exception e)
                {
                    Log.WriteLog("Failed to get instance data: " + 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();
        }