Пример #1
0
        public ActionResult GetEnhancedDetails(int id)
        {
            DEv1_0 de = dbDal.ReadDE(id);

            ContentObject co = de.ContentObjects[0];

            EMLCContent evtHelper = (EMLCContent)DEUtilities.FeedContent(de, co);
            string      addr      = DEUtilities.ReverseGeocodeLookup(evtHelper.Location().Latitude.ToString(), evtHelper.Location().Longitude.ToString());

            DE_Details_ViewModel vm = new DE_Details_ViewModel(evtHelper, addr, de.DateTimeSent);

            // return partial view, not full view
            return(PartialView("DE_View_partial", vm));
        }
Пример #2
0
        /// <summary>
        /// Base method, writes to stream
        /// </summary>
        /// <param name="type">type of object to write</param>
        /// <param name="value">object to write</param>
        /// <param name="writeStream">stream to write to</param>
        /// <param name="content">stuff</param>
        public override void WriteToStream(Type type, object value, Stream writeStream, HttpContent content)
        {
            DEv1_0 de  = value as DEv1_0;
            Event  evt = null;

            try
            {
                if (de != null)
                {
                    ContentObject co = de.ContentObjects[0];

                    EMLCContent evtHelper = (EMLCContent)DEUtilities.FeedContent(de, co);

                    var settings = new XmlWriterSettings();
                    settings.Indent             = false;
                    settings.OmitXmlDeclaration = false;

                    XmlWriter writer = XmlWriter.Create(writeStream, settings);
                    writer.WriteStartElement("html"); //html
                    writer.WriteStartElement("head"); //head
                    writer.WriteStartElement("meta");
                    writer.WriteAttributeString("charset", "UTF-8");

                    // We're returning some DE-related HTML, so set up the page to refresh every 5 seconds
                    // This is not a good way to do it long term.
                    //writer.WriteAttributeString("http-equiv", "refresh");
                    //string contentValue = $"5; URL={HttpContext.Current.Request.Url}";
                    //writer.WriteAttributeString("content", contentValue);

                    writer.WriteEndElement();         //meta
                    writer.WriteElementString("title", "TEST");
                    writer.WriteEndElement();         //head

                    writer.WriteStartElement("body"); //start body

                    writer.WriteStartElement("div");  //start div 1
                    writer.WriteAttributeString("style", "background-color:black;color:white;padding:5px;");

                    #region table
                    writer.WriteStartElement("table"); //start table
                    writer.WriteAttributeString("style", "color:white;");
                    #region row 1
                    writer.WriteStartElement("tr");  //start row

                    writer.WriteStartElement("td");  //start cell
                    writer.WriteAttributeString("style", "padding:15px;");
                    writer.WriteStartElement("img"); //start image
                    writer.WriteAttributeString("src", evtHelper.IconURL());
                    writer.WriteAttributeString("alt", evtHelper.FriendlyName());
                    writer.WriteEndElement();       //end image
                    writer.WriteEndElement();       //end cell

                    writer.WriteStartElement("td"); //start cell
                    writer.WriteElementString("h1", evtHelper.Title());
                    writer.WriteEndElement();       //end cell
                    writer.WriteEndElement();       //end row
                    #endregion row 1

                    #region row 2
                    writer.WriteStartElement("tr"); //start row
                    writer.WriteStartElement("td"); //start cell

                    writer.WriteAttributeString("colspan", "2");
                    writer.WriteValue(evtHelper.FriendlyName());

                    writer.WriteEndElement(); //end cell
                    writer.WriteEndElement(); //end row
                    #endregion row 2
                    writer.WriteEndElement(); //end table
                    #endregion table


                    writer.WriteEndElement(); //end div 1

                    // Loop through each kind of details and append HTML for each one
                    if (evtHelper.ResourceDetails != null)
                    {
                        foreach (ResourceDetail rd in evtHelper.ResourceDetails)
                        {
                            string sColor = "color:black";

                            writer.WriteStartElement("p"); //start paragraph
                            writer.WriteAttributeString("style", sColor);

                            if (rd.Status.PrimaryStatus == ResourcePrimaryStatusCodeList.Available)
                            {
                                sColor = "color:green";
                            }
                            else if (rd.Status.PrimaryStatus == ResourcePrimaryStatusCodeList.ConditionallyAvailable)
                            {
                                sColor = "color:yellow";
                            }
                            else if (rd.Status.PrimaryStatus == ResourcePrimaryStatusCodeList.NotAvailable)
                            {
                                sColor = "color:red";
                            }

                            writer.WriteElementString("p", "Latitude/Longitude: " + evtHelper.Location().Latitude.ToString() + ", " + evtHelper.Location().Longitude.ToString());
                            //writer.WriteElementString("p", "Lon: " + evtHelper.Location().Latitude.ToString());
                            string addr = DEUtilities.ReverseGeocodeLookup(evtHelper.Location().Latitude.ToString(), evtHelper.Location().Longitude.ToString());

                            if (string.IsNullOrWhiteSpace(addr))
                            {
                                addr = "Not Found";
                            }

                            writer.WriteElementString("p", "Address: " + addr); //+ some reverse lookup;

                            writer.WriteRaw("Primary Status: <span style=\"font-weight:bold;" + sColor + "\"> " + rd.Status.PrimaryStatus.ToString() + "</ span>" + " ");
                            writer.WriteEndElement(); //end paragraph
                        }
                    }

                    if (evtHelper.IncidentDetails != null)
                    {
                        foreach (IncidentDetail id in evtHelper.IncidentDetails)
                        {
                            string sColor = "color:black";

                            writer.WriteStartElement("p"); //start paragraph
                            writer.WriteAttributeString("style", sColor);
                            if (id.Status.PrimaryStatus == IncidentPrimaryStatusCodeList.Active)
                            {
                                sColor = "color:green";
                            }
                            else if (id.Status.PrimaryStatus == IncidentPrimaryStatusCodeList.Pending)
                            {
                                sColor = "color:orange";
                            }

                            string addr = "Not Found";
                            writer.WriteElementString("p", "Latitude/Longitude: " + evtHelper.Location().Latitude.ToString() + ", " + evtHelper.Location().Longitude.ToString());

                            if (id.LocationExtension != null && id.LocationExtension.Address != null)
                            {
                                addr = id.LocationExtension.Address.ToString();
                            }
                            else
                            {
                                //writer.WriteElementString("p", "Lon: " + evtHelper.Location().Latitude.ToString());
                                addr = DEUtilities.ReverseGeocodeLookup(evtHelper.Location().Latitude.ToString(), evtHelper.Location().Longitude.ToString());

                                if (string.IsNullOrWhiteSpace(addr))
                                {
                                    addr = "Not Found";
                                }
                            }
                            writer.WriteElementString("p", "Address: " + addr); //+ some reverse lookup;

                            writer.WriteRaw("Primary Status: <span style=\"font-weight:bold;" + sColor + "\"> " + id.Status.PrimaryStatus.ToString() + "</ span>" + " ");
                            writer.WriteEndElement(); //end paragraph
                        }
                    }

                    if (evtHelper.SensorDetails != null)
                    {
                        foreach (SensorDetail sensor in evtHelper.SensorDetails)
                        {
                            string sColor = "color:black;";

                            writer.WriteStartElement("p"); //start paragraph
                            writer.WriteAttributeString("style", sColor);
                            writer.WriteRaw("Sensor ID: " + sensor.ID + " ");
                            writer.WriteEndElement();      //end paragraph

                            writer.WriteStartElement("p"); //start paragraph
                            writer.WriteAttributeString("style", sColor);

                            if (sensor.Status == SensorStatusCodeList.Normal)
                            {
                                sColor = "color:green";
                            }
                            else if (sensor.Status == SensorStatusCodeList.LowPower)
                            {
                                sColor = "color:orange";
                            }
                            else if (sensor.Status == SensorStatusCodeList.Error)
                            {
                                sColor = "color:red";
                            }
                            else if (sensor.Status == SensorStatusCodeList.Sleeping)
                            {
                                sColor = "color:gray";
                            }
                            writer.WriteRaw("Primary Status: <span style=\"font-weight:bold;" + sColor + "\"> " + sensor.Status.ToString() + "</ span>" + " ");
                            writer.WriteEndElement(); //end paragraph

                            //assumes at least one item of device details is present
                            if (sensor.DeviceDetails != null)
                            {
                                CreateSensorDeviceInfo(writer, sensor.DeviceDetails);
                            }

                            if (sensor.PowerDetails != null)
                            {
                                CreateSensorPowerInfo(writer, sensor.PowerDetails);
                            }

                            if (sensor.PhysiologicalDetails != null)
                            {
                                CreateSensorPhysiologicalInfo(writer, sensor.PhysiologicalDetails);
                            }

                            if (sensor.EnvironmentalDetails != null)
                            {
                                CreateSensorEnvironmentalInfo(writer, sensor.EnvironmentalDetails);
                            }

                            if (sensor.LocationDetails != null)
                            {
                                CreateSensorLocationInfo(writer, sensor.LocationDetails);
                            }
                        }
                    }
                    writer.WriteEndElement(); //end body

                    writer.WriteEndElement(); //end html

                    writer.Flush();

                    writer.Close();
                }
            }
            catch (Exception e)
            {
                DEUtilities.LogMessage("An error occurred when trying to parse the DE", DEUtilities.LogLevel.Error);
                CreateErrorInfo(writeStream);
            }
        }