public void DeleteInstance(NdfObject inst) { Instances.Remove(inst); NdfClass cls = inst.Class; cls.Instances.Remove(inst); if (TopObjects.Contains(inst.Id)) { TopObjects.Remove(inst.Id); } }
public void AddEmptyProperties(NdfObject instance) { foreach (NdfProperty property in instance.Class.Properties) { if (instance.PropertyValues.All(x => x.Property != property)) { instance.PropertyValues.Add(new NdfPropertyValue(instance) { Property = property, Value = new NdfNull() }); } } }
public NdfObject CreateInstanceOf(NdfClass cls, bool isTopLevelInstance = true) { var newId = (uint)Instances.Count(); var inst = new NdfObject { Class = cls, Id = newId }; AddEmptyProperties(inst); Instances.Add(inst); if (isTopLevelInstance) { TopObjects.Add(inst.Id); inst.IsTopObject = true; } return(inst); }
public void AddEmptyProperties(NdfObject instance) { foreach (NdfProperty property in instance.Class.Properties) if (instance.PropertyValues.All(x => x.Property != property)) instance.PropertyValues.Add(new NdfPropertyValue(instance) { Property = property, Value = new NdfNull() }); }
public void DeleteInstance(NdfObject inst) { Instances.Remove(inst); NdfClass cls = inst.Class; cls.Instances.Remove(inst); if (TopObjects.Contains(inst.Id)) TopObjects.Remove(inst.Id); }
public NdfObject CreateInstanceOf(NdfClass cls, bool isTopLevelInstance = true) { var newId = (uint)Instances.Count(); var inst = new NdfObject { Class = cls, Id = newId }; AddEmptyProperties(inst); Instances.Add(inst); if (isTopLevelInstance) { TopObjects.Add(inst.Id); inst.IsTopObject = true; } return inst; }
public NdfPropertyValue(NdfObject instance) { _instance = instance; DetailsCommand = new ActionCommand(DetailsCommandExecute); }
/// <summary> /// Reads one object instance. /// </summary> /// <param name="ms"></param> /// <param name="index"></param> /// <param name="owner"></param> /// <returns></returns> protected NdfObject ReadObject(Stream ms, uint index, NdfBinary owner) { var instance = new NdfObject { Id = index }; if (owner.TopObjects.Contains(index)) instance.IsTopObject = true; var buffer = new byte[4]; ms.Read(buffer, 0, buffer.Length); int classId = BitConverter.ToInt32(buffer, 0); if (owner.Classes.Count < classId) throw new InvalidDataException("Object without class found."); NdfClass cls = instance.Class = owner.Classes[classId]; cls.Instances.Add(instance); // Read properties for (; ; ) { ms.Read(buffer, 0, buffer.Length); uint propertyId = BitConverter.ToUInt32(buffer, 0); if (propertyId == 0xABABABAB) break; var propVal = new NdfPropertyValue(instance) { Property = cls.Properties.SingleOrDefault(x => x.Id == propertyId) }; if (propVal.Property == null) // throw new InvalidDataException("Found a value for a property which doens't exist in this class."); foreach (var c in owner.Classes) foreach (var p in c.Properties) if (p.Id == propertyId) { propVal.Property = p; break; } instance.PropertyValues.Add(propVal); NdfValueWrapper res = ReadValue(ms, owner); propVal.Value = res; } owner.AddEmptyProperties(instance); return instance; }
protected static NdfPropertyValue getProperty(NdfObject obj,string str) { return obj.PropertyValues.Single(x => x.Property.Name.Equals(str)); }
private NdfObject CopyInstance(NdfObject instToCopy) { NdfObject newInst = instToCopy.Class.Manager.CreateInstanceOf(instToCopy.Class, instToCopy.IsTopObject); _copyInstanceResults.Add(newInst); foreach (var propertyValue in instToCopy.PropertyValues) { if (propertyValue.Type == NdfType.Unset) continue; var receiver = newInst.PropertyValues.Single(x => x.Property == propertyValue.Property); receiver.Value = GetCopiedValue(propertyValue); } instToCopy.Class.Instances.Add(newInst); var cls = Classes.SingleOrDefault(x => x.Object == instToCopy.Class); if (cls != null) cls.Instances.Add(new NdfObjectViewModel(newInst, cls.ParentVm)); return newInst; }