Represents a file type.
        public void ShowSaveFileDialogExtensionTest()
        {
            FileType rtfFileType = new FileType("RichText Document", ".rtf");
            FileType xpsFileType = new FileType("XPS Document", ".xps");
            IEnumerable<FileType> fileTypes = new FileType[] { rtfFileType, xpsFileType };
            string defaultFileName = "Document 1.rtf";
            FileDialogResult result = new FileDialogResult("Document 2.rtf", rtfFileType);

            MockFileDialogService service = new MockFileDialogService();
            service.Result = result;

            Assert.AreEqual(result, service.ShowSaveFileDialog(rtfFileType));
            Assert.AreEqual(rtfFileType, service.FileTypes.Single());
            AssertHelper.ExpectedException<ArgumentNullException>(() => FileDialogServiceExtensions.ShowSaveFileDialog(null, rtfFileType));
            AssertHelper.ExpectedException<ArgumentNullException>(() => service.ShowSaveFileDialog((FileType)null));

            Assert.AreEqual(result, service.ShowSaveFileDialog(rtfFileType, defaultFileName));
            Assert.AreEqual(rtfFileType, service.FileTypes.Single());
            Assert.AreEqual(defaultFileName, service.DefaultFileName);
            AssertHelper.ExpectedException<ArgumentNullException>(() => FileDialogServiceExtensions.ShowSaveFileDialog(null, rtfFileType, defaultFileName));
            AssertHelper.ExpectedException<ArgumentNullException>(() => service.ShowSaveFileDialog((FileType)null, defaultFileName));

            Assert.AreEqual(result, service.ShowSaveFileDialog(fileTypes));
            Assert.IsTrue(service.FileTypes.SequenceEqual(new FileType[] { rtfFileType, xpsFileType }));
            AssertHelper.ExpectedException<ArgumentNullException>(() => FileDialogServiceExtensions.ShowSaveFileDialog(null, fileTypes));
        }
        public void ShowMockFileDialogService()
        {
            var fileDialogService = new MockFileDialogService();

            var owner = new object();
            var fileType = new FileType("description", ".fileExtension");
            var fileTypes = new[] { fileType };
            var result = new FileDialogResult("selectedName", fileType);
            fileDialogService.Result = result;

            Assert.AreEqual(result, fileDialogService.ShowOpenFileDialog(owner, fileTypes, fileType, "defaultFileName"));

            Assert.AreEqual(FileDialogType.OpenFileDialog, fileDialogService.FileDialogType);
            Assert.AreEqual(owner, fileDialogService.Owner);
            Assert.AreEqual(fileTypes, fileDialogService.FileTypes);
            Assert.AreEqual(fileType, fileDialogService.DefaultFileType);
            Assert.AreEqual("defaultFileName", fileDialogService.DefaultFileName);

            fileDialogService.Clear();

            Assert.AreEqual(FileDialogType.None, fileDialogService.FileDialogType);
            Assert.IsNull(fileDialogService.Owner);
            Assert.IsNull(fileDialogService.FileTypes);
            Assert.IsNull(fileDialogService.DefaultFileType);
            Assert.IsNull(fileDialogService.DefaultFileName);

            fileDialogService.Result = result;
            Assert.AreEqual(result, fileDialogService.ShowSaveFileDialog(owner, fileTypes, fileType, "defaultFileName"));

            Assert.AreEqual(FileDialogType.SaveFileDialog, fileDialogService.FileDialogType);
            Assert.AreEqual(owner, fileDialogService.Owner);
            Assert.AreEqual(fileTypes, fileDialogService.FileTypes);
            Assert.AreEqual(fileType, fileDialogService.DefaultFileType);
            Assert.AreEqual("defaultFileName", fileDialogService.DefaultFileName);
        }
示例#3
0
        /// <summary>
        /// Shows the save file dialog box that allows a user to specify a filename to save a file as.
        /// </summary>
        /// <param name="fileTypes">The supported file types.</param>
        /// <param name="defaultFileType">Default file type.</param>
        /// <param name="defaultFileName">Default filename.</param>
        /// <returns>A FileDialogResult object which contains the filename entered by the user.</returns>
        /// <exception cref="ArgumentNullException">fileTypes must not be null.</exception>
        /// <exception cref="ArgumentException">fileTypes must contain at least one item.</exception>
        public FileDialogResult ShowSaveFileDialog(IEnumerable<FileType> fileTypes, FileType defaultFileType, string defaultFileName)
        {
            if (fileTypes == null) { throw new ArgumentNullException("fileTypes"); }
            if (!fileTypes.Any()) { throw new ArgumentException("The fileTypes collection must contain at least one item."); }

            SaveFileDialog dialog = new SaveFileDialog();

            return ShowFileDialog(dialog, fileTypes, defaultFileType, defaultFileName);
        }
示例#4
0
 /// <summary>
 /// Shows the save file dialog box that allows a user to specify a filename to save a file as.
 /// </summary>
 /// <param name="owner">The window that owns this SaveFileDialog.</param>
 /// <param name="fileTypes">The supported file types.</param>
 /// <param name="defaultFileType">Default file type.</param>
 /// <param name="defaultFileName">Default filename. The directory name is used as initial directory when it is specified.</param>
 /// <returns>A FileDialogResult object which contains the filename entered by the user.</returns>
 public FileDialogResult ShowSaveFileDialog(object owner, IEnumerable<FileType> fileTypes, FileType defaultFileType, string defaultFileName)
 {
     FileDialogType = FileDialogType.SaveFileDialog;
     Owner = owner;
     FileTypes = fileTypes;
     DefaultFileType = defaultFileType;
     DefaultFileName = defaultFileName;
     return Result;
 }
        public void CreateFilterTest()
        {
            FileType rtfFileType = new FileType("RichText Document", ".rtf");
            FileType xpsFileType = new FileType("XPS Document", ".xps");

            Assert.AreEqual("RichText Document|*.rtf", InvokeCreateFilter(new FileType[] { rtfFileType }));
            Assert.AreEqual("RichText Document|*.rtf|XPS Document|*.xps",
                InvokeCreateFilter(new FileType[] { rtfFileType, xpsFileType }));
        }
示例#6
0
 private void SaveAttachmentRequest()
 {
     IEnumerable <System.Waf.Applications.Services.FileType> fileTypes = new System.Waf.Applications.Services.FileType[] {
         new System.Waf.Applications.Services.FileType("all files", ".*"),
         new System.Waf.Applications.Services.FileType("jpg image", ".jpg"),
         new System.Waf.Applications.Services.FileType("bmp image", ".bmp"),
         new System.Waf.Applications.Services.FileType("png image", ".png")
     };
     FileDialogResult result = fileDialogService.ShowSaveFileDialog(fileTypes);
 }
示例#7
0
        public void ResultTest()
        {
            FileDialogResult result = new FileDialogResult();
            Assert.IsFalse(result.IsValid);

            FileType rtfFileType = new FileType("RichText Document", ".rtf");
            result = new FileDialogResult(@"C:\Document 1.rtf", rtfFileType);
            Assert.IsTrue(result.IsValid);
            Assert.AreEqual(@"C:\Document 1.rtf", result.FileName);
            Assert.AreEqual(rtfFileType, result.SelectedFileType);
        }
示例#8
0
        public void ConstructorTest()
        {
            FileType fileType = new FileType("RichText Documents (*.rtf)", ".rtf");
            Assert.AreEqual("RichText Documents (*.rtf)", fileType.Description);
            Assert.AreEqual(".rtf", fileType.FileExtension);

            AssertHelper.ExpectedException<ArgumentException>(() => new FileType(null, ".rtf"));
            AssertHelper.ExpectedException<ArgumentException>(() => new FileType("", ".rtf"));
            AssertHelper.ExpectedException<ArgumentException>(() => new FileType("RichText Documents", null));
            AssertHelper.ExpectedException<ArgumentException>(() => new FileType("RichText Documents", ""));
            AssertHelper.ExpectedException<ArgumentException>(() => new FileType("RichText Documents", "rtf"));
        }
示例#9
0
        private void AddAttachmentRequest()
        {
            CommunicationAttachment attachment = null;
            IEnumerable <System.Waf.Applications.Services.FileType> fileTypes = new System.Waf.Applications.Services.FileType[] {
                new System.Waf.Applications.Services.FileType("all files", ".*"),
                new System.Waf.Applications.Services.FileType("jpg image", ".jpg"),
                new System.Waf.Applications.Services.FileType("bmp image", ".bmp"),
                new System.Waf.Applications.Services.FileType("png image", ".png")
            };

            FileDialogResult result = fileDialogService.ShowOpenFileDialog(this, fileTypes);

            if (result.IsValid)
            {
                try
                {
                    /*					ShowLoadingAnimation = true;
                     *
                     *                                      Action addFolderItemAction = () =>
                     *                                      {
                     *                                              ReadFileContent(item, item.FileSystemPath);
                     *                                              ShowLoadingAnimation = false;
                     *                                      };
                     *                                      addFolderItemAction.BeginInvoke(null, null);*/
                    FileInfo fInfo = new FileInfo(result.FileName);
                    if (fInfo != null)
                    {
                        attachment = new CommunicationAttachment()
                        {
                            FileUrl = fInfo.Name, Url = result.FileName, State = CommunicationItemState.Appended
                        };
                    }
                }
                catch
                {
                    ShowLoadingAnimation = false;
                    throw;
                }
                if (attachment != null)
                {
                    OnUIThread(() =>
                    {
                        Attachments.Add(attachment);
                        AttacmentsCollection.Refresh();
                        State = CommunicationItemState.Modified;
                    });
                }
            }
        }
示例#10
0
        private void ChangeContactImage()
        {
            IEnumerable <System.Waf.Applications.Services.FileType> fileTypes = new System.Waf.Applications.Services.FileType[]
            {
                new System.Waf.Applications.Services.FileType("jpg image", ".jpg"),
                new System.Waf.Applications.Services.FileType("bmp image", ".bmp"),
                new System.Waf.Applications.Services.FileType("png image", ".png")
            };

            FileDialogResult result = _fileDialogService.ShowOpenFileDialog(this, fileTypes);

            if (result.IsValid)
            {
                try
                {
                    string fileName = result.FileName;

                    if (fileName == null || !IsImageFileValid(fileName))
                    {
                        return;
                    }

                    byte[] buff = null;
                    buff = File.ReadAllBytes(fileName);

                    if (buff.Length > 20000)
                    {
                        NotificationInteractionRequest.Raise(new ConditionalConfirmation()
                        {
                            Title   = "Error file selection".Localize(),
                            Content = "Image must be less than 20 kilobytes".Localize()
                        },
                                                             x =>
                        {
                        });
                    }
                    else
                    {
                        InnerItem.Photo = buff;
                    }
                }
                catch (Exception)
                {
                }
            }
        }
		private void AddAttachmentRequest()
		{
			CommunicationAttachment attachment = null;
			IEnumerable<System.Waf.Applications.Services.FileType> fileTypes = new System.Waf.Applications.Services.FileType[] {
                new System.Waf.Applications.Services.FileType("all files", ".*"),
                new System.Waf.Applications.Services.FileType("jpg image", ".jpg"),
                new System.Waf.Applications.Services.FileType("bmp image", ".bmp"),
                new System.Waf.Applications.Services.FileType("png image", ".png")
            };

			FileDialogResult result = fileDialogService.ShowOpenFileDialog(this, fileTypes);
			if (result.IsValid)
			{
				try
				{
					/*					ShowLoadingAnimation = true;

										Action addFolderItemAction = () =>
										{
											ReadFileContent(item, item.FileSystemPath);
											ShowLoadingAnimation = false;
										};
										addFolderItemAction.BeginInvoke(null, null);*/
					FileInfo fInfo = new FileInfo(result.FileName);
					if (fInfo != null)
					{
						attachment = new CommunicationAttachment() { FileUrl = fInfo.Name, Url = result.FileName, State = CommunicationItemState.Appended };
					}
				}
				catch
				{
					ShowLoadingAnimation = false;
					throw;
				}
				if (attachment != null)
				{
					OnUIThread(() =>
					{
						Attachments.Add(attachment);
						AttacmentsCollection.Refresh();
						State = CommunicationItemState.Modified;
					});
				}
			}
		}
示例#12
0
        private static FileDialogResult ShowFileDialog(FileDialog dialog, IEnumerable<FileType> fileTypes, FileType defaultFileType, string defaultFileName)
        {
            int filterIndex = fileTypes.ToList().IndexOf(defaultFileType);
            if (filterIndex >= 0) { dialog.FilterIndex = filterIndex + 1; }
            if (!string.IsNullOrEmpty(defaultFileName)) { dialog.FileName = defaultFileName; }

            dialog.Filter = CreateFilter(fileTypes);
            if (dialog.ShowDialog() == true)
            {
                if (dialog.FilterIndex - 1 < fileTypes.Count())
                {
                    defaultFileType = fileTypes.ElementAt(dialog.FilterIndex - 1);
                }
                else
                {
                    defaultFileType = null;
                }
                return new FileDialogResult(dialog.FileName, defaultFileType);
            }
            else
            {
                return new FileDialogResult();
            }
        }
示例#13
0
 /// <summary>
 /// Shows the open file dialog box that allows a user to specify a file that should be opened.
 /// </summary>
 /// <param name="service">The file dialog service.</param>
 /// <param name="fileType">The supported file type.</param>
 /// <param name="defaultFileName">Default filename. The directory name is used as initial directory when it is specified.</param>
 /// <returns>A FileDialogResult object which contains the filename selected by the user.</returns>
 /// <exception cref="ArgumentNullException">service must not be null.</exception>
 /// <exception cref="ArgumentNullException">fileType must not be null.</exception>
 public static FileDialogResult ShowOpenFileDialog(this IFileDialogService service, FileType fileType, string defaultFileName)
 {
     if (service == null) { throw new ArgumentNullException(nameof(service)); }
     if (fileType == null) { throw new ArgumentNullException(nameof(fileType)); }
     return service.ShowOpenFileDialog(null, new[] { fileType }, fileType, defaultFileName);
 }
示例#14
0
 /// <summary>
 /// Shows the open file dialog box that allows a user to specify a file that should be opened.
 /// </summary>
 /// <param name="service">The file dialog service.</param>
 /// <param name="owner">The window that owns this OpenFileDialog.</param>
 /// <param name="fileType">The supported file type.</param>
 /// <returns>A FileDialogResult object which contains the filename selected by the user.</returns>
 /// <exception cref="ArgumentNullException">service must not be null.</exception>
 /// <exception cref="ArgumentNullException">fileType must not be null.</exception>
 public static FileDialogResult ShowOpenFileDialog(this IFileDialogService service, object owner, FileType fileType)
 {
     if (service == null) { throw new ArgumentNullException(nameof(service)); }
     if (fileType == null) { throw new ArgumentNullException(nameof(fileType)); }
     return service.ShowOpenFileDialog(owner, new[] { fileType }, fileType, null);
 }
 /// <summary>
 /// Shows the open file dialog box that allows a user to specify a file that should be opened.
 /// </summary>
 /// <param name="service">The file dialog service.</param>
 /// <param name="owner">The window that owns this OpenFileDialog.</param>
 /// <param name="fileType">The supported file type.</param>
 /// <param name="defaultFileName">Default filename. The directory name is used as initial directory when it is specified.</param>
 /// <returns>A FileDialogResult object which contains the filename selected by the user.</returns>
 /// <exception cref="ArgumentNullException">service must not be null.</exception>
 /// <exception cref="ArgumentNullException">fileType must not be null.</exception>
 public static FileDialogResult ShowOpenFileDialog(this IFileDialogService service, object owner, FileType fileType, string defaultFileName)
 {
     if (service == null)
     {
         throw new ArgumentNullException(nameof(service));
     }
     if (fileType == null)
     {
         throw new ArgumentNullException(nameof(fileType));
     }
     return(service.ShowOpenFileDialog(owner, new FileType[] { fileType }, fileType, defaultFileName));
 }
 /// <summary>
 /// Shows the open file dialog box that allows a user to specify a file that should be opened.
 /// </summary>
 /// <param name="service">The file dialog service.</param>
 /// <param name="fileType">The supported file type.</param>
 /// <param name="aMultiSelect"></param>
 /// <returns>A FileDialogResult object which contains the filename selected by the user.</returns>
 /// <exception cref="ArgumentNullException">service must not be null.</exception>
 /// <exception cref="ArgumentNullException">fileType must not be null.</exception>
 public static FileDialogResult ShowOpenFileDialog(this IFileDialogService service, FileType fileType, bool aMultiSelect)
 {
     if (service == null) { throw new ArgumentNullException("service"); }
     if (fileType == null) { throw new ArgumentNullException("fileType"); }
     return service.ShowOpenFileDialog(null, new FileType[] { fileType }, fileType, null, aMultiSelect);
 }
		private void ChangeContactImage()
		{
			IEnumerable<System.Waf.Applications.Services.FileType> fileTypes = new System.Waf.Applications.Services.FileType[]
			{
				new System.Waf.Applications.Services.FileType("jpg image", ".jpg"),
				new System.Waf.Applications.Services.FileType("bmp image", ".bmp"),
				new System.Waf.Applications.Services.FileType("png image", ".png")
			};

			FileDialogResult result = _fileDialogService.ShowOpenFileDialog(this, fileTypes);
			if (result.IsValid)
			{
				try
				{
					string fileName = result.FileName;

					if (fileName == null || !IsImageFileValid(fileName))
						return;

					byte[] buff = null;
					buff = File.ReadAllBytes(fileName);

					if (buff.Length > 20000)
					{
						NotificationInteractionRequest.Raise(new ConditionalConfirmation()
						{
							Title = "Error file selection",
							Content = "Image must be less than 20 kilobytes"
						},
							x =>
							{

							});

					}
					else
					{
						InnerItem.Photo = buff;
					}

				}
				catch (Exception)
				{

				}
			}
		}
		private void SaveAttachmentRequest()
		{
			IEnumerable<System.Waf.Applications.Services.FileType> fileTypes = new System.Waf.Applications.Services.FileType[] {
                new System.Waf.Applications.Services.FileType("all files", ".*"),
                new System.Waf.Applications.Services.FileType("jpg image", ".jpg"),
                new System.Waf.Applications.Services.FileType("bmp image", ".bmp"),
                new System.Waf.Applications.Services.FileType("png image", ".png")
            };
			FileDialogResult result = fileDialogService.ShowSaveFileDialog(fileTypes);
		}
 public FileDialogResult ShowSaveFileDialog(IEnumerable<FileType> fileTypes, FileType defaultFileType, string defaultFileName)
 {
     FileTypes = fileTypes;
     DefaultFileType = defaultFileType;
     DefaultFileName = defaultFileName;
     return Result;
 }
 /// <summary>
 /// Shows the save file dialog box that allows a user to specify a filename to save a file as.
 /// </summary>
 /// <param name="service">The file dialog service.</param>
 /// <param name="fileTypes">The supported file types.</param>
 /// <param name="defaultFileType">Default file type.</param>
 /// <param name="defaultFileName">Default filename. The directory name is used as initial directory when it is specified.</param>
 /// <returns>A FileDialogResult object which contains the filename entered by the user.</returns>
 /// <exception cref="ArgumentNullException">service must not be null.</exception>
 /// <exception cref="ArgumentNullException">fileTypes must not be null.</exception>
 /// <exception cref="ArgumentException">fileTypes must contain at least one item.</exception>
 public static FileDialogResult ShowSaveFileDialog(this IFileDialogService service, IEnumerable<FileType> fileTypes, 
     FileType defaultFileType, string defaultFileName)
 {
     if (service == null) { throw new ArgumentNullException("service"); }
     return service.ShowSaveFileDialog(null, fileTypes, defaultFileType, defaultFileName);
 }
示例#21
0
 /// <summary>
 /// Shows the save file dialog box that allows a user to specify a filename to save a file as.
 /// </summary>
 /// <param name="service">The file dialog service.</param>
 /// <param name="fileType">The supported file type.</param>
 /// <returns>A FileDialogResult object which contains the filename entered by the user.</returns>
 /// <exception cref="ArgumentNullException">service must not be null.</exception>
 /// <exception cref="ArgumentNullException">fileType must not be null.</exception>
 public static FileDialogResult ShowSaveFileDialog(this IFileDialogService service, FileType fileType)
 {
     if (service == null) { throw new ArgumentNullException("service"); }
     if (fileType == null) { throw new ArgumentNullException("fileType"); }
     return service.ShowSaveFileDialog(new FileType[] { fileType }, fileType, null);
 }
 /// <summary>
 /// Shows the open file dialog box that allows a user to specify a file that should be opened.
 /// </summary>
 /// <param name="service">The file dialog service.</param>
 /// <param name="owner">The window that owns this OpenFileDialog.</param>
 /// <param name="fileType">The supported file type.</param>
 /// <param name="defaultFileName">Default filename. The directory name is used as initial directory when it is specified.</param>
 /// <returns>A FileDialogResult object which contains the filename selected by the user.</returns>
 /// <exception cref="ArgumentNullException">service must not be null.</exception>
 /// <exception cref="ArgumentNullException">fileType must not be null.</exception>
 public static FileDialogResult ShowOpenFileDialog(this IFileDialogService service, object owner, FileType fileType, string defaultFileName)
 {
     if (service == null) { throw new ArgumentNullException("service"); }
     if (fileType == null) { throw new ArgumentNullException("fileType"); }
     return service.ShowOpenFileDialog(owner, new FileType[] { fileType }, fileType, defaultFileName);
 }
 /// <summary>
 /// Shows the open file dialog box that allows a user to specify a file that should be opened.
 /// </summary>
 /// <param name="service">The file dialog service.</param>
 /// <param name="fileType">The supported file type.</param>
 /// <returns>A FileDialogResult object which contains the filename selected by the user.</returns>
 /// <exception cref="ArgumentNullException">service must not be null.</exception>
 /// <exception cref="ArgumentNullException">fileType must not be null.</exception>
 public static FileDialogResult ShowOpenFileDialog(this IFileDialogService service, FileType fileType)
 {
     if (service == null)
     {
         throw new ArgumentNullException(nameof(service));
     }
     if (fileType == null)
     {
         throw new ArgumentNullException(nameof(fileType));
     }
     return(service.ShowOpenFileDialog(null, new FileType[] { fileType }, fileType, null));
 }