예제 #1
0
 public void Append(UpdateStatistics uss)
 {
     foreach (string sTableName in uss.Keys)
     {
         this.Append(sTableName, uss[sTableName]);
     }
 }
예제 #2
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);
        }