private List <IPlugin> LoadPlugins(string path, Assembly pluginAssembly) { List <IPlugin> plugins = new List <IPlugin>(); Type pluginType = typeof(IPlugin); TypeFilter pluginTypeFilter = new TypeFilter(PluginService.PluginFilter); Type[] serviceProviderArgTypes = new Type[] { typeof(IServiceProvider), }; Type[] emptyArgTypes = new Type[0]; object[] serviceProviderArgs = new object[] { this.serviceProvider, }; object[] emptyArgs = new object[0]; foreach (string file in Directory.GetFiles(path, "*KinectStudioPlugin.dll", SearchOption.TopDirectoryOnly)) { try { Assembly dll = Assembly.LoadFrom(file); if (dll != pluginAssembly) { IEnumerable <Type> types = dll.ExportedTypes.Where(type => type.FindInterfaces(pluginTypeFilter, pluginType).Length > 0); foreach (Type type in types) { IPlugin plugin = null; try { { ConstructorInfo constructor = type.GetConstructor(serviceProviderArgTypes); if (constructor != null) { plugin = constructor.Invoke(serviceProviderArgs) as IPlugin; } } if (plugin == null) { ConstructorInfo constructor = type.GetConstructor(emptyArgTypes); if (constructor != null) { plugin = constructor.Invoke(emptyArgs) as IPlugin; } } bool okay = false; if (plugin != null) { okay = true; if (plugin.Id == Guid.Empty) { if (this.loggingService != null) { this.loggingService.LogLine(Strings.Plugin_Error_BadPluginId, plugin.Name, plugin.GetType().FullName, file); } okay = false; } if (okay) { Debug.Assert(plugin != null); foreach (IPlugin existingPlugin in plugins) { if (plugin.Id == existingPlugin.Id) { if (this.loggingService != null) { this.loggingService.LogLine(Strings.Plugin_Error_DuplicatePluginId, plugin.Name, plugin.GetType().FullName, file, existingPlugin.Name, existingPlugin.GetType().FullName); } okay = false; break; } } } } if (!okay) { IDisposable disposable = plugin as IDisposable; if (disposable != null) { disposable.Dispose(); } continue; } plugins.Add(plugin); IMetadataPlugin metadataPlugin = plugin as IMetadataPlugin; if (metadataPlugin != null) { PluginMetadataState metadataState = new PluginMetadataState(plugin); this.pluginMetadataStates.Add(metadataState); } } catch (Exception) { // TODO_LOG } } } } catch (BadImageFormatException) { // ignore non-managed DLLs } catch (Exception) { // TODO_LOG } } return(plugins); }
private void LoadMetadataDataTemplates() { DebugHelper.AssertUIThread(); Debug.Assert(this.plugins != null); lock (this.plugins) { this.readOnlyFileMetadata.Clear(); this.writableFileMetadata.Clear(); this.readOnlyStreamMetadata.Clear(); this.writableStreamMetadata.Clear(); // these defaults can be overridden LoadDefaultDataTemplate(this.writableFileMetadata, this.writableStreamMetadata, "KinectStudioPlugin.WritableByteMetadataValueDataTemplate", typeof(Byte)); LoadDefaultDataTemplate(this.writableFileMetadata, this.writableStreamMetadata, "KinectStudioPlugin.WritableInt16MetadataValueDataTemplate", typeof(Int16)); LoadDefaultDataTemplate(this.writableFileMetadata, this.writableStreamMetadata, "KinectStudioPlugin.WritableUInt16MetadataValueDataTemplate", typeof(UInt16)); LoadDefaultDataTemplate(this.writableFileMetadata, this.writableStreamMetadata, "KinectStudioPlugin.WritableInt32MetadataValueDataTemplate", typeof(Int32)); LoadDefaultDataTemplate(this.writableFileMetadata, this.writableStreamMetadata, "KinectStudioPlugin.WritableUInt32MetadataValueDataTemplate", typeof(UInt32)); LoadDefaultDataTemplate(this.writableFileMetadata, this.writableStreamMetadata, "KinectStudioPlugin.WritableInt64MetadataValueDataTemplate", typeof(Int64)); LoadDefaultDataTemplate(this.writableFileMetadata, this.writableStreamMetadata, "KinectStudioPlugin.WritableUInt64MetadataValueDataTemplate", typeof(UInt64)); LoadDefaultDataTemplate(this.writableFileMetadata, this.writableStreamMetadata, "KinectStudioPlugin.WritableSingleMetadataValueDataTemplate", typeof(Single)); LoadDefaultDataTemplate(this.writableFileMetadata, this.writableStreamMetadata, "KinectStudioPlugin.WritableDoubleMetadataValueDataTemplate", typeof(Double)); LoadDefaultDataTemplate(this.writableFileMetadata, this.writableStreamMetadata, "KinectStudioPlugin.WritableCharMetadataValueDataTemplate", typeof(Char)); LoadDefaultDataTemplate(this.writableFileMetadata, this.writableStreamMetadata, "KinectStudioPlugin.WritableBooleanMetadataValueDataTemplate", typeof(Boolean)); LoadDefaultDataTemplate(this.writableFileMetadata, this.writableStreamMetadata, "KinectStudioPlugin.WritableGuidMetadataValueDataTemplate", typeof(Guid)); LoadDefaultDataTemplate(this.writableFileMetadata, this.writableStreamMetadata, "KinectStudioPlugin.WritableDateTimeMetadataValueDataTemplate", typeof(DateTime)); LoadDefaultDataTemplate(this.writableFileMetadata, this.writableStreamMetadata, "KinectStudioPlugin.WritableTimeSpanMetadataValueDataTemplate", typeof(TimeSpan)); LoadDefaultDataTemplate(this.writableFileMetadata, this.writableStreamMetadata, "KinectStudioPlugin.WritablePointMetadataValueDataTemplate", typeof(Point)); LoadDefaultDataTemplate(this.writableFileMetadata, this.writableStreamMetadata, "KinectStudioPlugin.WritableSizeMetadataValueDataTemplate", typeof(Size)); LoadDefaultDataTemplate(this.writableFileMetadata, this.writableStreamMetadata, "KinectStudioPlugin.WritableRectMetadataValueDataTemplate", typeof(Rect)); LoadDefaultDataTemplate(this.writableFileMetadata, this.writableStreamMetadata, "KinectStudioPlugin.WritableStringMetadataValueDataTemplate", typeof(String)); LoadDefaultDataTemplate(this.writableFileMetadata, this.writableStreamMetadata, "KinectStudioPlugin.WritableBufferMetadataValueDataTemplate", typeof(KStudioMetadataValueBuffer)); LoadDefaultDataTemplate(this.writableFileMetadata, this.writableStreamMetadata, "KinectStudioPlugin.InvalidMetadataValueDataTemplate", typeof(KStudioInvalidMetadataValue)); LoadDefaultDataTemplate(this.writableFileMetadata, this.writableStreamMetadata, "KinectStudioPlugin.WritableByteArrayMetadataValueDataTemplate", typeof(Byte[])); LoadDefaultDataTemplate(this.writableFileMetadata, this.writableStreamMetadata, "KinectStudioPlugin.WritableInt16ArrayMetadataValueDataTemplate", typeof(Int16[])); LoadDefaultDataTemplate(this.writableFileMetadata, this.writableStreamMetadata, "KinectStudioPlugin.WritableUInt16ArrayMetadataValueDataTemplate", typeof(UInt16[])); LoadDefaultDataTemplate(this.writableFileMetadata, this.writableStreamMetadata, "KinectStudioPlugin.WritableInt32ArrayMetadataValueDataTemplate", typeof(Int32[])); LoadDefaultDataTemplate(this.writableFileMetadata, this.writableStreamMetadata, "KinectStudioPlugin.WritableUInt32ArrayMetadataValueDataTemplate", typeof(UInt32[])); LoadDefaultDataTemplate(this.writableFileMetadata, this.writableStreamMetadata, "KinectStudioPlugin.WritableInt64ArrayMetadataValueDataTemplate", typeof(Int64[])); LoadDefaultDataTemplate(this.writableFileMetadata, this.writableStreamMetadata, "KinectStudioPlugin.WritableUInt64ArrayMetadataValueDataTemplate", typeof(UInt64[])); LoadDefaultDataTemplate(this.writableFileMetadata, this.writableStreamMetadata, "KinectStudioPlugin.WritableSingleArrayMetadataValueDataTemplate", typeof(Single[])); LoadDefaultDataTemplate(this.writableFileMetadata, this.writableStreamMetadata, "KinectStudioPlugin.WritableDoubleArrayMetadataValueDataTemplate", typeof(Double[])); LoadDefaultDataTemplate(this.writableFileMetadata, this.writableStreamMetadata, "KinectStudioPlugin.WritableCharArrayMetadataValueDataTemplate", typeof(Char[])); LoadDefaultDataTemplate(this.writableFileMetadata, this.writableStreamMetadata, "KinectStudioPlugin.WritableBooleanArrayMetadataValueDataTemplate", typeof(Boolean[])); LoadDefaultDataTemplate(this.writableFileMetadata, this.writableStreamMetadata, "KinectStudioPlugin.WritableGuidArrayMetadataValueDataTemplate", typeof(Guid[])); LoadDefaultDataTemplate(this.writableFileMetadata, this.writableStreamMetadata, "KinectStudioPlugin.WritableDateTimeArrayMetadataValueDataTemplate", typeof(DateTime[])); LoadDefaultDataTemplate(this.writableFileMetadata, this.writableStreamMetadata, "KinectStudioPlugin.WritableTimeSpanArrayMetadataValueDataTemplate", typeof(TimeSpan[])); LoadDefaultDataTemplate(this.writableFileMetadata, this.writableStreamMetadata, "KinectStudioPlugin.WritablePointArrayMetadataValueDataTemplate", typeof(Point[])); LoadDefaultDataTemplate(this.writableFileMetadata, this.writableStreamMetadata, "KinectStudioPlugin.WritableSizeArrayMetadataValueDataTemplate", typeof(Size[])); LoadDefaultDataTemplate(this.writableFileMetadata, this.writableStreamMetadata, "KinectStudioPlugin.WritableRectArrayMetadataValueDataTemplate", typeof(Rect[])); LoadDefaultDataTemplate(this.writableFileMetadata, this.writableStreamMetadata, "KinectStudioPlugin.WritableStringArrayMetadataValueDataTemplate", typeof(String[])); LoadDefaultDataTemplate(this.readOnlyFileMetadata, this.readOnlyStreamMetadata, "KinectStudioPlugin.ReadOnlyNumberMetadataValueDataTemplate", typeof(Byte)); LoadDefaultDataTemplate(this.readOnlyFileMetadata, this.readOnlyStreamMetadata, "KinectStudioPlugin.ReadOnlyNumberMetadataValueDataTemplate", typeof(Int16)); LoadDefaultDataTemplate(this.readOnlyFileMetadata, this.readOnlyStreamMetadata, "KinectStudioPlugin.ReadOnlyNumberMetadataValueDataTemplate", typeof(UInt16)); LoadDefaultDataTemplate(this.readOnlyFileMetadata, this.readOnlyStreamMetadata, "KinectStudioPlugin.ReadOnlyNumberMetadataValueDataTemplate", typeof(Int32)); LoadDefaultDataTemplate(this.readOnlyFileMetadata, this.readOnlyStreamMetadata, "KinectStudioPlugin.ReadOnlyNumberMetadataValueDataTemplate", typeof(UInt32)); LoadDefaultDataTemplate(this.readOnlyFileMetadata, this.readOnlyStreamMetadata, "KinectStudioPlugin.ReadOnlyNumberMetadataValueDataTemplate", typeof(Int64)); LoadDefaultDataTemplate(this.readOnlyFileMetadata, this.readOnlyStreamMetadata, "KinectStudioPlugin.ReadOnlyNumberMetadataValueDataTemplate", typeof(UInt64)); LoadDefaultDataTemplate(this.readOnlyFileMetadata, this.readOnlyStreamMetadata, "KinectStudioPlugin.ReadOnlyNumberMetadataValueDataTemplate", typeof(Single)); LoadDefaultDataTemplate(this.readOnlyFileMetadata, this.readOnlyStreamMetadata, "KinectStudioPlugin.ReadOnlyNumberMetadataValueDataTemplate", typeof(Double)); LoadDefaultDataTemplate(this.readOnlyFileMetadata, this.readOnlyStreamMetadata, "KinectStudioPlugin.ReadOnlyStringMetadataValueDataTemplate", typeof(Char)); LoadDefaultDataTemplate(this.readOnlyFileMetadata, this.readOnlyStreamMetadata, "KinectStudioPlugin.ReadOnlyBooleanMetadataValueDataTemplate", typeof(Boolean)); LoadDefaultDataTemplate(this.readOnlyFileMetadata, this.readOnlyStreamMetadata, "KinectStudioPlugin.ReadOnlyStringMetadataValueDataTemplate", typeof(Guid)); LoadDefaultDataTemplate(this.readOnlyFileMetadata, this.readOnlyStreamMetadata, "KinectStudioPlugin.ReadOnlyStringMetadataValueDataTemplate", typeof(DateTime)); LoadDefaultDataTemplate(this.readOnlyFileMetadata, this.readOnlyStreamMetadata, "KinectStudioPlugin.ReadOnlyStringMetadataValueDataTemplate", typeof(TimeSpan)); LoadDefaultDataTemplate(this.readOnlyFileMetadata, this.readOnlyStreamMetadata, "KinectStudioPlugin.ReadOnlyStringMetadataValueDataTemplate", typeof(Point)); LoadDefaultDataTemplate(this.readOnlyFileMetadata, this.readOnlyStreamMetadata, "KinectStudioPlugin.ReadOnlyStringMetadataValueDataTemplate", typeof(Size)); LoadDefaultDataTemplate(this.readOnlyFileMetadata, this.readOnlyStreamMetadata, "KinectStudioPlugin.ReadOnlyStringMetadataValueDataTemplate", typeof(Rect)); LoadDefaultDataTemplate(this.readOnlyFileMetadata, this.readOnlyStreamMetadata, "KinectStudioPlugin.ReadOnlyStringMetadataValueDataTemplate", typeof(String)); LoadDefaultDataTemplate(this.readOnlyFileMetadata, this.readOnlyStreamMetadata, "KinectStudioPlugin.ReadOnlyBufferMetadataValueDataTemplate", typeof(KStudioMetadataValueBuffer)); LoadDefaultDataTemplate(this.readOnlyFileMetadata, this.readOnlyStreamMetadata, "KinectStudioPlugin.InvalidMetadataValueDataTemplate", typeof(KStudioInvalidMetadataValue)); LoadDefaultDataTemplate(this.readOnlyFileMetadata, this.readOnlyStreamMetadata, "KinectStudioPlugin.ReadOnlyArrayMetadataValueDataTemplate", typeof(Byte[])); LoadDefaultDataTemplate(this.readOnlyFileMetadata, this.readOnlyStreamMetadata, "KinectStudioPlugin.ReadOnlyArrayMetadataValueDataTemplate", typeof(Int16[])); LoadDefaultDataTemplate(this.readOnlyFileMetadata, this.readOnlyStreamMetadata, "KinectStudioPlugin.ReadOnlyArrayMetadataValueDataTemplate", typeof(UInt16[])); LoadDefaultDataTemplate(this.readOnlyFileMetadata, this.readOnlyStreamMetadata, "KinectStudioPlugin.ReadOnlyArrayMetadataValueDataTemplate", typeof(Int32[])); LoadDefaultDataTemplate(this.readOnlyFileMetadata, this.readOnlyStreamMetadata, "KinectStudioPlugin.ReadOnlyArrayMetadataValueDataTemplate", typeof(UInt32[])); LoadDefaultDataTemplate(this.readOnlyFileMetadata, this.readOnlyStreamMetadata, "KinectStudioPlugin.ReadOnlyArrayMetadataValueDataTemplate", typeof(Int64[])); LoadDefaultDataTemplate(this.readOnlyFileMetadata, this.readOnlyStreamMetadata, "KinectStudioPlugin.ReadOnlyArrayMetadataValueDataTemplate", typeof(UInt64[])); LoadDefaultDataTemplate(this.readOnlyFileMetadata, this.readOnlyStreamMetadata, "KinectStudioPlugin.ReadOnlyArrayMetadataValueDataTemplate", typeof(Single[])); LoadDefaultDataTemplate(this.readOnlyFileMetadata, this.readOnlyStreamMetadata, "KinectStudioPlugin.ReadOnlyArrayMetadataValueDataTemplate", typeof(Double[])); LoadDefaultDataTemplate(this.readOnlyFileMetadata, this.readOnlyStreamMetadata, "KinectStudioPlugin.ReadOnlyArrayMetadataValueDataTemplate", typeof(Char[])); LoadDefaultDataTemplate(this.readOnlyFileMetadata, this.readOnlyStreamMetadata, "KinectStudioPlugin.ReadOnlyArrayMetadataValueDataTemplate", typeof(Boolean[])); LoadDefaultDataTemplate(this.readOnlyFileMetadata, this.readOnlyStreamMetadata, "KinectStudioPlugin.ReadOnlyArrayMetadataValueDataTemplate", typeof(Guid[])); LoadDefaultDataTemplate(this.readOnlyFileMetadata, this.readOnlyStreamMetadata, "KinectStudioPlugin.ReadOnlyArrayMetadataValueDataTemplate", typeof(DateTime[])); LoadDefaultDataTemplate(this.readOnlyFileMetadata, this.readOnlyStreamMetadata, "KinectStudioPlugin.ReadOnlyArrayMetadataValueDataTemplate", typeof(TimeSpan[])); LoadDefaultDataTemplate(this.readOnlyFileMetadata, this.readOnlyStreamMetadata, "KinectStudioPlugin.ReadOnlyArrayMetadataValueDataTemplate", typeof(Point[])); LoadDefaultDataTemplate(this.readOnlyFileMetadata, this.readOnlyStreamMetadata, "KinectStudioPlugin.ReadOnlyArrayMetadataValueDataTemplate", typeof(Size[])); LoadDefaultDataTemplate(this.readOnlyFileMetadata, this.readOnlyStreamMetadata, "KinectStudioPlugin.ReadOnlyArrayMetadataValueDataTemplate", typeof(Rect[])); LoadDefaultDataTemplate(this.readOnlyFileMetadata, this.readOnlyStreamMetadata, "KinectStudioPlugin.ReadOnlyArrayMetadataValueDataTemplate", typeof(String[])); foreach (PluginMetadataState pluginState in this.pluginMetadataStates) { if (pluginState.IsEnabled) { Debug.Assert(pluginState.Plugin != null); IMetadataPlugin metadataPlugin = pluginState.Plugin as IMetadataPlugin; if (metadataPlugin != null) { LoadMetadataDataTemplates(this.readOnlyFileMetadata, metadataPlugin.FileReadOnlyDataTemplates); LoadMetadataDataTemplates(this.writableFileMetadata, metadataPlugin.FileWritableDataTemplates); LoadMetadataDataTemplates(this.readOnlyStreamMetadata, metadataPlugin.StreamReadOnlyDataTemplates); LoadMetadataDataTemplates(this.writableStreamMetadata, metadataPlugin.StreamWritableDataTemplates); } } } } }