protected virtual ElementBase CreateInternal(int id, InfContentsElem cttElem, InfElementsElemContainer elElem) { switch ((ElementType)elElem._elem.elementType) { case ElementType.Topic: return(new Topic(id, cttElem, elElem)); case ElementType.Item: return(new Item(id, cttElem, elElem)); case ElementType.ConceptGroup: return(new ConceptGroup(id, cttElem, elElem)); case ElementType.Task: return(new Task(id, cttElem, elElem)); } #if DEBUG throw new InvalidDataException("Unknown object type"); #else return(new Topic(id, cttElem, elElem)); #endif }
public Task(int id, InfContentsElem cttElem, InfElementsElemContainer elElem) : base(id, cttElem, elElem) { }
public ConceptGroup(int id, InfContentsElem cttElem, InfElementsElemContainer elElem) : base(id, cttElem, elElem) { }
protected ElementBase(int id, InfContentsElem cttElem, InfElementsElemContainer elElem) { Id = id; #if DEBUG && !DEBUG_IN_PROD LogTo.Debug("[{0} {1}] Creating", GetType().Name, Id); #endif TitleTextId = SetValue(elElem._elem.titleTextId, nameof(TitleTextId)); Deleted = SetValue(cttElem != null && cttElem.deleted != 0, nameof(Deleted)); TemplateId = SetValue(elElem._elem.templateId, nameof(TemplateId)); ConceptId = SetValue(elElem._elem.conceptId, nameof(ConceptId)); ComponentPos = SetValue(elElem._elem.componPos, nameof(ComponentPos)); OnComponentPosChanged(-1, ComponentPos); //AFactor = SetDbg(elElem._elem.AFactor, nameof(AFactor)); if (cttElem != null) { ParentId = SetValue(cttElem.parentId, nameof(ParentId)); FirstChildId = SetValue(cttElem.firstChildId, nameof(FirstChildId)); LastChildId = SetValue(cttElem.lastChildId, nameof(LastChildId)); NextSiblingId = SetValue(cttElem.nextSiblingId, nameof(NextSiblingId)); PrevSiblingId = SetValue(cttElem.prevSiblingId, nameof(PrevSiblingId)); DescendantCount = SetValue(cttElem.descendantCount, nameof(DescendantCount)); ChildrenCount = SetValue(cttElem.childrenCount, nameof(ChildrenCount)); } }
public ElementFieldFlags Update(InfContentsElem cttElem, InfElementsElemContainer elElem) { #if DEBUG && !DEBUG_IN_PROD LogTo.Debug("[{0} {1}] Updating", GetType().Name, Id); #endif // TODO: Set/Clear events handlers on component change ElementFieldFlags flags = ElementFieldFlags.None; if (elElem != null) { TitleTextId = SetValue(TitleTextId, elElem._elem.titleTextId, nameof(TitleTextId), ref flags); TemplateId = SetValue(TemplateId, elElem._elem.templateId, nameof(TemplateId), ref flags); ConceptId = SetValue(ConceptId, elElem._elem.conceptId, nameof(ConceptId), ref flags); ComponentPos = SetValue(ComponentPos, elElem._elem.componPos, nameof(ComponentPos), ref flags, OnComponentPosChanged); //AFactor = SetDbg(elElem._elem.AFactor, nameof(AFactor)); } if (cttElem != null) { Deleted = SetValue(Deleted, cttElem.deleted != 0, nameof(Deleted), ref flags); ParentId = SetValue(ParentId, cttElem.parentId, nameof(ParentId), ref flags); FirstChildId = SetValue(FirstChildId, cttElem.firstChildId, nameof(FirstChildId), ref flags); LastChildId = SetValue(LastChildId, cttElem.lastChildId, nameof(LastChildId), ref flags); NextSiblingId = SetValue(NextSiblingId, cttElem.nextSiblingId, nameof(NextSiblingId), ref flags); PrevSiblingId = SetValue(PrevSiblingId, cttElem.prevSiblingId, nameof(PrevSiblingId), ref flags); DescendantCount = SetValue(DescendantCount, cttElem.descendantCount, nameof(DescendantCount), ref flags); ChildrenCount = SetValue(ChildrenCount, cttElem.childrenCount, nameof(ChildrenCount), ref flags); } try { OnChanged?.Invoke(new SMElementChangedArgs(SMA.SMA.Instance, (IElement)this, flags)); } catch (Exception ex) { LogTo.Error(ex, "Error while signaling Element Changed event"); } return(flags); }
protected virtual void Commit(int id, InfContentsElem cttElem, InfElementsElemContainer elElem) { try { var el = Elements.SafeGet(id); if (el != null) { var flags = el.Update(cttElem, elElem); if (flags.HasFlag(ElementFieldFlags.Deleted)) { try { OnElementDeleted?.Invoke(new SMElementArgs(SMA.SMA.Instance, el)); } catch (Exception ex) { LogTo.Error(ex, "Error while signaling Element Deleted event"); } } else { try { OnElementModified?.Invoke(new SMElementChangedArgs(SMA.SMA.Instance, el, flags)); } catch (Exception ex) { LogTo.Error(ex, "Error while signaling Element Modified event"); } } } else { el = CreateInternal(id, cttElem, elElem); Elements[id] = el; try { OnElementCreated?.Invoke(new SMElementArgs(SMA.SMA.Instance, el)); } catch (Exception ex) { LogTo.Error(ex, "Error while signaling Element Created event"); } } } finally { if (id == _waitForElementId) { _waitForElementId = -1; _waitForElementEvent.Set(); } } }