/// <summary> /// method to get backend entity /// </summary> /// <param name="backendid">takes backend id as input</param> /// <returns>returns backend entity</returns> public BackendEntity Getbackend(string backendid) { RequestUpdateDAL requestupdatedal = new RequestUpdateDAL(); //calling dal method to get backend entity to be updated BackendEntity backend = requestupdatedal.GetBackend(backendid); return(backend); }
/// <summary> /// method to caliculate average sizes and latencies to update in userbackend /// </summary> /// <param name="BackendId">takes backendid as input</param> /// <param name="Totalrequestssize">takes totalrequestsize as input</param> /// <param name="TotalRequestlatency">takes total request latency as input</param> /// <param name="requestscount">takes request count as input</param> public void UpdateBackend(BackendEntity backend, int Totalrequestssize, int TotalRequestlatency, int requestscount) { //Get Caller Method name string callerMethodName = string.Empty; try { //Get Caller Method name from CallerInformation class callerMethodName = CallerInformation.TrackCallerMethodName(); //if request count more than one. if (requestscount > 0) { //updating average, last request sizes for backend backend.AverageRequestSize = GetAverage(backend.AverageRequestSize, backend.TotalRequestsCount, Totalrequestssize, requestscount); backend.LastRequestSize = Convert.ToInt32(Totalrequestssize / requestscount); //updating average, last request latencies for backend InsightLogger.TrackEvent("RequestUpdateWebJob :: method : requestupdate queue trigger, action:caliculate backend tracking variables, existing AverageRequestLatency:" + backend.AverageRequestLatency + " TotalRequestsLatency: " + TotalRequestlatency + " requsetcount: " + requestscount); backend.AverageRequestLatency = GetAverage(backend.AverageRequestLatency, backend.TotalRequestsCount, TotalRequestlatency, requestscount); InsightLogger.TrackEvent("RequestUpdateWebJob :: method : requestupdate queue trigger, action:caliculate backend tracking variables, current AverageRequestLatency:" + backend.AverageRequestLatency); InsightLogger.TrackEvent("RequestUpdateWebJob :: method : requestupdate queue trigger, action:caliculate backend tracking variables, existing AverageALLRequestLatency:" + backend.AverageAllRequestsLatency + " TotalBatchRequestsCount: " + backend.TotalBatchRequestsCount + " TotalRequestsLatency: " + TotalRequestlatency + " requsetcount: " + requestscount); backend.AverageAllRequestsLatency = GetAverage(backend.AverageAllRequestsLatency, backend.TotalBatchRequestsCount, TotalRequestlatency, requestscount); InsightLogger.TrackEvent("RequestUpdateWebJob :: method : requestupdate queue trigger, action:caliculate backend tracking variables, current AverageAllRequestsLatency:" + backend.AverageAllRequestsLatency); backend.LastRequestLatency = Convert.ToInt32(TotalRequestlatency / requestscount); InsightLogger.TrackEvent("RequestUpdateWebJob :: method : requestupdate queue trigger, action:caliculate backend tracking variables, current LastRequestLatency:" + backend.LastRequestLatency); backend.LastAllRequestsLatency = TotalRequestlatency; InsightLogger.TrackEvent("RequestUpdateWebJob :: method : requestupdate queue trigger, action:caliculate backend tracking variables, current LastAllRequestsLatency:" + backend.LastAllRequestsLatency); //updaing total requests per userbackend and total request batches/messages per userbackend backend.TotalRequestsCount = backend.TotalRequestsCount + requestscount; backend.TotalBatchRequestsCount = backend.TotalBatchRequestsCount + 1; } //calling DAL method to update backend entity RequestUpdateDAL requestupdatedal = new RequestUpdateDAL(); requestupdatedal.UpdateBackend(backend); } catch (DataAccessException DALexception) { throw DALexception; } catch (Exception exception) { //write exception into application insights InsightLogger.Exception(exception.Message + " - Error in BL while updating backend", exception, callerMethodName); throw new BusinessLogicException(); } }
/// <summary> /// method to update backend /// </summary> /// <param name="backend">takes backend entity as input</param> public void UpdateBackend(BackendEntity backend) { //Get Caller Method name string callerMethodName = string.Empty; try { //Get Caller Method name from CallerInformation class callerMethodName = CallerInformation.TrackCallerMethodName(); //call dataprovider method to update entity to azure table DataProvider.UpdateEntity <BackendEntity>(CoreConstants.AzureTables.ReferenceData, backend); } catch (Exception exception) { //write exception into application insights InsightLogger.Exception(exception.Message + " - Error while updating backend to azure table in DAL", exception, callerMethodName); throw new DataAccessException(); } }
/// <summary> /// method to get backend entity /// </summary> /// <param name="backendid">tackes backendId as input</param> /// <returns>returns backend entity</returns> public BackendEntity GetBackend(string backendid) { //Get Caller Method name string callerMethodName = string.Empty; try { //Get Caller Method name from CallerInformation class callerMethodName = CallerInformation.TrackCallerMethodName(); //call dataprovider method to retrieve entity from azure table BackendEntity backend = DataProvider.Retrieveentity <BackendEntity>(CoreConstants.AzureTables.ReferenceData, CoreConstants.AzureTables.BackendPK, backendid); return(backend); } catch (Exception exception) { //write exception into application insights InsightLogger.Exception(exception.Message + " - Error while getting backend from azure table in DAL", exception, callerMethodName); throw new DataAccessException(); } }
/// <summary> /// update Next CollectingTime of the backend which missed updates /// </summary> /// <param name="backendID"></param> /// <param name="missingUpdateLastCollectingTime"></param> /// <param name="avgAllRequestsLatency"></param> /// <param name="lastAllRequestsLatency"></param> public void UpdateMisseduserBackendNextCollectingTime(string backendID, DateTime missingUpdateLastCollectingTime, DateTime currTimestamp) { string callerMethodName = string.Empty; try { //Get Caller Method name from CallerInformation class callerMethodName = CallerInformation.TrackCallerMethodName(); // Create a retrieve operation that takes a NextUserCollectingTime Entity. NextUserCollectingTimeEntity ObjMissedUpdateNextCollectingTime = DataProvider.RetrieveEntity <NextUserCollectingTimeEntity>(azureTableReference, CoreConstants.AzureTables.UpdateTriggerNextCollectingTime, backendID); if (ObjMissedUpdateNextCollectingTime != null) { //get backend details by backendid from userconfiguration BackendEntity backendDetails = objdal.GetBackendDetailsByBackendID(backendID); if (backendDetails != null) { //update Missing Update Last CollectingTime with previous Missing Update NextCollectingTime ObjMissedUpdateNextCollectingTime.MissingUpdateLastCollectingTime = missingUpdateLastCollectingTime; //update Missing Update NextCollectingTime based on updatetriggering Rule R5 ObjMissedUpdateNextCollectingTime.MissingUpdateNextCollectingTime = utRules.GetNextMissingCollectingTime(currTimestamp, backendDetails.AverageAllRequestsLatency, backendDetails.LastAllRequestsLatency); // Execute update operation. DataProvider.UpdateEntity <NextUserCollectingTimeEntity>(azureTableReference, ObjMissedUpdateNextCollectingTime); InsightLogger.TrackEvent("UpdateTriggering, Action :: Set next missed update collecting time , Response :: Success, backend :[ " + 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); } }
// This function will get triggered/executed when a new message is written // on an Azure Queue called RequsetUpdate. public static void ProcessRequsetQueueMessage([QueueTrigger(CoreConstants.AzureQueues.RequsetUpdateQueue)] string message, TextWriter log) { //Get Caller Method name string callerMethodName = string.Empty; try { //Get Caller Method name from CallerInformation class callerMethodName = CallerInformation.TrackCallerMethodName(); InsightLogger.TrackEvent("RequestUpdateWebJob :: method : requestupdate queue trigger, action:Reading queue message, response:succuess, message: " + message); //deserialize Queue message to Requests RequestsUpdateData requestsdata = JsonConvert.DeserializeObject <RequestsUpdateData>(message); List <BackendRequest> backendrequestslist = requestsdata.Requests; RequestUpdateBL requsetupdatebl = new RequestUpdateBL(); //get backend to get missingconfirmationlimit for backend and also to update flags BackendEntity backend = requsetupdatebl.Getbackend(requestsdata.BackendID); int TotalRequestsize = 0; int TotalRequestlatency = 0; int requestcount = backendrequestslist.Count; //check if requests were available if (backendrequestslist != null && backendrequestslist.Count > 0) { //looping through each backendrequest to add requests , approvers and fields for each requet InsightLogger.TrackEvent("RequestUpdateWebJob :: method : requestupdate queue trigger, action:looping all requests"); foreach (BackendRequest backendrequest in backendrequestslist) { //split main backendrequest object into individual entities List <Approvers> approvers = backendrequest.RequestsList.Approvers; List <Field> genericInfoFields = backendrequest.RequestsList.Fields.GenericInfo; List <Field> overviewFields = backendrequest.RequestsList.Fields.Overview; Request request = backendrequest.RequestsList; //calling BL methods to add request , approval, approvers and fields if (!string.IsNullOrEmpty(request.UserID)) { InsightLogger.TrackEvent("RequestUpdateWebJob :: method : requestupdate queue trigger, action:clearing request waiting flag, response:success"); requsetupdatebl.AddUpdateRequest(backendrequest, request.UserID, requestsdata.BackendID); InsightLogger.TrackEvent("RequestUpdateWebJob :: method : requestupdate queue trigger, action:update request object, response:success, requestID:" + request.ID); requsetupdatebl.AddUpdateApproval(approvers, request.ID, backendrequest.RequestsList.UserID, requestsdata.BackendID, backend.MissingConfirmationsLimit, request.Title); InsightLogger.TrackEvent("RequestUpdateWebJob :: method : requestupdate queue trigger, action:update/remove/create approval object, response:success"); requsetupdatebl.AddUpdateApprovers(approvers, request.ID); requsetupdatebl.AddUpdateFields(genericInfoFields, overviewFields, request.ID); //caliculating request size int requestsize = requsetupdatebl.CalculateRequestSize(backendrequest); //caliculating total of size for all requests TotalRequestsize = TotalRequestsize + requestsize; //caliculating total of latency for all requests TotalRequestlatency = TotalRequestlatency + request.Latency; } } } InsightLogger.TrackEvent("RequestUpdateWebJob :: method : requestupdate queue trigger, action:looping all requests end"); //calling BL methods to update average sizes and latencies for userbackend and backend if (!string.IsNullOrEmpty(requestsdata.UserId)) { InsightLogger.TrackEvent("RequestUpdateWebJob :: method : requestupdate queue trigger, action:check user or request, response:user"); requsetupdatebl.UpdateUserBackend(requestsdata.UserId, requestsdata.BackendID, TotalRequestsize, TotalRequestlatency, requestcount); InsightLogger.TrackEvent("RequestUpdateWebJob :: method : requestupdate queue trigger, action:update userbackend tracking variables, response:success"); } InsightLogger.TrackEvent("RequestUpdateWebJob :: method : requestupdate queue trigger, action:update backend tracking variables, response:success, backendID:" + requestsdata.BackendID); requsetupdatebl.UpdateBackend(backend, TotalRequestsize, TotalRequestlatency, requestcount); InsightLogger.TrackEvent("RequestUpdateWebJob :: method : requestupdate queue trigger, action:end of the method"); } catch (DataAccessException dalexception) { //write message to web job dashboard logs log.WriteLine(dalexception.Message); } catch (BusinessLogicException blexception) { //write message to web job dashboard logs log.WriteLine(blexception.Message); } catch (Exception exception) { //write exception into application insights InsightLogger.Exception(exception.Message + " - Error in Queue trigger while processing request", exception, callerMethodName); log.WriteLine(exception.Message); } }