示例#1
0
        public IActionResult GetPartPins(
            [FromRoute] string database,
            [FromRoute] string id)
        {
            ICadmusRepository repository =
                _repositoryProvider.CreateRepository(database);
            string json = repository.GetPartContent(id);

            if (json == null)
            {
                return(new NotFoundResult());
            }
            // remove ISODate(...) function (this seems to be a Mongo artifact)
            json = Regex.Replace(json, @"ISODate\(([^)]+)\)", "$1");
            // Pascal-case properties
            json = _camelPropRegex.Replace(json,
                                           m => $"\"{m.Groups[1].Value.ToUpperInvariant()}{m.Groups[2].Value}\":");

            Match typeMatch = Regex.Match(json, "\"TypeId\":\\s*\"([^\"]+)\"");

            if (!typeMatch.Success)
            {
                return(NotFound());
            }

            Match  roleMatch = Regex.Match(json, "\"RoleId\":\\s*\"([^\"]+)\"");
            string role      = roleMatch.Success ? roleMatch.Groups[1].Value : null;

            IPartTypeProvider provider = _repositoryProvider.GetPartTypeProvider();
            Type  t      = provider.Get(typeMatch.Groups[1].Value);
            IPart part   = (IPart)JsonConvert.DeserializeObject(json, t);
            var   result = (from p in part.GetDataPins()
                            select new
            {
                p.Name,
                p.Value
            }).ToList();

            return(Ok(result));
        }