private string LastJobber(string hostname) { Jobber Ajob = new Jobber(); var LocalList = new Dictionary <string, Jobber>(); try { JobListLock.TryEnterReadLock(10000); LocalList = _Joblist; JobListLock.ExitReadLock(); } catch { if (JobListLock.IsReadLockHeld) { JobListLock.ExitReadLock(); } } foreach (KeyValuePair <string, Jobber> OneJob in LocalList) { if (OneJob.Value.Target.Equals(hostname)) { Ajob = OneJob.Value; } } return(Ajob.ThisTaskGuid); }
/// <summary> /// Submits a job back to the Console when it has been updated, either status update or completion. /// </summary> /// <param name="Job4Update"></param> /// <returns></returns> public bool UpdateJob(Jobber Job4Update) { try { JobListLock.EnterWriteLock(); _Joblist[Job4Update.ThisTaskGuid] = Job4Update; JobListLock.ExitWriteLock(); return(true); } catch { if (JobListLock.IsWriteLockHeld) { JobListLock.ExitWriteLock(); } return(false); } }
public Jobber GetJobByGUID(string jGUID) { Jobber job = new Jobber(); try { JobListLock.TryEnterReadLock(10000); job = _Joblist[jGUID]; JobListLock.ExitReadLock(); } catch { if (JobListLock.IsReadLockHeld) { JobListLock.ExitReadLock(); } } return(job); }
/// <summary> /// Used by the Console to submit new jobs to the service. /// </summary> /// <param name="SubmittedJob">Submit a fully filled out task request to the service</param> /// <returns>True if the Job was added to the queue</returns> public bool SubmitJob(Jobber SubmittedJob) { try { //Shorten them blasted FQDNs, unless they are IP addresses string hostname = ""; if (SDC.IsIPAddressValid(SubmittedJob.Target)) { hostname = SubmittedJob.Target; } else { char[] delimiter1 = new char[] { '.' }; // <-- Split on these string[] whackity = SubmittedJob.Target.Split(delimiter1); hostname = whackity[0].ToLower(); } SubmittedJob.Target = hostname; SubmittedJob.timerecieved = DateTime.Now; SubmittedJob.status = "Queued"; SubmittedJob.ThisTaskGuid = Guid.NewGuid().ToString(); //Here is where we need to implement file copy operations. if (!SubmittedJob.ResourceDir.Equals("")) { SubmittedJob.tasksummary = "Copying required directory " + SubmittedJob.ResourceDir; string username = ""; string password = ""; string domain = _ServersInScope[hostname]; if (_Credlist.Keys.Contains(domain))//Get the username and password for specific domain, otherwise use the default. { username = _Credlist[domain].user; password = _Credlist[domain].password; } else { username = _Credlist["default"].user; password = _Credlist["default"].password; } string sourcedir = SubmittedJob.ResourceDir; //Figure out the file mappings for UNC paths... string targetdir = @"C:\Temp\" + username + @"\AgentFiles\" + SubmittedJob.ResourceDir; string rUNC = @"\\" + hostname.ToString() + @"\" + targetdir.ToString(); //puts in UNC format, but has a : instead of a $ rUNC = rUNC.Replace(":", @"$"); //replaces : with $ for a legal UNC path try { SDC.UpdateDirectory(SubmittedJob.ResourceDir, rUNC, username, domain, password); SubmittedJob.tasksummary = "Directory Copied: " + SubmittedJob.ResourceDir; } catch { SubmittedJob.status = "Copy Failed!" + SubmittedJob.ResourceDir; SubmittedJob.TaskStatusColor = "Red"; } } JobListLock.EnterWriteLock(); _Joblist.Add(SubmittedJob.ThisTaskGuid, SubmittedJob); JobListLock.ExitWriteLock(); return(true); } catch { if (JobListLock.IsWriteLockHeld) { JobListLock.ExitWriteLock(); } return(false); } }
/// <summary> /// GetJob is the function called by the Agent to see iffen she has work for to do. /// </summary> /// <param name="clientnameaslower">Client name, shortname or FQDN</param> /// <returns></returns> public Jobber GetJob(string clientname, string clientip) { string clientnameaslower = clientname.ToLower(); string shortname = ""; string[] whackity; char[] delimiter1 = new char[] { '.' }; // <-- String Split on . //Try to fix issue with IP address based servers. first update & fix servers in scope. try { ServersInScopeLock.TryEnterWriteLock(3000); if (_ServersInScope.Keys.Contains(clientip)) { _ServersInScope.Add(clientnameaslower, _ServersInScope[clientip]); _ServersInScope.Remove(clientip); ServersInScopeLock.ExitWriteLock(); //Next, update the DataGridSource try { DatagridLock.TryEnterWriteLock(3000); _DatagridSource.Add(clientnameaslower, _DatagridSource[clientip]); _DatagridSource[clientnameaslower].servername = clientnameaslower; _DatagridSource.Remove(clientip); if (DatagridLock.IsWriteLockHeld) { DatagridLock.ExitWriteLock(); } } catch { if (DatagridLock.IsWriteLockHeld) { DatagridLock.ExitWriteLock(); } } } if (DatagridLock.IsWriteLockHeld) { DatagridLock.ExitWriteLock(); } if (ServersInScopeLock.IsWriteLockHeld) { ServersInScopeLock.ExitWriteLock(); } } catch { if (ServersInScopeLock.IsWriteLockHeld) { ServersInScopeLock.ExitWriteLock(); } if (DatagridLock.IsWriteLockHeld) { DatagridLock.ExitWriteLock(); } } if (SDC.IsIPAddressValid(clientnameaslower)) { shortname = clientnameaslower; } else { whackity = clientnameaslower.Split(delimiter1); shortname = whackity[0].ToLower(); } clientnameaslower = shortname; ConnectedClientLock.TryEnterWriteLock(5000); try { if (_ConnectedClients.Keys.Contains(clientnameaslower.ToString())) { _ConnectedClients[clientnameaslower.ToString()] = DateTime.Now; } else { _ConnectedClients.Add(clientnameaslower, DateTime.Now); } } catch { } ConnectedClientLock.ExitWriteLock(); Jobber Job4U = new Jobber(); ////// Warning!!!! JobListLock.TryEnterWriteLock(10000); try { foreach (Jobber Ajob in _Joblist.Values) { whackity = Ajob.Target.Split(delimiter1); string jobtarget = whackity[0].ToLower(); if (shortname.Equals(jobtarget) && Ajob.status.Equals("Queued")) { Ajob.status = "Sending"; //JobListLock.ExitWriteLock(); return(Ajob); } } if (JobListLock.IsWriteLockHeld) { JobListLock.ExitWriteLock(); } } finally { if (JobListLock.IsWriteLockHeld) { JobListLock.ExitWriteLock(); } } Job4U.Taskname = "No jobs for joo!"; bool needstobewhacked = true; //Send Terminate job to client if he aint in the current Active Server List. if (!_ServersInScope.Keys.Contains(clientname) && !_ServersInScope.Keys.Contains(clientip) && !_ServersInScope.Keys.Contains(clientname.ToLower())) { foreach (string serveronlist in _ServersInScope.Keys) { string isit = serveronlist.Split('.')[0].ToLower(); if (serveronlist.Split('.')[0].ToLower().Contains(clientname.ToLower())) { needstobewhacked = false; } } if (needstobewhacked) { Job4U.Taskname = "Terminate"; } } return(Job4U); }