コード例 #1
0
        /// <summary>
        /// Collects all of the data that needs to be indexed as defined in the index set.
        /// </summary>
        /// <param name="node">Media item XML being indexed</param>
        /// <param name="type">Type of index (should only ever be media)</param>
        /// <returns>Fields containing the data for the index</returns>
        protected override Dictionary <string, string> GetDataToIndex(XElement node, string type)
        {
            var fields = base.GetDataToIndex(node, type);

            //find the field which contains the file
            XElement fileElement = node.Elements().FirstOrDefault(x =>
            {
                if (x.Attribute("alias") != null)
                {
                    return((string)x.Attribute("alias") == this.UmbracoFileProperty);
                }
                else
                {
                    return(x.Name == this.UmbracoFileProperty);
                }
            });

            //make sure the file exists
            if (fileElement != default(XElement) && !string.IsNullOrEmpty(fileElement.Value))
            {
                // Parse the current value
                string filePath = fileElement.Value;
                if ((filePath).StartsWith("{"))
                {
                    filePath = JObject.Parse(filePath).Value <string>("src");
                }

                if (!filePath.IsNullOrWhiteSpace())
                {
                    // Get the file path from the data service
                    string fullPath = this.DataService.MapPath(filePath);
                    var    fi       = new FileInfo(fullPath);
                    if (fi.Exists)
                    {
                        try
                        {
                            if (!SupportedExtensions.Select(x => x.ToUpper()).Contains(fi.Extension.ToUpper()))
                            {
                                DataService.LogService.AddInfoLog((int)node.Attribute("id"), "UmbracoExamine.FileIndexer: Extension '" + fi.Extension + "' is not supported at this time");
                            }
                            else
                            {
                                fields.Add(TextContentFieldName, ExtractTextFromFile(fi));
                            }
                        }
                        catch (Exception ex)
                        {
                            DataService.LogService.AddErrorLog((int)node.Attribute("id"), "An error occurred: " + ex);
                        }
                    }
                    else
                    {
                        DataService.LogService.AddInfoLog((int)node.Attribute("id"), "UmbracoExamine.FileIndexer: No file found at path " + filePath);
                    }
                }
            }

            return(fields);
        }
コード例 #2
0
        private void buttonBrowse_Click(object sender, EventArgs e)
        {
            var wildcards = SupportedExtensions.Select(p => "*" + p);
            var dialog    = new OpenFileDialog()
            {
                Filter = FileFilterStrings.AudioFilter + string.Format("({0})|{1}", string.Join(", ", wildcards), string.Join(";", wildcards))
            };

            if (dialog.ShowDialog(this) == DialogResult.OK)
            {
                filePathBox.Text = dialog.FileName;
            }
        }
コード例 #3
0
        /// <summary>
        /// need to prevent extensions not in allowed extensions getting into the index
        /// </summary>
        /// <param name="node"></param>
        /// <returns></returns>
        private bool IsAllowedExtension(XElement node)
        {
            var extension = node.Element("umbracoExtension");

            if (extension != null)
            {
                var extensionValue = "." + extension.Value;
                if (SupportedExtensions.Select(x => x.ToUpper()).Contains(extensionValue.ToUpper()))
                {
                    return(true);
                }
            }
            return(false);
        }
コード例 #4
0
        /// <summary>
        /// Provides the means to extract the text to be indexed from the file specified
        /// </summary>
        /// <param name="file"></param>
        /// <returns></returns>
        protected virtual string ExtractTextFromFile(FileInfo file)
        {
            if (!SupportedExtensions.Select(x => x.ToUpper()).Contains(file.Extension.ToUpper()))
            {
                throw new NotSupportedException("The file with the extension specified is not supported");
            }

            var mediaParser = new MediaParser();

            Action <Exception> onError = (e) => OnIndexingError(new IndexingErrorEventArgs("Could not read media item", -1, e));

            var txt = mediaParser.ParseMediaText(file.FullName, onError, out _extractedMetaFromTika);

            return(txt);
        }
コード例 #5
0
        /// <summary>
        /// Provides the means to extract the text to be indexed from the file specified
        /// </summary>
        /// <param name="file"></param>
        /// <returns></returns>
        protected virtual string ExtractTextFromFile(FileInfo file)
        {
            if (!SupportedExtensions.Select(x => x.ToUpper()).Contains(file.Extension.ToUpper()))
            {
                throw new NotSupportedException("The file with the extension specified is not supported");
            }

            var pdf = new PDFParserPdfBox();

            Action <Exception> onError = (e) => OnIndexingError(new IndexingErrorEventArgs("Could not read PDF", -1, e));

            var txt = pdf.GetTextFromAllPages(file.FullName, onError);

            return(txt);
        }
コード例 #6
0
        /// <summary>
        /// Provides the means to extract the text to be indexed from the file specified
        /// </summary>
        /// <param name="filePath"></param>
        /// <param name="mediaFileSystem"></param>
        /// <returns></returns>
        protected virtual string ExtractTextFromFile(string filePath, MediaFileSystem mediaFileSystem)
        {
            var fileExtension = mediaFileSystem.GetExtension(filePath);

            if (!SupportedExtensions.Select(x => x.ToUpper()).Contains(fileExtension.ToUpper()))
            {
                throw new NotSupportedException("The file with the extension specified is not supported");
            }

            var pdf = new PDFParser();

            Action <Exception> onError = (e) => OnIndexingError(new IndexingErrorEventArgs("Could not read PDF", -1, e));

            var txt = pdf.GetTextFromAllPages(filePath, mediaFileSystem, onError);

            return(txt);
        }
コード例 #7
0
        public SoundSourceSelector()
        {
            InitializeComponent();
            AllowDrop = true;

            browseButton.Click += (s, e) =>
            {
                var wildcards = SupportedExtensions.Select(p => "*" + p);
                var dialog    = new OpenFileDialog()
                {
                    Title  = "音源選択",
                    Filter = "音声ファイル" + string.Format("({0})|{1}", string.Join(", ", wildcards), string.Join(";", wildcards))
                };
                if (dialog.ShowDialog(this) == DialogResult.OK)
                {
                    fileBox.Text = dialog.FileName;
                }
            };
        }