示例#1
0
        public string GetUriSuffix()
        {
            Contract.Requires(Uri.IsWellFormedUriString(Href, UriKind.Absolute));

            var uriSuffix = Href.Substring(Href.IndexOf("/api", StringComparison.InvariantCultureIgnoreCase) + 4);

            return(uriSuffix);
        }
示例#2
0
        public TableOfContentsEntry(string id, string text, int order, string href)
        {
            Id    = id ?? throw new ArgumentNullException(nameof(id));
            Text  = text ?? throw new ArgumentNullException(nameof(text));
            Order = order;
            Href  = href ?? throw new ArgumentNullException(nameof(href));

            var idx = Href.IndexOf('#');

            if (idx != -1)
            {
                Href = Href.Substring(0, idx);
            }
        }
        /// <summary>
        /// Returns tokenized Service Indication message.
        /// </summary>
        /// <returns>byte array</returns>
        public override byte[] GetWBXMLBytes()
        {
            MemoryStream wbxmlBytes = new MemoryStream();

            // header
            wbxmlBytes.WriteByte(WBXMLDocument.VERSION_1_2);
            wbxmlBytes.WriteByte(DOCUMENT_DTD_ServiceIndication);
            wbxmlBytes.WriteByte(WBXMLDocument.CHARSET_UTF_8);
            wbxmlBytes.WriteByte(WBXMLDocument.NULL); // String table length

            // xml
            wbxmlBytes.WriteByte(SetTagTokenIndications(TAGTOKEN_si, false, true));        // <si> with content
            wbxmlBytes.WriteByte(SetTagTokenIndications(TAGTOKEN_indication, true, true)); // <indication> with cont. and attr.

            #region Tokenizing of the HREF

            // find the starting attribute token (http:// https:// etc..)
            int  pos          = 0;
            byte hrefTagToken = ATTRIBUTESTARTTOKEN_href;
            foreach (string startString in hrefStartTokens.Keys)
            {
                if (this.Href.StartsWith(startString))
                {
                    hrefTagToken = hrefStartTokens[startString];
                    pos          = startString.Length;
                    break;
                }
            }

            // find the `A` domain token. (.com .net .org etc..)
            int    domainPos = -1;
            string domain    = string.Empty;
            foreach (string domainString in attributeValueTokens.Keys)
            {
                domainPos = this.Href.IndexOf(domainString);
                if (domainPos >= 0)
                {
                    domain = domainString;
                    break;
                }
            }
            #endregion

            // write href url
            if (domainPos >= 0) // encode domain
            {
                wbxmlBytes.WriteByte(hrefTagToken);
                WriteInlineString(wbxmlBytes, Href.Substring(pos, domainPos - pos));
                wbxmlBytes.WriteByte(attributeValueTokens[domain]);
                WriteInlineString(wbxmlBytes, Href.Substring(domainPos + domain.Length));
            }
            else // no domain to encode
            {
                wbxmlBytes.WriteByte(hrefTagToken);
                WriteInlineString(wbxmlBytes, Href.Substring(pos));
            }

            // writes action signal
            if (Action != ServiceIndicationAction.NotSet)
            {
                wbxmlBytes.WriteByte(GetActionToken(Action));
            }

            // writes Created dateTime signal (if set)
            if (Created != DateTime.MinValue)
            {
                wbxmlBytes.WriteByte(ATTRIBUTESTARTTOKEN_created);
                WriteDate(wbxmlBytes, Created);
            }

            // writes Experi dateTime signal (if set)
            if (Expires != DateTime.MinValue)
            {
                wbxmlBytes.WriteByte(ATTRIBUTESTARTTOKEN_si_expires);
                WriteDate(wbxmlBytes, Expires);
            }

            // writes Si-id (if set)
            if (Id != null)
            {
                wbxmlBytes.WriteByte(ATTRIBUTESTARTTOKEN_si_id);
                WriteInlineString(wbxmlBytes, Id);
            }

            // end indication
            wbxmlBytes.WriteByte(WBXMLDocument.TAGTOKEN_END); // </indication>

            // Writes texts
            WriteInlineString(wbxmlBytes, Text);

            // End tags
            wbxmlBytes.WriteByte(WBXMLDocument.TAGTOKEN_END);
            wbxmlBytes.WriteByte(WBXMLDocument.TAGTOKEN_END);

            byte[] wbxmlBytesArray = wbxmlBytes.ToArray();
            wbxmlBytes.Close();

            return(wbxmlBytesArray);
        }
示例#4
0
        /// <summary>
        /// Returns tokenized Service Loading message.
        /// </summary>
        /// <returns>byte array</returns>
        public override byte[] GetWBXMLBytes()
        {
            MemoryStream wbxmlBytes = new MemoryStream();

            // header
            wbxmlBytes.WriteByte(WBXMLDocument.VERSION_1_2);
            wbxmlBytes.WriteByte(DOCUMENT_DTD_ServiceIndication);
            wbxmlBytes.WriteByte(WBXMLDocument.CHARSET_UTF_8);
            wbxmlBytes.WriteByte(WBXMLDocument.NULL); // String table length

            // xml
            wbxmlBytes.WriteByte(SetTagTokenIndications(TAGTOKEN_sl, true, false));  // <sl> with attributes

            #region Tokenizing of the HREF

            // find the starting attribute token (http:// https:// etc..)
            int  pos          = 0;
            byte hrefTagToken = ATTRIBUTESTARTTOKEN_href;
            foreach (string startString in hrefStartTokens.Keys)
            {
                if (this.Href.StartsWith(startString))
                {
                    hrefTagToken = hrefStartTokens[startString];
                    pos          = startString.Length;
                    break;
                }
            }

            // find the `A` domain token. (.com .net .org etc..)
            int    domainPos = -1;
            string domain    = string.Empty;
            foreach (string domainString in attributeValueTokens.Keys)
            {
                domainPos = this.Href.IndexOf(domainString);
                if (domainPos >= 0)
                {
                    domain = domainString;
                    break;
                }
            }
            #endregion

            // write href url
            if (domainPos >= 0) // encode domain
            {
                wbxmlBytes.WriteByte(hrefTagToken);
                WriteInlineString(wbxmlBytes, Href.Substring(pos, domainPos - pos));
                wbxmlBytes.WriteByte(attributeValueTokens[domain]);
                WriteInlineString(wbxmlBytes, Href.Substring(domainPos + domain.Length));
            }
            else // no domain to encode
            {
                wbxmlBytes.WriteByte(hrefTagToken);
                WriteInlineString(wbxmlBytes, Href.Substring(pos));
            }

            // writes action signal
            if (Action != ServiceLoadingAction.NotSet)
            {
                wbxmlBytes.WriteByte(GetActionToken(Action));
            }

            // End tag
            wbxmlBytes.WriteByte(WBXMLDocument.TAGTOKEN_END);

            byte[] wbxmlBytesArray = wbxmlBytes.ToArray();
            wbxmlBytes.Close();

            return(wbxmlBytesArray);
        }
示例#5
0
 public string GetIdFromHref()
 {
     return(Href.Substring(Href.LastIndexOf("/") + 1));
 }