Removing resource from project

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

LVL 1
SkullkidAsked:
Who is Participating?
 
jbfraserConnect With a Mentor Commented:
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
 
jbfraserCommented:
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
 
SkullkidAuthor Commented:
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
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

 
jbfraserCommented:
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
 
SkullkidAuthor Commented:
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
 
jbfraserCommented:
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
 
SkullkidAuthor Commented:
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
 
SkullkidAuthor Commented:
Yes think i will do that, seems like an error in the PSI. Thanks for Your help :-)
0
 
SkullkidAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.