コード例 #1
0
 /// <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();
         }
     }
 }
コード例 #2
0
 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();
             }
         }
     }
 }
コード例 #3
0
 internal AsyncPathWork(IWorkItemCollection gameJobs, ICPULoad budget)
 {
     Jobs        = gameJobs ?? throw new ArgumentNullException(nameof(gameJobs));
     this.budget = budget;
     runtime     = 1L;
     time        = new Stopwatch();
 }
コード例 #4
0
        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));
            }
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        /// <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);
        }
コード例 #7
0
        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;
        }
コード例 #8
0
ファイル: Program.cs プロジェクト: DynConcepts/TfsVsoApi
        /// <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));
                    }
                }
            }
        }
コード例 #9
0
        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);
        }
コード例 #10
0
ファイル: WorkItemAPI.cs プロジェクト: DynConcepts/TfsVsoApi
 /// <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&lt;IReadOnlyList&lt;IWorkItem&gt;&gt;.</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;
     }));
 }
コード例 #11
0
        /// <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;
            }
        }
コード例 #12
0
 public void Dispose()
 {
     if (!isDisposed)
     {
         currentJob    = null;
         isDisposed    = true;
         lastStartTime = null;
         semaphore.Release(threads.Length);
         // Clear work queue
         lock (workQueue) {
             workQueue.Clear();
         }
         onComplete.Set();
     }
 }
コード例 #13
0
        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));
                    }
                }
            }
        }
コード例 #14
0
        /// <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);
            }
        }
コード例 #15
0
 partial void GetId_PostValidate(IWorkItemCollection instance, Int32 index);
コード例 #16
0
 partial void DisplayFields_SetCondition(ref IWorkItemCollection instance, ref IDisplayFieldList setValue);
コード例 #17
0
 partial void DefaultProjectHint_SetCondition(ref IWorkItemCollection instance, ref Int32 setValue);
コード例 #18
0
 public static void Run(IWorkItemCollection work_items)
 {
     jobManager.Run(work_items);
 }
コード例 #19
0
 partial void SortFields_SetCondition(ref IWorkItemCollection instance, ref ISortFieldList setValue);
コード例 #20
0
 partial void Resort_PostValidate(IWorkItemCollection instance);
コード例 #21
0
 partial void GetId_PreCondition(IWorkItemCollection instance, ref Int32 index);
コード例 #22
0
 public void IndexOf_UnitTest1()
 {
     IWorkItemCollection instance = GetTestInstance();
     int actual = instance.IndexOf(1);
 }
コード例 #23
0
        internal static IWorkItemCollection GetTestWorkItemCollection()
        {
            IWorkItemCollection instance = null;

            return(instance);
        }
コード例 #24
0
 /// <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);
 }
コード例 #25
0
 partial void PageSize_SetCondition(ref IWorkItemCollection instance, ref Int32 setValue);
コード例 #26
0
 partial void Collection_SetCondition(ref IWorkItem instance, ref IWorkItemCollection setValue);
コード例 #27
0
 partial void Resort_PreCondition(IWorkItemCollection instance);
コード例 #28
0
 public void GetId_UnitTest()
 {
     IWorkItemCollection instance = GetTestInstance();
     int actual = instance.GetId(0);
 }
コード例 #29
0
 public void GetEnumerator_UnitTest()
 {
     IWorkItemCollection instance = GetTestInstance();
     IEnumerator         actual   = instance.GetEnumerator();
 }
コード例 #30
0
 /// <summary>
 /// Starts a new job.
 /// </summary>
 /// <param name="workItems">The job to start.</param>
 private void StartJob(IWorkItemCollection workItems)
 {
     jobManager?.Start(workItems);
 }