Example #1
0
 private void DismissCompletedFiles()
 {
     if (FinishedFiles.Count > 0)
     {
         m_nSelected = -1;
         FinishedFiles.Clear();
     }
 }
Example #2
0
 public async void OnReceivedFileEvent(object sender, ReceiveFileEventArgs eventArgs)
 {
     if (eventArgs.FileEvent == ReceiveFileEventArgs.EFileEvent.NEWFILE)
     {
         ReceiveFile newFile = new ReceiveFile(eventArgs.FileName, eventArgs.FileType, eventArgs.FileID, eventArgs.FileSize);
         if (newFile.Open())
         {
             eventArgs.CancelFile = false;
             m_liReceivingFiles.Add(newFile);
             m_statusTimer.IsEnabled = true;
             Log.i(TAG, "Receiving " + newFile.FileName + " (" + newFile.FileSize.ToXByteSize() + ")", true);
         }
         else
         {
             eventArgs.CancelFile = true;
         }
     }
     else if (eventArgs.FileEvent == ReceiveFileEventArgs.EFileEvent.CANCELFILE)
     {
         ReceiveFile file = m_liReceivingFiles.Find(x => x.FileID == eventArgs.FileID);
         if (file != null)
         {
             Log.i(TAG, "Aborted file " + file.FileName, true);
             file.Cancel();
             m_liReceivingFiles.Remove(file);
         }
         else
         {
             Log.w(TAG, "Server requested cancelling of unknown file, Id:" + eventArgs.FileID);
         }
     }
     else if (eventArgs.FileEvent == ReceiveFileEventArgs.EFileEvent.DATA)
     {
         ReceiveFile file = m_liReceivingFiles.Find(x => x.FileID == eventArgs.FileID);
         if (file != null)
         {
             try
             {
                 await file.Write(eventArgs.Data, eventArgs.FilePos);
             }
             catch (Exception e)
             {
                 Log.e(TAG, "Error while writing received file data for file " + file.FileName + " - " + e.Message);
                 eventArgs.CancelFile = true;
                 file.Cancel();
                 m_liReceivingFiles.Remove(file);
                 return;
             }
             if (file.Complete)
             {
                 Log.i(TAG, "Completed file " + file.FileName, true);
                 FinishedFiles.Add(file);
                 m_liReceivingFiles.Remove(file);
                 Selected = FinishedFiles.Count - 1;
                 if (FinishedFiles.Count == 1)
                 {
                     ShowNotification = true;
                 }
             }
         }
     }
 }