-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSearchResultMixin.cs
45 lines (43 loc) · 1.06 KB
/
SearchResultMixin.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
using System;
using System.Collections.Generic;
using System.DirectoryServices;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media;
using System.Windows.Media.Imaging;
namespace CorporateBrowser
{
public static class SearchResultMixin
{
public static string SafeReadString(this SearchResult item, string property)
{
var props = item.Properties[property];
return props.Count > 0 ? props[0] as string : "";
}
public static ImageSource SafeReadPicture(this SearchResult item)
{
var jpegPhotoPropertyValue = item.Properties["jpegPhoto"];
if (jpegPhotoPropertyValue.Count > 0)
{
try
{
var realBytes = jpegPhotoPropertyValue[0] as byte[];
var memStream = new MemoryStream(realBytes, writable: false);
var jpeg = new JpegBitmapDecoder(memStream, BitmapCreateOptions.None, BitmapCacheOption.Default);
var result = jpeg.Frames[0];
return result;
}
catch (FileFormatException ex)
{
return null;
}
}
else
{
return null;
}
}
}
}