public void IconURLTest() { Event newEvent = new Event(); //set the basics newEvent.EventID = "ARDENTMC:TESTMESSAGE:EVENT:SIMPLE"; newEvent.EventMessageDateTime = System.DateTime.UtcNow; newEvent.EventTypeDescriptor.CodeValue = EventTypeCodeList.ATOM_GRDTRK_EQT_GRDVEH_CVLVEH_EM_EMS_AMBULANCE; newEvent.EventTypeDescriptor.EventTypeDescriptorExtension.Add("Ambulance"); newEvent.EventValidityDateTimeRange.StartDate = System.DateTime.UtcNow; newEvent.EventValidityDateTimeRange.EndDate = System.DateTime.UtcNow.AddDays(1.0); //set the location EventLocation location = new EventLocation(); location.LocationCylinder.CodeValue = LocationCreationCodeList.HUMAN; location.LocationCylinder.LocationPoint.Point.Lat = 30.0; location.LocationCylinder.LocationPoint.Point.Lon = 30.0; location.LocationCylinder.LocationCylinderRadiusValue = (decimal)1.0; newEvent.EventLocation = location; newEvent.Details = new ResourceDetail(); //set a comment EventComment comment = new EventComment(); comment.CommentText = "This is a simple NIEM Event message."; comment.DateTime = System.DateTime.UtcNow; comment.OrganizationIdentification = "ArdentMC"; comment.PersonHumanResourceIdentification = "Brian Wilkins"; newEvent.EventComment = new List <EventComment>(); newEvent.EventComment.Add(comment); // set event EMLCContent cont = new EMLCContent(newEvent); // getting URL string iconLoc = cont.IconURL(); Console.WriteLine(iconLoc); if (iconLoc == "") // If no url is returned { Assert.Fail(); } }
/// <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); } }