public virtual T ConstructObject <T>(string name, object[] args = null) where T : class { args ??= new object[0]; if (!string.IsNullOrWhiteSpace(name)) { try { if (PluginTypes.FirstOrDefault(t => t.FullName == name) is TypeInfo type) { var matchingConstructors = from ctor in type.GetConstructors() let parameters = ctor.GetParameters() where parameters.Length == args.Length where IsValidParameterFor(args, parameters) select ctor; if (matchingConstructors.FirstOrDefault() is ConstructorInfo constructor) { return((T)constructor.Invoke(args) ?? null); } } } catch { Log.Write("Plugin", $"Unable to construct object '{name}'", LogLevel.Error); } } Log.Write("Plugin", $"No constructor found for '{name}'", LogLevel.Debug); return(null); }
public (string headerName, string headerValue) ToString(ICspNonceService nonceService) { string headerName; if (ReportOnly) { headerName = "Content-Security-Policy-Report-Only"; } else { headerName = "Content-Security-Policy"; } var values = new List <string> { Default.ToString(nonceService), Script.ToString(nonceService), Style.ToString(nonceService), #pragma warning disable CS0618 // Type or member is obsolete Child.ToString(nonceService), #pragma warning restore CS0618 // Type or member is obsolete Connect.ToString(nonceService), Manifest.ToString(nonceService), Font.ToString(nonceService), FormAction.ToString(nonceService), Img.ToString(nonceService), Media.ToString(nonceService), Object.ToString(nonceService), FrameAncestors.ToString(), PluginTypes.ToString(), Frame.ToString(nonceService), Worker.ToString(nonceService), Prefetch.ToString(nonceService), BaseUri.ToString(nonceService), RequireSri.ToString() }; if (BlockAllMixedContent) { values.Insert(0, "block-all-mixed-content"); } if (UpgradeInsecureRequests) { values.Insert(0, "upgrade-insecure-requests"); } if (EnableSandbox) { values.Add(Sandbox.ToString()); } if (ReportUri != null) { values.Add("report-uri " + ReportUri); } string headerValue = string.Join(";", values.Where(s => s.Length > 0)); return(headerName, headerValue); }
protected MockPlugin(PluginTypes pluginType) { Types = _pluginTypes; PluginType = pluginType; _name = GetType().FullName; AssemblyName = "unit-test"; AssemblyVersion = "unit-test-version"; }
public async Task RunPlugin(PluginTypes pluginTypes, Response response, Thread thread, Board board, Session session, MainContext context) { if (isFirstRunning) { await sharedPlugins.LoadBoardPluginSettings((await context.Boards.ToListAsync()).Select(x => x.BoardKey)); isFirstRunning = false; } sharedPlugins.RunPlugins(pluginTypes, board, thread, response, session); }
Exception LoadPlugins(bool initialLoad) { var pluginsDirectory = ProjectSettings.PluginsFolder; if (!Directory.Exists(pluginsDirectory)) { return(null); } foreach (var directory in Directory.GetDirectories(pluginsDirectory)) { var compilerDll = Path.Combine(directory, "Compiler.dll"); if (File.Exists(compilerDll)) { var assembly = LoadAssembly(compilerDll); if (assembly == null) { continue; } var compilerType = assembly.GetTypes().FirstOrDefault(x => x.Implements <ICryMonoPlugin>()); Debug.LogAlways(" Initializing CryMono plugin: {0}...", compilerType.Name); var compiler = Activator.CreateInstance(compilerType) as ICryMonoPlugin; PluginTypes.Add(compiler, null); var assemblyPaths = Directory.GetFiles(directory, "*.dll", SearchOption.AllDirectories); var assemblies = new List <Assembly>(); foreach (var assemblyPath in assemblyPaths) { if (assemblyPath != compilerDll) { var foundAssembly = LoadAssembly(assemblyPath); if (foundAssembly != null) { assemblies.Add(foundAssembly); } } } try { PluginTypes[compiler] = compiler.GetTypes(assemblies); } catch (Exception ex) { return(ex); } } } return(null); }
public IPlugin Get(string name, PluginTypes type) { foreach (KeyValuePair<string, IPlugin> pair in _plugins) { if (pair.Value.PluginName == name && pair.Value.PluginType == type) { return pair.Value; } } return null; }
public IPlugin Get(string name, PluginTypes type) { foreach (KeyValuePair <string, IPlugin> pair in _plugins) { if (pair.Value.PluginName == name && pair.Value.PluginType == type) { return(pair.Value); } } return(null); }
public ZerochSharpPlugin( Board board, Thread thread, Response response, PluginTypes types, object settings = null, object sessionData = null) { Board = board; Thread = thread; PluginTypes = types; Response = response; PluginSetting = settings; SessionData = sessionData; }
public PluginData(string asmname, string classname, PluginTypes type, Type _class) { AssemblyName = asmname; ClassName = classname; PluginType = type; Class = _class; if (PluginType == PluginTypes.Generator) { PluginName = (Activator.CreateInstance(Class) as Generator).Name; } }
protected virtual void UseDefaultServices() { // IPluginHost acts as a tagging service here indicating UseDefaultServices // was already called earlier if (Services.HasService <IPluginHost>()) { return; } Services.AddSingleton(_ => Host); Services.TryAddSingleton <ILoggerFactory, NullLoggerFactory>(); Services.TryAddSingleton(typeof(ILogger <>), typeof(Logger <>)); if (!Services.HasService <PluginSetInfo>()) { var hasPluginSetInfo = Plugins.InfoByType.Count != 0; if (hasPluginSetInfo) { // Plugin set is known, so no need to look for plugins Services.TryAddSingleton(Plugins); } else { // Plugin set isn't known, so we need IPluginFinder Services.TryAddSingleton <IPluginFinder, PluginFinder>(); Services.TryAddSingleton(services => { var pluginFinder = services.GetRequiredService <IPluginFinder>(); var plugins = pluginFinder.FindPlugins(); return(plugins); }); } } // Adding filter that makes sure only plugins castable to the // requested ones are exposed. if (PluginTypes.Count > 0) { var hPluginTypes = PluginTypes.Select(t => (TypeRef)t).ToHashSet(); this.AddPluginFilter(p => p.CastableTo.Any(c => hPluginTypes.Contains(c))); } Services.TryAddSingleton <IPluginFactory, PluginFactory>(); Services.TryAddSingleton <IPluginCache, PluginCache>(); Services.TryAddSingleton(typeof(IPluginInstanceHandle <>), typeof(PluginInstanceHandle <>)); Services.TryAddSingleton(typeof(IPluginHandle <>), typeof(PluginHandle <>)); }
public virtual T ConstructObject <T>(string name, object[] args = null) where T : class { args ??= new object[0]; if (!string.IsNullOrWhiteSpace(name)) { try { if (PluginTypes.FirstOrDefault(t => t.FullName == name) is TypeInfo type) { var matchingConstructors = from ctor in type.GetConstructors() let parameters = ctor.GetParameters() where parameters.Length == args.Length where IsValidParameterFor(args, parameters) select ctor; if (matchingConstructors.FirstOrDefault() is ConstructorInfo constructor) { T obj = (T)constructor.Invoke(args) ?? null; if (obj != null) { Inject(obj, type); } return(obj); } else { Log.Write("Plugin", $"No constructor found for '{name}'", LogLevel.Error); } } } catch (TargetInvocationException e) when(e.Message == "Exception has been thrown by the target of an invocation.") { Log.Write("Plugin", "Object construction has thrown an error", LogLevel.Error); Log.Exception(e.InnerException); } catch (Exception e) { Log.Write("Plugin", $"Unable to construct object '{name}'", LogLevel.Error); Log.Exception(e); } } return(null); }
/// <summary> Retrieves all steps available in given assembly and selected type </summary> /// <param name="pluginAssembly"><see cref="PluginAssembly"/> for which steps should be /// retrieved</param> <param name="pluginType"<see cref="PluginType"/> for which steps /// should be retrieved</param> public void RetrieveSteps(PluginAssembly pluginAssembly, PluginType pluginType) { WorkAsync(new WorkAsyncInfo("Loading steps...", a => { a.Result = (pluginType != null) ? Service.GetSdkMessageProcessingSteps(pluginAssembly.Id, pluginType.Id) : Service.GetSdkMessageProcessingSteps(pluginAssembly.Id); }) { PostWorkCallBack = (a) => { PluginTypes = this.cbSourcePlugin.Items.Cast <PluginType>().ToArray(); ProcessingSteps = ((Entity[])a.Result).Select <Entity, ProcessingStep>(x => { return(new ProcessingStep(x, pluginAssembly, PluginTypes.Where(y => y.Id == ((EntityReference)x.Attributes[Constants.Crm.Attributes.PLUGIN_TYPE_ID]).Id).FirstOrDefault())); }).ToArray(); lvSteps.Items.Clear(); // var groups = new Dictionary<Guid, int>(); // If pluginType is null, so all available in current assembly types are selected //foreach (var type in this.PluginTypes) //{ // var item = new ListViewGroup // { // Header = type.FriendlyName, // }; // this.lvSteps.Groups.Add(item); groups.Add(type.Id, i++); //} foreach (var step in this.ProcessingSteps) { var item = new ListViewItem(new string[] { step.FriendlyName, step.StateCode.ToString() }); item.Tag = step; // item.Group = this.lvSteps.Groups[groups[step.ParentType.Id]]; this.lvSteps.Items.Add(item); } } }); }
public void Load(string jsonConfiguration) { JsonConfiguration = jsonConfiguration; var plugins = JsonConvert.DeserializeObject <Dictionary <string, JObject> >(JsonConfiguration); foreach (var plugin in plugins) { var type = PluginTypes.FirstOrDefault(each => each.Name == plugin.Key + "Plugin"); if (type == null) { throw new Exception("Invalid plugin: " + plugin.Key); } var instance = plugin.Value.ToObject(type) as Plugin; Plugins.Add(instance); } }
public Tuple <string, string> ToString(ICspNonceService nonceService) { string headerName; if (ReportOnly) { headerName = "Content-Security-Policy-Report-Only"; } else { headerName = "Content-Security-Policy"; } ICollection <string> values = new List <string> { DefaultSrc.ToString(nonceService), ScriptSrc.ToString(nonceService), StyleSrc.ToString(nonceService), ChildSrc.ToString(nonceService), ConnectSrc.ToString(nonceService), FontSrc.ToString(nonceService), FormAction.ToString(nonceService), ImgSrc.ToString(nonceService), MediaSrc.ToString(nonceService), ObjectSrc.ToString(nonceService), FrameAncestors.ToString(), PluginTypes.ToString() }; if (EnableSandbox) { values.Add(Sandbox.ToString()); } if (ReportUri != null) { values.Add("report-uri " + ReportUri); } string headerValue = string.Join(";", values.Where(s => s.Length > 0)); return(new Tuple <string, string>(headerName, headerValue)); }
public async void RunPlugins(PluginTypes types, Board board, Thread thread, Response response, Session session) { var targetPlugin = LoadedPlugins.Where(x => (x.PluginType & types) == types && x.IsEnabled && x.Valid && x.ActivatedBoards.Contains(board.BoardKey)) .OrderBy(x => x.Priority); foreach (var item in targetPlugin) { try { await item.Script.RunAsync(new ZerochSharpPlugin(board, thread, response, types, item.BoardSetting?[board.BoardKey] as dynamic, session)); } catch (CompilationErrorException ex) { Console.WriteLine("Error in plugin running."); Console.WriteLine(ex.Message); var plugin = LoadedPlugins.FirstOrDefault(x => x.PluginPath == item.PluginPath); if (plugin == null) { throw new InvalidOperationException(); } plugin.Valid = false; await SavePluginInfo(); Console.WriteLine($"Plugin {item.PluginName} is disabled."); } catch (Exception e) { throw new InvalidOperationException("error in running plugin", e); } } }
public static T ConstructObject <T>(string name, object[] args = null) where T : class { args ??= new object[0]; if (!string.IsNullOrWhiteSpace(name)) { try { var type = PluginTypes.FirstOrDefault(t => t.FullName == name); var matchingConstructors = from ctor in type?.GetConstructors() let parameters = ctor.GetParameters() where parameters.Length == args.Length where args.IsValidParameterFor(parameters) select ctor; var constructor = matchingConstructors.FirstOrDefault(); return((T)constructor?.Invoke(args) ?? null); } catch { Log.Write("Plugin", $"Unable to construct object '{name}'", LogLevel.Error); } } return(null); }
public static extern void Sixense_UpdateEyeTransform(PluginTypes.Vector pos, PluginTypes.Quat rot, bool isPositionTracked);
public static extern void Sixense_UpdateJointPositions(PluginTypes.Skeleton skel);
public static extern PluginTypes.Result sxCoreGetDataPrevious(uint tracked_device_index, uint history_index_back, out PluginTypes.TrackedDeviceData data);
public static extern PluginTypes.Result sxCoreGetInfo(uint tracked_device_index, out PluginTypes.TrackedDeviceInfo info);
internal void ProcessInfo(PluginTypes.TrackedDeviceInfo info) { const byte gpio_id_mask = 0x3; const byte gpio_rev_mask = 0xC; m_SerialNumber = info.serial_number; m_HardwareType = (Hardware)info.device_type; // m_Index = info.tracked_device_index; // Redundant, and screws up Hydra byte bid = (byte)(info.board_hardware_gpio & gpio_id_mask); byte brev = (byte)(info.board_hardware_gpio & gpio_rev_mask); m_Hardware = info.hardware_revision.ToString("X2") + "-" + bid.ToString("X") + "r" + brev.ToString("X"); m_Firmware = info.mcu_firmware_version_major.ToString("X2") + "." + info.mcu_firmware_version_minor.ToString("X2") + "-" + info.dsp_firmware_version_major.ToString("X2") + "." + info.dsp_firmware_version_minor.ToString("X2"); m_Runtime = info.runtime_version_major + "." + info.runtime_version_minor.ToString("00"); m_MagneticFrequency = info.magnetic_frequency; m_batteryVoltage = info.battery_voltage; m_hasInfo = (m_HardwareType != Hardware.NONE); if (m_hasInfo) m_Connected = true; }
public List <IPluginDescriptor> GetByType(PluginTypes type) { return(_plugins.Values.Where(d => d.Metadata.Type == type).ToList()); }
public static extern void Sixense_GetJointPositions(out PluginTypes.Skeleton skel);
public static extern void Sixense_GetSafeArea(out PluginTypes.Vector center, out float radius);
public static extern void Sixense_GetMovementDelta(out PluginTypes.Vector vec);
public static extern void Sixense_SetJointOffset(Tracker track, PluginTypes.Vector vec);
public static extern void Sixense_GetTorsoRotation(out PluginTypes.Quat rot);
public static extern void Sixense_GetHingeAxis(JointChain chain, out PluginTypes.Vector vec);
public static extern void Sixense_SetBaseConstraintTransform(PluginTypes.Vector pos, PluginTypes.Quat rot, bool isConstrained, bool isFixedHeight);
public static extern void Sixense_SetSafeArea(PluginTypes.Vector center, float radius);
public static extern void Sixense_SetTrackerTransform(Tracker track, PluginTypes.Vector pos, PluginTypes.Quat rot);
public static extern void Sixense_UpdateHingeAxis(JointChain chain, PluginTypes.Vector vec);
public static extern void Sixense_GetHeadOffset(out PluginTypes.Vector vec);
public static extern void Sixense_GetEyeTransform(out PluginTypes.Vector pos, out PluginTypes.Quat rot);
internal CspOptions Build() { List <string> directives = new List <string>(); string connectSourcesString = ConnectSources.Build(); if (!string.IsNullOrEmpty(connectSourcesString)) { directives.Add($"connect-src {connectSourcesString}"); } string defaultResourcesString = DefaultSources.Build(); if (!string.IsNullOrEmpty(defaultResourcesString)) { directives.Add($"default-src {defaultResourcesString}"); } string fontSourcesString = FontSources.Build(); if (!string.IsNullOrEmpty(fontSourcesString)) { directives.Add($"font-src {fontSourcesString}"); } string frameSourcesString = FrameSources.Build(); if (!string.IsNullOrEmpty(frameSourcesString)) { directives.Add($"frame-src {frameSourcesString}"); } string imgSourcesString = ImgSources.Build(); if (!string.IsNullOrEmpty(imgSourcesString)) { directives.Add($"img-src {imgSourcesString}"); } string manifestSourcesString = ManifestSources.Build(); if (!string.IsNullOrEmpty(manifestSourcesString)) { directives.Add($"manifest-src {manifestSourcesString}"); } string mediaSourcesString = MediaSources.Build(); if (!string.IsNullOrEmpty(mediaSourcesString)) { directives.Add($"media-src {mediaSourcesString}"); } string objectSourcesString = ObjectSources.Build(); if (!string.IsNullOrEmpty(objectSourcesString)) { directives.Add($"object-src {objectSourcesString}"); } string prefetchSourcesString = PrefetchSources.Build(); if (!string.IsNullOrEmpty(prefetchSourcesString)) { directives.Add($"prefetch-src {prefetchSourcesString}"); } string scriptSourcesString = ScriptSources.Build(); if (!string.IsNullOrEmpty(scriptSourcesString)) { directives.Add($"script-src {scriptSourcesString}"); } string styleSourcesString = StyleSources.Build(); if (!string.IsNullOrEmpty(styleSourcesString)) { directives.Add($"style-src {styleSourcesString}"); } string webrtcSourcesString = WebRtcSources.Build(); if (!string.IsNullOrEmpty(webrtcSourcesString)) { directives.Add($"webrtc-src {webrtcSourcesString}"); } string workerSourcesString = WorkerSources.Build(); if (!string.IsNullOrEmpty(workerSourcesString)) { directives.Add($"worker-src {workerSourcesString}"); } string baseUriString = BaseUri.Build(); if (!string.IsNullOrEmpty(baseUriString)) { directives.Add($"base-uri {baseUriString}"); } string pluginTypesString = PluginTypes.Build(); if (!string.IsNullOrEmpty(pluginTypesString)) { directives.Add($"plugin-types {pluginTypesString}"); } string sanboxOptionsString = Sandbox.Build(); if (!string.IsNullOrEmpty(sanboxOptionsString)) { directives.Add($"sandbox {sanboxOptionsString}"); } string formActionString = FormAction.Build(); if (!string.IsNullOrEmpty(formActionString)) { directives.Add($"form-action {formActionString}"); } string frameAncestors = FrameAncestors.Build(); if (!string.IsNullOrEmpty(frameAncestors)) { directives.Add($"frame-ancestors {frameAncestors}"); } if (upgrateInsecureRequests) { directives.Add("upgrade-insecure-requests"); } if (blockAllMixedContent) { directives.Add("block-all-mixed-content"); } string requireSriForString = RequireSriFor.Build(); if (!string.IsNullOrEmpty(requireSriForString)) { directives.Add($"require-sri-for {requireSriForString}"); } if (reportGroup != null) { directives.Add($"report-to {reportGroup.Group}"); } CspOptions options = new CspOptions { Content = string.Join("; ", directives), ReportingGroup = reportGroup }; return(options); }
public PluginMetadata(PluginTypes type) { Type = type; }
private T findForFamily <T>(Type pluginType, Func <IPluginTypeConfiguration, T> func, T defaultValue) { var family = PluginTypes.FirstOrDefault(x => x.PluginType == pluginType); return(family == null ? defaultValue : func(family)); }
public BootstrapInCodeConfiguration AddPluginType <TPlugin>() where TPlugin : class { PluginTypes.Add(typeof(TPlugin)); return(this); }
internal void ProcessData(PluginTypes.TrackedDeviceData data) { float scale = 0.001f; if (m_device != null) scale = 1.0f / m_device.m_worldUnitScaleInMillimeters; if (data.tracked_device_index != m_Index) { //Debug.Log("yo: " + m_Connected); m_hasInfo = false; m_Connected = false; } // m_Index = data.tracked_device_index; m_SequenceNumber = data.sequence_number; m_Time = data.packet_time; m_TrackerID = (m_Index == 0)?TrackerID.CONTROLLER_LEFT:TrackerID.CONTROLLER_RIGHT;//(TrackerID)data.tracker_id; // ***altered*** m_batteryPercentage = data.battery_percent; m_gain = data.dsp_gain; m_Enabled = true;//GetFlag(data.status, Status.ENABLED); // ***altered*** m_Docked = GetFlag(data.status, Status.DOCKED); m_powered = GetFlag(data.status, Status.HAS_EXTERNAL_POWER); m_charging = GetFlag(data.status, Status.BATTERY_CHARGING); m_batteryLow = GetFlag(data.status, Status.BATTERY_LOW); m_wired = GetFlag(data.status, Status.MODE_WIRED); m_HemiTrackingEnabled = GetFlag(data.status, Status.FILTER_HEMI_TRACKING_ENABLED); m_Buttons = (Buttons)data.buttons; m_Trigger = data.trigger; m_JoystickX = data.joystick_x; m_JoystickY = data.joystick_y; //Debug.Log("yo: " + data.tracker_pos[0]); m_Position.Set(data.tracker_pos[0] * scale, data.tracker_pos[1] * scale, -data.tracker_pos[2] * scale); m_Rotation.Set(data.tracker_rot_quat[0], data.tracker_rot_quat[1], -data.tracker_rot_quat[2], -data.tracker_rot_quat[3]); if (data.imu_gravity[0] != 0 && data.imu_gravity[1] != 0 && data.imu_gravity[2] != 0) m_Gravity.Set(data.imu_gravity[0], data.imu_gravity[1], -data.imu_gravity[2]); //Debug.Log("yo: " + m_Connected); if (!m_hasInfo) { //Debug.Log("updating"); UpdateInfo(); } }
public virtual T ConstructObject <T>(string name, object[] args = null) where T : class { args ??= new object[0]; if (!string.IsNullOrWhiteSpace(name)) { try { if (PluginTypes.FirstOrDefault(t => t.FullName == name) is TypeInfo type) { var matchingConstructors = from ctor in type.GetConstructors() let parameters = ctor.GetParameters() where parameters.Length == args.Length where IsValidParameterFor(args, parameters) select ctor; if (matchingConstructors.FirstOrDefault() is ConstructorInfo constructor) { T obj = (T)constructor.Invoke(args) ?? null; if (obj != null) { var resolvedProperties = from property in type.GetProperties() where property.GetCustomAttribute <ResolvedAttribute>() is ResolvedAttribute select property; foreach (var property in resolvedProperties) { var service = GetService(property.PropertyType); if (service != null) { property.SetValue(obj, service); } } var resolvedFields = from field in type.GetFields() where field.GetCustomAttribute <ResolvedAttribute>() is ResolvedAttribute select field; foreach (var field in resolvedFields) { var service = GetService(field.FieldType); if (service != null) { field.SetValue(obj, service); } } } return(obj); } else { Log.Write("Plugin", $"No constructor found for '{name}'", LogLevel.Error); } } } catch (TargetInvocationException e) when(e.Message == "Exception has been thrown by the target of an invocation.") { Log.Write("Plugin", "Object construction has thrown an error", LogLevel.Error); Log.Exception(e.InnerException); } catch (Exception e) { Log.Write("Plugin", $"Unable to construct object '{name}'", LogLevel.Error); Log.Exception(e); } } return(null); }
public static extern PluginTypes.Result sxCoreGetData(uint tracked_device_index, out PluginTypes.TrackedDeviceData data); // get packet data, this should be fast, and locking should only be on accessing the packet queue, not on device reading/writing/open/close
public static extern void Sixense_UpdateOriginTransform(PluginTypes.Vector pos, PluginTypes.Quat rot);
public static extern PluginTypes.Result sxCoreGetDataAtTime(uint tracked_device_index, UInt64 time, out PluginTypes.TrackedDeviceData data); // returns an interpolated position and orientation at a specified time in the past
public static extern void Sixense_SetHandAccessoryBindOffset(Hand bind, Tracker track, PluginTypes.Vector vec, PluginTypes.Quat quat);