public ManagedThread CreateSystemThread(ManagedJob job, bool signal, bool wait) { lock (syncLock) { ManagedThread managedThread = new ManagedThread(job, ThreadType.System, signal, wait); threadDictionary.Add(job.Name, managedThread); return(managedThread); } }
public void SchaduleTask(ITask task) { var gc = GCHandle.Alloc(task); var job = new ManagedJob { handle = gc }.Schedule(); gcHandles.Add(gc); jobHandles.Add(job); }
internal ManagedThread(ManagedJob job, ThreadType type, bool signal, bool wait) { _job = job; _name = job.Name; _args = job.GetArguments(); if (wait) { _waitFlag = new AutoResetEvent(signal); _wait = true; } CurrentState = JobState.Stopped; _thread = new Thread(new ThreadStart(Run)); _type = type; }
public static List <ManagedJob> CreateJobs() { List <ManagedJob> jobCollection = new List <ManagedJob>(); List <JobElement> jobList = ConfigurationHelper.GetEnabledJobs(); foreach (JobElement job in jobList) { // Look for implementation for the Job Type jobImplClass = LoadImplementationClass(ConfigurationHelper.GetJobType(job)); if (jobImplClass != null) { JobArgumentCollection jac = ConfigurationHelper.GetJobArgumentCollection(job); List <object> arguments = new List <object>(); arguments.Add(job.Name); arguments.Add(job.WaitForEvent); arguments.Add(jac); // Create an instance of the job ManagedJob managedJob = Activator.CreateInstance(jobImplClass, arguments.ToArray()) as ManagedJob; ISpawn spawn = managedJob as ISpawn; if (spawn != null) { ManagedJob[] spawnedJobs = spawn.SpawnJobs(); foreach (ManagedJob j in spawnedJobs) { job.Log.FileName = Path.Combine(Path.GetDirectoryName(job.Log.FileName), j.Name) + Path.GetExtension(job.Log.FileName); InitializeTracing(j, job.Log); jobCollection.Add(j); } } else { InitializeTracing(managedJob, job.Log); jobCollection.Add(managedJob); } } } return(jobCollection); }
private static void InitializeTracing(ManagedJob job, LogElement logElement) { if (logElement == null) { logElement = new LogElement(); logElement.FileName = job.Name + ".log"; logElement.LogLevel = InstanceConfig.CurrentInstance.Log.LogLevel; logElement.MaxLogSize = InstanceConfig.CurrentInstance.Log.MaxLogSize; } // Check if path includes a directory part of some sort if (!logElement.FileName.Contains(Path.DirectorySeparatorChar.ToString())) { // Append server directory logElement.FileName = Path.Combine(Path.GetDirectoryName(InstanceConfig.CurrentInstance.Log.FileName), logElement.FileName); } job.Tracing.Switch.Level = ConfigurationHelper.ConvertLogLevel(logElement.LogLevel); RollingFileTraceListener listener = new RollingFileTraceListener(logElement.FileName, logElement.MaxLogSize); //listener.TraceOutputOptions = TraceOptions.DateTime |TraceOptions.ThreadId; // todo fixme job.Tracing.Listeners.Add(listener); }