Beispiel #1
0
        /// <summary>
        /// Method wich used to map properties of two objects
        /// </summary>
        /// <typeparam name="T1"></typeparam>
        /// <typeparam name="T2"></typeparam>
        /// <param name="inputModel"></param>
        /// <returns></returns>
        public static T1 ResponseObjectMapper <T1, T2>(T2 inputModel)
        {
            //Get Caller Method name
            string callerMethodName = string.Empty;

            try
            {
                //Get Caller Method name from CallerInformation class
                callerMethodName = CallerInformation.TrackCallerMethodName();
                var entity     = Activator.CreateInstance <T1>();
                var properties = inputModel.GetType().GetProperties();
                foreach (var entry in properties)
                {
                    var propertyInfo = entity.GetType().GetProperty(entry.Name);
                    if (propertyInfo != null)
                    {
                        propertyInfo.SetValue(entity, entry.GetValue(inputModel), null);
                    }
                }
                return(entity);
            }
            catch (Exception exception)
            {
                //write exception into application insights
                InsightLogger.Exception(exception.Message + " - Error in DataProver while properties matching in object mapper", exception, callerMethodName);
                throw new Exception();
            }
        }
Beispiel #2
0
        /// <summary>
        /// method to delete multiple entities from azure table
        /// </summary>
        /// <typeparam name="T">Takes table entity type as input</typeparam>
        /// <param name="tablename">takes table name as input</param>
        /// <param name="entitieslist">takes entities list as input</param>
        public static void RemoveEntities <T>(string tablename, List <T> entitieslist) where T : ITableEntity, new()
        {
            //Get Caller Method name
            string callerMethodName = string.Empty;

            try
            {
                //Get Caller Method name from CallerInformation class
                callerMethodName = CallerInformation.TrackCallerMethodName();
                //get's azure table instance
                CloudTable          UserBackendConfigurationTable = GetAzureTableInstance(tablename);
                TableBatchOperation batchOperation = new TableBatchOperation();
                //insert list of entities into batch operation
                foreach (T entity in entitieslist)
                {
                    batchOperation.Add(TableOperation.Delete(entity));
                }
                UserBackendConfigurationTable.ExecuteBatch(batchOperation);
            }
            catch (Exception exception)
            {
                //write exception into application insights
                InsightLogger.Exception(exception.Message + " - Error in DataProver while removing entity from " + tablename, exception, callerMethodName);
                throw new Exception();
            }
        }
Beispiel #3
0
        /// <summary>
        /// method to get azure table storage object instance
        /// </summary>
        /// <param name="TableName">takes table name as input</param>
        /// <returns>Azure Table Instance</returns>
        public static CloudTable GetAzureTableInstance(string TableName)
        {
            //Get Caller Method name
            string callerMethodName = string.Empty;

            try
            {
                //Get Caller Method name from CallerInformation class
                callerMethodName = CallerInformation.TrackCallerMethodName();
                // Retrieve the storage account from the connection string.
                CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
                    CloudConfigurationManager.GetSetting(CoreConstants.AzureTables.AzureStorageConnectionString));
                // Create the table client.
                CloudTableClient tableClient = storageAccount.CreateCloudTableClient();
                // set retry for the connection for transient failures
                tableClient.DefaultRequestOptions = new TableRequestOptions
                {
                    RetryPolicy = new ExponentialRetry(TimeSpan.FromSeconds(5), 3)
                };
                // Create the CloudTable object that represents the table.
                CloudTable table = tableClient.GetTableReference(TableName);
                return(table);
            }
            catch (Exception exception)
            {
                //write exception into application insights
                InsightLogger.Exception(exception.Message + " - Error in DataProver while getting instance of azure table " + TableName, exception, callerMethodName);
                throw new Exception();
            }
        }
Beispiel #4
0
        /// <summary>
        /// method to insertor replace entity to azure table
        /// </summary>
        /// <typeparam name="T">Takes table entity type as input</typeparam>
        /// <param name="tablename">takes table name as input</param>
        /// <param name="entity">takes entity as input to insert</param>
        public static void InsertReplaceEntity <T>(string tablename, T entity) where T : ITableEntity, new()
        {
            //Get Caller Method name
            string callerMethodName = string.Empty;

            try
            {
                //Get Caller Method name from CallerInformation class
                callerMethodName = CallerInformation.TrackCallerMethodName();
                CloudTable     ReferenceDataTable     = GetAzureTableInstance(tablename);
                TableOperation insertreplaceOperation = TableOperation.InsertOrReplace(entity);
                ReferenceDataTable.Execute(insertreplaceOperation);
            }
            catch (Exception exception)
            {
                //write exception into application insights
                InsightLogger.Exception(exception.Message + " - Error in DataProver while insert or replace entity in " + tablename, exception, callerMethodName);
                throw new Exception();
            }
        }
Beispiel #5
0
        /// <summary>
        /// method to get entities list from azure table
        /// </summary>
        /// <typeparam name="T">Takes table entity type as input</typeparam>
        /// <param name="tablename">takes table name as input</param>
        /// <param name="query">takes query as input</param>
        /// <returns>returns entities list</returns>
        public static List <T> GetEntitiesList <T>(string tablename, TableQuery <T> query) where T : ITableEntity, new()
        {
            //Get Caller Method name
            string callerMethodName = string.Empty;

            try
            {
                //Get Caller Method name from CallerInformation class
                callerMethodName = CallerInformation.TrackCallerMethodName();
                //get's azure table instance
                CloudTable UserDeviceConfigurationTable = DataProvider.GetAzureTableInstance(tablename);
                //TableQuery<BackendEntity> query = new TableQuery<BackendEntity>().Where(TableQuery.GenerateFilterCondition(CoreConstants.AzureTables.PartitionKey, QueryComparisons.Equal, CoreConstants.AzureTables.Backend));
                List <T> allentities = UserDeviceConfigurationTable.ExecuteQuery(query).ToList();
                return(allentities);
            }
            catch (Exception exception)
            {
                //write exception into application insights
                InsightLogger.Exception(exception.Message + " - Error in DataProver while getting entities from " + tablename, exception, callerMethodName);
                throw new Exception();
            }
        }
Beispiel #6
0
        /// <summary>
        /// method to retrive entity from azure table
        /// </summary>
        /// <typeparam name="T">Takes table entity type as input</typeparam>
        /// <param name="tablename">takes table name as input</param>
        /// <param name="partitionkey">takes partition key as input</param>
        /// <param name="rowkey">takes row key as input</param>
        /// <returns>returns entity</returns>
        public static T Retrieveentity <T>(string tablename, string partitionkey, string rowkey) where T : ITableEntity, new()
        {
            //Get Caller Method name
            string callerMethodName = string.Empty;

            try
            {
                //Get Caller Method name from CallerInformation class
                callerMethodName = CallerInformation.TrackCallerMethodName();
                //get's azure table instance
                CloudTable     ReferenceDataTable  = GetAzureTableInstance(tablename);
                TableOperation RetrieveUser        = TableOperation.Retrieve <T>(partitionkey, rowkey);
                TableResult    RetrievedResultUser = ReferenceDataTable.Execute(RetrieveUser);
                return((T)RetrievedResultUser.Result);
            }
            catch (Exception exception)
            {
                //write exception into application insights
                InsightLogger.Exception(exception.Message + " - Error in DataProver while retrieving entity from " + tablename, exception, callerMethodName);
                throw new Exception();
            }
        }