Parse() public static method

Извлекает информацию о протоколе.
public static Parse ( string url ) : JanusProtocolInfo
url string Строка запроса.
return JanusProtocolInfo
Ejemplo n.º 1
0
        private void IdBoxTextChanged(object sender, EventArgs e)
        {
            var isValid = true;

            try
            {
                var input = _idBox.Text;

                if (!string.IsNullOrEmpty(input))
                {
                    var janusProtocolInfo = JanusProtocolInfo.Parse(input);
                    if (null != janusProtocolInfo && janusProtocolInfo.IsId)
                    {
                        MessageId = janusProtocolInfo.Id;
                    }
                    else
                    {
                        MessageId = int.Parse(input);
                    }
                }
                else
                {
                    isValid = false;
                }
            }
            catch
            {
                isValid = false;
            }

            _labelMessageIdIsText.Text = string.Format(SR.EnterTopicMessageIdForm.MessageIdIsTextFormat, MessageId);

            _labelMessageIdIsText.Visible = isValid;
            _okButton.Enabled             = isValid;
        }
        private int?GetActiveMessageId()
        {
            var info = JanusProtocolInfo.Parse(_browserFormService.Url);

            return(info != null &&
                   info.ResourceType == JanusProtocolResourceType.Message &&
                   info.IsId
                           ? (int?)info.Id : null);
        }
Ejemplo n.º 3
0
        internal EnterTopicMessageIdForm()
        {
            InitializeComponent();

            // Попытаться извлечь дефолтный номер сообщения из буфера обмена.
            var dto = Clipboard.GetDataObject();

            if (dto != null)
            {
                if (dto.GetDataPresent(DataFormats.Text))
                {
                    var data = (string)dto.GetData(DataFormats.Text);
                    var info = JanusProtocolInfo.Parse(data);
                    if (info != null && info.ResourceType == JanusProtocolResourceType.Message && info.IsId)
                    {
                        _idBox.Text = data;
                    }
                }
            }
        }
Ejemplo n.º 4
0
        private string ProcessUrlInternal(string url, string text)
        {
            if (url == null)
            {
                throw new ArgumentNullException("url");
            }
            if (text == null)
            {
                throw new ArgumentNullException("text");
            }

            var info = JanusProtocolInfo.Parse(url);

            string   title;
            string   imageUrl;
            LinkType linkType;

            if (info != null && info.ResourceType == JanusProtocolResourceType.Faq)
            {
                return(ProcessRsdnLinkInternal(_provider, info.Parameters, text));
            }

            url = RefineUrl(info, out imageUrl, out title, out linkType) ?? url;

            if (linkType == LinkType.External)
            {
                imageUrl = RefineImageForWellKnownUrls(_provider, url) ?? imageUrl;
            }

            const string format =
                "<a class='m' href='{0}{1}' title='{5}'><img border='0' align='absbottom' src='{3}' style='margin-bottom:1px;margin-right: 2px;'></a>" +
                "<a class='m' href='{0}{1}' title='{5}'>{2}</a>{4}";

            return(string.Format(format,
                                 ParseUrl(url).Groups["scheme"].Success ? "" : "http://",
                                 url.EncodeAgainstXSS(),
                                 text,
                                 imageUrl,
                                 GetPostfixImagePath(_provider, linkType, info),
                                 string.IsNullOrEmpty(title) ? url : title));
        }
Ejemplo n.º 5
0
        private void MessageBrowserNavigating(object sender, WebBrowserNavigatingEventArgs e)
        {
            if (!_blockExternalNavigation)
            {
                var protocolInfo = JanusProtocolInfo.Parse(e.Url.ToString());
                var linkType     = protocolInfo == null ? LinkType.External : protocolInfo.LinkType;
                var obManager    = _serviceManager.GetRequiredService <IOutboxManager>();
                var manager      = ApplicationManager.Instance;

                switch (linkType)
                {
                case LinkType.Local:
                    Debug.Assert(protocolInfo != null);
                    if (protocolInfo.ResourceType == JanusProtocolResourceType.Message)
                    {
                        manager.ForumNavigator.SelectMessage(protocolInfo.Id);
                    }
                    else
                    {
                        manager.ForumNavigator.SelectMessage(protocolInfo.Parameters);
                    }
                    break;

                case LinkType.Absent:
                    Debug.Assert(protocolInfo != null);
                    obManager.AddTopicForDownloadWithConfirm(protocolInfo.Id);
                    e.Cancel = true;
                    break;

                case LinkType.External:
                    _serviceManager.OpenUrlInBrowser(e.Url.OriginalString);
                    e.Cancel = true;
                    break;
                }
            }
            _blockExternalNavigation = false;
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Распределяет запросы протокола по обработчикам.
        /// </summary>
        /// <param name="uri">Путь запроса.</param>
        /// <returns>Результат обработки запроса.</returns>
        public Resource DispatchRequest(string uri)
        {
            try
            {
                var info = JanusProtocolInfo.Parse(uri);

                var resource = info != null ? info.ResourceName : uri;

                if (!_handlers.ContainsKey(resource))
                {
                    throw new ArgumentException(string.Format(SR.ResourceNotFound, resource));
                }

                System.Diagnostics.Debug.Assert(info != null);

                var jpea = new JanusProtocolEventArgs(info.Parameters);
                _handlers[resource](this, jpea);
                return(jpea.Response);
            }
            catch (Exception e)
            {
                return(new Resource(_mimeTypeHtml, HtmlPageBuilder.GetExceptionMessage(uri, e)));
            }
        }