/// <summary> /// Internal use /// </summary> public SignalRHostState ShallowCopy(bool allData = false, bool preserveState = false) { SignalRHostState e = new SignalRHostState(); e.StartAutoUpdating = false; e.HostName = HostName; e.ApplicationID = ApplicationID; e.LastMsgId = LastMsgId; if (preserveState) { e.IsLastMsgIdModified = IsLastMsgIdModified; } else { e.IsLastMsgIdModified = false; } e.DistinctString = GetDistinctString(true); e.IsPersisted = IsPersisted; if (preserveState) { e.IsEntityChanged = IsEntityChanged; } else { e.IsEntityChanged = false; } e.StartAutoUpdating = true; return(e); }
/// <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(SignalRHostState other) { if (other == null) { return(false); } else { return(HostName == other.HostName && ApplicationID == other.ApplicationID); } }
/// <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(SignalRHostState newdata) { int cnt = 0; if (LastMsgId != newdata.LastMsgId) { LastMsgId = newdata.LastMsgId; IsLastMsgIdModified = true; cnt++; } IsEntityChanged = cnt > 0; }
/// <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(SignalRHostState other) { if (other == null) { return(false); } if (HostName != other.HostName) { return(false); } if (ApplicationID != other.ApplicationID) { return(false); } return(true); }
/// <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(SignalRHostState from, SignalRHostState to) { if (to.IsPersisted) { if (from.IsLastMsgIdModified && !to.IsLastMsgIdModified) { to.LastMsgId = from.LastMsgId; to.IsLastMsgIdModified = true; } } else { to.IsPersisted = from.IsPersisted; to.HostName = from.HostName; to.ApplicationID = from.ApplicationID; to.LastMsgId = from.LastMsgId; to.IsLastMsgIdModified = from.IsLastMsgIdModified; } }
private static void KeepAliveThread() { SignalRHostStateSet set = new SignalRHostStateSet(); try { evt.Set(); int failCount = 0; var cntx = Cntx; var hsvc = new SignalRHostStateServiceProxy(); var host = hsvc.LoadEntityByNature(cntx, config.HostName, config.App.ID).SingleOrDefault(); if (host == null) { host = new SignalRHostState { HostName = config.HostName, ApplicationID = config.App.ID, LastMsgId = 0 }; var x = hsvc.AddOrUpdateEntities(cntx, new SignalRHostStateSet(), new SignalRHostState[] { host }); host = x.ChangedEntities[0].UpdatedItem; } while (true) { Thread.Sleep(1000 * config.HostStateUpdateIntervalInSeconds); hsvc = new SignalRHostStateServiceProxy(); if (IsLastMessageIdChanged) { host = new SignalRHostState { IsPersisted = true, HostName = config.HostName, ApplicationID = config.App.ID, LastMsgId = (long)LastMessageId, IsLastMsgIdModified = true }; try { hsvc.AddOrUpdateEntities(cntx, set, new SignalRHostState[] { host }); IsLastMessageIdChanged = false; if (failCount > 0) { Current.Subscribe(); failCount = 0; } } catch { failCount++; } } else { try { bool b = Current.PollMessages(cntx, LastMessageId); if (b || (Current.lastSent - Current.lastReceived) > TimeSpan.FromSeconds(20) || failCount > 0) { Current.Subscribe(); failCount = 0; } } catch { failCount++; } } if (Current.CallbackFailed) { try { Current.Subscribe(); failCount = 0; } catch { failCount++; } } } } finally { LastMessageIdUpdateThread = null; } }
/// <summary> /// Internal use /// </summary> public SignalRHostState ShallowCopy(bool allData = false, bool preserveState = false) { SignalRHostState e = new SignalRHostState(); e.StartAutoUpdating = false; e.HostName = HostName; e.ApplicationID = ApplicationID; e.LastMsgId = LastMsgId; if (preserveState) e.IsLastMsgIdModified = IsLastMsgIdModified; else e.IsLastMsgIdModified = false; e.DistinctString = GetDistinctString(true); e.IsPersisted = IsPersisted; if (preserveState) e.IsEntityChanged = IsEntityChanged; else e.IsEntityChanged = false; e.StartAutoUpdating = true; return e; }
/// <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(SignalRHostState other) { if (other == null) return false; else return HostName == other.HostName && ApplicationID == other.ApplicationID; }
/// <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(SignalRHostState other) { if (other == null) return false; if (HostName != other.HostName) return false; if (ApplicationID != other.ApplicationID) return false; return true; }