private static void UpdatePrimaryRegion(string productName, string uniqueId, string tableName)
        {
            Dictionary <string, string> primaryConfigs = MultiRegionConfig.GetConfigWithConfigKey(MultiRegionConfigTypes.PrimaryRegion, productName + "-RS-SQLCON");
            string        connectionString             = null;
            SqlConnection objSqlCon = null;

            primaryConfigs.ForEach(config => { connectionString = config.Value; });
            try
            {
                ReliableSqlDatabase sqlHelper = new ReliableSqlDatabase(connectionString);
                objSqlCon = (SqlConnection)sqlHelper.CreateConnection();
                objSqlCon.Open();
                SqlCommand objSqlCommand = new SqlCommand("UPDATE " + tableName + " SET isReplicated = 1 where Guid = '" + uniqueId + "'");
                objSqlCommand.CommandType = CommandType.Text;
                objSqlCommand.Connection  = objSqlCon;
                objSqlCommand.ExecuteNonQuery();
            }
            catch (Exception exp)
            {
                throw exp;
            }
            finally
            {
                if (objSqlCon.State == ConnectionState.Open)
                {
                    objSqlCon.Close();
                }
            }
        }
        public static List <CommonProcessQueue> GetPrimaryRegionData(CommonProcessQueue sourceRegionMetadata, ReplicationRegion primaryRegion)
        {
            try
            {
                ReliableSqlDatabase sqlHelper     = new ReliableSqlDatabase(primaryRegion.ConnectionString);
                SqlConnection       objSqlCon     = null;
                DataSet             sourceDataSet = null;

                objSqlCon = (SqlConnection)sqlHelper.CreateConnection();
                objSqlCon.Open();
                using (SqlCommand objSqlCommand = new SqlCommand("select * from " + sourceRegionMetadata.TableName + " where isreplicated = 0"))
                {
                    objSqlCommand.CommandType = CommandType.Text;
                    sourceDataSet             = sqlHelper.ExecuteDataSet(objSqlCommand);
                }
                sourceDataSet.Tables[0].TableName = sourceRegionMetadata.TableName;

                List <CommonProcessQueue> cpqList = new List <CommonProcessQueue>();

                DataTable dataTable = sourceDataSet.Tables[0].Clone();
                dataTable.Columns["updatedon"].DateTimeMode = DataSetDateTime.Utc;
                dataTable = sourceDataSet.Tables[0];
                foreach (DataRow dr in dataTable.Rows)
                {
                    CommonProcessQueue cpq = new CommonProcessQueue
                    {
                        ReplicationConfigKey      = sourceRegionMetadata.ReplicationConfigKey,
                        ReplicationSourceRegionId = sourceRegionMetadata.ReplicationSourceRegionId,
                        TransactionDateTime       = ((DateTime)dr["updatedon"]).ToUniversalTime(),
                        Guid          = dr["guid"].ToString(),
                        TableName     = sourceRegionMetadata.TableName,
                        ProcessStatus = 1
                    };
                    cpqList.Add(cpq);
                }

                return(cpqList);
            }
            catch (Exception exp)
            {
                throw exp;
            }
        }
        protected async Task <T> ExecuteSqlReaderWithStoreProcAsync <T>(string spName, SqlParameter[] parameters, Func <IDataReader, T> action)
        {
            T result;

            using (var conn = (SqlConnection)sqlHelper.CreateConnection())
            {
                using (SqlCommand cmd = new SqlCommand(spName, conn))
                {
                    conn.Open();
                    cmd.CommandType = CommandType.StoredProcedure;
                    if (parameters != null && parameters.Length > 0)
                    {
                        cmd.Parameters.AddRange(parameters);
                    }
                    using (var read = await sqlHelper.ExecuteReaderAsync(cmd, CommandBehavior.CloseConnection))
                    {
                        result = (T)action(read);
                    }
                }
            }
            return(result);
        }
        public static DataTable GetPrimaryRegionDataForReplication(CommonProcessQueue sourceRegionMetadata, ReplicationRegion primaryRegion)
        {
            try
            {
                ReliableSqlDatabase sqlHelper     = new ReliableSqlDatabase(primaryRegion.ConnectionString);
                SqlConnection       objSqlCon     = null;
                DataSet             sourceDataSet = null;

                objSqlCon = (SqlConnection)sqlHelper.CreateConnection();
                objSqlCon.Open();
                using (SqlCommand objSqlCommand = new SqlCommand("select * from " + sourceRegionMetadata.TableName + " where isreplicated = 0"))
                {
                    objSqlCommand.CommandType = CommandType.Text;
                    sourceDataSet             = sqlHelper.ExecuteDataSet(objSqlCommand);
                }
                sourceDataSet.Tables[0].TableName = sourceRegionMetadata.TableName;

                return(sourceDataSet.Tables[0]);
            }
            catch (Exception exp)
            {
                throw exp;
            }
        }