Exemple #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GPodder.Server"/> class.
        /// </summary>
        /// <param name='devices'>Devices.</param>
        /// <param name='subscriptions'></param>
        /// <param name='episodes'></param>
        public static void Initialize(List<Device> devices, string selectedDeviceId, List<Subscription> subscriptions, List<Episode> episodes, long lastUpdate)
        {
            LogMessage("Intializing data");

              // do this without triggering any hooks
              MyGPO.devices.AddRange(devices);
              if(!string.IsNullOrWhiteSpace(selectedDeviceId)) {
            MyGPO.selectedDevice = GetDevice(selectedDeviceId);
              }
              MyGPO.subscriptions.AddRange(subscriptions);
              MyGPO.episodes.AddRange(episodes);
              MyGPO.lastUpdate = lastUpdate;
              LogMessage("Done initializing data");
        }
 /// <summary>
 /// Cursors to device.
 /// </summary>
 /// <returns>The to device.</returns>
 /// <param name='cursor'>Cursor.</param>
 private Device cursorToDevice(ICursor cursor)
 {
     Device device = new Device();
       device.Id            = cursor.GetString(cursor.GetColumnIndex(Device.COL_ID));
       device.Caption       = cursor.GetString(cursor.GetColumnIndex(Device.COL_CAPTION));
       device.Subscriptions = cursor.GetInt(cursor.GetColumnIndex(Device.COL_SUBSCRIPTIONS));
       device.Type          = (Device.DeviceType)Enum.Parse(typeof(Device.DeviceType),cursor.GetString(cursor.GetColumnIndex(Device.COL_TYPE)));
       return device;
 }
Exemple #3
0
        /// <summary>
        /// Pulls the devices from server.
        /// </summary>
        public static void GetDevicesFromServer()
        {
            // if there is no connected user this is an error condition
              if(ConnectedUser == null) {
            throw new Exception("Cannot get devices without a user");
              }

              // get the response from the server
              string t = getResponseString(new Uri(GPodderLocation + GPodderAPI + @"devices/" + ConnectedUser.Username + JSONExtension));

              // parse the json into a list of devices
              List<Device> serverList = JsonConvert.DeserializeObject<List<Device>>(t);

              // make a record of the id of the selected device
              string id = selectedDevice != null ? selectedDevice.Id : string.Empty;

              // first go through all of the devices and remove them all!
              foreach(Device existing in devices) {
            foreach(DeviceUpdatedMethod removeCallback in deviceRemovedCallbacks){
              removeCallback(existing);
            }
              }
              devices.Clear();

              // go through each device on the server and make sure they are not yet on the list
              foreach(Device deviceOnServer in serverList) {
            foreach(DeviceUpdatedMethod addedCallback in deviceAddedCallbacks){
              addedCallback(deviceOnServer);
            }
            devices.Add(deviceOnServer);
              }

              // reselect the selected device
              selectedDevice = GetDevice(id);

              LogMessage("Done getting devices from Server");
        }
 /// <summary>
 /// Creates the content values.
 /// </summary>
 /// <returns>The content values.</returns>
 /// <param name='device'>Device.</param>
 private ContentValues createContentValues(Device device)
 {
     ContentValues values = new ContentValues();
       values.Put(Device.COL_ID, device.Id);
       values.Put(Device.COL_CAPTION, device.Caption);
       values.Put(Device.COL_TYPE, device.Type.ToString());
       values.Put(Device.COL_SUBSCRIPTIONS, device.Subscriptions);
       return values;
 }
 /// <summary>
 /// Update the specified device.
 /// </summary>
 /// <param name='device'>Device.</param>
 public void Update(Device device)
 {
     try {
     dbHelper.WritableDatabase.Update(Device.TABLE_NAME, createContentValues(device), Device.COL_ID + " =?", new string[]{device.Id});
       }
       catch(Exception exc) {
     throw new Exception("Failed to update device table for device " + device.Id, exc);
       }
 }
 /// <summary>
 /// Inserts the device.
 /// </summary>
 /// <returns>The device.</returns>
 /// <param name='comment'>Comment.</param>
 public bool InsertOrUpdate(Device device)
 {
     // attempt to query the database for this item
       ICursor cursor = dbHelper.WritableDatabase.Query(Device.TABLE_NAME, null, Device.COL_ID + "=?", new string[]{device.Id}, null, null, null);
       if(cursor.Count > 0) {
     Update(device);
     return false;
       }
       else {
     Insert(device);
     return true;
       }
 }
 /// <summary>
 /// Insert the specified device.
 /// </summary>
 /// <param name='device'>Device.</param>
 public void Insert(Device device)
 {
     try{
     dbHelper.WritableDatabase.InsertOrThrow(Device.TABLE_NAME, null, createContentValues(device));
       }
       catch(Exception exc) {
     throw new Exception("Could not insert device " + device.Id, exc);
       }
 }
 /// <summary>
 /// Deletes the device.
 /// </summary>
 /// <param name='device'>Device.</param>
 public void DeleteDevice(Device device)
 {
     try {
     dbHelper.WritableDatabase.Delete(Device.TABLE_NAME, Device.COL_ID + " = " + device.Id, null);
       }
       catch(Exception exc) {
     throw new Exception("Could not delete device " + device.Id, exc);
       }
       PortaPodderApp.LogMessage("Deleted the device " + device.Id);
 }