public OutgoingStatusMessage(Session session, ImState state, string contentType, int refresh) : base(Message.IMCOMPOSE_TYPE, string.Format(ISCOMPOSING, state.ToString(), contentType, IncludeRefresh(refresh)).Encode(Encoding.UTF8)) { _state = state; _composeContentType = contentType; _refresh = refresh; }
public override Message Validate() { XmlDocument ComposingXml = null; try { byte[] content; if (IsWrapped) { content = WrappedMessage.MessageContent; } else { content = DataContainer.Get(0, Size); } ComposingXml = new XmlDocument(); ComposingXml.LoadXml(RawContent); } catch (Exception e) { throw new ParseException("Invalid isComposing document", e); } XmlNodeList list = ComposingXml.GetElementsByTagName("state"); if (list.Count == 0) { throw new Exception("Mandatory 'state' element missing in isComposing document"); } _state = (ImState)Enum.Parse(typeof(ImState), list[0].InnerText); list = ComposingXml.GetElementsByTagName("contenttype"); if (list.Count > 0) { _composeContentType = list[0].InnerText; } list = ComposingXml.GetElementsByTagName("lastactive"); if (list.Count > 0) { _lastActive = ParseDT(list[0].InnerText); } list = ComposingXml.GetElementsByTagName("refresh"); if (list.Count > 0) { _refresh = int.Parse(list[0].InnerText); } return(this); }
/// <summary> /// Sets active and determines if a new send must be performed /// </summary> /// <param name="refresh"></param> /// <returns></returns> private bool ShouldActiveTransitionBeSent(int refresh) { DateTime now = DateTime.Now; _isComposing = ImState.active; _lastActive = now; if ((_activeEnd < now) || (_refresh != 0 && _activeEnd.AddSeconds((0 - _refresh / 2)) <= now)) { if (refresh < 60) { refresh = 60; } // SHOULD not be allowed _refresh = refresh; _activeEnd = _lastActive.AddSeconds(refresh); return(true); } return(false); }
/// <summary> /// Sets composing to IDLE, this is needed so new ACTIVE messages can be send /// </summary> private void EndComposing() { _isComposing = MSRP.ImState.idle; _activeEnd = DateTime.Now; }
public OutgoingStatusMessage(Session session, ImState state, string contentType, int refresh, string from, string to) : this(session, state, contentType, refresh) { _from = from; _to = to; }