public static string GetKeyName(string sTag, string sLanguage) { try { return(string.Concat(sTag.ToUpperInvariant(), KEY_SEPARATOR, sLanguage.ToLowerInvariant())); } catch (Exception excp) { ExcpHelper.ThrowUp(excp, "GetKeyName(sTag='{0}', sLanguage='{1}') ERROR", sTag, sLanguage); } return(null); }
public override void SetRelations() { if (this.ChangedProps.Contains(this.PeriodInfo) || this.ChangedProps.Contains(this.Status)) { try { this.Match.SetActiveChanged(); } catch (Exception excp) { ExcpHelper.ThrowUp <RelatedLineObjectNotFoundException>(excp, "LiveMatchInfo.SetRelations() ERROR. Parent Match not found for {0}", this); } } }
public override void SetRelations() { try { if (this.BetTag != null || this.BetDomainType == null) { this.BetDomainType = LineSr.Instance.AllObjects.BetDomainTypes.GetObject(this.BetTag); ExcpHelper.ThrowIf <RelatedLineObjectNotFoundException>(this.BetDomainType == null, "Cannot find BetDomainType (BetTag='{0}') for {1}", this.BetTag, this); } if (this.Match == null) { this.Match = LineSr.Instance.AllObjects.Matches.GetObject(this.MatchId); ExcpHelper.ThrowIf <RelatedLineObjectNotFoundException>(this.Match == null, "Cannot get parent Match (MatchId={0})", this.MatchId); } if (this.ChangedProps.Contains(this.Status) || this.ChangedProps.Contains(this.IsManuallyDisabled)) { //this.SetActiveChanged(); this.Match.SetActiveChanged(); } this.Match.BetDomains.SafelyAdd(this); } catch (RelatedLineObjectNotFoundException excp) { m_logger.WarnFormat("BetDomainLn.SetRelations() Warning '{0}' for {1}", excp.Message, this); } catch (Exception excp) { ExcpHelper.ThrowUp(excp, "BetDomainLn.SetRelations() ERROR for {0}", this); } }
public void InsertOrUpdate <T>(LineObjectCollection <T> locLineObjects, TableSpecification ts, UpdatesLn updatesLn) where T : ILineObject <T> { CheckTime ct = new CheckTime(false, "InsertOrUpdate for '{0}' entered", ts.TableName); List <object> lInserted = new List <object>(); List <object> lUpdated = new List <object>(); m_diInserted.Add(ts.TableName, lInserted); m_diUpdated.Add(ts.TableName, lUpdated); if (locLineObjects == null) { return; } UpdateStatistic us = m_uss.EnsureStatistic(ts.TableName); string sInfo = string.Format("{0} table [{1}] {2}; ", m_sLiveBet, ts.TableName, locLineObjects); #if DEBUG int iInsertCount = 0; int iUpdateCount = 0; #endif try { ct.AddEvent("Empty DataTables created."); foreach (string sKey in locLineObjects.Keys) { using (DataCopyTables dct = DataCopyTables.GetDataCopyTables(m_conn, m_transaction, ts.TableName)) { T obj = locLineObjects[sKey]; obj.UpdateId = updatesLn.UpdateId; if (obj.IsNew) { DataRow drNew = obj.CreateDataRow(dct.InsertDataTable); dct.InsertDataTable.Rows.Add(drNew); lInserted.Add(obj); } else { DataRow drNew = obj.CreateDataRow(dct.UpdateDataTable); dct.UpdateDataTable.Rows.Add(drNew); lUpdated.Add(obj); } #if DEBUG iInsertCount = dct.InsertDataTable.Rows.Count; iUpdateCount = dct.UpdateDataTable.Rows.Count; #endif if (dct.InsertDataTable.Rows.Count > 0) { using (IDbCommand cmdInsert = GenerateInsertCommand(m_conn, m_transaction, dct.InsertDataTable, ts)) { using (IDisposable dsp = SqlObjectFactory.CreateDbAdapter(null) as IDisposable) { IDbDataAdapter daInsert = dsp as IDbDataAdapter; Debug.Assert(daInsert != null); daInsert.InsertCommand = cmdInsert; dct.InsertDataTable.AcceptChanges(); foreach (DataRow dr in dct.InsertDataTable.Rows) { dr.SetAdded(); } using (DataSet ds = new DataSet()) { ds.Tables.Add(dct.InsertDataTable); daInsert.Update(ds); } } } us.InsertCount = dct.InsertDataTable.Rows.Count; ct.AddEvent("Insert completed ({0})", dct.InsertDataTable.Rows.Count); } if (dct.UpdateDataTable.Rows.Count > 0) { using (IDbCommand cmdUpdate = GenerateUpdateCommand(m_conn, m_transaction, dct.UpdateDataTable, ts)) { using (IDisposable dsp = SqlObjectFactory.CreateDbAdapter(null) as IDisposable) { IDbDataAdapter daUpdate = dsp as IDbDataAdapter; Debug.Assert(daUpdate != null); daUpdate.UpdateCommand = cmdUpdate; dct.UpdateDataTable.AcceptChanges(); foreach (DataRow dr in dct.UpdateDataTable.Rows) { dr.SetModified(); } using (DataSet ds = new DataSet()) { ds.Tables.Add(dct.UpdateDataTable); daUpdate.Update(ds); } } } us.UpdateCount = dct.UpdateDataTable.Rows.Count; ct.AddEvent("Update completed ({0})", dct.UpdateDataTable.Rows.Count); } ct.AddEvent("Insert/Update filled up (I.Cnt={0}; U.Cnt={1})", dct.InsertDataTable.Rows.Count, dct.UpdateDataTable.Rows.Count); } } //Debug.Assert(us.Count == arrObjects.Length); //m_elInfo.AddFormat("{0} Result: Succeeded; Inserted: {1}; Updated: {2}; Skipped; {3}", sInfo, us.InsertCount, us.UpdateCount, us.SkipCount); } catch (Exception excp) { m_elInfo.AddFormat("{0} Result: FAILED; Inserted: {1}; Updated: {2};", sInfo, us.InsertCount, us.UpdateCount); #if DEBUG if (typeof(T) == typeof(TaggedStringLn)) { FindDuplucates(locLineObjects); } int iCount = 0; string sObjectList = string.Format("ERROR objects (Count={0})\r\n", locLineObjects.Count); foreach (T obj in locLineObjects.Values) { sObjectList += obj.ToString() + "\r\n"; if (++iCount > MAX_ERROR_LIST_COUNT) { sObjectList += string.Format("And More {0} objects not listed", locLineObjects.Count - iCount); break; } } m_logger.Error(sObjectList, excp); #endif ExcpHelper.ThrowUp(excp, "ERROR InsertOrUpdate() for {0}", locLineObjects); } finally { ct.AddEvent("InsertOrUpdate for '{0}' completed", ts.TableName); ct.Info(m_logger); } }
public static int MergeLineObjects <T>(LineContainer lc, ILineObjectCollection <T> loc, MergeLineObjectsCallBack <T> objectsCallBack, ref long lOperationMask) where T : ILineObject <T> { Debug.Assert(objectsCallBack.GetLineObject != null); Debug.Assert(objectsCallBack.CreateLineObject != null); int iSucceededCount = 0; if (loc != null) { string sObjectListName = LineContainer.ContentTypeToObjectListName(typeof(T)); SerializableObjectList lObjects = lc.Objects.SafelyGetValue(sObjectListName); if (lObjects != null) { foreach (ISerializableObject so in lObjects) { //so.MethodTag = dgo; try { T tObj = objectsCallBack.GetLineObject(so); if (so.IsToRemove()) { if (tObj != null) { tObj = loc.MergeLineObject(tObj, so); if (objectsCallBack.RemoveLineObject != null) { objectsCallBack.RemoveLineObject(tObj); //m_logger.InfoFormat("Removed from Line {0}", tObj); lOperationMask |= (long)eOperationMask.RemovedFromCollection; } } } else { if (tObj == null) { // Object is NEW - DOES NOT exist yet in line tObj = objectsCallBack.CreateLineObject(); tObj.Deserialize(so); tObj = loc.MergeLineObject(tObj); lOperationMask |= (long)eOperationMask.AddedToCollection; //m_logger.DebugFormat("Added to Line {0}", tObj); } else { // Object Already Exists tObj = loc.MergeLineObject(tObj, so); if (tObj.ChangedProps != null && tObj.ChangedProps.Count > 0) { lOperationMask |= (long)eOperationMask.ObjectEdited; } } if (objectsCallBack.OnLineObjectMerged != null) { objectsCallBack.OnLineObjectMerged(tObj); } } iSucceededCount++; } catch (Exception excp) { m_logger.Error(excp.Message, excp); ExcpHelper.ThrowUp(excp, "MergeLineObjects<{0}>() ERROR for {1}", typeof(T).Name, so); } } } } return(iSucceededCount); }