public CommandTrackingEntity CreateNewCommandTracking(CommandTrackingEntity commandTracking)
 {
     m_Logger.DebugFormat("__{0}__: {1}: Enter Function", this.GetType().Name, MethodInfo.GetCurrentMethod().Name);
     try
     {
         commandTracking.TotalItems   = commandTracking.Items.Count;
         commandTracking.TotalSuccess = commandTracking.Items.Count <CommandItemTrackingEntity>(i => ((int)i.Status > commandItemStatusDefinition[SUCCESS].Item1 && (int)i.Status < commandItemStatusDefinition[SUCCESS].Item2));
         commandTracking.TotalFailure = commandTracking.Items.Count <CommandItemTrackingEntity>(i => ((int)i.Status > commandItemStatusDefinition[FAILURE].Item1 && (int)i.Status < commandItemStatusDefinition[FAILURE].Item2));
         using (CommandTrackingDatabaseUtility db = new CommandTrackingDatabaseUtility(m_DbConnectionString))
         {
             commandTracking = db.AddCommandItemTracking(db.AddCommandTracking(commandTracking));
         }
     }
     catch (SqlException ex)
     {
         m_Logger.ErrorFormat("__{0}__: {1}: SQL Exception={2}", this.GetType().Name, MethodInfo.GetCurrentMethod().Name, ex.ToString());
         throw;
     }
     catch (Exception ex)
     {
         m_Logger.ErrorFormat("__{0}__: {1}: Exception={2}", this.GetType().Name, MethodInfo.GetCurrentMethod().Name, ex.ToString());
         throw;
     }
     m_Logger.DebugFormat("__{0}__: {1}: Leave Function", this.GetType().Name, MethodInfo.GetCurrentMethod().Name);
     return(commandTracking);
 }
        public CommandTrackingEntity GetCommandTrackingByCommandTrackingID(string comandTrackingID)
        {
            m_Logger.DebugFormat("__{0}__: {1}: Enter Function", this.GetType().Name, MethodInfo.GetCurrentMethod().Name);
            CommandTrackingEntity commandTracking = new CommandTrackingEntity();

            try
            {
                using (CommandTrackingDatabaseUtility db = new CommandTrackingDatabaseUtility(m_DbConnectionString))
                {
                    commandTracking       = db.QueryCommandTrackingByCommandTrackingID(comandTrackingID);
                    commandTracking.Items = db.QueryCommandItemTrackingByCommandTrackingID(comandTrackingID);
                }
            }
            catch (SqlException ex)
            {
                m_Logger.ErrorFormat("__{0}__: {1}: SQL Exception={2}", this.GetType().Name, MethodInfo.GetCurrentMethod().Name, ex.ToString());
                throw;
            }
            catch (Exception ex)
            {
                m_Logger.ErrorFormat("__{0}__: {1}: Exception={2}", this.GetType().Name, MethodInfo.GetCurrentMethod().Name, ex.ToString());
                throw;
            }
            m_Logger.DebugFormat("__{0}__: {1}: Leave Function", this.GetType().Name, MethodInfo.GetCurrentMethod().Name);
            return(commandTracking);
        }
Exemplo n.º 3
0
        public CommandTrackingEntity AddCommandTracking(CommandTrackingEntity commandTracking)
        {
            m_Logger.DebugFormat("__{0}__: {1}: Enter Function", this.GetType().Name, MethodInfo.GetCurrentMethod().Name);
            string cmdText = "sp_CreateCommandTracking";

            commandTracking.CommandTrackingID = Guid.NewGuid().ToString().ToUpper();
            m_Logger.DebugFormat("__{0}__: {1}: Add a Command Tracking. GUID = {1}", this.GetType().Name, MethodInfo.GetCurrentMethod().Name, commandTracking.CommandTrackingID);
            try
            {
                AddSqlParameter("cmdid", SqlDbType.Char, commandTracking.CommandTrackingID);
                //0: CTTG_UNKNOWN, 1: CTTG_ENTITY, 2: CTTG_SELF_TMS, 3: CTTG_CHILD_TMS
                AddSqlParameter("CT_TargetGroup", SqlDbType.Int, 1);
                AddSqlParameter("CT_ReceiverID", SqlDbType.Char, commandTracking.ReceiverID);
                AddSqlParameter("CT_UserAccessID", SqlDbType.NVarChar, commandTracking.UserAccessID);
                AddSqlParameter("CT_MessageID", SqlDbType.Int, commandTracking.MessageID);
                AddSqlParameter("CT_TotalCommandItems", SqlDbType.Int, commandTracking.TotalItems);
                AddSqlParameter("CT_TotalSuccess", SqlDbType.Int, commandTracking.TotalSuccess);
                AddSqlParameter("CT_ErrorDescription", SqlDbType.NVarChar, commandTracking.ErrorDescription);
                AddSqlParameter("CT_Location", SqlDbType.NVarChar, DBNull.Value);
                AddSqlParameter("CT_Parameters", SqlDbType.NVarChar, commandTracking.Parameters);
                AddSqlParameter("CT_CommandData", SqlDbType.Image, DBNull.Value);
                AddSqlParameter("CT_TotalFailure", SqlDbType.Int, commandTracking.TotalFailure);
                ExecuteSqlCommandNonQuery(cmdText, CommandType.StoredProcedure);
            }
            catch (Exception ex)
            {
                m_Logger.ErrorFormat("__{0}__: {1}: Exception = {2} ", this.GetType().Name, MethodInfo.GetCurrentMethod().Name, ex.ToString());
                throw;
            }
            m_Logger.DebugFormat("__{0}__: {1}: Leave Function", this.GetType().Name, MethodInfo.GetCurrentMethod().Name);
            return(commandTracking);
        }
Exemplo n.º 4
0
        public CommandTrackingEntity UpdateCommandTracking(CommandTrackingEntity commandTracking)
        {
            m_Logger.DebugFormat("__{0}__: {1}: Enter Function", this.GetType().Name, MethodInfo.GetCurrentMethod().Name);
            int    affectedRows = 0;
            string cmdText      = "UPDATE tb_CommandTracking SET CT_ReceiverID = @CT_ReceiverID, CT_TotalCommandItems = @CT_TotalCommandItems, CT_TotalSuccess = @CT_TotalSuccess, CT_TotalFailure = @CT_TotalFailure, CT_UpdateTime = GETDATE(), CT_ErrorDescription = @CT_ErrorDescription WHERE CT_ID = @cmdid";

            m_Logger.DebugFormat("__{0}__: {1}: Update a Command Tracking. GUID = {1}", this.GetType().Name, MethodInfo.GetCurrentMethod().Name, commandTracking.CommandTrackingID);
            try
            {
                AddSqlParameter("cmdid", SqlDbType.Char, commandTracking.CommandTrackingID);
                AddSqlParameter("CT_ReceiverID", SqlDbType.Char, commandTracking.ReceiverID);
                AddSqlParameter("CT_TotalCommandItems", SqlDbType.Int, commandTracking.TotalItems);
                AddSqlParameter("CT_TotalSuccess", SqlDbType.Int, commandTracking.TotalSuccess);
                AddSqlParameter("CT_TotalFailure", SqlDbType.Int, commandTracking.TotalFailure);
                AddSqlParameter("CT_ErrorDescription", SqlDbType.NVarChar, commandTracking.ErrorDescription);
                affectedRows = ExecuteSqlCommandNonQuery(cmdText, CommandType.Text);
            }
            catch (Exception ex)
            {
                m_Logger.ErrorFormat("__{0}__: {1}: Exception = {2} ", this.GetType().Name, MethodInfo.GetCurrentMethod().Name, ex.ToString());
                throw;
            }
            if (affectedRows == 1)
            {
                m_Logger.DebugFormat("__{0}__: {1}: Update successfully", this.GetType().Name, MethodInfo.GetCurrentMethod().Name);
            }
            else
            {
                m_Logger.DebugFormat("__{0}__: {1}: Unexpected result to update", this.GetType().Name, MethodInfo.GetCurrentMethod().Name);
            }
            m_Logger.DebugFormat("__{0}__: {1}: Leave Function", this.GetType().Name, MethodInfo.GetCurrentMethod().Name);
            return(commandTracking);
        }
Exemplo n.º 5
0
        public CommandTrackingEntity AddCommandItemTracking(CommandTrackingEntity commandTracking)
        {
            m_Logger.DebugFormat("__{0}__: {1}: Enter Function", this.GetType().Name, MethodInfo.GetCurrentMethod().Name);
            string cmdText = "sp_CreateCommandItemTracking";

            try
            {
                foreach (CommandItemTrackingEntity item in commandTracking.Items)
                {
                    AddSqlParameter("cmdid", SqlDbType.Char, commandTracking.CommandTrackingID);
                    item.ItemID = Guid.NewGuid().ToString().ToUpper();
                    m_Logger.DebugFormat("__{0}__: {1}: Add a item. GUID = {1}", this.GetType().Name, MethodInfo.GetCurrentMethod().Name, item.ItemID);
                    AddSqlParameter("cmditemid", SqlDbType.Char, item.ItemID);
                    AddSqlParameter("CIT_ReceiverID", SqlDbType.Char, item.ReceiverID);
                    AddSqlParameter("CIT_MessageID", SqlDbType.Int, item.MessageID);
                    AddSqlParameter("CIT_Status", SqlDbType.Int, item.Status);
                    AddSqlParameter("CIT_ErrorDescription", SqlDbType.NVarChar, item.ErrorDescription);
                    AddSqlParameter("CIT_Location", SqlDbType.NVarChar, DBNull.Value);
                    AddSqlParameter("CIT_Parameters", SqlDbType.NVarChar, item.Parameters);
                    ExecuteSqlCommandNonQuery(cmdText, CommandType.StoredProcedure);
                }
            }
            catch (Exception ex)
            {
                m_Logger.ErrorFormat("__{0}__: {1}: Exception = {2} ", this.GetType().Name, MethodInfo.GetCurrentMethod().Name, ex.ToString());
                throw;
            }
            m_Logger.DebugFormat("__{0}__: {1}: Leave Function", this.GetType().Name, MethodInfo.GetCurrentMethod().Name);
            return(commandTracking);
        }
        public CommandTrackingEntity UpdateCommandTracking(CommandTrackingEntity commandTracking)
        {
            m_Logger.DebugFormat("__{0}__: {1}: Enter Function", this.GetType().Name, MethodInfo.GetCurrentMethod().Name);
            List <CommandItemTrackingEntity> newItems     = new List <CommandItemTrackingEntity>();
            List <CommandItemTrackingEntity> existedItems = new List <CommandItemTrackingEntity>();

            try
            {
                using (CommandTrackingDatabaseUtility db = new CommandTrackingDatabaseUtility(m_DbConnectionString))
                {
                    List <CommandItemTrackingEntity> currentItems = db.QueryCommandItemTrackingByCommandTrackingID(commandTracking.CommandTrackingID);
                    foreach (CommandItemTrackingEntity item in commandTracking.Items)
                    {
                        if (item.ItemID != null)
                        {
                            m_Logger.DebugFormat("__{0}__: {1}: It is an item which is not a new one", this.GetType().Name, MethodInfo.GetCurrentMethod().Name);
                            if (currentItems.Count <CommandItemTrackingEntity>(i => (i.ItemID == item.ItemID) && (i.ReceiverID != item.ReceiverID || i.Status != item.Status || i.ErrorDescription != item.ErrorDescription)) > 0)
                            {
                                m_Logger.DebugFormat("__{0}__: {1}: It must be updated", this.GetType().Name, MethodInfo.GetCurrentMethod().Name);
                                existedItems.Add(item);
                            }
                        }
                        else
                        {
                            m_Logger.DebugFormat("__{0}__: {1}: It is a new item", this.GetType().Name, MethodInfo.GetCurrentMethod().Name);
                            newItems.Add(item);
                        }
                    }
                    commandTracking.Items        = existedItems;
                    commandTracking              = db.UpdateCommandItemTracking(commandTracking);
                    commandTracking.Items        = newItems;
                    commandTracking              = db.AddCommandItemTracking(commandTracking);
                    commandTracking.Items        = db.QueryCommandItemTrackingByCommandTrackingID(commandTracking.CommandTrackingID);
                    commandTracking.TotalItems   = commandTracking.Items.Count;
                    commandTracking.TotalSuccess = commandTracking.Items.Count <CommandItemTrackingEntity>(i => ((int)i.Status > commandItemStatusDefinition[SUCCESS].Item1 && (int)i.Status < commandItemStatusDefinition[SUCCESS].Item2));
                    commandTracking.TotalFailure = commandTracking.Items.Count <CommandItemTrackingEntity>(i => ((int)i.Status > commandItemStatusDefinition[FAILURE].Item1 && (int)i.Status < commandItemStatusDefinition[FAILURE].Item2));
                    commandTracking              = db.UpdateCommandTracking(commandTracking);
                }
            }
            catch (SqlException ex)
            {
                m_Logger.ErrorFormat("__{0}__: {1}: SQL Exception={2}", this.GetType().Name, MethodInfo.GetCurrentMethod().Name, ex.ToString());
                throw;
            }
            catch (Exception ex)
            {
                m_Logger.ErrorFormat("__{0}__: {1}: Exception={2}", this.GetType().Name, MethodInfo.GetCurrentMethod().Name, ex.ToString());
                throw;
            }
            m_Logger.DebugFormat("__{0}__: {1}: Leave Function", this.GetType().Name, MethodInfo.GetCurrentMethod().Name);
            return(commandTracking);
        }
Exemplo n.º 7
0
        public CommandTrackingEntity UpdateCommandItemTracking(CommandTrackingEntity commandTracking)
        {
            m_Logger.DebugFormat("__{0}__: {1}: Enter Function", this.GetType().Name, MethodInfo.GetCurrentMethod().Name);
            int    affectedRows = 0;
            string cmdText      = "UPDATE tb_CommandItemTracking SET CIT_ReceiverID = @CIT_ReceiverID, CIT_Status = @CIT_Status, CIT_ErrorDescription = @CIT_ErrorDescription, CIT_Parameters = @CIT_Parameters, CIT_UpdateTime = GETDATE() WHERE CIT_CommandID = @cmdid AND CIT_ID = @cmditemid";

            try
            {
                foreach (CommandItemTrackingEntity item in commandTracking.Items)
                {
                    AddSqlParameter("cmdid", SqlDbType.Char, commandTracking.CommandTrackingID);
                    m_Logger.DebugFormat("__{0}__: {1}: Add a item. GUID = {1}", this.GetType().Name, MethodInfo.GetCurrentMethod().Name, item.ItemID);
                    AddSqlParameter("cmditemid", SqlDbType.Char, item.ItemID);
                    AddSqlParameter("CIT_ReceiverID", SqlDbType.Char, item.ReceiverID);
                    AddSqlParameter("CIT_Status", SqlDbType.Int, item.Status);
                    AddSqlParameter("CIT_ErrorDescription", SqlDbType.NVarChar, item.ErrorDescription);
                    AddSqlParameter("CIT_Parameters", SqlDbType.NVarChar, item.Parameters);
                    affectedRows = ExecuteSqlCommandNonQuery(cmdText, CommandType.Text);
                    if (affectedRows == 1)
                    {
                        m_Logger.DebugFormat("__{0}__: {1}: Add successfully", this.GetType().Name, MethodInfo.GetCurrentMethod().Name);
                    }
                    else
                    {
                        m_Logger.DebugFormat("__{0}__: {1}: Unexpected result to add", this.GetType().Name, MethodInfo.GetCurrentMethod().Name);
                    }
                    affectedRows = 0;
                }
            }
            catch (Exception ex)
            {
                m_Logger.ErrorFormat("__{0}__: {1}: Exception = {2} ", this.GetType().Name, MethodInfo.GetCurrentMethod().Name, ex.ToString());
                throw;
            }
            m_Logger.DebugFormat("__{0}__: {1}: Leave Function", this.GetType().Name, MethodInfo.GetCurrentMethod().Name);
            return(commandTracking);
        }