Example #1
0
        public string PingMac(string mac)
        {
            var model = new DevicesRequestJSON()
            {
                docTemplate = new List <string>
                {
                    "*"
                },
                pageNumber = 1,
                pageSize   = 50
            };
            //00:13:50:05:00:11:90:e6
            string jsonBody = JsonConvert.SerializeObject(model);

            SLDPAPI.SilverLink link = new SilverLink();
            link.ClientID   = "u9p7PiX9b35jgZuQAxqsMw1tfcRSZKTA"; //Chieh-min="u9p7PiX9b35jgZuQAxqsMw1tfcRSZKTA";// Mike's="DY8WxUI4oveZU2sWu3dkoNjCkEUB1Tsh";
            link.Secret     = "ZY3GjWNDWMI67ASH";                 //Chieh-min="ZY3GjWNDWMI67ASH";// Mike's="vgWI2nZ1rQIS3Acm";
            link.CustomerID = "starfishstaging";
            string CustomerID = "starfishstaging";

            //link.BaseURL = "https://api.silverlink.silverspringnet.com/v2/streamingintervals/starfishstaging";//https://api.silverlink.silverspringnet.com/sdp/v1/ping/starfishstaging?nic_macId=001350050005E7D6
            link.BaseURL = "https://api.silverlink.silverspringnet.com";
            // GET https://api.silverlink.silverspringnet.com/sdp/v1/webhook/hke?nic_macid=00beef1f000f051d

            string resp = link.Get("/sdp/v1/ping/" + CustomerID + "?nic_macid=" + mac, CustomerID);

            return(resp);
        }
        /// <summary>
        /// Fetch a list of devices, in JSON format, from the Gateway.
        /// </summary>
        /// <returns>A JSON document containing the available devices.</returns>
        public DevicesResponse GetDevices()
        {
            var json = "";

            SLDPAPI.SilverLink link = new SilverLink();

            // Set up the SLDP API request.
            link.ClientID  = GatewaySettings.Instance.ClientId;
            link.Secret    = GatewaySettings.Instance.ClientSecret;
            link.Solution  = GatewaySettings.Instance.Solution;
            link.BaseURL   = GatewaySettings.Instance.GatewayBaseURL;
            link.TokenPath = GatewaySettings.Instance.GatewayTokens;

            FileLogger.Write("About to send Gateway request");
            FileLogger.Write("Customer Id = " + GatewaySettings.Instance.Solution);
            FileLogger.Write("Base URL = " + GatewaySettings.Instance.GatewayBaseURL);
            FileLogger.Write("Path = " + GatewaySettings.Instance.GatewayDeviceSearch);

            try
            {
                string path = GatewaySettings.Instance.GatewayDeviceSearch.Replace("<solution>", GatewaySettings.Instance.Solution);
                FileLogger.Write("About to send Gateway request");
                FileLogger.Write("Customer Id = " + GatewaySettings.Instance.Solution);
                FileLogger.Write("Base URL = " + GatewaySettings.Instance.GatewayBaseURL);
                FileLogger.Write("Path = " + path);
                json = link.Get(path);
            }
            catch (Exception e)
            {
                FileLogger.Write("Get failed");
                FileLogger.Write(e.Message);
                FileLogger.Write(e.StackTrace);

                // Rethrow the error if the POST failed.
                throw e;
            }
            FileLogger.Write("JSON response = " + json);

            GatewaySettings.Instance.SfdpToken = link.SilverLinkToken;
            FileLogger.Write("Token acquired from SFDP");
            FileLogger.Write(GatewaySettings.Instance.SfdpToken);

            DevicesResponse devices = null;

            try
            {
                devices = JsonConvert.DeserializeObject <DevicesResponse>(json);
            }
            catch (Exception jsonDeserializeError)
            {
                FileLogger.Write("Error deserializing device search response");
                FileLogger.Write(jsonDeserializeError.Message);
                FileLogger.Write(jsonDeserializeError.Message);
            }

            return(devices);
        }