/// <summary> /// Called by workers when the job queue is empty. /// </summary> internal void ReportInactive() { if (Interlocked.Decrement(ref activeThreads) <= 0) { IWorkItemCollection next = null; lock (workQueue) { // Remove the old head, and check for a new one int n = workQueue.Count; if (n > 0) { workQueue.Dequeue(); } if (n > 1) { next = workQueue.Peek(); } } if (next != null) { AdvanceNext(next); } else { currentJob = null; if (lastStartTime != null) { // Measure the runtime LastRunTime = lastStartTime.ElapsedTicks; lastStartTime = null; } onComplete.Set(); } } }
public void Run(IWorkItemCollection work_items) { if (semaphore == null) { Initialize(); } if (runSingleThreaded || threads.Count == 0) { for (int i = 0; i < work_items.Count; i++) { work_items.InternalDoWorkItem(i); } } else { workerThreadCount = threads.Count; nextWorkIndex = -1; workItems = work_items; Thread.MemoryBarrier(); semaphore.Release(threads.Count); manualResetEvent.WaitOne(); manualResetEvent.Reset(); if (errorOccured) { foreach (WorkerThread thread in threads) { thread.PrintExceptions(); } } } }
internal AsyncPathWork(IWorkItemCollection gameJobs, ICPULoad budget) { Jobs = gameJobs ?? throw new ArgumentNullException(nameof(gameJobs)); this.budget = budget; runtime = 1L; time = new Stopwatch(); }
public AsyncJobManager() { int n = CPUBudget.coreCount; if (n < 1) { // Ensure at least one thread is created n = 1; } activeThreads = 0; currentJob = null; isDisposed = false; LastRunTime = 0L; lastStartTime = null; nextWorkIndex = -1; onComplete = new ManualResetEvent(false); semaphore = new Semaphore(0, n); threads = new WorkerThread[n]; // Should only be 2 tasks - dupes and critters workQueue = new Queue <IWorkItemCollection>(); for (int i = 0; i < n; i++) { threads[i] = new WorkerThread(this, "FastTrackWorker{0}".F(i)); } }
public void Query_UnitTest5() { IWorkItemStore instance = GetTestInstance(); const string wiql = "SELECT [System.Id], [System.WorkItemType], [System.Title], [System.AssignedTo], [System.State], [System.Tags] FROM WorkItems"; IWorkItemCollection actual = instance.Query(wiql); Assert.IsNotNull(actual); }
/// <summary> /// Advances to the next task in the queue. /// </summary> /// <param name="toStart">The job that will be started.</param> private void AdvanceNext(IWorkItemCollection toStart) { int n = threads.Length; nextWorkIndex = -1; activeThreads = n; currentJob = toStart; // Not sure if this matters, borrowed from Klei code Thread.MemoryBarrier(); semaphore.Release(n); }
public PerformanceBalancer(IThreadCollection threadCollection, IWorkItemCollection workItemCollection, PerformanceBalanceSettings settings) { settings.Check(); this.threadCollection = threadCollection; this.workItemCollection = workItemCollection; this.strategies = (settings.PerformanceBalancerStrategies ?? new List <IPerformanceBalancerStrategy>()).ToArray(); this.settings = settings; }
/// <summary> /// TFSs the vso API. /// </summary> /// <param name="tfs">The TFS.</param> private static void TfsVSOApi(ITfsTeamProjectCollection tfs) { tfs.EnsureAuthenticated(); bool first = true; var workitemstore = tfs.GetService <IWorkItemStore>(); //var linkTester = workitemstore.GetWorkItem(195); //var links = linkTester.Links; //var count = links.Count; //foreach (ILink link in links) //{ // Console.WriteLine("\t\t{0}\tComment: {1}", WriteSpecific(link), SafeWriteComment(link)); //} const string wiql = "SELECT * FROM WorkItems WHERE [System.TeamProject] = 'RestPlaypen' ORDER BY [System.Id] "; IWorkItemCollection wic = workitemstore.Query(wiql); foreach (IWorkItem wi in wic) { if (wi.Rev > 1) { Console.WriteLine("{0}:{1}\t{2}", wi.Id, wi.Rev, wi.Title); IRevisionCollection revisions = wi.Revisions; foreach (IRevision revision in revisions) { var value = (DateTime)revision.Fields["System.ChangedDate"].Value; Console.WriteLine("\t{0}\t{1}\t{2} {3}", revision.Index, revision.Fields.Count, value, value.Kind); bool dumpFields = false; if (dumpFields && first) { first = false; List <string> names = (from IField field in revision.Fields select field.ReferenceName).ToList(); names.Sort(); foreach (string name in names) { Console.WriteLine("\t\t{0}", name); } } } } if (wi.Links.Count > 0) { Console.WriteLine("{0}:{1}\t{2}", wi.Id, wi.Rev, wi.Title); Console.WriteLine("\t{0} Links", wi.Links.Count); foreach (ILink link in wi.Links) { Console.WriteLine("\t\t{0}\tComment: {1}", WriteSpecific(link), SafeWriteComment(link)); } } } }
public void ReadAllProperties_UnitTest() { CredentialsStore credentials = CredentialsProvider.Read(@"..\..\..\RestCredentials.xml"); var uri = new Uri(credentials.VsoCollection); var tpc = new TfsTeamProjectCollection(uri); tpc.EnsureAuthenticated(); var workItemStore = tpc.GetService <WorkItemStore>(); const string wiql = "SELECT [System.Id], [System.WorkItemType], [System.Title], [System.AssignedTo], [System.State], [System.Tags] FROM WorkItems"; WorkItemCollection real = workItemStore.Query(wiql); IWorkItemCollection instance = WorkItemCollectionWrapper.GetWrapper(real); ReadAllProperties(typeof(IWorkItemCollection), instance); }
/// <summary> /// Wiqls the query. /// </summary> /// <param name="wiql">The wiql.</param> /// <param name="fullyPopulate">if set to <c>true</c> [fully populate].</param> /// <returns>Task<IReadOnlyList<IWorkItem>>.</returns> public Task <IReadOnlyList <IWorkItem> > WiqlQuery(string wiql, bool fullyPopulate) { return(AsyncOperation(() => { IWorkItemStore workItemStore = WorkItemStore(); IWorkItemCollection witCollection = workItemStore.Query(wiql); var result = new List <IWorkItem>(); foreach (IWorkItem item in witCollection) { result.Add(item); } return (IReadOnlyList <IWorkItem>)result; })); }
/// <summary> /// Starts a new job. /// </summary> /// <param name="workItems">The job to start.</param> private void StartJob(IWorkItemCollection workItems) { var jobManager = AsyncJobManager.Instance; if (jobManager != null) { if (Interlocked.Increment(ref jobCount) <= 1) { onPathDone.Reset(); } jobManager.Run(new AsyncPathWork(workItems, budget)); running = true; } }
public void Dispose() { if (!isDisposed) { currentJob = null; isDisposed = true; lastStartTime = null; semaphore.Release(threads.Length); // Clear work queue lock (workQueue) { workQueue.Clear(); } onComplete.Set(); } }
public void Scan_WorkItems_UnitTest() { ITfsTeamProjectCollection tfs = new TfsTeamProjectCollectionImpl(new Uri(VSOClientManager.VsoCollection)); tfs.EnsureAuthenticated(); var workitemstore = tfs.GetService <IWorkItemStore>(); const string wiql = "SELECT * FROM WorkItems WHERE [System.TeamProject] = 'RestPlaypen' ORDER BY [System.Id] "; IWorkItemCollection wic = workitemstore.Query(wiql); bool first = true; foreach (IWorkItem wi in wic) { if (wi.Rev > 1) { //Console.WriteLine("{0}:{1}\t{2}", wi.Id, wi.Rev, wi.Title); IRevisionCollection revisions = wi.Revisions; foreach (IRevision revision in revisions) { var value = (DateTime)revision.Fields["System.ChangedDate"].Value; //Console.WriteLine("\t{0}\t{1}\t{2} {3}", revision.Index, revision.Fields.Count, value, value.Kind); bool dumpFields = true; if (dumpFields && first) { first = false; List <string> names = (from IField field in revision.Fields select field.ReferenceName).ToList(); names.Sort(); foreach (string name in names) { //Console.WriteLine("\t\t{0}", name); } } } } if (wi.Links.Count > 0) { //Console.WriteLine("{0}:{1}\t{2}", wi.Id, wi.Rev, wi.Title); //Console.WriteLine("\t{0} Links", wi.Links.Count); foreach (ILink link in wi.Links) { //Console.WriteLine("\t\t{0}\tComment: {1}", WriteSpecific(link), SafeWriteComment(link)); } } } }
/// <summary> /// Starts executing the list of work items in the background. Returns immediately /// after execution begins; use Wait to monitor the status. /// </summary> /// <param name="workItems">The work items to run in parallel.</param> public void Start(IWorkItemCollection workItems) { int n = threads.Length; bool starting = false; if (isDisposed) { throw new ObjectDisposedException(nameof(AsyncJobManager)); } lock (workQueue) { starting = workQueue.Count == 0; workQueue.Enqueue(workItems); } if (starting) { lastStartTime = Stopwatch.StartNew(); AdvanceNext(workItems); } }
partial void GetId_PostValidate(IWorkItemCollection instance, Int32 index);
partial void DisplayFields_SetCondition(ref IWorkItemCollection instance, ref IDisplayFieldList setValue);
partial void DefaultProjectHint_SetCondition(ref IWorkItemCollection instance, ref Int32 setValue);
public static void Run(IWorkItemCollection work_items) { jobManager.Run(work_items); }
partial void SortFields_SetCondition(ref IWorkItemCollection instance, ref ISortFieldList setValue);
partial void Resort_PostValidate(IWorkItemCollection instance);
partial void GetId_PreCondition(IWorkItemCollection instance, ref Int32 index);
public void IndexOf_UnitTest1() { IWorkItemCollection instance = GetTestInstance(); int actual = instance.IndexOf(1); }
internal static IWorkItemCollection GetTestWorkItemCollection() { IWorkItemCollection instance = null; return(instance); }
/// <summary> /// Runs the work items but does not wait for them to finish. /// </summary> /// <param name="workItems">The work items to run.</param> public static void RunAsync(IWorkItemCollection workItems) { Instance?.StartJob(workItems); }
partial void PageSize_SetCondition(ref IWorkItemCollection instance, ref Int32 setValue);
partial void Collection_SetCondition(ref IWorkItem instance, ref IWorkItemCollection setValue);
partial void Resort_PreCondition(IWorkItemCollection instance);
public void GetId_UnitTest() { IWorkItemCollection instance = GetTestInstance(); int actual = instance.GetId(0); }
public void GetEnumerator_UnitTest() { IWorkItemCollection instance = GetTestInstance(); IEnumerator actual = instance.GetEnumerator(); }
/// <summary> /// Starts a new job. /// </summary> /// <param name="workItems">The job to start.</param> private void StartJob(IWorkItemCollection workItems) { jobManager?.Start(workItems); }