protected override void Execute(CodeActivityContext context)
        {
            //Channel Details
            var writeKey = Write_API_Key.Get(context);

            //Field Values
            var f1 = Field1.Get(context) != null ? "&field1=" + Field1.Get(context) : "";
            var f2 = Field2.Get(context) != null ? "&field2=" + Field2.Get(context) : "";
            var f3 = Field3.Get(context) != null ? "&field3=" + Field3.Get(context) : "";
            var f4 = Field4.Get(context) != null ? "&field4=" + Field4.Get(context) : "";
            var f5 = Field5.Get(context) != null ? "&field5=" + Field5.Get(context) : "";
            var f6 = Field6.Get(context) != null ? "&field6=" + Field6.Get(context) : "";
            var f7 = Field7.Get(context) != null ? "&field7=" + Field7.Get(context) : "";
            var f8 = Field8.Get(context) != null ? "&field8=" + Field8.Get(context) : "";

            var chosenFormat = Format.GetHashCode() == 0 ? "" : "." + Format.ToString();

            //Optional Parameters
            var lat        = Lat.Get(context) == 0 ? "" : "&lat=" + Lat.Get(context).ToString();
            var lon        = Long.Get(context) == 0 ? "" : "&long=" + Long.Get(context).ToString();
            var elevation  = Elevation.Get(context) == 0 ? "" : "&elevation=" + Elevation.Get(context).ToString();
            var status     = Status.Get(context) == null ? "" : "&status=" + Status.Get(context);
            var twitter    = Twitter.Get(context) == null ? "" : "&twitter=" + Twitter.Get(context);
            var tweet      = Tweet.Get(context) == null ? "" : "&tweet=" + Tweet.Get(context);
            var created_at = Created_at.Get(context) == null ? "" : "&created_at=" + Created_at.Get(context);


            //Http Request URL
            string URL = "https://api.thingspeak.com/update" + chosenFormat + "?api_key=" + writeKey;

            URL = URL + f1 + f2 + f3 + f4 + f5 + f6 + f7 + f8 + lat + lon + elevation + status + twitter + tweet + created_at;

            //Creating GET Http Request
            WebRequest   wrGETURL  = WebRequest.Create(URL);
            Stream       objStream = wrGETURL.GetResponse().GetResponseStream();
            StreamReader objReader = new StreamReader(objStream);

            //Capturing the response
            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);
        }
예제 #2
0
        public override string ToString()
        {
            string content = "当前状态 : " + FaultTitle + "\r\n太阳能电压 : " + Field1.ToString("0.00") + " V\r\n超容电压 : " + Field2.ToString("0.00") + " V\r\n超容电流 : " + Field3.ToString("0.00") + " A\r\n功率 : " + Field4.ToString("0.00") + " W\r\n温度 : " + Field5.ToString("0.00") + " ℃";

            if (Field6 > 100)
            {
                content += "\r\n更新时间 : " + CreateTime;
            }
            else
            {
                content += "\r\n超容余量 : " + Field6.ToString("0.00") + " %\r\n更新时间 : " + CreateTime;
            }
            return(content);
        }