public ImageLoader(object FileDir) { _root = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); // Get full exe app location on disk. var DirPath = Path.Combine(Root, FileDir.ToString()); if (Directory.Exists(DirPath)) // Check if directory is exists. { _supportedExtensions = new[] { ".bmp", ".jpeg", ".jpg", ".png" }; _isCatched = true; _files = Directory.GetFiles(Path.Combine(Root, FileDir.ToString()), "*.*").Where ((ext) => SupportedExtensions.Contains(Path.GetExtension(ext).ToLower())); _imageSources = new List <ImageSource>(); foreach (var file in Files) { BitmapImage BMP = new BitmapImage(); BMP.BeginInit(); BMP.CacheOption = BitmapCacheOption.OnLoad; BMP.UriSource = new Uri(file, UriKind.Absolute); BMP.EndInit(); BMP.Freeze(); _imageSources.Add(BMP); } } }
public bool IsSupportedExtension(string extension) { if (SupportedExtensions == null || SupportedExtensions.Count == 0) { return(true); } return(SupportedExtensions.Contains(extension)); }
public static void ParseMetadata( DirectoryInfo inputDirectory, DirectoryInfo jsonOutputDirectory, string sqliteFilepath, bool exportSqlite, bool exportJson, bool shouldOverwrite) { var files = inputDirectory.EnumerateFiles(); var validFiles = files.Where(n => SupportedExtensions.Contains(n.Extension)); var fileTagMap = new Dictionary <string, IDictionary <string, IEnumerable <string> > >(); foreach (var file in validFiles) { var path = file.FullName; TagLib.File tagFile = null; try { tagFile = TagLib.File.Create(path); } catch (Exception) { // TODO: Add Logging continue; } if (tagFile.GetTag(TagLib.TagTypes.Xiph) is TagLib.Ogg.XiphComment xiph) { IDictionary <string, IEnumerable <string> > tagMap = xiph.ToDictionary( fieldName => fieldName, fieldName => xiph.GetField(fieldName).AsEnumerable()); fileTagMap.Add(file.Name, tagMap); continue; } if (tagFile.GetTag(TagLib.TagTypes.Id3v2) is TagLib.Id3v2.Tag id3File) { IDictionary <string, IEnumerable <string> > tagMap = GetID3v2TagMap(id3File); fileTagMap.Add(file.Name, tagMap); continue; } } if (fileTagMap.Any()) { if (exportSqlite) { ExportSqlite(fileTagMap, sqliteFilepath); } if (exportJson) { ExportJson(fileTagMap, jsonOutputDirectory, shouldOverwrite); } } }
static FontCollection LoadSystemFonts() { // TODO: currently only supports Windows var collection = new FontCollection(); foreach (var file in Directory.EnumerateFiles(Environment.GetFolderPath(Environment.SpecialFolder.Fonts))) { if (SupportedExtensions.Contains(Path.GetExtension(file).ToLowerInvariant())) { collection.AddFontFile(file, throwOnError: false); } } return(collection); }
public string ModuleName(string filename) { if (!_fileSystem.File.Exists(filename)) { return(null); } if (!SupportedExtensions.Contains(_fileSystem.Path.GetExtension(filename))) { return(null); } var contents = _fileSystem.File.ReadLines(filename, Encoding.Default); var nameLine = contents.FirstOrDefault(line => line.StartsWith("Attribute VB_Name = ")); if (nameLine == null) { return(_fileSystem.Path.GetFileNameWithoutExtension(filename)); } //The format is Attribute VB_Name = "ModuleName" return(nameLine.Substring("Attribute VB_Name = ".Length + 1, nameLine.Length - "Attribute VB_Name = ".Length - 2)); }
public bool SupportsExtension(string oid) => SupportedExtensions != null && SupportedExtensions.Contains(oid);
protected void AddNodesToQueue(IEnumerable <XElement> nodes, string type) { if (_searchConfiguration.EnableIndexing == false) { LogHelper.Info <ElasticPublishedContentMediaIndexer>("Skipping AddNodesToQueue. EnableIndexing is configured to disabled."); return; } var umbracoContext = GetUmbracoContext(); if (umbracoContext == null) { LogHelper.Info <ElasticPublishedContentMediaIndexer>(() => "Skipping AddNodesToQueue as a valid UmbracoContext was unobtainable."); return; } var fullUrlResolverService = new UmbracoContextFullUrlResolverService(umbracoContext); using (var searchIndexingQueueService = new SearchIndexingQueueService(_searchConfiguration)) { LogHelper.Info <ElasticPublishedContentMediaIndexer>("AddNodesToQueue: {0} node(s) for index type {1}.", () => nodes.Count(), () => type); foreach (var node in nodes) { DataService.LogService.AddVerboseLog((int)node.Attribute("id"), string.Format("AddSingleNodeToIndex with type: {0}", type)); int nodeId = int.Parse(node.Attribute(XName.Get("id")).Value); var values = GetDataToIndex(node, type); //raise the event and assign the value to the returned data from the event var indexingNodeDataArgs = new IndexingNodeDataEventArgs(node, nodeId, values, type); OnGatheringNodeData(indexingNodeDataArgs); values = indexingNodeDataArgs.Fields; values.TryGetValue("nodeName", out string nodeName); string publishDate = string.Empty; if (!values.TryGetValue("reviewedDate", out publishDate)) { if (!values.TryGetValue("publishedDate", out publishDate)) { if (values.TryGetValue("updateDate", out publishDate)) { // Defaulted to updateDate property } } } var document = new SearchIndexDocumentModel() { NodeId = nodeId, Site = _site, Published = DateTime.Parse(publishDate), Title = nodeName }; // Determine if this is content or media if (string.Equals(type, UmbracoExamine.IndexTypes.Content, StringComparison.OrdinalIgnoreCase)) { var url = fullUrlResolverService.ResolveContentFullUrlById(nodeId); // Get content based on content fields in order of priority var contentBuilder = new StringBuilder(); foreach (var contentField in values.Where(x => IndexerData.UserFields.Select(y => y.Name).Contains(x.Key))) { var contentFieldValue = contentField.Value; // Check if it has a value and append it if (string.IsNullOrEmpty(contentFieldValue) == false) { if (contentFieldValue.DetectIsJson() && JsonUtility.TryParseJson(contentFieldValue, out object parsedJson)) { var processedJsonValue = ProcessJsonValue(parsedJson); if (string.IsNullOrEmpty(processedJsonValue) == false) { contentBuilder.AppendLine(processedJsonValue); } } else { var sanitisedValue = contentFieldValue.StripHtml().Trim(); if (string.IsNullOrWhiteSpace(sanitisedValue) == false) { contentBuilder.AppendLine(sanitisedValue); } } } } string content = contentBuilder.ToString().Trim(); document.Url = url; document.Content = content; // index the node searchIndexingQueueService.QueueUpsert(document); } else if (string.Equals(type, UmbracoExamine.IndexTypes.Media, StringComparison.OrdinalIgnoreCase)) { var fileExtension = node.Elements().FirstOrDefault(x => { if (x.Attribute("alias") != null) { return((string)x.Attribute("alias") == this.UmbracoExtensionProperty); } else { return(x.Name == this.UmbracoExtensionProperty); } }); if (HasNode(fileExtension) == false) { LogHelper.Warn <ElasticPublishedContentMediaIndexer>("Media name " + nodeName + " with ID " + nodeId + " has not been pushed up to SQS. Reason: " + UmbracoExtensionProperty + " value was not present."); continue; } if (!SupportedExtensions.Contains(fileExtension.Value, StringComparer.OrdinalIgnoreCase)) { LogHelper.Info <ElasticPublishedContentMediaIndexer>("Media name " + nodeName + " with ID " + nodeId + " has not been pushed up to SQS. Reason: File extension, " + fileExtension.Value + ", is not supported."); continue; } var filePath = node.Elements().FirstOrDefault(x => { if (x.Attribute("alias") != null) { return((string)x.Attribute("alias") == this.UmbracoFileProperty); } else { return(x.Name == this.UmbracoFileProperty); } }); if (HasNode(filePath) == false) { LogHelper.Warn <ElasticPublishedContentMediaIndexer>("Media name " + nodeName + " with ID " + nodeId + " has not been pushed up to SQS. Reason: " + UmbracoFileProperty + " value was not present."); continue; } //get the file path from the data service var fullPath = this.DataService.MapPath((string)filePath); if (System.IO.File.Exists(fullPath) == false) { LogHelper.Warn <ElasticPublishedContentMediaIndexer>("Media name " + nodeName + " with ID " + nodeId + " has not been pushed up to SQS. Reason: Physical file does not exist."); continue; } var fileInfo = new FileInfo(fullPath); var url = fullUrlResolverService.ResolveMediaFullUrl(filePath.Value); // index the node var pdf = System.IO.File.ReadAllBytes(fullPath); var pdfEncoded = Convert.ToBase64String(pdf); document.Url = url; document.Content = "Umbraco Media File"; document.FileBase64Encoded = pdfEncoded; document.FileExtension = fileInfo.Extension; document.FileSizeInBytes = fileInfo.Length; searchIndexingQueueService.QueueUpsert(document); } } } }
private void ScanImagesThread( BackgroundWorker imagesScanner, DoWorkEventArgs e) { IndexOfCurImg = -2; int count = 0; if (UiStartDirectory != null) { var directoryInfo = new DirectoryInfo(UiStartDirectory); foreach (var imageFile in directoryInfo.GetFiles().Where(s => s.Extension.Length >= 3 && SupportedExtensions.Contains( s.Extension.ToLower()))) { Dispatcher.Invoke(new Action(() => { var img = new Image { Source = DefImage, Tag = imageFile.FullName, MaxWidth = SizeImage, MaxHeight = SizeImage * 0.8, Stretch = Stretch.UniformToFill, Margin = new Thickness(3) }; img.MouseLeftButtonUp += OnImageWrapPanelClick; img.MouseEnter += OnStartHover; img.MouseLeave += OnEndHover; imgWrapList.Children.Add(img); var timeToolTip = new ToolTip { PlacementTarget = img, Content = imageFile.Name }; img.ToolTip = timeToolTip; count = imgWrapList.Children.Count; if (count != 1) { return; } UcImageViewer.ImageList.IndexOfCurImg = 0; OnImageWrapPanelClick(imgWrapList.Children[0], new RoutedEventArgs()); }), null); } for (int i = 0; i < count; i++) { var counter = i; Dispatcher.Invoke(new Action(() => { if (imgWrapList.Children.Count == 0) { return; } var img = ((Image)imgWrapList.Children[counter]); img.Source = ImageUtils.GetSmallImage(img.Tag.ToString(), (int)SizeImage + 30); }), null); Thread.Sleep(40); } } }
public static bool CheckForExtension(string NeededExt) { return(SupportedExtensions.Contains(NeededExt)); }