private void UpdateDevices()
        {
            try
            {
                var response = Post(string.Format(_initTmpl, _userName), Commands.GetClientInitContext());
                var responseStream = response.GetResponseStream();
                if (responseStream == null)
                    return;

                var text = new StreamReader(responseStream).ReadToEnd();
                var json = (JObject)JsonConvert.DeserializeObject(text);
                //if (json.containsKey("error"))
                //{
                //    throw new InvalidResponseException((String)json["error"));
                //}
                JObject userInfoObj = (JObject)json["userInfo"];
                _userInfo = new UserInfo((String)userInfoObj["firstName"], (String)userInfoObj["lastName"]);

                JArray content = (JArray)json["content"];
                _devices.Clear();
                foreach (JObject x in content)
                {
                    Device device = new Device();
                    PopulateProps(device, x);
                    _devices.Add(device);
                }
            }
            catch (Exception e)
            {
                throw new Exception("Error parsing server response.", e);
            }
        }
Exemple #2
0
 public static String GetWipeDeviceCmd(Device device)
 {
     if (device == null)
     {
         throw new ArgumentException("Device should not be null");
     }
     if (device.Id == null)
     {
         throw new ArgumentException("Device Id should never be null.");
     }
     return string.Format(_wipeDeviceTmpl, device.Id, device.Id);
 }
Exemple #3
0
 public static String GetLockDeviceCmd(String passcode, Device device)
 {
     String newPasscode = passcode ?? string.Empty;
     if (device == null)
     {
         throw new ArgumentException("Device should not be null");
     }
     if (device.Id == null)
     {
         throw new ArgumentException("Device Id should never be null.");
     }
     return string.Format(_lockDeviceTmpl, device.Id, newPasscode, device.Id);
 }
Exemple #4
0
 public static String GetSendMsgCmd(bool playSound, String message, String title, Device device)
 {
     String msg = message ?? string.Empty;
     String subject = title ?? "Important Message";
     if (device == null)
     {
         throw new ArgumentException("Device should not be null");
     }
     if (device.Id == null)
     {
         throw new ArgumentException("Device Id should never be null.");
     }
     return string.Format(_sendMessageTmpl, playSound, msg, device.Id, device.Id, subject);
 }
        private void PopulateProps(Device device, JObject deviceProps)
        {
            try
            {
                device.CanWipeAfterLock = ((Boolean)deviceProps["canWipeAfterLock"]);
                device.LocFoundEnabled = ((Boolean)deviceProps["locFoundEnabled"]);
                JObject loc = deviceProps["location"] as JObject;
                if (loc != null)
                {
                    LocationInfo deviceLocationInfo = new LocationInfo
                    {
                        TimeStamp = ((long)loc["timeStamp"]).ToDateTime(),
                        LocationType = loc["locationType"],
                        IsLocationFinished = (Boolean)loc["locationFinished"],
                        HorizontalAccuracy = (Double)loc["horizontalAccuracy"],
                        PositionType = (String)loc["positionType"],
                        Longitude = (Double)loc["longitude"],
                        IsInaccurate = (Boolean)loc["isInaccurate"],
                        Latitude = (Double)loc["latitude"],
                        IsOld = (Boolean)loc["isOld"]
                    };
                    device.LocationInfo = deviceLocationInfo;
                }
                device.DeviceModel = ((String)deviceProps["deviceModel"]);
                JObject remLck = deviceProps["remoteLock"] as JObject;
                if (remLck != null)
                {
                    RemoteLockInfo remoteLockInfo = new RemoteLockInfo
                    {
                        StatusCode = ((String)remLck["statusCode"]),
                        CreateTimestamp = ((long)remLck["createTimestamp"]).ToDateTime(),
                    };
                    device.RemoteLockInfo = (remoteLockInfo);
                }
                device.ActivationLocked = ((Boolean)deviceProps["activationLocked"]);
                device.RawDeviceModel = ((String)deviceProps["rawDeviceModel"]);
                device.LocationEnabled = ((Boolean)deviceProps["locationEnabled"]);
                device.ModelDisplayName = ((String)deviceProps["modelDisplayName"]);
                device.Id = ((String)deviceProps["id"]);
                device.LostModeCapable = ((Boolean)deviceProps["lostModeCapable"]);
                device.DeviceDisplayName = ((String)deviceProps["deviceDisplayName"]);
                device.DarkWake = ((Boolean)deviceProps["darkWake"]);
                device.LocationCapable = ((Boolean)deviceProps["locationCapable"]);
                device.MaxMsgChar = ((long)deviceProps["maxMsgChar"]);
                device.Name = ((String)deviceProps["name"]);
                device.BatteryLevel = ((Double)deviceProps["batteryLevel"]);
                JObject f = deviceProps["features"] as JObject;
                if (f != null)
                {
                    FeaturesInfo featuresInfo = new FeaturesInfo
                    {
                        IsCltEnabled = ((Boolean)f["CLT"]),
                        IsCwpEnabled = ((Boolean)f["CWP"]),
                        IsWmgEnabled = ((Boolean)f["WMG"]),
                        IsXrmEnabled = ((Boolean)f["XRM"]),
                        IsClkEnabled = ((Boolean)f["CLK"]),
                        IsSndEnabled = ((Boolean)f["SND"]),
                        IsLstEnabled = ((Boolean)f["LST"]),
                        IsKeyEnabled = ((Boolean)f["KEY"]),
                        IsWipEnabled = ((Boolean)f["WIP"]),
                        IsLocEnabled = ((Boolean)f["LOC"]),
                        IsLlcEnabled = ((Boolean)f["LLC"]),
                        IsMsgEnabled = ((Boolean)f["MSG"]),
                        IsLmgEnabled = ((Boolean)f["LMG"]),
                        IsRemEnabled = ((Boolean)f["REM"]),
                        IsLckEnabled = ((Boolean)f["LCK"]),
                        IsSvpEnabled = ((Boolean)f["SVP"]),
                        IsLklEnabled = ((Boolean)f["LKL"]),
                        IsTeuEnabled = ((Boolean)f["TEU"]),
                        IsPinEnabled = ((Boolean)f["PIN"]),
                        IsLkmEnabled = ((Boolean)f["LKM"]),
                        IsKpdEnabled = ((Boolean)f["KPD"])
                    };
                    device.FeaturesInfo = (featuresInfo);
                }
                device.DeviceClass = ((String)deviceProps["deviceClass"]);
                device.WipeInProgress = ((Boolean)deviceProps["wipeInProgress"]);
                device.PasscodeLength = ((long)deviceProps["passcodeLength"]);
                device.IsMac = ((Boolean)deviceProps["isMac"]);
                device.IsLocating = ((Boolean)deviceProps["isLocating"]);
                device.DeviceColor = ((String)deviceProps["deviceColor"]);
                device.BatteryStatus = ((String)deviceProps["batteryStatus"]);
                device.DeviceStatus = ((String)deviceProps["deviceStatus"]);
                device.LockedTimestamp = ((long?)deviceProps["lockedTimestamp"]).ToDateTime();
                device.WipedTimestamp = ((long?)deviceProps["wipedTimestamp"]).ToDateTime();
                JObject msgObj = deviceProps["msg"] as JObject;
                if (msgObj != null)
                {
                    MsgInfo msgInfo = new MsgInfo
                    {
                        StatusCode = ((String)msgObj["statusCode"]),
                        CreateTimestamp = ((long)msgObj["createTimestamp"]).ToDateTime(),
                        UserText = ((Boolean)msgObj["userText"]),
                        PlaySound = ((Boolean)msgObj["playSound"])
                    };
                    device.MsgInfo = msgInfo;
                }
                device.LostModeEnabled = ((Boolean)deviceProps["lostModeEnabled"]);
                device.LostTimestamp = ((String)deviceProps["lostTimestamp"]);
                JObject lstDev = deviceProps["lostDevice"] as JObject;
                if (lstDev != null)
                {
                    LostDeviceInfo lostDeviceInfo = new LostDeviceInfo
                    {
                        StatusCode = ((String)lstDev["statusCode"]),
                        CreateTimestamp = ((long)lstDev["createTimestamp"]).ToDateTime(),
                        Text = ((String)lstDev["text"]),
                        UserText = ((Boolean)lstDev["userText"]),
                        StopLostMode = ((Boolean)lstDev["stopLostMode"]),
                        OwnerNbr = ((String)lstDev["ownerNbr"]),
                        Sound = ((Boolean)lstDev["sound"]),
                        EmailUpdates = ((Boolean)lstDev["emailUpdates"])
                    };
                    device.LostDeviceInfo = (lostDeviceInfo);
                }
                device.UserInfo = _userInfo;
            }
            catch (Exception)
            {

            }
        }
 public void WipeDevice(Device device)
 {
     String cmd = Commands.GetWipeDeviceCmd(device);
     Post(string.Format("/fmipservice/device/{0}/remoteWipe", _userName), cmd);
 }
 public void LockDevice(Device device, String passcode)
 {
     String cmd = Commands.GetLockDeviceCmd(passcode, device);
     Post(string.Format("/fmipservice/device/{0}/remoteLock", _userName), cmd);
 }
 public void SendMessage(Device device, String msg, String title, bool playSound)
 {
     String cmd = Commands.GetSendMsgCmd(playSound, msg, title, device);
     Post(string.Format("/fmipservice/device/{0}/sendMessage", _userName), cmd);
 }
 public Device Locate(Device device)
 {
     if (device == null)
     {
         throw new ArgumentNullException("device");
     }
     String deviceId = device.Id;
     long start = DateTime.Now.Ticks;
     Device deviceToLocate = device;
     UpdateDevices();
     deviceToLocate = FindDevice(deviceId);
     if (deviceToLocate == null)
     {
         throw new DeviceNotFoundException(deviceId);
     }
     return deviceToLocate;
 }