CreateUnchecked() static private method

static private CreateUnchecked ( string text, WoopsaValueType type, System.DateTime timestamp = null ) : WoopsaValue
text string
type WoopsaValueType
timestamp System.DateTime
return WoopsaValue
Beispiel #1
0
        public static WoopsaValue ToWoopsaValue(object value, WoopsaValueType type, DateTime?timeStamp = null)
        {
            try
            {
                switch (type)
                {
                case WoopsaValueType.Logical:
                    return(new WoopsaValue((bool)value, timeStamp));

                case WoopsaValueType.Integer:
                    return(new WoopsaValue(Convert.ToInt64(value), timeStamp));

                case WoopsaValueType.Real:
                    return(new WoopsaValue(Convert.ToDouble(value), timeStamp));

                case WoopsaValueType.DateTime:
                    return(new WoopsaValue((DateTime)value, timeStamp));

                case WoopsaValueType.TimeSpan:
                    if (value is TimeSpan)
                    {
                        return(new WoopsaValue((TimeSpan)value, timeStamp));
                    }
                    else
                    {
                        return(new WoopsaValue(TimeSpan.FromSeconds(Convert.ToDouble(value)),
                                               timeStamp));
                    }

                case WoopsaValueType.Text:
                    if (value == null)
                    {
                        return(new WoopsaValue(string.Empty, timeStamp));
                    }
                    else if (value.GetType().IsEnum)
                    {
                        return(new WoopsaValue(value.ToString(), timeStamp));
                    }
                    else if (string.IsNullOrEmpty((string)value))
                    {
                        return(new WoopsaValue(string.Empty, timeStamp));
                    }
                    else
                    {
                        return(new WoopsaValue(WoopsaFormat.ToStringWoopsa(value), timeStamp));
                    }

                default:
                    return(WoopsaValue.CreateUnchecked(WoopsaFormat.ToStringWoopsa(value), type, timeStamp));
                }
            }
            catch (InvalidCastException)
            {
                throw new WoopsaException(String.Format("Cannot typecast object of type {0} to Woopsa Type {1}", value.GetType(), type.ToString()));
            }
        }
Beispiel #2
0
 private WoopsaValue HandleCall(IWoopsaValue requestsArgument)
 {
     using (new WoopsaServerModelAccessFreeSection(_server))
     {
         ServerRequest[] requestsList             = JsonSerializer.Deserialize <ServerRequest[]>(requestsArgument.AsText, WoopsaUtils.ObjectToInferredTypesConverterOptions);
         List <MultipleRequestResponse> responses = new List <MultipleRequestResponse>();
         foreach (var request in requestsList)
         {
             string result = null;
             try
             {
                 using (new WoopsaServerModelAccessLockedSection(_server))
                 {
                     if (request.Verb.Equals(WoopsaFormat.VerbRead))
                     {
                         result = _server.ReadValue(request.Path);
                     }
                     else if (request.Verb.Equals(WoopsaFormat.VerbMeta))
                     {
                         result = _server.GetMetadata(request.Path);
                     }
                     else if (request.Verb.Equals(WoopsaFormat.VerbWrite))
                     {
                         result = _server.WriteValueDeserializedJson(request.Path, request.Value);
                     }
                     else if (request.Verb.Equals(WoopsaFormat.VerbInvoke))
                     {
                         result = _server.InvokeMethodDeserializedJson(request.Path,
                                                                       request.Arguments);
                     }
                 }
             }
             catch (Exception e)
             {
                 result = WoopsaFormat.Serialize(e);
             }
             MultipleRequestResponse response = new MultipleRequestResponse();
             response.Id     = request.Id;
             response.Result = result;
             responses.Add(response);
         }
         return(WoopsaValue.CreateUnchecked(responses.Serialize(), WoopsaValueType.JsonData));
     }
 }
 protected void EnqueueNewMonitoredValue(IWoopsaValue newValue)
 {
     if (!newValue.IsSameValue(_oldValue))
     {
         _oldValue = newValue;
         if (newValue.TimeStamp == null)
         {
             newValue = WoopsaValue.CreateUnchecked(newValue.AsText, newValue.Type, DateTime.Now);
         }
         WoopsaServerNotification newNotification = new WoopsaServerNotification(newValue, SubscriptionId);
         lock (_lock)
         {
             if (MonitorInterval == WoopsaSubscriptionServiceConst.MonitorIntervalLastPublishedValueOnly)
             {
                 _notifications.Clear();
             }
             _notifications.Add(newNotification);
         }
     }
 }
Beispiel #4
0
        internal string WriteValue(string path, string value)
        {
            IWoopsaElement item = FindByPath(path);

            if ((item is IWoopsaProperty))
            {
                IWoopsaProperty property = item as IWoopsaProperty;
                if (property.IsReadOnly)
                {
                    throw new WoopsaInvalidOperationException(String.Format(
                                                                  "Cannot write a read-only WoopsaProperty for path {0}", path));
                }
                property.Value = WoopsaValue.CreateUnchecked(value, property.Type);
                return(property.Value.Serialize());
            }
            else
            {
                throw new WoopsaInvalidOperationException(String.Format("Cannot write value of a non-WoopsaProperty for path {0}", path));
            }
        }
Beispiel #5
0
        private WoopsaValue HandleCall(IWoopsaValue requestsArgument)
        {
            var serializer = new JavaScriptSerializer();

            ServerRequest[] requestsList             = serializer.Deserialize <ServerRequest[]>(requestsArgument.AsText);
            List <MultipleRequestResponse> responses = new List <MultipleRequestResponse>();

            foreach (var request in requestsList)
            {
                string result = null;
                try
                {
                    if (request.Verb.Equals(WoopsaFormat.VerbRead))
                    {
                        result = _server.ReadValue(request.Path);
                    }
                    else if (request.Verb.Equals(WoopsaFormat.VerbMeta))
                    {
                        result = _server.GetMetadata(request.Path);
                    }
                    else if (request.Verb.Equals(WoopsaFormat.VerbWrite))
                    {
                        result = _server.WriteValueDeserializedJson(request.Path, request.Value);
                    }
                    else if (request.Verb.Equals(WoopsaFormat.VerbInvoke))
                    {
                        result = _server.InvokeMethodDeserializedJson(request.Path,
                                                                      request.Arguments);
                    }
                }
                catch (Exception e)
                {
                    result = WoopsaFormat.Serialize(e);
                }
                MultipleRequestResponse response = new MultipleRequestResponse();
                response.Id     = request.Id;
                response.Result = result;
                responses.Add(response);
            }
            return(WoopsaValue.CreateUnchecked(responses.Serialize(), WoopsaValueType.JsonData));
        }
Beispiel #6
0
 internal string WriteValue(string path, string value)
 {
     return(WriteValue(path, (woopsaValueType) => WoopsaValue.CreateUnchecked(value, woopsaValueType)));
 }