public DBLogHistory gettingDetailsOfIncident(int pstrLogId) { WinMonitorEntityModelContext contextObj = new WinMonitorEntityModelContext(); DBLogHistory historyObj = new DBLogHistory(); historyObj = (from history in contextObj.DBLogHistories where history.DBLogId == pstrLogId select history).First(); return(historyObj); }
//function to get expected end date public DummyClassToGetExpectedEndTime gettingExpectedEndTime(int componentId) { DummyClassToGetExpectedEndTime dummyObj = new DummyClassToGetExpectedEndTime(); WinMonitorEntityModelContext contextObj = new WinMonitorEntityModelContext(); DBIncident incidentObj = new DBIncident(); DBLogHistory historyObj = new DBLogHistory(); incidentObj = contextObj.Database.SqlQuery <DBIncident>("select * from DBIncidents where DBCSId='" + componentId + "';").First(); historyObj = contextObj.Database.SqlQuery <DBLogHistory>("select * from DBLogHistory where DBIncidentId='" + incidentObj.DBIncidentId + "';").Last(); if (incidentObj.DBExpectedDuration != null) { dummyObj.expectedEndpresentOrNot = true; dummyObj.expectedEndDate = contextObj.Database.SqlQuery <DateTime>("select DATEADD(hour, " + incidentObj.DBExpectedDuration + ", '" + historyObj.DBDateTimeStart + "')").First(); } else { dummyObj.expectedEndpresentOrNot = false; dummyObj.expectedEndDate = null; } return(dummyObj); }
//method to delete existing incident of particular element public void deletingExistingIncidentOfComponent(int pstrComponentId, int pstrCompanyId) { WinMonitorEntityModelContext contextObj = new WinMonitorEntityModelContext(); DBIncident incidentObj = new DBIncident(); DBComponent_With_Status componentObj = new DBComponent_With_Status(); DBLogHistory historyObj = new DBLogHistory(); componentObj = (from component in contextObj.DBComponent_With_Status where component.DBCSId == pstrComponentId select component).FirstOrDefault(); incidentObj = (from incident in contextObj.DBIncidents where incident.DBCSId == pstrComponentId select incident).FirstOrDefault(); historyObj = (from log in contextObj.DBLogHistories where ((log.DBCompanyId == pstrCompanyId) && (log.DBCSId == pstrComponentId) && (log.DBDateTimeEnd == null)) select log).Last(); historyObj.DBDateTimeStart = DateTime.UtcNow;; contextObj.SaveChanges(); contextObj.DBIncidents.Remove(incidentObj); contextObj.SaveChanges(); }
public List <DummyPerformance> gettingEventTimeStored(int pstrComponentId, int eventStartOffset, int eventEndOffset, string pstrRecentOrNot) { WinMonitorEntityModelContext contextObj = new WinMonitorEntityModelContext(); DBLogHistory lastHistoryObj = new DBLogHistory(); DateTime nowTime = DateTime.UtcNow; DateTime eventStart, eventEnd; if (pstrRecentOrNot == "true") { if (((nowTime.Day + eventStartOffset) <= 0) || ((nowTime.Day + eventEndOffset) <= 0)) { eventStart = nowTime.AddDays(eventStartOffset); eventEnd = nowTime.AddDays(eventEndOffset); } else { eventStart = new DateTime(nowTime.Year, nowTime.Month, nowTime.Day + eventStartOffset, nowTime.Hour, nowTime.Minute, nowTime.Second); eventEnd = new DateTime(nowTime.Year, nowTime.Month, nowTime.Day + eventEndOffset, nowTime.Hour, nowTime.Minute, nowTime.Second); } } else { if (((nowTime.Day + eventStartOffset) <= 0) || ((nowTime.Day + eventEndOffset) <= 0)) { eventStart = nowTime.AddDays(eventStartOffset); eventEnd = nowTime.AddDays(eventEndOffset); eventStart = new DateTime(eventStart.Year, eventStart.Month, eventStart.Day, 0, 0, 0); eventEnd = new DateTime(eventEnd.Year, eventEnd.Month, eventEnd.Day, 0, 0, 0); } else { eventStart = new DateTime(nowTime.Year, nowTime.Month, nowTime.Day + eventStartOffset, 0, 0, 0); eventEnd = new DateTime(nowTime.Year, nowTime.Month, nowTime.Day + eventEndOffset, 0, 0, 0); } } List <DummyPerformance> listPerformance = new List <DummyPerformance>(); DummyPerformance performanceObj; int a = 0; List <DBLogHistory> listHistory = new List <DBLogHistory>(); listHistory = (from historyObj in contextObj.DBLogHistories where ((historyObj.DBCSId == pstrComponentId) && (eventStart <= historyObj.DBDateTimeStart) && (historyObj.DBDateTimeStart <= eventEnd) && (historyObj.DBStatus != "Operational")) select historyObj).ToList(); if (listHistory.Count > 0) { performanceObj = new DummyPerformance(); a = (contextObj.GetDateDiffInSec(eventStart, listHistory[0].DBDateTimeStart).First()).Value; performanceObj.mLogId = -1; performanceObj.mDiff = a; performanceObj.mStatus = "Operational"; listPerformance.Add(performanceObj); int i; DateTime?lastInList = DateTime.UtcNow; for (i = 0; i < listHistory.Count; i++) { if (listHistory[i].DBDateTimeEnd != null) { performanceObj = new DummyPerformance(); a = (contextObj.GetDateDiffInSec(listHistory[i].DBDateTimeStart, listHistory[i].DBDateTimeEnd).First()).Value; performanceObj.mLogId = listHistory[i].DBLogId; performanceObj.mDiff = a; performanceObj.mStatus = listHistory[i].DBStatus; listPerformance.Add(performanceObj); if (i != listHistory.Count - 1) { performanceObj = new DummyPerformance(); a = (contextObj.GetDateDiffInSec(listHistory[i].DBDateTimeEnd, listHistory[i + 1].DBDateTimeStart).First()).Value; performanceObj.mLogId = -1; performanceObj.mDiff = a; performanceObj.mStatus = "Operational"; listPerformance.Add(performanceObj); } else { lastInList = listHistory[i].DBDateTimeEnd; performanceObj = new DummyPerformance(); a = (contextObj.GetDateDiffInSec(lastInList, eventEnd).First()).Value; performanceObj.mLogId = -1; performanceObj.mDiff = a; performanceObj.mStatus = "Operational"; listPerformance.Add(performanceObj); } } else { performanceObj = new DummyPerformance(); a = (contextObj.GetDateDiffInSec(listHistory[i].DBDateTimeStart, eventEnd).First()).Value; performanceObj.mLogId = listHistory[i].DBLogId; performanceObj.mDiff = a; performanceObj.mStatus = listHistory[i].DBStatus; listPerformance.Add(performanceObj); } } } else { performanceObj = new DummyPerformance(); a = (contextObj.GetDateDiffInSec(eventStart, eventEnd).First()).Value; performanceObj.mLogId = -1; performanceObj.mDiff = a; performanceObj.mStatus = "Operational"; listPerformance.Add(performanceObj); } return(listPerformance); }
//method to delete selected components public void DeleteSelectedComponents(List <int> pListOfComponents, int pCompanyId) { WinMonitorEntityModelContext contextObj = new WinMonitorEntityModelContext(); foreach (int componentId in pListOfComponents) { DBIncident incidentObj = new DBIncident(); DBLogHistory historyObj = new DBLogHistory(); DBComponent_With_Status componentObj = new DBComponent_With_Status(); int incidentIdStoringVariable = -1; incidentObj = (from incident in contextObj.DBIncidents where incident.DBCSId == componentId select incident).FirstOrDefault(); componentObj = (from component in contextObj.DBComponent_With_Status where component.DBCSId == componentId select component).FirstOrDefault(); if (incidentObj != null) { incidentIdStoringVariable = incidentObj.DBIncidentId; //Adding log history historyObj.DBCompanyId = pCompanyId; historyObj.DBComponentName = componentObj.DBComponentName; historyObj.DBCSId = componentObj.DBCSId; historyObj.DBDateTimeStart = DateTime.UtcNow;; historyObj.DBIncidentId = incidentIdStoringVariable; historyObj.DBDateTimeEnd = null; historyObj.DBIncidentDetails = "Incident Deleted"; historyObj.DBIncidentName = incidentObj.DBIncidentName; historyObj.DBLogId = getseqDBLogId(); historyObj.DBStatus = "Operational"; contextObj.DBLogHistories.Add(historyObj); contextObj.SaveChanges(); contextObj.DBIncidents.Remove(incidentObj); contextObj.SaveChanges(); } else { historyObj = new DBLogHistory(); //Adding log history historyObj.DBCompanyId = pCompanyId; historyObj.DBComponentName = componentObj.DBComponentName; historyObj.DBCSId = componentObj.DBCSId; historyObj.DBDateTimeStart = DateTime.UtcNow;; historyObj.DBDateTimeEnd = null; historyObj.DBIncidentId = incidentIdStoringVariable; historyObj.DBIncidentDetails = "Component Deleted"; historyObj.DBIncidentName = "Component Deleted"; historyObj.DBLogId = getseqDBLogId(); historyObj.DBStatus = "Operational"; contextObj.DBLogHistories.Add(historyObj); contextObj.SaveChanges(); } contextObj.DBComponent_With_Status.Remove(componentObj); contextObj.SaveChanges(); } }
//Method to add master component to component list of company in database public string AddComponentToDb(List <string> pMasterComponentListFromPage, int pCompanyId, string pPrimaryDataCenter) { WinMonitorEntityModelContext contextObj = new WinMonitorEntityModelContext(); try { foreach (string masterComponentName in pMasterComponentListFromPage) { DBComponent_With_Status component = new DBComponent_With_Status(); DBLogHistory historyObj = new DBLogHistory(); component.DBCSId = getseqDBCSId(); component.DBComponentName = masterComponentName; component.DBStatus = "Operational"; component.DBType = "master"; component.DBCompanyId = pCompanyId; component.DBMasterComponentName = masterComponentName; component.DBCenterName = pPrimaryDataCenter; //adding master component to db contextObj.DBComponent_With_Status.Add(component); contextObj.SaveChanges(); //code to add details to log hisory historyObj.DBLogId = getseqDBLogId(); historyObj.DBCompanyId = pCompanyId; historyObj.DBCSId = component.DBCSId; historyObj.DBIncidentId = -1; historyObj.DBComponentName = component.DBComponentName; historyObj.DBIncidentName = ""; historyObj.DBIncidentDetails = ""; historyObj.DBDateTimeStart = DateTime.UtcNow;; historyObj.DBStatus = component.DBStatus; historyObj.DBDateTimeEnd = null; //adds history obj to database contextObj.DBLogHistories.Add(historyObj); contextObj.SaveChanges(); } return("Master Component added added !!"); } catch (DbUpdateException exUpdateDB) { Console.Write(exUpdateDB); return("DbUpdateException"); } catch (DbEntityValidationException exEntityValidateDB) { Console.Write(exEntityValidateDB); return("DbEntityValidationException"); } catch (NotSupportedException exNotSupportedDB) { Console.Write(exNotSupportedDB); return("NotSupportedException"); } catch (ObjectDisposedException exObjectDisposedDB) { Console.Write(exObjectDisposedDB); return("ObjectDisposedException"); } catch (InvalidOperationException exInvalidOperationDB) { Console.Write(exInvalidOperationDB); return("InvalidOperationException"); } }
//Incidents Save details method public string mSaveAddIncidentDetails(string pstringIncidentName, string pstringIncidentDetails, List <int> pstringComponentIdList, int pCompanyId) { try { WinMonitorEntityModelContext mDBContext = new WinMonitorEntityModelContext(); DBIncident mDBIncidentObj = new DBIncident(); DBLogHistory historyObj = new DBLogHistory(); foreach (int componentId in pstringComponentIdList) { mDBIncidentObj.DBIncidentId = getseqDBIncidentId(); mDBIncidentObj.DBIncidentName = pstringIncidentName; mDBIncidentObj.DBDescription = pstringIncidentDetails; mDBIncidentObj.DBCSId = componentId; //adds new incident to the incidents table mDBContext.DBIncidents.Add(mDBIncidentObj); mDBContext.SaveChanges(); //code to add details to log hisory historyObj.DBLogId = getseqDBLogId(); historyObj.DBCompanyId = pCompanyId; historyObj.DBCSId = componentId; historyObj.DBIncidentId = mDBIncidentObj.DBIncidentId; historyObj.DBComponentName = mDBContext.Database.SqlQuery <string>("select DBComponentName from DBComponent_With_Status where DBCSId=" + componentId + ";").FirstOrDefault(); historyObj.DBIncidentName = mDBIncidentObj.DBIncidentName; historyObj.DBIncidentDetails = mDBIncidentObj.DBDescription; historyObj.DBDateTimeStart = DateTime.UtcNow;; historyObj.DBStatus = mDBContext.Database.SqlQuery <string>("select DBStatus from DBComponent_With_Status where DBCSId=" + componentId + ";").FirstOrDefault(); historyObj.DBDateTimeEnd = null; //adds history obj to database mDBContext.DBLogHistories.Add(historyObj); //save the specific component details to the database mDBContext.SaveChanges(); } return("Incident Successfully added !!"); } catch (DbUpdateException exUpdateDB) { Console.Write(exUpdateDB); return("DbUpdateException"); } catch (DbEntityValidationException exEntityValidateDB) { Console.Write(exEntityValidateDB); return("DbEntityValidationException"); } catch (NotSupportedException exNotSupportedDB) { Console.Write(exNotSupportedDB); return("NotSupportedException"); } catch (ObjectDisposedException exObjectDisposedDB) { Console.Write(exObjectDisposedDB); return("ObjectDisposedException"); } catch (InvalidOperationException exInvalidOperationDB) { Console.Write(exInvalidOperationDB); return("InvalidOperationException"); } catch (Exception ex) { Console.Write(ex); return("Misllaneous Exception"); } }
//update staus of selected components public string UpdatingStatusOfComponentsSelected(List <int> pselectedComponentList, string pStatusToBeChanged, int pCompanyId) { try { WinMonitorEntityModelContext contextObj = new WinMonitorEntityModelContext(); DBLogHistory historyObj = new DBLogHistory(); DBCompany companyObj = new DBCompany(); string previousStatus; companyObj = (from company in contextObj.DBCompanies where company.DBCompanyId == pCompanyId select company).FirstOrDefault(); string strResult = String.Empty; if (pStatusToBeChanged == "Operational") { foreach (int componentId in pselectedComponentList) { DBComponent_With_Status componentObj = new DBComponent_With_Status(); DBIncident incidentObj = new DBIncident(); componentObj = (from component in contextObj.DBComponent_With_Status where component.DBCSId == componentId select component).FirstOrDefault(); if (companyObj.DBSecondaryCenter != componentObj.DBCenterName) { incidentObj = (from incident in contextObj.DBIncidents where incident.DBCSId == componentId select incident).FirstOrDefault(); if (incidentObj != null) { historyObj = (from histObj in contextObj.DBLogHistories where ((histObj.DBCompanyId == pCompanyId) && (histObj.DBCSId == componentId) && (histObj.DBIncidentId == incidentObj.DBIncidentId)) orderby histObj.DBDateTimeStart descending, histObj.DBDateTimeEnd descending select histObj).First(); historyObj.DBDateTimeEnd = DateTime.UtcNow;; contextObj.SaveChanges(); contextObj.DBIncidents.Remove(incidentObj); contextObj.SaveChanges(); } componentObj.DBStatus = pStatusToBeChanged; contextObj.SaveChanges(); } List <DBSubscription> subscriptionObjList = new List <DBSubscription>(); subscriptionObjList = (from subObj in contextObj.DBSubscriptions where subObj.DBCompanyId == pCompanyId select subObj).ToList(); DBEmailPage emailPageObj = new DBEmailPage(); emailPageObj = (from emailPage in contextObj.DBEmailPages where emailPage.DBEmailPageId == 1 select emailPage).FirstOrDefault(); foreach (DBSubscription subscriptionObj in subscriptionObjList) { PerformSubscription performSubscriptionObj = new PerformSubscription(); WebClient clientObj = new WebClient(); int endIndex, startIndex; string stringToBeReplaced; string stringHtml = emailPageObj.DBEmailContent.ToString(); endIndex = stringHtml.IndexOf("<!--end of eventsUpdateDiv-->"); startIndex = stringHtml.IndexOf("<div id=\"divForEvents\">"); stringToBeReplaced = stringHtml.Substring(startIndex, endIndex - startIndex); stringHtml = stringHtml.Replace(stringToBeReplaced, ""); endIndex = stringHtml.IndexOf("<!--end of dataCenterChangeUpdate-->"); startIndex = stringHtml.IndexOf("<div id=\"divForDataCenterUpdate\">"); stringToBeReplaced = stringHtml.Substring(startIndex, endIndex - startIndex); stringHtml = stringHtml.Replace(stringToBeReplaced, ""); string link = "http://cha-en-pdp2:2108/?pUserCompanyName=CompanyNameVariable"; //change url to direct to user page stringHtml = stringHtml.Replace("linkToBeChanged", link); stringHtml = stringHtml.Replace("CompanyNameVariable", companyObj.DBCompanyName); stringHtml = stringHtml.Replace("customerNameVariable", subscriptionObj.DBName); stringHtml = stringHtml.Replace("ComponentNameForStatusUpdateVariable", componentObj.DBComponentName); stringHtml = stringHtml.Replace("ComponentStatusUpdateVariable", componentObj.DBStatus); performSubscriptionObj.sendEmail(subscriptionObj.DBEmail, null, "Component Status Updated", stringHtml); } } strResult = "Incident Successfully deleted !!"; } else { foreach (int componentId in pselectedComponentList) { DBComponent_With_Status componentObj = new DBComponent_With_Status(); componentObj = (from component in contextObj.DBComponent_With_Status where component.DBCSId == componentId select component).FirstOrDefault(); previousStatus = componentObj.DBStatus; componentObj.DBStatus = pStatusToBeChanged; contextObj.SaveChanges(); DBIncident incidentObj = new DBIncident(); incidentObj = (from incident in contextObj.DBIncidents where incident.DBCSId == componentId select incident).FirstOrDefault(); //code to add details to log hisory historyObj.DBLogId = getseqDBLogId(); historyObj.DBCompanyId = pCompanyId; historyObj.DBCSId = componentId; historyObj.DBIncidentId = incidentObj.DBIncidentId; historyObj.DBComponentName = componentObj.DBComponentName; historyObj.DBIncidentName = incidentObj.DBIncidentName; historyObj.DBIncidentDetails = incidentObj.DBDescription; historyObj.DBDateTimeStart = DateTime.UtcNow;; historyObj.DBStatus = componentObj.DBStatus; historyObj.DBDateTimeEnd = null; List <DBSubscription> subscriptionObjList = new List <DBSubscription>(); subscriptionObjList = (from subObj in contextObj.DBSubscriptions where subObj.DBCompanyId == pCompanyId select subObj).ToList(); DBEmailPage emailPageObj = new DBEmailPage(); emailPageObj = (from emailPage in contextObj.DBEmailPages where emailPage.DBEmailPageId == 1 select emailPage).FirstOrDefault(); foreach (DBSubscription subscriptionObj in subscriptionObjList) { PerformSubscription performSubscriptionObj = new PerformSubscription(); WebClient clientObj = new WebClient(); int endIndex, startIndex; string stringToBeReplaced; string stringHtml = emailPageObj.DBEmailContent.ToString(); endIndex = stringHtml.IndexOf("<!--end of eventsUpdateDiv-->"); startIndex = stringHtml.IndexOf("<div id=\"divForEvents\">"); stringToBeReplaced = stringHtml.Substring(startIndex, endIndex - startIndex); stringHtml = stringHtml.Replace(stringToBeReplaced, ""); endIndex = stringHtml.IndexOf("<!--end of dataCenterChangeUpdate-->"); startIndex = stringHtml.IndexOf("<div id=\"divForDataCenterUpdate\">"); stringToBeReplaced = stringHtml.Substring(startIndex, endIndex - startIndex); stringHtml = stringHtml.Replace(stringToBeReplaced, ""); string link = "http://cha-en-pdp2:2108/?pUserCompanyName=CompanyNameVariable"; //change url to direct to user page stringHtml = stringHtml.Replace("linkToBeChanged", link); stringHtml = stringHtml.Replace("CompanyNameVariable", companyObj.DBCompanyName); stringHtml = stringHtml.Replace("customerNameVariable", subscriptionObj.DBName); stringHtml = stringHtml.Replace("ComponentNameForStatusUpdateVariable", componentObj.DBComponentName); stringHtml = stringHtml.Replace("ComponentStatusUpdateVariable", componentObj.DBStatus); performSubscriptionObj.sendEmail(subscriptionObj.DBEmail, null, "Component Status Updated", stringHtml); } } strResult = "Incident Successfully added !!"; } return(strResult); } catch (DbUpdateException exUpdateDB) { Console.Write(exUpdateDB); return("DbUpdateException"); } catch (DbEntityValidationException exEntityValidateDB) { Console.Write(exEntityValidateDB); return("DbEntityValidationException"); } catch (NotSupportedException exNotSupportedDB) { Console.Write(exNotSupportedDB); return("NotSupportedException"); } catch (ObjectDisposedException exObjectDisposedDB) { Console.Write(exObjectDisposedDB); return("ObjectDisposedException"); } catch (InvalidOperationException exInvalidOperationDB) { Console.Write(exInvalidOperationDB); return("InvalidOperationException"); } catch (Exception ex) { Console.Write(ex); return("Misllaneous Exception"); } }
//Specific Components Save details method public string mSaveAddSpecificComponentDetails(string pstringSpecificComponentName, string pstringSpecificComponentStatus, int pstringSpecificComponentCompanyId, string pstringSpecificComponentDataCenter) { try { WinMonitorEntityModelContext mDBContext = new WinMonitorEntityModelContext(); DBComponent_With_Status mDBSpecific_Component_With_StatusObj = new DBComponent_With_Status(); DBLogHistory mDBLogObj = new DBLogHistory(); mDBSpecific_Component_With_StatusObj.DBCSId = getseqDBCSId(); mDBSpecific_Component_With_StatusObj.DBComponentName = pstringSpecificComponentName; mDBSpecific_Component_With_StatusObj.DBStatus = pstringSpecificComponentStatus; mDBSpecific_Component_With_StatusObj.DBType = "Specific"; mDBSpecific_Component_With_StatusObj.DBCompanyId = pstringSpecificComponentCompanyId; mDBSpecific_Component_With_StatusObj.DBMasterComponentName = null; mDBSpecific_Component_With_StatusObj.DBCenterName = pstringSpecificComponentDataCenter; //adds new specific component to the components table mDBContext.DBComponent_With_Status.Add(mDBSpecific_Component_With_StatusObj); //save the specific component details to the database mDBContext.SaveChanges(); mDBLogObj.DBLogId = getseqDBLogId(); mDBLogObj.DBCompanyId = pstringSpecificComponentCompanyId; mDBLogObj.DBCSId = mDBSpecific_Component_With_StatusObj.DBCSId; mDBLogObj.DBIncidentId = -1; mDBLogObj.DBComponentName = mDBSpecific_Component_With_StatusObj.DBComponentName; mDBLogObj.DBIncidentName = ""; mDBLogObj.DBIncidentDetails = ""; mDBLogObj.DBDateTimeStart = DateTime.UtcNow;; mDBLogObj.DBStatus = pstringSpecificComponentStatus; mDBLogObj.DBDateTimeEnd = null; //adds component to log history mDBContext.DBLogHistories.Add(mDBLogObj); //save the log details to the database mDBContext.SaveChanges(); return("Specific Component Successfully added !!"); } catch (DbUpdateException exUpdateDB) { Console.Write(exUpdateDB); return("DbUpdateException"); } catch (DbEntityValidationException exEntityValidateDB) { Console.Write(exEntityValidateDB); return("DbEntityValidationException"); } catch (NotSupportedException exNotSupportedDB) { Console.Write(exNotSupportedDB); return("NotSupportedException"); } catch (ObjectDisposedException exObjectDisposedDB) { Console.Write(exObjectDisposedDB); return("ObjectDisposedException"); } catch (InvalidOperationException exInvalidOperationDB) { Console.Write(exInvalidOperationDB); return("InvalidOperationException"); } catch (Exception ex) { Console.Write(ex); return("Misllaneous Exception"); } }