コード例 #1
0
ファイル: UnitTest2.cs プロジェクト: diegotrujillor/SMCL
        public void CanCreateAlarmTypeAndLog()
        {
            IRepository<AlarmType> repoA = new AlarmTypeRepository();
            AlarmType alarm = new AlarmType();
            alarm.NameAlarmType = "PruebaAlarma";
            alarm.Description = "Prueba descriptiva alarma";

            repoA.Save(alarm);

            IRepository<User> repoB = new UserRepository();
            User user = new User();
            user = repoB.GetById(1);
            IRepository<Event> repoC = new EventRepository();
            Event eventt = new Event();
            eventt = repoC.GetById(2);

            IRepository<Log> repoD = new LogRepository();
            Log log = new Log();
            log.DateTime = DateTime.Now;
            log.Text = "Prueba descriptiva log";
            log.Event = eventt;
            log.User = user;

            repoD.Save(log);
        }
コード例 #2
0
ファイル: UnitTest5.cs プロジェクト: diegotrujillor/SMCL
        public void TestMethod1()
        {
            IRepository<Monitoring> repoM = new MonitoringRepository();
            var res = repoM.GetByProperty("CommentsOnAlarm", null);

            IRepository<Signal> repo1 = new SignalRepository();
            Signal signal = new Signal();
            signal = repo1.GetById(1);
            IRepository<Appliance> repo2 = new ApplianceRepository();
            Appliance appliance = new Appliance();
            appliance = repo2.GetById(1);
            IRepository<AlarmType> repo3 = new AlarmTypeRepository();
            AlarmType alarmType = new AlarmType();
            alarmType = repo3.GetById(1);
            IRepository<User> repo4 = new UserRepository();
            User user = new User();
            user = repo4.GetById(2);

            IRepository<MappingTag> repoMT = new MappingTagRepository();
            MappingTag tag = new MappingTag();
            tag.Tag = "PruebaTag";
            tag.Description = "Prueba descriptiva mapping tag";
            tag.Signal = signal;
            tag.Appliance = appliance;
            tag.AlarmType = alarmType;

            Monitoring monitor = new Monitoring();
            monitor.Value = float.Parse("2.400");
            monitor.DateTime = DateTime.Now;
            monitor.CommentsOnAlarm = "Prueba de comentarios sobre alarma, monitoreo";
            monitor.MappingTag = tag;
            monitor.User = user;

            tag.Monitorings.Add(monitor);

            repoMT.Save(tag);

            /*INSERT 4000 RECORDS for TEST*/
            //IRepository<Monitoring> repoM = new MonitoringRepository();
            //IRepository<User> repo4 = new UserRepository();
            //User user = new User();
            //user = repo4.GetById(6);

            //IRepository<MappingTag> repoMT = new MappingTagRepository();
            //MappingTag tag = new MappingTag();
            //tag = repoMT.GetById(103);

            //for (int i = 0; i < 4000; i++)
            //{
            //    Monitoring monitor = new Monitoring();
            //    monitor.Value = (1000 + i);
            //    monitor.DateTime = DateTime.Now;
            //    monitor.CommentsOnAlarm = null;
            //    monitor.MappingTag = tag;
            //    monitor.User = user;

            //    repoM.Save(monitor);
            //}
        }
コード例 #3
0
ファイル: UnitTest4.cs プロジェクト: diegotrujillor/SMCL
        public void CanCreateSignalApplianceAndValues()
        {
            IRepository<Area> repoT = new AreaRepository();
            Area area = new Area();
            area = repoT.GetById(1);
            IRepository<AlarmType> repoAT = new AlarmTypeRepository();
            AlarmType alarm = new AlarmType();
            alarm = repoAT.GetById(1);

            IRepository<Signal> repoA = new SignalRepository();
            Signal signal = new Signal();
            signal.Name = "PruebaSenal";
            signal.Description = "Prueba descriptiva senal";

            repoA.Save(signal);

            IRepository<Appliance> repoB = new ApplianceRepository();
            Appliance appliance = new Appliance();
            appliance.NameAppliance = "PruebaAppliance";
            appliance.Description = "Prueba descriptiva appliance";
            appliance.Area = area;

            SignalAppliance signalAppliance = new SignalAppliance();
            signalAppliance.Signal = signal;
            signalAppliance.Appliance = appliance;

            appliance.Signals.Add(signalAppliance);

            repoB.Save(appliance);

            IRepository<SignalApplianceValue> repoSAV = new SignalApplianceValueRepository();
            SignalApplianceValue signalApplianceValue = new SignalApplianceValue();
            signalApplianceValue.Value = 40;
            signalApplianceValue.SignalAppliance = signalAppliance;
            signalApplianceValue.AlarmType = alarm;

            repoSAV.Save(signalApplianceValue);
        }
コード例 #4
0
ファイル: UnitTest6.cs プロジェクト: diegotrujillor/SMCL
        public void CanCreateSignalWithToleranceAndAssociatedSignalApplianceValues()
        {
            IRepository<Area> repoT = new AreaRepository();
            Area area = new Area();
            area = repoT.GetById(1);
            IRepository<AlarmType> repoAT = new AlarmTypeRepository();
            AlarmType normalAlarm = new AlarmType();
            normalAlarm = repoAT.GetById(1);
            AlarmType highAlarm = new AlarmType();
            highAlarm = repoAT.GetById(2);
            AlarmType lowAlarm = new AlarmType();
            lowAlarm = repoAT.GetById(3);

            IRepository<Signal> repoA = new SignalRepository();
            Signal signal = new Signal();
            signal.Name = "PruebaSenal";
            signal.Description = "Prueba descriptiva senal";

            repoA.Save(signal);

            IRepository<Appliance> repoB = new ApplianceRepository();
            Appliance appliance = new Appliance();
            appliance.NameAppliance = "PruebaAppliance";
            appliance.Description = "Prueba descriptiva appliance";
            appliance.Area = area;

            IRepository<SignalAppliance> repoSAppl = new SignalApplianceRepository();
            SignalAppliance signalAppliance = new SignalAppliance();
            signalAppliance.Signal = signal;
            signalAppliance.Appliance = appliance;
            signalAppliance.Tolerance = SIGNAL_APPLIANCE_TOLERANCE;

            appliance.Signals.Add(signalAppliance);

            IRepository<SignalApplianceValue> repoSApplV = new SignalApplianceValueRepository();
            SignalApplianceValue normalValue = new SignalApplianceValue();
            normalValue.AlarmType = normalAlarm;
            normalValue.SignalAppliance = signalAppliance;
            normalValue.Value = SIGNAL_APPLIANCE_SET_POINT;

            SignalApplianceValue highValue = new SignalApplianceValue();
            highValue.AlarmType = highAlarm;
            highValue.SignalAppliance = signalAppliance;
            highValue.Value = SIGNAL_APPLIANCE_SET_POINT + SIGNAL_APPLIANCE_TOLERANCE;

            SignalApplianceValue lowValue = new SignalApplianceValue();
            lowValue.AlarmType = lowAlarm;
            lowValue.SignalAppliance = signalAppliance;
            lowValue.Value = SIGNAL_APPLIANCE_SET_POINT - SIGNAL_APPLIANCE_TOLERANCE;

            signalAppliance.SignalApplianceValues.Add(normalValue);
            signalAppliance.SignalApplianceValues.Add(highValue);
            signalAppliance.SignalApplianceValues.Add(lowValue);

            repoB.Save(appliance);

            SignalApplianceValue createdNormalValue = repoSApplV.GetById(normalValue.Id);
            Assert.AreEqual(normalValue.Value, createdNormalValue.Value);

            SignalApplianceValue createdHighValue = repoSApplV.GetById(highValue.Id);
            Assert.AreEqual(highValue.Value, createdHighValue.Value);

            SignalApplianceValue createdLowValue = repoSApplV.GetById(lowValue.Id);
            Assert.AreEqual(lowValue.Value, createdLowValue.Value);

            repoSApplV.Delete(normalValue.Id);
            repoSApplV.Delete(highValue.Id);
            repoSApplV.Delete(lowValue.Id);

            repoSAppl.Delete(signalAppliance.Id);

            repoB.Delete(appliance.Id);

            repoA.Delete(signal.Id);
        }
コード例 #5
0
ファイル: UnitTest6.cs プロジェクト: diegotrujillor/SMCL
        public void ListSignalAppliancesWithAlarmTypesAndValuesInOneRecord()
        {
            IRepository<SignalAppliance> dbSA = new SignalApplianceRepository();
            IRepository<Signal> dbS = new SignalRepository();
            IRepository<Appliance> dbApp = new ApplianceRepository();
            IRepository<SignalApplianceValue> dbSAppV = new SignalApplianceValueRepository();
            IRepository<AlarmType> dbAT = new AlarmTypeRepository();
            IRepository<Area> dbA = new AreaRepository();

            Area area = new Area();
            area = dbA.GetById(1);
            AlarmType normalAlarm = new AlarmType();
            normalAlarm = dbAT.GetById(1);
            AlarmType highAlarm = new AlarmType();
            highAlarm = dbAT.GetById(2);
            AlarmType lowAlarm = new AlarmType();
            lowAlarm = dbAT.GetById(3);

            Signal signal = new Signal();
            signal.Name = "PruebaSenal";
            signal.Description = "Prueba descriptiva senal";

            dbS.Save(signal);

            Appliance appliance = new Appliance();
            appliance.NameAppliance = "PruebaAppliance";
            appliance.Description = "Prueba descriptiva appliance";
            appliance.Area = area;

            SignalAppliance signalAppliance = new SignalAppliance();
            signalAppliance.Signal = signal;
            signalAppliance.Appliance = appliance;
            signalAppliance.Tolerance = SIGNAL_APPLIANCE_TOLERANCE;

            appliance.Signals.Add(signalAppliance);

            SignalApplianceValue normalValue = new SignalApplianceValue();
            normalValue.AlarmType = normalAlarm;
            normalValue.SignalAppliance = signalAppliance;
            normalValue.Value = SIGNAL_APPLIANCE_SET_POINT;

            SignalApplianceValue highValue = new SignalApplianceValue();
            highValue.AlarmType = highAlarm;
            highValue.SignalAppliance = signalAppliance;
            highValue.Value = SIGNAL_APPLIANCE_SET_POINT + SIGNAL_APPLIANCE_TOLERANCE;

            SignalApplianceValue lowValue = new SignalApplianceValue();
            lowValue.AlarmType = lowAlarm;
            lowValue.SignalAppliance = signalAppliance;
            lowValue.Value = SIGNAL_APPLIANCE_SET_POINT - SIGNAL_APPLIANCE_TOLERANCE;

            signalAppliance.SignalApplianceValues.Add(normalValue);
            signalAppliance.SignalApplianceValues.Add(highValue);
            signalAppliance.SignalApplianceValues.Add(lowValue);

            dbApp.Save(appliance);

            var result = from sa in dbSA.GetAll()
                                   join s in dbS.GetAll() on sa.Signal.Id equals s.Id
                                   join app in dbApp.GetAll() on sa.Appliance.Id equals app.Id
                                   join sapv in dbSAppV.GetAll() on sa.Id equals sapv.SignalAppliance.Id
                                   join a in dbAT.GetAll() on sapv.AlarmType.Id equals a.Id
                                   where sa.Id.Equals(signalAppliance.Id)
                                   group new {a.Id, a.NameAlarmType, sapv.Value } by new {sa.Id, app.NameAppliance, s.Name, sa.Tolerance} into g
                         select new { signalAppliance = g.Key, setPoint = from v in g where v.Id == 1 select v.Value, highValue = from v in g where v.Id == 2 select v.Value, lowValue = from v in g where v.Id == 3 select v.Value };

            foreach (var sa in result)
            {
                Assert.AreEqual(sa.signalAppliance.Id, signalAppliance.Id);
                ObjectDumper.Write(sa.setPoint);
                Assert.AreEqual(normalValue.Value, sa.setPoint.ElementAtOrDefault(0));
                ObjectDumper.Write(sa.highValue);
                Assert.AreEqual(highValue.Value, sa.highValue.ElementAtOrDefault(0));
                ObjectDumper.Write(sa.lowValue);
                Assert.AreEqual(lowValue.Value, sa.lowValue.ElementAtOrDefault(0));
            }

            dbSAppV.Delete(normalValue.Id);
            dbSAppV.Delete(highValue.Id);
            dbSAppV.Delete(lowValue.Id);

            dbSA.Delete(signalAppliance.Id);

            dbApp.Delete(appliance.Id);

            dbS.Delete(signal.Id);
        }
コード例 #6
0
ファイル: UnitTest6.cs プロジェクト: diegotrujillor/SMCL
        public void ListMonitoringRecordsForInbox()
        {
            IRepository<SignalAppliance> dbSA = new SignalApplianceRepository();
            IRepository<MappingTag> dbMapT = new MappingTagRepository();
            IRepository<Monitoring> dbMon = new MonitoringRepository();
            IRepository<Signal> dbS = new SignalRepository();
            IRepository<Appliance> dbApp = new ApplianceRepository();
            IRepository<SignalApplianceValue> dbSAppV = new SignalApplianceValueRepository();
            IRepository<AlarmType> dbAT = new AlarmTypeRepository();
            IRepository<Area> dbA = new AreaRepository();

            var monRecords = from r in (
                                          from mon in dbMon.GetAll()
                                          join mapp in dbMapT.GetAll() on mon.MappingTag.Id equals mapp.Id
                                        select new { monDatetime = mon.DateTime, appId = mapp.Appliance.Id, sigId = mapp.Signal.Id, pv =  (mapp.AlarmType.Id.Equals(Convert.ToInt32("1")) ? mon.Value: 0 ), alarm = (mon.Value == 1 && !mapp.AlarmType.Id.Equals(Convert.ToInt32("1")) ? mapp.AlarmType.Id : 0 ) ,userId = mon.User.Id})
                            group r by new {r.monDatetime, r.appId, r.sigId, r.userId} into g
                           select new { monRecord = g.Key, monValue = g.Sum(d => d.pv), alarm = g.Sum(d => d.alarm) };

            var result = from m in monRecords
                         join mon in dbMon.GetAll() on m.monRecord.monDatetime equals mon.DateTime
                         join mapp in dbMapT.GetAll() on new { mapId = mon.MappingTag.Id, appId = m.monRecord.appId, sigId = m.monRecord.sigId } equals new { mapId = mapp.Id, appId = mapp.Appliance.Id, sigId = mapp.Signal.Id }
                         where (m.alarm == 0 ? 1 : m.alarm) == mapp.AlarmType.Id
                         select new { monId = mon.Id, dateTime = m.monRecord.monDatetime, appId = m.monRecord.appId, sigId = m.monRecord.sigId, alarm = m.alarm, monValue = m.monValue, userId = m.monRecord.userId };

            /*
                to_char(tmp.datetime, 'yyyy/mm/dd hh24:mi:ss') mon_datetime, area.are_name, sig.sig_name,
                decode(tmp.alarm, 'A', 'Alta', 'B', 'Baja', 'N', 'Normal', 'Desconodido') ala_typ_name,
                smcl_get_appl_signal_comment(tmp.datetime, tmp.app_id, tmp.sig_id, tmp.alarm) mon_comment_on_alarm,
                appl.app_name, case when tmp.sig_id = 1 then round_half_way_down(trunc(tmp.mon_value, 3), 2) else round_half_way_down(trunc(tmp.mon_value, 2), 1) end mon_value ,
                tmp.sig_id, usr.usr_first_name || ' ' || usr.usr_last_name_1 || '(' || usr.usr_login_email || ')' username,
             */
            //group new {a.Id, a.NameAlarmType, sapv.Value } by new {sa.Id, app.NameAppliance, s.Name, sa.Tolerance} into g
            //select new { signalAppliance = g.Key, setPoint = from v in g where v.Id == 1 select v.Value, highValue = from v in g where v.Id == 2 select v.Value, lowValue = from v in g where v.Id == 3 select v.Value };

            ObjectDumper.Write(result.Count());

            foreach (var v in result)
            {
                ObjectDumper.Write(v);
            }
        }
コード例 #7
0
        public ActionResult DeleteConfirmed(int id)
        {
            List<Object> logList = new List<Object>();
            ViewData["ValidationErrorMessage"] = String.Empty;

            MappingTag mappingtag = db.GetById(id);

            try
            {
                IRepository<Signal> dbS = new SignalRepository();
                IRepository<Appliance> dbA = new ApplianceRepository();
                IRepository<AlarmType> dbAT = new AlarmTypeRepository();

                if (mappingtag != null)
                {
                    db.Delete(id);
                    logList.Add(log.GetNewLog(ConfigurationManager.AppSettings["DeleteText"] +
                                              ControllerContext.RouteData.Values["controller"] +
                                              "(Id=" + mappingtag.Id.ToString().Replace("-", "").ToUpper() +
                                              " - Description=" + mappingtag.Description +
                                              " - Tag=" + mappingtag.Tag +
                                              " - AlarmTypeName=" + dbAT.GetById(mappingtag.AlarmType.Id).NameAlarmType +
                                              " - ApplianceName=" + dbA.GetById(mappingtag.Appliance.Id).NameAppliance +
                                              " - SignalName=" + dbS.GetById(mappingtag.Signal.Id).Name + ")",
                                              (int)EventTypes.Delete,
                                              (int)Session["UserId"]));
                    log.Write(logList);
                }
            }
            catch (GenericADOException)
            {
                ViewData["ValidationErrorMessage"] = ConfigurationManager.AppSettings["CannotDeleteHasAssociatedRecords"];

                logList.Add(log.GetNewLog(ConfigurationManager.AppSettings["DeleteText"] +
                                          ConfigurationManager.AppSettings["CannotDeleteHasAssociatedRecords"] + " " +
                                          ControllerContext.RouteData.Values["controller"] +
                                          "(Id=" + mappingtag.Id.ToString().Replace("-", "").ToUpper() +
                                          " - Description=" + mappingtag.Description +
                                          " - Tag=" + mappingtag.Tag +
                                          " - AlarmTypeName=" + dbAT.GetById(mappingtag.AlarmType.Id).NameAlarmType +
                                          " - ApplianceName=" + dbA.GetById(mappingtag.Appliance.Id).NameAppliance +
                                          " - SignalName=" + dbS.GetById(mappingtag.Signal.Id).Name + ")",
                                          (int)EventTypes.Delete,
                                          (int)Session["UserId"]));
                log.Write(logList);

                MappingTag entity = db.GetById(id);
                entity.AlarmType = dbAT.GetById(entity.AlarmType.Id);
                entity.Appliance = dbA.GetById(entity.Appliance.Id);
                entity.Signal = dbS.GetById(entity.Signal.Id);

                return View(entity);
            }
            catch (Exception ex)
            {
                ViewData["ValidationErrorMessage"] = ConfigurationManager.AppSettings["UnknownError"];

                logList.Add(log.GetNewLog(ConfigurationManager.AppSettings["DeleteText"] + ex.InnerException.Message, (int)EventTypes.Delete, (int)Session["UserId"]));
                log.Write(logList);

                return View();
            }

            return RedirectToAction("Index");
        }