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);
        }
 /// <summary>
 /// Update species fact fields with latest red list values.
 /// </summary>
 protected override void SetReadListValues()
 {
     if (AllowAutomaticUpdate)
     {
         if (RedListCalculator.IsEvaluationStatusSet)
         {
             Field5.SetValueAutomatic(CriteriaDocumentation);
         }
         else
         {
             // Reset values to nothing.
             Field5.SetValueAutomatic(null);
         }
     }
 }
示例#3
0
        public string ToOldString()
        {
            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") + " ℃";

            content += "\r\n更新时间 : " + CreateTime;

            return(content);
        }
示例#4
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);
        }
示例#5
0
        /// <summary>
        /// Update species fact fields from Dyntaxa.
        /// </summary>
        public void SetTaxonNameValues()
        {
            if (AllowAutomaticUpdate)
            {
                StringBuilder summary = new StringBuilder();
                summary.Append(this.Taxon.ScientificNameAndAuthor);
                summary.Append(".");
                TaxonNameList scientificNames = new TaxonNameList();
                TaxonNameList swedishNames    = new TaxonNameList();
                //TaxonName originalName;
                foreach (TaxonName name in this.Taxon.TaxonNames)
                {
                    if (name.TaxonNameType.Id == 0 &&
                        name.TaxonNameUseType.Id == 0 &&
                        !name.IsRecommended)
                    {
                        scientificNames.Add(name);
                    }

                    if (name.TaxonNameType.Id == 1 &&
                        name.TaxonNameUseType.Id == 0 &&
                        !name.IsRecommended)
                    {
                        swedishNames.Add(name);
                    }
                }

                if (scientificNames.IsNotEmpty())
                {
                    if (scientificNames.Count == 1)
                    {
                        summary.Append(" Synonym: ");
                        summary.Append(scientificNames[0].Name);
                        if (scientificNames[0].Author.IsNotEmpty())
                        {
                            summary.Append(" ");
                            summary.Append(scientificNames[0].Author);
                            summary.Append(".");
                        }
                    }
                    else
                    {
                        summary.Append(" Synonymer: ");
                        for (int i = 0; i < scientificNames.Count - 1; i++)
                        {
                            summary.Append(scientificNames[i].Name);
                            if (scientificNames[i].Author.IsNotEmpty())
                            {
                                summary.Append(" ");
                                summary.Append(scientificNames[i].Author);
                            }
                            if (i < (scientificNames.Count - 2))
                            {
                                summary.Append(", ");
                            }
                        }
                        summary.Append(" och ");
                        summary.Append(scientificNames[scientificNames.Count - 1].Name);
                        if (scientificNames[scientificNames.Count - 1].Author.IsNotEmpty())
                        {
                            summary.Append(" ");
                            summary.Append(scientificNames[scientificNames.Count - 1].Author);
                        }
                        summary.Append(".");
                    }
                }

                if (swedishNames.IsNotEmpty())
                {
                    if (swedishNames.Count == 1)
                    {
                        summary.Append(" Svensk synonym: ");
                        summary.Append(swedishNames[0].Name);
                        summary.Append(".");
                    }
                    else
                    {
                        summary.Append(" Svenska synonymer: ");
                        for (int i = 0; i < swedishNames.Count - 1; i++)
                        {
                            summary.Append(scientificNames[i].Name);
                            if (i < (swedishNames.Count - 2))
                            {
                                summary.Append(", ");
                            }
                        }
                        summary.Append(" och ");
                        summary.Append(swedishNames[swedishNames.Count - 1].Name);
                        summary.Append(".");
                    }
                }

                Field5.SetValueAutomatic(summary.ToString());
            }
        }