Example #1
0
 public DiskEntity(DiskEntity entity)
 {
     this.CreationDate = entity.CreationDate;
     this.Icon         = entity.Icon;
     this.Id           = entity.Id;
     this.Name         = entity.Name;
     this.Permission   = entity.Permission;
     this.UpdateDate   = entity.UpdateDate;
     this.UserId       = entity.UserId;
 }
 public DiskEntity(DiskEntity entity)
 {
     this.CreationDate = entity.CreationDate;
     this.Icon = entity.Icon;
     this.Id = entity.Id;
     this.Name = entity.Name;
     this.Permission = entity.Permission;
     this.UpdateDate = entity.UpdateDate;
     this.UserId = entity.UserId;
 }
 public void UpdateLocalEntity(DiskEntity entity)
 {
     if (entity.GetType().Equals(typeof(File)))
     {
         using (var store = IsolatedStorageFile.GetUserStoreForApplication())
         {
             string oldName = (entity as File).Path.Split('~').Last();
             string finalDestination = (entity as File).Path.Replace(oldName, entity.Name);
             store.MoveFile((entity as File).Path, finalDestination);
             GetLocalEntities();
         }
     }
 }
 public void DeleteLocalEntity(DiskEntity selectedLocalEntity)
 {
     if (selectedLocalEntity.GetType().Equals(typeof(File)))
     {
         using (var store = IsolatedStorageFile.GetUserStoreForApplication())
         {
             store.DeleteFile((selectedLocalEntity as File).Path);
         }
     }
     else
     {
         // No folders in local storage, I'm lazy
     }
     LocalEntities.Remove(selectedLocalEntity);
 }
 public void SelectLocalEntity(DiskEntity selectedEntity)
 {
     SelectedLocalEntity = LocalEntities.Where(e => e.CreationDate.Equals(selectedEntity.CreationDate)).FirstOrDefault();
 }
 public void CutEntity(DiskEntity selectedEntity)
 {
     if (selectedEntity.GetType().Equals(typeof(File)))
     {
         _copiedOrCutedEntity = selectedEntity;
     }
 }
 public async void ShareEntity(DiskEntity selectedEntity, string recipientEmail, string permissionString)
 {
     PermissionRight permission = (PermissionRight)Enum.Parse(typeof(PermissionRight), permissionString);
     if (selectedEntity.GetType().Equals(typeof(Folder)))
     {
         var result = await _folderApi.ShareFolder(selectedEntity as Folder, recipientEmail, permission, _user.Token);
     }
     else
     {
         var result = await _fileApi.ShareFile(selectedEntity as File, recipientEmail, permission, _user.Token);
     }
 }
 public async void GetSharedUsers(DiskEntity selectedEntity)
 {
     if (selectedEntity.GetType().Equals(typeof(Folder)))
     {
         List<Permission> whyCantIDoItInOnlyOneStep = await _folderApi.GetSharedUsers(selectedEntity as Folder, _user.Token);
         Permissions.Clear();
         foreach (var permission in whyCantIDoItInOnlyOneStep)
         {
             Permissions.Add(permission);
         }
     }
     else
     {
         List<Permission> whyCantIDoItInOnlyOneStep = await _fileApi.GetSharedUsers(selectedEntity as File, _user.Token);
         Permissions = new ObservableCollection<Permission>(whyCantIDoItInOnlyOneStep);
     }
 }
 public Uri GetAnonymousShareLink(DiskEntity selectedEntity)
 {
     if (selectedEntity.GetType().Equals(typeof(Folder)))
     {
         return _folderApi.GetAnonymousShareLink(selectedEntity as Folder);
     }
     else
     {
         return _fileApi.GetAnonymousShareLink(selectedEntity as File);
     }
 }
 public async void DeleteEntity(DiskEntity selectedEntity)
 {
    var entity = Entities.Where(e => e.Id.Equals(selectedEntity.Id)).FirstOrDefault();
    if (entity.GetType().Equals(typeof(File)))
    {
        bool result = await _fileApi.DeleteFile(entity as File, _user.Token);
    }
    else
    {
        bool result = await _folderApi.DeleteFolder(entity as Folder, _user.Token);
    }
    // If it's true the entity has just been removed
    // If it's false it means the entity has already been removed
    // So in both cases we remove it from the list
    Entities.Remove(entity);
 }
 public void SelectEntity(DiskEntity selectedEntity)
 {
     SelectedEntity = Entities.Where(e=>e.Id.Equals(selectedEntity.Id)).FirstOrDefault();
 }
 private DiskEntity DetermineIcon(DiskEntity entity)
 {
     if (entity.GetType().Equals(typeof(Folder)))
     {
         entity.Icon = new BitmapImage(new Uri("/Resources/Images/folder.png", UriKind.Relative));
     }
     else
     {
         if (((File)entity).ContentType.StartsWith("application"))
         {
             entity.Icon = new BitmapImage(new Uri("/Resources/Images/applicationFile.png", UriKind.Relative));
         }
         else if (((File)entity).ContentType.StartsWith("audio"))
         {
             entity.Icon = new BitmapImage(new Uri("/Resources/Images/audioFile.png", UriKind.Relative));
         }
         else if (((File)entity).ContentType.StartsWith("image"))
         {
             entity.Icon = new BitmapImage(new Uri("/Resources/Images/imageFile.png", UriKind.Relative));
         }
         else if (((File)entity).ContentType.StartsWith("text"))
         {
             entity.Icon = new BitmapImage(new Uri("/Resources/Images/textFile.png", UriKind.Relative));
         }
         else if (((File)entity).ContentType.StartsWith("video"))
         {
             entity.Icon = new BitmapImage(new Uri("/Resources/Images/videoFile.png", UriKind.Relative));
         }
         else
         {
             entity.Icon = new BitmapImage(new Uri("/Resources/Images/unknownFile.png", UriKind.Relative));
         }
     }
     return entity;
 }
 public async void UpdateEntity(DiskEntity entity)
 {
     DiskEntity newEntity = null;
     if (entity.GetType().Equals(typeof(Folder)))
     {
         newEntity = await _folderApi.UpdateFolder(entity as Folder, _user.Token);
     }
     else
     {
         newEntity = await _fileApi.UpdateFile(entity as File, _user.Token);
     }
     if (newEntity != null)
     {
         newEntity = DetermineIcon(newEntity);
         int index = Entities.IndexOf(Entities.Where(e => e.Id.Equals(entity.Id)).FirstOrDefault());
         Entities.RemoveAt(index);
         Entities.Insert(index, newEntity);
     }
 }