Click or drag to resize

IFileSystemItemGetThumbnailAsync Method

IT Hit User File System
Called when thumbnail is requested by the platform.

Namespace:  ITHit.FileSystem
Assembly:  ITHit.FileSystem (in ITHit.FileSystem.dll) Version: 8.1.26727.0-Beta2
Syntax
Task<byte[]> GetThumbnailAsync(
	uint size,
	IOperationContext operationContext
)

Parameters

size
Type: SystemUInt32
Thumbnail size in pixels.
operationContext
Type: ITHit.FileSystemIOperationContext
Provides information about the environment.

Return Value

Type: TaskByte
Thumbnail bitmap or null if no thumbnail should be displayed for this item.
Exceptions
ExceptionCondition
NotImplementedExceptionIf no thumbnail should be displayed.
Remarks

To show thumbnails in your virtual drive on Windows platform follow these steps:

  1. Derive your class from one of the [!:ThumbnailProviderHandlerBase] class descendants. Add the GuidAttribute, ProgIdAttribute and ComVisibleAttribute attributes to your class. You do not need to implement any methods in your class.
  2. Add the desktop3:ThumbnailProviderHandler tag to your Package.appxmanifest (in case of packaged app) or appxmanifest.xml (in case of a sparse package) that references your class. Alternativly you can register your class as a COM component using regsvr32 or any other method.
  3. Implement the GetThumbnailAsync(UInt32, IOperationContext) method to return the thumbnail bitmap data.

Thumbnails functionality does NOT require package or application identity.

Examples

The code below is part of 'WebDAVDrive' C# sample provided with the SDK.

C#
[ComVisible(true)]
[ProgId("WebDAVDrive.ThumbnailProvider")]
[Guid("A5B0C82F-50AA-445C-A404-66DEB510E84B")]
public class ThumbnailProviderRpc : ThumbnailProviderHandlerRpcBase
{

}

The code below is part of 'WebDAVDrive' C# sample provided with the SDK.

XML
<Extensions>
  <desktop3:Extension Category="windows.cloudFiles">
    <desktop3:CloudFiles>
      <desktop3:CustomStateHandler Clsid="754F334F-095C-46CD-B033-B2C0523D2829"/>
      <desktop3:ThumbnailProviderHandler Clsid="A5B0C82F-50AA-445C-A404-66DEB510E84B"/>

      <desktop3:ExtendedPropertyHandler Clsid="20000000-0000-0000-0000-000000000001"/>
      <desktop3:BannersHandler Clsid="20000000-0000-0000-0000-000000000001"/>

      <desktop3:CloudFilesContextMenus>
        <desktop3:Verb Id="LockCommand" Clsid="A22EBD03-343E-433C-98DF-372C6B3A1538" />
      </desktop3:CloudFilesContextMenus>

    </desktop3:CloudFiles>
  </desktop3:Extension>
  <com:Extension Category="windows.comServer">
    <com:ComServer>
      <!-- When changing ProgId make sure to change it also in the ThumbnailProvider.cs -->

      <com:ExeServer DisplayName="WebDAVDrive.ShellExtension" Executable="WebDAVDrive.ShellExtension\WebDAVDrive.ShellExtension.exe">
        <com:Class Id="A5B0C82F-50AA-445C-A404-66DEB510E84B" />
      </com:ExeServer>

      <com:ExeServer DisplayName="WebDAVDrive.ShellExtension" Executable="WebDAVDrive.ShellExtension\WebDAVDrive.ShellExtension.exe">
        <com:Class Id="A22EBD03-343E-433C-98DF-372C6B3A1538" />
      </com:ExeServer>

      <com:ExeServer DisplayName="WebDAVDrive.ShellExtension" Executable="WebDAVDrive.ShellExtension\WebDAVDrive.ShellExtension.exe">
          <com:Class Id="754F334F-095C-46CD-B033-B2C0523D2829" />
      </com:ExeServer>

    </com:ComServer>
  </com:Extension>
</Extensions>

The code below is part of 'WebDAVDrive' C# sample provided with the SDK.

C#
public async Task<byte[]> GetThumbnailAsync(uint size, IOperationContext operationContext)
{
    byte[] thumbnail = null;

    string[] exts = Program.Settings.RequestThumbnailsFor.Trim().Split("|");
    string ext = System.IO.Path.GetExtension(UserFileSystemPath).TrimStart('.');

    if (exts.Any(ext.Equals) || exts.Any("*".Equals))
    {
        string ThumbnailGeneratorUrl = Program.Settings.ThumbnailGeneratorUrl.Replace("{thumbnail width}", size.ToString()).Replace("{thumbnail height}", size.ToString());
        string filePathRemote = ThumbnailGeneratorUrl.Replace("{path to file}", Engine.Mapping.MapPath(UserFileSystemPath));

        try
        {
            using (IDownloadResponse response = await Dav.DownloadAsync(new Uri(filePathRemote)))
            {
                using (Stream stream = await response.GetResponseStreamAsync())
                {
                    thumbnail = await StreamToByteArrayAsync(stream);
                }
            }
        }
        catch (System.Net.WebException we)
        {
            Logger.LogMessage(we.Message, UserFileSystemPath);
        }
        catch (Exception e)
        {
            Logger.LogError($"Failed to load thumbnail {size}px", UserFileSystemPath, null, e);
        }
    }

    string thumbnailResult = thumbnail != null ? "Success" : "Not Impl";
    Logger.LogMessage($"{nameof(VirtualEngine)}.{nameof(GetThumbnailAsync)}() - {thumbnailResult}", UserFileSystemPath);

    return thumbnail;
}

private static async Task<byte[]> StreamToByteArrayAsync(Stream stream)
{
    using (MemoryStream memoryStream = new())
    {
        await stream.CopyToAsync(memoryStream);
        return memoryStream.ToArray();
    }
}
See Also