Ejemplo n.º 1
0
        public void TestRepoUpdate()
        {
            iotRepository <Location> repo = new iotRepository <Location>();
            //get
            List <Location> locs = repo.GetAll().ToList();
            //add if required
            Location loc = new Location();

            if (locs != null)
            {
                loc.LocationName = Guid.NewGuid().ToString();
                loc.Lat          = 0;
                loc.Lng          = 0;
                repo.Add(loc);
                //update
                locs = repo.GetAll().ToList();
                loc  = locs.Where(l => { return(l.LocationName == loc.LocationName); }).First();
                Location StoredBefore = repo.GetById(loc.Id);
                StoredBefore.Lat = 53.325241;
                repo.Update(StoredBefore);
                //verify
                Location stored = repo.GetById(loc.Id);
                Assert.IsTrue(loc.Lat == stored.Lat);
            }
        }
Ejemplo n.º 2
0
 public void TestEntityDbReadLoad()
 {
     try
     {
         int  ReadTestInterations = 250;
         int  maxQueryTimeMs      = 25;
         bool ReadSuccess         = false;
         int  FailCount           = 0;
         TestRepoCreate();
         Stopwatch watch = new Stopwatch();
         iotRepository <iotDomain> repo    = new iotRepository <iotDomain>();
         List <iotDomain>          domains = repo.GetAll().ToList();
         iotDomain domain = domains.First();
         watch.Start();
         for (int i = 0; i < ReadTestInterations; i++)
         {
             ReadSuccess = TestRepoSingleRead(domain.Id);
             if (!ReadSuccess)
             {
                 FailCount++;
             }
         }
         watch.Stop();
         double TimePerQueryMs = watch.ElapsedMilliseconds / ReadTestInterations;
         Assert.IsTrue(TimePerQueryMs < maxQueryTimeMs);
     }
     catch (Exception ex)
     {
         Assert.Fail();
     }
 }
Ejemplo n.º 3
0
        public void TestConnectorRepo()
        {
            iotRepository <iotDomain> repo    = new iotRepository <iotDomain>();
            List <iotDomain>          domains = repo.GetAll().ToList();

            Assert.IsTrue(domains != null);
        }
Ejemplo n.º 4
0
        private void AddPropertyForMapperAndDevice(sconnConfigMapper maper, Device edited, int DevNo)
        {
            try
            {
                iotRepository <DeviceProperty> proprepo = new iotRepository <DeviceProperty>();
                DeviceProperty prop = new DeviceProperty();
                prop.PropertyName   = "Input" + maper.SeqNumber;  //TODO read from name cfg
                prop.Device         = edited;
                prop.LastUpdateTime = DateTime.Now;
                proprepo.Add(prop);
                List <DeviceProperty> storeprops = proprepo.GetAll().ToList();
                DeviceProperty        storedProp = (from s in storeprops
                                                    where s.PropertyName == prop.PropertyName
                                                    select s).First();

                //create parameter and bind mapper to it
                iotRepository <DeviceParameter> paramrepo = new iotRepository <DeviceParameter>();
                DeviceParameter param = new DeviceParameter();
                param.Value    = sconnConfigToStringVal(maper, site.siteCfg.deviceConfigs[DevNo]);
                param.Type     = ParamTypeForSconnMapper(maper);
                param.Property = storedProp;
                paramrepo.Add(param);
                List <DeviceParameter> storeparams = paramrepo.GetAll().ToList();
                DeviceParameter        storedParam = (from p in storeparams
                                                      where p.Property == param.Property
                                                      select p).First();

                maper.Parameter = storedParam;
                iotRepository <sconnConfigMapper> mapperRepo = new iotRepository <sconnConfigMapper>();
                mapperRepo.Add(maper);
            }
            catch (Exception e)
            {
            }
        }
Ejemplo n.º 5
0
        public void TestRepoRead()
        {
            iotRepository <Location> repo = new iotRepository <Location>();
            List <Location>          locs = repo.GetAll().ToList();

            Assert.IsTrue(locs != null);
        }
Ejemplo n.º 6
0
 public List <Device> GetAllDevice()
 {
     try
     {
         iotRepository <Device> repo = new iotRepository <Device>();
         return(repo.GetAll().ToList());
     }
     catch (Exception ex)
     {
         throw new FaultException(ex.Message);
     }
 }
Ejemplo n.º 7
0
        public void TestRepoCreate()
        {
            iotRepository <iotDomain> locrepo = new iotRepository <iotDomain>();
            iotDomain dm = new iotDomain();

            dm.DomainName = Guid.NewGuid().ToString();
            dm.Sites      = new List <Site>();
            locrepo.Add(dm);
            List <iotDomain> locs = locrepo.GetAll().ToList();

            Assert.IsTrue(locs.Contains(dm));
            locrepo.Delete(dm);
        }
Ejemplo n.º 8
0
 public List <DeviceAction> DeviceActions()
 {
     try
     {
         iotRepository <DeviceAction> repo = new iotRepository <DeviceAction>();
         List <DeviceAction>          acts = repo.GetAll().ToList();
         return(acts);
     }
     catch (Exception e)
     {
         nlogger.ErrorException(e.Message, e);
         return(new List <DeviceAction>());
     }
 }
Ejemplo n.º 9
0
 public List <DeviceCredentials> DeviceCredentials()
 {
     try
     {
         iotRepository <DeviceCredentials> repo  = new iotRepository <DeviceCredentials>();
         List <DeviceCredentials>          creds = repo.GetAll().ToList();
         return(creds);
     }
     catch (Exception e)
     {
         nlogger.ErrorException(e.Message, e);
         return(new List <DeviceCredentials>());
     }
 }
Ejemplo n.º 10
0
 public List <ActionParameter> ActionParams()
 {
     try
     {
         iotRepository <ActionParameter> repo = new iotRepository <ActionParameter>();
         List <ActionParameter>          acts = repo.GetAll().ToList();
         return(acts);
     }
     catch (Exception e)
     {
         nlogger.ErrorException(e.Message, e);
         return(new List <ActionParameter>());
     }
 }
Ejemplo n.º 11
0
 public List <DeviceType> DeviceTypes()
 {
     try
     {
         iotRepository <DeviceType> repo = new iotRepository <DeviceType>();
         List <DeviceType>          devt = repo.GetAll().ToList();
         return(devt);
     }
     catch (Exception e)
     {
         nlogger.ErrorException(e.Message, e);
         return(new List <DeviceType>());
     }
 }
Ejemplo n.º 12
0
 public List <Location> Locations()
 {
     try
     {
         iotRepository <Location> repo = new iotRepository <Location>();
         List <Location>          locs = repo.GetAll().ToList();
         return(locs);
     }
     catch (Exception e)
     {
         nlogger.ErrorException(e.Message, e);
         return(new List <Location>());
     }
 }
Ejemplo n.º 13
0
 public List <DeviceParameter> DeviceParameters()
 {
     try
     {
         iotRepository <DeviceParameter> repo   = new iotRepository <DeviceParameter>();
         List <DeviceParameter>          devpar = repo.GetAll().ToList();
         return(devpar);
     }
     catch (Exception e)
     {
         nlogger.ErrorException(e.Message, e);
         return(new List <DeviceParameter>());
     }
 }
Ejemplo n.º 14
0
 public List <DeviceProperty> DeviceProperties()
 {
     try
     {
         iotRepository <DeviceProperty> repo  = new iotRepository <DeviceProperty>();
         List <DeviceProperty>          props = repo.GetAll().ToList();
         return(props);
     }
     catch (Exception e)
     {
         nlogger.ErrorException(e.Message, e);
         return(new List <DeviceProperty>());
     }
 }
Ejemplo n.º 15
0
 public List <EndpointInfo> Endpoints()
 {
     try
     {
         iotRepository <EndpointInfo> repo = new iotRepository <EndpointInfo>();
         List <EndpointInfo>          endp = repo.GetAll().ToList();
         return(endp);
     }
     catch (Exception e)
     {
         nlogger.ErrorException(e.Message, e);
         return(new List <EndpointInfo>());
     }
 }
Ejemplo n.º 16
0
        /**************************** Get ****************************/


        public List <iotDomain> Domains()
        {
            try
            {
                iotRepository <iotDomain> repo    = new iotRepository <iotDomain>();
                List <iotDomain>          domains = repo.GetAll().ToList();
                return(domains);
            }
            catch (Exception e)
            {
                nlogger.ErrorException(e.Message, e);
                return(new List <iotDomain>());
            }
        }
Ejemplo n.º 17
0
        private bool LoadConfigToDevice(Device dev)
        {
            try
            {
                //iotConnector connt = new iotConnector();
                //Device edited = connt.DeviceList().Where(n => n.DeviceId == dev.DeviceId).First();
                iotRepository <Device> devrep = new iotRepository <Device>();
                Device edited = devrep.GetById(dev.DeviceId);

                int devAddr = IndexForHostDevice();
                //Reload properties and actions if they changed
                //Update

                int inputs = site.siteCfg.deviceConfigs[devAddr].memCFG[ipcDefines.mAdrInputsNO];
                if (edited.Properties.Count != inputs)
                {
                    //clear current properies


                    //load
                    for (int i = 0; i < inputs; i++)
                    {
                        sconnConfigMapper maper = new sconnConfigMapper();
                        maper.ConfigType = ipcDefines.mAdrInput;
                        maper.SeqNumber  = i;
                        AddPropertyForMapperAndDevice(maper, edited, devAddr);
                    }
                }
                else //update
                {
                    foreach (var item in edited.Properties)
                    {
                        //get parameter
                        // List<DeviceParameter> propparams = (from par in item.ResultParameters
                        //                         select par).ToList();
                        DeviceParameter param = item.ResultParameters.ElementAt(0);
                        param.Value = sconnConfigToStringVal(param.sconnMappers.ElementAt(0), site.siteCfg.deviceConfigs[devAddr]);

                        //iotRepository<DeviceParameter> repo = new iotRepository<DeviceParameter>();
                        //repo.Update(param);
                        //cont.SaveChanges();

                        if (param != null)
                        {
                            //get input mapper
                            sconnConfigMapper maper = (from cm in param.sconnMappers
                                                       select cm).FirstOrDefault();
                            if (maper != null)
                            {
                                param.Value = sconnConfigToStringVal(maper, site.siteCfg.deviceConfigs[devAddr]);
                                // cont.SaveChanges();
                            }
                        }
                    }
                }

                int outputs = site.siteCfg.deviceConfigs[devAddr].memCFG[ipcDefines.mAdrOutputsNO];
                int relays  = site.siteCfg.deviceConfigs[devAddr].memCFG[ipcDefines.mAdrRelayNO];
                if (edited.Actions.Count != outputs + relays)
                {
                    //remove existing
                    if (edited.Actions.Count > 0)
                    {
                        iotRepository <DeviceAction> actrep = new iotRepository <DeviceAction>();
                        List <DeviceAction>          acts   = actrep.GetAll().ToList();
                        for (int i = 0; i < acts.Count; i++)
                        {
                            actrep.Delete(acts.ElementAt(i));
                        }
                    }

                    for (int i = 0; i < outputs; i++)
                    {
                        sconnConfigMapper maper = new sconnConfigMapper();
                        maper.ConfigType = ipcDefines.mAdrOutput;
                        maper.SeqNumber  = i;
                        AddActionForMapperAndDevice(maper, edited, devAddr);
                    }

                    for (int i = 0; i < relays; i++)
                    {
                        sconnConfigMapper maper = new sconnConfigMapper();
                        maper.ConfigType = ipcDefines.mAdrRelay;
                        maper.SeqNumber  = i;
                        AddActionForMapperAndDevice(maper, edited, devAddr);
                    }
                }
                else
                {
                    foreach (var item in edited.Actions)
                    {
                        //get action
                        DeviceParameter param = (from par in item.ResultParameters
                                                 select par).FirstOrDefault();
                        if (param != null)
                        {
                            //get input mapper
                            sconnConfigMapper maper = (from cm in param.sconnMappers
                                                       select cm).FirstOrDefault();
                            if (maper != null)
                            {
                                param.Value = sconnConfigToStringVal(maper, site.siteCfg.deviceConfigs[devAddr]);
                                param.Type  = param.Type;
                                // cont.SaveChanges();
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                return(false);
            }

            return(true);
        }