//method to change data center of components list selected
        public void ChangingDataCenter(List <int> mListOfCheckBoxes, int pstrCompanyId, string pstrDataCenterSelected)
        {
            WinMonitorEntityModelContext contextObj = new WinMonitorEntityModelContext();
            DBCompany companyObj = new DBCompany();

            companyObj = (from company in contextObj.DBCompanies
                          where company.DBCompanyId == pstrCompanyId
                          select company).FirstOrDefault();
            foreach (int componentId in mListOfCheckBoxes)
            {
                DBComponent_With_Status componentObj = new DBComponent_With_Status();
                componentObj = (from component in contextObj.DBComponent_With_Status
                                where component.DBCSId == componentId
                                select component).FirstOrDefault();
                componentObj.DBCenterName = pstrDataCenterSelected;
                contextObj.SaveChanges();
                List <DBSubscription> subscriptionObjList = new List <DBSubscription>();
                subscriptionObjList = (from subObj in contextObj.DBSubscriptions
                                       where subObj.DBCompanyId == pstrCompanyId
                                       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 componentStatusChangeDiv-->");
                    startIndex         = stringHtml.IndexOf("<div id=\"divForComponentStatusUpdate\">");
                    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("ComponentNameForDataCenterUpdateVariable", componentObj.DBComponentName);
                    stringHtml = stringHtml.Replace("DataCenterVariable", componentObj.DBCenterName);

                    performSubscriptionObj.sendEmail(subscriptionObj.DBEmail, null, "Data Center Updated", stringHtml);
                }
            }
        }
Пример #2
0
        //function to update events in Database
        public void UpdatingCalenderInDB(int pstrEventId, DateTime pstrNewEventStart, DateTime pstrNewEventEnd)
        {
            WinMonitorEntityModelContext contextObj = new WinMonitorEntityModelContext();
            DBCalendar calenderObj = new DBCalendar();

            calenderObj = (from calenderEvent in contextObj.DBCalendars
                           where calenderEvent.DBEventId == pstrEventId
                           select calenderEvent).FirstOrDefault();
            if (calenderObj.DBEventStatus == "Active")
            {
                calenderObj.DBEventStartTime = pstrNewEventStart;
                calenderObj.DBEventEndTime   = pstrNewEventEnd;
                contextObj.SaveChanges();
                DBCompany companyObj = new DBCompany();
                companyObj = (from company in contextObj.DBCompanies
                              where company.DBCompanyId == calenderObj.DBCompanyId
                              select company).FirstOrDefault();
                List <DBSubscription> subscriptionObjList = new List <DBSubscription>();
                subscriptionObjList = (from subObj in contextObj.DBSubscriptions
                                       where subObj.DBCompanyId == calenderObj.DBCompanyId
                                       select subObj).ToList();
                DBCalendar calEvent = new DBCalendar();
                calEvent = (from calObj in contextObj.DBCalendars
                            where calObj.DBEventId == pstrEventId
                            select calObj).FirstOrDefault();
                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 stringHtml = emailPageObj.DBEmailContent.ToString();

                    endIndex   = stringHtml.IndexOf("<!--end of componentUpdateDiv-->");
                    startIndex = stringHtml.IndexOf("<div id=\"divForComponentUpdates\">");
                    string 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("EventNameVariable", calEvent.DBEventTitle);
                    stringHtml = stringHtml.Replace("EventDetailsVariable", calEvent.DBEventDetails);
                    stringHtml = stringHtml.Replace("EventStartTimeVariable", calEvent.DBEventStartTime.ToString());
                    stringHtml = stringHtml.Replace("EventEndTimeVariable", calEvent.DBEventEndTime.ToString());
                    performSubscriptionObj.sendEmail(subscriptionObj.DBEmail, null, "Event Schedule Updated", stringHtml);
                }
            }
        }
Пример #3
0
        //Admin Maintenance Calendar

        //AddEVent In Calendar
        public string mSaveCalendarEvent(string pstrTitle, string pstrDetails, string pstrStartTime, string pstrEndTime, string pstrEventFor, string pstrMaintenance, int pstrCompanyId)
        {
            try
            {
                WinMonitorEntityModelContext mDBContext = new WinMonitorEntityModelContext();
                if (pstrEventFor == "all")
                {
                    List <DBCompany> companyList = new List <DBCompany>();
                    companyList = (from company in mDBContext.DBCompanies
                                   select company).ToList();
                    foreach (DBCompany companyObj in companyList)
                    {
                        DBCalendar CalObj = new DBCalendar();
                        CalObj.DBEventId      = getseqDBCalEventId();
                        CalObj.DBEventTitle   = pstrTitle;
                        CalObj.DBEventDetails = pstrDetails;

                        DateTime mdateStartTime = DateTime.Parse(pstrStartTime);
                        CalObj.DBEventStartTime = mdateStartTime;

                        DateTime mdateEndTime = DateTime.Parse(pstrEndTime);
                        CalObj.DBEventEndTime = mdateEndTime;

                        CalObj.DBEventDifferenceTime = mdateEndTime.Subtract(mdateStartTime).ToString();

                        CalObj.DBEventMaintenance = pstrMaintenance;

                        CalObj.DBCompanyId = companyObj.DBCompanyId;

                        TimeSpan mstrRecordState = mdateEndTime.Subtract(DateTime.UtcNow);
                        if (mstrRecordState.TotalMinutes > 0)
                        {
                            CalObj.DBEventStatus = "Active";
                        }
                        else
                        {
                            CalObj.DBEventStatus = "Inactive";
                        }


                        mDBContext.DBCalendars.Add(CalObj);
                        mDBContext.SaveChanges();

                        List <DBSubscription> subscriptionObjList = new List <DBSubscription>();
                        subscriptionObjList = (from subObj in mDBContext.DBSubscriptions
                                               where subObj.DBCompanyId == companyObj.DBCompanyId
                                               select subObj).ToList();
                        DBEmailPage emailPageObj = new DBEmailPage();
                        emailPageObj = (from emailPage in mDBContext.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 stringHtml = emailPageObj.DBEmailContent.ToString();

                            endIndex   = stringHtml.IndexOf("<!--end of componentUpdateDiv-->");
                            startIndex = stringHtml.IndexOf("<div id=\"divForComponentUpdates\">");
                            string 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("EventNameVariable", CalObj.DBEventTitle);
                            stringHtml = stringHtml.Replace("EventDetailsVariable", CalObj.DBEventDetails);
                            stringHtml = stringHtml.Replace("EventStartTimeVariable", CalObj.DBEventStartTime.ToString());
                            stringHtml = stringHtml.Replace("EventEndTimeVariable", CalObj.DBEventEndTime.ToString());
                            performSubscriptionObj.sendEmail(subscriptionObj.DBEmail, null, "New Event Scheduled", stringHtml);
                        }
                    }
                }
                else
                {
                    DBCalendar CalObj = new DBCalendar();
                    CalObj.DBEventId      = getseqDBCalEventId();
                    CalObj.DBEventTitle   = pstrTitle;
                    CalObj.DBEventDetails = pstrDetails;

                    DateTime mdateStartTime = DateTime.Parse(pstrStartTime);
                    CalObj.DBEventStartTime = mdateStartTime;

                    DateTime mdateEndTime = DateTime.Parse(pstrEndTime);
                    CalObj.DBEventEndTime = mdateEndTime;

                    CalObj.DBEventDifferenceTime = mdateEndTime.Subtract(mdateStartTime).ToString();

                    //CalObj.DBEventRepetition = pstrEventFor;
                    CalObj.DBEventMaintenance = pstrMaintenance;

                    CalObj.DBCompanyId = pstrCompanyId;

                    TimeSpan mstrRecordState = mdateEndTime.Subtract(DateTime.UtcNow);
                    if (mstrRecordState.TotalMinutes > 0)
                    {
                        CalObj.DBEventStatus = "Active";
                    }
                    else
                    {
                        CalObj.DBEventStatus = "Inactive";
                    }


                    mDBContext.DBCalendars.Add(CalObj);
                    mDBContext.SaveChanges();

                    DBCompany companyObj = new DBCompany();
                    companyObj = (from company in mDBContext.DBCompanies
                                  where company.DBCompanyId == pstrCompanyId
                                  select company).FirstOrDefault();
                    List <DBSubscription> subscriptionObjList = new List <DBSubscription>();
                    subscriptionObjList = (from subObj in mDBContext.DBSubscriptions
                                           where subObj.DBCompanyId == pstrCompanyId
                                           select subObj).ToList();
                    DBEmailPage emailPageObj = new DBEmailPage();
                    emailPageObj = (from emailPage in mDBContext.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 stringHtml = emailPageObj.DBEmailContent.ToString();

                        endIndex   = stringHtml.IndexOf("<!--end of componentUpdateDiv-->");
                        startIndex = stringHtml.IndexOf("<div id=\"divForComponentUpdates\">");
                        string 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("EventNameVariable", CalObj.DBEventTitle);
                        stringHtml = stringHtml.Replace("EventDetailsVariable", CalObj.DBEventDetails);
                        stringHtml = stringHtml.Replace("EventStartTimeVariable", CalObj.DBEventStartTime.ToString());
                        stringHtml = stringHtml.Replace("EventEndTimeVariable", CalObj.DBEventEndTime.ToString());
                        performSubscriptionObj.sendEmail(subscriptionObj.DBEmail, null, "New Event Scheduled", stringHtml);
                    }
                }



                return("Event Saved Sucessfully!!");
            }
            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");
            }
        }