Solved

Removing resource from project

Posted on 2009-04-14
9
1,007 Views
Last Modified: 2013-11-15
I want to remove a resource from a given project but keep getting jobStatus = 'unknown' and the error description is empty.

Got no problem adding resources.
So if anyone got some code to remove a resource, please share.
project.CheckOutProject(ProjectUID, sessionID, ((string)Langauge.Txt["RmvResSessionDesc"]));

projectTeamDS.ProjectTeam.RemoveProjectTeamRow(rowToRemove);

project.QueueUpdateProjectTeam(jobID, sessionID, ProjectUID, projectTeamDS);

queue.WaitForQueue(jobID); //here i get jobStatus = 'unknown' 

project.QueueCheckInProject(jobID, ProjectUID, true, sessionID, ((string)Langauge.Txt["RmvResSessionDesc"]));

queue.WaitForQueue(jobID);
 

WaitForQueue() //standart taken from MS

{

            WSQueue.JobState jobState;

            const int QUEUE_WAIT_TIME = 2; // two seconds

            bool jobDone = false;

            string xmlError = string.Empty;

            int wait = 0;

            wait = queue.GetJobWaitTime(jobId);
 

            System.Threading.Thread.Sleep(wait * 1000);

            do

            {

                jobState = queue.GetJobCompletionState(jobId, out xmlError);

                

                if (jobState == WSQueue.JobState.Success)

                {

                    jobDone = true;

                }

                else

                {

                    if (jobState == WSQueue.JobState.Unknown

                    || jobState == WSQueue.JobState.Failed

                    || jobState == WSQueue.JobState.FailedNotBlocking

                    || jobState == WSQueue.JobState.CorrelationBlocked

                    || jobState == WSQueue.JobState.Canceled)

                    {

                        // If the job failed, error out

                        throw (new ApplicationException("Queue request failed \"Job State: " + jobState + 

                                "\"<br />Job ID: " + jobId + 

                                ".<br />" + xmlError +

                                "<br />Estimated wait time:" + wait + "<br />iteration:" + iteration));

                    }

                    else

                    {

                        System.Threading.Thread.Sleep(QUEUE_WAIT_TIME * 1000);

                    }

                }

            }

            while (!jobDone);

}

Open in new window

0
Comment
Question by:Skullkid
  • 5
  • 4
9 Comments
 
LVL 13

Expert Comment

by:jbfraser
ID: 24147796
I don't have any code for thise, but I've got a couple ideas.

Does your queue job actually fail? Use the PWA web interface to check the queue jobs. Make sure to show successful jobs as well as failed and cancelled.

Also, does your WaitforQueue code run as a user with enough permissions to manage the Queue? That's more than usual Project Manager permissions, for example.


James Fraser
0
 
LVL 1

Author Comment

by:Skullkid
ID: 24156453
The queue job never shows, as it is never in the queue, when i check in the project that queue job shows in the list.

User got all permissions possible on computer and in PWA, (system admin)
0
 
LVL 13

Expert Comment

by:jbfraser
ID: 24158549
If the job isn't in the queue, then "Unknown" is the correct result for WaitForQueue, as I understand it. Your problem is earlier in the code: check the QueueUpdateProjectTeam call.  Is this throwing any exceptions? Are you using a new GUID for the job?


James Fraser
0
 
LVL 1

Author Comment

by:Skullkid
ID: 24161166
No exceptions, and yes new Guid.
I have made it work for the add resource.

However i looked at ProjTool, and found that it worked if i remove the resource like this:
'See code snipped'.
But i can't show the form from a webpart, and if i did'nt call the show() method the DataSource is'nt loaded.


int index = projectTeamDS.ProjectTeam.Rows.IndexOf(row);

System.Windows.Forms.DataGridView remover = new System.Windows.Forms.DataGridView();

remover.DataSource = projectTeamDS.ProjectTeam;

((System.ComponentModel.ISupportInitialize)remover).BeginInit();

System.Windows.Forms.Form f = new System.Windows.Forms.Form();

f.Controls.Add(remover);

f.Show();

remover.DataSource = projectTeamDS.ProjectTeam;

Console.WriteLine("index: " + index + " count: " + remover.Rows.Count + " count: " + projectTeamDS.ProjectTeam.Count);

if (index == -1)

{

   Console.WriteLine("res not round");

   return; 

}

remover.Rows.RemoveAt(index);

Open in new window

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 13

Expert Comment

by:jbfraser
ID: 24161484
I don't think your code snippit above actually removes the resource from the project. That only removes them from the Datasource, but doesn't save that back to the project.

When a resource is really removed from a project, many other things need to happen: Assignments need to be deleted, Task work may need to change, &c. Removing a row from the projectTeam won't do these things. Now that I think about it, I'm not sure if RemoveProjectTeamRow() will do those things either. You may need to remove assignments manually.

For the resource you are trying to remove: do you get different behavior if you try removing a team member/resource that has no assignments in the project?


James Fraser
0
 
LVL 1

Author Comment

by:Skullkid
ID: 24161677
Yes i know, the code snip was put in instead of projectTeamDS.ProjectTeam.RemoveProjectTeamRow(rowToRemove);
then i check in/out the project and update. I can see that the resource is removed from the team when i browse it through PWA
0
 
LVL 13

Accepted Solution

by:
jbfraser earned 210 total points
ID: 24161758
Hmm. I surprised that worked.

As a workaround, can you force the DS to load? I forget the method but something like refresh() or load()

I'm about out of options. I think a call to MS support may be your best answer. The documentation for RemoveProjectTeamRow hardly deserves the word documentation.


Sorry I couldn't help...
James Fraser
0
 
LVL 1

Author Comment

by:Skullkid
ID: 24161941
Yes think i will do that, seems like an error in the PSI. Thanks for Your help :-)
0
 
LVL 1

Author Comment

by:Skullkid
ID: 24166864
No tryed several things, cant force it to load. However i decompiled the system.windows.forms.dll and found the source code for DataGridView here i replicaeted the remove code and now it works.

If anyone else should need this solution, my complete test prg is in code snip!!
Some try catch blocks has been removed for reading...
InitWebSvc();

            

//find 

Guid resUID = new Guid("d2064d5b-5dad-4d99-a975-b06bd4f1bdb7");

WSProject.ProjectDataSet.ProjectRow pr = project.ReadProjectList().Project[0];

Guid ProjectUID = pr.PROJ_UID;

Console.WriteLine("Res name: " + resource.ReadResource(new Guid("d2064d5b-5dad-4d99-a975-b06bd4f1bdb7")).Resources[0].RES_NAME);

Console.WriteLine("Proj name: " + pr.PROJ_NAME);
 

 //Insert Res row in project team

Guid sessionID = Guid.NewGuid(), jobID = Guid.Empty;

WSProject.ProjectTeamDataSet projectTeamDS = project.ReadProjectTeam(ProjectUID); 
 

//projectTeamDS.ProjectTeam.RemoveProjectTeamRow();

Console.WriteLine(projectTeamDS.GetXml());

for(int i=0; i<projectTeamDS.ProjectTeam.Rows.Count;i++)

{

   Guid resRowId = (Guid)projectTeamDS.ProjectTeam.Rows[i].ItemArray[1];

   if (resUID == resRowId)

   {

      projectTeamDS.ProjectTeam.Rows[i].Delete();

   }

}

Console.WriteLine(projectTeamDS.GetXml());
 

jobID = Guid.NewGuid();

QueueHandler queue = QueueHandler.GetInstance(URLPREFIX + psiBase);

try

{

   //try catch for project is allready cheched out

   project.CheckOutProject(ProjectUID, sessionID, "desc");

   project.QueueUpdateProjectTeam(jobID, sessionID, ProjectUID, projectTeamDS);

   queue.WaitForQueue(jobID);

} catch (Exception ex)

{ throw ex; }

finally

{

   project.QueueCheckInProject(jobID, ProjectUID, true,  

          sessionID, "desc");

   queue.WaitForQueue(jobID);

   Console.ReadKey();

}

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
MS Project export 1 659
Scrum Master, example of role 1 198
Microsft project 2007 - Outdent default font bold 1 70
Best online site to draw use case diagrams 4 75
At the office, we’ve started to get serious about organizing what we’re doing. I mean, it was getting to the point where every time I received a phone call, it began with “I know you’re really busy, but…” My boss was taking tasks away from me left a…
"Disruption" is the most feared word for C-level executives these days. They agonize over their industry being disturbed by another player - most likely by startups.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now