void ReadAndOutputXConfig() { if (FEyetracker != null) { try { XConfiguration x = FEyetracker.GetXConfiguration(); FLowerLeft[0] = new Vector3D(x.LowerLeft.X, x.LowerLeft.Y, x.LowerLeft.Z) * 0.1; FUpperLeft[0] = new Vector3D(x.UpperLeft.X, x.UpperLeft.Y, x.UpperLeft.Z) * 0.1; FUpperRight[0] = new Vector3D(x.UpperRight.X, x.UpperRight.Y, x.UpperRight.Z) * 0.1; frameCount = 0; FXConfigSetToOutput = true; noXConfCount = 0; } catch (EyetrackerException ee) { FLogger.Log(LogType.Error, "Could not read XConfiguration from Eyetracker: " + ee.Message); FXConfigSetToOutput = false; noXConfCount += 1; } catch (Exception e) { FLogger.Log(LogType.Error, "Could not read XConfiguration from Eyetracker: " + e.Message); FXConfigSetToOutput = false; noXConfCount += 1; } } else { FLogger.Log(LogType.Error, "Could not read XConfiguration from Eyetracker (FEyetracker is null)"); FXConfigSetToOutput = false; frameCount = 0; noXConfCount += 1; } }
public void Test(string uri = "XMLFile1.xml") { if (!File.Exists(uri)) { return; } XmlReaderSettings settings = new XmlReaderSettings(); settings.IgnoreComments = true; settings.IgnoreWhitespace = true; settings.IgnoreProcessingInstructions = true; settings.DtdProcessing = DtdProcessing.Ignore; settings.CloseInput = true; //var uri = "XMLFile1.xml"; Console.WriteLine("\n\nfile:=" + uri); using (XmlReader rd = XmlReader.Create(uri, settings)) { var xs = new XConfiguration(rd); Console.WriteLine("settings count=" + xs.Settings.Count); //XmlParse(rd); } }
void ITracker.SetXConfig(XConfSettings xconfig, double angle) { //Do XConfig //XConfSettings xconf = new XConfSettings(512, 290, 0, 20, 3, 2); //Dreamhack values /* Read from file in future. * try * { * using(Open("eriver.xconf", "r") as File f) { * XConfSettings.load(xconf, f); * } * } * catch (IOError e) * { * Console.WriteLine("No XConf file. Continuing without..."); * } */ double[] x = new double[] { (-xconfig.Width) / 2 + xconfig.Dx, xconfig.Width / 2 - xconfig.Dx, (-xconfig.Width) / 2 + xconfig.Dx }; double[] y = new double[] { xconfig.Height + xconfig.Dy, xconfig.Height + xconfig.Dy, xconfig.Dy }; double[] z = new double[] { xconfig.Dz, xconfig.Dz, xconfig.Dz }; double theta = Math.PI * ((angle + xconfig.Dangle) / 180); XConfiguration xconf = new XConfiguration(); xconf.UpperLeft = new Point3D(x[0], Math.Cos(theta) * y[0] - Math.Sin(theta) * z[0], Math.Sin(theta) * y[0] + Math.Cos(theta) * z[0]); xconf.UpperRight = new Point3D(x[1], Math.Cos(theta) * y[1] - Math.Sin(theta) * z[1], Math.Sin(theta) * y[1] + Math.Cos(theta) * z[1]); xconf.LowerLeft = new Point3D(x[2], Math.Cos(theta) * y[2] - Math.Sin(theta) * z[2], Math.Sin(theta) * y[2] + Math.Cos(theta) * z[2]); et.SetXConfiguration(xconf); //(UpperLeft, UpperRight, LowerLeft); }
public static void SaveContextPermissionsToFile(BotContext context) { if (!PermissionsInContext.ContainsKey(context)) { return; } XConfiguration cfg = XConfiguration.GetConfigurationUtility(context, "userPerms.permissions"); foreach (ulong id in PermissionsInContext[context].Keys) { cfg.SetConfigurationValue(id.ToString(), PermissionsInContext[context][id].ToString(), true); } cfg.SaveConfigurationFile(); }
public static void Init(object session, RunMode mode, string configFileName) { GlobalConfiguration.Mode = mode; GlobalConfiguration.configFileName = configFileName; Assembly assembly = GlobalConfiguration.GetAssembly(); if (assembly == (Assembly)null) { throw new Exception("Can't find calling assembly."); } if (session != null && session is Session) { GlobalConfiguration.CurrentSession = session as Session; } if (GlobalConfiguration.__caches.ContainsKey(assembly)) { return; } XConfiguration configuration = GlobalConfiguration.GetConfiguration(mode, assembly); bool flag = false; if (configuration != null) { GlobalConfiguration.__caches.Add(assembly, configuration); } if (session == null) { return; } User currentUser = GlobalConfiguration.CurrentSession.GetCurrentUser(); if (GlobalConfiguration.Configuration.RequiredKeyPairs.Count <= 0 || !currentUser.Personas.Contains(GlobalConfiguration.CurrentSession.Users.Personas.SuperAdministrator)) { return; } foreach (KeyValuePair <string, XConfiguration.RequiredKeySetting> requiredKeyPair in (IEnumerable <KeyValuePair <string, XConfiguration.RequiredKeySetting> >)GlobalConfiguration.Configuration.RequiredKeyPairs) { if (string.IsNullOrWhiteSpace(requiredKeyPair.Value.Value)) { flag = true; break; } } if (!flag && string.Equals(GlobalConfiguration.AppSettings["BypassConfigurationScreen"], "true", StringComparison.OrdinalIgnoreCase)) { return; } GlobalConfiguration.RequiredConfigKeysReview(GlobalConfiguration.Configuration.RequiredKeyPairs, string.IsNullOrWhiteSpace(configFileName) ? assembly.GetName().Name : configFileName); // FrmConfigurationManager.AlreadyShown = true; }
private static void SaveInternal(XConfiguration configuration, string configFile) { using (MemoryStream memoryStream = new MemoryStream()) { EllieMae.Encompass.BusinessObjects.DataObject data = new EllieMae.Encompass.BusinessObjects.DataObject(); configuration.Save((Stream)memoryStream); memoryStream.Flush(); data.Load(memoryStream.ToArray()); if (data.Size == 0) { throw new Exception("Failed to save configuration."); } try { GlobalConfiguration.CurrentSession.DataExchange.SaveCustomDataObject(configFile, data); } catch (Exception ex) { } } }
// set the XConfiguration to eyetracker, if useCurrentXConfig public void UpdateXConfiguration(XConfiguration xconfig, bool useCurrentXConfig) { if (FEyetracker != null) { XConfiguration xConfig = null; if (useCurrentXConfig) { xConfig = FEyetracker.GetXConfiguration(); FEyetracker.SetXConfiguration(xConfig); } else if (!useCurrentXConfig) { xConfig = xconfig; FEyetracker.SetXConfiguration(xConfig); } } else { OnCustomError("Could not change XConfiguration, no eyetracker defined .."); } }
/// <summary> /// References the data store for user permissions and gets the user's associated permission level. Returns <see cref="DefaultPermissionLevel"/> if the value does not exist. /// </summary> /// <param name="userId">The ID of the user to get permissions of.</param> /// <param name="context">The bot context to grab the information from.</param> /// <exception cref="MalformedConfigDataException"/> /// <returns></returns> public static byte GetPermissionLevelOfUser(ulong userId, BotContext context) { XConfiguration cfg = XConfiguration.GetConfigurationUtility(context, "userPerms.permissions"); string permLvl = cfg.GetConfigurationValue(userId.ToString(), DefaultPermissionLevel.ToString(), reloadConfigFile: true); if (byte.TryParse(permLvl, out byte perms)) { // Catch case byte returnValue = perms; if (context.DefaultUserPermissions.TryGetValue(userId, out byte contextPermissionLevel)) { if (contextPermissionLevel == 255) { XanBotLogger.WriteDebugLine($"Note: The user [{userId}] has permission level 255 for BotContext [{context.Name}], which is intended for use in the backend console only. If any commands rely on 255 being console-only, this may cause problems!"); } returnValue = contextPermissionLevel; } return(returnValue); } throw new MalformedConfigDataException("The data stored for the permission level of user [" + userId + "] is malformed. Reason: Could not cast " + permLvl + " into a byte."); }
void ITracker.SetXConfig(XConfSettings xconfig, double angle) { //Do XConfig //XConfSettings xconf = new XConfSettings(512, 290, 0, 20, 3, 2); //Dreamhack values /* Read from file in future. try { using(Open("eriver.xconf", "r") as File f) { XConfSettings.load(xconf, f); } } catch (IOError e) { Console.WriteLine("No XConf file. Continuing without..."); } */ double[] x= new double[]{(-xconfig.Width)/2 + xconfig.Dx, xconfig.Width/2 - xconfig.Dx, (-xconfig.Width)/2 + xconfig.Dx}; double[] y= new double[]{xconfig.Height+xconfig.Dy, xconfig.Height+xconfig.Dy, xconfig.Dy}; double[] z= new double[]{xconfig.Dz, xconfig.Dz, xconfig.Dz}; double theta = Math.PI * ((angle + xconfig.Dangle) / 180); XConfiguration xconf = new XConfiguration(); xconf.UpperLeft = new Point3D( x[0], Math.Cos(theta)*y[0] - Math.Sin(theta)*z[0], Math.Sin(theta)*y[0] + Math.Cos(theta)*z[0]); xconf.UpperRight = new Point3D( x[1], Math.Cos(theta)*y[1] - Math.Sin(theta)*z[1], Math.Sin(theta)*y[1] + Math.Cos(theta)*z[1]); xconf.LowerLeft = new Point3D( x[2], Math.Cos(theta)*y[2] - Math.Sin(theta)*z[2], Math.Sin(theta)*y[2] + Math.Cos(theta)*z[2]); et.SetXConfiguration(xconf); //(UpperLeft, UpperRight, LowerLeft); }
internal InnerAppSettings(XConfiguration configuration) { this.Configuration = configuration; }
public static void Save(object session, bool ignoreLog) { Assembly assembly = GlobalConfiguration.GetAssembly(); XConfiguration configuration = GlobalConfiguration.Configuration; string configurationFileName = GlobalConfiguration.GetConfigurationFileName(GlobalConfiguration.Mode, assembly); switch (GlobalConfiguration.Mode) { case RunMode.EncompassServer: if (session == null) { session = (object)GlobalConfiguration.getRuntimeSession(); } using (MemoryStream memoryStream = new MemoryStream()) { EllieMae.Encompass.BusinessObjects.DataObject data = new EllieMae.Encompass.BusinessObjects.DataObject(); configuration.Save((Stream)memoryStream); memoryStream.Flush(); if (!ignoreLog) { try { //GlobalTracer.TraceVerboseFormat("The length of configuration file stream is:{0}.", (object)memoryStream.Length); } catch (Exception ex) { } } data.Load(memoryStream.ToArray()); if (!ignoreLog) { try { //GlobalTracer.TraceVerboseFormat("The size of data object is:{0}.", (object)data.Size); } catch (Exception ex) { } } if (data.Size == 0) { if (!ignoreLog) { try { //GlobalTracer.TraceError("Failed to save configuration."); } catch (Exception ex) { } } throw new Exception("Failed to save configuration."); } try { (session as Session).DataExchange.SaveCustomDataObject(configurationFileName, data); break; } catch (Exception ex1) { if (ignoreLog) { break; } try { //GlobalTracer.TraceErrorFormat("Failed to save changes to configuration file, details:{0}", (object)ex1.Message); break; } catch (Exception ex2) { break; } } } case RunMode.WebServer: case RunMode.Client: configuration.Save(configurationFileName); break; } }
public override async Task ExecuteCommandAsync(BotContext context, XanBotMember executingMember, DiscordMessage originalMessage, string[] args, string allArgs) { if (args.Length == 0) { throw new CommandException(this, "Invalid argument count. Expected at least one argument."); } else if (args.Length >= 1) { XConfiguration targetConfig = XConfiguration.GetConfigurationUtility(context); // If there is 1 or more arguments... string subCommand = args[0].ToLower(); // >> config list if (subCommand == "list") { string message = "**Configuration Values:**\n```lua\n"; string[] keys = targetConfig.Keys.ToArray(); foreach (string key in keys) { message += "[\"" + key + "\"]=" + targetConfig.GetConfigurationValue(key) + "\n"; } message += "```"; await ResponseUtil.RespondToAsync(originalMessage, message); // >> config get } else if (subCommand == "get") { if (args.Length != 2) { throw new CommandException(this, "Expected two arguments for operation \"get\" -- get <key>"); } if (args[1].Contains(' ')) { throw new CommandException(this, "Config keys cannot contain spaces."); } string value = targetConfig.GetConfigurationValue(args[1]); if (value != null) { await ResponseUtil.RespondToAsync(originalMessage, "```\n[" + args[1] + "]=" + value + "\n```"); } else { await ResponseUtil.RespondToAsync(originalMessage, "The specified key does not exist in the configuration."); } // >> config set } else if (subCommand == "set") { if (args.Length != 3) { throw new CommandException(this, "Expected two arguments for operation \"set\" -- set <key> <value>"); } if (args[1].Contains(' ')) { throw new CommandException(this, "Config keys cannot contain spaces."); } targetConfig.SetConfigurationValue(args[1], args[2]); await ResponseUtil.RespondToAsync(originalMessage, "Set [`" + args[1] + "`] to: `" + args[2] + "`"); // >> config remove } else if (subCommand == "remove") { if (args.Length != 2) { throw new CommandException(this, "Expected two arguments for operation \"remove\" -- remove <key>"); } if (args[1].Contains(' ')) { throw new CommandException(this, "Config keys cannot contain spaces."); } bool wasRemoved = targetConfig.RemoveConfigurationValue(args[1]); if (wasRemoved) { await ResponseUtil.RespondToAsync(originalMessage, $"Removed configuration entry `{args[1]}`"); } else { await ResponseUtil.RespondToAsync(originalMessage, $"Could not remove configuration entry `{args[1]}` -- it doesn't exist in the first place."); } // something else } else { throw new CommandException(this, string.Format("Invalid operation \"{0}\" (expected get, set, remove, or list)", subCommand)); } } }
// called when data for any output pin is requested public void Evaluate(int SpreadMax) { if (FInit) { FEyetrackerInfoIn.Changed += new SpreadChangedEventHander <EyetrackerInfo>(FEyetrackerInfo_Changed); } if (!FXConfigSetToOutput && FUpdateIn.IsChanged && FUpdateIn[0] == true) { ReadAndOutputXConfig(); } // Enabled true if ((FConnectionChanged || FEnable.IsChanged) && FEnable[0] == true) { try { if (FEyetrackerInfo != null) { FEyetrackerOut.SliceCount = FEyetrackerInfoIn.SliceCount; if (FSyncManager == null) { FClock = new Clock(); FSyncManager = new SyncManager(FClock, FEyetrackerInfo); FSyncManager.SyncManagerError += new EventHandler(FSyncManager_SyncManagerError); FSyncManager.SyncStateChanged += new EventHandler <SyncStateChangedEventArgs>(FSyncManager_SyncStateChanged); } if (FEyetracker == null) { // get tracker representation from EyetrackerInfo FEyetracker = EyetrackerFactory.CreateEyetracker(FEyetrackerInfo); FEyetracker.ConnectionError += new EventHandler <ConnectionErrorEventArgs>(FEyetracker_ConnectionError); FEyetracker.XConfigurationChanged += new EventHandler <XConfigurationChangedEventArgs>(FEyetracker_XConfigurationChanged); FEyetracker.FramerateChanged += new EventHandler <FramerateChangedEventArgs>(FEyetracker_FramerateChanged); FEyetrackerOut[0] = FEyetracker; ReadAndOutputXConfig(); } } } catch (EyetrackerException ex) { if (ex.ErrorCode == 0x20000402) { // trigger custom-error event for IS1Node FLogger.Log(LogType.Error, "EyetrackerException occured (errorCode " + ex.ErrorCode.ToString() + ") - Failed to upgrade protocol." + "This probably means that the firmware needs to be upgraded to a version that supports the new sdk."); } else { FLogger.Log(LogType.Error, "Error Code: " + ex.ErrorCode + " Message: " + ex.Message); } } catch (Exception e) { FLogger.Log(LogType.Error, "Could not connect to eyetracker. " + "Connection failed" + "(" + e.Message + ")"); } } // Enabled false else if ((FConnectionChanged || FEnable.IsChanged) && FEnable[0] == false) { // disconnect and stop eye tracker correctly if (FEyetracker != null) { FEyetracker.ConnectionError -= new EventHandler <ConnectionErrorEventArgs>(FEyetracker_ConnectionError); FEyetracker.Dispose(); FEyetracker = null; FEyetrackerOut.SliceCount = 1; } if (FSyncManager != null) { FSyncManager.SyncManagerError -= new EventHandler(FSyncManager_SyncManagerError); FSyncManager.SyncStateChanged -= new EventHandler <SyncStateChangedEventArgs>(FSyncManager_SyncStateChanged); FSyncManager.Dispose(); FSyncManager = null; FClock = null; } frameCount = 0; noXConfCount = 0; } // input params changed if (FSyncManager != null && FEyetracker != null) { if (FFramerateIn.IsChanged) { FEyetracker.SetFramerate(FFramerateIn[0]); } if (FUpdateIn.IsChanged && FUpdateIn[0] == true) { FSerial[0] = FEyetracker.GetUnitInfo().SerialNumber; IList <float> Framerate = FEyetracker.EnumerateFramerates(); FFramerates.SliceCount = Framerate.Count; if (Framerate.Count == 1) { FCurrentFramerate[0] = Framerate[0]; } for (int i = 0; i < Framerate.Count; i++) { FFramerates[i] = Framerate[i]; } try { IList <string> IlluminationModes = FEyetracker.EnumerateIlluminationModes(); FIlluminationMode.SliceCount = IlluminationModes.Count; for (int i = 0; i < IlluminationModes.Count; i++) { FIlluminationMode[i] = IlluminationModes[i]; } } catch (EyetrackerException ex) { FLogger.Log(LogType.Error, "Could not set illumination mode, " + ex.Message); } XConfiguration x = FEyetracker.GetXConfiguration(); FLowerLeft[0] = new Vector3D(x.LowerLeft.X, x.LowerLeft.Y, x.LowerLeft.Z) * 0.1; FUpperLeft[0] = new Vector3D(x.UpperLeft.X, x.UpperLeft.Y, x.UpperLeft.Z) * 0.1; FUpperRight[0] = new Vector3D(x.UpperRight.X, x.UpperRight.Y, x.UpperRight.Z) * 0.1; } if (FXConfigurationIn.IsChanged) { try { if (FXConfigurationIn[0] != null) { FEyetracker.SetXConfiguration(FXConfigurationIn[0]); } } catch (Exception ee) { FLogger.Log(LogType.Error, "Could not set XConfiguration, " + ee.Message); } } } if (FConnectionChanged && FEyetrackerInfo == null) { // Eyetracker has been disconnected, (recognized by error) } if (FEyetrackerInfoIn.IsChanged) { } FConnectionChanged = false; FInit = false; }
// XConfig calculation void CalcXConfigPointsToOutput(bool compensateInitOffset) { Vector3D ll = new Vector3D(); Vector3D lr = new Vector3D(); Vector3D ul = new Vector3D(); Vector3D ur = new Vector3D(); ll.x = FDisplayWidth[0] * 0.5 * -1 - (FEyetrackerSideOffset[0] * -1); ll.y = FDisplayOffset[0]; ll.z = FEyetrackerOffset[0] * -1; lr.x = FDisplayWidth[0] * 0.5 - (FEyetrackerSideOffset[0] * -1); lr.y = FDisplayOffset[0]; lr.z = FEyetrackerOffset[0] * -1; ul.x = FDisplayWidth[0] * 0.5 * -1 - (FEyetrackerSideOffset[0] * -1); ul.y = FDisplayOffset[0] + FDisplayHeight[0]; ul.z = FEyetrackerOffset[0] * -1; ur.x = FDisplayWidth[0] * 0.5 - (FEyetrackerSideOffset[0] * -1); ur.y = FDisplayOffset[0] + FDisplayHeight[0]; ur.z = FEyetrackerOffset[0] * -1; double oZ = ll.z; double oY = ll.y; Vector3D uLTemp = ul; Vector3D uRTemp = ur; uLTemp.z = uLTemp.z - oZ; uLTemp.y = uLTemp.y - oY; uRTemp.z = uRTemp.z - oZ; uRTemp.y = uRTemp.y - oY; uLTemp = VMath.RotateX(FDisplayDegree[0] * CDegToRad * -1) * uLTemp; uRTemp = VMath.RotateX(FDisplayDegree[0] * CDegToRad * -1) * uRTemp; uLTemp.z = uLTemp.z + oZ; uLTemp.y = uLTemp.y + oY; uRTemp.z = uRTemp.z + oZ; uRTemp.y = uRTemp.y + oY; ul = uLTemp; ur = uRTemp; ll = VMath.RotateX(FEyetrackerDegree[0] * CDegToRad) * ll; ll = VMath.RotateY(FEyetrackerRotation[0] * CDegToRad * -1) * ll; lr = VMath.RotateX(FEyetrackerDegree[0] * CDegToRad) * lr; lr = VMath.RotateY(FEyetrackerRotation[0] * CDegToRad * -1) * lr; ul = VMath.RotateX(FEyetrackerDegree[0] * CDegToRad) * ul; ul = VMath.RotateY(FEyetrackerRotation[0] * CDegToRad * -1) * ul; ur = VMath.RotateX(FEyetrackerDegree[0] * CDegToRad) * ur; ur = VMath.RotateY(FEyetrackerRotation[0] * CDegToRad * -1) * ur; if (compensateInitOffset) { ll += initOffset; lr += initOffset; ul += initOffset; ur += initOffset; } // apply plane normal rotation double angle = FPlaneNormalRotate[0] * CDegToRad; Vector3D llToUr = ur - ll; Vector3D planeCenter = ll + (llToUr * 0.5); Vector3D dir = (ul - ll).CrossRH(ur - ul); dir = ~dir; ll = RotateArbitrary(ll, angle, planeCenter, dir); ul = RotateArbitrary(ul, angle, planeCenter, dir); ur = RotateArbitrary(ur, angle, planeCenter, dir); XConfiguration xConfig = new XConfiguration(); xConfig.LowerLeft = new Point3D(ll.x * 10, ll.y * 10, ll.z * 10); xConfig.UpperLeft = new Point3D(ul.x * 10, ul.y * 10, ul.z * 10); xConfig.UpperRight = new Point3D(ur.x * 10, ur.y * 10, ur.z * 10); FLowerLeft[0] = ll; FUpperLeft[0] = ul; FUpperRight[0] = ur; FXConfiguration[0] = xConfig; }