示例#1
0
        private NativeFilePickerAcceptType[] BuildFileTypesMap()
        {
            var acceptTypes = new List <NativeFilePickerAcceptType>();

            foreach (var choice in FileTypeChoices)
            {
                var acceptType = new NativeFilePickerAcceptType();
                acceptType.Description = choice.Key;

                var acceptItems = new List <NativeFilePickerAcceptTypeItem>();
                foreach (var extension in choice.Value)
                {
                    var acceptItem = new NativeFilePickerAcceptTypeItem()
                    {
                        MimeType   = MimeTypeService.GetFromExtension(extension),
                        Extensions = new[] { extension }
                    };
                    acceptItems.Add(acceptItem);
                }

                acceptType.Accept = acceptItems.ToArray();
                acceptTypes.Add(acceptType);
            }

            return(acceptTypes.ToArray());
        }
示例#2
0
        private NativeFilePickerAcceptType[] BuildFileTypesMap()
        {
            var allExtensions = FileTypeFilter.Except(new[] { "*" });

            var acceptTypes = allExtensions
                              .Select(fileType => BuildNativeFilePickerAcceptType(fileType))
                              .ToList();

            if (!FileTypeFilter.Contains("*"))
            {
                var fullAcceptItem = new NativeFilePickerAcceptTypeItem
                {
                    MimeType   = "*/*",
                    Extensions = allExtensions.ToArray()
                };

                var fullAcceptType = new NativeFilePickerAcceptType()
                {
                    Description = "All files",
                    Accept      = new[] { fullAcceptItem }
                };

                acceptTypes.Insert(0, fullAcceptType);
            }

            return(acceptTypes.ToArray());
        }
示例#3
0
        private NativeFilePickerAcceptType[] BuildFileTypesMap()
        {
            var acceptTypes = new List <NativeFilePickerAcceptType>();

            var mimeTypeGroups = FileTypeFilter
                                 .Except(new[] { "*" })
                                 .GroupBy(f => MimeTypeService.GetFromExtension(f))
                                 .ToArray();

            var allAccepts = new List <NativeFilePickerAcceptTypeItem>();

            foreach (var mimeTypeGroup in mimeTypeGroups)
            {
                var extensions = mimeTypeGroup.ToArray();

                var acceptType = new NativeFilePickerAcceptType();
                acceptType.Description = extensions.Length > 1 ? string.Empty : extensions.First();

                var acceptItem = new NativeFilePickerAcceptTypeItem()
                {
                    MimeType   = mimeTypeGroup.Key,
                    Extensions = extensions
                };
                allAccepts.Add(acceptItem);

                acceptType.Accept = new[] { acceptItem };
                acceptTypes.Add(acceptType);
            }

            if (allAccepts.Count > 1)
            {
                var fullAcceptType = new NativeFilePickerAcceptType()
                {
                    Description = "All",
                    Accept      = allAccepts.ToArray()
                };

                acceptTypes.Insert(0, fullAcceptType);
            }

            return(acceptTypes.ToArray());
        }
示例#4
0
        private NativeFilePickerAcceptType[] BuildFileTypesMap()
        {
            var acceptTypes = new List <NativeFilePickerAcceptType>();

            foreach (var choice in FileTypeChoices)
            {
                var acceptType = new NativeFilePickerAcceptType();
                acceptType.Description = choice.Key;

                var acceptItem = new NativeFilePickerAcceptTypeItem()
                {
                    MimeType = "*/*", Extensions = choice.Value.ToArray()
                };

                acceptType.Accept = new NativeFilePickerAcceptTypeItem[] { acceptItem };
                acceptTypes.Add(acceptType);
            }

            return(acceptTypes.ToArray());
        }