protected override void ReadXmlBase(XmlReader reader) { base.ReadXmlBase(reader); DesignByContract.Check.Assert(reader.LocalName == "subject", "Expected LocalName is 'subject', but it is " + reader.LocalName); this.subject = new PartySelf(); this.subject.ReadXml(reader); DesignByContract.Check.Assert(reader.LocalName == "is_queryable", "Expected LocalName is 'is_queryable', but it is " + reader.LocalName); this.isQueryable = reader.ReadElementContentAsBoolean("is_queryable", RmXmlSerializer.OpenEhrNamespace); //this.isQueryableSet = true; reader.MoveToContent(); DesignByContract.Check.Assert(reader.LocalName == "is_modifiable", "Expected LocalName is 'is_modifiable', but it is " + reader.LocalName); this.isModifiable = reader.ReadElementContentAsBoolean("is_modifiable", RmXmlSerializer.OpenEhrNamespace); //this.isModifiableSet = true; reader.MoveToContent(); if (reader.LocalName == "other_details") { string otherDetailsType = reader.GetAttribute("type", RmXmlSerializer.XsiNamespace); DesignByContract.Check.Assert(!string.IsNullOrEmpty(otherDetailsType), "otherDetailsType must not be null or empty."); this.otherDetails = Locatable.GetLocatableObjectByType(otherDetailsType) as ItemStructure; this.otherDetails.ReadXml(reader); } }
public IEnumerable <Seller> GetSellersByLocationForProduct(Locatable location, double maxDistanceToSeller, string productTitle, bool fullMatch = true) { var sellers = GetSellersForProduct(productTitle, fullMatch); var squareMaxDistance = maxDistanceToSeller * maxDistanceToSeller; return(sellers.Where(s => s.SquareDistanceTo(location) < squareMaxDistance)); }
public override bool ValidValue(object aValue) { bool result = true; Locatable locatable = aValue as Locatable; if (locatable == null) { result = false; ValidationContext.AcceptValidationError(this, string.Format(AmValidationStrings.ExpectingValueXToBeTypeY, aValue, "Locatable")); } //TODO: validate template ID - probably need to do this in OperationalTemplate class if (!locatable.IsArchetypeRoot) { result = false; ValidationContext.AcceptValidationError(this, string.Format(AmValidationStrings.ExpectingValueXToBeTypeY, aValue, "CArchetypeRoot")); } if (locatable.ArchetypeNodeId != archetypeId.Value) { result = false; ValidationContext.AcceptValidationError(this, string.Format(AmValidationStrings.ExpectingNodeIdXButGotY, archetypeId.Value, locatable.ArchetypeNodeId)); } if (!base.ValidValue(aValue)) { result = false; } return(result); }
protected override void ReadXmlBase(System.Xml.XmlReader reader) { base.ReadXmlBase(reader); DesignByContract.Check.Assert(reader.LocalName == "description", "Expected LocalName is 'description', but it is " + reader.LocalName); string descriptionType = reader.GetAttribute("type", RmXmlSerializer.XsiNamespace); this.description = Locatable.GetLocatableObjectByType(descriptionType) as ItemStructure; if (this.description == null) { throw new InvalidOperationException("descriptionType must be type of ItemStructure: " + descriptionType); } this.description.ReadXml(reader); this.description.Parent = this; DesignByContract.Check.Assert(reader.LocalName == "timing", "Expected LocalName is 'timing', but it is " + reader.LocalName); this.timing = new OpenEhr.RM.DataTypes.Encapsulated.DvParsable(); this.timing.ReadXml(reader); DesignByContract.Check.Assert(reader.LocalName == "action_archetype_id", "Expected LocalName is 'action_archetype_id', but it is " + reader.LocalName); this.actionArchetypeId = reader.ReadElementString("action_archetype_id", RmXmlSerializer.OpenEhrNamespace); reader.MoveToContent(); }
public static double Distance(this Locatable d1, Locatable d2) { float x = d1.X - d2.X; float y = d1.Y - d2.Y; return(Math.Sqrt(Math.Pow(x, 2) + Math.Pow(y, 2))); }
protected override void AddItem(T item) { Check.Require(this.parent != null || item.Parent != null, "item of type Pathable must have Parent attribute set when list parent not set"); Check.Invariant(identifiedLocatables != null, "identifiedLocatables must not be null"); Locatable locatable = item as Locatable; Check.Assert(item != null, "item must not be null"); if (item.Parent == null) { item.Parent = this.parent; } else if (this.parent == null) { this.parent = item.Parent; } else if (!Object.ReferenceEquals(item.Parent, this.parent)) { throw new ApplicationException("item parent must have same parent as other items"); } NamedLocatableList <T> namedLocatables; if (identifiedLocatables.ContainsKey(item.ArchetypeNodeId)) { namedLocatables = identifiedLocatables[item.ArchetypeNodeId]; } else { namedLocatables = new NamedLocatableList <T>(); identifiedLocatables.Add(item.ArchetypeNodeId, namedLocatables); } DvCodedText codedName = item.Name as DvCodedText; if (codedName != null) { if (namedLocatables.Contains(codedName.DefiningCode.TerminologyId.Value, codedName.DefiningCode.CodeString)) { throw new ApplicationException(string.Format("locatable ({0}) name ({1}) already existing in the namedLocatable list.", item.ArchetypeNodeId, codedName.ToString())); } } else if (namedLocatables.Contains(item.Name.Value)) { throw new ApplicationException(string.Format("locatable ({0}) name ({1}) already existing in this namedLocatable list", item.ArchetypeNodeId, item.Name.Value)); } namedLocatables.Add(item); base.AddItem(item); }
public void AddIndicator(Locatable locatable) { Indicator indicator = locatable.GetIndicatorInstance(m_indicatorParent ?? transform); m_indicators.Add(indicator); indicator.gameObject.SetActive(false); indicator.gameObject.layer = m_layer; foreach (Transform trans in indicator.GetComponentsInChildren <Transform>(true)) { trans.gameObject.layer = m_layer; } }
public void Register(Locatable locatable) { Locatables.Add(locatable); if (Started) { foreach (Locator locator in Locators) { locator.AddIndicator(locatable); } } }
public void UpdateLocatable(int guid, int x, int y, bool solid, string sprite, int scale, Vector3 rgb) { if (LocatableDict.ContainsKey(guid)) { LocatableDict[guid] = new Locatable(x, y, solid, sprite, scale, rgb); } else { LocatableDict.Add(guid, new Locatable(x, y, solid, sprite, scale, rgb)); } QuadTree.Add(guid); }
public async Task <LocatableResponse> SaveAsync(Locatable locatable) { try { await _locatableRepository.AddAsync(locatable); await _unitOfWork.CompleteAsync(); return(new LocatableResponse(locatable)); } catch (Exception ex) { return(new LocatableResponse($"An error ocurred while saving the locatable: {ex.Message}")); } }
void BuildPathMap(Locatable locatable) { foreach (object value in locatable.GetAllAttributeValues()) { ILocatableList locatableList = value as ILocatableList; if (locatableList != null) { foreach (Locatable locatableValue in locatableList) { if (locatableValue.IsArchetypeRoot) { string archetypedPath = rootLocatable.PathOfItem(locatableValue); // %HYYKA% // CM: 16/04/09 in normal case, pathMap should not contain duplicated keys. // otherwise, the data instance is invalid. Since this is not for validation purpose, // when there are duplicated path in pathMap, not throw exception. //pathMap.Add(archetypedPath, locatableValue); if (!pathMap.ContainsKey(archetypedPath)) { pathMap.Add(archetypedPath, locatableValue); } } BuildPathMap(locatableValue); } } else { Locatable locatableValue = value as Locatable; if (locatableValue != null) { if (locatableValue.IsArchetypeRoot) { string archetypedPath = rootLocatable.PathOfItem(locatableValue); pathMap.Add(archetypedPath, locatableValue); } BuildPathMap(locatableValue); } } } }
void Update() { Vector2 cameraCenter = m_camera.WorldToScreenPoint(transform.position); Vector2 centerOffset; if (m_center == null) { //Camera center centerOffset = Vector2.zero; } else { //Target center centerOffset = (Vector2)m_camera.WorldToScreenPoint(m_center.transform.position) - cameraCenter; } for (int i = 0; i < m_locatables.Count; i++) { Locatable locatable = m_locatables[i]; Indicator indicator = m_indicators[i]; Vector2 locatablePosition = m_camera.WorldToScreenPoint(locatable.transform.position); Vector2 direction = locatablePosition - (cameraCenter + centerOffset); if (!locatable.isActiveAndEnabled || m_camera.pixelRect.Contains(locatablePosition) || direction.magnitude > locatable.IndicationRange) { indicator.gameObject.SetActive(false); continue; } else if (!indicator.isActiveAndEnabled) { indicator.gameObject.SetActive(true); } indicator.transform.rotation = Quaternion.Euler(0, 0, direction.ZAngle()); Vector2 cameraEdge = FindIntersectionWithBounds(cameraCenter, centerOffset, direction, m_camera.rect); float distance = (locatablePosition - cameraEdge).magnitude; indicator.transform.position = cameraCenter + centerOffset + direction.normalized * locatable.SpaceFromCenter; indicator.transform.localScale = Vector3.one * (1 - (0.5f * distance / locatable.IndicationRange)); } }
bool ILocatableList.Contains(string nodeId, string name) { Check.Invariant(identifiedLocatables != null, "identifiedLocatables must not be null"); if (((ILocatableList)this).Contains(nodeId)) { List <T> namedLocatableList = this.identifiedLocatables[nodeId];// as IList; for (int i = 0; i < namedLocatableList.Count; i++) { Locatable locatable = namedLocatableList[i]; if (locatable.Name.Value == name) { return(true); } } } return(false); }
public async Task <LocatableResponse> UpdateAsync(int id, Locatable locatable) { var existingLocatable = await _locatableRepository.FindById(id); if (existingLocatable == null) { return(new LocatableResponse("Locatable not found")); } existingLocatable.Id = locatable.Id; try { _locatableRepository.Update(existingLocatable); await _unitOfWork.CompleteAsync(); return(new LocatableResponse(existingLocatable)); } catch (Exception ex) { return(new LocatableResponse($"An error ocurred while updating the locatable: {ex.Message}")); } }
bool ILocatableList.Contains(string nodeId, string terminologyId, string codeString) { Check.Invariant(identifiedLocatables != null, "identifiedLocatables must not be null"); Check.Require(!string.IsNullOrEmpty(nodeId), "nodeId must not be null or empty."); Check.Require(!string.IsNullOrEmpty(codeString), "codeString must not be null or empty."); if (((ILocatableList)this).Contains(nodeId)) { List <T> namedLocatableList = this.identifiedLocatables[nodeId]; for (int i = 0; i < namedLocatableList.Count; i++) { Locatable locatable = namedLocatableList[i]; DvCodedText codedName = locatable.Name as DvCodedText; Check.Assert(codedName != null, "locatable name must be type of DvCodedText."); if (terminologyId != null) { if (codedName.DefiningCode.CodeString == codeString && codedName.DefiningCode.TerminologyId.Value == terminologyId) { return(true); } } else { if (codedName.DefiningCode.CodeString == codeString) { return(true); } } } } return(false); }
public async Task AddAsync(Locatable locatable) { await _context.Locatables.AddAsync(locatable); }
public bool Equals(Locatable loc) { return(x == loc.x && y == loc.y); }
bool ILocatableList.Contains(Locatable locatable) { return(this.InnerList.Contains(locatable as T)); }
public static string MkMessage(string msg, Locatable l) { return(string.Format("fail {0} {1}", l.line, l.column)); }
public virtual string ErrorOutput(ErrorCode ec, Locatable loc) { return($"INTERPRETATION ERROR: ({ec.ToString()}) - Line :{loc.line.ToString()}, Column:{loc.column.ToString()} | {errorDescription[ec]}"); }
private AssertionContext ProcessPathPartWithWildcardForArId(AssertionContext contextObj, PathStep pathStep) { DesignByContract.Check.Require(pathStep.Attribute == "//*", "anyAttribute value must be //*."); Locatable locatable = contextObj.Data as Locatable; if (locatable != null) { ArchetypedPathProcessor archetypePathProcessor = new ArchetypedPathProcessor(locatable); string archetypePathWithWildcardKey = null; if (!string.IsNullOrEmpty(pathStep.ArchetypeNodeId)) { archetypePathWithWildcardKey = pathStep.Attribute + "[" + pathStep.ArchetypeNodeId + "]"; } else if (!string.IsNullOrEmpty(pathStep.NodePattern)) { archetypePathWithWildcardKey = pathStep.Attribute + "[{/" + pathStep.NodePattern + "/}]"; } else { throw new NotSupportedException(pathStep.Value + " path not supported"); } object obj = null; if (!archetypePathProcessor.PathExists(archetypePathWithWildcardKey)) { return(null); } if (archetypePathProcessor.PathUnique(archetypePathWithWildcardKey)) { obj = archetypePathProcessor.ItemAtPath(archetypePathWithWildcardKey); } else { obj = archetypePathProcessor.ItemsAtPath(archetypePathWithWildcardKey); } if (obj == null) { throw new ApplicationException("obj must not be null."); } return(new AssertionContext(obj, contextObj)); } AssumedTypes.IList ilist = contextObj.Data as AssumedTypes.IList; if (ilist == null) { throw new ApplicationException("only support either locatable or ilist"); } AssumedTypes.List <object> results = new OpenEhr.AssumedTypes.List <object>(); foreach (Locatable locatableItem in ilist) { AssertionContext assertionContext = new AssertionContext(locatableItem, contextObj); AssertionContext result = ProcessPathPartWithWildcardForArId(assertionContext, pathStep); if (result != null && result.Data != null) { results.Add(result.Data); } } if (results.Count > 0) { return(new AssertionContext(results, contextObj)); } return(null); }
protected override void ReadXmlBase(System.Xml.XmlReader reader) { base.ReadXmlBase(reader); // TODO: CM: 09/07/09 need to disable this assertion check when EhrTypes is not used // in deserialization since TDS origin is optional. When the origin is not existing in // openEHR instance, need to get the origin by CalculatOrigin function. At the moment, // TddTransformer still uses EhrTypes for the deserialization. DesignByContract.Check.Assert(reader.LocalName == "origin", "Expected LocalName is 'origin', but it is " + reader.LocalName); // HKF: 7 Aug 2009 - need to allow origin to be nil for TDD and EhrGateDataObjects transformation prior to OperationalTemplate augmentation if (reader.HasAttributes && reader.GetAttribute("nil", RmXmlSerializer.XsiNamespace) == "true") { // leave origin as null and skip reader.Skip(); } else { this.origin = new OpenEhr.RM.DataTypes.Quantity.DateTime.DvDateTime(); this.origin.ReadXml(reader); } if (reader.LocalName == "period") { this.period = new OpenEhr.RM.DataTypes.Quantity.DateTime.DvDuration(); this.period.ReadXml(reader); } if (reader.LocalName == "duration") { this.duration = new OpenEhr.RM.DataTypes.Quantity.DateTime.DvDuration(); this.duration.ReadXml(reader); } if (reader.LocalName == "events") { LocatableList <Event <ItemStructure.ItemStructure> > events = new LocatableList <Event <OpenEhr.RM.DataStructures.ItemStructure.ItemStructure> >(); do { string eventType = reader.GetAttribute("type", RmXmlSerializer.XsiNamespace); Event <ItemStructure.ItemStructure> anEvent = OpenEhr.RM.Common.Archetyped.Impl.Locatable.GetLocatableObjectByType(eventType) as Event <ItemStructure.ItemStructure>; if (anEvent == null) { throw new InvalidOperationException("anEvent must not be null."); } anEvent.ReadXml(reader); anEvent.Parent = this; events.Add(anEvent); } while (reader.LocalName == "events"); this.events = events as AssumedTypes.List <Event <T> >; } if (reader.LocalName == "summary") { string summaryType = reader.GetAttribute("type", RmXmlSerializer.XsiNamespace); this.summary = Locatable.GetLocatableObjectByType(summaryType) as ItemStructure.ItemStructure; if (this.summary == null) { throw new InvalidOperationException("History summary type must be type of ItemStructure: " + summaryType); } this.summary.ReadXml(reader); this.summary.Parent = this; } }
public override string ErrorOutput(ErrorCode ec, Locatable loc) { return($"fail {loc.line.ToString()} {loc.column.ToString()}"); }
public void Remove(Locatable locatable) { _context.Locatables.Remove(locatable); }
public ArchetypedPathProcessor(Locatable rootLocatable) { Check.Require(rootLocatable != null, "rootLocatable must not be null"); this.rootLocatable = rootLocatable; }
public void Update(Locatable locatable) { _context.Locatables.Update(locatable); }
public TypeCheckerException(string msg, Locatable l) : base(MkMessage(msg, l)) { }
public Rectangle GetLocatableRectangle(int guid) { Locatable loc = LocatableDict[guid]; return(new Rectangle(loc.X, loc.Y, 10 * loc.Scale, 10 * loc.Scale)); }
public Zombie(int id, int x, int y, int nextX, int nextY) : base(id, x, y) { this.nextPosition = new Locatable(nextX, nextY); }