コード例 #1
0
ファイル: Response.cs プロジェクト: LBNunes/Avatar
        public static Response FromJSON(object json)
        {
            Response r = new Response();
            Message.FromJSON(r, json);

            r.responseData = Util.JsonOptField(json as IDictionary<string, object>, "responseData") as IDictionary<string, object>;

            return r;
        }
コード例 #2
0
ファイル: DeviceDriver.cs プロジェクト: LBNunes/Avatar
        public void Handshake(Call serviceCall, Response serviceResponse, CallContext messageContext)
        {
            string deviceParameter = serviceCall.GetParameterString(DEVICE_KEY);

            if (deviceParameter == null)
            {
                serviceResponse.error = "No 'device' parameter informed.";
                return;
            }

            try
            {
                UpDevice device = UpDevice.FromJSON(Json.Deserialize(deviceParameter));

                gateway.deviceManager.RegisterDevice(device);

                serviceResponse.AddParameter(DEVICE_KEY, Json.Serialize(gateway.currentDevice.ToJSON()));

                //TODO: actually implement the driver register for other devices...
                //Response driversResponse = gateway.CallService(device, new Call("uos.DeviceDriver", "listDrivers"));
                //object driverList = driversResponse.GetResponseData("driverList");
                //if (driverList != null)
                //{
                //    var driverMap = (IDictionary<string, object>)Json.Deserialize(driverList.ToString());
                //    // TODO: this is duplicated with DeviceManager.registerRemoteDriverInstances
                //    foreach (string id in driverMap.Keys)
                //    {
                //        UpDriver upDriver = UpDriver.FromJSON(Json.Deserialize(driverMap[id].ToString()));
                //        DriverModel driverModel = new DriverModel(id, upDriver, device.name);
                //        gateway.driverManager.Insert(driverModel);
                //    }
                //}
            }
            catch (System.Exception e)
            {
                serviceResponse.error = e.Message;
                logger.LogError("Problems on handshake: " + e.Message + "," + e.StackTrace);
            }
        }
コード例 #3
0
        public Response CallService(object instance, Call call, CallContext context)
        {
            MethodInfo method = FindMethod(call, instance);

            if (method != null)
            {
                logger.Log(
                    "Calling service '" + call.service + "' of driver '" + call.driver + "' on instance '" + call.instanceId + "'");

                HandleStreamCall(call, context);

                Response response = new Response();
                method.Invoke(instance, new object[] { call, response, context });

                logger.Log("Finished service call.");
                return response;
            }
            else
                throw new System.Exception(
                    "No Service Implementation found for service '" + call.service +
                    "' on driver '" + call.driver + "' with id '" + call.instanceId + "'.");
        }
コード例 #4
0
ファイル: DeviceDriver.cs プロジェクト: LBNunes/Avatar
 public void Goodbye(Call serviceCall, Response serviceResponse, CallContext messageContext)
 {
     gateway.deviceManager.DeviceLeft(messageContext.callerNetworkDevice);
 }
コード例 #5
0
ファイル: DeviceDriver.cs プロジェクト: LBNunes/Avatar
        /// <summary>
        /// This method is responsible for informing the unknown equivalent driverss.
        /// </summary>
        /// <param name="serviceCall"></param>
        /// <param name="serviceResponse"></param>
        /// <param name="messageContext"></param>
        public void TellEquivalentDrivers(Call serviceCall, Response serviceResponse, CallContext messageContext)
        {
            try
            {
                string equivalentDrivers = serviceCall.GetParameterString(DRIVERS_NAME_KEY);
                IList<object> equivalentDriversJson = Json.Deserialize(equivalentDrivers) as IList<object>;
                List<object> jsonList = new List<object>();
                IDictionary<string, object> responseData = new Dictionary<string, object>();

                for (int i = 0; i < equivalentDriversJson.Count; i++)
                {
                    string equivalentDriver = equivalentDriversJson[i] as string;
                    UpDriver driver = gateway.driverManager.GetDriverFromEquivalanceTree(equivalentDriver);

                    if (driver != null)
                        AddToEquivalanceList(jsonList, driver);
                }

                responseData[INTERFACES_KEY] = Json.Serialize(jsonList);
                serviceResponse.responseData = responseData;
            }
            catch (System.Exception e)
            {
                logger.LogError("Problems on equivalent drivers. " + e.StackTrace);
            }
        }
コード例 #6
0
ファイル: DeviceDriver.cs プロジェクト: LBNunes/Avatar
        public void ListDrivers(Call serviceCall, Response serviceResponse, CallContext messageContext)
        {
            logger.Log("Handling DeviceDriverImpl#listDrivers service");

            try
            {
                IDictionary<string, object> parameters = serviceCall.parameters;
                DriverManager driverManager = gateway.driverManager;

                // Handles parameters to filter message...
                IList<DriverData> listDrivers =
                    driverManager.ListDrivers(
                        ((parameters != null) ? (parameters[DRIVER_NAME_KEY] as string) : null),
                        gateway.currentDevice.name
                    );

                IDictionary<string, object> driversList = new Dictionary<string, object>();
                if ((listDrivers != null) && (listDrivers.Count > 0))
                {
                    foreach (var driver in listDrivers)
                        driversList[driver.instanceID] = driver.driver.ToJSON();
                }

                IDictionary<string, object> responseData = new Dictionary<string, object>();
                responseData[DRIVER_LIST_KEY] = driversList;
                serviceResponse.responseData = responseData;
            }
            catch (System.Exception e)
            {
                serviceResponse.error = e.Message;
                logger.LogError("Problem on ListDrivers service: " + e.Message + "," + e.StackTrace);
            }
        }
コード例 #7
0
ファイル: GatewayServer.cs プロジェクト: LBNunes/Avatar
        private Response HandleServiceCall(string message, CallContext messageContext)
        {
            try
            {
                Call serviceCall = Call.FromJSON(Json.Deserialize(message));
                Response response = gateway.HandleServiceCall(serviceCall, messageContext);
                logger.Log("Returning service response");
                return response;
            }
            catch (System.Exception e)
            {
                PushLog("Internal Failure: ", e);

                Response errorResponse = new Response();
                errorResponse.error = e.Message == null ? "Internal Error" : e.Message;
                return errorResponse;
            }
        }