Example #1
0
        internal async Task AddList(string description)
        {
            try
            {
                Stream[] files = await Task.Factory.StartNew(() =>
                {
                    OpenFileDialog fileDialog = new OpenFileDialog();
                    fileDialog.Filter         = "fichiers csv (*.csv)|*.csv";
                    fileDialog.Multiselect    = true;
                    fileDialog.Title          = "Liste de machine/URL";
                    fileDialog.ShowDialog();

                    return(fileDialog.OpenFiles());
                });

                if (string.IsNullOrEmpty(description))
                {
                    description = "Multi ajout";
                }

                foreach (var file in files)
                {
                    foreach (string url in GetUrl(file))
                    {
                        await AddMachine(url, description);
                    }
                }
            }
            catch (Exception ex)
            {
                LogErreur(ex);
                Notify.ShowNotification("Erreur", "Erreur ajouté au fichier log", System.Windows.Forms.ToolTipIcon.Error);
            }
        }
Example #2
0
        private void EnableOpenFileDialog()
        {
            OpenFileDialog fileBrowser = new OpenFileDialog();

            fileBrowser.Multiselect = true;
            fileBrowser.Filter      = "Image files (*.jpg, *.jpeg, *.jpe, *.jfif, *.png) | *.jpg; *.jpeg; *.jpe; *.jfif; *.png";
            var result = fileBrowser.ShowDialog();

            if (result == true)
            {
                List <ImageSource> images = new List <ImageSource>();
                foreach (FileStream file in fileBrowser.OpenFiles())
                {
                    BitmapImage image = new BitmapImage();
                    image.BeginInit();
                    image.StreamSource = file;
                    image.EndInit();
                    ImageThumbnailUploadVM imageThumbnailVM = new ImageThumbnailUploadVM(_imageToUpload);
                    imageThumbnailVM.ImageSource  = image;
                    imageThumbnailVM.Name         = ParseImageName(file.Name);
                    imageThumbnailVM.DateUploaded = DateTime.Now;
                    _imageToUpload.Add(imageThumbnailVM);
                }
                NotifyPropertyChanged("CanClickUpload");
            }
        }
        /// <summary>
        /// Import user activity data from file.
        /// </summary>
        public List <SessionGroup> ImportFile()
        {
            var groups = new List <SessionGroup>();

            var openFileDialog = new OpenFileDialog()
            {
                Filter      = string.Format("UAD-файлы (*.{0})|*.{0}", XmlUserActivityDataContext.UadFileExtension),
                Multiselect = true,
            };
            bool?result = openFileDialog.ShowDialog();

            if (result == true)
            {
                foreach (var stream in openFileDialog.OpenFiles())
                {
                    using (stream)
                    {
                        var sessionGroup = XmlUserActivityDataContext.LoadSessionGroup(stream);
                        groups.Add(sessionGroup);
                    }
                }
            }

            return(groups);
        }
        /// <summary>
        /// Adds the items.
        /// </summary>
        /// <param name="files">The files.</param>
        private void AddItems(OpenFileDialog files)
        {
            Stream[] fileStreams = files.OpenFiles();
            for (int index = 0; index < files.FileNames.Length; index++)
            {
                Gallery gallery = ((Gallery)galleryListBox.SelectedItem);

                ClientImage image = new ClientImage
                {
                    ImageName   = TruncatePath(files.FileNames[index]),
                    GalleryName = gallery.Name,
                    GalleryId   = gallery.GalleryID,
                    PhotoBytes  = GetByteArrayFromStream(fileStreams[index])
                };

                uploadListBox.Items.Add(image);
            }
        }
Example #5
0
        private void ExecuteImportDataFromFile()
        {
            var openFileDialog = new OpenFileDialog()
            {
                Filter      = string.Format("UAD-файлы (*.{0})|*.{0}", XmlUserActivityDataContext.UadFileExtension),
                Multiselect = true,
            };
            bool?result = openFileDialog.ShowDialog();

            if (result == true)
            {
                var serializer = new XmlSerializer(typeof(SessionGroup));
                foreach (var stream in openFileDialog.OpenFiles())
                {
                    using (stream)
                    {
                        SessionGroup sessionGroup = XmlUserActivityDataContext.LoadSessionGroup(stream);
                        SessionGroups.Add(sessionGroup);
                    }
                }

                var newRegions = new List <RegionImageItemVM>();
                foreach (var region in SessionGroups.SelectMany(sg => sg.Sessions).SelectMany(s => s.Regions))
                {
                    foreach (var image in region.Variations)
                    {
                        if (newRegions.FirstOrDefault(r => r.RegionName == region.Name && r.ImageName == image.Name) == null)
                        {
                            var newRegion = new RegionImageItemVM()
                            {
                                RegionName = region.Name, Image = image
                            };
                            newRegions.Add(newRegion);
                        }
                    }
                }
                RegionSelector.Clear();
                RegionSelector.AddRange(newRegions.OrderBy(r => r.RegionName));
                RegionSelector.SelectedItem = RegionSelector.FirstOrDefault();
            }
        }
Example #6
0
        private void ValidateFiles(OpenFileDialog dlg)
        {
            bool exist             = false;
            int  totalNumberOfFile = _vm.Files.Count + dlg.FileNames.Length;

            if (totalNumberOfFile > Maxnumberoffile)
            {
                ErrorHandler.ShowWarning((Maxnumberoffile - _vm.Files.Count) > 0
                                             ? string.Format("You can only upload {0} images more.",
                                                             (Maxnumberoffile - _vm.Files.Count).ToString(CultureInfo.InvariantCulture))
                                             : "The image library is full.");
                return;
            }

            int i = 0;

            foreach (var file in dlg.OpenFiles())
            {
                if (file.Length > Maxfilesize)
                {
                    if (!exist)
                    {
                        ErrorHandler.ShowWarning("There are at least one file exceed 1 MB.");
                        exist = true;
                    }
                }
                else
                {
                    _vm.TotalNumberOfFiles += 1;
                    var image = new BitmapImage();
                    //TODOHERE
                    image.StreamSource = file;
                    var fileViewModel = new FileViewModel(_vm, file.Length, dlg.SafeFileNames[i], image, file)
                    {
                        IsFinish = false
                    };
                    _vm.Files.Add(fileViewModel);
                }
                i++;
            }
        }
Example #7
0
        private void InputFileSelectionButton_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog fileDialog = new OpenFileDialog();

            fileDialog.Multiselect = true;
            fileDialog.Filter      = "All files (*.*)|*.*|Text Files (*.txt)|*.txt|Log Files (*.log)|*.log";
            fileDialog.DefaultExt  = "*.*";
            Nullable <bool> result = fileDialog.ShowDialog();

            if (result == true)
            {
                // Opens and reads files, adds to list
                // TODO: Check for douplicates
                Stream[] inputFileStream = fileDialog.OpenFiles();
                inputFilePaths.AddRange(fileDialog.FileNames);
                foreach (Stream s in inputFileStream)
                {
                    inputFiles.Add((new StreamReader(s)).ReadToEnd());
                }
                UpdatePreview();
            }
        }
Example #8
0
        /// <summary>
        /// WHISPER の検索結果を格納したテキストファイルからカードテキストデータを構築します。必要なら永続化します。
        /// </summary>
        private void OnBrowseSearchTxt(object sender, RoutedEventArgs e)
        {
#if !OFFLINE
            imgLoading.Visibility = Visibility.Visible;
            imgLoaded.Visibility  = Visibility.Collapsed;

            var dlg = new OpenFileDialog
            {
                FileName        = "search.txt",
                CheckFileExists = true,
                Multiselect     = true,
                Filter          = "テキスト ファイル (*.txt)|*.txt|すべてのファイル (*.*)|*.*"
            };

            if (dlg.ShowDialog(this) == true)
            {
                var  streams = dlg.OpenFiles();
                bool append  = false;

                foreach (var stream in streams)
                {
                    using var sr = new StreamReader(stream, Encoding.GetEncoding("shift-jis"));
                    App.SetCardInfosFromWhisper(sr, append);
                    append = true;
                }

                string appendixPath = App.GetPath("appendix.xml");
                if (File.Exists(appendixPath))
                {
                    Card.FixCardInfo(appendixPath);
                }

                App.SaveAsXml(App.GetPath("cards.xml"));

                imgLoaded.Visibility = Visibility.Visible;
            }
            imgLoading.Visibility = Visibility.Collapsed;
#endif
        }
Example #9
0
        private void OpenButton_Click(object sender, RoutedEventArgs e)
        {
            string[]       filenames      = { };
            Stream[]       streams        = { };
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Multiselect      = false;
            openFileDialog.Filter           = "PDF files (*.pdf)|*.pdf|Office files (*.doc;*.docx;*.xls;*.xlsx;*.ppt;*.pptx)|*.doc;*.docx;*.xls;*.xlsx;*.ppt;*.pptx|Text files (*.txt;*.rtf)|*.txt;*.rtf|All files (*.*)|*.*";
            openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            if (openFileDialog.ShowDialog() == true)
            {
                filenames = openFileDialog.FileNames;
                streams   = openFileDialog.OpenFiles();
            }
            if (streams.Length > 0)
            {
                TextReader textReader = new IFilterTextReader.FilterReader(filenames[0]);
                using (textReader)
                {
                    readerTextbox.Text = textReader.ReadToEnd();
                }
            }
        }
Example #10
0
        private void CheckInButton_Click(object sender, RoutedEventArgs e)
        {
            // Ensure a folder is selected
            if (FolderListBox.SelectedItems.Count == 0)
            {
                return;
            }

            // Get selected folder name
            var selectedFolderName = FolderListBox.SelectedItems[0] as string;

            // Open a file dialog
            var fileDialog = new OpenFileDialog
            {
                Filter = "C# Files|*.cs" // Only allow C# files to be checked in
            };
            var dialogResult = fileDialog.ShowDialog();

            // Check in selected files (may be more than one)
            if (dialogResult.HasValue && dialogResult.Value)
            {
                var selectedFiles = fileDialog.OpenFiles();
                var filenames     = fileDialog.FileNames;

                for (var i = 0; i < selectedFiles.Length; i++)
                {
                    var filename = Path.GetFileName(filenames[i]);
                    _Client.CheckIn(_LoggedInUser.Username, selectedFolderName, filename, selectedFiles[i]);
                }
            }

            /* Wait for check in to complete before refreshing the file list
             * Not good to block UI thread, but this is makes the UI behave more predictable to the user (new file shows up automatically).
             * The delay is very short so it is not noticeable to the user. */
            Thread.Sleep(100);
            RefreshFileList();
        }
Example #11
0
        public static void Attach(FileDialogOptions options)
        {
            try
            {
                var filter = new List <string>();

                if (options.AcceptFiles)
                {
                    filter.Add("Image files (*.jpg, *.jpeg, *.jpe, *.png) | *.jpg; *.jpeg; *.jpe; *.png");
                }

                if (options.AcceptPdfDocuments)
                {
                    filter.Add("PDF Documents | *.pdf");
                }

                if (options.AcceptWordDocuments)
                {
                    filter.Add("Word Documents |*.doc; *.docx");
                }

                if (options.AcceptExcelDocuments)
                {
                    filter.Add("Excel Worksheets|*.xls; *.xlsx");
                }

                var fileDialog = new OpenFileDialog
                {
                    Filter = string.Join(" | ", filter),
                    Title  = options.DialogTitle ?? (options.Multiple
                            ? SharedPhrases.AttachFiles
                            : SharedPhrases.AttachFile),
                    CheckFileExists = true,
                    CheckPathExists = true,
                    Multiselect     = options.Multiple
                };

                if (fileDialog.ShowDialog() != true)
                {
                    return;
                }

                if (options.Multiple)
                {
                    var streams = fileDialog.OpenFiles();

                    for (var i = 0; i < fileDialog.FileNames.Length; i++)
                    {
                        options.Files.Add(new IO.File()
                        {
                            Path   = fileDialog.FileNames[i],
                            Stream = streams[i]
                        });
                    }

                    return;
                }

                options.File = new IO.File()
                {
                    Path   = fileDialog.FileName,
                    Stream = fileDialog.OpenFile()
                };
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }
        }
Example #12
0
        public ImageViewModel TryLoadImage()
        {
            OpenFileDialog fileDialog = new OpenFileDialog()
            {
                CheckFileExists = true,
                CheckPathExists = true,
                Multiselect     = true,
                Filter          = "JPG Files (*.jpg)|*.jpg|JPEG Files (*.jpeg)|*.jpeg|PNG Files (*.png)|*.png"
            };

            Func <string, bool> isValidFile = file =>
            {
                string[] extensions =
                {
                    ".jpg",
                    ".png",
                    ".jpeg"
                };

                string ext = Path.GetExtension(file);
                return(extensions.Contains(ext));
            };

            fileDialog.FileOk += (sender, args) =>
            {
                if (!fileDialog.FileNames.All(isValidFile))
                {
                    args.Cancel = true;
                }
            };

            bool?dialogResult = fileDialog.ShowDialog();

            if (dialogResult.HasValue && dialogResult.Value)
            {
                try
                {
                    Stream[] files = fileDialog.OpenFiles();
                    for (int i = 0; i < fileDialog.FileNames.Length; i++)
                    {
                        string filePath = fileDialog.FileNames[i];
                        Stream file     = files[i];
                        byte[] fileData = null;

                        using (var stream = new MemoryStream())
                        {
                            file.CopyTo(stream);
                            fileData = stream.ToArray();
                        }

                        ImageViewModel viewModel = new ImageViewModel(0, Path.GetFileName(filePath), fileData);

                        return(viewModel);
                    }
                }
                catch (Exception ex)
                {
                }
            }

            return(null);
        }
        private void AddPatterns()
        {
            OpenFileDialog fileDialog = new OpenFileDialog()
            {
                CheckFileExists = true,
                CheckPathExists = true,
                Multiselect     = true,
                Filter          = "JPEG Files (*.jpeg)|*.jpeg|PNG Files (*.png)|*.png|JPG Files (*.jpg)|*.jpg"
            };

            Func <string, bool> isValidFile = file =>
            {
                string[] extensions =
                {
                    ".png",
                    ".jpeg",
                    ".jpg"
                };

                string ext = Path.GetExtension(file);
                return(extensions.Contains(ext));
            };

            fileDialog.FileOk += (sender, args) =>
            {
                if (!fileDialog.FileNames.All(isValidFile))
                {
                    args.Cancel = true;
                }
            };

            bool?dialogResult = fileDialog.ShowDialog();

            if (dialogResult.HasValue && dialogResult.Value)
            {
                try
                {
                    Stream[] files = fileDialog.OpenFiles();
                    for (int i = 0; i < fileDialog.FileNames.Length; i++)
                    {
                        string filePath = fileDialog.FileNames[i];
                        Stream file     = files[i];
                        byte[] fileData = null;

                        using (var stream = new MemoryStream())
                        {
                            file.CopyTo(stream);
                            fileData = stream.ToArray();
                        }

                        CheckablePatternDataViewModel viewModel = new PatternDataViewModel(Path.GetFileName(filePath), Pattern.PatternType, fileData)
                                                                  .ToCheckable(ItemState.Added);

                        Children.Add(viewModel);
                    }
                }
                catch (Exception ex)
                {
                }


                CheckItem();
            }
        }
Example #14
0
        private void btnSeleccionarFotografias_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog op = new OpenFileDialog();

            op.Multiselect = true;
            op.Title       = "Selecciona de 3 a 8 imágenes";
            op.Filter      = "Image files (*.jpg, *.jpeg, *.jpe, *.jfif, *.png) | *.jpg; *.jpeg; *.jpe; *.jfif; *.png";

            if (op.ShowDialog() == true)
            {
                archivoImagen = op.FileNames.ToList();
                streamImagen.Clear();


                for (int i = 0; i < archivoImagen.Count; i++)
                {
                    streamImagen.Add(op.OpenFiles()[i]);

                    switch (i)
                    {
                    case 0:
                        imagen1.Source = new BitmapImage(new Uri(archivoImagen[i]));
                        imagen2.Source = null;
                        imagen3.Source = null;
                        imagen4.Source = null;
                        imagen5.Source = null;
                        imagen6.Source = null;
                        imagen7.Source = null;
                        imagen8.Source = null;
                        break;

                    case 1:
                        imagen2.Source = new BitmapImage(new Uri(archivoImagen[i]));
                        break;

                    case 2:
                        imagen3.Source = new BitmapImage(new Uri(archivoImagen[i]));
                        break;

                    case 3:
                        imagen4.Source = new BitmapImage(new Uri(archivoImagen[i]));
                        break;

                    case 4:
                        imagen5.Source = new BitmapImage(new Uri(archivoImagen[i]));
                        break;

                    case 5:
                        imagen6.Source = new BitmapImage(new Uri(archivoImagen[i]));
                        break;

                    case 6:
                        imagen7.Source = new BitmapImage(new Uri(archivoImagen[i]));
                        break;

                    case 7:
                        imagen8.Source = new BitmapImage(new Uri(archivoImagen[i]));
                        break;
                    }
                }
            }
        }
Example #15
0
        private Tuple <string, string> FileDialogOpen()
        {
            StreamReader   streamread;
            OpenFileDialog open = new OpenFileDialog();

            Stream[] listStream;
            //listStream = open.OpenFiles();
            string alltext = "";
            string title   = "title";


            open.Multiselect = true;
            open.Filter      = "Pliki webowe (*.html)|*.html;";

            if (open.ShowDialog() == true)
            {
                //open.OpenFiles;

                listStream = open.OpenFiles();

                foreach (var x in listStream)
                {
                    streamread = new StreamReader(x);
                    string tempText = streamread.ReadToEnd();
                    if (tempText.Contains($"<div class=\"_3b0c\"><div class=\"_3b0d\">"))
                    {
                        int positionTitle    = tempText.IndexOf($"<div class=\"_3b0c\"><div class=\"_3b0d\">");
                        int positionEndTitle = tempText.IndexOf($"</div></div></div><div class=\"_4t5n\" role=\"main\">");
                        // MessageBox.Show(positionTitle.ToString()+"  "+ positionEndTitle.ToString());
                        if (positionTitle > 0 & positionEndTitle > 0)
                        {
                            title = tempText.Substring(positionTitle + 38, positionEndTitle - positionTitle - 38);
                        }


                        tempText = tempText.Remove(0, positionTitle);
                    }

                    alltext += tempText;
                    streamread.Close();

                    //string textFile = streamread.ReadToEnd();
                    // txtBlockFile.Text = File.ReadAllText(open.FileName);
                }



                //openFile(alltext);
                // string x=  countMessage(alltext).Item1;
                // groupMessages();

                //return "  Nazwa konwersacji: " + title;



                //streamread = new StreamReader(open.FileName);
            }


            return(Tuple.Create(title, alltext));
        }