public bool SendCommandToManager(ServiceType type, string data) { try { if (data != null && !data.Equals(String.Empty)) { _proxy.Invoke(type, data); return(true); } return(false); } catch (Exception ex) { LogServer.LogException(ex, General.EXCEPTION_GENERAL, $"A problem occured while communicating with device of type {type}"); return(false); } }
public object GetPropertyFromManager(ServiceType type, string data) { try { if (data != null && !data.Equals(String.Empty)) { var temp = _proxy.GetPropertyData(type, data); DataBoundary serialized = JsonConvert.DeserializeObject <DataBoundary>(temp.ToString()); var vals = serialized.Attributes.FirstOrDefault(); object reflected = ((JArray)vals.Value).ToObject(Type.GetType(vals.Key.ToString())); return(reflected); } return(null); } catch (Exception ex) { LogServer.LogException(ex, STT.General.EXCEPTION_GENERAL, $"A problem occured while communicating with device of type {type}"); return(null); } }
private object ServiceGenericLogic(ServiceType type, string data) { try { if (OperationContext.Current != null) { IPublishing registeredUser = OperationContext.Current.GetCallbackChannel <IPublishing>(); var result = false; if (!_callbackList.Contains(new KeyValuePair <ServiceType, IPublishing>(type, registeredUser))) { result = _callbackList.TryAdd(type, registeredUser); } } IManager manager; object childManager = null; DataBoundary serializedObject = JsonConvert.DeserializeObject <DataBoundary>(data); if (Services.TryGetValue(type, out manager) && serializedObject != null) { MethodInfo method; if (serializedObject.TypeName != string.Empty && serializedObject.TypeName != null) { method = manager.GetType().GetMethod(serializedObject.TypeName); childManager = method.Invoke(manager, new object[0]); method = childManager.GetType().GetMethod(serializedObject.CommandName); } else { method = manager.GetType().GetMethod(serializedObject.CommandName); } if (method != null) { List <object> parameters = new List <object>(); foreach (var val in serializedObject.Attributes) { var typo = Type.GetType(val.Key.ToString()); if (typo.IsEnum) { parameters.Add(Enum.Parse(typo, val.Value.ToString())); } else { parameters.Add(val.Value.ToString()); } } object result; if (childManager != null) { result = method.Invoke(childManager, parameters.ToArray()); } else { result = method.Invoke(manager, parameters.ToArray()); } serializedObject.Attributes.Clear(); serializedObject.Attributes.Add(method.ReturnType, result); return(JsonConvert.SerializeObject(serializedObject)); } } return(null); } catch (Exception e) { LogServer.LogException(e, General.EXCEPTION_GENERAL); return(null); } }