CreateChecked() 공개 정적인 메소드

public static CreateChecked ( string text, WoopsaValueType type, System.DateTime timestamp = null ) : WoopsaValue
text string
type WoopsaValueType
timestamp System.DateTime
리턴 WoopsaValue
예제 #1
0
        public static WoopsaValue DeserializeWoopsaValue(string jsonText)
        {
            var result = JsonSerializer.Deserialize <WoopsaReadResult>(jsonText);

            if (result != null)
            {
                var         valueType = (WoopsaValueType)Enum.Parse(typeof(WoopsaValueType), result.Type);
                WoopsaValue resultWoopsaValue;
                DateTime?   timeStamp;
                if (result.TimeStamp != null)
                {
                    timeStamp = DateTime.Parse(result.TimeStamp, CultureInfo.InvariantCulture);
                }
                else
                {
                    timeStamp = null;
                }
                if (valueType == WoopsaValueType.JsonData)
                {
                    resultWoopsaValue = new WoopsaValue(WoopsaJsonData.CreateFromDeserializedData(result.Value), timeStamp);
                }
                else
                {
                    resultWoopsaValue = WoopsaValue.CreateChecked(WoopsaFormat.ToStringWoopsa(result.Value),
                                                                  valueType, timeStamp);
                }
                return(resultWoopsaValue);
            }
            else
            {
                return(WoopsaValue.Null);
            }
        }
예제 #2
0
        internal string InvokeMethod(string path, NameValueCollection arguments)
        {
            int argumentsCount = arguments != null ? arguments.Count : 0;

            return(InvokeMethod(path, argumentsCount,
                                (argumentName, woopsaValueType) =>
            {
                string argumentValue = arguments[argumentName];
                if (argumentValue != null)
                {
                    return WoopsaValue.CreateChecked(argumentValue, woopsaValueType);
                }
                else
                {
                    return null;
                }
            }));
        }
예제 #3
0
        internal string InvokeMethod(string path, NameValueCollection arguments)
        {
            IWoopsaElement item = FindByPath(path);

            if (item is IWoopsaMethod)
            {
                int           argumentsCount = arguments != null ? arguments.Count : 0;
                IWoopsaMethod method         = item as IWoopsaMethod;
                if (argumentsCount == method.ArgumentInfos.Count())
                {
                    List <WoopsaValue> woopsaArguments = new List <WoopsaValue>();
                    foreach (var argInfo in method.ArgumentInfos)
                    {
                        string argumentValue = arguments[argInfo.Name];
                        if (argumentValue == null)
                        {
                            throw new WoopsaInvalidOperationException(String.Format(
                                                                          "Missing argument {0} for method {1}", argInfo.Name, item.Name));
                        }
                        woopsaArguments.Add(WoopsaValue.CreateChecked(argumentValue, argInfo.Type));
                    }
                    IWoopsaValue result = method.Invoke(woopsaArguments.ToArray());
                    return(result != null?result.Serialize() : WoopsaConst.WoopsaNull);
                }
                else
                {
                    throw new WoopsaInvalidOperationException(String.Format(
                                                                  "Wrong argument count for method {0}", item.Name));
                }
            }
            else
            {
                throw new WoopsaInvalidOperationException(String.Format(
                                                              "Cannot invoke a {0}", item.GetType()));
            }
        }