Exemple #1
0
        /// <summary>
        /// Create XML document
        /// </summary>
        /// <param name="sourceFile">Input source text file</param>
        /// <returns>XML document</returns>
        public XDocument CreateXml(IEnumerable <string> sourceFile)
        {
            if (sourceFile is null)
            {
                throw new ArgumentNullException(nameof(sourceFile));
            }

            XDocument xDocument = new XDocument(new XDeclaration("1.0", "utf-8", null));

            XElement xRoot = new XElement("urlAddresses");

            foreach (var item in sourceFile)
            {
                if (service.ValidDocument(item))
                {
                    XElement urlAddressNode = new XElement("urlAddress");

                    GetHost(item, urlAddressNode);

                    GetSegment(item, urlAddressNode);

                    GetParam(item, urlAddressNode);

                    xRoot.Add(urlAddressNode);
                }
                else
                {
                    logger.Warn($"{item} is not valid!");
                }
            }

            xDocument.Add(xRoot);
            return(xDocument);
        }
        public IEnumerable <Uri> GetUrlsData()
        {
            IEnumerable <string> urls = File.ReadLines(_filePath);

            var result = new List <Uri>();

            foreach (var item in urls)
            {
                if (_validator.Validate(item))
                {
                    result.Add(new Uri(item));
                }
                else
                {
                    _logger.Warn($"Invalid url was taken: {item}");
                }
            }

            return(result);
        }
Exemple #3
0
        public ContentResult CalculateFigureArea([FromBody] List <FigurePoint> points)
        {
            _logger.Info("CalculateFigureArea - Trying to calculate area of figure");

            var logPoints = new StringBuilder();

            points.ForEach(p => logPoints.AppendFormat("[{0}, {1}], ", p.X, p.Y));
            logPoints.Length -= 2; // remove ", " after last point
            _logger.Info("given points " + logPoints);

            decimal firstSum  = 0,
                    secondSum = 0;

            for (int i = 1; i < points.Count - 1; i++)
            {
                firstSum  += points[i].Y * (points[i - 1].X + points[i + 1].X);
                secondSum += points[i].X * (points[i + 1].Y + points[i - 1].Y);
            }


            firstSum  /= 2;
            secondSum /= 2;

            _logger.Info("firstSum = " + firstSum);
            _logger.Info("secondSum = " + secondSum);

            var isValidArea = firstSum == secondSum;

            if (isValidArea)
            {
                _logger.Info("This figure matches the criteria, returning area");
                return(Content("{ \"isValidArea\":" + isValidArea.ToString().ToLower() + ", \"value\":" + firstSum + "}", "application/json"));
            }
            else
            {
                _logger.Warn("Figure with this points doesn't match criteria.");
                return(Content("{ \"isValidArea\":" + isValidArea.ToString().ToLower() + ", \"value\": \"" + firstSum + " / " + secondSum + "\"}", "application/json"));
            }
        }