PSI Summary of Project Server

Source: Internet
Author: User

Create a project based on the template. The returned projectuid is the unique ID of the project. In addition, due to the impact of various State attributes of the project, try catch is required when calling the PSI method.

 
Try {guid projectuid = projectsvc. createprojectfromtemplate (templateguid, projectname);} catch (exception ex) {message = "Create project failed. <br/>" + ex. Message ;}

 

// If you need to add other properties of the project, such as the project manager

Projectwebsvc. projectdataset projectds = new projectwebsvc. projectdataset (); projectds = projectsvc. readproject (projectuid, projectwebsvc. datastoreenum. workingstore); Private guid sessionuid = guid. newguid (); // this GUID is required for both the project to be migrated and the project to be migrated. The GUID must be consistent. Uidprivate string session_desc = ""; // The above field description try {// Export Project projectsvc. checkoutproject (projectuid, sessionuid, session_desc);} catch (exception ex) {message = "Create project success, but check out failed. <br/> "+ ex. message; return;} // obtain the project object projectwebsvc. projectdataset. projectrow project = projectds. project. findbyproj_uid (projectuid); // The projectownerid attribute is the project manager. This person must have the permission to create a project. . Project. projectownerid = new GUID (projectownerid );

 

Then you can check the project.

// Assign values to another custom field (for example, project status). This custom field is defined in the query table and is of the string type projectwebsvc. projectdataset. projectcustomfieldsrow cfrowpstatustext = projectds. projectcustomfields. newprojectcustomfieldsrow (); cfrowpstatustext. proj_uid = draftprojectuid; cfrowpstatustext. custom_field_uid = guid. newguid (); cfrowpstatustext. md_prop_uid = new GUID (pstatus); // pstatus indicates the MD whose md_prop_name is "project status" found from projectserver_published.dbo.msp_custom_fields. The value of _ prop_uid. Cfrowpstatustext. field_type_enum = 21; // 21 is a text type if (newcreateuid! = Guid. Empty) // newcreateuid {cfrowpstatustext. code_value = projectstatusitemguid; // projectstatusitemguid is the identifier (identifier) of 'Project status a' found in the identifier );}

 

// Update project guid jobid = guid. newguid (); projectsvc. queueupdateproject (jobid, sessionuid, projectds, false); this. psiwaitforqueue (queuesystemsvc, jobid); // check in the project bool isforcecheckin = true; guid jobid1 = guid. newguid (); projectsvc. queuecheckinproject (jobid1, projectuid, isforcecheckin, sessionuid, session_desc); this. psiwaitforqueue (queuesystemsvc, jobid1); // release project guid jobid2 = guid. newguid (); projectsvc. queuepublish (jobid2, projectuid, false, String. empty); this. psiwaitforqueue (queuesystemsvc, jobid2 );

 

 

// The following is an example of resourcewebsvc to update the resource attributes (Time Table approver. resourcedataset resourceds = new resourcewebsvc. resourcedataset (); resourceds = resourcesvc. readresource (item. resource); try {resourcesvc. checkoutresources (UIDs);} catch (exception ex) {message = "check out resource failed. <br/> "+ ex. message;} resourcewebsvc. resourcedataset. resourcesrow resource1 = resourceds. resources. findbyres_uid (resourceuid); resource1.res _ timesheet_mgr_uid = resourcetimesheetmanageruid; // assign a value to the time table approver. This person must have the global permission to accept the time table. // The update will automatically move to try {Resour. updateresources (resourceds, false, true); // auto check in} catch (exception ex) {item. message = "update resource property failed. <br> "+ ex. message; resourcesvc. checkinresources (UIDs, true );}

// Insert a task projectds = projectsvc into an existing project. readproject (New GUID (projectuid), projectwebsvc. datastoreenum. workingstore); // check out the project ry {projectsvc. checkoutproject (New GUID (projectuid), sessionuid, session_desc);} catch (exception ex) {message = "check out project failed. <br/> "+ ex. message; return;} // Add a new job line projectwebsvc. projectdataset. taskrow = projectds. task. newtaskrow (); taskrow. Proj_uid = new GUID (projectuid); taskrow. task_uid = taskuid; // task uidtaskrow. task_name = taskname; // project name taskrow. task_dur_fmt = (INT) pslibrary. task. durationformat. day; // format the task duration (minutes, hours, days, etc ...) // Limit type 4 indicates that the start time must not be earlier than (if task_constraint_type is greater than 2, task_constraint_type and task_constraint_date must be specified at the same time, and must be modified at the same time, however, if task_constraint_date remains unchanged, these two attributes must be modified at the same time, but the modification may change the project duration.) taskrow. task_constraint_type = 4; // expiry date taskrow. task_constraint_date = datetime. now; // taskrow of the task duration. task_dur = 0; // indicates that the task row is added in the middle, rather than the child taskrow for a task. addposition = (INT) pslibrary. task. addpositiontype. middle; If (taskrow. addposition = (INT) pslibrary. task. addpositiontype. middle) {// taskrow. addaftertaskuid indicates the UID and taskrow of the frontend task. task_parent_uid indicates the parent uid. The two are not the same concept taskrow. addaftertaskuid = new GUID (beforetaskuid); // beforetaskuid is the UID taskrow of the previous task in the same level task. task_outline_level = 3; // WBS level} projectds. task. addtaskrow (taskrow); bool isforcecheckin = true; guid jobid3 = guid. newguid (); projectsvc. queuecheckinproject (jobid3, new GUID (projectuid), isforcecheckin, sessionuid, session_desc); this. psiwaitforqueue (queuesystemsvc, jobid3 );

 

 

/// <Summary> /// monitor the execution of the entire queue job (general method) /// </Summary> /// <Param name = "queuesystemsvc"> queuesystem Web Service </param> /// <Param name = "jobid"> job guid </ param> Public void psiwaitforqueue (queuesystemwebsvc. queuesystem queuesystemsvc, guid jobid) {queuesystemwebsvc. jobstate; const int queue_wait_time = 4; // One second bool jobdone = false; string xmlerror = string. empty; int wait = 0; // wait For the project to get through the queue. //-get the estimated wait time in seconds. wait = queuesystemsvc. getjobwaittime (jobid); //-wait for it. // logger. info ("waiting on queue. estimate: {0} seconds. \ r \ n "+ wait); //-Wait until it is done. do {//-get the job state. jobstate = queuesystemsvc. getjobcompletionstate (jobid, out xmlerror); If (jobstate = queuesystemwebsvc. jobstate. success) {Jobdone = true;} else {If (jobstate = queuesystemwebsvc. jobstate. unknown | jobstate = queuesystemwebsvc. jobstate. failed | jobstate = queuesystemwebsvc. jobstate. failednotblocking | jobstate = queuesystemwebsvc. jobstate. correlationblocked | jobstate = queuesystemwebsvc. jobstate. canceled) {// if the job failed, error out. throw (New applicationexception ("queue request" + jobstate +" For job ID "+ jobid + ". \ r \ n "+ xmlerror); // logger. error ("queue request" + jobstate + "for job ID" + jobid + ". \ r \ n "+ xmlerror);} else {// console. writeline ("job state:" + jobstate + "for job ID:" + jobid); // console. write ("~ "); Thread. Sleep (queue_wait_time * 1000) ;}} while (! Jobdone); // console. Write ("\ r \ n ");}

 

 

If you study projectserver, you can add QQ 411033149. Let's discuss it together!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.