Community forum

Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
View
Go to last post Go to first unread
Offline burnsmeister  
#1 Posted : Wednesday, April 22, 2015 4:20:25 PM(UTC)
burnsmeister

Rank: No customer

Joined: 3/31/2015(UTC)
Posts: 6
United Kingdom
Location: England, Pool

Thanks: 1 times
Was thanked: 2 time(s) in 2 post(s)
Hi Folks.
I have inherited some code which programmatically creates jobs and adds notifications. The code was written using VC API v6.x.x but having upgraded to VC API v7.x.x it will no longer compile. I realise that the way VC handles notifications has changed but I cannot find anywhere explaining how to do this programmatically.

The original code is shown below -
Code:
NotificationClass nc = job.NewNotification(NotificationClass.NType.SQL);
nc.Description = functionDisplay + descriptionPostfix;
nc.SQL.ConnectionId = sqlCon.Id;
nc.SQL.CommandType = System.Data.CommandType.Text;

string userId = new User(DB, Configuration.system).id;

if (type.Equals("ERROR"))
	nc.SQL.Command = "spSysErrorInsert " + userId + "," + functionId.ToString() + "," + DB.WrapValue(Environment.MachineName) + "," + DB.WrapValue("VisualCron") + "," + DB.WrapValue("Execution Error") + "," + DB.WrapValue("Check VisualCron Logs") + ",null,null,null,null,null";
else
	nc.SQL.Command = "spSysActivityInsert " + userId + "," + functionId.ToString() + ",null," + DB.WrapValue(type) + "," + DB.WrapValue(type.Substring(0, 1) + type.Substring(1).ToLower()) + ",null,null,null,null,null";

//Add to notification server
server.Notifications.Add(nc);

//Attach notification to event based on passed type
if (type.Equals("START"))
	job.StartNotifications.Add(nc.Id);
else if (type.Equals("END"))
	job.CompleteNotifications.Add(nc.Id);
else if (type.Equals("ERROR"))
	job.ErrorNotifications.Add(nc.Id);

This line now fails - server.Notifications.Add(nc);

I cannot work out how to create a TaskNotificationClass which seems to have replaced the NotificationClass.

All help greatly appreciated!!

Regards.

John

Edited by moderator Friday, April 24, 2015 6:42:35 AM(UTC)  | Reason: Not specified

Offline Support  
#2 Posted : Wednesday, April 22, 2015 10:31:27 PM(UTC)
Support

Rank: Official support

Medals:
Joined: 2/23/2008(UTC)
Posts: 9,412

Thanks: 573 times
Was thanked: 326 time(s) in 314 post(s)
The StartNotifications etc are no longer used as TaskNotifications are connected to what we call Flows. Here is the code below that we use to convert old Notification to new:

Code:

            If j.StartNotifications.Count > 0 Then
                For Each startNotificationId As String In j.StartNotifications
                    Dim tf As New FlowClass
                    tf.ActionType = FlowClass.FlowActionT.RunNotification
                    tf.NotificationId = startNotificationId
                    tf.EventType = FlowClass.FlowEventT.OnStart
                    j.Flow.Add(tf)
                Next
                j.StartNotifications.Clear()
            End If
            ' complete notifications
            If j.CompleteNotifications.Count > 0 Then
                For Each completeNotificationId As String In j.CompleteNotifications
                    Dim tf As New FlowClass
                    tf.ActionType = FlowClass.FlowActionT.RunNotification
                    tf.NotificationId = completeNotificationId
                    tf.EventType = FlowClass.FlowEventT.OnComplete
                    j.Flow.Add(tf)
                Next
                j.CompleteNotifications.Clear()
            End If
            ' error notifications
            If j.ErrorNotifications.Count > 0 Then
                For Each errorNotificationId As String In j.ErrorNotifications
                    Dim tf As New FlowClass
                    tf.ActionType = FlowClass.FlowActionT.RunNotification
                    tf.NotificationId = errorNotificationId
                    tf.EventType = FlowClass.FlowEventT.OnError
                    j.Flow.Add(tf)
                Next
                j.ErrorNotifications.Clear()
            End If
Henrik
Support
http://www.visualcron.com

Please like VisualCron on facebook!
Offline burnsmeister  
#3 Posted : Thursday, April 23, 2015 9:35:30 AM(UTC)
burnsmeister

Rank: No customer

Joined: 3/31/2015(UTC)
Posts: 6
United Kingdom
Location: England, Pool

Thanks: 1 times
Was thanked: 2 time(s) in 2 post(s)
Hi Henrik.

Thanks for getting back to me. I'm not sure that what you propose is exactly what I'm trying to achive so I'll give a bit more background. The jobs and tasks are being created on the fly when we sync with VC. So effectively on each sync the jobs/tasks are removed and recreated. I'm sure there was a good reason why it was done that way but I wasn't involved in the development of the code so can't really comment too much.

So basically each job is created and in VC v6.x.x a new notification was programmatically created on the server (as per the code above) and assigned to the job. It's this part that now doesn't work - the creation of the notification on the server. Is it possible that you could show me an example of how to programmatically create a notification on the server?

Many thanks for your help!

John
Offline ErikC  
#4 Posted : Thursday, April 23, 2015 10:19:20 AM(UTC)
ErikC

Rank: Paid support

Joined: 2/26/2008(UTC)
Posts: 1,437
Netherlands
Location: Amsterdam

Thanks: 95 times
Was thanked: 187 time(s) in 163 post(s)
Hi,

You need to create the notification first in VC. You can do this programmaticaly, but this code will use the allready created notifications.

To see all the notification id's you can need use this code:

Code:
List<TaskNotificationClass> notifications = s.Notifications.GetAll();
Console.WriteLine("Notification ID                      -- Name");
Console.WriteLine("---------------------------------------------");
foreach (TaskNotificationClass notification in notifications)
{
    Console.WriteLine(notification.Task.Id + " -- " + notification.Task.Name);
 }


On a job you create a flow and use the right notification id .

Code:
List<JobClass> jobs = s.Jobs.GetAll();
JobClass job = jobs[indexnumber]; //indexnumber to get one of your jobs
FlowClass fc = new FlowClass();
fc.ActionType = FlowClass.FlowActionT.RunNotification;
fc.EventType = FlowClass.FlowEventT.OnComplete; //choose from enum
fc.NotificationId = notificationID; //use one from the list 
job.Flow.Add(fc);
s.Jobs.Update(job);


On a task you do the same:

Code:
List<JobClass> jobs = s.Jobs.GetAll();
JobClass job = jobs[indexnumber];  //indexnumber to get one of your jobs
TaskClass task = job.Tasks[indexnumber];  //indexnumber to get one of your tasks inside the job
FlowClass fc = new FlowClass();
fc.ActionType = FlowClass.FlowActionT.RunNotification;
fc.EventType = FlowClass.FlowEventT.OnComplete;  //choose from enum
fc.NotificationId = notificationID;  //use one from the list
task.Flow.Add(fc);
s.Jobs.Tasks.Update(task);


That's it.
I use this also to put my notifications on jobs and tasks and it rocks!

Regards,
Erik

Edited by user Thursday, April 23, 2015 10:23:33 AM(UTC)  | Reason: typo

Uses Visualcron since 2006.
thanks 1 user thanked ErikC for this useful post.
Support on 4/23/2015(UTC)
Offline burnsmeister  
#5 Posted : Thursday, April 23, 2015 10:48:44 AM(UTC)
burnsmeister

Rank: No customer

Joined: 3/31/2015(UTC)
Posts: 6
United Kingdom
Location: England, Pool

Thanks: 1 times
Was thanked: 2 time(s) in 2 post(s)
Hi Erik.

Thanks for your reply. I see exactly what you are doing there - really clearly.

My problem still is that I need to be able to create the notifications at the time I'm creating the job - programmatically.... I can't really create them on the server beforehand.

Many thanks for your help.

John

Offline ErikC  
#6 Posted : Thursday, April 23, 2015 10:58:35 AM(UTC)
ErikC

Rank: Paid support

Joined: 2/26/2008(UTC)
Posts: 1,437
Netherlands
Location: Amsterdam

Thanks: 95 times
Was thanked: 187 time(s) in 163 post(s)
Ok,

Creating a notification is like this:

Code:
//1st create a task
TaskClass tc = new TaskClass();
//you used an SQL task, so create the type
TaskSQLClass tsqlc = new TaskSQLClass();
//fill in your properties
tsqlc.CommandType = System.Data.CommandType.Text;
//than join the both together
tc.SQL = tsqlc;

//now create a notification
TaskNotificationClass tnc = new TaskNotificationClass();
//join the task to the notification
tnc.Task = tc;

//add the notification to the server
s.Notifications.Add(tnc); 


Regards
Erik
Uses Visualcron since 2006.
thanks 1 user thanked ErikC for this useful post.
Support on 4/23/2015(UTC)
Offline burnsmeister  
#7 Posted : Thursday, April 23, 2015 11:07:41 AM(UTC)
burnsmeister

Rank: No customer

Joined: 3/31/2015(UTC)
Posts: 6
United Kingdom
Location: England, Pool

Thanks: 1 times
Was thanked: 2 time(s) in 2 post(s)
Great thanks Erik - I'll give that a try today and see if I can make it work.

Really appreciate your help!

Cheers.

John
thanks 1 user thanked burnsmeister for this useful post.
ErikC on 4/24/2015(UTC)
Offline ErikC  
#8 Posted : Thursday, April 23, 2015 11:10:11 AM(UTC)
ErikC

Rank: Paid support

Joined: 2/26/2008(UTC)
Posts: 1,437
Netherlands
Location: Amsterdam

Thanks: 95 times
Was thanked: 187 time(s) in 163 post(s)
Hi John,

Glad i could help. BigGrin
Please let us know in the forum if you sorted it out, so I can close this issue.

Regards
Erik
Uses Visualcron since 2006.
thanks 1 user thanked ErikC for this useful post.
Support on 4/23/2015(UTC)
Offline burnsmeister  
#9 Posted : Thursday, April 23, 2015 5:14:54 PM(UTC)
burnsmeister

Rank: No customer

Joined: 3/31/2015(UTC)
Posts: 6
United Kingdom
Location: England, Pool

Thanks: 1 times
Was thanked: 2 time(s) in 2 post(s)
Ok so partial success! I can now create the notifications but with some missing information. For some reason the CommandText is not being stored when the notifcation is created.

I've also managed to add an 'on error' flow event to the job but haven't been able to hook that up to the notification.

Making progress but not quite there yet!

Happy for you to close the issue and I'll come back to the forum if I need any more help.

Cheers.

John



Offline Support  
#10 Posted : Thursday, April 23, 2015 5:40:53 PM(UTC)
Support

Rank: Official support

Medals:
Joined: 2/23/2008(UTC)
Posts: 9,412

Thanks: 573 times
Was thanked: 326 time(s) in 314 post(s)
Use:

Code:
Task.SQL.EncryptedCommand = clientObject.Encrypt("Your command")
Henrik
Support
http://www.visualcron.com

Please like VisualCron on facebook!
thanks 1 user thanked Support for this useful post.
burnsmeister on 4/23/2015(UTC)
Offline burnsmeister  
#11 Posted : Thursday, April 23, 2015 5:54:57 PM(UTC)
burnsmeister

Rank: No customer

Joined: 3/31/2015(UTC)
Posts: 6
United Kingdom
Location: England, Pool

Thanks: 1 times
Was thanked: 2 time(s) in 2 post(s)
YES!

That's got the sql text storing nicely. I'm sure with the other code examples you showed me wearlier I can work out how to attach the notification to the flow event.

Help much appreciated Henrik - genius!
thanks 1 user thanked burnsmeister for this useful post.
ErikC on 4/24/2015(UTC)
Users browsing this topic
Guest (2)
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Powered by YAF.NET | YAF.NET © 2003-2016, Yet Another Forum.NET
This page was generated in 0.436 seconds.
Scroll to Top