public Response <bool> Update(Outage outage)
        {
            Console.WriteLine($"Request: Update.");

            if (outage == null)
            {
                return(new Response <bool>(ResponseStatus.Error, "Outage is invalid.", false));
            }

            Outage oldOutage = outageService.Get(outage.Id, out string message);

            if (oldOutage == null || oldOutage.State == OutageState.Closed)
            {
                return(new Response <bool>(ResponseStatus.Error, "Outage is closed and cannot be further updated.", false));
            }

            bool result = outageService.Update(outage, out message);

            if (result)
            {
                return(new Response <bool>(ResponseStatus.OK, message, result));
            }
            else
            {
                return(new Response <bool>(ResponseStatus.Error, message, result));
            }
        }
Example #2
0
        public async Task <IActionResult> PutOutage([FromRoute] int id, [FromBody] Outage outage)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != outage.OutageID)
            {
                return(BadRequest());
            }

            _context.Entry(outage).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!OutageExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Example #3
0
        public int Insert(Outage outage, out string message)
        {
            if (outage == null)
            {
                message = "Outage is invalid.";
                return(0);
            }

            if (outage.Id > 0)
            {
                message = "Outage cannot have an id.";
                return(0);
            }

            bool IsValid = OutageValidator.Validate(outage, out message);

            if (!IsValid)
            {
                return(0);
            }

            int id = repository.Insert(outage);

            if (id > 0)
            {
                message = string.Empty;
            }
            else
            {
                message = "An error occured while trying to insert outage.";
            }

            return(id);
        }
Example #4
0
        public Outage GetOutage(int?id)
        {
            ApplicationOutageEntities entities = new ApplicationOutageEntities();
            Outage outage = entities.Outages.Find(id);

            return(outage);
        }
Example #5
0
        public bool Update(Outage outage, out string message)
        {
            if (outage == null)
            {
                message = "Outage is invalid.";
                return(false);
            }

            if (outage.Id <= 0)
            {
                message = "Outage id is invalid.";
                return(false);
            }

            bool IsValid = OutageValidator.Validate(outage, out message);

            if (!IsValid)
            {
                return(false);
            }

            bool result = repository.Update(outage);

            if (result)
            {
                message = string.Empty;
            }
            else
            {
                message = "An error occured while trying to update outage.";
            }

            return(result);
        }
Example #6
0
        internal void Refresh(Outage outage)
        {
            OutageHeader     = outage.OutageHeader;
            PlatformHeader   = outage.Platform;
            OpeningStatement = outage.OpeningStatement;
            TopLeftIcon      = outage.Icon;
            ReturnTimeHeader = outage.ReturnTimeHeader;
            //ServiceImpactedHeader = outage.ServiceImpacted;
            ServiceImpactedBody = outage.ServiceImpacted;
            //ProblemSummaryHeader = outage.ProblemSummary;
            ProblemSummaryBody = outage.ProblemSummary;
            StartTime          = outage.Start.ToString();
            ReturnTime         = outage.Return.ToString();
            Platform           = outage.Platform;

            Europe    = outage.Locations.GetImage("Europe");
            China     = outage.Locations.GetImage("China");
            HongKong  = outage.Locations.GetImage("Hong-Kong");
            Singapore = outage.Locations.GetImage("Singapore");
            Korea     = outage.Locations.GetImage("Korea");
            Tokyo     = outage.Locations.GetImage("Tokyo");
            USWest    = outage.Locations.GetImage("US-West");
            USEast    = outage.Locations.GetImage("US-East");

            EmailSubject_Textbox.Text = outage.EmailHeader;
        }
Example #7
0
        public async Task <IActionResult> Edit(int id, [Bind("OutageID,StartDate,EndDate,Application,Description")] Outage outage)
        {
            if (id != outage.OutageID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(outage);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!OutageExists(outage.OutageID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Index"));
            }
            return(View(outage));
        }
Example #8
0
        public ActionResult DeleteConfirmed(int id)
        {
            Outage outage = db.Outages.Find(id);

            db.Outages.Remove(outage);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Example #9
0
        private string GenerateBody(Outage outage)
        {
            StringBuilder body = new StringBuilder();

            body.AppendLine($"<h1 align='center'>Outage Report - {DateTime.Now.ToLocalTime()}</h1>");
            body.AppendLine("<hr>");
            body.AppendLine("<h2 align='center'>Outage Information</h2>");
            body.AppendLine("<table width='100%' border='1' cellpadding='5'>");
            body.AppendLine("<tr>");
            body.AppendLine("<th width='20%' align='right'>ID</th>");
            body.AppendLine($"<td width='80%'>{outage.Id}</td>");
            body.AppendLine("</tr>");
            body.AppendLine("<tr>");
            body.AppendLine("<th width='20%' align='right'>Description</th>");
            body.AppendLine($"<td width='80%'>{SplitLines(outage.Description)}</td>");
            body.AppendLine("</tr>");
            body.AppendLine("<tr>");
            body.AppendLine("<th width='20%' align='right'>Creation Date</th>");
            body.AppendLine($"<td width='80%'>{outage.CreationDate.ToShortDateString()}</td>");
            body.AppendLine("</tr>");
            body.AppendLine("<tr>");
            body.AppendLine("<th width='20%' align='right'>Voltage Level</th>");
            body.AppendLine($"<td width='80%'>{outage.VoltageLevel.ToString().ToUpper()}</td>");
            body.AppendLine("</tr>");
            body.AppendLine("<tr>");
            body.AppendLine("<th width='20%' align='right'>State</th>");
            body.AppendLine($"<td width='80%'>{outage.State.ToString().ToUpper()}</td>");
            body.AppendLine("</tr>");
            body.AppendLine("<tr>");
            body.AppendLine("<th width='20%' align='right'>Faulty Element</th>");
            body.AppendLine($"<td width='80%'>{outage.ElementName}</td>");
            body.AppendLine("</tr>");
            body.AppendLine("<tr>");
            body.AppendLine("<th width='20%' align='right'>Longitude</th>");
            body.AppendLine($"<td width='80%'>{String.Format("{0:0.######}", outage.Longitude)}</td>");
            body.AppendLine("</tr>");
            body.AppendLine("<tr>");
            body.AppendLine("<th width='20%' align='right'>Latitude</th>");
            body.AppendLine($"<td width='80%'>{String.Format("{0:0.######}", outage.Latitude)}</td>");
            body.AppendLine("</tr>");
            body.AppendLine("</table>");
            body.AppendLine("<br>");
            body.AppendLine("<h2 align='center'>Executed Actions</h2>");
            body.AppendLine("<table width='100%' border='1' cellpadding='5'>");
            body.AppendLine("<tr>");
            body.AppendLine("<th width='20%'>Execution Date</th>");
            body.AppendLine("<th width='80%'>Description</th>");
            body.AppendLine("</tr>");
            foreach (var action in outage.Actions)
            {
                body.AppendLine("<tr>");
                body.AppendLine($"<td align='center'>{action.ExecutionDate.ToShortDateString()}</td>");
                body.AppendLine($"<td>{SplitLines(action.Description)}</td>");
                body.AppendLine("</tr>");
            }
            body.AppendLine("</table>");
            return(body.ToString());
        }
        public void Returns_OK()
        {
            Response <Outage> response       = system.Get(outage.Id);
            Outage            outageResponse = response.Data;
            ResponseStatus    status         = response.Status;

            Assert.IsTrue(outage.Description == outageResponse.Description);
            Assert.AreEqual(ResponseStatus.OK, status);
        }
        public void Returns_ERROR_because_of_repository_error()
        {
            Response <Outage> response       = invalidSystem.Get(outage.Id);
            Outage            outageResponse = response.Data;
            ResponseStatus    status         = response.Status;

            Assert.IsNotNull(outageResponse);
            Assert.AreEqual(ResponseStatus.Error, status);
        }
Example #12
0
        public Outage DeleteOutage(int id)
        {
            ApplicationOutageEntities entities = new ApplicationOutageEntities();
            Outage outage = entities.Outages.Find(id);

            entities.Outages.Remove(outage);
            entities.SaveChanges();
            return(outage);
        }
        public void Returns_ERROR_because_of_id()
        {
            Response <Outage> response       = system.Get(-1);
            Outage            outageResponse = response.Data;
            ResponseStatus    status         = response.Status;

            Assert.IsNotNull(outageResponse);
            Assert.AreEqual(ResponseStatus.Error, status);
        }
Example #14
0
        // Any exceptions in this handler will be exposed through ProcessException event and cause OutageLogProcessor
        // to requeue the data gap outage so it will be processed again (could be that remote system is offline).
        private void ProcessDataGap(Outage dataGap)
        {
            // Establish start and stop time for temporal session
            m_subscriptionInfo.StartTime = dataGap.Start.ToString(OutageLog.DateTimeFormat, CultureInfo.InvariantCulture);
            m_subscriptionInfo.StopTime  = dataGap.End.ToString(OutageLog.DateTimeFormat, CultureInfo.InvariantCulture);

            OnStatusMessage(MessageLevel.Info, $"Starting data gap recovery for period \"{m_subscriptionInfo.StartTime}\" - \"{m_subscriptionInfo.StopTime}\"...");

            // Enable data monitor
            m_dataStreamMonitor.Enabled = true;

            // Reset measurement counters
            m_measurementsRecoveredForDataGap       = 0;
            m_measurementsRecoveredOverLastInterval = 0;

            // Reset processing fields
            m_mostRecentRecoveredTime = dataGap.Start.Ticks;
            m_abnormalTermination     = false;

            // Reset process completion wait handle
            m_dataGapRecoveryCompleted.Reset();

            // Start temporal data recovery session
            m_temporalSubscription.Subscribe(m_subscriptionInfo);

            // Wait for process completion - success or fail
            m_dataGapRecoveryCompleted.Wait();

            // If temporal session failed to connect, retry data recovery for this outage
            if (m_abnormalTermination)
            {
                // Make sure any data recovered so far doesn't get unnecessarily re-recovered, this requires that source historian report data in time-sorted order
                dataGap = new Outage(new DateTime(GSF.Common.Max((Ticks)dataGap.Start.Ticks, m_mostRecentRecoveredTime - (m_subscriptionInfo.UseMillisecondResolution ? Ticks.PerMillisecond : 1L)), DateTimeKind.Utc), dataGap.End);

                // Re-insert adjusted data gap at the top of the processing queue
                m_dataGapLog.Insert(0, dataGap);
                FlushLogAsync();

                if (m_measurementsRecoveredForDataGap == 0)
                {
                    OnStatusMessage(MessageLevel.Warning, $"Failed to establish temporal session. Data recovery for period \"{m_subscriptionInfo.StartTime}\" - \"{m_subscriptionInfo.StopTime}\" will be re-attempted.");
                }
                else
                {
                    OnStatusMessage(MessageLevel.Warning, $"Temporal session was disconnected during recovery operation. Data recovery for adjusted period \"{dataGap.Start.ToString(OutageLog.DateTimeFormat, CultureInfo.InvariantCulture)}\" - \"{m_subscriptionInfo.StopTime}\" will be re-attempted.");
                }
            }

            // Unsubscribe from temporal session
            m_temporalSubscription.Unsubscribe();

            // Disable data monitor
            m_dataStreamMonitor.Enabled = false;

            OnStatusMessage(m_measurementsRecoveredForDataGap == 0 ? MessageLevel.Warning : MessageLevel.Info, $"Recovered {m_measurementsRecoveredForDataGap} measurements for period \"{m_subscriptionInfo.StartTime}\" - \"{m_subscriptionInfo.StopTime}\".");
        }
 public async Task InsertOutage(Outage outage)
 {
     try
     {
         await App.MobileService.GetTable <Outage>().InsertAsync(outage);
     }
     catch (Exception ex)
     {
     }
 }
Example #16
0
        public async Task <IActionResult> Create([Bind("OutageID,StartDate,EndDate,Application,Description")] Outage outage)
        {
            if (ModelState.IsValid)
            {
                _context.Add(outage);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(outage));
        }
Example #17
0
 public ActionResult Edit([Bind(Include = "ID,ApplicationID,StartDate,EndDate,IncidentNumber,Impact,Description,Component")] Outage outage)
 {
     if (ModelState.IsValid)
     {
         db.Entry(outage).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.ApplicationID = new SelectList(db.Applications, "ID", "ApplicationName", outage.ApplicationID);
     return(View(outage));
 }
        public void Setup()
        {
            outage             = new Outage();
            outage.Description = "Test";
            outage.ElementName = "Test";
            ExecutedAction action = new ExecutedAction();

            action.Description = "Test";
            outage.Actions.Add(action);

            id = system.Insert(outage).Data;
        }
Example #19
0
        public async Task <IActionResult> PostOutage([FromBody] Outage outage)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.Outage.Add(outage);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetOutage", new { id = outage.OutageID }, outage));
        }
 public int Insert(Outage outage)
 {
     if (outage.Id <= 0)
     {
         outage.Id = context.GenerateID();
         context.Outages.Add(outage);
         return(outage.Id);
     }
     else
     {
         return(0);
     }
 }
 public bool Remove(int id)
 {
     if (id > 0 && context.Outages.Any(p => p.Id == id))
     {
         Outage outage = context.Outages.First(p => p.Id == id);
         context.Outages.Remove(outage);
         return(true);
     }
     else
     {
         return(false);
     }
 }
        public ActionResult Save(Outage outage)
        {
            if (ModelState.IsValid)
            {
                OutageManager outageManager = new OutageManager();

                if (outageManager.AddOutage(outage))
                {
                    return(RedirectToAction("Index"));
                }
            }
            return(View(outage));
        }
 public int Insert(Outage outage)
 {
     try
     {
         context.Outages.Add(outage);
         context.SaveChanges();
         return(outage.Id);
     }
     catch (Exception)
     {
         return(0);
     }
 }
        public void Refresh(Outage outage)
        {
            OutageType       = outage.OutageType;
            OpeningStatement = outage.OpeningStatementKB;
            Platform         = outage.Platform;
            ProblemSummary   = outage.ProblemSummary;
            ServicesImpacted = outage.ServiceImpacted;
            Locations        = FormatLocations(outage.Locations);
            Start            = outage.Start.ToString();
            Return           = outage.Return.ToString();

            SummaryHeader = outage.SummaryHeaderKB;
            HeaderImage   = outage.DSIcon;
        }
 public bool Update(Outage outage)
 {
     if (outage.Id > 0 && context.Outages.Any(p => p.Id == outage.Id))
     {
         Outage oldOutage = context.Outages.First(p => p.Id == outage.Id);
         context.Outages.Remove(oldOutage);
         context.Outages.Add(outage);
         return(true);
     }
     else
     {
         return(false);
     }
 }
        public Response <Outage> Get(int id)
        {
            Console.WriteLine($"Request: Get.");
            Outage outage = outageService.Get(id, out string message);

            if (outage != null && outage.Id > 0)
            {
                return(new Response <Outage>(ResponseStatus.OK, message, outage));
            }
            else
            {
                return(new Response <Outage>(ResponseStatus.Error, message, outage));
            }
        }
        public void Setup()
        {
            Outage outage = new Outage();

            outage.CreationDate = new DateTime(2006, 6, 6);
            outage.Description  = "Test";
            outage.ElementName  = "Test";
            ExecutedAction action = new ExecutedAction();

            action.Description = "Test";
            outage.Actions.Add(action);

            system.Insert(outage);
        }
        public void Setup()
        {
            outage             = new Outage();
            outage.Description = "Test";
            outage.ElementName = "Test";
            ExecutedAction action = new ExecutedAction();

            action.Description = "Test";
            outage.Actions.Add(action);

            system.Insert(outage);
            outage.Id = 0;
            invalidGeneratorSystem.Insert(outage);
        }
Example #29
0
        // GET: Outages/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Outage outage = db.Outages.Find(id);

            if (outage == null)
            {
                return(HttpNotFound());
            }
            return(View(outage));
        }
 public bool Remove(int id)
 {
     try
     {
         Outage outage = context.Outages.Find(id);
         context.Outages.Remove(outage);
         context.SaveChanges();
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Example #31
0
        // Any exceptions in this handler will be exposed through ProcessException event and cause OutageLogProcessor
        // to requeue the data gap outage so it will be processed again (could be that remote system is offline).
        private void ProcessDataGap(Outage dataGap)
        {
            // Establish start and stop time for temporal session
            m_subscriptionInfo.StartTime = dataGap.Start.ToString(OutageLog.DateTimeFormat, CultureInfo.InvariantCulture);
            m_subscriptionInfo.StopTime = dataGap.End.ToString(OutageLog.DateTimeFormat, CultureInfo.InvariantCulture);

            OnStatusMessage("Starting data gap recovery for period \"{0}\" - \"{1}\"...", m_subscriptionInfo.StartTime, m_subscriptionInfo.StopTime);

            // Enable data monitor            
            m_dataStreamMonitor.Enabled = true;

            // Reset measurement counters
            m_measurementsRecoveredForDataGap = 0;
            m_measurementsRecoveredOverLastInterval = 0;

            // Reset processing fields
            m_mostRecentRecoveredTime = dataGap.Start.Ticks;
            m_abnormalTermination = false;

            // Reset process completion wait handle
            m_dataGapRecoveryCompleted.Reset();

            // Start temporal data recovery session
            m_temporalSubscription.Subscribe(m_subscriptionInfo);

            // Wait for process completion - success or fail
            m_dataGapRecoveryCompleted.Wait();

            // If temporal session failed to connect, retry data recovery for this outage
            if (m_abnormalTermination)
            {
                // Make sure any data recovered so far doesn't get unnecessarily re-recovered, this requires that source historian report data in time-sorted order
                dataGap = new Outage(new DateTime(GSF.Common.Max((Ticks)dataGap.Start.Ticks, m_mostRecentRecoveredTime - (m_subscriptionInfo.UseMillisecondResolution ? Ticks.PerMillisecond : 1L)), DateTimeKind.Utc), dataGap.End);

                // Re-insert adjusted data gap at the top of the processing queue
                m_dataGapLog.Insert(0, dataGap);
                FlushLogAsync();

                if (m_measurementsRecoveredForDataGap == 0)
                    OnStatusMessage("WARNING: Failed to establish temporal session. Data recovery for period \"{0}\" - \"{1}\" will be re-attempted.", m_subscriptionInfo.StartTime, m_subscriptionInfo.StopTime);
                else
                    OnStatusMessage("WARNING: Temporal session was disconnected during recovery operation. Data recovery for adjusted period \"{0}\" - \"{1}\" will be re-attempted.", dataGap.Start.ToString(OutageLog.DateTimeFormat, CultureInfo.InvariantCulture), m_subscriptionInfo.StopTime);
            }

            // Disconnect temporal session
            m_temporalSubscription.Stop();

            // Disable data monitor            
            m_dataStreamMonitor.Enabled = false;

            OnStatusMessage("{0}Recovered {1} measurements for period \"{2}\" - \"{3}\".", m_measurementsRecoveredForDataGap == 0 ? "WARNING: " : "", m_measurementsRecoveredForDataGap, m_subscriptionInfo.StartTime, m_subscriptionInfo.StopTime);
        }
Example #32
0
 // Can only start data gap processing when end time of recovery range is beyond recovery start delay
 private bool CanProcessDataGap(Outage dataGap)
 {
     return m_connected && Enabled && (DateTime.UtcNow - dataGap.End).TotalSeconds > m_recoveryStartDelay;
 }