/// <summary> /// Update changes to the current entity compared to an input <paramref name="newdata" /> and set the entity to a proper state for updating. /// </summary> /// <param name="newdata">The "new" entity acting as the source of the changes, if any.</param> /// <returns> /// </returns> public void UpdateChanges(ShortMessageDataBlock newdata) { int cnt = 0; if (DataHash != newdata.DataHash) { DataHash = newdata.DataHash; IsDataHashModified = true; cnt++; } bool bDataBlock = DataBlock == null && newdata.DataBlock != null || DataBlock != null && newdata.DataBlock == null || DataBlock != null && newdata.DataBlock != null && DataBlock.Length != newdata.DataBlock.Length; if (!bDataBlock && DataBlock != null) { for (int i = 0; i < DataBlock.Length; i++) { bDataBlock = DataBlock[i] != newdata.DataBlock[i]; if (bDataBlock) { break; } } } if (bDataBlock) { DataBlock = newdata.DataBlock; IsDataBlockModified = true; cnt++; } IsEntityChanged = cnt > 0; }
/// <summary> /// Merge changes inside entity <paramref name="from" /> to the entity <paramref name="to" />. Any changes in <paramref name="from" /> that is not changed in <paramref name="to" /> is updated inside <paramref name="to" />. /// </summary> /// <param name="from">The "old" entity acting as merging source.</param> /// <param name="to">The "new" entity which inherits changes made in <paramref name="from" />.</param> /// <returns> /// </returns> public static void MergeChanges(ShortMessageDataBlock from, ShortMessageDataBlock to) { if (to.IsPersisted) { if (from.IsDataHashModified && !to.IsDataHashModified) { to.DataHash = from.DataHash; to.IsDataHashModified = true; } if (from.IsDataBlockModified && !to.IsDataBlockModified) { to.DataBlock = from.DataBlock; to.IsDataBlockModified = true; } } else { to.IsPersisted = from.IsPersisted; to.SeqID = from.SeqID; to.AttachmentID = from.AttachmentID; to.EndByte = from.EndByte; to.StartByte = from.StartByte; to.DataHash = from.DataHash; to.IsDataHashModified = from.IsDataHashModified; to.DataBlock = from.DataBlock; to.IsDataBlockModified = from.IsDataBlockModified; } }
/// <summary> /// Whether or not the present entity is identitical to <paramref name="other" />, in the sense that they have the same (set of) intrinsic identifiers. /// </summary> /// <param name="other">The entity to be compared to.</param> /// <returns> /// The result of comparison. /// </returns> public bool IsEntityTheSame(ShortMessageDataBlock other) { if (other == null) { return(false); } else { return(SeqID == other.SeqID && AttachmentID == other.AttachmentID); } }
/// <summary> /// Whether or not the present entity is identitical to <paramref name="other" />, in the sense that they have the same (set of) primary key(s). /// </summary> /// <param name="other">The entity to be compared to.</param> /// <returns> /// The result of comparison. /// </returns> public bool IsEntityIdentical(ShortMessageDataBlock other) { if (other == null) { return(false); } if (SeqID != other.SeqID) { return(false); } if (AttachmentID != other.AttachmentID) { return(false); } return(true); }
/// <summary> /// Internal use /// </summary> public ShortMessageDataBlock ShallowCopy(bool allData = false, bool preserveState = false, bool checkLoadState = false) { ShortMessageDataBlock e = new ShortMessageDataBlock(); e.StartAutoUpdating = false; e.SeqID = SeqID; e.AttachmentID = AttachmentID; e.EndByte = EndByte; e.StartByte = StartByte; e.DataHash = DataHash; if (preserveState) { e.IsDataHashModified = IsDataHashModified; } else { e.IsDataHashModified = false; } if (allData) { if (!checkLoadState || IsDataBlockLoaded) { e.DataBlock = DataBlock; } if (preserveState) { e.IsDataBlockModified = IsDataBlockModified; } else { e.IsDataBlockModified = false; } e.IsDataBlockLoaded = IsDataBlockLoaded; } e.DistinctString = GetDistinctString(true); e.IsPersisted = IsPersisted; if (preserveState) { e.IsEntityChanged = IsEntityChanged; } else { e.IsEntityChanged = false; } e.StartAutoUpdating = true; return(e); }
/// <summary> /// Internal use /// </summary> public ShortMessageDataBlock ShallowCopy(bool allData = false, bool preserveState = false, bool checkLoadState = false) { ShortMessageDataBlock e = new ShortMessageDataBlock(); e.StartAutoUpdating = false; e.SeqID = SeqID; e.AttachmentID = AttachmentID; e.EndByte = EndByte; e.StartByte = StartByte; e.DataHash = DataHash; if (preserveState) e.IsDataHashModified = IsDataHashModified; else e.IsDataHashModified = false; if (allData) { if (!checkLoadState || IsDataBlockLoaded) e.DataBlock = DataBlock; if (preserveState) e.IsDataBlockModified = IsDataBlockModified; else e.IsDataBlockModified = false; e.IsDataBlockLoaded = IsDataBlockLoaded; } e.DistinctString = GetDistinctString(true); e.IsPersisted = IsPersisted; if (preserveState) e.IsEntityChanged = IsEntityChanged; else e.IsEntityChanged = false; e.StartAutoUpdating = true; return e; }
/// <summary> /// Update changes to the current entity compared to an input <paramref name="newdata" /> and set the entity to a proper state for updating. /// </summary> /// <param name="newdata">The "new" entity acting as the source of the changes, if any.</param> /// <returns> /// </returns> public void UpdateChanges(ShortMessageDataBlock newdata) { int cnt = 0; if (DataHash != newdata.DataHash) { DataHash = newdata.DataHash; IsDataHashModified = true; cnt++; } bool bDataBlock = DataBlock == null && newdata.DataBlock != null || DataBlock != null && newdata.DataBlock == null || DataBlock != null && newdata.DataBlock != null && DataBlock.Length != newdata.DataBlock.Length; if (!bDataBlock && DataBlock != null) { for (int i = 0; i < DataBlock.Length; i++) { bDataBlock = DataBlock[i] != newdata.DataBlock[i]; if (bDataBlock) break; } } if (bDataBlock) { DataBlock = newdata.DataBlock; IsDataBlockModified = true; cnt++; } IsEntityChanged = cnt > 0; }
/// <summary> /// Merge changes inside entity <paramref name="from" /> to the entity <paramref name="to" />. Any changes in <paramref name="from" /> that is not changed in <paramref name="to" /> is updated inside <paramref name="to" />. /// </summary> /// <param name="from">The "old" entity acting as merging source.</param> /// <param name="to">The "new" entity which inherits changes made in <paramref name="from" />.</param> /// <returns> /// </returns> public static void MergeChanges(ShortMessageDataBlock from, ShortMessageDataBlock to) { if (to.IsPersisted) { if (from.IsDataHashModified && !to.IsDataHashModified) { to.DataHash = from.DataHash; to.IsDataHashModified = true; } if (from.IsDataBlockModified && !to.IsDataBlockModified) { to.DataBlock = from.DataBlock; to.IsDataBlockModified = true; } } else { to.IsPersisted = from.IsPersisted; to.SeqID = from.SeqID; to.AttachmentID = from.AttachmentID; to.EndByte = from.EndByte; to.StartByte = from.StartByte; to.DataHash = from.DataHash; to.IsDataHashModified = from.IsDataHashModified; to.DataBlock = from.DataBlock; to.IsDataBlockModified = from.IsDataBlockModified; } }
/// <summary> /// Whether or not the present entity is identitical to <paramref name="other" />, in the sense that they have the same (set of) intrinsic identifiers. /// </summary> /// <param name="other">The entity to be compared to.</param> /// <returns> /// The result of comparison. /// </returns> public bool IsEntityTheSame(ShortMessageDataBlock other) { if (other == null) return false; else return SeqID == other.SeqID && AttachmentID == other.AttachmentID; }
/// <summary> /// Whether or not the present entity is identitical to <paramref name="other" />, in the sense that they have the same (set of) primary key(s). /// </summary> /// <param name="other">The entity to be compared to.</param> /// <returns> /// The result of comparison. /// </returns> public bool IsEntityIdentical(ShortMessageDataBlock other) { if (other == null) return false; if (SeqID != other.SeqID) return false; if (AttachmentID != other.AttachmentID) return false; return true; }