//newlogs和singlelogs参数二选一 private void SendToZHIREN_SaveInLOCAL(System.Data.Linq.Table <TFTAttLog> table, LinkedList <TFTAttLog> newLogs, TFTAttLog singlelog) { //sqlCmd.ExecuteNonQuery(); if (singlelog != null) { newLogs = new LinkedList <TFTAttLog>(); newLogs.AddFirst(singlelog); } ZhiRenHandler.sendUserVerified(newLogs, response => { if (response == null || response.Length == 0) { return; } if (response[0].Code != null) { //todo:调试模式下依然按照成功处理 等之人后端搞定之后去除isDebugging判断 if (!Log.isDebugging() && response[0].Code.Contains("error")) { Log.e("ZHIREN error" + response[0].ErrorMessage); return; } lock (myObject) { foreach (var log in newLogs) { try { //success table.InsertOnSubmit(log); Log.d("SAVE:" + table.Contains(log)); table.Context.SubmitChanges(); Log.d("SAVED:" + log); } catch (Exception e) { Log.e(e.Message); if (Log.isDebugging()) { throw new Exception("ERROR"); } } } } } }); }
/// <summary> /// Extension method for DataContext objects that determine if the object is already contained in the DataContext /// </summary> /// <param name="item">The entity to check existance for</param> /// <returns>True if the Entity exists otherwise false</returns> public static bool IsValid <T>(this System.Data.Linq.DataContext dataContext, T item) where T : class, System.ComponentModel.INotifyPropertyChanged { if (null == item) { return(false); } try { System.Data.Linq.Table <T> table = dataContext.GetTable <T>(); if (table == null) { return(false); } else { return(table.Contains(item)); } } catch { return(false); } }