示例#1
0
        private static void RefreshByType(eDataSyncCacheType type)
        {
            using (DataTable dt = DataCopy.GetDataTable(ConnectionManager.GetConnection(), null, "SELECT * FROM UpdateFileEntry WHERE DataSyncCacheType = '{0}' ORDER BY DataSyncCacheID DESC", type))
            {
                CheckTime ct = new CheckTime();
                ct.AddEvent("UpdateFileEntry SQL Done (Count = {0})", dt.Rows.Count);

                if (dt.Rows.Count > 0)
                {
                    SetLastUpdate(UpdateFileEntrySr.CreateFromDataRow(dt.Rows[0]));
                }

                foreach (DataRow dr in dt.Rows)
                {
                    try
                    {
                        UpdateFileEntrySr ufe = UpdateFileEntrySr.CreateFromDataRow(dr);

                        if (m_diUpdates.ContainsKey(ufe.DataSyncCacheID))
                        {
                            m_diUpdates.Add(ufe.DataSyncCacheID, ufe);
                        }
                    }
                    catch (Exception excp)
                    {
                        m_logger.ErrorFormat("RefreshByType Row Exception:{0}\r\n{1}", excp, excp.Message, excp.StackTrace);
                    }
                }

                ct.AddEvent("RefreshByType({0}) filled up (Count = {1})", type, m_diUpdates.Count);
                ct.Info(m_logger);
            }
        }
示例#2
0
        private void SplitCollection()
        {
            CheckTime ct = new CheckTime("SplitCollection() entered.");

            pages.Clear();

            ct.AddEvent("Cleared");

            SyncList <IMatchVw> lMatches = Matches.ToSyncList();

            foreach (var match in lMatches)
            {
                if (!pages.ContainsKey(match.StartDate))
                {
                    pages.Add(match.StartDate, new SortableObservableCollection <IMatchVw>());
                    match.IsHeaderForPreMatch = true;
                    pages[match.StartDate].Add(match);
                }
                else
                {
                    match.IsHeaderForPreMatch = false;
                    pages[match.StartDate].Add(match);
                }
            }

            lMatches.Clear();

            ct.AddEvent("Cycle completed");

            totalPages = pages.Count;
            if (pages.Count == 0)
            {
                SampleMatches.Clear();
                return;
            }

            if (currentPage > pages.Count - 1)
            {
                currentPage = pages.Count - 1;
            }

            if (currentPage == 0)
            {
                currentPage = GetSavedPage();
            }

            if (pages.ElementAt(currentPage).Value.ElementAt(0) != null)
            {
                CurrentSeason     = pages.ElementAt(currentPage).Value.ElementAt(0).VirtualSeason.ToString();
                CurrentPageToShow = pages.ElementAt(currentPage).Value.ElementAt(0).VirtualDay.ToString();
            }

            SampleMatches.ApplyChanges(pages.ElementAt(currentPage).Value);


            ct.AddEvent("ApplyChanges completed");
            ct.Info(_logger);
        }
示例#3
0
        public void SearchResults(SyncList <MatchResultVw> lResultsToSync, DelegateFilterResults dfr)
        {
            CheckTime ct = new CheckTime("SearchResults() entered");

            lock (m_oReadLocker)
            {
                ct.AddEvent("Inside of lock");

                if (lResultsToSync != null)
                {
                    HashSet <MatchResultVw> hsMatches = new HashSet <MatchResultVw>();

                    SyncList <MatchResultLn> lAllResults = m_diAll.MatchResults.ToSyncList();

                    foreach (MatchResultLn result in lAllResults)
                    {
                        if (dfr == null || dfr(result))
                        {
                            hsMatches.Add(result.MatchResultView);

                            if (!lResultsToSync.Contains(result.MatchResultView))
                            {
                                lResultsToSync.Add(result.MatchResultView);
                            }
                        }
                    }

                    for (int i = 0; i < lResultsToSync.Count;)
                    {
                        MatchResultVw matchResultView = lResultsToSync[i];

                        if (!hsMatches.Contains(matchResultView))
                        {
                            lResultsToSync.RemoveAt(i);
                        }
                        else
                        {
                            i++;
                        }
                    }
                }
            }

            ct.AddEvent("Completed");
            ct.Info(m_logger);
        }
        public static bool MergeFromLineContainer(LineContainer lc)
        {
            CheckTime ct = new CheckTime(false, "MergeFromLineContainer() entered");

            long lOperationMask = 0L;

            eServerSourceType esst = eServerSourceType.BtrPre;

            if (lc.Attributes.ContainsKey("line"))
            {
                string sLine = lc.Attributes["line"];
                ExcpHelper.ThrowIf(!Enum.TryParse(sLine, true, out esst), "Cannot parse LineType from '{0}'", sLine);
            }

            string sType      = lc.Attributes["type"];
            string sMessageId = lc.Attributes["messageid"];

            try
            {
                /*
                 * sTrace += string.Format("{0} docid={1}\r\n", sTrace, sMessageId);
                 *
                 * if (bExtendTrace)
                 * {
                 *  sTrace += lc.BuildTraceString();
                 * }
                 */

                // TimeTypeLn
                {
                    TimeTypeDictionary ttd = LineSr.Instance.AllObjects.GetLineObjectCollection <TimeTypeLn>() as TimeTypeDictionary;

                    int iCount = LineSr.MergeLineObjects <TimeTypeLn>(lc, ttd, new LineSr.MergeLineObjectsCallBack <TimeTypeLn>()
                    {
                        GetLineObject = delegate(ISerializableObject so)
                        {
                            SerializableProperty <string> spTag = so.GetSerializableProperty("Tag") as SerializableProperty <string>;

                            return(ttd.GetObject(spTag.Value));
                        },
                        CreateLineObject = delegate()
                        {
                            return(new TimeTypeLn());
                        }
                    });

                    ct.AddEvent("TimeType(s) Succeeded ({0})", iCount);
                }

                // ScoreTypeLn
                {
                    ScoreTypeDictionary std = LineSr.Instance.AllObjects.GetLineObjectCollection <ScoreTypeLn>() as ScoreTypeDictionary;

                    int iCount = LineSr.MergeLineObjects <ScoreTypeLn>(lc, std, new LineSr.MergeLineObjectsCallBack <ScoreTypeLn>()
                    {
                        GetLineObject = delegate(ISerializableObject so)
                        {
                            SerializableProperty <string> spTag = so.GetSerializableProperty("Tag") as SerializableProperty <string>;

                            return(std.GetObject(spTag.Value));
                        },
                        CreateLineObject = delegate()
                        {
                            return(new ScoreTypeLn());
                        }
                    });

                    ct.AddEvent("ScoreType(s) Succeeded ({0})", iCount);
                }

                // BetTypeLn
                {
                    BetTypeDictionary btd = LineSr.Instance.AllObjects.GetLineObjectCollection <BetTypeLn>() as BetTypeDictionary;

                    int iCount = LineSr.MergeLineObjects <BetTypeLn>(lc, btd, new LineSr.MergeLineObjectsCallBack <BetTypeLn>()
                    {
                        GetLineObject = delegate(ISerializableObject so)
                        {
                            SerializableProperty <string> spTag = so.GetSerializableProperty("Tag") as SerializableProperty <string>;

                            return(btd.GetObject(spTag.Value));
                        },
                        CreateLineObject = delegate()
                        {
                            return(new BetTypeLn());
                        }
                    });

                    ct.AddEvent("BetType(s) Succeeded ({0})", iCount);
                }

                // BetDomainTypeLn
                {
                    BetDomainTypeDictionary bdtd = LineSr.Instance.AllObjects.GetLineObjectCollection <BetDomainTypeLn>() as BetDomainTypeDictionary;

                    int iCount = LineSr.MergeLineObjects <BetDomainTypeLn>(lc, bdtd, new LineSr.MergeLineObjectsCallBack <BetDomainTypeLn>()
                    {
                        GetLineObject = delegate(ISerializableObject so)
                        {
                            SerializableProperty <string> spTag = so.GetSerializableProperty("Tag") as SerializableProperty <string>;

                            return(bdtd.GetObject(spTag.Value));
                        },
                        CreateLineObject = delegate()
                        {
                            return(new BetDomainTypeLn());
                        }
                    });

                    ct.AddEvent("BetDomainType(s) Succeeded ({0})", iCount);
                }

                // Groups
                {
                    GroupDictionary gd = LineSr.Instance.AllObjects.GetLineObjectCollection <GroupLn>() as GroupDictionary;

                    int iCount = LineSr.MergeLineObjects <GroupLn>(lc, gd, new LineSr.MergeLineObjectsCallBack <GroupLn>()
                    {
                        GetLineObject = delegate(ISerializableObject so)
                        {
                            // 143881406612

                            SerializableProperty <string> spType = so.GetSerializableProperty("Type") as SerializableProperty <string>;
                            SerializableProperty <long> spSvrId  = so.GetSerializableProperty("SvrGroupId") as SerializableProperty <long>;

                            Debug.Assert(spType != null);
                            Debug.Assert(spSvrId != null);

                            return(gd.SafelyGetGroupByKeyName(spType.Value, spSvrId.Value));
                        },
                        CreateLineObject = delegate()
                        {
                            return(new GroupLn());
                        }
                    });

                    ct.AddEvent("Group(s) Succeeded ({0})", iCount);
                }

                // Competitors
                {
                    CompetitorDictionary cd = LineSr.Instance.AllObjects.GetLineObjectCollection <CompetitorLn>() as CompetitorDictionary;

                    int iCount = LineSr.MergeLineObjects <CompetitorLn>(lc, cd, new LineSr.MergeLineObjectsCallBack <CompetitorLn>()
                    {
                        GetLineObject = delegate(ISerializableObject so)
                        {
                            SerializableProperty <long> spCompetitor = so.GetSerializableProperty("CompetitorId") as SerializableProperty <long>;

                            Debug.Assert(spCompetitor != null);

                            return(cd.GetObject(spCompetitor.Value));
                        },
                        CreateLineObject = delegate()
                        {
                            return(new CompetitorLn());
                        }
                    });

                    ct.AddEvent("Competitor(s) Succeeded ({0})", iCount);
                }
                // CompetitorToOutrightLn
                {
                    var cd = LineSr.Instance.AllObjects.GetLineObjectCollection <CompetitorToOutrightLn>() as CompetitorToOutrightDictionary;

                    int iCount = LineSr.MergeLineObjects <CompetitorToOutrightLn>(lc, cd, new LineSr.MergeLineObjectsCallBack <CompetitorToOutrightLn>()
                    {
                        GetLineObject = delegate(ISerializableObject so)
                        {
                            SerializableProperty <long> spCompetitor = so.GetSerializableProperty("match2competitorid") as SerializableProperty <long>;

                            Debug.Assert(spCompetitor != null);

                            return(cd.GetObject(spCompetitor.Value));
                        },
                        CreateLineObject = delegate()
                        {
                            return(new CompetitorToOutrightLn());
                        }
                    });

                    ct.AddEvent("Competitor(s) Succeeded ({0})", iCount);
                }

                // Strings
                {
                    TaggedStringDictionary tsd = LineSr.Instance.AllObjects.GetLineObjectCollection <TaggedStringLn>() as TaggedStringDictionary;
                    int iCount = LineSr.MergeLineObjects <TaggedStringLn>(lc, tsd, new LineSr.MergeLineObjectsCallBack <TaggedStringLn>()
                    {
                        GetLineObject = delegate(ISerializableObject so)
                        {
                            SerializableProperty <long> spStringId = so.GetSerializableProperty("StringId") as SerializableProperty <long>;

                            return(tsd.GetObject(spStringId.Value));
                        },
                        CreateLineObject = delegate()
                        {
                            return(new TaggedStringLn());
                        }
                    });

                    ct.AddEvent("String(s) Succeeded ({0})", iCount);
                }

                SyncList <MatchLn> lMatchesToRemove = new SyncList <MatchLn>();

                // Matches
                {
                    SyncHashSet <long> lMatchIds = new SyncHashSet <long>();

                    MatchDictionary md     = LineSr.Instance.AllObjects.GetLineObjectCollection <MatchLn>() as MatchDictionary;
                    int             iCount = LineSr.MergeLineObjects <MatchLn>(lc, md, new LineSr.MergeLineObjectsCallBack <MatchLn>()
                    {
                        GetLineObject = delegate(ISerializableObject so)
                        {
                            SerializableProperty <long> spMatchId = so.GetSerializableProperty("MatchId") as SerializableProperty <long>;

                            lMatchIds.Add(spMatchId.Value);

                            return(md.GetObject(spMatchId.Value));
                        },
                        CreateLineObject = delegate()
                        {
                            return(new MatchLn());
                        },
                        OnLineObjectMerged = delegate(MatchLn match)
                        {
                            if (match != null)
                            {
                                if (match.Code.Value == 0)
                                {
                                    match.Code.Value = Math.Abs((int)(match.MatchId % 100000));
                                }

                                if (match.EndDate.Value == null)
                                {
                                    match.EndDate.Value = new DateTimeSr(DateTime.MaxValue);
                                }
                            }
                        },
                        RemoveLineObject = delegate(MatchLn match)
                        {
                            lMatchesToRemove.Add(match);
                        }
                    }, ref lOperationMask);

                    if (sType.ToLowerInvariant() == "initial")
                    {
                        SyncList <MatchLn> lAllLiveMatches = LineSr.Instance.QuickSearchMatches(delegate(MatchLn match)
                        {
                            return(match.IsLiveBet.Value && match.SourceType == esst);
                        });

                        foreach (var match in lAllLiveMatches)
                        {
                            if (!lMatchIds.Contains(match.MatchId))
                            {
                                lMatchesToRemove.Add(match);
                            }
                        }
                    }

                    ct.AddEvent("Match(es) Succeeded ({0})", iCount);
                }

                // MatchToGroup items
                {
                    MatchToGroupDictionary mtogd = LineSr.Instance.AllObjects.GetLineObjectCollection <MatchToGroupLn>() as MatchToGroupDictionary;
                    int iCount = LineSr.MergeLineObjects <MatchToGroupLn>(lc, mtogd, new LineSr.MergeLineObjectsCallBack <MatchToGroupLn>()
                    {
                        GetLineObject = delegate(ISerializableObject so)
                        {
                            SerializableProperty <long> spMatchId = so.GetSerializableProperty("MatchId") as SerializableProperty <long>;
                            SerializableProperty <long> spGroupId = so.GetSerializableProperty("GroupId") as SerializableProperty <long>;

                            return(mtogd.GetObject(MatchToGroupLn.GetKeyName(spMatchId.Value, spGroupId.Value)));
                        },
                        CreateLineObject = delegate()
                        {
                            return(new MatchToGroupLn());
                        }
                    });

                    ct.AddEvent("MatchToGroup(s) Succeeded ({0})", iCount);
                }

                // LiveMatchInfo
                {
                    LiveMatchInfoDictionary lmid = LineSr.Instance.AllObjects.GetLineObjectCollection <LiveMatchInfoLn>() as LiveMatchInfoDictionary;
                    int iCount = LineSr.MergeLineObjects <LiveMatchInfoLn>(lc, lmid, new LineSr.MergeLineObjectsCallBack <LiveMatchInfoLn>()
                    {
                        GetLineObject = delegate(ISerializableObject so)
                        {
                            SerializableProperty <long> spMatchId = so.GetSerializableProperty("MatchId") as SerializableProperty <long>;

                            return(lmid.GetObject(spMatchId.Value));
                        },
                        CreateLineObject = delegate()
                        {
                            return(new LiveMatchInfoLn());
                        },
                        OnLineObjectMerged = delegate(LiveMatchInfoLn matchInfo)
                        {
                            if (matchInfo != null)
                            {
                                if (matchInfo.ExpiryDate.Value == null)
                                {
                                    matchInfo.ExpiryDate.Value = new DateTimeSr(DateTime.Now.AddMinutes(30)); // Half an hour
                                }

                                if (matchInfo.ChangedProps.Contains(matchInfo.PeriodInfo))
                                {
                                    lOperationMask |= (long)eOperationMask.MatchPeriodInfoChanged;
                                }
                            }
                        },
                        RemoveLineObject = delegate(LiveMatchInfoLn lmi)
                        {
                        }
                    });

                    ct.AddEvent("LiveMatchInfo(s) Succeeded ({0})", iCount);
                }

                // BetDomainLn
                {
                    BetDomainDictionary bdmd = LineSr.Instance.AllObjects.GetLineObjectCollection <BetDomainLn>() as BetDomainDictionary;
                    int iCount = LineSr.MergeLineObjects <BetDomainLn>(lc, bdmd, new LineSr.MergeLineObjectsCallBack <BetDomainLn>()
                    {
                        GetLineObject = delegate(ISerializableObject so)
                        {
                            SerializableProperty <long> spBetDomainId = so.GetSerializableProperty("BetDomainId") as SerializableProperty <long>;

                            return(bdmd.GetObject(spBetDomainId.Value));
                        },
                        CreateLineObject = delegate()
                        {
                            return(new BetDomainLn());
                        },
                        RemoveLineObject = delegate(BetDomainLn bdmn)
                        {
                            LineSr.Instance.RemoveBetDomain(bdmn);
                        }
                    }, ref lOperationMask);

                    ct.AddEvent("BetDomain(s) Succeeded ({0})", iCount);
                }

                // OddLn
                {
                    OddDictionary oddd   = LineSr.Instance.AllObjects.GetLineObjectCollection <OddLn>() as OddDictionary;
                    int           iCount = LineSr.MergeLineObjects <OddLn>(lc, oddd, new LineSr.MergeLineObjectsCallBack <OddLn>()
                    {
                        GetLineObject = delegate(ISerializableObject so)
                        {
                            SerializableProperty <long> spOutcomeId = so.GetSerializableProperty("OutcomeId") as SerializableProperty <long>;

                            return(oddd.GetObject(spOutcomeId.Value));
                        },
                        CreateLineObject = delegate()
                        {
                            return(new OddLn());
                        },
                        RemoveLineObject = delegate(OddLn odd)
                        {
                            odd.Active.Value = false;
                            //LineSr.Instance.RemoveOdd(odd);
                        }
                    });

                    ct.AddEvent("Odd(s) Succeeded ({0})", iCount);
                }

                // Process Removed matches
                foreach (var match in lMatchesToRemove)
                {
                    LiveMatchInfoLn lmi = match.LiveMatchInfo;

                    if (lmi.Status.Value == eMatchStatus.Ended && match.SourceType == eServerSourceType.BtrLive)
                    {
                        MergeMatchResult(match);
                    }

                    LineSr.Instance.RemoveMatch(match);
                }
            }
            catch (Exception excp)
            {
                ct.AddEvent("ERROR");
                m_logger.Error(excp.Message, excp);
                m_logger.Excp(excp, "MergeFromLigaStavok() ERROR");
                throw;
            }
            finally
            {
                //m_logger.Info(sTrace);
                //m_logger.DebugFormat("LineContainer Trace Length = {0}", sTrace.Length);
                ct.AddEvent("MergeFromLigaStavok(Type={0}, MessageId={1}) completed", sType, sMessageId);
                ct.Info(m_logger);
            }

#if DEBUG
            if ((lOperationMask & EVENT_REASON_MASK) > 0)
            {
                m_logger.InfoFormat("MergeFromLineContainer() result {0}", lOperationMask);
            }
#endif

            return(true);
        }
示例#5
0
        public void FromXml(XmlTextReader tr)
        {
            CheckTime ct = new CheckTime(false, "LineContainer.FromXml() entered.");

            try
            {
                while (tr.Read())
                {
                    string sCurrentTagName = tr.Name;

                    switch (tr.NodeType)
                    {
                    case XmlNodeType.Attribute:

                        break;

                    case XmlNodeType.Element:

                        while (tr.MoveToNextAttribute())
                        {
                            this.Attributes[tr.Name] = tr.Value;
                        }

                        if (sCurrentTagName == this.XmlTagName)
                        {
                            break;
                        }

                        if (!tr.IsEmptyElement)
                        {
                            try
                            {
                                Type contentType = ObjectListNameToContentType(sCurrentTagName);
                                SerializableObjectList lObjects = m_di.EnsureSerializableObjectList(contentType, sCurrentTagName);
                                lObjects.FromXml(tr);
                                ct.AddEvent("{0} completed", sCurrentTagName);
                            }
                            catch (Exception excp)
                            {
                                throw;
                            }
                        }

                        break;

                    case XmlNodeType.EndElement:

                        if (tr.Name == this.XmlTagName)
                        {
                            return;
                        }

                        break;
                    }
                }
            }
            finally
            {
                ct.AddEvent("LineContainer.FromXml() completed.");
                ct.Info(m_logger);
            }
        }
示例#6
0
        /*
         * private static bool DeleteMatches(IDbConnection conn, IDbTransaction transaction)
         * {
         *  LineObjectCollection<MatchLn> locMatches = LineSr.Instance.ObjectsToRemove.GetLineObjectCollection<MatchLn>();
         *
         *  if (locMatches != null && locMatches.Count > 0)
         *  {
         *      IdentityList il = new IdentityList();
         *
         *      foreach (MatchLn mtch in locMatches.Values)
         *      {
         *          il.AddUnique(mtch.MatchId);
         *      }
         *
         *      string sMatchIds = il.FormatIds();
         *
         *      DataCopy.ExecuteScalar(conn, transaction, DELETE_MATCH_ODDS_QUERY, sMatchIds);
         *      DataCopy.ExecuteScalar(conn, transaction, DELETE_MATCH_BETDOMAIN_QUERY, sMatchIds);
         *      DataCopy.ExecuteScalar(conn, transaction, DELETE_MATCH_TO_GROUP_QUERY, sMatchIds);
         *      DataCopy.ExecuteScalar(conn, transaction, DELETE_LIVE_MATCH_INFO_QUERY, sMatchIds);
         *      DataCopy.ExecuteScalar(conn, transaction, DELETE_MATCHES_QUERY, sMatchIds);
         *
         *      return true;
         *  }
         *
         *  return false;
         * }
         */

        public static eFileSyncResult UpdateDatabase(IDbConnection conn, eUpdateType eut, string sProviderDescription, UpdateStatistics us)
        {
            eFileSyncResult fsr = eFileSyncResult.Failed;

            DateTime dtStart      = DateTime.Now;
            string   sErrorString = string.Empty;

            DataCopy dc = null;

            string sUpdateDescription = eut.ToString();

            CheckTime ct = new CheckTime("UpdateAll({0}) Entered", sUpdateDescription);

            DictionaryOfLineObjectCollectionLight dlocToModify = LineSr.Instance.NewOrChangedObjects;
            DictionaryOfLineObjectCollectionLight dlocToDelete = LineSr.Instance.ObjectsToRemove;

            try
            {
                using (IDbTransaction transaction = conn.BeginTransaction())
                {
                    dc = new DataCopy(conn, transaction, sUpdateDescription);

                    try
                    {
                        UpdatesLn updatesLn = new UpdatesLn(eut, string.Format("Saving {0} and Deleting {1} line tables", dlocToModify.Count, dlocToDelete.Count), sProviderDescription);

                        updatesLn.Save(conn, transaction);
                        Debug.Assert(updatesLn.UpdateId > 0);

                        // Insert or Update objects
                        dc.InsertOrUpdate(dlocToModify.GetLineObjectCollection <TaggedStringLn>(), TaggedStringLn.TableSpec, updatesLn);

                        dc.InsertOrUpdate(dlocToModify.GetLineObjectCollection <TimeTypeLn>(), TimeTypeLn.TableSpec, updatesLn);
                        dc.InsertOrUpdate(dlocToModify.GetLineObjectCollection <ScoreTypeLn>(), ScoreTypeLn.TableSpec, updatesLn);
                        dc.InsertOrUpdate(dlocToModify.GetLineObjectCollection <BetTypeLn>(), BetTypeLn.TableSpec, updatesLn);
                        dc.InsertOrUpdate(dlocToModify.GetLineObjectCollection <BetDomainTypeLn>(), BetDomainTypeLn.TableSpec, updatesLn);

                        dc.InsertOrUpdate(dlocToModify.GetLineObjectCollection <GroupLn>(), GroupLn.TableSpec, updatesLn);
                        dc.InsertOrUpdate(dlocToModify.GetLineObjectCollection <CompetitorLn>(), CompetitorLn.TableSpec, updatesLn);
                        dc.InsertOrUpdate(dlocToModify.GetLineObjectCollection <MatchLn>(), MatchLn.TableSpec, updatesLn);
                        dc.InsertOrUpdate(dlocToModify.GetLineObjectCollection <CompetitorToOutrightLn>(), CompetitorToOutrightLn.TableSpec, updatesLn);
                        dc.InsertOrUpdate(dlocToModify.GetLineObjectCollection <LiveMatchInfoLn>(), LiveMatchInfoLn.TableSpec, updatesLn);
                        dc.InsertOrUpdate(dlocToModify.GetLineObjectCollection <MatchResultLn>(), MatchResultLn.TableSpec, updatesLn);
                        dc.InsertOrUpdate(dlocToModify.GetLineObjectCollection <MatchToGroupLn>(), MatchToGroupLn.TableSpec, updatesLn);
                        dc.InsertOrUpdate(dlocToModify.GetLineObjectCollection <BetDomainLn>(), BetDomainLn.TableSpec, updatesLn);
                        dc.InsertOrUpdate(dlocToModify.GetLineObjectCollection <ResourceRepositoryLn>(), ResourceRepositoryLn.TableSpec, updatesLn);
                        dc.InsertOrUpdate(dlocToModify.GetLineObjectCollection <ResourceAssignmentLn>(), ResourceAssignmentLn.TableSpec, updatesLn);
                        dc.InsertOrUpdate(dlocToModify.GetLineObjectCollection <CompetitorInfosLn>(), CompetitorInfosLn.TableSpec, updatesLn);
                        dc.InsertOrUpdate(dlocToModify.GetLineObjectCollection <MatchInfosLn>(), MatchInfosLn.TableSpec, updatesLn);
                        dc.InsertOrUpdate(dlocToModify.GetLineObjectCollection <TournamentInfosLn>(), TournamentInfosLn.TableSpec, updatesLn);
                        dc.InsertOrUpdate(dlocToModify.GetLineObjectCollection <OddLn>(), OddLn.TableSpec, updatesLn);
                        //dc.InsertOrUpdate(dlocToModify.GetLineObjectCollection<LiabilityLn>(), LiabilityLn.TableSpec, updatesLn);
                        dc.InsertOrUpdate(dlocToModify.GetLineObjectCollection <LanguageLn>(), LanguageLn.TableSpec, updatesLn);
                        dc.InsertOrUpdate(dlocToModify.GetLineObjectCollection <MultistringGroupLn>(), MultistringGroupLn.TableSpec, updatesLn);
                        //dc.InsertOrUpdate(dlocToModify.GetLineObjectCollection<TournamentMatchLocksLn>(), TournamentMatchLocksLn.TableSpec, updatesLn);

                        // Delete Objects
                        dc.DeleteObjects(dlocToDelete.GetLineObjectCollection <OddLn>(), OddLn.TableSpec);
                        dc.DeleteObjects(dlocToDelete.GetLineObjectCollection <BetDomainLn>(), BetDomainLn.TableSpec);
                        dc.DeleteObjects(dlocToDelete.GetLineObjectCollection <MatchToGroupLn>(), MatchToGroupLn.TableSpec);
                        dc.DeleteObjects(dlocToDelete.GetLineObjectCollection <LiveMatchInfoLn>(), LiveMatchInfoLn.TableSpec);
                        dc.DeleteObjects(dlocToDelete.GetLineObjectCollection <CompetitorToOutrightLn>(), CompetitorToOutrightLn.TableSpec);
                        dc.DeleteObjects(dlocToDelete.GetLineObjectCollection <MatchLn>(), MatchLn.TableSpec);

                        if (dc.Statistics.IsInsrtedOrUpdatedOrDeleted)
                        {
                            // DK: If You like to test data import then uncomment line bellow:
                            // throw new SystemException("Developer Exception: Always rollback transaction for test purposes");

                            transaction.Commit();
                            fsr = eFileSyncResult.Succeeded;
                            ct.AddEvent("Commited");
                        }
                        else
                        {
                            transaction.Rollback();
                            fsr = eFileSyncResult.Skipped;
                            ct.AddEvent("Rolled Back");
                        }

                        if (us != null)
                        {
                            us.Append(dc.Statistics);
                        }
                    }
                    catch (Exception excp)
                    {
                        transaction.Rollback();
                        m_logger.Excp(excp, "UpdateAllWithSqlBulkCopy General Transaction Exception");
                    }
                    finally
                    {
                        DateTime dtEnd = DateTime.Now;

                        if (fsr != eFileSyncResult.Skipped)
                        {
                            // DK: Let's write to log ONLY Succeeded or Failed file syncrhonization info.

                            string sInfo = @"
{7} UpdateAllWithSqlBulkCopy({0}) {1}

{2}


{3}

Start: {4};  
  End: {5};  
 Time: {6};
";

                            m_logger.InfoFormat(
                                sInfo,                // Format
                                sProviderDescription, // Provider Description
                                fsr,                  // Result
                                sErrorString,         // Errors if any
                                dc.Statistics,        // Statistic
                                dtStart,
                                dtEnd,
                                dtEnd - dtStart,     // Time
                                sUpdateDescription); // LiveBet or PreMatch
                        }
                        else
                        {
                            m_logger.InfoFormat("{0} UpdateAllWithSqlBulkCopy Skipped. Time: {1}", sUpdateDescription, dtEnd - dtStart);
                        }

                        if (fsr == eFileSyncResult.Succeeded)
                        {
                        }

                        ct.AddEvent("UpdateAll({0}) completed", sUpdateDescription);
                        ct.Info(m_logger);
                    }
                }
                //                }
            }
            catch (Exception excp)
            {
                sErrorString += ExcpHelper.FormatException(excp, "UpdateAllWithSqlBulkCopy General Exception");
                m_logger.Error(sErrorString, excp);
            }

            return(fsr);
        }
示例#7
0
        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);
            }
        }
示例#8
0
        public static eFileSyncResult SyncRoutines(eUpdateType eut, string sProviderDescription, bool bUseDatabase, UpdateStatistics us, DelegateMerge dm)
        {
            Debug.Assert(dm != null);

            CheckTime ct = new CheckTime(true, "SyncRoutines(UseDatabase={0}) entered", bUseDatabase);

            /*
             * if (DalStationSettings.Instance.EnableRunProcessControl)
             * {
             *  string sInfo = SystemControl.GetSystemInfo() + "\r\n" + ProcessControl.Current.ToDetailedString();
             *  m_logger.Info(sInfo);
             *
             #if DEBUG
             *  m_logger.Info(ProcessControl.Current.GetThreadSummary());
             #endif
             *
             *  ct.AddEvent("Control completed");
             * }
             */

            try
            {
                eFileSyncResult fsr = eFileSyncResult.Failed;

                lock (m_oUpdateLocker)
                {
                    ct.AddEvent("Inside of lock");

                    LineSr.Instance.NewOrChangedObjects.UnsetPropertiesChanged();
                    LineSr.Instance.NewOrChangedObjects.Clear();

                    bool bProcessUpdateSucceeded = false;

                    lock (m_oReadLocker)
                    {
                        ct.AddEvent("Cache Update Started");
                        bProcessUpdateSucceeded = dm(null);
                        ct.AddEvent("Cache Update Completed ({0}, {1})", LineSr.Instance.NewOrChangedObjects.Count, LineSr.Instance.ObjectsToRemove.Count);
                    }

                    if (bUseDatabase)
                    {
                        // We use database to store Live Data
                        fsr = DataCopy.UpdateDatabase(ConnectionManager.GetConnection(), eut, sProviderDescription, us);
                        ct.AddEvent("Database Update Completed");

                        if (fsr == eFileSyncResult.Succeeded)
                        {
                            LineSr.Instance.NewOrChangedObjects.NotifyPropertiesChanged();
                            DatabaseCache.Instance.AddNewObjectsAfterCommit();
                            DatabaseCache.Instance.RemoveObjectsAfterCommit();
                            LineSr.Instance.ObjectsToRemove.Clear();

                            ct.AddEvent("Routines Completed (fsr=Succeeded)");
                        }
                        else
                        {
                            ct.AddEvent("Routines Completed (fsr=Skipped or Failed)");
                        }
                    }
                    else
                    {
                        // We DON'T use database to store Live Data
                        fsr = eFileSyncResult.Succeeded;
                        LineSr.Instance.NewOrChangedObjects.NotifyPropertiesChanged();
                        ct.AddEvent("Routines Completed");
                    }

                    if (fsr == eFileSyncResult.Succeeded && bProcessUpdateSucceeded)
                    {
                        ct.AddEvent("ProcessDataSqlUpdateSucceeded() Completed");
                    }
                }

                return(fsr);
            }
            catch (Exception excp)
            {
                LineSr.Instance.ObjectsToRemove.Clear();
                m_logger.Excp(excp, "SyncRoutines(eUpdateType={0}, sProviderDescription='{1}') ERROR", eut, sProviderDescription);

                ct.AddEvent("Exception Completed");
                ct.Error(m_logger);
            }
            finally
            {
                ct.AddEvent("Completed");
                ct.Info(m_logger);
            }

            return(eFileSyncResult.Failed);
        }
示例#9
0
        public void VerifySelectedOdds(SortableObservableCollection <ITipItemVw> socSelectedOdds, SyncHashSet <ITipItemVw> hsOddsToRemove = null)
        {
            CheckTime ct = new CheckTime(true, "VerifySelectedOdds(TipCount={0})", socSelectedOdds.Count);

            ExcpHelper.ThrowIf <ArgumentNullException>(socSelectedOdds == null, "VerifySelectedOdds(NULL) ERROR");

            lock (_verifyLocker)
            {
                ct.AddEvent("Lock Entered");

                if (hsOddsToRemove != null)
                {
                    hsOddsToRemove.Clear();
                }
                else
                {
                    hsOddsToRemove = new SyncHashSet <ITipItemVw>();
                }

                SyncList <ITipItemVw> lTipItems = socSelectedOdds.ToSyncList();

                foreach (TipItemVw tiv in lTipItems)
                {
                    // Check if selected odd is not expired
                    if (!CheckOdd(tiv.Odd))
                    {
                        hsOddsToRemove.Add(tiv);
                    }
                    // Check if selected odd is not yet in current collection (m_lSelectedOdds)
                    else if (!m_lSelectedOdds.Contains(tiv.Odd))
                    {
                        m_lSelectedOdds.Add(tiv.Odd);
                        tiv.Odd.BetDomain.Match.SetSelected(tiv.Odd, true);
                    }
                }

                ct.AddEvent("Check Completed");

                // Remove from socSelectedOdds and m_lSelectedOdds
                for (int i = 0; i < lTipItems.Count;)
                {
                    var tiv = lTipItems[i];

                    if (hsOddsToRemove.Contains(tiv))
                    {
                        // This Odd is expired
                        lTipItems.Remove(tiv);
                        socSelectedOdds.Remove(tiv);
                        m_lSelectedOdds.Remove(tiv.Odd);
                        tiv.Odd.BetDomain.Match.SetSelected(tiv.Odd, false);
                    }
                    else
                    {
                        i++;
                    }
                }

                ct.AddEvent("Remove from List Completed");

                // Remove from m_lSelectedOdd those items were not removed in previous cycle
                for (int i = 0; i < m_lSelectedOdds.Count;)
                {
                    IOddLn odd = m_lSelectedOdds[i];

                    TipItemVw tiv = new TipItemVw(odd);

                    if (!lTipItems.Contains(tiv))
                    {
                        m_lSelectedOdds.Remove(odd);
                        tiv.Odd.BetDomain.Match.SetSelected(tiv.Odd, false);
                    }
                    else
                    {
                        i++;
                    }
                }

                ct.AddEvent("Remove from List2 Completed");
            }

            ct.Info(m_logger);
        }
示例#10
0
        public void SearchMatches(SyncList <IMatchVw> lMatchesToSync, string sSearch, string sLanguage, DelegateFilterMatches dfm)
        {
            CheckTime ct = new CheckTime(false, "SearchMatches('{0}', '{1}') entered", sSearch, sLanguage);

            lock (m_oReadLocker)
            {
                if (lMatchesToSync != null)
                {
                    HashSet <IMatchVw> hsMatches   = new HashSet <IMatchVw>();
                    SyncList <MatchLn> lAllMatches = m_diAll.Matches.ToSyncList();

                    if (!string.IsNullOrEmpty(sSearch))
                    {
                        ct.AddEvent("Search by string in {0} matches", lAllMatches.Count);

                        IdentityList ilGroups      = new IdentityList();
                        IdentityList ilCompetitors = new IdentityList();

                        m_diAll.TaggedStrings.SearchRelatedStrings(sSearch, sLanguage, ilGroups, ilCompetitors);

                        int  iCode     = 0;
                        bool bIsNumber = int.TryParse(sSearch, out iCode) && 0 < iCode && iCode < MAX_MATCH_CODE;

                        if (ilCompetitors.Count > 0 || bIsNumber)
                        {
                            foreach (var mtch in lAllMatches)
                            {
#if DEBUG || TRACE_ID_FROM_FILE
                                if (TraceHelper.TraceFromFileLongValues("MatchIds.txt", (long)mtch.MatchId, new TraceHelper.DelegateLongFromRegistryFound(MatchIdFromFileFound), mtch))
                                {
                                    // Put breakpoint here to catch certain match by mtch.MatchId
                                }
#endif
                                string sCode = mtch.Code.Value.ToString("G");

                                if (sCode.IndexOf(sSearch, StringComparison.OrdinalIgnoreCase) >= 0 || ilCompetitors.Contains(mtch.HomeCompetitorId.Value) || ilCompetitors.Contains(mtch.AwayCompetitorId.Value))
                                {
                                    SearchMatchImp(hsMatches, lMatchesToSync, mtch, dfm);
                                }
                                //else
                                //{
                                //    SyncList<GroupLn> lGroups = LineSr.Instance.AllObjects.MatchesToGroups.GetMatchGroups(mtch.MatchId);

                                //    foreach (GroupLn group in lGroups)
                                //    {
                                //        if (ilGroups.Contains(group.GroupId))
                                //        {
                                //            SearchMatchImp(hsMatches, lMatchesToSync, mtch, dfm);
                                //        }
                                //    }
                                //}
                            }
                        }
                    }
                    else
                    {
                        ct.AddEvent("Search directly in {0} matches", lAllMatches.Count);

                        foreach (var mtch in lAllMatches)
                        {
#if DEBUG || TRACE_ID_FROM_FILE
                            if (TraceHelper.TraceFromFileLongValues("MatchIds.txt", (long)mtch.MatchId, new TraceHelper.DelegateLongFromRegistryFound(MatchIdFromFileFound), mtch))
                            {
                                // Put breakpoint here to catch certain match by mtch.MatchId
                            }
#endif
                            SearchMatchImp(hsMatches, lMatchesToSync, mtch, dfm);
                        }
                    }

                    ct.AddEvent("Search Completed");

                    for (int i = 0; i < lMatchesToSync.Count;)
                    {
                        IMatchVw matchView = lMatchesToSync[i];

                        if (!hsMatches.Contains(matchView))
                        {
                            lMatchesToSync.RemoveAt(i);
                        }
                        else
                        {
                            i++;
                        }
                    }

                    ct.AddEvent("Remove Completed");
                }
            }

            ct.AddEvent("Completed (Found {0} match(es))", lMatchesToSync.Count);
            ct.Info(m_logger);
        }