Beispiel #1
0
        private static List <ValidMethods> GetValidMethodList(Object target)
        {
            var srcTarget = target;

            if (target is Component component)
            {
                target = component.gameObject;
            }
            var result = new List <ValidMethods>();

            if (target is GameObject go)
            {
                {
                    var methods      = GetValidMethodsFromType(go.GetType());
                    var validMethods = new ValidMethods()
                    {
                        targetType = go.GetType(),
                        methods    = methods,
                        target     = go,
                    };
                    result.Add(validMethods);
                }

                var components = go.GetComponents <Component>();
                var identicalComponentsDict = new Dictionary <System.Type, List <ValidMethods> >();
                foreach (var comp in components)
                {
                    var methods      = GetValidMethodsFromType(comp.GetType());
                    var targetType   = comp.GetType();
                    var validMethods = new ValidMethods()
                    {
                        targetType = targetType,
                        methods    = methods,
                        target     = comp,
                    };
                    if (!identicalComponentsDict.ContainsKey(targetType))
                    {
                        identicalComponentsDict[targetType] = new List <ValidMethods>();
                    }
                    identicalComponentsDict[targetType].Add(validMethods);
                    result.Add(validMethods);
                }

                foreach (var kv in identicalComponentsDict)
                {
                    if (kv.Value.Count > 1)
                    {
                        var index = 0;
                        foreach (var validMethods in kv.Value)
                        {
                            validMethods.identicalComponentIndex = index;
                            index++;
                        }
                    }
                }
                return(result);
            }
            return(new List <ValidMethods>());
        }
Beispiel #2
0
        public CommandResponse ParseCommand()
        {
            var message = new StringBuilder();

            if (string.IsNullOrWhiteSpace(_resource))
            {
                return CommandResponse.Set(false, $"The Resource OPTION is missing. All requests require a Resource type to be specified.");
            }

            message.AppendLine("Resource: " + _resource);
            message.AppendLine("Format: " + _format);

            if (_headers == null || !_headers.Any())
            {
                return CommandResponse.Set(false, $"All requests requires the setheaders option.");
            }

            if (!ValidMethods.Contains(_method))
            {
                return CommandResponse.Set(false, $"The Method {_method} is invalid.");
            }

            if (_method == "get" || _method == "delete" || _method == "put")
            {
                if (_parameters == null || !_parameters.Any())
                {
                    return CommandResponse.Set(false, $"The Parameters OPTION is missing or invalid. The GET, PUT and DELETE method requires parameters.");
                }

                message.AppendLine("Parameters: " + _parameters);
            }

            if ((_method == "put" || _method == "post"))
            {
                if (!string.IsNullOrWhiteSpace(_body))
                {
                    try
                    {
                        _pointerBody = JsonConvert.DeserializeObject<NrlsPointerBody>(_body);
                    }
                    catch(Exception ex)
                    {
                        return CommandResponse.Set(false, $"The Body OPTION is invalid. Exception Message: {ex.Message}");
                    }

                }
                else if (!string.IsNullOrWhiteSpace(_input))
                {
                    var inputLocation = GetInputLocation();

                    if (inputLocation == null)
                    {
                        return CommandResponse.Set(false, $"The Input OPTION is invalid. See --help for more details.");
                    }
                    else
                    {
                        if (!inputLocation.Success)
                        {
                            return inputLocation;
                        }

                        try
                        {
                            var jsonParser = new FhirJsonParser();
                            var pointer = File.ReadAllText(inputLocation.Result);
                            _pointer = jsonParser.Parse<DocumentReference>(pointer);
                        }
                        catch(Exception ex)
                        {
                            return CommandResponse.Set(false, $"Error trying to parse input. Exception Message: {ex.Message}");
                        }
                        
                       
                    }
                }
                else
                {
                    return CommandResponse.Set(false, $"Both the Body OPTION and the Input OPTION are missing. PUT and POST methods require at least one.");
                }
            }

            ////not for beta
            //if (_method == "put")
            //{
            //    //its now a parameter
            //    if (string.IsNullOrWhiteSpace(_uniqueId))
            //    {
            //        return CommandResponse.Set(false, $"The id OPTION is missing. PUT methods require a id.");
            //    }

            //    message.AppendLine("id: " + _uniqueId);
            //}

            return CommandResponse.Set(true, message.ToString());
        }