public async Task Get_ActionTemplatesWithWrongUserPass_ResponseReturnsFalseAndExceptionMessage() { GetActionTemplatesResponse response = await actionService.GetActionTemplatesAsync(VALID_IP, WRONG_USERPASS, WRONG_USERPASS); Console.WriteLine("Response IsSuccess : " + response.IsSuccess + " : Message : " + response.Content); Assert.IsTrue(!response.IsSuccess && response.Content.Length > 5); }
public async Task Setup_ActionRule_Sample_OnDailyReccuringEvent_WithExtraCondition_BlinkLed() { //Create a daily recurrence event, after adding the scheduled event and upon sucess, the ScheduledEvent.EventID will be populated with the ID assigned by the device. //This ID needs to be used to setup the action trigger later in this sample ScheduledEvent myDailyRecurrence = new ScheduledEvent("DailyRecurrence", new ICalendar(PulseInterval.DAILY, 1)); ServiceResponse MyRecurrenceEvent = await eventService.Add_ScheduledEventAsync(VALID_IP, VALID_USER, VALID_PASS, myDailyRecurrence); //Output Console.WriteLine("Scheduled event created : Success " + MyRecurrenceEvent.IsSuccess + " device event ID : " + myDailyRecurrence.EventID); //Get the action templates supported by the device GetActionTemplatesResponse aTemplates = await actionService.GetActionTemplatesAsync(VALID_IP, VALID_USER, VALID_PASS); //Create an ActionConfiguration //By passing a ActionTemplate instance, the ActionCofig will directly import the necessary action and associated recipient template parameters //To get a quick overview (text output) of the possible template parameters, run the "Get_ActionTemplates" test method ActionConfiguration BlinkLed = new ActionConfiguration(aTemplates.Templates["com.axis.action.fixed.ledcontrol"]); //Set the action config paramters BlinkLed.Parameters["interval"] = "250"; BlinkLed.Parameters["led"] = "statusled"; BlinkLed.Parameters["color"] = "red,none"; BlinkLed.Parameters["duration"] = "5"; //Add the action config to the device ServiceResponse AddConfigResponse = await actionService.AddActionConfigurationAsync(VALID_IP, VALID_USER, VALID_PASS, BlinkLed); //Output Console.WriteLine("ActionConfig Created : Add new action config : Success " + AddConfigResponse.IsSuccess + " response ID : " + AddConfigResponse.Content + " and config ID : " + BlinkLed.ConfigID); //Get the event instances suppported by the device, this will also contain our previously created daily recurrence event GetEventInstancesResponse eInstances = await eventService.GetEventsInstancesAsync(VALID_IP, VALID_USER, VALID_PASS); ActionRule OnRecurrenceAndStreamAccessBlink = new ActionRule() { Name = "OnDailyRecurrenceAndStreamAccessBlink", Enabled = true, Trigger = eInstances.EventInstances.Find(x => x.TopicExpression == "tns1:UserAlarm/tnsaxis:Recurring/Pulse"), //See GetEventInstances output for the correct event name Configuration = BlinkLed, }; //Set the event trigger properties and parameters OnRecurrenceAndStreamAccessBlink.SetActivationTimeout(10); OnRecurrenceAndStreamAccessBlink.Trigger.Parameters["id"].Value = myDailyRecurrence.EventID; //To get a list of the event parameters look at the Get_eventIntsances Test method output //Create an extra eventtrigger condition, you can get an instance from the eInstances EventTrigger OnLiveStreamAccessCondition = eInstances.EventInstances.Find(x => x.TopicExpression == "tns1:VideoSource/tnsaxis:LiveStreamAccessed"); OnLiveStreamAccessCondition.Parameters["accessed"].Value = "1"; //True - "0" for false //Add the trigger to the action rule conditions OnRecurrenceAndStreamAccessBlink.AddExtraCondition(OnLiveStreamAccessCondition); //Add the rule to the device, either create a new ServiceResponse instance but you can use the AddConfigResponse instance as well AddConfigResponse = await actionService.AddActionRuleAsync(VALID_IP, VALID_USER, VALID_PASS, OnRecurrenceAndStreamAccessBlink); //Output Console.WriteLine("Add new action rule : Success " + AddConfigResponse.IsSuccess + " response ID : " + AddConfigResponse.Content + " and rule ID : " + OnRecurrenceAndStreamAccessBlink.RuleID); //Test conditions Assert.IsTrue(AddConfigResponse.IsSuccess && AddConfigResponse.Content != "0"); }
public async Task Setup_ActionRule_Sample_OnMotionDetected_SendFilesToNetworkShare() { GetActionTemplatesResponse aTemplates = await actionService.GetActionTemplatesAsync(VALID_IP, VALID_USER, VALID_PASS); GetEventInstancesResponse eInstances = await eventService.GetEventsInstancesAsync(VALID_IP, VALID_USER, VALID_PASS); //Create an ActionConfiguration first, //By passing a ActionTemplate instance, the ActionCofig will directly import the necessary action and associated recipient template parameters //To get a quick overview (text output) of the possible template parameters, runt the "Get_ActionTemplates" test method ActionConfiguration sendToNetworkShareConfig = new ActionConfiguration(aTemplates.Templates["com.axis.action.fixed.send_images.networkshare"]); //Set the action configuration parameters, sendToNetworkShareConfig.Parameters["stream_options"] = "resolution=640x480&videocodec=jpeg&camera=1"; sendToNetworkShareConfig.Parameters["pre_duration"] = "3000"; //milliseconds sendToNetworkShareConfig.Parameters["post_duration"] = "3000"; //milliseconds sendToNetworkShareConfig.Parameters["max_images"] = "6"; sendToNetworkShareConfig.Parameters["create_folder"] = ""; sendToNetworkShareConfig.Parameters["filename"] = "image%y-%m-%d_%H-%M-%S-%f.jpg";//Modifiers can be used, see camera help (web-ui \ Events) sendToNetworkShareConfig.Parameters["max_sequence_number"] = "6"; sendToNetworkShareConfig.Parameters["upload_path"] = "VIDEO"; sendToNetworkShareConfig.Parameters["share_id"] = "controlledStorage-AzBy"; //To find the shareid use http://<ip>/axis-cgi/disks/networkshare/list.cgi?schemaversion=1&shareid=all sendToNetworkShareConfig.Parameters["qos"] = ""; ServiceResponse AddConfigResponse = await actionService.AddActionConfigurationAsync(VALID_IP, VALID_USER, VALID_PASS, sendToNetworkShareConfig); Console.WriteLine("Add new action config : Success " + AddConfigResponse.IsSuccess + " response ID : " + AddConfigResponse.Content + " and config ID : " + sendToNetworkShareConfig.ConfigID); //VMD3 - TopicExpression - tns1:RuleEngine/tnsaxis:VMD3/vmd3_video_1 ActionRule newMotionDetectionRule = new ActionRule() { Name = "MD Rule", Enabled = true, Trigger = eInstances.EventInstances.Find(x => x.TopicExpression == "tns1:RuleEngine/tnsaxis:VMD3/vmd3_video_1"), //Run Get_EventInstances TestMethod for list output of all available events Configuration = sendToNetworkShareConfig, }; newMotionDetectionRule.SetActivationTimeout(10); newMotionDetectionRule.Trigger.Parameters["areaid"].Value = "0"; //Is the default value - for quick overview run Test GetEventInstances newMotionDetectionRule.Trigger.Parameters["active"].Value = "1"; //=True, it takes a boolean value but does not work with True / False directly //Add the rule to the device, either create a new ServiceResponse instance but you can use the AddConfigResponse instance as well AddConfigResponse = await actionService.AddActionRuleAsync(VALID_IP, VALID_USER, VALID_PASS, newMotionDetectionRule); Console.WriteLine("Add new action rule : Success " + AddConfigResponse.IsSuccess + " response ID : " + AddConfigResponse.Content + " and rule ID : " + newMotionDetectionRule.RuleID); Assert.IsTrue(AddConfigResponse.IsSuccess && AddConfigResponse.Content != "0"); }
/// <summary> /// Method to retrieve the supported Actions templates of a device /// </summary> /// <param name="IP">The device ip address</param> /// <param name="User">User to authenticate the http request</param> /// <param name="Password">Password to use</param> /// <returns>GetActionTemplatesResponse, GetActionTemplatesResponse.Templates contains a List<ActionTemplate> with the supported Action Templates of the device</returns> /// public async Task <GetActionTemplatesResponse> GetActionTemplatesAsync(string IP, string User, string Password) { GetRecipientTemplatesResponse recTempResp = await this.GetRecipientTemplatesAsync(IP, User, Password); GetActionTemplatesResponse actTempResp = parseGetActionTemplatesResponse(await base.sendRequestAsync(IP, User, Password, @"<act:GetActionTemplates />")); //Bind a recipientTemplate instance to an actionTemplate instance if (recTempResp.IsSuccess) { foreach (KeyValuePair <string, ActionTemplate> ac in actTempResp.Templates) { recTempResp.Templates.TryGetValue(ac.Value.RecipientTemplate, out ac.Value.recipientTemplateObj); } } return(actTempResp); }
public async Task Get_ActionTemplates() { GetActionTemplatesResponse response = await actionService.GetActionTemplatesAsync(VALID_IP, VALID_USER, VALID_PASS); foreach (KeyValuePair <string, ActionTemplate> t in response.Templates) { Console.WriteLine("New template : " + t.ToString()); Console.WriteLine("\t" + "Recipient : " + t.Value.RecipientTemplate); Console.WriteLine("\t" + "Ref token : " + (t.Value.recipientTemplateObj != null ? t.Value.recipientTemplateObj.TemplateToken : "Null")); Console.WriteLine("Template parameters:"); foreach (string s in t.Value.Get_Parameters()) { Console.WriteLine("\t" + s); } } Assert.IsTrue(response.IsSuccess && response.HttpStatusCode == System.Net.HttpStatusCode.OK && !response.SOAPContent.IsEmpty && response.Templates.Count > 0); }
public async Task Setup_ActionRule_Sample_OnTamperingBlinkLed() { GetActionTemplatesResponse aTemplates = await actionService.GetActionTemplatesAsync(VALID_IP, VALID_USER, VALID_PASS); GetEventInstancesResponse eInstances = await eventService.GetEventsInstancesAsync(VALID_IP, VALID_USER, VALID_PASS); //Create an ActionConfiguration first, //By passing a ActionTemplate instance, the ActionCofig will directly import the necessary action and associated recipient template parameters //To get a quick overview (text output) of the possible template parameters, run the "Get_ActionTemplates" test method ActionConfiguration BlinkLed = new ActionConfiguration(aTemplates.Templates["com.axis.action.fixed.ledcontrol"]); BlinkLed.Parameters["interval"] = "250"; BlinkLed.Parameters["led"] = "statusled"; BlinkLed.Parameters["color"] = "red,none"; BlinkLed.Parameters["duration"] = "5"; ServiceResponse AddConfigResponse = await actionService.AddActionConfigurationAsync(VALID_IP, VALID_USER, VALID_PASS, BlinkLed); Console.WriteLine("Add new action config : Success " + AddConfigResponse.IsSuccess + " response ID : " + AddConfigResponse.Content + " and config ID : " + BlinkLed.ConfigID); ActionRule OnTamperingRule = new ActionRule() { Name = "OnTampering", Enabled = true, Trigger = eInstances.EventInstances.Find(x => x.TopicExpression == "tns1:VideoSource/tnsaxis:Tampering"), Configuration = BlinkLed, }; OnTamperingRule.SetActivationTimeout(10); OnTamperingRule.Trigger.Parameters["tampering"].Value = "1"; OnTamperingRule.Trigger.Parameters["channel"].Value = "1"; //Add the rule to the device, either create a new ServiceResponse instance but you can use the AddConfigResponse instance as well AddConfigResponse = await actionService.AddActionRuleAsync(VALID_IP, VALID_USER, VALID_PASS, OnTamperingRule); Console.WriteLine("Add new action rule : Success " + AddConfigResponse.IsSuccess + " response ID : " + AddConfigResponse.Content + " and rule ID : " + OnTamperingRule.RuleID); Assert.IsTrue(AddConfigResponse.IsSuccess && AddConfigResponse.Content != "0"); }
public async Task Setup_ActionRule_Sample_OnPresetReachedBlinkLed() { GetActionTemplatesResponse aTemplates = await actionService.GetActionTemplatesAsync(VALID_IP, VALID_USER, VALID_PASS); GetEventInstancesResponse eInstances = await eventService.GetEventsInstancesAsync(VALID_IP, VALID_USER, VALID_PASS); //Create an ActionConfiguration first, //By passing a ActionTemplate instance, the ActionCofig will directly import the necessary action and associated recipient template parameters //To get a quick overview (text output) of the possible template parameters, runt the "Get_ActionTemplates" test method ActionConfiguration BlinkLed = new ActionConfiguration(aTemplates.Templates["com.axis.action.fixed.ledcontrol"]); BlinkLed.Parameters["interval"] = "250"; BlinkLed.Parameters["led"] = "statusled"; BlinkLed.Parameters["color"] = "red,none"; BlinkLed.Parameters["duration"] = "5"; ServiceResponse AddConfigResponse = await actionService.AddActionConfigurationAsync(VALID_IP, VALID_USER, VALID_PASS, BlinkLed); Console.WriteLine("Add new action config : Success " + AddConfigResponse.IsSuccess + " response ID : " + AddConfigResponse.Content + " and config ID : " + BlinkLed.ConfigID); ActionRule PresetReachedRule = new ActionRule() { Name = "PresetReachedRule", Enabled = true, Trigger = eInstances.EventInstances.Find(x => x.TopicExpression == "tns1:PTZController/tnsaxis:PTZPresets/Channel_1"), //Run Get_EventInstances TestMethod for list output of all available events Configuration = BlinkLed, }; PresetReachedRule.SetActivationTimeout(10); PresetReachedRule.Trigger.Parameters["PresetToken"].Value = "-1"; //See Test GetEventInstances output to see eventInstances and possible parameters PresetReachedRule.Trigger.Parameters["on_preset"].Value = "1"; // Bool value is indicated with 1 / 0 //Add the rule to the device, either create a new ServiceResponse instance but you can use the AddConfigResponse instance as well AddConfigResponse = await actionService.AddActionRuleAsync(VALID_IP, VALID_USER, VALID_PASS, PresetReachedRule); Console.WriteLine("Add new action rule : Success " + AddConfigResponse.IsSuccess + " response ID : " + AddConfigResponse.Content + " and rule ID : " + PresetReachedRule.RuleID); Assert.IsTrue(AddConfigResponse.IsSuccess && AddConfigResponse.Content != "0"); }
public async Task Setup_ActionRule_Sample_OnMyACAPEvent() { GetActionTemplatesResponse aTemplates = await actionService.GetActionTemplatesAsync(VALID_IP, VALID_USER, VALID_PASS); GetEventInstancesResponse eInstances = await eventService.GetEventsInstancesAsync(VALID_IP, VALID_USER, VALID_PASS); //Create an ActionConfiguration first, //By passing a ActionTemplate instance, the ActionCofig will directly import the necessary action and associated recipient template parameters //To get a quick overview (text output) of the possible template parameters, runt the "Get_ActionTemplates" test method ActionConfiguration BlinkLed = new ActionConfiguration(aTemplates.Templates["com.axis.action.fixed.ledcontrol"]); BlinkLed.Parameters["interval"] = "250"; BlinkLed.Parameters["led"] = "statusled"; BlinkLed.Parameters["color"] = "red,none"; BlinkLed.Parameters["duration"] = "5"; ServiceResponse AddConfigResponse = await actionService.AddActionConfigurationAsync(VALID_IP, VALID_USER, VALID_PASS, BlinkLed); Console.WriteLine("Add new action config : Success " + AddConfigResponse.IsSuccess + " response ID : " + AddConfigResponse.Content + " and config ID : " + BlinkLed.ConfigID); //VMD3 - TopicExpression - tns1:RuleEngine/tnsaxis:RuleEngine/VMD3/vmd3_video_1 ActionRule NewAcapTrigger = new ActionRule() { Name = "CX JPG", Enabled = true, Trigger = eInstances.EventInstances.Find(x => x.TopicExpression == "tnsaxis:CameraApplicationPlatform/MyTickerApp"), //correct version tnsaxis:CameraApplicationPlatform/MyTickerApp Configuration = BlinkLed, }; NewAcapTrigger.SetActivationTimeout(0); NewAcapTrigger.Trigger.addMessageContent = false; //Default is True but sometimes must be set on false for certain ACAP events this has to be on a per ACAP base //Add the rule to the device, either create a new ServiceResponse instance but you can use the AddConfigResponse instance as well AddConfigResponse = await actionService.AddActionRuleAsync(VALID_IP, VALID_USER, VALID_PASS, NewAcapTrigger); Console.WriteLine("Add new action rule : Success " + AddConfigResponse.IsSuccess + " response ID : " + AddConfigResponse.Content + " and rule ID : " + NewAcapTrigger.RuleID); Assert.IsTrue(AddConfigResponse.IsSuccess && AddConfigResponse.Content != "0"); }
private GetActionTemplatesResponse parseGetActionTemplatesResponse(ServiceResponse Response) { GetActionTemplatesResponse response = Response.Factory <GetActionTemplatesResponse>(); if (Response.IsSuccess) { try { XElement templates = response.SOAPContent.Element(NS_SOAP_ENV + "Body").Element(NS_ACTION + "GetActionTemplatesResponse").Element(NS_ACTION + "ActionTemplates"); ActionTemplate newTemplate; foreach (XElement el in templates.Elements()) { newTemplate = new ActionTemplate(); newTemplate.TemplateToken = el.Element(NS_ACTION + "TemplateToken").Value; if (el.Element(NS_ACTION + "RecipientTemplate") != null) { newTemplate.RecipientTemplate = el.Element(NS_ACTION + "RecipientTemplate").Value; } foreach (XElement param in el.Element(NS_ACTION + "Parameters").Elements()) { newTemplate.Parameters.Add(param.Attribute("Name").Value, string.Empty); } response.Templates.Add(newTemplate.TemplateToken, newTemplate); } } catch (Exception ex) { response.IsSuccess = false; response.Content = "[ParseActionTemplatesResponse] " + ex.Message; } } return(response); }
public async Task Setup_ActionRule_Sample_OnceEveryHour_And_between9and11_SendPictureToEmail() { //Create the hourly recurrence first and add to device ScheduledEvent myHourlyRecurrence = new ScheduledEvent("HourlyRecurrence", new ICalendar(PulseInterval.HOURLY, 1)); ServiceResponse deviceResponse = await eventService.Add_ScheduledEventAsync(VALID_IP, VALID_USER, VALID_PASS, myHourlyRecurrence); if (deviceResponse.IsSuccess) //Recurrence added { //Create the Weekdays evening schedule annd add to device ScheduledEvent myWeeklyEveningSchedule = new ScheduledEvent("WorkingDays", new ICalendar(new ScheduleTime(17, 30), new ScheduleTime(21), new ScheduleDay[] { ScheduleDay.MO, ScheduleDay.TU, ScheduleDay.WE, ScheduleDay.TH, ScheduleDay.FR })); deviceResponse = await eventService.Add_ScheduledEventAsync(VALID_IP, VALID_USER, VALID_PASS, myWeeklyEveningSchedule); if (deviceResponse.IsSuccess) //Schedule added { //First get the possible templates for the device GetActionTemplatesResponse aTemplates = await actionService.GetActionTemplatesAsync(VALID_IP, VALID_USER, VALID_PASS); if (aTemplates.IsSuccess) { //Now create the action template based on template instance- Send SMTP with picture attached ActionConfiguration SendSMTP = new ActionConfiguration(aTemplates.Templates["com.axis.action.fixed.notification.smtp"]); //Set the action config paramters SendSMTP.Parameters["subject"] = "Week evenings timeLapse"; SendSMTP.Parameters["message"] = "Photo %d"; SendSMTP.Parameters["email_to"] = "*****@*****.**"; SendSMTP.Parameters["email_from"] = "*****@*****.**"; SendSMTP.Parameters["host"] = "smtp-relay.gmail.com"; SendSMTP.Parameters["port"] = "587"; SendSMTP.Parameters["login"] = ""; SendSMTP.Parameters["password"] = ""; //Add the action config to the device deviceResponse = await actionService.AddActionConfigurationAsync(VALID_IP, VALID_USER, VALID_PASS, SendSMTP); if (deviceResponse.IsSuccess) { //Get the event instances suppported by the device, the collection will also contain our previously created schedule and recurrence event this way GetEventInstancesResponse eInstances = await eventService.GetEventsInstancesAsync(VALID_IP, VALID_USER, VALID_PASS); ActionRule OnEveryWeekDayEveningHourSendPicture = new ActionRule() { Name = "OnEveryWeekDayEveningHourSendPicture", Enabled = true, Trigger = eInstances.EventInstances.Find(x => x.TopicExpression == "tns1:UserAlarm/tnsaxis:Recurring/Pulse"), //See GetEventInstances output for the correct event name Configuration = SendSMTP, }; OnEveryWeekDayEveningHourSendPicture.Trigger.Parameters["id"].Value = myHourlyRecurrence.EventID; //Create and add extra condition to Action Rule EventTrigger OnWeekDayEveningSchedule = eInstances.EventInstances.Find(x => x.TopicExpression == "tns1:UserAlarm/tnsaxis:Recurring/Interval"); OnWeekDayEveningSchedule.Parameters["id"].Value = myWeeklyEveningSchedule.EventID; OnWeekDayEveningSchedule.Parameters["active"].Value = "1"; OnEveryWeekDayEveningHourSendPicture.AddExtraCondition(OnWeekDayEveningSchedule); //Create action rule on device deviceResponse = await actionService.AddActionRuleAsync(VALID_IP, VALID_USER, VALID_PASS, OnEveryWeekDayEveningHourSendPicture); Assert.IsTrue(deviceResponse.IsSuccess); } } } } }