Ejemplo n.º 1
0
        public object Execute(XElement operationElement)
        {
            XNamespace ns = Constants.DefaultLegacyNamespace;

            var id = PrimitiveTypeParser.Parse <long>(operationElement.Descendants(ns + "taskId").First().Value);

            Task task = null;

            try
            {
                task = _inquiryProcessor.GetTask(id);
            }
            catch (RootObjectNotFoundException)
            {
                // Eat it. Just return an empty response.
            }

            using (var stream = new MemoryStream())
            {
                var serializer = new XmlSerializer(typeof(Task), Constants.DefaultLegacyNamespace);
                serializer.Serialize(stream, task);

                stream.Seek(0, 0);

                var xDocument      = XDocument.Load(stream, LoadOptions.None);
                var taskAsXElement = xDocument.Descendants(ns + "Task");
                return(taskAsXElement.Elements());
            }
        }
Ejemplo n.º 2
0
        public void Parse_non_null_int()
        {
            int?val       = 16;
            var converted = PrimitiveTypeParser.Parse <int?>(val.ToString());

            Assert.AreEqual(val.Value, converted.Value);
        }
Ejemplo n.º 3
0
        public PagedDataRequest Create(Uri requestUri)
        {
            int?pageNumber;
            int?pageSize;

            try
            {
                var valueCollection = requestUri.ParseQueryString();

                pageNumber = PrimitiveTypeParser.Parse <int?>(valueCollection[Constants.CommonParameterNames.PageNumber]);

                pageSize = PrimitiveTypeParser.Parse <int?>(valueCollection[Constants.CommonParameterNames.PageSize]);
            }

            catch (Exception e)
            {
                _log.Error("Error parsing input", e);
                throw new HttpException((int)System.Net.HttpStatusCode.BadRequest, e.Message);
            }

            pageNumber = pageNumber.GetBoundedValue(DefaultPageSize, Constants.Paging.MinPageSize);

            pageSize = pageSize.GetBoundedValue(DefaultPageSize, Constants.Paging.MinPageSize, MaxPageSize);

            return(new PagedDataRequest(pageNumber.Value, pageSize.Value));
        }
Ejemplo n.º 4
0
        public PagedDataRequest Create(Uri requestUri)
        {
            int?pageNumber = null;
            int?pageSize   = null;

            try
            {
                var valueCollection = QueryHelpers.ParseQuery(requestUri.Query); // requestUri.ParseQueryString();
                if (valueCollection.Count != 0)
                {
                    pageNumber = PrimitiveTypeParser.Parse <int?>(valueCollection[Constants.CommonParameterNames.PageNumber]);
                    pageSize   = PrimitiveTypeParser.Parse <int?>(valueCollection[Constants.CommonParameterNames.PageSize]);
                }
            }
            catch (Exception e)
            {
                _log.LogError(null, e, "Error parsing input", null); // Error("Error parsing input", e);

                throw new HttpRequestException(HttpStatusCode.BadRequest.ToString(), e);
            }

            pageNumber = pageNumber.GetBoundedValue(Constants.Paging.DefaultPageNumber, Constants.Paging.MinPageNumber);
            pageSize   = pageSize.GetBoundedValue(DefaultPageSize, Constants.Paging.MinPageSize, MaxPageSize);

            return(new PagedDataRequest(pageNumber.Value, pageSize.Value));
        }
Ejemplo n.º 5
0
        public void Parse_non_null_DateTime()
        {
            var now       = DateTime.Now;
            var converted = PrimitiveTypeParser.Parse <DateTime?>(now.ToString(CultureInfo.InvariantCulture));

            // Compare string representations b/c the reconstituted one doesn't have the exact number of ticks.
            Assert.AreEqual(now.ToString(CultureInfo.InvariantCulture),
                            converted.Value.ToString(CultureInfo.InvariantCulture));
        }
        private void InitializePaths(XmlNode pathsNode)
        {
            Paths.Clear();

            foreach (XmlNode pathNode in pathsNode.ChildNodes)
            {
                if (pathNode.NodeType != XmlNodeType.Element)
                {
                    continue;
                }

                string pathKey = pathNode.Name;
                if (Paths.ContainsKey(pathKey))
                {
                    throw new XmlException($"The path {pathKey} was defined " +
                                           "more than once.");
                }

                XmlAttribute closeAttibute =
                    pathNode.Attributes[XmlAttributePathClose];
                if (closeAttibute == null)
                {
                    throw new XmlException($"The {XmlAttributePathClose} " +
                                           $"attribute was missing on path {pathKey}.");
                }
                if (!bool.TryParse(closeAttibute.Value, out bool closePath))
                {
                    throw new XmlException($"The {XmlAttributePathClose} " +
                                           "attribute value was no valid boolean on " +
                                           $"path {pathKey}.");
                }

                List <Vector3> pathPoints = new List <Vector3>();

                foreach (XmlNode pointNode in pathNode.ChildNodes)
                {
                    if (pointNode.NodeType != XmlNodeType.Element ||
                        pointNode.Name != XmlNodePathPoint)
                    {
                        continue;
                    }

                    if (!PrimitiveTypeParser.TryParse(pointNode.InnerText,
                                                      out Vector3 pathPoint))
                    {
                        throw new XmlException("The point definition with " +
                                               $"index {pathPoints.Count} in path {pathKey} " +
                                               "was no valid 3-dimensional vector.");
                    }

                    pathPoints.Add(pathPoint);
                }

                Paths[pathKey] = new PathLinear(pathPoints, closePath);
            }
        }
Ejemplo n.º 7
0
 public void Parse_null_int()
 {
     Assert.IsNull(PrimitiveTypeParser.Parse <int?>(null));
 }
Ejemplo n.º 8
0
 public void Parse_null_DateTime()
 {
     Assert.IsNull(PrimitiveTypeParser.Parse <DateTime?>(null));
 }