public async Task InvokeAsync(HttpContext context, IUserObject userObject, IUserRepository repository) { if (context.Request.Headers.ContainsKey("Authorization")) { var authHeader = context.Request.Headers["Authorization"].ToString(); var sub = GetSubFromToken(authHeader); User user = await repository.GetUserBySub(sub); if (user != null) { userObject.Sub = sub; userObject.Token = authHeader; userObject.UserId = user.Id; } await next(context); } else { //context.Response.StatusCode = 401; //await context.Response.WriteAsync("Authorization Header is missing."); await next(context); } }
private IDictionary <string, object> RpcGetConfiguration(string uuid) { IUserObject instance = m_mot.GetInstance(Guid.Parse(uuid)); if (instance == null) { throw new ArgumentException("No such object."); } IDictionary <string, object> config = m_mot.GetConfiguration(instance.UUID); if (config == null) { throw new ArgumentException("Object does not have a configuration."); } // Set up the result Dictionary <string, object> result = new Dictionary <string, object>(); result["active"] = config; IConfigurationDescription configDescription = m_mot.GetConfigurationDescription(instance.UUID); List <IDictionary <string, object> > details = new List <IDictionary <string, object> >(); foreach (IConfigurationValue value in configDescription) { details.Add(value.Pack()); } result["details"] = details; return(result); }
private void ChangeTransparencyAccordingToHealth(IUserObject aUserObject) { Color objectColor = aUserObject.GetGameObject().GetComponent <SpriteRenderer> ().material.color; objectColor.a = ((float)aUserObject.GetHealth()) / aUserObject.GetInitialHealth(); aUserObject.GetGameObject().GetComponent <SpriteRenderer> ().material.color = objectColor; }
private IDictionary <string, string> RpcSetConfiguration(string uuid, IDictionary <string, object> config) { // Make sure the object ID is valid IUserObject instance = m_mot.GetInstance(Guid.Parse(uuid)); if (instance == null) { throw new ArgumentException("No such object."); } // Make sure it is an object and it is configurable if (instance.ObjectType.IsFactory() || !(instance is IConfigurable)) { throw new ArgumentException("Cannot apply configuration to this type of object."); } // Get the matching configuration description IConfigurationDescription desc = m_mot.GetConfigurationDescription(instance.UUID); if (desc == null) { throw new ArgumentException("No configuration description available for object."); } // Verify the configuration Dictionary <string, string> failures = new Dictionary <string, string>(); config = desc.Verify(config, failures); if (config != null) { IConfigurable configurable = instance as IConfigurable; if (configurable.ValidateConfiguration(desc, config, failures)) { configurable.ApplyConfiguration(desc, config); } } return(failures); }
public void Visit(IQuadTree aQuadTree) { IUserObject insertedUserObject = this.insertedPoint.GetUserObject(); IShape insertedShape = insertedUserObject.GetShape(); IRectangle targetBoundary = CalculateTargetBoundary(insertedShape); if (null != aQuadTree.GetRootPoints()) { List <IPoint <IUserObject> > pointsToBeDeleted = new List <IPoint <IUserObject> > (); foreach (IPoint <IUserObject> currentPoint in aQuadTree.GetRootPoints()) { Visit(currentPoint); if (currentPoint.GetUserObject().GetHealth() < 1) { pointsToBeDeleted.Add(currentPoint); this.userObjectSpawner.PushBackDeadObject(currentPoint.GetUserObject()); } if (insertedUserObject.GetHealth() < 1) { this.userObjectSpawner.PushBackDeadObject(insertedUserObject); break; } } aQuadTree.RemovePointsFromRoot(pointsToBeDeleted); } }
/// <summary> /// Get the configuration description for the instance /// </summary> /// <param name="forInstance"></param> /// <returns></returns> public IConfigurationDescription GetConfigurationDescription(Guid forInstance) { IUserObject instance = GetInstance(forInstance); if (instance == null) { return(null); } // User creatable object use the parent to provide the description if (instance is IUserCreatableObject) { return(GetConfigurationDescription((instance as IUserCreatableObject).ParentUUID)); } // Look it up lock (m_configinfo) { // Use the fully qualified class name to get the config info string fqcn = instance.GetType().Namespace + "." + instance.GetType().Name; if (!m_configinfo.ContainsKey(fqcn)) { this.Log().Warn("Could not find configuration information for class '{0}'", fqcn); return(null); } return(m_configinfo[fqcn]); } }
public void Visit(IQuadTree aQuadTree) { if (null != this.insertedPoint) { IUserObject insertedUserObject = this.insertedPoint.GetUserObject(); IShape insertedShape = insertedUserObject.GetShape(); IRectangle targetBoundary = calculateTargetBoundary(insertedShape); ICollection <IPoint <IUserObject> > points = aQuadTree.GetPoints(targetBoundary, false); foreach (IPoint <IUserObject> currentPoint in points) { visit(currentPoint); if (currentPoint.GetUserObject().GetHealth() < 1) { aQuadTree.RemovePointFromRoot(currentPoint); this.userObjectSpawner.PushBackDeadObject(currentPoint.GetUserObject()); } if (insertedUserObject.GetHealth() < 1) { aQuadTree.RemovePointFromRoot(this.insertedPoint); this.userObjectSpawner.PushBackDeadObject(insertedUserObject); break; } } } }
/// <summary> /// Get the description for the instance /// </summary> /// <param name="forInstance"></param> /// <returns></returns> public IObjectDescription GetDescription(Guid forInstance) { IUserObject instance = GetInstance(forInstance); if (instance == null) { return(null); } lock (m_descriptions) { if (instance is IUserCreatableObject) { if (!m_descriptions.ContainsKey(instance.UUID.ToString())) { this.Log().Warn("Object '{0}' exists but has no description.", instance.UUID); return(null); } return(m_descriptions[instance.UUID.ToString()]); } // Use the fully qualified class name to get the description string fqcn = instance.GetType().Namespace + "." + instance.GetType().Name; if (!m_descriptions.ContainsKey(fqcn)) { this.Log().Warn("Expected to find description for class '{0}'.", fqcn); return(null); } return(m_descriptions[fqcn]); } }
private void ResizeSprite(IUserObject aUserObject) { GameObject gameObject = aUserObject.GetGameObject(); RectTransform rectTransform = gameObject.GetComponent <RectTransform> (); IShape shape = aUserObject.GetShape(); float newWidth = 1f; float newHeight = 1f; if (typeof(IRectangle).IsAssignableFrom(aUserObject.GetShape().GetType())) { newWidth = ((IRectangle)shape).GetWidth(); newHeight = ((IRectangle)shape).GetHeight(); } else if (typeof(ICircle).IsAssignableFrom(aUserObject.GetShape().GetType())) { newWidth = 2 * ((ICircle)shape).GetRadius(); newHeight = newWidth; } SpriteRenderer spriteRenderer = gameObject.GetComponent <SpriteRenderer> (); Vector3 localScale = rectTransform.localScale; localScale.x = newWidth / spriteRenderer.sprite.bounds.size.x; localScale.y = newHeight / spriteRenderer.sprite.bounds.size.y; rectTransform.localScale = localScale; }
// Update is called once per frame void Update() { IUserObject userObject = userObjectSpawner.Spawn(); IPoint <IUserObject> point = new Point <IUserObject>(userObject.GetShape().GetCenterX(), userObject.GetShape().GetCenterY(), userObject); quadTree.Insert(point, insertQuadTreeVisitor); }
/// <summary> /// Get an object instance given a UUID /// </summary> /// <typeparam name="T"></typeparam> /// <param name="forInstance"></param> /// <returns></returns> public T GetInstance <T>(Guid forInstance) where T : IUserObject { IUserObject instance = GetInstance(forInstance); if (instance is T) { return((T)instance); } return(default(T)); }
private void visit(IPoint <IUserObject> aPoint) { IUserObject currentUserObject = aPoint.GetUserObject(); IShape currentShape = currentUserObject.GetShape(); IUserObject insertedUserObject = this.insertedPoint.GetUserObject(); IShape insertedShape = insertedUserObject.GetShape(); bool collision = checkCollision(currentShape, insertedShape); if (collision) { insertedUserObject.TakeDamage(this.damagePoint); currentUserObject.TakeDamage(this.damagePoint); } }
private IEnumerator Spawn() { while (suitableForSpawn) { try { IUserObject userObject = userObjectSpawner.Spawn(); IPoint <IUserObject> point = new Point <IUserObject> (userObject.GetShape().GetCenterX(), userObject.GetShape().GetCenterY(), userObject); insertQuadTreeVisitor.SetInsertedPoint(point); quadTree.Insert(point, insertQuadTreeVisitor); } catch (OverLimitSpawnException exception) { suitableForSpawn = false; Debug.Log(exception); EditorUtility.DisplayDialog("Info", exception.Message, "OK"); } yield return(waitForObjectCreation); } }
private void Visit(IPoint <IUserObject> aPoint) { IUserObject currentUserObject = aPoint.GetUserObject(); IShape currentShape = currentUserObject.GetShape(); IUserObject insertedUserObject = this.insertedPoint.GetUserObject(); IShape insertedShape = insertedUserObject.GetShape(); bool collision = CheckCollision(currentShape, insertedShape); if (collision) { insertedUserObject.TakeDamage(this.damagePoint); currentUserObject.TakeDamage(this.damagePoint); ParticleSystem particleSystem = currentUserObject.GetGameObject().GetComponent <ParticleSystem> (); particleSystem.Play(); ChangeTransparencyAccordingToHealth(insertedUserObject); ChangeTransparencyAccordingToHealth(currentUserObject); } }
/// <summary> /// Add an object instance to the master table /// </summary> /// <param name="instance"></param> public bool AddInstance(IUserObject instance) { lock (m_instances) { if (m_instances.ContainsKey(instance.UUID)) { if (m_instances[instance.UUID] != instance) { this.Log().Warn("Object '{0}' is already registered with a different instance.", instance.UUID); return(false); } return(true); } // Add and test for supporting metadata m_instances[instance.UUID] = instance; // TODO: Make sure we have a description and a configuration for the instance if (GetDescription(instance.UUID) != null) { // Does this instance have configuration information? if ((instance as IConfigurable) != null) { if (GetConfigurationDescription(instance.UUID) == null) { this.Log().Warn("Object '{0}' has no configuration information. Will not add.", instance.UUID); } else { return(true); } } else { return(true); } } else { this.Log().Warn("Object '{0}' has no description information. Will not add.", instance.UUID); } // Not enough data, remove it m_instances.Remove(instance.UUID); return(false); } }
/// <summary> /// Remove an instance from the master table. /// </summary> /// <param name="uuid"></param> public bool RemoveInstance(Guid uuid) { lock (m_instances) { if (!m_instances.ContainsKey(uuid)) { return(false); } // Get the instance and see what other steps are needed IUserObject instance = m_instances[uuid]; if (!instance.ObjectType.IsDeletable()) { return(false); } // TODO: Remove the configuration // TODO: Remove the description // Finally we need to remove the instance m_instances.Remove(uuid); return(true); } }
/// <summary> /// Get information about an object. /// </summary> /// <param name="forInstance"></param> /// <param name="instance"></param> /// <param name="description"></param> /// <returns></returns> private bool GetObjectInformation(Guid forInstance, out IUserObject instance, out IConfigurationDescription description) { description = null; instance = GetInstance(forInstance); if (instance == null) { this.Log().Warn("Requested configuration for non-existant object '{0}'", forInstance); return(false); } IConfigurable configurable = instance as IConfigurable; if (configurable == null) { this.Log().Warn("Requested configuration for unconfigurable object '{0}' (Class {1}.{2})", forInstance, instance.GetType().Namespace, instance.GetType().Name); return(false); } description = GetConfigurationDescription(forInstance); if (description == null) { this.Log().Warn("No configuration description for object '{0}' (Class {1}.{2})", forInstance, instance.GetType().Namespace, instance.GetType().Name); return(false); } return(true); }
public ObjectDataController(IObjectDataDictionary repoDic, ICode repoCode, IUserObject repoUserObj) { this.dalObjectData = repoDic; this.dalCode = repoCode; this.dalUserObj = repoUserObj; }
public UserObject(IPersistentData persistentData, IUserObject other) : this(persistentData, other.Id, other.Name) { other.GetData(out _data, out _offset, out _length); }
public CollectionRepository(DatabaseContext context, IUserObject userObject) : base(context) { UserObject = userObject; }
public void PushBackDeadObject(IUserObject aUserObject) { aUserObject.GetGameObject().SetActive(false); this.deadObjectsPool.Enqueue(aUserObject); }
public ObjectDataController(IObjectDataDictionary repoDic, ICode repoCode, IUserObject repoUserObj) { this.dalObjectData = repoDic; this.dalCode = repoCode; this.dalUserObj = repoUserObj; }
public void PushBackDeadObject(IUserObject aUserObject) { this.deadObjectsPool.Enqueue(aUserObject); }
public DatabaseContext(DbContextOptions <DatabaseContext> options, IUserObject userObject) : base(options) { this.userObject = userObject; }
private bool ExistsAndAllowedToUse(IUserObject userobject) { return((userobject != null) && (userobject.UserId == _userManager.GetUserId(HttpContext.User))); }