internal void CanIClaimHomeId(string hardwareId, string homeId, Action <bool> callback)
 {
     try
     {
         ClaimHomeIdInfo claimHomeIdInfo = new ClaimHomeIdInfo()
         {
             HardwareId = hardwareId, HomeId = homeId
         };
         if (null != claimHomeIdInfo)
         {
             string jsonString = claimHomeIdInfo.SerializeToJsonStream();
             logger.Log("Checking for unique Home ID: {0}", jsonString);
             WebClient webClient = new WebClient();
             webClient.UploadStringCompleted  += webClient_CanIClaimHomeIdCompleted;
             webClient.Headers["Content-type"] = "application/json";
             webClient.Encoding = Encoding.UTF8;
             webClient.UploadStringAsync(new Uri(this.uri.OriginalString + "/CanClaimHomeId"), "POST", jsonString,
                                         new ClaimHomeIdCallbackTokenObject()
             {
                 Callback = callback, JsonSerialized = jsonString
             });
         }
     }
     catch (Exception e)
     {
         logger.Log("Exception thrown while checking for unique Home ID, exception={0}", e.Message);
     }
 }
        public bool CanClaimHomeId(ClaimHomeIdInfo chi)
        {
            bool canClaim = false;
            bool selfclaimed = false;
            bool homeIdPresent = false;
            bool add = false;
            HomeIdentityTable homeIdTable = Helper.GetHomeIdentityTable();
            if (null != homeIdTable)
            {
                selfclaimed = homeIdTable.IsHomeIdHardwareIdPairPresent(chi.HardwareId, chi.HomeId);
            }

            if (selfclaimed)
            {
                canClaim = true;
            }
            else
            {
                homeIdPresent = homeIdTable.IsHomeIdPresent(chi.HomeId);

                if (homeIdPresent)
                {
                    // there is a different device that has claimed this id already
                    canClaim = false;
                }
                else
                {
                    // either no device has used this homeid or same device wants to use a different
                    // homeid, both should be allowed
                    canClaim = true;
                    add = true;
                }
            }

            if (add)
            {
                homeIdTable.AddHomeIdentity(chi.HardwareId, chi.HomeId);
            }

            return canClaim;
        }
Example #3
0
 internal void CanIClaimHomeId(string hardwareId, string homeId, Action<bool> callback)
 {
     try
     {
         ClaimHomeIdInfo claimHomeIdInfo = new ClaimHomeIdInfo() { HardwareId = hardwareId, HomeId = homeId };
         if (null != claimHomeIdInfo)
         {
             string jsonString = claimHomeIdInfo.SerializeToJsonStream();
             logger.Log("Checking for unique Home ID: {0}", jsonString);
             WebClient webClient = new WebClient();
             webClient.UploadStringCompleted += webClient_CanIClaimHomeIdCompleted;
             webClient.Headers["Content-type"] = "application/json";
             webClient.Encoding = Encoding.UTF8;
             webClient.UploadStringAsync(new Uri(this.uri.OriginalString + "/CanClaimHomeId"), "POST", jsonString,
                         new ClaimHomeIdCallbackTokenObject() { Callback = callback, JsonSerialized = jsonString });
         }
     }
     catch (Exception e)
     {
         logger.Log("Exception thrown while checking for unique Home ID, exception={0}", e.Message);
     }
 }