Ejemplo n.º 1
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");
 }
Ejemplo n.º 2
0
        public static void MergeRoutes(string inRoutes, string inCon)
        {
            string[] routes = inRoutes.Split('|');
            int metric = 0;
            for(int i = 0; i < routes.Length/2; i += 2)
            {
                try
                {
                    metric = Int32.Parse(routes[i]) + 1;
                }
                catch (Exception e)
                {
                    System.Diagnostics.Debug.WriteLine(e.ToString());
                }
                if(metric == 0)
                    continue;
                TaskEntry job = DataBase.jobs.Find(
                    delegate(TaskEntry peer)
                    {
                        return peer.id == routes[i + 1];
                    }
                );

                foreach(Route KV in job.routes)
                {
                    if(KV.cons.Contains(inCon))
                    {
                        KV.cons.Remove(inCon);
                    }
                }

                Route res = job.routes.Find(
                    delegate(Route peer)
                    {
                        return peer.metric == metric;
                    }
                );
                if (res == null)
                {
                    string[] inIDs = new string[1]{inCon};
                    Route r = new Route(metric, inIDs);
                    job.routes.Add(r);
                    setRoutesChanged();
                }
                else
                {
                    res.cons.Add(inCon);
                }

            }
        }
Ejemplo n.º 3
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");
 }