示例#1
0
        /// <summary>
        /// Registers the device with the server.
        /// </summary>
        /// <param name="mac">Device's Mac address</param>
        /// <param name="sn">Device's Serial Number</param>
        /// <param name="model">Device's Model. Note that the model must be first created in the partner.syncpro.io portal</param>
        /// <param name="fwVersion">Device's FW version</param>
        /// <param name="partnerId">PartnerID - claim your at [email protected]</param>
        /// <returns>
        /// Returns the devices uuid and accessKey, which should be saved locally and used for every future API call.
        /// If fails, returns null.
        /// </returns>
        public static RegisterDeviceResponse RegisterDevice(string partnerId, string mac, string sn, string model, string fwVersion)
        {
            //First, assemble device registration data
            RegistrationData deviceRegData = new RegistrationData(mac, sn, model, fwVersion, partnerId);

            //Send registration request with device registration data as string
            HttpsClientResponse res = WebMethods.RegisterDevice(deviceRegData);

            if (res.Code == 422)
            {
                //Device is already registers
                throw new DeviceAlreadyRegisteredException("Error 422: Device is already registered");
            }
            if (res.Code == 404)
            {
                //Could not find supported device
                throw new DeviceModelNotFoundException("Error 404: Could not find supported device");
            }

            if (res.Code != 201)
            {
                Logging.Notice(@"SyncProApi \ RegisterDevice", res.Code.ToString() + ":" + res.ContentString);
                //Todo: Throw exception - Device already registered.
                return(null);
            }
            return(JsonConvert.DeserializeObject <RegisterDeviceResponse>(res.ContentString));
        }
示例#2
0
        /// <summary>
        /// Default constructor. Initializes the partnerID and read debug information from file.
        /// </summary>
        /// <param name="partnerId"></param>
        public Api(string uuid, string accessKey)
        {
            _uuid      = uuid;
            _accessKey = accessKey;

            _webMethods = new WebMethods(_uuid, _accessKey);
        }