public static object ToBaseType(this IWoopsaValue value) { switch (value.Type) { case WoopsaValueType.Null: return(null); case WoopsaValueType.Logical: return(value.ToBool()); case WoopsaValueType.Integer: return(value.ToInt64()); case WoopsaValueType.Real: return(value.ToDouble()); case WoopsaValueType.DateTime: return(value.ToDateTime()); case WoopsaValueType.TimeSpan: return(value.ToTimeSpan()); case WoopsaValueType.Text: case WoopsaValueType.WoopsaLink: case WoopsaValueType.JsonData: case WoopsaValueType.ResourceUrl: return(value.AsText); default: return(null); } }
protected override bool GetWatchedPropertyValue(out IWoopsaValue value) { try { if (_watchedProperty is WoopsaElement) { if (((WoopsaElement)_watchedProperty).IsDisposed) { _watchedProperty = null; } } if (_watchedProperty == null) { var item = Root.ByPathOrNull(PropertyPath); _watchedProperty = item as IWoopsaProperty; } if (_watchedProperty != null) { value = _watchedProperty.Value; return(true); } else { value = WoopsaValue.Null; return(true); } } catch (Exception) { // The property might have become invalid, search it new the next time _watchedProperty = null; throw; } }
public static string Serialize(this IWoopsaValue value) { StringBuilder stringBuilder = new StringBuilder(); Serialize(stringBuilder, value); return(stringBuilder.ToString()); }
public static void DecodeWoopsaLink(this IWoopsaValue value, out string woopsaServerUrl, out string woopsaItemPath) { if (value.Type == WoopsaValueType.WoopsaLink) { string[] parts = value.AsText.Split(WoopsaConst.WoopsaLinkSeparator); if (parts.Length == 1) { woopsaServerUrl = null; woopsaItemPath = WoopsaUtils.RemoveInitialSeparator(parts[0]); } else if (parts.Length == 2) { woopsaServerUrl = parts[0]; woopsaItemPath = WoopsaUtils.RemoveInitialSeparator(parts[1]); } else { throw new WoopsaException(string.Format("Badly formed WoopsaLink {0} ", value.AsText)); } } else { throw new WoopsaException(string.Format("Cannot decode WoopsaValue of type {0} as a WoopsaLink", value.Type)); } }
public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result) { result = null; foreach (var method in InnerObject.Methods) { if (method.Name.Equals(binder.Name)) { var argumentInfos = method.ArgumentInfos.ToArray(); var arguments = new IWoopsaValue[argumentInfos.Length]; for (int i = 0; i < argumentInfos.Length; i++) { WoopsaValueType woopsaValueType; WoopsaConverter woopsaConverter; if (CustomTypeConverters != null) { CustomTypeConverters.InferWoopsaType(args[i].GetType(), out woopsaValueType, out woopsaConverter); arguments[i] = woopsaConverter.ToWoopsaValue(args[i], woopsaValueType, null); } else { arguments[i] = WoopsaValue.ToWoopsaValue(args[i], argumentInfos[i].Type); } } result = method.Invoke(arguments); return(true); } } return(false); }
protected override bool GetWatchedPropertyValue(out IWoopsaValue value) { try { IWoopsaProperty currentlyWatchedProperty; IWoopsaValue currentlyWatchedPropertyValue; if ((_watchedProperty == null) || (_watchedProperty is WoopsaElement && ((WoopsaElement)_watchedProperty).IsDisposed)) { IWoopsaProperty newWatchedProperty; newWatchedProperty = Root.ByPathOrNull(PropertyPath) as IWoopsaProperty; if (newWatchedProperty != null) { currentlyWatchedProperty = newWatchedProperty; currentlyWatchedPropertyValue = currentlyWatchedProperty.Value; } else { currentlyWatchedProperty = _watchedProperty; currentlyWatchedPropertyValue = WoopsaValue.Null; } } else { currentlyWatchedProperty = _watchedProperty; currentlyWatchedPropertyValue = _watchedProperty.Value; } if (currentlyWatchedProperty != null) { if (OnCanWatch(this, currentlyWatchedProperty)) { value = currentlyWatchedPropertyValue; _watchedProperty = currentlyWatchedProperty; return(true); } else { value = WoopsaValue.Null; return(false); } } else { value = WoopsaValue.Null; return(true); } } catch (Exception) { // The property might have become invalid, search it new the next time _watchedProperty = null; throw; } }
public static bool ToBool(this IWoopsaValue value) { if (value.Type == WoopsaValueType.Logical) { return(WoopsaFormat.ToBool(value.AsText)); } else { throw new WoopsaException(WoopsaExceptionMessage.WoopsaCastTypeMessage("bool", value.Type.ToString())); } }
public static string JsonValueText(this IWoopsaValue value) { if (MustQuote(value.Type)) { return(ValueEscapeCharacter + JsonEscape(value.AsText) + ValueEscapeCharacter); } else { return(value.AsText); } }
public override object FromWoopsaValue(IWoopsaValue value, Type targetType) { if (targetType == typeof(decimal)) { return(decimal.Parse(value.AsText)); } else { return(base.FromWoopsaValue(value, targetType)); } }
public static string DecodeWoopsaLocalLink(this IWoopsaValue value) { DecodeWoopsaLink(value, out string woopsaServerUrl, out string woopsaItemPath); if (woopsaServerUrl == null) // it is a local path { return(woopsaItemPath); } else { throw new WoopsaException(String.Format("{0} is not a local woopsa link", value.AsText)); } }
protected bool GetSynchronizedWatchedPropertyValue(out IWoopsaValue value) { Channel.OnBeforeWoopsaModelAccess(); try { return(GetWatchedPropertyValue(out value)); } finally { Channel.OnAfterWoopsaModelAccess(); } }
protected override bool GetWatchedPropertyValue(out IWoopsaValue value) { try { value = ((WoopsaBaseClientObject)Root).Client.ClientProtocol.Read(PropertyPath); return(true); } catch { value = null; return(false); } }
private string InvokeMethod(string path, int argumentsCount, Func <string, WoopsaValueType, WoopsaValue> getArgumentByName) { IWoopsaElement item = FindByPath(path); if (item is IWoopsaMethod) { IWoopsaMethod method = item as IWoopsaMethod; if (argumentsCount == method.ArgumentInfos.Count()) { List <WoopsaValue> woopsaArguments = new List <WoopsaValue>(); foreach (var argInfo in method.ArgumentInfos) { WoopsaValue argumentValue = getArgumentByName(argInfo.Name, argInfo.Type); if (argumentValue == null) { string message = String.Format("Missing argument {0} for method {1}", argInfo.Name, item.Name); OnLog(WoopsaVerb.Invoke, path, NoArguments, message, false); throw new WoopsaInvalidOperationException(message); } else { woopsaArguments.Add(argumentValue); } } WoopsaValue[] argumentsArray = woopsaArguments.ToArray(); IWoopsaValue methodResult = method.Invoke(argumentsArray); string result = methodResult != null?methodResult.Serialize() : WoopsaConst.WoopsaNull; OnLog(WoopsaVerb.Invoke, path, argumentsArray, result, true); return(result); } else { string message = String.Format("Wrong argument count for method {0}", item.Name); OnLog(WoopsaVerb.Invoke, path, NoArguments, message, false); throw new WoopsaInvalidOperationException(message); } } else { string message = String.Format("Cannot invoke a {0}", item.GetType()); OnLog(WoopsaVerb.Invoke, path, NoArguments, message, false); throw new WoopsaInvalidOperationException(message); } }
public static int ToInt32(this IWoopsaValue value) { if (value.Type == WoopsaValueType.Integer) { if (WoopsaFormat.TryParseWoopsa(value.AsText, out int result)) { return(result); } else { throw new WoopsaException(WoopsaExceptionMessage.WoopsaCastValueMessage("Int32", value.AsText)); } } else { throw new WoopsaException(WoopsaExceptionMessage.WoopsaCastTypeMessage("Int32", value.Type.ToString())); } }
public static TimeSpan ToTimeSpan(this IWoopsaValue value) { if (value.Type == WoopsaValueType.TimeSpan) { if (WoopsaFormat.TryParseWoopsa(value.AsText, out double result)) { return(TimeSpan.FromSeconds(result)); } else { throw new WoopsaException(WoopsaExceptionMessage.WoopsaCastValueMessage("TimeSpan", value.AsText)); } } else { throw new WoopsaException(WoopsaExceptionMessage.WoopsaCastTypeMessage("TimeSpan", value.Type.ToString())); } }
public static DateTime ToDateTime(this IWoopsaValue value) { if (value.Type == WoopsaValueType.DateTime) { if (DateTime.TryParse(value.AsText, CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind, out var result)) { return(result); } else { throw new WoopsaException(WoopsaExceptionMessage.WoopsaCastValueMessage("DateTime", value.AsText)); } } else { throw new WoopsaException(WoopsaExceptionMessage.WoopsaCastTypeMessage("DateTime", value.Type.ToString())); } }
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)); } }
public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result) { result = null; foreach (var method in InnerObject.Methods) { if (method.Name.Equals(binder.Name)) { var argumentInfos = method.ArgumentInfos.ToArray(); var arguments = new IWoopsaValue[argumentInfos.Length]; for (int i = 0; i < argumentInfos.Length; i++) { arguments[i] = WoopsaValue.ToWoopsaValue(args[i], argumentInfos[i].Type); } result = method.Invoke(arguments); return(true); } } return(false); }
/// <summary> /// Compare the values ignoring the timestamp /// </summary> public static bool IsSameValue(this IWoopsaValue left, IWoopsaValue right) { if (left != null) { if (right != null) { return(left.Type == right.Type && left.AsText == right.AsText); } else { return(false); } } else { return(right == null); } }
public void TestWoopsaObjects() { WoopsaRoot root = new WoopsaRoot(); WoopsaObject tunnel1 = new WoopsaObject(root, "Tunnel1"); Assert.AreEqual(root.Items.Count(), 1); WoopsaObject tunnel2 = new WoopsaObject(root, "Tunnel2"); Assert.AreEqual(root.Items.Count(), 2); WoopsaObject coMessung1 = new WoopsaObject(tunnel1, "CoMessung1"); Assert.AreEqual(coMessung1.GetPath(), "/Tunnel1/CoMessung1"); WoopsaProperty property1 = new WoopsaProperty(coMessung1, "Level", WoopsaValueType.Real, (sender) => 1040.0); int property2Value = 0; WoopsaProperty property2 = new WoopsaProperty(coMessung1, "Variation", WoopsaValueType.Real, (sender) => property2Value, (sender, value) => property2Value = value.ToInt32()); Assert.AreEqual(coMessung1.Properties.Count(), 2); Assert.AreEqual(coMessung1.Properties.First().Value.ToDouble(), 1040.0); coMessung1.Properties.ByName("Variation").Value = 45; Assert.AreEqual(coMessung1.Properties.ByName("Variation").Value.ToInt32(), 45); Assert.AreEqual(coMessung1.Properties.ByName("Variation").Value.ToString(), "45"); (coMessung1.ByName("Variation") as IWoopsaProperty).Value = (WoopsaValue)36; Assert.AreEqual(coMessung1.Properties.ByName("Variation").Value.ToInt32(), 36); coMessung1.Properties["Variation"].Value = 5; Assert.AreEqual(property2Value, 5); int variation = coMessung1.Properties["Variation"].Value; Assert.AreEqual(variation, 5); WoopsaMethod method1 = new WoopsaMethod(coMessung1, "Calibrate", WoopsaValueType.Null, new WoopsaMethodArgumentInfo[] { new WoopsaMethodArgumentInfo("minLevel", WoopsaValueType.Real), new WoopsaMethodArgumentInfo("maxLevel", WoopsaValueType.Real) }, Calibrate); IWoopsaValue result = method1.Invoke(1.1, 5.5); Assert.AreEqual(result, WoopsaValue.Null); Assert.AreEqual(_minLevel, 1.1); Assert.AreEqual(_maxLevel, 5.5); }
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); } } }
public override bool Equals(object obj) { if (obj is IWoopsaValue) { IWoopsaValue right = (IWoopsaValue)obj; return(right.Type == _type && right.AsText == _text); } else if (obj == null && _type == WoopsaValueType.Null) { return(true); } else if (obj is bool && _type == WoopsaValueType.Logical) { return(((bool)obj) == (bool)this); } else if (obj is sbyte || obj is Int16 || obj is Int32 || obj is Int64) { return(Convert.ToInt64(obj) == (Int64)this); } else if (obj is Byte || obj is UInt16 || obj is UInt32 || obj is UInt64) { return(Convert.ToUInt64(obj) == (UInt64)this); } else if (obj is float || obj is double || obj is decimal) { return(Convert.ToDouble(obj) == (double)this); } else if (obj is DateTime) { return(((DateTime)obj) == (DateTime)this); } else if (obj is TimeSpan) { return(((TimeSpan)obj) == (TimeSpan)this); } else if (obj is string) { return((string)obj == _text); } return(base.Equals(obj)); }
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)); }
public static double ToDouble(this IWoopsaValue value) { if (value.Type == WoopsaValueType.Real) { if (WoopsaFormat.TryParseWoopsa(value.AsText, out double result)) { return(result); } else { throw new WoopsaException(WoopsaExceptionMessage.WoopsaCastValueMessage("double", value.AsText)); } } else if (value.Type == WoopsaValueType.Integer) { return(value.ToInt64()); } else { throw new WoopsaException(WoopsaExceptionMessage.WoopsaCastTypeMessage("double", value.Type.ToString())); } }
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())); } }
public static void Serialize(StringBuilder stringBuilder, IWoopsaValue value) { stringBuilder.Append(ElementOpen); // Value if (MustQuote(value.Type)) { SerializeKeyValue(stringBuilder, KeyValue, value.AsText, true, true); } else { SerializeKeyValue(stringBuilder, KeyValue, value.AsText, false, false); } stringBuilder.Append(ElementSeparator); // Type SerializeKeyValue(stringBuilder, KeyType, value.Type.ToString(), true, false); // TimeStamp if (value.TimeStamp.HasValue) { stringBuilder.Append(ElementSeparator); SerializeKeyValue(stringBuilder, KeyTimeStamp, WoopsaFormat.ToStringWoopsa(value.TimeStamp.Value), true, false); } stringBuilder.Append(ElementClose); }
protected override bool GetWatchedPropertyValue(out IWoopsaValue value) { try { if (_watchedProperty is WoopsaElement) if (((WoopsaElement)_watchedProperty).IsDisposed) _watchedProperty = null; if (_watchedProperty == null) { var item = Root.ByPathOrNull(PropertyPath); _watchedProperty = item as IWoopsaProperty; } if (_watchedProperty != null) { value = _watchedProperty.Value; return true; } else { value = WoopsaValue.Null; return true; } } catch (Exception) { // The property might have become invalid, search it new the next time _watchedProperty = null; throw; } }
public void WriteAdsValue(IWoopsaProperty property, IWoopsaValue value) { WoopsaAdsProperty adsProperty = (WoopsaAdsProperty)property; AdsStream stream = new AdsStream(); switch (property.Type) { case WoopsaValueType.Integer: if (adsProperty.AdsInfo.Type == BeckhoffValueType.WORD || adsProperty.AdsInfo.Type == BeckhoffValueType.UINT) stream = new AdsStream(BitConverter.GetBytes(value.ToUInt16())); else if (adsProperty.AdsInfo.Type == BeckhoffValueType.DWORD || adsProperty.AdsInfo.Type == BeckhoffValueType.UDINT) stream = new AdsStream(BitConverter.GetBytes(value.ToUInt32())); else if (adsProperty.AdsInfo.Type == BeckhoffValueType.SINT) stream = new AdsStream(BitConverter.GetBytes(value.ToSByte())); else if (adsProperty.AdsInfo.Type == BeckhoffValueType.INT) stream = new AdsStream(BitConverter.GetBytes(value.ToInt16())); else if (adsProperty.AdsInfo.Type == BeckhoffValueType.DINT) stream = new AdsStream(BitConverter.GetBytes(value.ToInt32())); else if (adsProperty.AdsInfo.Type == BeckhoffValueType.LINT) stream = new AdsStream(BitConverter.GetBytes(value.ToInt64())); else if (adsProperty.AdsInfo.Type == BeckhoffValueType.USINT || adsProperty.AdsInfo.Type == BeckhoffValueType.BYTE) { stream = new AdsStream(1); stream.WriteByte(value.ToByte()); } else if (adsProperty.AdsInfo.Type == BeckhoffValueType.ULINT) stream = new AdsStream(BitConverter.GetBytes(value.ToUInt64())); else throw new WoopsaException("Ads type not compatible with Woopsa Integer"); break; case WoopsaValueType.Logical: stream = new AdsStream(BitConverter.GetBytes(value.ToBool())); break; case WoopsaValueType.Real: if (adsProperty.AdsInfo.Type == BeckhoffValueType.REAL) stream = new AdsStream(BitConverter.GetBytes(value.ToFloat())); else if (adsProperty.AdsInfo.Type == BeckhoffValueType.LREAL) stream = new AdsStream(BitConverter.GetBytes(value.ToDouble())); else throw new WoopsaException("Ads type not compatible with Woopsa Real"); break; case WoopsaValueType.Text: stream = new AdsStream(80); byte[] byteString = System.Text.Encoding.ASCII.GetBytes(value.ToString()); stream.Write(byteString, 0, byteString.Length); break; case WoopsaValueType.TimeSpan: stream = new AdsStream(BitConverter.GetBytes((uint)(value.ToTimeSpan().Ticks / TimeSpan.TicksPerMillisecond))); break; case WoopsaValueType.DateTime: TimeSpan timeSp; DateTime dateTime; if (adsProperty.AdsInfo.Type == BeckhoffValueType.TIME_OF_DAY) { dateTime = value.ToDateTime(); uint timeOfDay = (uint)dateTime.Millisecond + ((uint)dateTime.Second + ((uint)dateTime.Minute + ((uint)dateTime.Hour * 60)) * 60) * 1000; stream = new AdsStream(BitConverter.GetBytes(timeOfDay)); } else { timeSp = value.ToDateTime() - BeckhoffPlcReferenceDateTime; stream = new AdsStream(BitConverter.GetBytes((uint)timeSp.TotalSeconds)); } break; default: stream = new AdsStream(1); break; } _tcAds.Write(adsProperty.AdsInfo.IndexGroup, adsProperty.AdsInfo.IndexOffset, stream); }
protected abstract bool GetWatchedPropertyValue(out IWoopsaValue value);
public WoopsaServerNotification(IWoopsaValue value, int subscriptionId) { Value = value; SubscriptionId = subscriptionId; }
public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result) { result = null; foreach (var method in InnerObject.Methods) { if (method.Name.Equals(binder.Name)) { var argumentInfos = method.ArgumentInfos.ToArray(); var arguments = new IWoopsaValue[argumentInfos.Length]; for (int i = 0; i < argumentInfos.Length; i++) arguments[i] = WoopsaValue.ToWoopsaValue(args[i], argumentInfos[i].Type); result = method.Invoke(arguments); return true; } } return false; }
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); } } }
private void SetProperty(IWoopsaProperty property, IWoopsaValue value) { Client.ClientProtocol.Write(this.GetPath(Root).TrimEnd(WoopsaConst.WoopsaPathSeparator) + WoopsaConst.WoopsaPathSeparator + property.Name, value.AsText); }
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); }
protected bool GetSynchronizedWatchedPropertyValue(out IWoopsaValue value) { Channel.OnBeforeWoopsaModelAccess(); try { return GetWatchedPropertyValue(out value); } finally { Channel.OnAfterWoopsaModelAccess(); } }
protected override bool GetWatchedPropertyValue(out IWoopsaValue value) { try { value = ((WoopsaBaseClientObject)Root).Client.ClientProtocol.Read(PropertyPath); return true; } catch { value = null; return false; } }
public static bool IsNull(this IWoopsaValue value) { return(value.Type == WoopsaValueType.Null); }
public static void Serialize(StringBuilder stringBuilder, IWoopsaValue value) { stringBuilder.Append(ElementOpen); // Value if (MustQuote(value.Type)) SerializeKeyValue(stringBuilder, KeyValue, value.AsText, true, true); else SerializeKeyValue(stringBuilder, KeyValue, value.AsText, false, false); stringBuilder.Append(ElementSeparator); // Type SerializeKeyValue(stringBuilder, KeyType, value.Type.ToString(), true, false); // TimeStamp if (value.TimeStamp.HasValue) { stringBuilder.Append(ElementSeparator); SerializeKeyValue(stringBuilder, KeyTimeStamp, WoopsaFormat.ToStringWoopsa(value.TimeStamp.Value), true, false); } stringBuilder.Append(ElementClose); }