Beispiel #1
0
 static void WriteResult(CountObj obj, int batchID, string DBName, int result)
 {
     using (SqlConnection sqlConn = new SqlConnection(ResultDBConnectionString))
     {
         sqlConn.Open();
         using (SqlCommand sqlComm = new SqlCommand())
         {
             sqlComm.Connection = sqlConn;
             string sqlResultUpdate = String.Format(@"IF Exists (select 1 from CARReconResultDetail where ReconBatchID = {0} and ObjectName = '{1}' and DBName = '{2}' )
                         delete CARReconResultDetail where  ReconBatchID = {0} and ObjectName = '{1}' and DBName = '{2}'
                 insert into CARReconResultDetail(ReconBatchID, ObjectName, SystemID,DBName, Result) values({0},'{1}','{2}','{3}'," + result.ToString() + ")",
                                                    batchID.ToString(), obj.ObjectName, obj.SystemID, DBName);
             sqlComm.CommandText = sqlResultUpdate;
             sqlComm.ExecuteNonQuery();
         }
     }
 }
Beispiel #2
0
        static void RecordCount(object obj, int batchID)
        {
            CountObj countObj = (CountObj)obj;

            string StageSQL = "";
            string CDSSQL   = "";
            string CARSQL   = "";

            int CDSstageCount = -1;
            int CDSCount      = -1;
            int CARCount      = -1;

            switch (countObj.SystemID)
            {
            case "CCS":
                StageSQL = "select count(*) from [CCS_STAGE].[TMOBILE_CARE].[dbo].[" + FindTableName(countObj.ObjectName, "Stage") + "] Where 1=1";
                CDSSQL   = "select count(*) from [CCS].[dbo].[" + FindTableName(countObj.ObjectName, "CDS") + "] Where 1=1";
                CARSQL   = "select count(*) from [CAR_CCS].[CCS].[" + FindTableName(countObj.ObjectName, "CAR") + "] Where 1=1 and CAR_bitIsCurrent = 1";
                break;

            case "ECS":
                StageSQL = "select count(*) from [ECS_STAGE].[TMOBILE_EMPLOYEE_PROD].[dbo].[" + FindTableName(countObj.ObjectName, "Stage") + "] Where 1=1";
                CDSSQL   = "select count(*) from [ECS].[dbo].[" + FindTableName(countObj.ObjectName, "CDS") + "] Where 1=1";
                CARSQL   = "select count(*) from [CAR_ECS].[ECS].[" + FindTableName(countObj.ObjectName, "CAR") + "] Where 1=1 and CAR_bitIsCurrent = 1";
                break;

            case "DCS":
                StageSQL = "select count(*) from [DCS_STAGE].[TMOBILE_INDIRECT_PROD].[dbo].[" + FindTableName(countObj.ObjectName, "Stage") + "] Where 1=1";
                CDSSQL   = "select count(*) from [DCS].[dbo].[" + FindTableName(countObj.ObjectName, "CDS") + "] Where 1=1";
                CARSQL   = "select count(*) from [CAR_DCS].[DCS].[" + FindTableName(countObj.ObjectName, "CAR") + "] Where 1=1 and CAR_bitIsCurrent = 1";
                break;
            }

#if DEBUG
            LogWriter.Write(CARSQL);
            LogWriter.Write(CDSSQL);
            LogWriter.Write(StageSQL);
#endif

            SqlConnection CDSConn    = null;
            SqlConnection CARConn    = null;
            SqlConnection resultConn = null;

            SqlCommand CDSComm    = null;
            SqlCommand CARComm    = null;
            SqlCommand ResultComm = null;

            try
            {
                CDSConn    = new SqlConnection(CDSConnectionString);
                CARConn    = new SqlConnection(CARConnectionString);
                resultConn = new SqlConnection(ResultDBConnectionString);
                CDSConn.Open();
                CARConn.Open();
                resultConn.Open();
                CDSComm               = new SqlCommand();
                CDSComm.Connection    = CDSConn;
                CARComm               = new SqlCommand();
                CARComm.Connection    = CARConn;
                ResultComm            = new SqlCommand();
                ResultComm.Connection = resultConn;

                //CAR Count
                try
                {
                    CARComm.CommandText = CARSQL;
                    SqlDataReader CARRd = CARComm.ExecuteReader();
                    if (CARRd.Read())
                    {
                        CARCount = CARRd.GetInt32(0);
                    }
                    CARRd.Close();
                }
                catch (Exception ex)
                {
                    LogWriter.Write(ex.ToString());
                    CARCount = -1;
                    if (!failedList.Contains(countObj))
                    {
                        failedList.Add(countObj);
                    }
                }



                //CDS count
                SqlDataReader CDSRd = null;
                try
                {
                    CDSComm.CommandText = CDSSQL;
                    CDSRd = CDSComm.ExecuteReader();
                    if (CDSRd.Read())
                    {
                        CDSCount = CDSRd.GetInt32(0);
                    }
                    CDSRd.Close();
                }
                catch (Exception ex)
                {
                    LogWriter.Write(ex.ToString());
                    CDSCount = -1;
                    if (!failedList.Contains(countObj))
                    {
                        failedList.Add(countObj);
                    }
                }

                //CDS Stage count
                try
                {
                    CDSComm.CommandText = StageSQL;
                    CDSRd = CDSComm.ExecuteReader();
                    if (CDSRd.Read())
                    {
                        CDSstageCount = CDSRd.GetInt32(0);
                    }
                    CDSRd.Close();
                }
                catch (Exception ex)
                {
                    LogWriter.Write(ex.ToString());
                    CDSstageCount = -1;
                    if (!failedList.Contains(countObj))
                    {
                        failedList.Add(countObj);
                    }
                }

                LogWriter.Write(CDSstageCount.ToString());
                LogWriter.Write(CDSCount.ToString());
                LogWriter.Write(CARCount.ToString());

                WriteResult(countObj, batchID, "CAR", CARCount);
                WriteResult(countObj, batchID, "CDS", CDSCount);
                WriteResult(countObj, batchID, "CDSStage", CDSstageCount);
            }
            catch (Exception ex)
            {
                LogWriter.Write(ex.ToString());
                failedList.Add(countObj);
            }
            finally
            {
                CDSComm.Dispose();
                CARComm.Dispose();
                ResultComm.Dispose();

                CDSConn.Close();
                CARConn.Close();
                resultConn.Close();
            }
        }
Beispiel #3
0
 static string GetDateCondition(CountObj obj)
 {
     return("XXX");
 }
Beispiel #4
0
        static void Main(string[] args)
        {
            LogWriter.Write("CAR Recon Process Starts...");

            using (SqlConnection PECon = new SqlConnection(PEConnectionString))
            {
                PECon.Open();
                using (SqlCommand cmd = new SqlCommand())
                {
                    cmd.Connection  = PECon;
                    cmd.CommandText = @"select * from [dbo].[PE_ProcessList] where ProcessType in (102) and SystemType <> 4";  // Disable IDS for now
                    SqlDataReader objectListReader = cmd.ExecuteReader();

                    //Get ReconBatch
                    int      newBatchID            = 0;
                    DateTime currentDateTime       = DateTime.Now;
                    string   currentDateTimeString = currentDateTime.ToString("yyyy-MM-dd HH:mm:ss.fff");
                    using (SqlConnection resultConn = new SqlConnection(ResultDBConnectionString))
                    {
                        resultConn.Open();
                        using (SqlCommand resultComm = new SqlCommand())
                        {
                            resultComm.Connection  = resultConn;
                            resultComm.CommandText = @"insert into CARReconBatch(ReconDate) OUTPUT Inserted.ReconBatchID values('" + currentDateTime + "')";
                            SqlDataReader batchIDReader = resultComm.ExecuteReader();
                            if (batchIDReader.Read())
                            {
                                newBatchID = batchIDReader.GetInt32(0);
                            }
                        }
                    }
                    LogWriter.Write("Current BatchID = " + newBatchID.ToString());


                    while (objectListReader.Read())
                    {
#if DEBUG
                        LogWriter.Write("Counting " + objectListReader["Path"].ToString());
#endif
                        //Start counting...
                        string myPath       = objectListReader["Path"].ToString();
                        string myObjectName = objectListReader["ProcessName"].ToString();
                        string mySystemID   = "";
                        switch (Int32.Parse(objectListReader["SystemType"].ToString()))
                        {
                        case 1:
                            mySystemID = "CCS";
                            break;

                        case 2:
                            mySystemID = "DCS";
                            break;

                        case 3:
                            mySystemID = "ECS";
                            break;

                        case 4:
                            mySystemID = "IDS";
                            break;
                        }



                        //Start counting CAR
                        CountObj myCountObj = new CountObj();
                        myCountObj.ObjectName = myObjectName;
                        myCountObj.Path       = myPath;
                        myCountObj.SystemID   = mySystemID;
                        RecordCount(myCountObj, newBatchID);

                        //
                    }

                    //Start retrying objects has issue
                    //LogWriter.Write("Start retrying counting...");
                    //int currentRrtryRemain = retryTime;
                    //while(failedList.Count>0 && currentRrtryRemain>0)
                    //{
                    //    foreach(CountObj obj in failedList)
                    //    {
                    //        RecordCount(obj, newBatchID);
                    //    }
                    //    currentRrtryRemain--;
                    //}
                }
            }
            LogWriter.Write("CAR Recon finished");
        }