Using PSI to create Master Project and Sub Projects

S

Sasquat

I'm trying to create an Master Project with a task associated with an
Sub-Project using PSI. But when a call QueueCreateProject or
QueueCreateProjectAndCheckout the method returns Error
InvalidProjectTypeForCreation. Some articles in Project Server 2007
SDK said that project types like ProjectType.MasterProject and
ProjectType.InsertedProject can be used with PSI to create projects
("Project.ProjectType Enumeration" SDK description). How can I do
this?

using (WebSvcProject.Project prj = new WebSvcProject.Project())
{

Guid UID_MasterProject = Guid.NewGuid();
Guid UID_SubProject = Guid.NewGuid();
Guid UID_CreateMasterProject = Guid.NewGuid();
Guid UID_CreateSubProject = Guid.NewGuid();
Guid UID_Session = Guid.NewGuid();
Guid UID_CheckInMasterProject = Guid.NewGuid();
Guid UID_CheckInSubProject = Guid.NewGuid();

prj.Url = URL_PWA + "/project.asmx";
prj.Credentials = CredentialCache.DefaultCredentials;
prj.PreAuthenticate = true;

WebSvcQueueSystem.QueueSystem queue = new
WebSvcQueueSystem.QueueSystem();
queue.Url = URL_PWA + "/QueueSystem.asmx";
queue.Credentials = CredentialCache.DefaultCredentials;
queue.PreAuthenticate = true;

ProjectDataSet subPrjDS = new ProjectDataSet();
ProjectDataSet.ProjectRow subPrjRow =
subPrjDS.Project.NewProjectRow();
subPrjRow.PROJ_UID = UID_SubProject;
subPrjRow.PROJ_NAME = "SUB PROJETO " +
DateTime.Now.ToShortDateString().Replace("/", "") + " " +
DateTime.Now.ToShortTimeString().Replace(":", "");
subPrjRow.PROJ_TYPE =
Convert.ToInt32(PSLibrary.Project.ProjectType.InsertedProject);
subPrjRow.PROJ_STALE_FLAGS = 0;
subPrjDS.Project.AddProjectRow(subPrjRow);

ProjectDataSet.TaskRow task1SubPrj = subPrjDS.Task.NewTaskRow();
task1SubPrj.PROJ_UID = UID_SubProject;
task1SubPrj.TASK_UID = Guid.NewGuid();
task1SubPrj.TASK_DUR_FMT = (int)PSLibrary.Task.DurationFormat.Day;
task1SubPrj.TASK_DUR = 9600; // 8 hours in duration units (minute/
10)
task1SubPrj.TASK_NAME = "Task X";
task1SubPrj.TASK_START_DATE = System.DateTime.Now.AddDays(1);
subPrjDS.Task.AddTaskRow(task1SubPrj);

prj.QueueCreateProjectAndCheckOut(UID_CreateSubProject,
UID_Session, "SUB-PROJECT CHECK-OUT", subPrjDS, false);
WaitForQueue(queue, UID_CreateSubProject);

ProjectDataSet masterPrjDS = new ProjectDataSet();
ProjectDataSet.ProjectRow masterPrjRow =
masterPrjDS.Project.NewProjectRow();
masterPrjRow.PROJ_UID = UID_MasterProject;
masterPrjRow.PROJ_NAME = "PROJETO MASTER " +
DateTime.Now.ToShortDateString().Replace("/", "") + " " +
DateTime.Now.ToShortTimeString().Replace(":", "");
masterPrjRow.PROJ_STALE_FLAGS = 4;
masterPrjDS.Project.AddProjectRow(masterPrjRow);

ProjectDataSet.TaskRow task1MasterPrj =
masterPrjDS.Task.NewTaskRow();
task1MasterPrj.PROJ_UID = masterPrjRow.PROJ_UID;
task1MasterPrj.TASK_UID = Guid.NewGuid();
task1MasterPrj.TASK_DUR_FMT =
Convert.ToInt32(PSLibrary.Task.DurationFormat.Day);
task1MasterPrj.TASK_DUR = 4800; // 8 hours in duration units
(minute/10)
task1MasterPrj.TASK_NAME = "Task Y";
task1MasterPrj.TASK_START_DATE = System.DateTime.Now.AddDays(1);
masterPrjDS.Task.AddTaskRow(task1MasterPrj);

ProjectDataSet.TaskRow task2MasterPrj =
masterPrjDS.Task.NewTaskRow();
task2MasterPrj.PROJ_UID = UID_MasterProject;
task2MasterPrj.TASK_UID = Guid.NewGuid();
task2MasterPrj.TASK_NAME = subPrjRow.PROJ_NAME;
task2MasterPrj.TASK_DUR_FMT =
(int)PSLibrary.Task.DurationFormat.Day;
task2MasterPrj.TASK_IS_SUMMARY = true;
task2MasterPrj.TASK_IS_EFFORT_DRIVEN = false;
task2MasterPrj.TASK_IS_SUBPROJ = true;
task2MasterPrj.TASK_TYPE = 1;
task2MasterPrj.TASK_IS_ROLLED_UP = true;
task2MasterPrj.TASK_EXT_PROJ_UID = UID_SubProject;
task2MasterPrj.TASK_START_DATE = System.DateTime.Now.AddDays(3);
masterPrjDS.Task.AddTaskRow(task2MasterPrj);

prj.QueueCreateProject(UID_CreateMasterProject, masterPrjDS,
false);
WaitForQueue(queue, UID_CreateMasterProject);

prj.QueueCheckInProject(UID_CheckInSubProject, UID_SubProject,
true, UID_Session, "SUB-PROJECT CHECK-IN");
WaitForQueue(queue, UID_CheckInSubProject);
}
 
D

Dale Howard [MVP]

Sasquat --

I would recommend you post this question in the
microsoft.public.project.developer newsgroup, as you are more likely to get
an answer in that group. Hope this helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top