Esempio n. 1
0
        /// <summary>
        /// Update next collecting time for each backend
        /// </summary>
        public void UpdateNextCollectingTime(bool IsFirstTime)
        {
            string callerMethodName = string.Empty;

            try
            {
                //Get Caller Method name from CallerInformation class
                callerMethodName = CallerInformation.TrackCallerMethodName();
                //get's azure table instance
                CloudTable UserDeviceConfigurationTable = DataProvider.GetAzureTableInstance(azureTableUserDeviceConfiguration);
                //Get all backends
                List <BackendEntity> lstbackends  = objdal.GetBackends();
                DateTime             curTimestamp = DateTime.Now;
                //for each backend get minimum update frequency for all the userbackend's associated
                //foreach(BackendEntity backend in lstbackends)
                Parallel.ForEach <BackendEntity>(lstbackends, backend =>
                {
                    InsightLogger.TrackEvent("UpdateTriggering, Action :: for each backend :: set next collecting time (Rule R1) :: start() , Response :: Backend Name : " + backend.BackendID);
                    string backendID = backend.RowKey;
                    //Get all the userbackends associated with the backend
                    TableQuery <UserBackendEntity> tquery    = new TableQuery <UserBackendEntity>().Where(TableQuery.GenerateFilterCondition(CoreConstants.AzureTables.RowKey, QueryComparisons.Equal, backend.RowKey));
                    List <UserBackendEntity> allUserBackends = UserDeviceConfigurationTable.ExecuteQuery(tquery).ToList();
                    int minUpdateFrequency = 0;
                    if (allUserBackends != null && allUserBackends.Count > 0)
                    {
                        minUpdateFrequency = allUserBackends.Min(r => r.DefaultUpdateFrequency);
                    }
                    //get minimum update frequency from User Backend list

                    //InsightLogger.TrackEvent("UpdateTriggering, Action :: Collecting the minimum Default Update Frequency of all the userbackends under the backend :" + backendID + " , Response :: Minimum Update Frquency :" + minUpdateFrequency );
                    //Get next collecting hours based on update Triggering Rule :: R1
                    int nextCollectingTimeInMinutes;
                    if (minUpdateFrequency < defaultMinUpdateFrequency)
                    {
                        nextCollectingTimeInMinutes = defaultMinUpdateFrequency;
                    }
                    else
                    {
                        nextCollectingTimeInMinutes = minUpdateFrequency / nextCollectingTimeDividend;
                    }
                    //update backend next collecting time in refernecedata table
                    this.InsertorUpdateBackendNextCollectingTime(backendID, nextCollectingTimeInMinutes, backend.AverageAllRequestsLatency, backend.LastAllRequestsLatency, IsFirstTime, curTimestamp);
                    InsightLogger.TrackEvent("UpdateTriggering, Action :: for each backend :: Set next collecting time (Rule R1) :: End() , Response :: Success, Backend Name : " + backend.BackendID);
                    // this.objdal.CollectUsersNeedUpdateByBackend(backendID);
                });
            }
            catch (BusinessLogicException balexception)
            {
                throw balexception;
            }
            catch (DataAccessException dalexception)
            {
                throw dalexception;
            }
            catch (Exception exception)
            {
                InsightLogger.Exception(exception.Message, exception, callerMethodName);
                throw new DataAccessException(exception.Message, exception.InnerException);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// This method Archival the data which is greater than two months old in azure table
        /// </summary>
        /// <param name="timerInfo"></param>
        /// <param name="log"></param>
        public static void ArchivalData([TimerTrigger(typeof(DailyScheduleForArchival))] TimerInfo timerInfo, TextWriter log)
        {
            string callerMethodName = string.Empty;

            try
            {
                //Get Caller Method name from CallerInformation class
                callerMethodName = CallerInformation.TrackCallerMethodName();
                var                  timestamp   = DateTime.Today.AddDays(Convert.ToInt32(ConfigurationManager.AppSettings["ArchivalDayInterval"])).ToString("yyyy-MM-dd");
                UserBackendDAL       objdal      = new UserBackendDAL();
                List <BackendEntity> lstbackends = objdal.GetBackends();
                //foreach backend
                DateTime currentTimestamp = DateTime.Now;
                //foreach(BackendEntity backend in lstbackends)
                Parallel.ForEach <BackendEntity>(lstbackends, backend =>
                {
                    string backendID = backend.RowKey;
                    InsightLogger.TrackEvent("UpdateTriggering, Action :: for each backend :: Archival historical data : start() , Response :: Backend Name : " + backendID);
                    //Get all the userbackends associated with the backendS
                    CloudTable UserDeviceConfigurationTable  = DataProvider.GetAzureTableInstance(azureTableUserDeviceConfiguration);
                    TableQuery <UserBackendEntity> tquery    = new TableQuery <UserBackendEntity>().Where(TableQuery.GenerateFilterCondition(CoreConstants.AzureTables.RowKey, QueryComparisons.Equal, backend.RowKey));
                    List <UserBackendEntity> allUserBackends = UserDeviceConfigurationTable.ExecuteQuery(tquery).ToList();
                    foreach (UserBackendEntity user in allUserBackends)
                    {
                        string username = user.UserID;
                        objdal.ArchivalRequestsData(username, timestamp);
                    }
                    InsightLogger.TrackEvent("UpdateTriggering, Action :: for each backend :: Archival historical data : End() , Response :: Backend Name : " + backendID);
                });
            }
            catch (BusinessLogicException balexception)
            {
                //write exception message to web job dashboard logs
                //log.WriteLine(balexception.Message);
                //write Business Logic Exception into application insights
                InsightLogger.Exception(balexception.Message, balexception, callerMethodName);
            }
            catch (DataAccessException dalexception)
            {
                //write exception message to web job dashboard logs
                //log.WriteLine(dalexception.Message);
                //write Data layer logic Exception into application insights
                InsightLogger.Exception(dalexception.Message, dalexception, callerMethodName);
            }
            catch (Exception exception)
            {
                // log.WriteLine("Error in adidas.clb.job.UpdateTriggering :: Functions :: RegularChecksforUserbackendLostsUpdate() :: Exception Message=" + exception.Message);
                //write  Exception into application insights
                InsightLogger.Exception(exception.Message, exception, callerMethodName);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// method to get all backends
        /// </summary>
        /// <returns>returns list of backends as personalization response form</returns>
        public PersonalizationResponseListDTO <BackendDTO> GetBackends()
        {
            string callerMethodName = string.Empty;

            try
            {
                //Get Caller Method name from CallerInformation class
                callerMethodName = CallerInformation.TrackCallerMethodName();
                UserBackendDAL userbackenddal = new UserBackendDAL();
                //calling data access layer method
                List <BackendEntity> backends        = userbackenddal.GetBackends();
                List <BackendDTO>    backendslistdto = new List <BackendDTO>();
                //if backends not available return null
                if (backends != null && backends.Count > 0)
                {
                    //backends entity converting to data transfer object
                    foreach (BackendEntity backend in backends)
                    {
                        BackendDTO backenddto = DataProvider.ResponseObjectMapper <BackendDTO, BackendEntity>(backend);
                        backendslistdto.Add(backenddto);
                    }
                }
                else
                {
                    backendslistdto = null;
                }
                var ResponseBackends = new PersonalizationResponseListDTO <BackendDTO>();
                ResponseBackends.result = backendslistdto;
                return(ResponseBackends);
            }
            catch (DataAccessException DALexception)
            {
                throw DALexception;
            }
            catch (Exception exception)
            {
                InsightLogger.Exception(exception.Message, exception, callerMethodName);
                //LoggerHelper.WriteToLog(exception + " - Error in BL while retreiving backends : "
                //+exception.ToString(), CoreConstants.Priority.High, CoreConstants.Category.Error);
                throw new BusinessLogicException();
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Method to associate all existing backends in the system to user
        /// </summary>
        /// <param name="userid">takes userid as input</param>
        public void AddAllBackends(string userid)
        {
            string callerMethodName = string.Empty;

            try
            {
                //Get Caller Method name from CallerInformation class
                callerMethodName = CallerInformation.TrackCallerMethodName();
                UserBackendDAL userbackenddal = new UserBackendDAL();
                //method to get all backends available in system
                List <BackendEntity>     backends         = userbackenddal.GetBackends();
                List <UserBackendEntity> userbackendslist = new List <UserBackendEntity>();
                //preparing userbackend obj for each backend obj
                foreach (BackendEntity backend in backends)
                {
                    UserBackendEntity userbackend = new UserBackendEntity();
                    userbackend.PartitionKey           = string.Concat(CoreConstants.AzureTables.UserBackendPK, userid);
                    userbackend.RowKey                 = backend.BackendID;
                    userbackend.BackendID              = backend.BackendID;
                    userbackend.UserID                 = userid;
                    userbackend.DefaultUpdateFrequency = Convert.ToInt32(ConfigurationManager.AppSettings[CoreConstants.Config.UpdateFrequency]);
                    userbackendslist.Add(userbackend);
                }
                //calling data access layer method to add backends
                userbackenddal.AddBackends(userbackendslist);
            }
            catch (DataAccessException DALexception)
            {
                throw DALexception;
            }
            catch (Exception exception)
            {
                InsightLogger.Exception(exception.Message, exception, callerMethodName);
                //LoggerHelper.WriteToLog(exception + " - Error in BL while adding userbackends : "
                //+exception.ToString(), CoreConstants.Priority.High, CoreConstants.Category.Error);
                throw new BusinessLogicException();
            }
        }