/// <summary> /// method to delete single userbackend /// </summary> /// <param name="userID">takes userid as input</param> /// <param name="userBackendID">takes user backend id as input</param> /// <returns>returns deleted user backend entity</returns> public UserBackendEntity DeleteUserBackend(string userID, string userBackendID) { string callerMethodName = string.Empty; try { //Get Caller Method name from CallerInformation class callerMethodName = CallerInformation.TrackCallerMethodName(); UserBackendDAL userbackenddal = new UserBackendDAL(); //calling data access layer method UserBackendEntity userbackendentity = userbackenddal.DeleteUserBackend(userID, userBackendID); return(userbackendentity); } catch (DataAccessException DALexception) { throw DALexception; } catch (Exception exception) { InsightLogger.Exception(exception.Message, exception, callerMethodName); //LoggerHelper.WriteToLog(exception + " - Error in BL while deleting single userbackend : " //+exception.ToString(), CoreConstants.Priority.High, CoreConstants.Category.Error); throw new BusinessLogicException(); } }
/// <summary> /// method to get list of backends associated to user /// </summary> /// <param name="userID">takes userid as input</param> /// <returns>returns list of userbackends</returns> public List <UserBackendEntity> GetUserBackendsList(string userID, List <string> userbackends) { string callerMethodName = string.Empty; try { //Get Caller Method name from CallerInformation class callerMethodName = CallerInformation.TrackCallerMethodName(); //if userbackendid's not provided get all associated backends to user by default if (userbackends != null) { SynchDAL synchdDAL = new SynchDAL(); //calling data access layer method return(synchdDAL.GetUserAllBackends(userID, userbackends)); } else { UserBackendDAL userbackenddal = new UserBackendDAL(); return(userbackenddal.GetUserAllBackends(userID)); } } catch (DataAccessException DALexception) { throw DALexception; } catch (Exception exception) { InsightLogger.Exception(exception.Message, exception, callerMethodName); //LoggerHelper.WriteToLog(exception + " - Error in BL while getting userbackend list per user : " //+ exception.ToString(), CoreConstants.Priority.High, CoreConstants.Category.Error); throw new BusinessLogicException(); } }
/// <summary> ///method to remove userbackends /// </summary> /// <param name="UserID">takes userid as input</param> public void RemoveBackends(string UserID) { string callerMethodName = string.Empty; try { //Get Caller Method name from CallerInformation class callerMethodName = CallerInformation.TrackCallerMethodName(); UserBackendDAL userbackenddal = new UserBackendDAL(); //to get all backends associated to user List <UserBackendEntity> alluserbackends = userbackenddal.GetUserAllBackends(UserID); if (alluserbackends != null && alluserbackends.Count > 0) { //calling data access layer method to remove user backends userbackenddal.RemoveBackends(alluserbackends); } } catch (DataAccessException DALexception) { throw DALexception; } catch (Exception exception) { InsightLogger.Exception(exception.Message, exception, callerMethodName); //LoggerHelper.WriteToLog(exception + " - Error in BL while removing userbackends : " //+exception.ToString(), CoreConstants.Priority.High, CoreConstants.Category.Error); throw new BusinessLogicException(); } }
/// <summary> /// This method triggered based on given time interval(i.e MyDailyScheduleForMissingUpdates) /// This method will verifies whether any userbackend(s)/Request(s) missed update or not /// if any user(s)/Request(s) misses update then keep the messages into update trigger input queue in UpdateTriggerMsg Format. /// </summary> public static void CollectMissingUpdates([TimerTrigger(typeof(MyDailyScheduleForMissingUpdates))] TimerInfo timerInfo, TextWriter log) { string callerMethodName = string.Empty; try { //Get Caller Method name from CallerInformation class callerMethodName = CallerInformation.TrackCallerMethodName(); // InsightLogger.TrackStartEvent(callerMethodName); //foreach backend NextUserCollectingTimeDAL objnextcollectingTime = new NextUserCollectingTimeDAL(); //get all the userbackends needs to update List <NextUserCollectingTimeEntity> lstbackends = objnextcollectingTime.GetBackendsNeedsUpdate(); DateTime currentTimestampForMissedUpdates = DateTime.Now; Parallel.ForEach <NextUserCollectingTimeEntity>(lstbackends, backend => { InsightLogger.TrackEvent("UpdateTriggering, Action :: for each backend :: collect missing updates : start() , Response :: Backend Name : " + backend.BackendID); //getting minutes difference between currenttime and Missing Update Next CollectingTime TimeSpan tspan = backend.MissingUpdateNextCollectingTime.Subtract(currentTimestampForMissedUpdates); int waitingMinutes = tspan.Minutes; //if minutes difference is with in RegularChecksWaitingTimeInMinutes(>=-8 and <=0) then invoke MissedUpdatesWaitingTimeInMinutes method() if (waitingMinutes >= -(Convert.ToInt32(ConfigurationManager.AppSettings["MissedUpdatesWaitingTimeInMinutes"])) && waitingMinutes <= 0) { UserBackendDAL objUserBackendDAL = new UserBackendDAL(); //collects the missed update userbackends,Requests and convert into update trigger message format and put into UT input queue objUserBackendDAL.CollectUsersMissedUpdatesByBackend(backend.BackendID, currentTimestampForMissedUpdates); //update the backend entity with new missing update collecting time[i.e MissingUpdateLastCollectingTime= MissingUpdateNextCollectingTime and MissingUpdateNextCollectingTime=Max(] objnextcollectingTime.UpdateMisseduserBackendNextCollectingTime(backend.BackendID, backend.MissingUpdateNextCollectingTime, DateTime.Now); InsightLogger.TrackEvent("UpdateTriggering, Action :: for each backend :: collect missing updates : End() , Response :: Success, Backend Name : " + backend.BackendID); } else { InsightLogger.TrackEvent("UpdateTriggering, Action :: for each backend :: collect missing updates : End(), Response :: next missing update collecting time of the backend [ " + backend.BackendID + " ] is greater-than to current time."); } }); } 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); } }
/// <summary> /// This method triggered based on given time interval(i.e MyDailyScheduleForRegularUpdates) /// This method will verifies whether the userbackends needs update or not based on UT RUle ,if it requires update then it will update the userbackend /// if any user needs update then keep the messages into update trigger input queue in UpdateTriggerMsg Format. /// </summary> public static void CollectUsersNeedsUpdate([TimerTrigger(typeof(MyDailyScheduleForRegularUpdates))] TimerInfo timerInfo, TextWriter log) { string callerMethodName = string.Empty; try { //Get Caller Method name from CallerInformation class callerMethodName = CallerInformation.TrackCallerMethodName(); NextUserCollectingTimeDAL objnextcollentingTime = new NextUserCollectingTimeDAL(); //get all the userbackends needs to update List <NextUserCollectingTimeEntity> lstbackends = objnextcollentingTime.GetBackendsNeedsUpdate(); //foreach backend DateTime currentTimestamp = DateTime.Now; Parallel.ForEach <NextUserCollectingTimeEntity>(lstbackends, backend => { InsightLogger.TrackEvent("UpdateTriggering, Action :: for each backend :: collect users needing update : start(), Response :: Backend Name : " + backend.BackendID); //getting minutes difference between currenttime and Regular Update Next CollectingTime TimeSpan span = backend.RegularUpdateNextCollectingTime.Subtract(currentTimestamp); int minutes = span.Minutes; //if minutes difference is with in RegularChecksWaitingTimeInMinutes(>=-5 and <=0) then invoke CollectUsersNeedUpdateByBackend method() if (minutes >= -(Convert.ToInt32(ConfigurationManager.AppSettings["RegularChecksWaitingTimeInMinutes"])) && minutes <= 0) { UserBackendDAL objdal = new UserBackendDAL(); //collect the users needing update and keep the messages in update trigger input queue objdal.CollectUsersNeedUpdateByBackend(backend.BackendID, currentTimestamp); //update the backend entity with new collecting time[i.e LastCollectingTime= NextCollectingTime and NextCollectingTime=NextCollectingTime+(Backend MinimumusersUpdateFrequency)/2 ] objnextcollentingTime.UpdateBackendRegularNextCollectingTime(backend.BackendID, backend.MinimumUpdateFrequency, backend.RegularUpdateNextCollectingTime); InsightLogger.TrackEvent("UpdateTriggering, Action :: for each backend :: collect users needing update : End(), Response :: Success, Backend Name : " + backend.BackendID); } else { InsightLogger.TrackEvent("UpdateTriggering, Action :: for each backend :: collect users needing update : End(), Response :: next collecting time of the backend [ " + backend.BackendID + " ] is greater-than to current time."); } }); } 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 Access Exception into application insights InsightLogger.Exception(dalexception.Message, dalexception, callerMethodName); } catch (Exception exception) { // log.WriteLine("Error in adidas.clb.job.UpdateTriggering :: Functions :: RegularChecksforBackendNeedsUpdate() :: Exception Message=" + exception.Message); //write exception into application insights InsightLogger.Exception(exception.Message, exception, callerMethodName); } }
/// <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); } }
/// <summary> /// method to get all userbackends /// </summary> /// <param name="UserID">takes userid as input</param> /// <returns>returns list of user backend</returns> public IEnumerable <UserBackendDTO> GetUserAllBackends(string UserID) { string callerMethodName = string.Empty; try { //Get Caller Method name from CallerInformation class callerMethodName = CallerInformation.TrackCallerMethodName(); UserBackendDAL userbackenddal = new UserBackendDAL(); //calling data access layer method to get user backends List <UserBackendEntity> alluserbackends = userbackenddal.GetUserAllBackends(UserID); //calling data access layer method to get user backend synch List <SynchEntity> allbackendsynch = userbackenddal.GetAllUserBackendsSynch(UserID); List <UserBackendDTO> userbackendsdtolist = new List <UserBackendDTO>(); //check for null if (alluserbackends != null && alluserbackends.Count > 0) { //converting userdevice entity to userdevice data transfer object foreach (UserBackendEntity userbackendentity in alluserbackends) { UserBackendDTO userbackenddto = UserBackendEntityDTOMapper(userbackendentity); SynchEntity synchentity = allbackendsynch.Where(m => m.RowKey.Equals(userbackendentity.BackendID)).FirstOrDefault(); //if user backend synch available then convert to dto if (synchentity != null) { SynchDTO synchdto = DataProvider.ResponseObjectMapper <SynchDTO, SynchEntity>(synchentity); userbackenddto.synch = synchdto; } userbackendsdtolist.Add(userbackenddto); } } else { userbackendsdtolist = null; } return((IEnumerable <UserBackendDTO>)userbackendsdtolist); } catch (DataAccessException DALexception) { throw DALexception; } catch (Exception exception) { InsightLogger.Exception(exception.Message, exception, callerMethodName); //LoggerHelper.WriteToLog(exception + " - Error in BL while retreiving userbackends : " //+exception.ToString(), CoreConstants.Priority.High, CoreConstants.Category.Error); throw new BusinessLogicException(); } }
/// <summary> /// method to calculate sync waiting time /// </summary> /// <param name="Backendtouser">takes backends associated to user</param> /// <returns>returns synch waiting time</returns> public int CalcSynchTime(IEnumerable <UserBackendEntity> Userbackends) { UserBackendDAL userBackenddal = new UserBackendDAL(); //calling data access layer method to backend entities IEnumerable <BackendEntity> Backendtouser = userBackenddal.GetRequiredBackends(Userbackends); //calling rules to caliculate synch time if (Backendtouser != null) { return(Rules.SynchWaitingTime(Backendtouser));; } else { return(0); } }
/// <summary> /// method to get single userbackend /// </summary> /// <param name="userID">takes userid as input</param> /// <param name="userBackendID">takes user backend id as input</param> /// <returns>returns user backend with id associated to user in the form of personalization response</returns> public PersonalizationResponseDTO <UserBackendDTO> GetUserBackend(string userID, string userBackendID) { string callerMethodName = string.Empty; try { //Get Caller Method name from CallerInformation class callerMethodName = CallerInformation.TrackCallerMethodName(); UserBackendDAL userbackenddal = new UserBackendDAL(); UserBackendEntity userbackendentity = userbackenddal.GetUserBackend(userID, userBackendID); SynchEntity synch = userbackenddal.GetBackendSynch(userID, userBackendID); //converting userbackend entity to Response data transfer object var ResponseUserBackend = new PersonalizationResponseDTO <UserBackendDTO>(); ///check for null if (userbackendentity != null) { UserBackendDTO userbackenddto = UserBackendEntityDTOMapper(userbackendentity); //adding synch to user backend if (synch != null) { SynchDTO synchdto = DataProvider.ResponseObjectMapper <SynchDTO, SynchEntity>(synch); userbackenddto.synch = synchdto; } ResponseUserBackend.result = userbackenddto; } else { ResponseUserBackend.result = null; } return(ResponseUserBackend); } catch (DataAccessException DALexception) { throw DALexception; } catch (Exception exception) { InsightLogger.Exception(exception.Message, exception, callerMethodName); //LoggerHelper.WriteToLog(exception + " - Error in BL while retreiving single userbackend : " //+exception.ToString(), CoreConstants.Priority.High, CoreConstants.Category.Error); throw new BusinessLogicException(); } }
/// <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(); } }
/// <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(); } }
/// <summary> ///method to add userbackends /// </summary> /// <param name="Backendtouser">takes list of user backends as input</param> public void AddBackends(List <UserBackendEntity> Backendtouser) { string callerMethodName = string.Empty; try { //Get Caller Method name from CallerInformation class callerMethodName = CallerInformation.TrackCallerMethodName(); UserBackendDAL userbackenddal = new UserBackendDAL(); //calling data access layer method userbackenddal.AddBackends(Backendtouser); } 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(); } }
// This function will get triggered/executed when a new message is written // on an Azure Queue called queue. /// <summary> /// This method automatically triggered when ever a new message inserted into queue. /// </summary> public static void ProcessQueueMessage([QueueTrigger("%utQueue%")] string message, TextWriter log) { //Get Caller Method name string callerMethodName = string.Empty; try { //Get Caller Method name from CallerInformation class callerMethodName = CallerInformation.TrackCallerMethodName(); string queueName = Convert.ToString(ConfigurationManager.AppSettings["UpdateTriggerInputQueue"]); // InsightLogger.TrackStartEvent(callerMethodName); //checking update triggering queue message null or empty if (!string.IsNullOrEmpty(message)) { //log.WriteLine("adidas.clb.job.UpdateTriggering :: Processing update triggering queue message :: start()" + message); //write message into application insights InsightLogger.TrackEvent(queueName + " , Action :: UpdateTriggering input queue triggered : Start(), \n Response :: Message:" + message); //Deserializ input queue message into UpdateTriggeringMsg object UpdateTriggeringMsg objUTMsg = JsonConvert.DeserializeObject <UpdateTriggeringMsg>(message); //checking UpdateTriggeringMsg is null or not if (objUTMsg != null) { //get userupdateMsg list from UpdateTriggeringMsg List <UserUpdateMsg> lstUsers = null; //checking users list in UpdateTriggeringMsg null or not if (objUTMsg.Users != null) { lstUsers = objUTMsg.Users.ToList(); InsightLogger.TrackEvent(queueName + " , Action :: Users Provided? , Response :: true "); } //get RequestUpdateMsg list from UpdateTriggeringMsg List <RequestUpdateMsg> lstRequests = null; //checking request list in UpdateTriggeringMsg null or not if (objUTMsg.Requests != null) { lstRequests = objUTMsg.Requests.ToList(); InsightLogger.TrackEvent(queueName + " , Action :: Requests Provided? , Response :: true "); } //Declare a CancellationToken object, which indicates whether cancellation is requested var ctsut = new CancellationTokenSource(); //create object for userbackend class for calling the Updateusers & updateRequest methods UserBackendDAL objUserbackendDAL = new UserBackendDAL(); //Parallely update the user update and request update messages from UserUpdateMsg. Task[] tasksProcessQueueMsg = new Task[2]; //Process users update messages tasksProcessQueueMsg[0] = Task.Factory.StartNew(() => objUserbackendDAL.UpdateUserBackends(lstUsers, objUTMsg.VIP, objUTMsg.GetPDFs, objUTMsg.ChangeAfter, queueName)); //Process request update Messages tasksProcessQueueMsg[1] = Task.Factory.StartNew(() => objUserbackendDAL.UpdateRequests(lstRequests, objUTMsg.VIP, objUTMsg.GetPDFs, objUTMsg.ChangeAfter, queueName)); //create processTimeoutperiod variable and assign the value from app.config file int processTimeoutperiod = Convert.ToInt32(CloudConfigurationManager.GetSetting("timeoutperiod")); //if all the tasks which are not completed with in the timeout period then those task automatically canceled by CancellationToken object cancel method. if (!Task.WaitAll(tasksProcessQueueMsg, processTimeoutperiod, ctsut.Token)) { //Communicates a request for cancellation ctsut.Cancel(); } //log.WriteLine("adidas.clb.job.UpdateTriggering :: Processing update triggering queue message :: End()" + message); //write message into application insights InsightLogger.TrackEvent(queueName + " , Action :: UpdateTriggering input queue triggered : End()"); } else { InsightLogger.TrackEvent(queueName + " , Action :: update triggering message is null"); } } } catch (DataAccessException dalexception) { //write exception message to web job dashboard logs //log.WriteLine(dalexception.Message); //write exception into application insights InsightLogger.Exception(dalexception.Message, dalexception, callerMethodName); } catch (Exception exception) { //write exception message to web job dashboard logs // log.WriteLine(exception.Message); //write exception into application insights InsightLogger.Exception(exception.Message, exception, callerMethodName); } }
public NextUserCollectingTimeDAL() { objdal = new UserBackendDAL(); utRules = new UpdateTriggeringRules(); }