public static void Truncate() { try { var ExpiredRows = DateTime.Now.Date.AddDays(-1 * RetentionMaxDays); var DeleteCount = MessageQueueDB.DeleteWhere(m => m.Created < ExpiredRows && m.Processed != null); if (DeleteCount > 0) { SessionLog.RecordTraceValue("Truncating Message Queue Rows", DeleteCount.ToString()); } } catch (Exception ex) { ReportQueueException(ex); } }
public static void Push(object Message) { try { SessionLog.StartPerformance("Push"); Truncate(); var msg = new MessageQueueRow(); msg.MessageType = Message.GetType().Name; msg.IsClientIncomming = false; msg.Created = DateTime.Now; msg.Message = Serialize(Message); MessageQueueDB.Insert(msg); StartPump(); } catch (Exception ex) { ReportQueueException(ex); } }
private static void Pump(Platform.NetworkConnectionType connectionType) { try { if (connectionType == Platform.NetworkConnectionType.None) { return; } if (InHere) { PumpAgain = true; SessionLog.RecordTrace("Attempting to pump while already pumping"); return; } InHere = true; PumpAgain = false; var messages = new List <Message> (); var infomessages = new List <String> (); int totallength = 0; foreach (var item in MessageQueueDB.SelectWhere(m => m.Processed == null)) { var msg = new Message() { Key = item.Id.ToString(), MessageType = item.MessageType, Body = item.Message }; if (totallength + msg.Body.Length > TotalMessageSizeLimit) { if (messages.Count == 0) { messages.Add(msg); infomessages.Add("Msg " + msg.Key + " truncated from " + msg.Body.Length.ToString()); msg.Body = msg.Body.Substring(0, TotalMessageSizeLimit); } PumpAgain = true; break; } else { messages.Add(msg); totallength += msg.Body.Length; #if ANDROID try { // 3/25/15: no more retry for large messages // trying this for Android first, if successfull we may as well apply to WinPhone if (msg.Body.Length > LargeMessage) { item.Processed = DateTime.Now; MessageQueueDB.Update(item); } } catch (Exception ex) { ReportQueueException(ex); } #endif } } if (messages.Count > 0) { foreach (var info in infomessages) { messages.Add(new Message() { Key = "0", MessageType = "Info", Body = info }); } var svc = Services.NewServiceClient(); svc.PushCompleted += (x, y) => { InHere = false; // mark committed messages as processed in the database if (y.Error != null) { ReportQueueException(y.Error); } else { if (y.Result != null) { try { foreach (var result in y.Result) { int i; if (result.Key.Length > 8) { ParseLongResult(result.Key); } else if (int.TryParse(result.Key, out i) && i > 0) { foreach (var m in MessageQueueDB.SelectWhere(m => m.Id == i)) { m.Processed = DateTime.Now; MessageQueueDB.Update(m); } } } } catch (Exception ex) { LittleWatson.ReportException(ex); } } } InHere = false; if (PumpAgain) { StartPump(); } else { SessionLog.EndPerformance("Push"); } }; var upd = AppStats.Current.CultureSettingsLastUpdated.ToString("yyyy/MM/dd"); svc.PushAsync(AppStats.Current.AppInstance, AppStats.Current.Culture, AppStats.Current.Version + "?" + upd, messages); return; } } catch (Exception ex) { ReportQueueException(ex); } InHere = false; return; }