Beispiel #1
0
        private void OnRegisterEmbodiment(RESTConnector.Request req, RESTConnector.Response resp)
        {
            RegisterEmbodimentReq ereq = req as RegisterEmbodimentReq;

            if (resp.Success)
            {
                try {
                    IDictionary json         = Json.Deserialize(Encoding.UTF8.GetString(resp.Data)) as IDictionary;
                    string      embodimentId = json["_id"] as string;
                    string      token        = json["embodimentToken"] as string;

                    if (ereq.Callback != null)
                    {
                        ereq.Callback(token, embodimentId);
                    }
                }
                catch (Exception e)
                {
                    Log.Error("TopicClient", "OnRegisterEmbodiment Exception: {0}", e.ToString());
                    resp.Success = false;
                }
            }

            if (!resp.Success && ereq.Callback != null)
            {
                ereq.Callback(null, null);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Register an embodiment with the gateway.
        /// </summary>
        /// <param name="a_GroupId"></param>
        /// <param name="a_OrgId"></param>
        /// <param name="a_BearerToken"></param>
        /// <param name="a_EmbodimentName"></param>
        /// <param name="a_EmbodimentType"></param>
        /// <param name="a_Callback"></param>
        /// <returns></returns>
        public bool RegisterEmbodiment(string a_GroupId,
                                       string a_OrgId,
                                       string a_BearerToken,
                                       string a_EmbodimentName,
                                       string a_EmbodimentType,
                                       OnRegisteredEmbodiment a_Callback)
        {
            RESTConnector connection = RESTConnector.GetConnector(SERVICE_ID, "/v1/auth/registerEmbodiment");

            if (connection == null)
            {
                Log.Error("TopicClient", "RobotGatewayV1 service credentials not found.");
                return(false);
            }

            Dictionary <string, string> headers = new Dictionary <string, string>();

            headers["Content-Type"]  = "application/json";
            headers["Authorization"] = "Bearer " + a_BearerToken;
            headers["groupId"]       = a_GroupId;
            headers["orgId"]         = a_OrgId;
            headers["macId"]         = Utility.MacAddress;

            Dictionary <string, object> json = new Dictionary <string, object>();

            json["embodimentName"]  = a_EmbodimentName;
            json["type"]            = a_EmbodimentType;
            json["groupId"]         = a_GroupId;
            json["orgId"]           = a_OrgId;
            json["macId"]           = Utility.MacAddress;
            json["embodimentToken"] = "token";

            RegisterEmbodimentReq req = new RegisterEmbodimentReq();

            req.Send     = Encoding.UTF8.GetBytes(Json.Serialize(json));
            req.Headers  = headers;
            req.Callback = a_Callback;

            req.OnResponse += OnRegisterEmbodiment;
            return(connection.Send(req));
        }