TaskCollection.ToString()

Hello!


I have a question. When working in MS Project, I set up predecessor relationships for a task.

Suppose I have a task whose start data should be 9 days after the Finish of another task (say “Task 22”). Microsoft Project, in the “Predecessors” column of the Gantt view, shows this relationship as follows:

"22FS+9 days"

If I add other predecessor tasks, these relationships are added this the text in this column for the given task. Each predecessor relationship is shown, separated by commas:

22FS+9 days, 26FS, etc.

Is there a way of accessing this string through Aspose? My initial thought was that since the Predecessor property of a Task (t.Predecessors) is a TaskCollection, I could use the TaskCollection.ToString() method.

However, when I examine t.Predecessors.ToString() the method evaluates to “Aspose.Tasks.TaskCollection”.

Is there another (simple) way to get to the “22FS+9 day” format?

Thanks,

Doug Poland



So, I think I answered my own question, but will share the results here for anyone else interested in this particular topic:


<span style=“font-family: “Courier New”; font-size: x-small;”> string predecessorString = “”;
<span style=“background-color: rgb(255, 255, 0); font-family: “Courier New”; font-size: x-small;”> foreach(TaskLink tl in project.TaskLinks)
<span style=“font-family: “Courier New”; font-size: x-small;”> {
<span style=“background-color: rgb(255, 255, 0); font-family: “Courier New”; font-size: x-small;”> if (tl.SuccTask.Equals(t))
<span style=“font-family: “Courier New”; font-size: x-small;”> {
<span style=“font-family: “Courier New”; font-size: x-small;”> predecessorString += “,”;
<span style=“background-color: rgb(255, 255, 0); font-family: “Courier New”; font-size: x-small;”> predecessorString += tl.PredTask.Get(Tsk.Id).ToString();//note ID, not Uid
<span style=“font-family: “Courier New”; font-size: x-small;”> switch (tl.LinkType)
<span style=“font-family: “Courier New”; font-size: x-small;”> {
<span style=“font-family: “Courier New”; font-size: x-small;”> case TaskLinkType.FinishToFinish:
<span style=“font-family: “Courier New”; font-size: x-small;”> predecessorString += “FF”;
<span style=“font-family: “Courier New”; font-size: x-small;”> break;
<span style=“font-family: “Courier New”; font-size: x-small;”> case TaskLinkType.FinishToStart:
<span style=“background-color: rgb(255, 255, 0); font-family: “Courier New”; font-size: x-small;”> predecessorString += “FS”;
<span style=“font-family: “Courier New”; font-size: x-small;”> break;
<span style=“font-family: “Courier New”; font-size: x-small;”> case TaskLinkType.StartToFinish:
<span style=“font-family: “Courier New”; font-size: x-small;”> predecessorString += “SF”;
<span style=“font-family: “Courier New”; font-size: x-small;”> break;
<span style=“font-family: “Courier New”; font-size: x-small;”> case TaskLinkType.StartToStart:
<span style=“font-family: “Courier New”; font-size: x-small;”> predecessorString += “SS”;
<span style=“font-family: “Courier New”; font-size: x-small;”> break;
<span style=“font-family: “Courier New”; font-size: x-small;”> }
<span style=“background-color: rgb(255, 255, 0); font-family: “Courier New”; font-size: x-small;”> double lag = tl.LinkLag / (10.0 * 60.0 * 8.0); //assume 8.0 hour day
<span style=“font-family: “Courier New”; font-size: x-small;”> if (lag < 0)
<span style=“font-family: “Courier New”; font-size: x-small;”> {
<span style=“font-family: “Courier New”; font-size: x-small;”> predecessorString += lag.ToString();
<span style=“font-family: “Courier New”; font-size: x-small;”> predecessorString += " days";
<span style=“font-family: “Courier New”; font-size: x-small;”> }
<span style=“font-family: “Courier New”; font-size: x-small;”> else if (lag > 0)
<span style=“font-family: “Courier New”; font-size: x-small;”> {
<span style=“background-color: rgb(255, 255, 0); font-family: “Courier New”; font-size: x-small;”> predecessorString += “+”;
<span style=“background-color: rgb(255, 255, 0); font-family: “Courier New”; font-size: x-small;”> predecessorString += lag.ToString();
<span style=“background-color: rgb(255, 255, 0); font-family: “Courier New”; font-size: x-small;”> predecessorString += " days"; //probably should be “day”

<span style=“font-family: “Courier New”; font-size: x-small;”> }
<span style=“font-family: “Courier New”; font-size: x-small;”> }
<span style=“font-family: “Courier New”; font-size: x-small;”> }
<span style=“font-family: “Courier New”; font-size: x-small;”> if (predecessorString.Length > 1)
<span style=“font-family: “Courier New”; font-size: x-small;”> {
<span style=“font-family: “Courier New”; font-size: x-small;”> predecessorString = predecessorString.Substring(1); //remove leading comma
}

Hi,

Thank you for writing to Aspose support team.

Your solution is similar to the one I prepared for you. There is no builtin property available which can be used to retrieve this column. In your sample code there is a missing reference ‘t’ in the following line of code:

if (tl.SuccTask.Equals(t))*

You may also give a try to the following sample code to achieve this requirement and share the feedback.

Project proj = new Project(@“Sample.mpp”);
int succTaskId = 0;
string data = null;
foreach (TaskLink link in proj.TaskLinks)
{
    if (link.SuccTask.Get(Tsk.Uid) != succTaskId)
    {
        Console.Write(data);
        Console.WriteLine("");
        succTaskId = link.SuccTask.Get(Tsk.Uid);
        data = succTaskId + "==>";
    }
    else
    {
        data += ",";
    }
    data += link.PredTask.Get(Tsk.Uid).ToString();
    switch (link.LinkType)
    {
        case TaskLinkType.FinishToFinish:
        {
            data += "FF";
            break;
        }
        case TaskLinkType.FinishToStart:
        {
            data += "FS";
            break;
        }
        case TaskLinkType.StartToFinish:
        {
            data += "SF";
            break;
        }
        case TaskLinkType.StartToStart:
        {
            data += "SS";
            break;
        }
    }
    if (link.LinkLag != 0)
    {
        if (link.LinkLag < 0)
            data += "-" + (link.LinkLag / 4800) + " " + link.LagFormat;
        else
            data += "+" + (link.LinkLag / 4800) + " " + link.LagFormat;
    }
}

Console.WriteLine(data);