Ejemplo n.º 1
0
 protected void Page_Load(object sender, EventArgs e)
 {
     try
     {
         //if (this.Request.HttpMethod != "POST")
         //{
         //    this.Response.Write("Request method must be POST");
         //    return;
         //}
         // handle as image
         //string device = this.Request.Form["deviceid"].ToString();
         using (SmartCityEntities ctx = new SmartCityEntities())
         {
             SampledImage sImage = new SampledImage();
             sImage.device_id       = Convert.ToInt32(this.Request.QueryString["device"]);
             sImage.image_timestamp = DateTime.Now;
             System.IO.BufferedStream bufRead    = new System.IO.BufferedStream(this.Request.Files[0].InputStream);
             System.IO.BinaryReader   binaryRead = new System.IO.BinaryReader(bufRead);
             sImage.imagesample = binaryRead.ReadBytes(this.Request.Files[0].ContentLength);
             ctx.SampledImage.Add(sImage);
             ctx.SaveChanges();
         }
         return;
     }
     catch (Exception ex)
     {
         this.Response.Write(ex.ToString());
         return;
     }
 }
Ejemplo n.º 2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (this.Request.HttpMethod != "GET")
                {
                    this.Response.Write("Request method must be GET");
                    return;
                }

                System.Text.StringBuilder bld = new System.Text.StringBuilder();
                bld.AppendLine("<?xml version=\"1.0\" encoding=\"utf-8\" ?> ");
                bld.Append("<Devices>");
                NumberFormatInfo numFormat = new NumberFormatInfo();
                numFormat.NumberDecimalSeparator = ".";
                using (SmartCityEntities ctx = new SmartCityEntities())
                {
                    List <int?> tt = ctx.Sample.Select(d => d.device_id).Distinct().ToList();
                    foreach (int?item in tt)
                    {
                        if (item.HasValue)
                        {
                            bld.Append(String.Format("<Device>{0}</Device>", item.Value));
                        }
                    }
                }
                bld.AppendLine("</Devices>");
                this.Response.Write(bld.ToString());
            }
            catch (Exception ex)
            {
                this.Response.Write(ex.ToString());
                return;
            }
        }
Ejemplo n.º 3
0
 protected void Page_Load(object sender, EventArgs e)
 {
     try
     {
         //if (this.Request.HttpMethod != "POST")
         //{
         //    this.Response.Write("Request method must be POST");
         //    return;
         //}
         // handle as image
         //string device = this.Request.Form["deviceid"].ToString();
         using (SmartCityEntities ctx = new SmartCityEntities())
         {
             SampledImage sImage = new SampledImage();
             sImage.device_id = Convert.ToInt32(this.Request.QueryString["device"]);
             sImage.image_timestamp = DateTime.Now;
             System.IO.BufferedStream bufRead = new System.IO.BufferedStream(this.Request.Files[0].InputStream);
             System.IO.BinaryReader binaryRead = new System.IO.BinaryReader(bufRead);
             sImage.imagesample = binaryRead.ReadBytes(this.Request.Files[0].ContentLength);
             ctx.SampledImage.Add(sImage);
             ctx.SaveChanges();
         }
         return;
     }
     catch (Exception ex)
     {
         this.Response.Write(ex.ToString());
         return;
     }
 }
Ejemplo n.º 4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (this.Request.HttpMethod != "GET")
                {
                    this.Response.Write("Request method must be GET");
                    return;
                }
                this.Response.ContentType = "multipart/form-data";
                using (SmartCityEntities ctx = new SmartCityEntities())
                {
                    int deviceid = Convert.ToInt32(this.Request.QueryString["device"].ToString());

                    SampledImage sImage = ctx.SampledImage.OrderByDescending(pimg => pimg.id_images).FirstOrDefault(devid => devid.device_id == deviceid);
                    if(sImage != null)
                    {
                        this.Response.ContentType = "image/jpg";
                        this.Response.AppendHeader("Content-Disposition", string.Format("attachment; filename={0}.jpg", deviceid));
                        this.Response.OutputStream.Write(sImage.imagesample, 0, sImage.imagesample.Count());
                        return;
                    }
                }

            }
            catch (Exception ex)
            {
                this.Response.Write(ex.ToString());
                return;
            }
        }
Ejemplo n.º 5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (this.Request.HttpMethod != "GET")
                {
                    this.Response.Write("Request method must be GET");
                    return;
                }
                this.Response.ContentType = "multipart/form-data";
                using (SmartCityEntities ctx = new SmartCityEntities())
                {
                    int deviceid = Convert.ToInt32(this.Request.QueryString["device"].ToString());

                    SampledImage sImage = ctx.SampledImage.OrderByDescending(pimg => pimg.id_images).FirstOrDefault(devid => devid.device_id == deviceid);
                    if (sImage != null)
                    {
                        this.Response.ContentType = "image/jpg";
                        this.Response.AppendHeader("Content-Disposition", string.Format("attachment; filename={0}.jpg", deviceid));
                        this.Response.OutputStream.Write(sImage.imagesample, 0, sImage.imagesample.Count());
                        return;
                    }
                }
            }
            catch (Exception ex)
            {
                this.Response.Write(ex.ToString());
                return;
            }
        }
Ejemplo n.º 6
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (this.Request.HttpMethod != "GET")
                {
                    this.Response.Write("Request method must be GET");
                    return;
                }

                System.Text.StringBuilder bld = new System.Text.StringBuilder();
                bld.AppendLine("<?xml version=\"1.0\" encoding=\"utf-8\" ?> ");
                bld.Append("<Devices>");
                NumberFormatInfo numFormat = new NumberFormatInfo();
                numFormat.NumberDecimalSeparator = ".";
                using (SmartCityEntities ctx = new SmartCityEntities())
                {
                    List<int?> tt = ctx.Sample.Select(d => d.device_id).Distinct().ToList();
                    foreach (int? item in tt)
                    {
                        if (item.HasValue)
                        {
                            bld.Append(String.Format("<Device>{0}</Device>", item.Value));
                        }
                    }
                }
                bld.AppendLine("</Devices>");
                this.Response.Write(bld.ToString());

            }
            catch (Exception ex)
            {
                this.Response.Write(ex.ToString());
                return;
            }
        }
Ejemplo n.º 7
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                System.Text.StringBuilder bld = new System.Text.StringBuilder();
                bld.AppendLine("<?xml version=\"1.0\" encoding=\"utf-8\" ?> ");
                bld.AppendLine("<Measurements>");
                NumberFormatInfo numFormat = new NumberFormatInfo();
                numFormat.NumberDecimalSeparator = ".";
                int device = 0;
                using (SmartCityEntities ctx = new SmartCityEntities())
                {

                    List<Sample> samples = ctx.Sample.ToList();
                    if (this.Request.QueryString.AllKeys.Contains("device"))
                    {
                        device = Convert.ToInt32(this.Request.QueryString["device"]);
                        samples = samples.Where(dev => dev.device_id == device).ToList();
                    }
                    samples = samples.OrderBy(dev => dev.id_measurement).Take(1).ToList();
                    foreach (var item in samples)
                    {
                        bld.AppendLine("<Measurement>");
                        bld.AppendLine(String.Format("<id>{0}</id>", item.id_measurement));
                        bld.AppendLine(String.Format("<deviceId>{0}</deviceId>", item.device_id));
                        bld.AppendLine(String.Format("<timestamp>{0}</timestamp>", item.sample_time));
                        bld.AppendLine(String.Format(numFormat, "<longitude>{0}</longitude>", item.lon));
                        bld.AppendLine(String.Format(numFormat, "<latitude>{0}</latitude>", item.lat));
                        bld.AppendLine(String.Format(numFormat, "<humidity>{0}</humidity>", item.humidity));
                        bld.AppendLine(String.Format(numFormat, "<temperature>{0}</temperature>", item.temperature));

                        bld.AppendLine(String.Format(numFormat, "<pressure>{0}</pressure>", item.pressure));
                        bld.AppendLine(String.Format(numFormat, "<sound>{0}</sound>", item.sound));
                        bld.AppendLine(String.Format(numFormat, "<uv>{0}</uv>", item.uv));
                        bld.AppendLine(String.Format(numFormat, "<xacceleration>{0}</xacceleration>", item.xacceleration));
                        bld.AppendLine(String.Format(numFormat, "<yacceleration>{0}</yacceleration>", item.yacceleration));
                        bld.AppendLine(String.Format(numFormat, "<zacceleration>{0}</zacceleration>", item.zacceleration));

                        bld.AppendLine(String.Format(numFormat, "<xrotation>{0}</xrotation>", item.xrotation));
                        bld.AppendLine(String.Format(numFormat, "<yrotation>{0}</yrotation>", item.yrotation));
                        bld.AppendLine(String.Format(numFormat, "<zrotation>{0}</zrotation>", item.zrotation));

                        bld.AppendLine(String.Format(numFormat, "<xmagneticforce>{0}</xmagneticforce>", item.xmagneticforce));
                        bld.AppendLine(String.Format(numFormat, "<ymagneticforce>{0}</ymagneticforce>", item.ymagneticforce));
                        bld.AppendLine(String.Format(numFormat, "<zmagneticforce>{0}</zmagneticforce>", item.zmagneticforce));

                        bld.AppendLine(String.Format(numFormat, "<accelerationmagnitude>{0}</accelerationmagnitude>", item.accelerationmagnitude));

                        bld.AppendLine(String.Format("</Measurement>"));
                    }
                }
                bld.AppendLine("</Measurements>");
                string xmlDat = bld.ToString();
                System.Drawing.Image imgGo = Computed(xmlDat);
                byte[] imgArr = ImageToByte2(imgGo);
                this.Response.ContentType = "image/png";
                this.Response.AppendHeader("Content-Disposition", string.Format("attachment; filename={0}.png", device));
                this.Response.OutputStream.Write(imgArr, 0, imgArr.Count());
                return;
            }
            catch (Exception ex)
            {
                this.Response.Write(ex.ToString());
                return;
            }
        }
Ejemplo n.º 8
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (this.Request.HttpMethod != "POST")
                {
                    this.Response.Write("Request method must be POST");
                    return;
                }

                System.IO.BufferedStream bufStream = new System.IO.BufferedStream(this.Request.InputStream);
                System.IO.StreamReader   read      = new System.IO.StreamReader(bufStream);

                string postData = read.ReadToEnd();
                System.Xml.XmlDocument xmldoc = new System.Xml.XmlDocument();
                xmldoc.LoadXml(postData);

                NumberFormatInfo numFormat = new NumberFormatInfo();
                numFormat.NumberDecimalSeparator = ".";
                using (SmartCityEntities ctx = new SmartCityEntities())
                {
                    Sample newSample = new Sample();
                    newSample.device_id   = Convert.ToInt32(xmldoc["Measurements"]["Measurement"]["deviceId"].InnerText.ToString());
                    newSample.sample_time = DateTime.Now;
                    if (xmldoc["Measurements"]["Measurement"].GetElementsByTagName("latitude").Count > 0)
                    {
                        newSample.lat = Convert.ToDecimal(xmldoc["Measurements"]["Measurement"]["latitude"].InnerText.Replace(',', '.'), numFormat);
                    }
                    if (xmldoc["Measurements"]["Measurement"].GetElementsByTagName("longitude").Count > 0)
                    {
                        newSample.lon = Convert.ToDecimal(xmldoc["Measurements"]["Measurement"]["longitude"].InnerText.Replace(',', '.'), numFormat);
                    }
                    if (xmldoc["Measurements"]["Measurement"].GetElementsByTagName("temperature").Count > 0)
                    {
                        newSample.temperature = Convert.ToDouble(xmldoc["Measurements"]["Measurement"]["temperature"].InnerText.ToString().Replace(',', '.'), numFormat);
                    }
                    if (xmldoc["Measurements"]["Measurement"].GetElementsByTagName("humidity").Count > 0)
                    {
                        newSample.humidity = Convert.ToDouble(xmldoc["Measurements"]["Measurement"]["humidity"].InnerText.ToString().Replace(',', '.'), numFormat);
                    }
                    if (xmldoc["Measurements"]["Measurement"].GetElementsByTagName("pressure").Count > 0)
                    {
                        newSample.pressure = Convert.ToDouble(xmldoc["Measurements"]["Measurement"]["pressure"].InnerText.ToString().Replace(',', '.'), numFormat);
                    }
                    if (xmldoc["Measurements"]["Measurement"].GetElementsByTagName("sound").Count > 0)
                    {
                        newSample.sound = Convert.ToDouble(xmldoc["Measurements"]["Measurement"]["sound"].InnerText.ToString().Replace(',', '.'), numFormat);
                    }
                    if (xmldoc["Measurements"]["Measurement"].GetElementsByTagName("winddirection").Count > 0)
                    {
                        newSample.winddirection = Convert.ToDouble(xmldoc["Measurements"]["Measurement"]["winddirection"].InnerText.ToString().Replace(',', '.'), numFormat);
                    }
                    if (xmldoc["Measurements"]["Measurement"].GetElementsByTagName("uv").Count > 0)
                    {
                        newSample.uv = Convert.ToDouble(xmldoc["Measurements"]["Measurement"]["uv"].InnerText.ToString().Replace(',', '.'), numFormat);
                    }
                    if (xmldoc["Measurements"]["Measurement"].GetElementsByTagName("xacceleration").Count > 0)
                    {
                        newSample.xacceleration = Convert.ToDouble(xmldoc["Measurements"]["Measurement"]["xacceleration"].InnerText.ToString().Replace(',', '.'), numFormat);
                    }
                    if (xmldoc["Measurements"]["Measurement"].GetElementsByTagName("yacceleration").Count > 0)
                    {
                        newSample.yacceleration = Convert.ToDouble(xmldoc["Measurements"]["Measurement"]["yacceleration"].InnerText.ToString().Replace(',', '.'), numFormat);
                    }
                    if (xmldoc["Measurements"]["Measurement"].GetElementsByTagName("zacceleration").Count > 0)
                    {
                        newSample.zacceleration = Convert.ToDouble(xmldoc["Measurements"]["Measurement"]["zacceleration"].InnerText.ToString().Replace(',', '.'), numFormat);
                    }
                    if (xmldoc["Measurements"]["Measurement"].GetElementsByTagName("xrotation").Count > 0)
                    {
                        newSample.xrotation = Convert.ToDouble(xmldoc["Measurements"]["Measurement"]["xrotation"].InnerText.ToString().Replace(',', '.'), numFormat);
                    }
                    if (xmldoc["Measurements"]["Measurement"].GetElementsByTagName("yrotation").Count > 0)
                    {
                        newSample.yrotation = Convert.ToDouble(xmldoc["Measurements"]["Measurement"]["yrotation"].InnerText.ToString().Replace(',', '.'), numFormat);
                    }
                    if (xmldoc["Measurements"]["Measurement"].GetElementsByTagName("zrotation").Count > 0)
                    {
                        newSample.zrotation = Convert.ToDouble(xmldoc["Measurements"]["Measurement"]["zrotation"].InnerText.ToString().Replace(',', '.'), numFormat);
                    }
                    if (xmldoc["Measurements"]["Measurement"].GetElementsByTagName("xmagneticforce").Count > 0)
                    {
                        newSample.xmagneticforce = Convert.ToDouble(xmldoc["Measurements"]["Measurement"]["xmagneticforce"].InnerText.ToString().Replace(',', '.'), numFormat);
                    }
                    if (xmldoc["Measurements"]["Measurement"].GetElementsByTagName("ymagneticforce").Count > 0)
                    {
                        newSample.ymagneticforce = Convert.ToDouble(xmldoc["Measurements"]["Measurement"]["ymagneticforce"].InnerText.ToString().Replace(',', '.'), numFormat);
                    }
                    if (xmldoc["Measurements"]["Measurement"].GetElementsByTagName("zmagneticforce").Count > 0)
                    {
                        newSample.zmagneticforce = Convert.ToDouble(xmldoc["Measurements"]["Measurement"]["zmagneticforce"].InnerText.ToString().Replace(',', '.'), numFormat);
                    }
                    if (xmldoc["Measurements"]["Measurement"].GetElementsByTagName("accelerationmagnitude").Count > 0)
                    {
                        newSample.accelerationmagnitude = Convert.ToDouble(xmldoc["Measurements"]["Measurement"]["accelerationmagnitude"].InnerText.ToString().Replace(',', '.'), numFormat);
                    }
                    if (xmldoc["Measurements"]["Measurement"].GetElementsByTagName("battery").Count > 0)
                    {
                        newSample.battery = Convert.ToDouble(xmldoc["Measurements"]["Measurement"]["battery"].InnerText.ToString().Replace(',', '.'), numFormat);
                    }
                    if (xmldoc["Measurements"]["Measurement"].GetElementsByTagName("wind").Count > 0)
                    {
                        newSample.wind = Convert.ToDouble(xmldoc["Measurements"]["Measurement"]["wind"].InnerText.ToString().Replace(',', '.'), numFormat);
                    }
                    ctx.Sample.Add(newSample);
                    ctx.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                this.Response.Write(ex.ToString());
                return;
            }
        }
Ejemplo n.º 9
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (this.Request.HttpMethod != "POST")
                {
                    this.Response.Write("Request method must be POST");
                    return;
                }

                System.IO.BufferedStream bufStream = new System.IO.BufferedStream(this.Request.InputStream);
                System.IO.StreamReader read = new System.IO.StreamReader(bufStream);

                string postData = read.ReadToEnd();
                System.Xml.XmlDocument xmldoc = new System.Xml.XmlDocument();
                xmldoc.LoadXml(postData);

                NumberFormatInfo numFormat = new NumberFormatInfo();
                numFormat.NumberDecimalSeparator = ".";
                using (SmartCityEntities ctx = new SmartCityEntities())
                {
                    Sample newSample = new Sample();
                    newSample.device_id = Convert.ToInt32(xmldoc["Measurements"]["Measurement"]["deviceId"].InnerText.ToString());
                    newSample.sample_time = DateTime.Now;
                    if (xmldoc["Measurements"]["Measurement"].GetElementsByTagName("latitude").Count > 0)
                    {
                        newSample.lat = Convert.ToDecimal(xmldoc["Measurements"]["Measurement"]["latitude"].InnerText.Replace(',', '.'), numFormat);
                    }
                    if (xmldoc["Measurements"]["Measurement"].GetElementsByTagName("longitude").Count > 0)
                    {
                        newSample.lon = Convert.ToDecimal(xmldoc["Measurements"]["Measurement"]["longitude"].InnerText.Replace(',', '.'), numFormat);
                    }
                    if (xmldoc["Measurements"]["Measurement"].GetElementsByTagName("temperature").Count > 0)
                    {
                        newSample.temperature = Convert.ToDouble(xmldoc["Measurements"]["Measurement"]["temperature"].InnerText.ToString().Replace(',', '.'), numFormat);
                    }
                    if (xmldoc["Measurements"]["Measurement"].GetElementsByTagName("humidity").Count > 0)
                    {
                        newSample.humidity = Convert.ToDouble(xmldoc["Measurements"]["Measurement"]["humidity"].InnerText.ToString().Replace(',', '.'), numFormat);
                    }
                    if (xmldoc["Measurements"]["Measurement"].GetElementsByTagName("pressure").Count > 0)
                    {
                        newSample.pressure = Convert.ToDouble(xmldoc["Measurements"]["Measurement"]["pressure"].InnerText.ToString().Replace(',', '.'), numFormat);
                    }
                    if (xmldoc["Measurements"]["Measurement"].GetElementsByTagName("sound").Count > 0)
                    {
                        newSample.sound = Convert.ToDouble(xmldoc["Measurements"]["Measurement"]["sound"].InnerText.ToString().Replace(',', '.'), numFormat);
                    }
                    if (xmldoc["Measurements"]["Measurement"].GetElementsByTagName("winddirection").Count > 0)
                    {
                        newSample.winddirection = Convert.ToDouble(xmldoc["Measurements"]["Measurement"]["winddirection"].InnerText.ToString().Replace(',', '.'), numFormat);
                    }
                    if (xmldoc["Measurements"]["Measurement"].GetElementsByTagName("uv").Count > 0)
                    {
                        newSample.uv = Convert.ToDouble(xmldoc["Measurements"]["Measurement"]["uv"].InnerText.ToString().Replace(',', '.'), numFormat);
                    }
                    if (xmldoc["Measurements"]["Measurement"].GetElementsByTagName("xacceleration").Count > 0)
                    {
                        newSample.xacceleration = Convert.ToDouble(xmldoc["Measurements"]["Measurement"]["xacceleration"].InnerText.ToString().Replace(',', '.'), numFormat);
                    }
                    if (xmldoc["Measurements"]["Measurement"].GetElementsByTagName("yacceleration").Count > 0)
                    {
                        newSample.yacceleration = Convert.ToDouble(xmldoc["Measurements"]["Measurement"]["yacceleration"].InnerText.ToString().Replace(',', '.'), numFormat);
                    }
                    if (xmldoc["Measurements"]["Measurement"].GetElementsByTagName("zacceleration").Count > 0)
                    {
                        newSample.zacceleration = Convert.ToDouble(xmldoc["Measurements"]["Measurement"]["zacceleration"].InnerText.ToString().Replace(',', '.'), numFormat);
                    }
                    if (xmldoc["Measurements"]["Measurement"].GetElementsByTagName("xrotation").Count > 0)
                    {
                        newSample.xrotation = Convert.ToDouble(xmldoc["Measurements"]["Measurement"]["xrotation"].InnerText.ToString().Replace(',', '.'), numFormat);
                    }
                    if (xmldoc["Measurements"]["Measurement"].GetElementsByTagName("yrotation").Count > 0)
                    {
                        newSample.yrotation = Convert.ToDouble(xmldoc["Measurements"]["Measurement"]["yrotation"].InnerText.ToString().Replace(',', '.'), numFormat);
                    }
                    if (xmldoc["Measurements"]["Measurement"].GetElementsByTagName("zrotation").Count > 0)
                    {
                        newSample.zrotation = Convert.ToDouble(xmldoc["Measurements"]["Measurement"]["zrotation"].InnerText.ToString().Replace(',', '.'), numFormat);
                    }
                    if (xmldoc["Measurements"]["Measurement"].GetElementsByTagName("xmagneticforce").Count > 0)
                    {
                        newSample.xmagneticforce = Convert.ToDouble(xmldoc["Measurements"]["Measurement"]["xmagneticforce"].InnerText.ToString().Replace(',', '.'), numFormat);
                    }
                    if (xmldoc["Measurements"]["Measurement"].GetElementsByTagName("ymagneticforce").Count > 0)
                    {
                        newSample.ymagneticforce = Convert.ToDouble(xmldoc["Measurements"]["Measurement"]["ymagneticforce"].InnerText.ToString().Replace(',', '.'), numFormat);
                    }
                    if (xmldoc["Measurements"]["Measurement"].GetElementsByTagName("zmagneticforce").Count > 0)
                    {
                        newSample.zmagneticforce = Convert.ToDouble(xmldoc["Measurements"]["Measurement"]["zmagneticforce"].InnerText.ToString().Replace(',', '.'), numFormat);
                    }
                    if (xmldoc["Measurements"]["Measurement"].GetElementsByTagName("accelerationmagnitude").Count > 0)
                    {
                        newSample.accelerationmagnitude = Convert.ToDouble(xmldoc["Measurements"]["Measurement"]["accelerationmagnitude"].InnerText.ToString().Replace(',', '.'), numFormat);
                    }
                    if (xmldoc["Measurements"]["Measurement"].GetElementsByTagName("battery").Count > 0)
                    {
                        newSample.battery = Convert.ToDouble(xmldoc["Measurements"]["Measurement"]["battery"].InnerText.ToString().Replace(',', '.'), numFormat);
                    }
                    if (xmldoc["Measurements"]["Measurement"].GetElementsByTagName("wind").Count > 0)
                    {
                        newSample.wind = Convert.ToDouble(xmldoc["Measurements"]["Measurement"]["wind"].InnerText.ToString().Replace(',', '.'), numFormat);
                    }
                    ctx.Sample.Add(newSample);
                    ctx.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                this.Response.Write(ex.ToString());
                return;
            }
        }
Ejemplo n.º 10
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //string response = System.IO.File.ReadAllText(MapPath("TestXml.xml"));
            //this.Page.Request.QueryString;
            //this.Response.Write(response);
            try
            {
                if (this.Request.HttpMethod != "GET")
                {
                    this.Response.Write("Request method must be GET");
                    return;
                }
                System.Text.StringBuilder bld = new System.Text.StringBuilder();
                bld.AppendLine("<?xml version=\"1.0\" encoding=\"utf-8\" ?> ");
                bld.AppendLine("<Measurements>");
                NumberFormatInfo numFormat = new NumberFormatInfo();
                numFormat.NumberDecimalSeparator = ".";
                using (SmartCityEntities ctx = new SmartCityEntities())
                {
                    List <Sample> samples = ctx.Sample.ToList();
                    if (this.Request.QueryString.AllKeys.Contains("device"))
                    {
                        int device = Convert.ToInt32(this.Request.QueryString["device"]);
                        samples = samples.Where(dev => dev.device_id == device).ToList();
                    }
                    bool isonlylast = false;
                    if (this.Request.QueryString.AllKeys.Contains("onlylast") & this.Request.QueryString["onlylast"] == "true")
                    {
                        isonlylast = true;
                        samples    = samples.OrderBy(dev => dev.id_measurement).Take(1).ToList();
                    }
                    if (this.Request.QueryString.AllKeys.Contains("lat") & this.Request.QueryString.AllKeys.Contains("lon") & this.Request.QueryString.AllKeys.Contains("radius"))
                    {
                        double  lat    = Convert.ToDouble(this.Request.QueryString["lat"].Replace(',', '.'), numFormat);
                        double  lon    = Convert.ToDouble(this.Request.QueryString["lon"].Replace(',', '.'), numFormat);
                        double  radius = Convert.ToDouble(this.Request.QueryString["radius"].Replace(',', '.'), numFormat);
                        double  latOff = 0.0;
                        double  lonOff = 0.0;
                        decimal latd   = (decimal)lat;
                        decimal lond   = (decimal)lon;
                        LatOffset(radius, lat, lon, out latOff, out lonOff);
                        samples = samples.Where(dev => dev.lat > (latd - (decimal)latOff) & dev.lat <(latd + (decimal)latOff)& dev.lon> (lond - (decimal)lonOff) & dev.lon < (lond + (decimal)lonOff)).ToList();
                    }
                    foreach (var item in samples)
                    {
                        bld.AppendLine("<Measurement>");
                        bld.AppendLine(String.Format("<id>{0}</id>", item.id_measurement));
                        bld.AppendLine(String.Format("<deviceId>{0}</deviceId>", item.device_id));
                        bld.AppendLine(String.Format("<timestamp>{0}</timestamp>", item.sample_time));
                        bld.AppendLine(String.Format(numFormat, "<longitude>{0}</longitude>", item.lon));
                        bld.AppendLine(String.Format(numFormat, "<latitude>{0}</latitude>", item.lat));

                        //bool humset = false;
                        //bool tempset = false;
                        //bool presset = false;
                        //if (item.lat.HasValue & item.lon.HasValue & isonlylast)
                        //{
                        //    string lat = item.lat.ToString().Replace(',', '.');
                        //    string lon = item.lon.ToString().Replace(',', '.');
                        //    CityCountry cc = ReverseGeocoding.GetCityCountry(lat, lon);
                        //    bld.AppendLine(String.Format("<Country>{0}</Country>", cc.countryName));
                        //    bld.AppendLine(String.Format("<City>{0}</City>", cc.adminName1));

                        //    WeatherReading ww = WorldWeather.getWeatherAt(lat, lon);
                        //    bld.AppendLine(String.Format("<Humidity>{0}</Humidity>", ww.humidity.Replace(',', '.')));
                        //    bld.AppendLine(String.Format("<Temperature>{0}</Temperature>", ww.tempC.Replace(',', '.')));
                        //    bld.AppendLine(String.Format("<Windspeed>{0}</Windspeed>", ww.windspeed.Replace(',', '.')));
                        //    bld.AppendLine(String.Format("<Winddirection>{0}</Winddirection>", ww.winddirection.Replace(',', '.')));
                        //    bld.AppendLine(String.Format("<Visibility>{0}</Visibility>", ww.visibility.Replace(',', '.')));
                        //    bld.AppendLine(String.Format("<Pressure>{0}</Pressure>", ww.pressure.Replace(',', '.')));
                        //    bld.AppendLine(String.Format("<Cloudcover>{0}</Cloudcover>", ww.cloudcover.Replace(',', '.')));
                        //}
                        //else
                        //{
                        bld.AppendLine(String.Format(numFormat, "<humidity>{0}</humidity>", item.humidity));
                        bld.AppendLine(String.Format(numFormat, "<temperature>{0}</temperature>", item.temperature));
                        bld.AppendLine(String.Format(numFormat, "<pressure>{0}</pressure>", item.pressure));
                        //}
                        bld.AppendLine(String.Format(numFormat, "<sound>{0}</sound>", item.sound));
                        bld.AppendLine(String.Format(numFormat, "<uv>{0}</uv>", item.uv));
                        bld.AppendLine(String.Format(numFormat, "<xacceleration>{0}</xacceleration>", item.xacceleration));
                        bld.AppendLine(String.Format(numFormat, "<yacceleration>{0}</yacceleration>", item.yacceleration));
                        bld.AppendLine(String.Format(numFormat, "<zacceleration>{0}</zacceleration>", item.zacceleration));

                        bld.AppendLine(String.Format(numFormat, "<xrotation>{0}</xrotation>", item.xrotation));
                        bld.AppendLine(String.Format(numFormat, "<yrotation>{0}</yrotation>", item.yrotation));
                        bld.AppendLine(String.Format(numFormat, "<zrotation>{0}</zrotation>", item.zrotation));

                        bld.AppendLine(String.Format(numFormat, "<xmagneticforce>{0}</xmagneticforce>", item.xmagneticforce));
                        bld.AppendLine(String.Format(numFormat, "<ymagneticforce>{0}</ymagneticforce>", item.ymagneticforce));
                        bld.AppendLine(String.Format(numFormat, "<zmagneticforce>{0}</zmagneticforce>", item.zmagneticforce));

                        bld.AppendLine(String.Format(numFormat, "<accelerationmagnitude>{0}</accelerationmagnitude>", item.accelerationmagnitude));

                        //bld.AppendLine(String.Format("<longitude>{0}</longitude>", item.lon.ToString().Replace(',', '.')));
                        //bld.AppendLine(String.Format("<latitude>{0}</latitude>", item.lat.ToString().Replace(',', '.')));
                        //bld.AppendLine(String.Format("<humidity>{0}</humidity>", item.humidity.ToString().Replace(',', '.')));
                        //bld.AppendLine(String.Format("<temperature>{0}</temperature>", item.temperature.ToString().Replace(',', '.')));
                        bld.AppendLine(String.Format("</Measurement>"));
                    }
                }
                bld.AppendLine("</Measurements>");
                this.Response.Write(bld.ToString());
            }
            catch (Exception ex)
            {
                this.Response.Write(ex.ToString());
                return;
            }
        }
Ejemplo n.º 11
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //string response = System.IO.File.ReadAllText(MapPath("TestXml.xml"));
            //this.Page.Request.QueryString;
            //this.Response.Write(response);
            try
            {
                if (this.Request.HttpMethod != "GET")
                {
                    this.Response.Write("Request method must be GET");
                    return;
                }
                System.Text.StringBuilder bld = new System.Text.StringBuilder();
                bld.AppendLine("<?xml version=\"1.0\" encoding=\"utf-8\" ?> ");
                bld.AppendLine("<Measurements>");
                NumberFormatInfo numFormat = new NumberFormatInfo();
                numFormat.NumberDecimalSeparator = ".";
                using (SmartCityEntities ctx = new SmartCityEntities())
                {
                    List<Sample> samples = ctx.Sample.ToList();
                    if (this.Request.QueryString.AllKeys.Contains("device"))
                    {
                        int device = Convert.ToInt32(this.Request.QueryString["device"]);
                        samples = samples.Where(dev => dev.device_id == device).ToList();
                    }
                    bool isonlylast = false;
                    if (this.Request.QueryString.AllKeys.Contains("onlylast") & this.Request.QueryString["onlylast"] == "true")
                    {
                        isonlylast = true;
                        samples = samples.OrderBy(dev => dev.id_measurement).Take(1).ToList();
                    }
                    if (this.Request.QueryString.AllKeys.Contains("lat") & this.Request.QueryString.AllKeys.Contains("lon") & this.Request.QueryString.AllKeys.Contains("radius"))
                    {
                        double lat = Convert.ToDouble(this.Request.QueryString["lat"].Replace(',','.'), numFormat);
                        double lon = Convert.ToDouble(this.Request.QueryString["lon"].Replace(',','.'), numFormat);
                        double radius = Convert.ToDouble(this.Request.QueryString["radius"].Replace(',','.'), numFormat);
                        double latOff = 0.0;
                        double lonOff = 0.0;
                        decimal latd = (decimal)lat;
                        decimal lond = (decimal)lon;
                        LatOffset(radius, lat, lon, out latOff, out lonOff);
                        samples = samples.Where(dev => dev.lat > (latd - (decimal)latOff) & dev.lat < (latd + (decimal)latOff) & dev.lon > (lond - (decimal)lonOff) & dev.lon < (lond + (decimal)lonOff)).ToList();
                    }
                    foreach (var item in samples)
                    {
                        bld.AppendLine("<Measurement>");
                        bld.AppendLine(String.Format("<id>{0}</id>", item.id_measurement));
                        bld.AppendLine(String.Format("<deviceId>{0}</deviceId>", item.device_id));
                        bld.AppendLine(String.Format("<timestamp>{0}</timestamp>", item.sample_time));
                        bld.AppendLine(String.Format(numFormat, "<longitude>{0}</longitude>", item.lon));
                        bld.AppendLine(String.Format(numFormat, "<latitude>{0}</latitude>", item.lat));

                        //bool humset = false;
                        //bool tempset = false;
                        //bool presset = false;
                        //if (item.lat.HasValue & item.lon.HasValue & isonlylast)
                        //{
                        //    string lat = item.lat.ToString().Replace(',', '.');
                        //    string lon = item.lon.ToString().Replace(',', '.');
                        //    CityCountry cc = ReverseGeocoding.GetCityCountry(lat, lon);
                        //    bld.AppendLine(String.Format("<Country>{0}</Country>", cc.countryName));
                        //    bld.AppendLine(String.Format("<City>{0}</City>", cc.adminName1));

                        //    WeatherReading ww = WorldWeather.getWeatherAt(lat, lon);
                        //    bld.AppendLine(String.Format("<Humidity>{0}</Humidity>", ww.humidity.Replace(',', '.')));
                        //    bld.AppendLine(String.Format("<Temperature>{0}</Temperature>", ww.tempC.Replace(',', '.')));
                        //    bld.AppendLine(String.Format("<Windspeed>{0}</Windspeed>", ww.windspeed.Replace(',', '.')));
                        //    bld.AppendLine(String.Format("<Winddirection>{0}</Winddirection>", ww.winddirection.Replace(',', '.')));
                        //    bld.AppendLine(String.Format("<Visibility>{0}</Visibility>", ww.visibility.Replace(',', '.')));
                        //    bld.AppendLine(String.Format("<Pressure>{0}</Pressure>", ww.pressure.Replace(',', '.')));
                        //    bld.AppendLine(String.Format("<Cloudcover>{0}</Cloudcover>", ww.cloudcover.Replace(',', '.')));
                        //}
                        //else
                        //{
                            bld.AppendLine(String.Format(numFormat, "<humidity>{0}</humidity>", item.humidity));
                            bld.AppendLine(String.Format(numFormat, "<temperature>{0}</temperature>", item.temperature));
                            bld.AppendLine(String.Format(numFormat, "<pressure>{0}</pressure>", item.pressure));
                        //}
                        bld.AppendLine(String.Format(numFormat, "<sound>{0}</sound>", item.sound));
                        bld.AppendLine(String.Format(numFormat, "<uv>{0}</uv>", item.uv));
                        bld.AppendLine(String.Format(numFormat, "<xacceleration>{0}</xacceleration>", item.xacceleration));
                        bld.AppendLine(String.Format(numFormat, "<yacceleration>{0}</yacceleration>", item.yacceleration));
                        bld.AppendLine(String.Format(numFormat, "<zacceleration>{0}</zacceleration>", item.zacceleration));

                        bld.AppendLine(String.Format(numFormat, "<xrotation>{0}</xrotation>", item.xrotation));
                        bld.AppendLine(String.Format(numFormat, "<yrotation>{0}</yrotation>", item.yrotation));
                        bld.AppendLine(String.Format(numFormat, "<zrotation>{0}</zrotation>", item.zrotation));

                        bld.AppendLine(String.Format(numFormat, "<xmagneticforce>{0}</xmagneticforce>", item.xmagneticforce));
                        bld.AppendLine(String.Format(numFormat, "<ymagneticforce>{0}</ymagneticforce>", item.ymagneticforce));
                        bld.AppendLine(String.Format(numFormat, "<zmagneticforce>{0}</zmagneticforce>", item.zmagneticforce));

                        bld.AppendLine(String.Format(numFormat, "<accelerationmagnitude>{0}</accelerationmagnitude>", item.accelerationmagnitude));

                        //bld.AppendLine(String.Format("<longitude>{0}</longitude>", item.lon.ToString().Replace(',', '.')));
                        //bld.AppendLine(String.Format("<latitude>{0}</latitude>", item.lat.ToString().Replace(',', '.')));
                        //bld.AppendLine(String.Format("<humidity>{0}</humidity>", item.humidity.ToString().Replace(',', '.')));
                        //bld.AppendLine(String.Format("<temperature>{0}</temperature>", item.temperature.ToString().Replace(',', '.')));
                        bld.AppendLine(String.Format("</Measurement>"));
                    }
                }
                bld.AppendLine("</Measurements>");
                this.Response.Write(bld.ToString());
            }
            catch (Exception ex)
            {
                this.Response.Write(ex.ToString());
                return;
            }
        }
Ejemplo n.º 12
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                System.Text.StringBuilder bld = new System.Text.StringBuilder();
                bld.AppendLine("<?xml version=\"1.0\" encoding=\"utf-8\" ?> ");
                bld.AppendLine("<Measurements>");
                NumberFormatInfo numFormat = new NumberFormatInfo();
                numFormat.NumberDecimalSeparator = ".";
                int device = 0;
                using (SmartCityEntities ctx = new SmartCityEntities())
                {
                    List <Sample> samples = ctx.Sample.ToList();
                    if (this.Request.QueryString.AllKeys.Contains("device"))
                    {
                        device  = Convert.ToInt32(this.Request.QueryString["device"]);
                        samples = samples.Where(dev => dev.device_id == device).ToList();
                    }
                    samples = samples.OrderBy(dev => dev.id_measurement).Take(1).ToList();
                    foreach (var item in samples)
                    {
                        bld.AppendLine("<Measurement>");
                        bld.AppendLine(String.Format("<id>{0}</id>", item.id_measurement));
                        bld.AppendLine(String.Format("<deviceId>{0}</deviceId>", item.device_id));
                        bld.AppendLine(String.Format("<timestamp>{0}</timestamp>", item.sample_time));
                        bld.AppendLine(String.Format(numFormat, "<longitude>{0}</longitude>", item.lon));
                        bld.AppendLine(String.Format(numFormat, "<latitude>{0}</latitude>", item.lat));
                        bld.AppendLine(String.Format(numFormat, "<humidity>{0}</humidity>", item.humidity));
                        bld.AppendLine(String.Format(numFormat, "<temperature>{0}</temperature>", item.temperature));

                        bld.AppendLine(String.Format(numFormat, "<pressure>{0}</pressure>", item.pressure));
                        bld.AppendLine(String.Format(numFormat, "<sound>{0}</sound>", item.sound));
                        bld.AppendLine(String.Format(numFormat, "<uv>{0}</uv>", item.uv));
                        bld.AppendLine(String.Format(numFormat, "<xacceleration>{0}</xacceleration>", item.xacceleration));
                        bld.AppendLine(String.Format(numFormat, "<yacceleration>{0}</yacceleration>", item.yacceleration));
                        bld.AppendLine(String.Format(numFormat, "<zacceleration>{0}</zacceleration>", item.zacceleration));

                        bld.AppendLine(String.Format(numFormat, "<xrotation>{0}</xrotation>", item.xrotation));
                        bld.AppendLine(String.Format(numFormat, "<yrotation>{0}</yrotation>", item.yrotation));
                        bld.AppendLine(String.Format(numFormat, "<zrotation>{0}</zrotation>", item.zrotation));

                        bld.AppendLine(String.Format(numFormat, "<xmagneticforce>{0}</xmagneticforce>", item.xmagneticforce));
                        bld.AppendLine(String.Format(numFormat, "<ymagneticforce>{0}</ymagneticforce>", item.ymagneticforce));
                        bld.AppendLine(String.Format(numFormat, "<zmagneticforce>{0}</zmagneticforce>", item.zmagneticforce));

                        bld.AppendLine(String.Format(numFormat, "<accelerationmagnitude>{0}</accelerationmagnitude>", item.accelerationmagnitude));

                        bld.AppendLine(String.Format("</Measurement>"));
                    }
                }
                bld.AppendLine("</Measurements>");
                string xmlDat = bld.ToString();
                System.Drawing.Image imgGo = Computed(xmlDat);
                byte[] imgArr = ImageToByte2(imgGo);
                this.Response.ContentType = "image/png";
                this.Response.AppendHeader("Content-Disposition", string.Format("attachment; filename={0}.png", device));
                this.Response.OutputStream.Write(imgArr, 0, imgArr.Count());
                return;
            }
            catch (Exception ex)
            {
                this.Response.Write(ex.ToString());
                return;
            }
        }