Ejemplo n.º 1
0
        public void StoreInDataBase(int datasetID, CollectionDescription cd, ReplicatorDbContext _context)
        {
            if (datasetID == 1)
            {
                Dataset1 ds1 = new Dataset1();

                ds1.ID        = datasetID;
                ds1.Code1     = cd.Collection.ReceiverPropertyArray[0].Code;
                ds1.Value1    = cd.Collection.ReceiverPropertyArray[0].ReceiverValue;
                ds1.Code2     = cd.Collection.ReceiverPropertyArray[1].Code;
                ds1.Value2    = cd.Collection.ReceiverPropertyArray[1].ReceiverValue;
                ds1.TimeStamp = DateTime.Now;

                _context.Dataset1.Add(ds1);
                Logger.Log(LogComponent.READER, LogComponent.DATABASE, DateTime.Now, cd.ToString());
            }
            else if (datasetID == 2)
            {
                Dataset2 ds2 = new Dataset2();

                ds2.ID        = datasetID;
                ds2.Code1     = cd.Collection.ReceiverPropertyArray[0].Code;
                ds2.Value1    = cd.Collection.ReceiverPropertyArray[0].ReceiverValue;
                ds2.Code2     = cd.Collection.ReceiverPropertyArray[1].Code;
                ds2.Value2    = cd.Collection.ReceiverPropertyArray[1].ReceiverValue;
                ds2.TimeStamp = DateTime.Now;

                _context.Dataset2.Add(ds2);
                Logger.Log(LogComponent.READER, LogComponent.DATABASE, DateTime.Now, cd.ToString());
            }
            else if (datasetID == 3)
            {
                Dataset3 ds3 = new Dataset3();

                ds3.ID        = datasetID;
                ds3.Code1     = cd.Collection.ReceiverPropertyArray[0].Code;
                ds3.Value1    = cd.Collection.ReceiverPropertyArray[0].ReceiverValue;
                ds3.Code2     = cd.Collection.ReceiverPropertyArray[1].Code;
                ds3.Value2    = cd.Collection.ReceiverPropertyArray[1].ReceiverValue;
                ds3.TimeStamp = DateTime.Now;

                _context.Dataset3.Add(ds3);
                Logger.Log(LogComponent.READER, LogComponent.DATABASE, DateTime.Now, cd.ToString());
            }
            else //if (datasetID == 4)
            {
                Dataset4 ds4 = new Dataset4();

                ds4.ID        = datasetID;
                ds4.Code1     = cd.Collection.ReceiverPropertyArray[0].Code;
                ds4.Value1    = cd.Collection.ReceiverPropertyArray[0].ReceiverValue;
                ds4.Code2     = cd.Collection.ReceiverPropertyArray[1].Code;
                ds4.Value2    = cd.Collection.ReceiverPropertyArray[1].ReceiverValue;
                ds4.TimeStamp = DateTime.Now;

                _context.Dataset4.Add(ds4);
                Logger.Log(LogComponent.READER, LogComponent.DATABASE, DateTime.Now, cd.ToString());
            }

            _context.SaveChanges();
        }
Ejemplo n.º 2
0
        public bool CheckDeadBand(int datasetID, CollectionDescription cd, ReplicatorDbContext _context)
        {
            if (datasetID == 2)
            {
                List <Dataset2> collection = new List <Dataset2>();
                Dataset2        ds2        = new Dataset2();

                foreach (var item in _context.Dataset2.Where(x => true))
                {
                    ds2.ID     = item.ID;
                    ds2.Code1  = item.Code1;
                    ds2.Code2  = item.Code2;
                    ds2.Value1 = item.Value1;
                    ds2.Value2 = item.Value2;
                    collection.Add(ds2);
                }


                return(collection
                       .Where(x =>
                              (x.Value1 > (cd.Collection.ReceiverPropertyArray[0].ReceiverValue * 0.98) &&
                               x.Value1 < (cd.Collection.ReceiverPropertyArray[0].ReceiverValue * 1.02))
                              &&
                              (x.Value2 > (cd.Collection.ReceiverPropertyArray[1].ReceiverValue * 0.98) &&
                               x.Value2 < (cd.Collection.ReceiverPropertyArray[1].ReceiverValue * 1.02))
                              ).Count() > 0 ? false : true);
            }
            else if (datasetID == 3)
            {
                List <Dataset3> collection = new List <Dataset3>();
                Dataset3        ds3        = new Dataset3();

                foreach (var item in _context.Dataset3.Where(x => true))
                {
                    ds3.ID     = item.ID;
                    ds3.Code1  = item.Code1;
                    ds3.Code2  = item.Code2;
                    ds3.Value1 = item.Value1;
                    ds3.Value2 = item.Value2;
                    collection.Add(ds3);
                }
                return(collection
                       .Where(x =>
                              (x.Value1 > (cd.Collection.ReceiverPropertyArray[0].ReceiverValue * 0.98) &&
                               x.Value1 < (cd.Collection.ReceiverPropertyArray[0].ReceiverValue * 1.02))
                              &&
                              (x.Value2 > (cd.Collection.ReceiverPropertyArray[1].ReceiverValue * 0.98) &&
                               x.Value2 < (cd.Collection.ReceiverPropertyArray[1].ReceiverValue * 1.02))
                              ).Count() > 0 ? false : true);
            }
            else // (if (datasetID == 4)
            {
                List <Dataset4> collection = new List <Dataset4>();
                Dataset4        ds4        = new Dataset4();

                foreach (var item in _context.Dataset4.Where(x => true))
                {
                    ds4.ID     = item.ID;
                    ds4.Code1  = item.Code1;
                    ds4.Code2  = item.Code2;
                    ds4.Value1 = item.Value1;
                    ds4.Value2 = item.Value2;
                    collection.Add(ds4);
                }
                return(collection
                       .Where(x =>
                              (x.Value1 > (cd.Collection.ReceiverPropertyArray[0].ReceiverValue * 0.98) &&
                               x.Value1 < (cd.Collection.ReceiverPropertyArray[0].ReceiverValue * 1.02))
                              &&
                              (x.Value2 > (cd.Collection.ReceiverPropertyArray[1].ReceiverValue * 0.98) &&
                               x.Value2 < (cd.Collection.ReceiverPropertyArray[1].ReceiverValue * 1.02))
                              ).Count() > 0 ? false : true);
            }
        }