Exemple #1
0
        /// <summary>
        /// Adds file to file collection
        /// </summary>
        /// <param name="file"></param>
        private void AddFile(FileInfo file)
        {
            if (file.Exists)
            {
                string fileName = file.Name;

                //Create a new UserFile object
                UserFile userFile = new UserFile();
                userFile.FileName   = file.Name;
                userFile.FileStream = file.OpenRead();

                //Check for the file size limit (configurable)
                if (userFile.FileStream.Length <= Configuration.Instance.MaxFileSize)
                {
                    //Add to the list
                    _files.Add(userFile);
                }
                else
                {
                    MessageChildWindow messageWindow = new MessageChildWindow();
                    messageWindow.Message = UserMessages.MaxFileSize + (Configuration.Instance.MaxFileSize / 1024).ToString() + "KB.";
                    messageWindow.Show();

                    if (MaximumFileSizeReached != null)
                    {
                        MaximumFileSizeReached(this, null);
                    }
                }
            }
        }
Exemple #2
0
 /// <summary>
 /// Start uploading files
 /// </summary>
 private void UploadFiles()
 {
     if (_files.Count == 0)
     {
         MessageChildWindow messageWindow = new MessageChildWindow();
         messageWindow.Message = UserMessages.ErrorNoFilesSelected;
         messageWindow.Show();
     }
     else
     {
         //Tell the collection to start uploading
         _files.UploadFiles();
     }
 }
Exemple #3
0
        /// <summary>
        /// Open the select file dialog
        /// </summary>
        private void SelectUserFiles()
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Multiselect = true;

            try
            {
                //Check the file filter (filter is used to filter file extensions to select, for example only .jpg files)
                if (!string.IsNullOrEmpty(Configuration.Instance.FileFilter))
                {
                    ofd.Filter = Configuration.Instance.FileFilter;
                }
            }
            catch (ArgumentException ex)
            {
                //User supplied a wrong configuration file
                throw new Exception(UserMessages.ErrorFileFilterConfig, ex);
            }

            if (ofd.ShowDialog() == true)
            {
                foreach (FileInfo file in ofd.Files)
                {
                    try
                    {
                        AddFile(file);
                    }
                    catch
                    {
                        //Unable to add file
                        MessageChildWindow messageWindow = new MessageChildWindow();
                        messageWindow.Message = string.Format(UserMessages.AddFileError, file.Name);
                        messageWindow.Show();
                    }
                }
            }
        }