Ejemplo n.º 1
0
        /// <summary>
        /// 將Cap物件轉為Kml
        /// </summary>
        /// <returns></returns>
        public string ToKml()
        {
            // alert
            StringBuilder sbAlert = new StringBuilder();

            sbAlert.Append(string.Format("<{0}>{1}</{0}>", "identifier", identifier));
            sbAlert.Append(string.Format("<{0}>{1}</{0}>", "sender", sender));
            sbAlert.Append(string.Format("<{0}>{1}</{0}>", "sent", sent));
            sbAlert.Append(string.Format("<{0}>{1}</{0}>", "status", status));
            sbAlert.Append(string.Format("<{0}>{1}</{0}>", "msgType", msgType));
            if (!string.IsNullOrEmpty(source))
            {
                sbAlert.Append(string.Format("<{0}>{1}</{0}>", "source", source));
            }
            sbAlert.Append(string.Format("<{0}>{1}</{0}>", "scope", scope));
            if (!string.IsNullOrEmpty(restriction))
            {
                sbAlert.Append(string.Format("<{0}>{1}</{0}>", "restriction", restriction));
            }
            if (!string.IsNullOrEmpty(addresses))
            {
                sbAlert.Append(string.Format("<{0}>{1}</{0}>", "addresses", addresses));
            }
            if (code.Any())
            {
                foreach (var c in code)
                {
                    sbAlert.Append(string.Format("<{0}>{1}</{0}>", "code", c));
                }
            }
            if (!string.IsNullOrEmpty(note))
            {
                sbAlert.Append(string.Format("<{0}>{1}</{0}>", "note", note));
            }
            if (!string.IsNullOrEmpty(references))
            {
                sbAlert.Append(string.Format("<{0}>{1}</{0}>", "references", references));
            }
            if (!string.IsNullOrEmpty(incidents))
            {
                sbAlert.Append(string.Format("<{0}>{1}</{0}>", "incidents", incidents));
            }
            string result = StringUtility.ReplaceContent(CapDocumentSetting.Default.kmlTemplate, "alert", sbAlert.ToString());

            // info
            StringBuilder sbInfo = new StringBuilder();

            if (info.Any())
            {
                foreach (var i in info)
                {
                    StringBuilder sbInfoItem = new StringBuilder();
                    if (!string.IsNullOrEmpty(i.language))
                    {
                        sbInfoItem.Append(string.Format("<{0}>{1}</{0}>", "language", i.language));
                    }
                    if (i.category.Any())
                    {
                        foreach (var c in i.category)
                        {
                            sbInfoItem.Append(string.Format("<{0}>{1}</{0}>", "category", c));
                        }
                    }
                    sbInfoItem.Append(string.Format("<{0}>{1}</{0}>", "event", i.@event));
                    if (i.responseType.Any())
                    {
                        foreach (var r in i.responseType)
                        {
                            sbInfoItem.Append(string.Format("<{0}>{1}</{0}>", "responseType", r));
                        }
                    }
                    sbInfoItem.Append(string.Format("<{0}>{1}</{0}>", "urgency", i.urgency));
                    sbInfoItem.Append(string.Format("<{0}>{1}</{0}>", "severity", i.severity));
                    sbInfoItem.Append(string.Format("<{0}>{1}</{0}>", "certainty", i.certainty));
                    StringUtility.SetCotent(sbInfoItem, "audience", i.audience);
                    if (i.eventCode.Any())
                    {
                        foreach (var e in i.eventCode)
                        {
                            string contentString = string.Format("<{0}>{1}</{0}>", "valueName", e.valueName) + string.Format("<{0}>{1}</{0}>", "value", e.value);
                            sbInfoItem.Append(string.Format("<{0}>{1}</{0}>", "eventCode", contentString));
                        }
                    }
                    StringUtility.SetCotent(sbInfoItem, "effective", i.effective);
                    StringUtility.SetCotent(sbInfoItem, "onset", i.onset);
                    StringUtility.SetCotent(sbInfoItem, "expires", i.expires);
                    StringUtility.SetCotent(sbInfoItem, "senderName", i.senderName);
                    StringUtility.SetCotent(sbInfoItem, "headline", i.headline);
                    StringUtility.SetCotent(sbInfoItem, "description", i.description);
                    StringUtility.SetCotent(sbInfoItem, "instruction", i.instruction);
                    StringUtility.SetCotent(sbInfoItem, "web", HttpUtility.HtmlEncode(i.web));
                    StringUtility.SetCotent(sbInfoItem, "contact", i.contact);
                    StringUtility.SetCotent(sbInfoItem, "headline", i.headline);
                    if (i.parameter.Any())
                    {
                        foreach (var p in i.parameter)
                        {
                            string contentString = string.Format("<{0}>{1}</{0}>", "valueName", p.valueName) + string.Format("<{0}>{1}</{0}>", "value", p.value);
                            sbInfoItem.Append(string.Format("<{0}>{1}</{0}>", "parameter", contentString));
                        }
                    }

                    // area
                    StringBuilder sbArea = new StringBuilder();
                    if (i.area.Any())
                    {
                        StringBuilder sbAreaItem = new StringBuilder();
                        foreach (var a in i.area)
                        {
                            StringBuilder sbAreaPolygon = new StringBuilder();
                            if (a.polygon.Any())
                            {
                                sbAreaPolygon.Append(string.Format(CapDocumentSetting.Default.kmlAreaPolygonTemplate, "polygon", string.Join(" ", a.polygon)));
                                //foreach (var p in a.polygon)
                                //{
                                //    sbAreaPolygon.Append(string.Format("<{0}>{1}</{0}>", "polygon", p));
                                //}
                            }
                            if (a.circle.Any())
                            {
                                sbAreaPolygon.Append(string.Format(CapDocumentSetting.Default.kmlAreaPolygonTemplate, "circle", string.Join(" ", a.circle)));
                                //foreach (var c in a.circle)
                                //{
                                //    sbAreaPolygon.Append(string.Format("<{0}>{1}</{0}>", "circle", c));
                                //}
                            }
                            if (a.geocode.Any())
                            {
                                foreach (var g in a.geocode)
                                {
                                    sbAreaPolygon.Append(GeoCodeUtility.GetPolygon(g.value, "kml"));
                                    //string contentString = string.Format("<{0}>{1}</{0}>", "valueName", g.valueName) + string.Format("<{0}>{1}</{0}>", "value", g.value);
                                    //sbAreaPolygon.Append(string.Format("<{0}>{1}</{0}>", "geocode", contentString));
                                }
                            }
                            StringBuilder sbAreaOther = new StringBuilder();
                            StringUtility.SetCotent(sbAreaOther, "altitude", a.altitude.ToString());
                            StringUtility.SetCotent(sbAreaOther, "ceiling", a.ceiling.ToString());
                            sbAreaItem.Append(string.Format(CapDocumentSetting.Default.kmlAreaTemplate, a.areaDesc,
                                                            sbAreaPolygon.ToString(), sbAreaOther.ToString()));
                        }
                        sbArea.Append(string.Format(CapDocumentSetting.Default.kmlAreaScopeTemplate, sbAreaItem.ToString()));
                    }

                    // resource
                    StringBuilder sbResource = new StringBuilder();
                    if (i.resource.Any())
                    {
                        StringBuilder sbResourceItem = new StringBuilder();
                        foreach (var r in i.resource)
                        {
                            StringUtility.SetCotent(sbResourceItem, "resourceDesc", r.resourceDesc);
                            StringUtility.SetCotent(sbResourceItem, "mimeType", r.mimeType);
                            StringUtility.SetCotent(sbResourceItem, "size", r.size);
                            StringUtility.SetCotent(sbResourceItem, "uri", r.uri);
                            StringUtility.SetCotent(sbResourceItem, "derefUri", r.derefUri);
                            StringUtility.SetCotent(sbResourceItem, "digest", r.digest);
                            sbResourceItem.Append(string.Format(CapDocumentSetting.Default.kmlResourceTemplate, sbResourceItem.ToString()));
                        }
                        sbResource.Append(string.Format(CapDocumentSetting.Default.kmlResourceScopeTemplate, sbResourceItem.ToString()));
                    }

                    sbInfo.Append(string.Format(CapDocumentSetting.Default.kmlInfoTemplate, sbInfoItem.ToString(), sbArea.ToString(), sbResource.ToString()));
                }
            }
            result = StringUtility.ReplaceContent(result, "info", sbInfo.ToString());

            return(result);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 將Cap物件轉為GeoRss
        /// </summary>
        /// <returns>GeoRss字串</returns>
        public string ToGeoRssItem()
        {
            StringBuilder sbGeoRssItem = new StringBuilder();
            string        result       = StringUtility.ReplaceContent(CapDocumentSetting.Default.geoRssItemTemplate, "identifier", identifier);

            result = StringUtility.ReplaceContent(result, "sent", sent);
            result = StringUtility.ReplaceContent(result, "sender", sender);
            string        @event         = string.Empty;
            StringBuilder sbMultiPolygon = new StringBuilder();

            if (info.Any())
            {
                result = StringUtility.ReplaceContent(result, "description", info[0].description);
                @event = info[0].@event;
                foreach (var i in info)
                {
                    if (i.area.Any())
                    {
                        foreach (var a in i.area)
                        {
                            if (a.circle.Any())
                            {
                                sbMultiPolygon.Append(string.Format(CapDocumentSetting.Default.geoRssItemPolygonTemplate, string.Join(" ", a.circle)));
                            }
                            if (a.polygon.Any())
                            {
                                sbMultiPolygon.Append(string.Format(CapDocumentSetting.Default.geoRssItemPolygonTemplate, string.Join(" ", a.polygon)));
                            }
                            if (a.geocode.Any())
                            {
                                foreach (var g in a.geocode)
                                {
                                    sbMultiPolygon.Append(string.Format(CapDocumentSetting.Default.geoRssItemGeoCodeTemplate, GeoCodeUtility.GetPolygon(g.value, "gml")));
                                }
                            }
                        }
                    }
                }
                result = StringUtility.ReplaceContent(result, "multipolygon", sbMultiPolygon.ToString());
            }
            result = StringUtility.ReplaceContent(result, "event", @event);
            sbGeoRssItem.Append(result);

            return(sbGeoRssItem.ToString());
        }