none
How to enhance the speed of my task filtering program RRS feed

  • Question

  • Hi everyone! I am writing a code to fetch me all the tasks on the project server that have certain user in the task's resource team. After testing, I found my program was working. However, the speed is extremely low. I tested the program on some simple tasks like 7-8 of them, but it will take several minutes. My company has extremely large number of tasks stored on the PWA, so I am afraid this function will not be useful to be put in use.

    Can someone help me?

    I wrote the code in C#. The variable projContext is the ProjectContext.

              
      //The following function will judge whether a user is in the task's resource team by visiting the assignments corresponding the task
            public static bool isUserinCurrentTask(String proID, String taskID, String userName)
            {
                PublishedProject proj = projContext.Projects.GetById(proID);
                PublishedTaskCollection tCollection = proj.Tasks;
                projContext.Load(tCollection);
                projContext.ExecuteQuery();
                PublishedTask pTask = tCollection.GetById(taskID);
                projContext.Load(pTask.Assignments);//The Assignment object has the property Owner to refer to
                projContext.ExecuteQuery();
                foreach (PublishedAssignment a in pTask.Assignments)// loop the assignments
                {
                    projContext.Load(a.Owner);
                    projContext.ExecuteQuery();
                    if (a.Owner.Email.ToLower() == userName.ToLower())
                        return true;
    
                }
                return false;
            }
            //The following function will reture you the list of all tasks that user is involved in
            public static List<PublishedTask> getAllUserTasks(String userName)
            {
                ProjectCollection pCollection = projContext.Projects;
                List<PublishedTask> result = new List<PublishedTask>();
                projContext.Load(pCollection);
                projContext.ExecuteQuery();
                foreach (PublishedProject proj in pCollection)//loop the projects
                {
                    projContext.Load(proj.Tasks);
                    projContext.ExecuteQuery();
                    foreach (PublishedTask task in proj.Tasks)// loop the tasks
                    {
                        projContext.Load(task,t=>t.Id);
                        projContext.ExecuteQuery();
                        Console.WriteLine(task.Id);
                        if (isUserinCurrentTask(proj.Id.ToString(), task.Id.ToString(), userName))
                            result.Add(task);
                    }
    
                }
                return result;
            }

    My main thought is to visit all assignments and see whether the user is the owner of the assignment, and if so, I will add the corresponding task into the result list. However, I believe it is because I need to load a lot of variables that the program is extremely slow. Wish some genius can help me solve the problem.

    Thank you very much.


    Friday, October 25, 2013 6:02 PM

Answers

  • Have you tried using the Linq methods to filter out result rather than looping?

    Thanks | Sunil Kr Singh | http://epmxperts.wordpress.com

    • Marked as answer by Qingye Jiang Monday, November 11, 2013 9:41 PM
    Tuesday, October 29, 2013 2:22 PM
    Moderator

All replies

  • Hello,

    Why don't you query the Project Server Reporting database for this info? It will be a lot quicker..

    Paul


    Paul Mather | Twitter | http://pwmather.wordpress.com | CPS

    Friday, October 25, 2013 6:19 PM
    Moderator
  • Qingye,

    If I understand correctly, you wish to find all assignments for a specific resource.  If that truly is the case, there is out-of-the-box functionality that provides that information. 

    In PWA:

    1. Click on Resource Center in the Action Menu

    2. Select from the listing of resources the resource that interests you

    3. Click on Assignments in the ribbon

    No C# coding is required--which frees you to do more difficult things that OOB functionality does not do.




    • Edited by Edward Hanna Friday, October 25, 2013 6:46 PM Remove signature
    Friday, October 25, 2013 6:46 PM
  • Thanks Edward. The thing is I am strying to build up a Windows Store app that may use the functionalities of PWA. I need to explore the API of Project Server. Now I am kind of stuck because of the lack of development documents in this topic.

    Qingye Jiang

    Friday, October 25, 2013 9:05 PM
  • Because now I am trying to build up a WIndows Store App using the Project Server API, I try to avoid visiting the database directly. Thanks!

    Qingye Jiang

    Friday, October 25, 2013 9:06 PM
  • As Paul said. Use the reporting database, much faster but it does rely on the project managers publishing their projects.

    Rod Gill

    The one and only Project VBA Book

    Rod Gill Project Management

    Friday, October 25, 2013 10:17 PM
    Moderator
  • Hi,

    instead of using the Project Server Reporting schema you can use the oData/PowerPivot in Project Online to retrieve data for you app.

    Best,

    Renke


    http://www.holert.com Project Management with MS Project - Oldenburg, Berlin, Munich/Germany

    Monday, October 28, 2013 8:45 AM
  • Have you tried using the Linq methods to filter out result rather than looping?

    Thanks | Sunil Kr Singh | http://epmxperts.wordpress.com

    • Marked as answer by Qingye Jiang Monday, November 11, 2013 9:41 PM
    Tuesday, October 29, 2013 2:22 PM
    Moderator
  • Hi Sunil:

    That is exactly what I want to do. However I am not quite familiar with how to use Linq to do queries on Project Server Data. Would you be so kind to provide me with an example? Thank you so much!


    Qingye Jiang

    Tuesday, October 29, 2013 5:03 PM
  • There are couple of ways to perform Linq Query on datasets, i can give you a few examples here, but would suggest you to go through this MSDn link http://msdn.microsoft.com/en-us/library/bb399358.aspx

    Basic examples would be as below

    string filterExpforAlltaskUID = "TASK_UID='" + tskUIDrow["TASK_UID"] + "' AND MD_PROP_UID='" + TaskECFUID + "'";
    DataTable DistTbl = PrjDS.Tables["TaskCustomFields"].Select(filterExpforAlltaskUID).CopyToDataTable().DefaultView.ToTable();
    Guid ECFGuid =new Guid("c179f9c8-b9e6-4583-910b-208bfb944b76");
     var project = PrjDS.ProjectCustomFields.Where(p => p.MD_PROP_UID==ECFGuid && p.TEXT_VALUE =="Value to be matched").ToArray();
    
    Let us know if this helps

    Thanks | Sunil Kr Singh | http://epmxperts.wordpress.com

    Wednesday, October 30, 2013 3:06 PM
    Moderator
  • Thanks a lot and sorry for the late reply (I was busy with another project recently). It works so fast!


    Qingye Jiang

    Monday, November 11, 2013 9:42 PM