public List<MeteoAgriNode> GetData(string parameterId, DateTime start, int slots)
        {
            try
             {
            string address = string.Format(Server + "addUPI?function=getdata&session-id={0}&id={1}&df={2}&date={3}&slots={4}&cache={5}&mode={6}",
                                           Uri.EscapeDataString(sessionId),
                                           Uri.EscapeDataString(parameterId),
                                           Uri.EscapeDataString(DateFormat),
                                           Uri.EscapeDataString(start.ToString("yyyyMMddTHH:mm:ss")),
                                           Uri.EscapeDataString(slots.ToString()),
                                           Uri.EscapeDataString(Cache),
                                           Uri.EscapeDataString(Mode));

            string result = wc.DownloadString(address);

            XPathDocument doc = new XPathDocument(new StringReader(result));
            XPathNavigator error, nav = doc.CreateNavigator();

            nav.MoveToRoot();
            nav.MoveToFirstChild();
            if (nav.LocalName != "response") throw new Exception("Expecting 'response' but found '" + nav.LocalName);

            XPathNodeIterator nodeRows, ni = nav.SelectChildren("node", "");
            if (ni.Count < 1)
            {
               string addUPIError = "";
               ni = nav.SelectChildren("error", "");
               if (ni.Count > 0)
               {
                  ni.MoveNext();
                  error = ni.Current;
                  if (error.HasAttributes)
                  {
                     if (error.MoveToAttribute("msg", ""))
                        addUPIError = error.Value;
                  }
               }

               throw new Exception(addUPIError);
            }

            List<MeteoAgriNode> nodesList = new List<MeteoAgriNode>();

            XPathNavigator row, node;
            while (ni.MoveNext())
            {
               node = ni.Current;
               nodeRows = node.SelectChildren("v", "");

               string nodeId = "";
               if (node.HasAttributes)
               {
                  nodeId = node.GetAttribute("id", "");
               }

               if (nodeRows.Count < 1)
               {
                  throw new Exception("No values were found for 'parameter id' = " + parameterId + " [nodeId='" + nodeId + "']");
               }

               MeteoAgriNode newNode = new MeteoAgriNode(nodeId);
               nodesList.Add(newNode);

               while (nodeRows.MoveNext())
               {
                  MeteoAgriData newData = new MeteoAgriData();
                  row = nodeRows.Current;
                  newData.Value = row.Value;
                  if (row.HasAttributes)
                  {
                     newData.Type = row.GetAttribute("type", "");
                     newData.D = row.GetAttribute("d", "");
                     newData.S = row.GetAttribute("s", "");
                     newData.T = row.GetAttribute("t", "");
                  }
                  newNode.Data.Add(newData);
               }
            }

            return nodesList;
             }
             catch (Exception ex)
             {
            exceptionMessage = ex.Message;

            if (Verbose)
            {
               Console.WriteLine("");
               Console.WriteLine("An exception has rised during data recovery. The message returned was:");
               Console.WriteLine(ex.Message);
               Console.WriteLine("");
            }
            return null;
             }
        }
        public void GetData(string parameterId, DateTime start, int slots, TimeSeries ts, int col_index, string dateFormat)
        {
            try
             {
            string address = string.Format(Server + "addUPI?function=getdata&session-id={0}&id={1}&df={2}&date={3}&slots={4}&cache={5}&mode={6}",
                                           Uri.EscapeDataString(sessionId),
                                           Uri.EscapeDataString(parameterId),
                                           Uri.EscapeDataString(DateFormat),
                                           Uri.EscapeDataString(start.ToString("yyyyMMddTHH:mm:ss")),
                                           Uri.EscapeDataString(slots.ToString()),
                                           Uri.EscapeDataString(Cache),
                                           Uri.EscapeDataString(Mode));

            string result = wc.DownloadString(address);

            XPathDocument doc = new XPathDocument(new StringReader(result));
            XPathNavigator error, nav = doc.CreateNavigator();

            nav.MoveToRoot();
            nav.MoveToFirstChild();
            if (nav.LocalName != "response") throw new Exception("Expecting 'response' but found '" + nav.LocalName);

            XPathNodeIterator nodeRows, ni = nav.SelectChildren("node", "");
            if (ni.Count < 1)
            {
               string addUPIError = "";
               ni = nav.SelectChildren("error", "");
               if (ni.Count > 0)
               {
                  ni.MoveNext();
                  error = ni.Current;
                  if (error.HasAttributes)
                  {
                     if (error.MoveToAttribute("msg", ""))
                        addUPIError = error.Value;
                  }
               }

               throw new Exception(addUPIError);
            }

            //List<MeteoAgriNode> nodesList = new List<MeteoAgriNode>();
            MeteoAgriData newData = new MeteoAgriData();
            DateTime instant = DateTime.Now;
            string instant_str;
            bool start_defined = false;

            XPathNavigator row, node;
            while (ni.MoveNext())
            {
               node = ni.Current;
               nodeRows = node.SelectChildren("v", "");

               string nodeId = "";
               if (node.HasAttributes)
               {
                  nodeId = node.GetAttribute("id", "");
               }

               if (nodeRows.Count < 1)
               {
                  throw new Exception("No values were found for 'parameter id' = " + parameterId + " [nodeId='" + nodeId + "']");
               }

               //MeteoAgriNode newNode = new MeteoAgriNode(nodeId);
               //nodesList.Add(newNode);

               while (nodeRows.MoveNext())
               {
                  //MeteoAgriData newData = new MeteoAgriData();

                  row = nodeRows.Current;
                  newData.Value = row.Value;
                  if (row.HasAttributes)
                  {
                     newData.Type = row.GetAttribute("type", "");
                     newData.D = row.GetAttribute("d", "");
                     newData.S = row.GetAttribute("s", "");
                     newData.T = row.GetAttribute("t", "");
                  }

                  int instant_index = -1;

                  if (!start_defined)
                  {
                     instant = DateTime.ParseExact(newData.T, "yyyyMMddTHH:mm:ss", null);
                     instant_str = start.ToString(dateFormat);
                     start_defined = true;

                     if (ts.StartInstant > instant)
                     {
                        ts.StartInstant = instant;
                        instant_index = ts.AddInstant(instant);
                     }
                     else if (ts.StartInstant != instant)
                     {
                        instant_index = ts.Index(instant, Mohid.Core.SearchType.FIND_EXACTLY);
                        if (instant_index == -1)
                           instant_index = ts.AddInstant(instant);
                     }
                     else
                     {
                        instant_index = 0;
                     }

                  }
                  else
                  {
                     if (!start_defined)
                        throw new Exception("The start instant was not found in the imported data.");

                     instant = instant.AddSeconds(double.Parse(newData.T));
                     instant_str = instant.ToString(dateFormat);

                     instant_index = ts.Index(instant, Mohid.Core.SearchType.FIND_EXACTLY);
                     if (instant_index == -1)
                        instant_index = ts.AddInstant(instant);
                  }

                  ts[col_index, instant_index] = newData.Value;
                  //newNode.Data.Add(newData);
               }
            }

            //return nodesList;
             }
             catch (Exception ex)
             {
            exceptionMessage = ex.Message;

            if (Verbose)
            {
               Console.WriteLine("");
               Console.WriteLine("An exception has rised during data recovery. The message returned was:");
               Console.WriteLine(ex.Message);
               Console.WriteLine("");
            }
             }
        }