Workflow phases represents collection of Stages to represent project life cycle.
Example of phases are :
- Create- Project information is captured in this phase.
- Select- A subset of projects are selected in this phase.
- Plan- An execution plan will be detailed out
- Manage - Execution are monitored
- Measure- Workflow is finished.
For creating Workflow Phases using CSOM, there is a class in CSOM is PhaseCreationInformation.
Exporting: projectContext associated with exporting environment
//creating custom Phase class to store phase details
public class CPhase
{
public string Description { get; set; }
public Guid Id { get; set; }
public string Name { get; set; }
}
//Workflow Phases loading...
projectContext.Load(projectContext.Phases);
projectContext.ExecuteQuery();
List<CPhase> lstPhase = new List<CPhase>(); //creating list to store to all phases
foreach (Phase phase in projectContext.Phases)
{
CPhase passedPhase = new CPhase();
passedPhase.Description = phase.Description;
passedPhase.Id = phase.Id;
passedPhase.Name = phase.Name;
lstPhase.Add(passedPhase); //Adding phase details to list
}
Importing: projectContext associated with importing environment
// Loading workflow phases from importing environment
projectContext.Load(projectContext.Phases);
projectContext.ExecuteQuery();
//Importing workflow phases to importing environment
Dictionary<string, Microsoft.ProjectServer.Client.Phase> cachedPhases = new Dictionary<string, Microsoft.ProjectServer.Client.Phase>(); //creating Dictionary to check existing phase
foreach (Microsoft.ProjectServer.Client.Phase phase in projectContext.Phases)
{
cachedPhases.Add(phase.Name, phase);
}
Microsoft.ProjectServer.Client.PhaseCreationInformation phaseInfo = null;
for (int ip = 0; ip < lstPhase.Count; ip++)
{
try
{
if (cachedPhases.ContainsKey(Convert.ToString(lstPhase[ip].Name)))
{
// Phase already exists
}
else
{
#region Phase Creation
phaseInfo = new Microsoft.ProjectServer.Client.PhaseCreationInformation();
phaseInfo.Description = Convert.ToString(lstPhase[ip].Description);
phaseInfo.Id = new Guid(lstPhase[ip].Id.ToString());
phaseInfo.Name = Convert.ToString(lstPhase[ip].Name);
projectContext.Phases.Add(phaseInfo);
projectContext.Phases.Update();
projectContext.ExecuteQuery();
#endregion
}
}
catch (Exception ex)
{
//log exception
}
}
Hope this code will help you. Thanks
0 Comment(s)