예제 #1
0
        /// <summary>
        /// Creates the resource detail with the given name
        /// </summary>
        /// <returns>The resource detail.</returns>
        /// <param name="name">Name.</param>
        /// <param name="agency">Agency</param>
        public static ResourceDetail createResourceDetail(string name, string agency)
        {
            ResourceDetail resource = new ResourceDetail();

            resource.Status = new ResourceStatus();
            resource.setPrimaryStatus(ResourcePrimaryStatusCodeList.Available);

            resource.OwningOrg            = new ResourceOrganization();
            resource.OwningOrg.ResourceID = name;
            resource.OwningOrg.OrgID      = agency;

            return(resource);
        }
예제 #2
0
        /// <summary>
        /// Sends the location.
        /// </summary>
        /// <returns>The location.</returns>
        /// <param name="lat">Lat.</param>
        /// <param name="lon">Lon.</param>
        /// <param name="url">URL.</param>
        /// <param name="name">Name.</param>
        /// <param name="agency">Agency.</param>
        /// <param name="resourceType">Resource type.</param>
        /// <param name="eventDetails">Event details.</param>
        public static async Task SendLocation(double lat, double lon, string url, string name, string agency, string resourceType, List <EventDetails> eventDetails)
        {
            DEv1_0         de       = new DEv1_0();
            Event          newEvent = new Event();
            ResourceDetail resource = new ResourceDetail();

            resource.Status = new ResourceStatus();
            //resource.Status.SecondaryStatus = new List<AltStatus>();
            resource.setPrimaryStatus(ResourcePrimaryStatusCodeList.Available);
            resource.OwningOrg            = new ResourceOrganization();
            resource.OwningOrg.ResourceID = name;
            // resource.AddSecondaryStatusText("Test", "001");
            newEvent.EventTypeDescriptor = new EventTypeDescriptor();
            newEvent.EventTypeDescriptor.EventTypeCode = resourceType;
            //EventTypeCodeList.ATOM_GRDTRK_EQT_GRDVEH_CVLVEH_EM_EMS_AMBULANCE.ToString();
            de.SenderID                = name + "." + agency + "@watchtower";
            de.DistributionID          = name;
            de.DateTimeSent            = DateTime.Now;
            de.DistributionStatus      = StatusValue.Test;
            de.DistributionType        = TypeValue.Update;
            de.CombinedConfidentiality = "Unclassified";

            // add resource details at beginning
            eventDetails.Insert(0, resource);
            newEvent.Details = eventDetails;
            newEvent.EventID = de.DistributionID;
            newEvent.EventMessageDateTime = DateTime.Now;
            newEvent.EventValidityDateTimeRange.StartDate = DateTime.Now;
            newEvent.EventValidityDateTimeRange.EndDate   = DateTime.Now.AddMinutes(30);

            newEvent.EventLocation = new EventLocation();
            newEvent.EventLocation.LocationCylinder = new LocationCylinder();
            newEvent.EventLocation.LocationCylinder.LocationPoint           = new LocationPoint();
            newEvent.EventLocation.LocationCylinder.LocationPoint.Point     = new Point();
            newEvent.EventLocation.LocationCylinder.LocationPoint.Point.Lat = lat;
            newEvent.EventLocation.LocationCylinder.LocationPoint.Point.Lon = lon;


            de.ContentObjects = new List <EMS.EDXL.DE.ContentObject>();

            //Debug.WriteLine(newEvent.ToString());

            XElement xml = XElement.Parse(newEvent.ToString());

            EMS.EDXL.DE.ContentObject co = new EMS.EDXL.DE.ContentObject();
            co.XMLContent = new XMLContentType();
            co.XMLContent.AddEmbeddedXML(xml);
            de.ContentObjects.Add(co);

            await sendMessage(de, url);
        }
예제 #3
0
        private void sendTimer_Tick(object sender, ElapsedEventArgs e)
        {
            this.sendTimer.Stop();
            DEv1_0 de = new DEv1_0();

            de.CombinedConfidentiality = "U";
            de.DateTimeSent            = DateTime.UtcNow;
            de.DistributionID          = PinPointConfig.UnitID;
            de.SenderID = "*****@*****.**";
            de.DistributionReference.Add(PinPointConfig.UnitID + "," + de.SenderID + ",1753-01-01T00:00:00.0000000Z");
            de.DistributionStatus = StatusValue.Actual;
            de.DistributionType   = TypeValue.Update;
            de.Language           = "en-US";

            Event emlc = new Event();

            emlc.EventID = PinPointConfig.UnitID;
            LocationCylinder loc = new LocationCylinder();

            loc.CodeValue = gpsManager.CurrentLocation.CodeValue;
            loc.LocationCylinderHalfHeightValue = -99999;
            loc.LocationCylinderRadiusValue     = -99999;
            loc.LocationPoint.Point.Height      = gpsManager.CurrentLocation.LocationPoint.Point.Height;
            loc.LocationPoint.Point.Lat         = gpsManager.CurrentLocation.LocationPoint.Point.Lat;
            loc.LocationPoint.Point.Lon         = gpsManager.CurrentLocation.LocationPoint.Point.Lon;
            loc.LocationPoint.Point.srsName     = "http://metadata.ces.mil/mdr/ns/GSIP/crs/WGS84E_3D";
            emlc.EventLocation.LocationCylinder = loc;
            emlc.EventMessageDateTime           = DateTime.UtcNow;
            emlc.EventTypeDescriptor.CodeValue  = (EventTypeCodeList)Enum.Parse(typeof(EventTypeCodeList), PinPointConfig.UnitType);
            emlc.EventTypeDescriptor.EventTypeDescriptorExtension.Add(emlc.EventTypeDescriptor.CodeValue.ToString().Replace("_", "."));
            emlc.EventValidityDateTimeRange.StartDate = emlc.EventMessageDateTime;
            emlc.EventValidityDateTimeRange.EndDate   = emlc.EventMessageDateTime.AddMinutes(30);

            ResourceDetail resourceDetail = new ResourceDetail();

            resourceDetail.Status = new ResourceStatus();
            TextStatus textStatus = new TextStatus();

            textStatus.Description = "Foo";
            textStatus.SourceID    = "VA.LCFR";
            resourceDetail.Status.SecondaryStatus = new List <AltStatus>();
            resourceDetail.Status.SecondaryStatus.Add(textStatus);

            //Log.Info(@"Type: " + unitStatus + " and the file is at " + UNITSTATPATH);
            resourceDetail.setPrimaryStatus(ResourcePrimaryStatusCodeList.Available);
            emlc.Details = resourceDetail;



            List <string> keywords = new List <string>();

            keywords.Add("PinPoint AvL");
            keywords.Add(PinPointConfig.UnitID);
            keywords.Add(emlc.EventTypeDescriptor.CodeValue.ToString().Replace("_", "."));
            ContentObject co = new ContentObject("http://edxlsharp.codeplex.com/ValueLists/ContentKeywords", keywords);

            co.XMLContent = new XMLContentType();
            co.XMLContent.EmbeddedXMLContent = new List <XElement>();
            string   str = emlc.ToString();
            XElement xe  = XElement.Parse(str);

            co.XMLContent.AddEmbeddedXML(xe);
            co.ContentDescription = "PinPoint AvL";
            de.ContentObjects.Add(co);
            XmlSerializer     x         = new XmlSerializer(de.GetType());
            XmlWriterSettings xsettings = new XmlWriterSettings();

            xsettings.Indent             = true;
            xsettings.OmitXmlDeclaration = true;

            using (var stream = new StringWriter())
                using (var writer = XmlWriter.Create(stream, xsettings))
                {
                    x.Serialize(writer, de);
                    str = stream.ToString();
                }
            HttpWebRequest  request;
            HttpWebResponse resp;
            //WebProxy proxy;
            string requesturi = PinPointConfig.PostURL;

            request                   = (HttpWebRequest)WebRequest.Create(requesturi);
            request.KeepAlive         = true;
            request.Method            = "POST";
            request.ContentType       = "text/xml";
            request.AllowAutoRedirect = true;
            request.ContentLength     = Encoding.UTF8.GetByteCount(str);

            /*if (!String.IsNullOrWhiteSpace(proxyHostName) && !String.IsNullOrWhiteSpace(proxyPort))
             * {
             * proxy = new WebProxy();
             * proxy.Address = new Uri("http://" + proxyHostName + ":" + proxyPort);
             * if (!string.IsNullOrWhiteSpace(proxyUsername) && !string.IsNullOrEmpty(proxyPassword))
             * {
             *  proxy.Credentials = new NetworkCredential(proxyUsername, proxyPassword);
             * }
             * request.Proxy = proxy;
             * }*/
            try
            {
                SetBody(request, str);
                resp = (HttpWebResponse)request.GetResponse();
                resp.Close();
            }
            catch (Exception ex)
            {
                log.Error("Error in HTTPSender: " + ex.ToString());
            }
            OnSent(EventArgs.Empty);
            this.sendTimer.Start();
        }