Tuesday, July 22, 2008

Mapping Assignments Between a 2003 Task and a 2007 Task with mpFx

   1: private void CreateAssignments(Guid projectGuid,
   2:                                     Task legacyTask,
   3:                                     Guid taskGuid,
   4:                                     ref ProjectDataSet projectDataSet)
   5:      {
   6:          foreach (Microsoft.Office.Interop.MSProject.Resource legacyResource in legacyTask.Resources)
   7:          {
   8:              Guid resourceGuid = _resourceMap[legacyResource.Name];
   9:  
  10:              // If the resource is not part of the project team, we have to update it
  11:              if (!_projectTeams[projectGuid].Contains(resourceGuid))
  12:              {
  13:                  OnAnalyzeStatusChanged(this, string.Format("Adding {0} to the proejct team", legacyResource.Name));
  14:                  using (ProjectTeamDataSet projectTeam = _projectServer.Projects.OpenProjectTeam(projectGuid))
  15:                  {
  16:                      ProjectTeamDataSet.ProjectTeamRow resource = projectTeam.ProjectTeam.NewProjectTeamRow();
  17:  
  18:                      resource.PROJ_UID = projectGuid;
  19:                      resource.RES_IS_ENTERPRISE_RESOURCE = true;
  20:                      resource.RES_NAME = legacyResource.Name;
  21:                      resource.RES_UID = resourceGuid;
  22:                      resource.NEW_RES_UID = resourceGuid;
  23:                      resource.RES_TYPE = (int) Resource.Type.WorkResource;
  24:  
  25:                      projectTeam.ProjectTeam.AddProjectTeamRow(resource);
  26:  
  27:                      _projectServer.Projects.UpdateProjectTeam(projectGuid, projectTeam, _checkedOutProjects[projectGuid].SessionGuid, false);
  28:  
  29:                      _projectTeams[projectGuid].Add(resourceGuid);
  30:                  }
  31:              }
  32:  
  33:              ProjectDataSet.AssignmentRow assignment = projectDataSet.Assignment.NewAssignmentRow();
  34:  
  35:              assignment.PROJ_UID = projectGuid;
  36:              assignment.TASK_UID = taskGuid;
  37:              assignment.ASSN_UID = Guid.NewGuid();
  38:              assignment.RES_UID = resourceGuid;
  39:  
  40:              projectDataSet.Assignment.AddAssignmentRow(assignment);
  41:          }
  42:      }v

No comments:

Disclaimer

Content on this site is provided "AS IS" with no warranties and confers no rights. Additionally, all content on this site is my own personal opinion and does not represent my employer's view in any way.