Community forum

Please note that VisualCron support is not actively monitoring this community forum. Please use our contact page for contacting the VisualCron support directly.


timzimmerman
2012-11-26T22:12:37Z
Hello,

I have a few hundred jobs with several tasks in each one that must all be updated to a new server path. I've been looking through the API documentation and haven't been able to figure out a way to loop through each property of each task to check for the old server path. What I would like to do is find properties with the path and update them. Unfortunately I don't see any task properties enumeration or class. Any help is appreciated.

Thank you!
Sponsor
Forum information
Support
2012-11-27T07:45:30Z
Is it a specific Task type you are looking at or searching for a property in general. If it is in general then you need to use a .NET reflection method to search through all properties.
Henrik
Support
http://www.visualcron.com 
Please like  VisualCron on facebook!
timzimmerman
2012-11-27T14:55:45Z
There are many task types involved. For example, the path that I need to change appears in Arguments, WorkingDirectory, and CmdLine in Execute tasks and in ArchivePath in Archive Compress tasks. I just need to loop through each task type and all of each task's properties searching for the server path.

I'm not too familiar with Reflection and have been trying for a few hours to access the properties of each task type to no avail. Would you possibly be able to point me in the right direction? I've been able to have each class corresponding to each property in TaskClass show up in PropertyInfo through this:

Dim propInfo As PropertyInfo() = GetType(VisualCron.TaskClass).GetProperties()


But I haven't figured out where to take it from there yet.

Thank you for your help!
timzimmerman
2012-11-28T22:43:01Z
UPDATE:

Sorry this is in a whole new reply; there were issues when I tried to edit this second code block into my previous reply.

I've been playing around with it quite a bit more and have finally arrived at some progres...

Here is my code so far. The only problem I'm running into right now is I'm not getting the property values that contain the server path I'm trying to update. I am getting some of the property values, but for things like TaskExecuteClass.CmdLine (a property that usually contains the path) I am getting empty strings.


Dim strAdd As String = ""
For Each t As VisualCronAPI.Server In vcClient.Servers.GetAll()
	For Each f As VisualCron.JobClass In t.Jobs.GetAll
		For Each s As VisualCron.TaskClass In f.Tasks
			Dim propVal As Object
			Dim propInfo As PropertyInfo() = s.GetType().GetProperties()
			For i As Integer = 0 To propInfo.Length - 1
				With propInfo(i)
					If s.TaskType.ToString = propInfo(i).Name.ToString Then
						Dim classInst As Object = Activator.CreateInstance(Type.GetType(propInfo(i).PropertyType.AssemblyQualifiedName))
						Dim classProps As PropertyInfo() = classInst.GetType().GetProperties()
						For h As Integer = 0 To classProps.Length - 1
							With classProps(h)
								If .GetIndexParameters().Length = 0 Then
									propVal = .GetValue(classInst, Nothing)
									If Not propVal Is Nothing Then
										If propVal.ToString.Contains("\\path\") Or propVal.ToString.Contains("\\PATH\") Then
											strAdd = .Name & " - " & propVal.ToString
										End If
									End If
								End If
								If strAdd <> "" Then
									ListBox1.Items.Add(strAdd)
								End If
							End With
						Next
					End If
				End With
			Next
			If s.Name.ToString.Contains("\\path\") Or s.Name.ToString.Contains("\\PATH\") Then
				strAdd = s.Name.ToString
				ListBox1.Items.Add(strAdd)
			End If
		Next s
	Next f
Next t
ListBox1.Sorted = True


Any insight?
timzimmerman
2012-12-03T16:38:23Z
UPDATE:

After a chat with Henrik and much trial and error beforehand I have reached a solution.

Here is a link to a solved question I posted on StackOverflow about not being able to reach the string values inside each task's property:

http://stackoverflow.com...of-propertyinfo-getvalue 

And here is my code that covers resetting the property values. The key here after the SetValue() is called is that serverObj.Jobs.Update() and serverObj.Jobs.Tasks.Update() are called. This code is probably super-inefficient, but speed isn't key in my particular case so this works for me. Improve it if you know how.

Dim count As Integer = 0
Dim strAdd As String = ""
For Each t As VisualCronAPI.Server In vcClient.Servers.GetAll()
For Each f As VisualCron.JobClass In t.Jobs.GetAll
For Each s As VisualCron.TaskClass In f.Tasks
Dim propVal As Object
Dim propInfo As PropertyInfo() = s.GetType().GetProperties()
For i As Integer = 0 To propInfo.Length - 1
With propInfo(i)
If s.TaskType.ToString = propInfo(i).Name.ToString Then
Dim asm As Assembly = Assembly.Load("VisualCron")
Dim typeName As String = String.Format("VisualCron.{0}", propInfo(i).PropertyType.Name)
Dim tp As Type = asm.GetType(typeName)
Dim classInst As Object = Activator.CreateInstance(tp)
Dim classProps As PropertyInfo() = classInst.GetType().GetProperties()
For h As Integer = 0 To classProps.Length - 1
With classProps(h)
If .GetIndexParameters().Length = 0 Then
propVal = .GetValue(CallByName(s, propInfo(i).Name.ToString, [Get]), Nothing)
If Not propVal Is Nothing Then
If propVal.ToString.ToUpper.Contains("\\SERVER\") Then
tp.GetProperty(classProps(h).Name.ToString).SetValue(CallByName(s, propInfo(i).Name.ToString, [Get]), "\\NEW_PATH\", Nothing)
t.Jobs.Update(f)
t.Jobs.Tasks.Update(s)
End If
End If
End If
End With
Next
End If
End With
Next
Next s
Next f
Next t


Sorry about no syntax highlighting... it keeps screwing up and cutting off the top half of my code.
Scroll to Top