Overview Used Variables

GuyS (45 posts)
March 17, 2020 09:28 AM
Accepted Answer

Hello World,

I'm in the process of copying an adTempus installation to another server.

I've been exporting and importing Jobs, but would like an overview of all used Variables per Group/Job.

I'm using nested Variables, and need to be sure that Variables are set on the right level.

 

Example:

Group 2020:

        Variable Year = 2020 

   Group Month:

        Variable Year* = 2020    -> I need to be sure that Year is not overwritten by a value of Group Month

        Variable Month=03 

 

 Thanks for any idea's,

 

Guy Swagten

The Netherlands 

This topic has an accepted answer. Jump to it.
Bill Staff (601 posts)
March 17, 2020 10:17 AM
Accepted Answer

Here's some code (in C#) that will enumerate all the groups, jobs, and steps, and report any variables that are overridden:

//if the adTempus server is on a different computer, replace . with the name
//for example,
//string ServerName=@"someserver";
string ServerName=@".";


void Main()
{
    using (var session = Scheduler.Connect(ServerName, LoginAuthenticationType.Windows, "", ""))
    {
        using (var context = session.NewDataContext())
        {
            var root = context.GetJobGroup(null);

            var seenVariables = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
            CheckVariables(root, seenVariables);
        }
    }
}


void CheckVariables(JobGroup group,Dictionary<string,string> parentSeenVariables)
{
    var seenVariables = parentSeenVariables.ToDictionary(entry => entry.Key, entry => entry.Value, StringComparer.OrdinalIgnoreCase);

    CheckVariables(group.JobVariables,seenVariables,string.Format("Group \"{0}\"",group.FullyQualifiedName));
    
    var jobs=group.GetJobs(ObjectFetchOptions.FullFetch,false);
    foreach(var item in jobs)
    {
        CheckVariables(item,seenVariables);    
    }
    
    var childGroups=group.GetGroups(ObjectFetchOptions.FullFetch,false);
    foreach(var item in childGroups)
    {
        CheckVariables(item,seenVariables);
    }
}

void CheckVariables(Job job,Dictionary<string,string> seenVariables)
{
    CheckVariables(job.JobVariables,seenVariables,string.Format("Job \"{0}\"",job.FullyQualifiedName));
    
    foreach(var item in job.Steps)
    {
        CheckVariables(item.JobVariables, seenVariables, string.Format("Job \"{0}\" step {1}", job.FullyQualifiedName,item.StepNumber));
    }
}

void CheckVariables(ArcanaDevelopment.adTempus.Client.Collections.JobVariableCollection variables, Dictionary<string, string> seenVariables, string locationDescription)
{
    foreach (var item in variables)
    {
        string seenLocation;

        if (seenVariables.TryGetValue(item.Name, out seenLocation))
        {
            WriteOutput(string.Format("{0} overrides variable \"{1}\" from {2}", locationDescription, item.Name, seenLocation));
        }
        else
        {
            seenVariables.Add(item.Name, locationDescription);
        }
    }
}

void WriteOutput(string output)
{
    Debug.WriteLine(output);    
}

You can run this code using LINQPad or Visual Studio.

Bill Staff (601 posts)
March 17, 2020 10:18 AM
Accepted Answer
I just noticed that you posted this in the Reporting forum, but unless you need something that's reusable in the Console by non-developers, it's much easier to do it this way than with a report :)
GuyS (45 posts)
March 18, 2020 07:34 AM
Accepted Answer

Ah, thanks Bill, this solution will do the job!

 

You always find a new thing for me to find out :-) LINQPad, nice.

And I also added the code to my 'Speeltuin'-tool. (You can google the meaning of it :-))

Still a little struggle with the adTempus DB on another server, but that's a Windows thing, I think.

 

Kind regards,

Guy

Replies are disabled for this topic.