Beispiel #1
0
 public static void addTask(String id, String name, String exec, String data, String workingDir )
 {
     TaskEntry job = new TaskEntry();
     job.id = id;
     job.name = name;
     job.master = Settings.myID;
     job.workDir = workingDir;
     String[] names = exec.Split('\\');
     //System.Diagnostics.Debug.WriteLine(workingDir+names[names.Length - 1]);
     if (!File.Exists(workingDir+names[names.Length - 1]))
         File.Copy(exec, workingDir+names[names.Length - 1]);
     job.exec = names[names.Length - 1];
     foreach (String file in Directory.GetFiles(data))
     {
         String[] files = file.Split('\\');
         //System.Diagnostics.Debug.WriteLine(workingDir + "data\\" + files[files.Length - 1]);
         if (!File.Exists(workingDir + "data\\" + files[files.Length - 1]))
             File.Copy(file, workingDir + "data\\" + files[files.Length - 1]);
         job.data.Add("data\\" + files[files.Length - 1]);
     }
     if(job.master == Settings.myID)
     {
         string[] IDs =new  string[1]{Settings.myID};
         Route r = new Route(0, IDs);
         job.routes.Add(r);
     }
     DataBase.jobs.Add(job);
     DataBase.setTasksChanged();
     if(!queue.Contains(id))
         Subscribe(id);
     if(!Directory.Exists(Settings.workingDirectory + id + "\\data"))
         Directory.CreateDirectory(Settings.workingDirectory + id + "\\data");
     if(!Directory.Exists(Settings.workingDirectory + id + "\\result"))
         Directory.CreateDirectory(Settings.workingDirectory + id + "\\result");
 }
Beispiel #2
0
 public static void addTask(String id, String name )
 {
     TaskEntry job = new TaskEntry();
     job.id = id;
     job.master = Settings.myID;
     job.name = name;
     job.workDir = Settings.workingDirectory + id + "\\";
     if (File.Exists(job.workDir+"task.exe"))
         job.exec = "task.exe";
     lock(DataBase.dataTrans)
     {
     foreach (String file in Directory.GetFiles(job.workDir + "data\\"))
     {
         String[] files = file.Split('\\');
         if (File.Exists(job.workDir + "data\\" + files[files.Length - 1]))
         {
             job.data.Add("data\\" + files[files.Length - 1]);
             DataBase.dataTrans.Add("data\\" + files[files.Length - 1], Settings.myID);
         }
     }
     }
     if(job.master == Settings.myID)
     {
         string[] IDs =new  string[1]{Settings.myID};
         Route r = new Route(0, IDs);
         job.routes.Add(r);
     }
     DataBase.jobs.Add(job);
     DataBase.setTasksChanged();
     if(!queue.Contains(id))
         Subscribe(id);
     if(!Directory.Exists(Settings.workingDirectory + id + "\\data"))
         Directory.CreateDirectory(Settings.workingDirectory + id + "\\data");
     if(!Directory.Exists(Settings.workingDirectory + id + "\\result"))
         Directory.CreateDirectory(Settings.workingDirectory + id + "\\result");
 }
Beispiel #3
0
        public static void RetainPool( TaskEntry job )
        {
            Random r_num = new Random();
            List<string> localData = new List<string>();
            string[] ress;
            string result;
            int index;
            lock(DataBase.dataTrans)
            {
                foreach(KeyValuePair<string, string> KV in DataBase.dataTrans)
                {
                    //System.Diagnostics.Debug.WriteLine("read {0} = {1}", KV.Key, KV.Value);
             		ress = KV.Key.Split('\\');
                    result = "result\\" + ress[ress.Length - 1];
                    if(KV.Value == Settings.myID && !job.result.Contains(result))
                        localData.Add(KV.Key);
                }

                poolVol = (10 < localData.Count()) ? 10 : localData.Count();

                while(pool.Count() != poolVol)
                {
                    index = r_num.Next(0,localData.Count());
                    pool.Add(localData[index]);
                    localData.RemoveAt(index);
                }
            }
        }