Esempio n. 1
0
        private XElement SaveHostToXml(UrlPartsGetter urlPartsGetter)
        {
            XElement xHost = new XElement("host");

            XAttribute xHostNameAttribute = new XAttribute("name", urlPartsGetter.GetHost());

            xHost.Add(xHostNameAttribute);

            return(xHost);
        }
Esempio n. 2
0
        public XDocument UrlsToXml()
        {
            XElement xUrls = new XElement("urls");

            foreach (string url in _urls)
            {
                try
                {
                    XElement xHost       = null;
                    XElement xSegments   = null;
                    XElement xParameters = null;

                    UrlPartsGetter urlPartsGetter = new UrlPartsGetter(url);
                    XElement       xUrl           = new XElement("urls");

                    xHost       = SaveHostToXml(urlPartsGetter);
                    xSegments   = SaveSegmentsToXml(urlPartsGetter);
                    xParameters = SaveParametersToXml(urlPartsGetter);

                    if (xHost != null)
                    {
                        xUrl.Add(xHost);
                    }

                    if (xSegments != null)
                    {
                        xUrl.Add(xSegments);
                    }

                    if (xParameters != null)
                    {
                        xUrl.Add(xParameters);
                    }

                    xUrls.Add(xUrl);
                }
                catch (Exception ex)
                {
                    _logger.Error(ex.Message);
                    _logger.Error($"Impossible to add {url}");
                }
            }

            _xDocument.Add(xUrls);
            return(_xDocument);
        }
Esempio n. 3
0
        private XElement SaveSegmentsToXml(UrlPartsGetter urlPartsGetter)
        {
            XElement xSegments = null;

            var segments = urlPartsGetter.GetUriParts();

            if (segments.Any())
            {
                xSegments = new XElement("uri");

                foreach (var segment in urlPartsGetter.GetUriParts())
                {
                    XElement xSegment = new XElement("segment", segment);
                    xSegments.Add(xSegment);
                }
            }

            return(xSegments);
        }
Esempio n. 4
0
        private XElement SaveParametersToXml(UrlPartsGetter urlPartsGetter)
        {
            XElement xParameters = null;

            var parameters = urlPartsGetter.GetParameters();

            if (parameters.Any())
            {
                xParameters = new XElement("parameters");

                foreach (var kvp in parameters)
                {
                    XElement   xParameter = new XElement("parameter");
                    XAttribute xParameterValueAttribute = new XAttribute("value", kvp.Value);
                    XAttribute xParameterKeyAttribute   = new XAttribute("key", kvp.Key);

                    xParameter.Add(xParameterValueAttribute, xParameterKeyAttribute);
                    xParameters.Add(xParameter);
                }
            }

            return(xParameters);
        }