File Server Resource Manager: Creating a custom classification module - Implementation
아티클
Hello everyone,
This is part 3 of my mini-series on how to create a custom file classification module that can be run by the File Server Resource Manager which ships with Windows Server 2008 R2. (If you missed the other parts, you can return to the index by clicking here)
The Implementation
To create a custom classification module you need to implement the IFsrmClassifierModuleImplementation interface. (See here for a description of the interface's members: https://msdn.microsoft.com/en-us/library/dd878721(VS.85).aspx) For that you will need to add a reference to the srmlib.dll to your project. (The DLL can be found in the system32 folder of Windows Server 2008 R2 or, alternatively, it comes with the Windows SDK.)
Here is a very simple implementation code:
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Runtime.InteropServices;using Microsoft.Storage;namespace FileServerClassificationModules{ /// <summary> /// All classification modules are COM servers. /// </summary> [ComVisible(true), Guid("B99FC137-4934-40C5-BB31-04C04B201479")] public class FileNameClassifier : IFsrmClassifierModuleImplementation { private DateTime _lastModified; /// <summary> /// The file's name. /// </summary> private String _name; public void DoesPropertyValueApply(string property, string Value, out bool applyValue, Guid idRule, Guid idPropDef) { // This will never be called if the module is registered correctly, but // it needs to be implemented anyway. applyValue = false; } public void GetPropertyValueToApply(string property, out string Value, Guid idRule, Guid idPropDef) { // I am not checking for the property. To improve performance I create 1 classification // module per property type - to avoid having to do costly string comparisons. // In this case I would call the module "File Name Module". I would use it for every property // that I'd want to set to the file's name. Value = _name; } public object LastModified { get { return _lastModified; } } public void OnBeginFile(IFsrmPropertyBag propertyBag, object[] arrayRuleIds) { _name = propertyBag.Name; } public void OnEndFile() { } public void OnLoad(IFsrmPipelineModuleDefinition moduleDefinition, out FsrmPipelineModuleConnector moduleConnector) { _lastModified = DateTime.Now; // bind this module to the module definition moduleConnector = new FsrmPipelineModuleConnector(); moduleConnector.Bind(moduleDefinition, this); } public void OnUnload() { } public void UseRulesAndDefinitions(IFsrmCollection Rules, IFsrmCollection propertyDefinitions) { } }}