protected override void Execute(CodeActivityContext context) { var chID = Channel__ID.Get(context); var readKey = Read_API_Key.Get(context) == null ? "" : "api_key=" + Read_API_Key.Get(context); var chosenFormat = Format.ToString(); var chosenField = (FieldNumber.GetHashCode() + 1).ToString(); var results = Results.Get(context) == 0 ? "" : "&results=" + Results.Get(context).ToString(); var days = Days.Get(context) == 0 ? "" : "&days=" + Days.Get(context).ToString(); var minutes = Minutes.Get(context) == 0 ? "" : "&minutes=" + Minutes.Get(context).ToString(); var start = Start.Get(context) == null ? "" : "&start=" + Start.Get(context); var end = End.Get(context) == null ? "" : "&end=" + End.Get(context); var timezone = Timezone.Get(context) == null ? "" : "&timezone=" + Timezone.Get(context); var offset = Offset.Get(context) == 0 ? "" : "&offset=" + Offset.Get(context).ToString(); var status = Status.Get(context) == true ? "&status=true" : ""; var metadata = Metadata.Get(context) == true ? "&metadata=true" : ""; var location = Location.Get(context) == true ? "&location=true" : ""; var min = Min.Get(context) == 0 ? "" : "&min=" + Min.Get(context).ToString(); var max = Max.Get(context) == 0 ? "" : "&max=" + Max.Get(context).ToString(); var round = Round.Get(context) == 0 ? "" : "&round=" + Round.Get(context).ToString(); var timescale = Timescale.Get(context) == null ? "" : "×cale=" + Timescale.Get(context); var sum = Sum.Get(context) == null ? "" : "&sum=" + Sum.Get(context); var average = Average.Get(context) == null ? "" : "&average=" + Average.Get(context); var median = Median.Get(context) == null ? "" : "&median=" + Median.Get(context); var callback = Callback.Get(context) == null ? "" : "&callback=" + Callback.Get(context); string URL = "https://api.thingspeak.com/channels/" + chID + "/fields/" + chosenField + "." + chosenFormat + "?"; URL = URL + readKey + results + days + minutes + start + end + timezone + offset + status + metadata + location + min + max + round + timescale + sum + average + median + callback; WebRequest wrGETURL = WebRequest.Create(URL); Stream objStream = wrGETURL.GetResponse().GetResponseStream(); StreamReader objReader = new StreamReader(objStream); string sLine = ""; string httpResponse = ""; while (sLine != null) { sLine = objReader.ReadLine(); if (sLine != null) { httpResponse = httpResponse + sLine + "\n"; } } objStream.Close(); //objReader.Close(); Response.Set(context, httpResponse); }
// Module defining this command // Optional custom code for this activity /// <summary> /// Returns a configured instance of System.Management.Automation.PowerShell, pre-populated with the command to run. /// </summary> /// <param name="context">The NativeActivityContext for the currently running activity.</param> /// <returns>A populated instance of System.Management.Automation.PowerShell</returns> /// <remarks>The infrastructure takes responsibility for closing and disposing the PowerShell instance returned.</remarks> protected override ActivityImplementationContext GetPowerShell(NativeActivityContext context) { System.Management.Automation.PowerShell invoker = global::System.Management.Automation.PowerShell.Create(); System.Management.Automation.PowerShell targetCommand = invoker.AddCommand(PSCommandName); // Initialize the arguments if (Start.Expression != null) { targetCommand.AddParameter("Start", Start.Get(context)); } if (End.Expression != null) { targetCommand.AddParameter("End", End.Get(context)); } if (Days.Expression != null) { targetCommand.AddParameter("Days", Days.Get(context)); } if (Hours.Expression != null) { targetCommand.AddParameter("Hours", Hours.Get(context)); } if (Minutes.Expression != null) { targetCommand.AddParameter("Minutes", Minutes.Get(context)); } if (Seconds.Expression != null) { targetCommand.AddParameter("Seconds", Seconds.Get(context)); } return(new ActivityImplementationContext() { PowerShellInstance = invoker }); }
protected override void Execute(CodeActivityContext context) { Int32 day = Day.Get(context); Int32 month = Month.Get(context); Int32 year = Year.Get(context); Int32 hours = Hours.Get(context); Int32 minutes = Minutes.Get(context); Int32 seconds = Seconds.Get(context); Boolean IsLeapYear = DateTime.IsLeapYear(year); if (day < 1 || day > 31) { throw new System.ArgumentOutOfRangeException(nameof(day), "Day out of range (1 - 31"); } if (month < 1 || month > 12) { throw new System.ArgumentOutOfRangeException(nameof(month), "Month out of range (1 - 12)"); } if (hours < 0 || hours > 23) { throw new System.ArgumentOutOfRangeException(nameof(hours), "Hours out of range (0 - 23)"); } if (minutes < 0 || minutes > 59) { throw new System.ArgumentOutOfRangeException(nameof(minutes), "Minutes out of range (0 - 23)"); } if (seconds < 0 || seconds > 59) { throw new System.ArgumentOutOfRangeException(nameof(minutes), "Secondes out of range (0 - 23)"); } if ((month == 2 && day == 29) && !IsLeapYear) { throw new System.ArgumentOutOfRangeException(nameof(year), "year is not a leap year."); } Date.Set(context, new DateTime(year, month, day, hours, minutes, seconds)); }