protected virtual void Commit(int id, InfContentsElem?cttElem, InfElementsElem?elElem) { 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.Instance, (IElement)el)); } catch (Exception ex) { LogTo.Error(ex, "Error while signaling Element Deleted event"); } } else { try { OnElementModified?.Invoke(new SMElementChangedArgs(SMA.Instance, (IElement)el, flags)); } catch (Exception ex) { LogTo.Error(ex, "Error while signaling Element Modified event"); } } } else { el = CreateInternal(id, cttElem ?? default(InfContentsElem), elElem ?? default(InfElementsElem)); Elements[id] = el; try { OnElementCreated?.Invoke(new SMElementArgs(SMA.Instance, (IElement)el)); } catch (Exception ex) { LogTo.Error(ex, "Error while signaling Element Created event"); } } }
protected void OnElementUpdatedInternal(ElementBase el, ElementFieldFlags flags) { bool deleted = flags.HasFlag(ElementFieldFlags.Deleted); try { if (deleted) { OnElementDeleted?.Invoke(new SMElementArgs(Core.SM, el)); } else { OnElementModified?.Invoke(new SMElementChangedArgs(Core.SM, el, flags)); } } catch (Exception ex) { var eventType = deleted ? "Deleted" : "Modified"; LogTo.Error(ex, $"Error while signaling Element {eventType} event"); } finally { if (el.Id == _waitForElementId) { _waitForElementId = -1; _waitForElementEvent.Set(); } } }
protected void OnElementUpdatedInternal(ElementBase el, ElementFieldFlags flags) { bool deleted = flags.HasFlag(ElementFieldFlags.Deleted); try { if (deleted) { OnElementDeleted?.Invoke(new SMElementEventArgs(Core.SM, el)); } else { OnElementModified?.Invoke(new SMElementChangedEventArgs(Core.SM, el, flags)); } } catch (Exception ex) { var eventType = deleted ? "Deleted" : "Modified"; LogTo.Error(ex, "Error while signaling Element {EventType} event", eventType); } finally { LastElementId = el.Id; if (_waitForElementId == WaitForElementCreatedTriggerId && flags.HasFlag(ElementFieldFlags.Deleted) && el.Deleted == false) { LastCreatedElementId = el.Id; _waitForElementId = -1; _waitForElementResultId = el.Id; _waitForElementCreatedEvent.Set(); } else if (_waitForElementId == WaitForElementUpdatedTriggerId || _waitForElementId == WaitForElementAnyTriggerId) { LastUpdatedElementId = el.Id; _waitForElementId = -1; _waitForElementResultId = el.Id; _waitForElementUpdatedEvent.Set(); } else if (el.Id == _waitForElementId) { _waitForElementId = -1; _waitForElementIdEvent.Set(); } _waitForElementAnyEvent.Set(); } }
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(); } } }