Beispiel #1
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)
            {
            }
        }
        /****  LOAD ****/

        public void TestEntityDbWriteLoad()
        {
            try
            {
                int       ReadTestInterations = 5;
                int       maxQueryTimeMs      = 25;
                Stopwatch watch = new Stopwatch();
                watch.Start();
                for (int i = 0; i < ReadTestInterations; i++)
                {
                    iotRepository <Location> locrepo = new iotRepository <Location>();
                    Location loc = new Location();
                    loc.LocationName = Guid.NewGuid().ToString();
                    loc.Lat          = 0;
                    loc.Lng          = 0;
                    locrepo.Add(loc);
                }
                watch.Stop();
                double TimePerQueryMs = watch.ElapsedMilliseconds / ReadTestInterations;
                Assert.IsTrue(TimePerQueryMs < maxQueryTimeMs);
            }
            catch (Exception ex)
            {
                Assert.Fail();
            }
        }
        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);
            }
        }
        public void TestConnectorRepo()
        {
            iotRepository <iotDomain> repo    = new iotRepository <iotDomain>();
            List <iotDomain>          domains = repo.GetAll().ToList();

            Assert.IsTrue(domains != null);
        }
 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();
     }
 }
        public void TestRepoRead()
        {
            iotRepository <Location> repo = new iotRepository <Location>();
            List <Location>          locs = repo.GetAll().ToList();

            Assert.IsTrue(locs != null);
        }
Beispiel #7
0
 public List <Device> GetAllDevice()
 {
     try
     {
         iotRepository <Device> repo = new iotRepository <Device>();
         return(repo.GetAll().ToList());
     }
     catch (Exception ex)
     {
         throw new FaultException(ex.Message);
     }
 }
 public EndpointInfo EndpointWithId(int id)
 {
     try
     {
         iotRepository <EndpointInfo> repo = new iotRepository <EndpointInfo>();
         return(repo.GetById(id));
     }
     catch (Exception e)
     {
         nlogger.ErrorException(e.Message, e);
         return(new EndpointInfo());
     }
 }
 public DeviceCredentials DeviceCredentialWithId(int id)
 {
     try
     {
         iotRepository <DeviceCredentials> repo = new iotRepository <DeviceCredentials>();
         return(repo.GetById(id));
     }
     catch (Exception e)
     {
         nlogger.ErrorException(e.Message, e);
         return(new DeviceCredentials());
     }
 }
 public ActionParameter ActionParamWithId(int id)
 {
     try
     {
         iotRepository <ActionParameter> repo = new iotRepository <ActionParameter>();
         return(repo.GetById(id));
     }
     catch (Exception e)
     {
         nlogger.ErrorException(e.Message, e);
         return(new ActionParameter());
     }
 }
 public iotDomain DomainWithId(int id)
 {
     try
     {
         iotRepository <iotDomain> repo = new iotRepository <iotDomain>();
         return(repo.GetById(id));
     }
     catch (Exception e)
     {
         nlogger.ErrorException(e.Message, e);
         return(new iotDomain());
     }
 }
 public int AddDevice(Device Device)
 {
     try
     {
         iotRepository <Device> repo = new iotRepository <Device>();
         repo.Add(Device);
         return(Device.Id);
     }
     catch (Exception ex)
     {
         throw new FaultException(ex.Message);
     }
 }
 public bool UpdateDevice(Device Device)
 {
     try
     {
         iotRepository <Device> repo = new iotRepository <Device>();
         repo.Update(Device);
         return(true);
     }
     catch (Exception ex)
     {
         throw new FaultException(ex.Message);
     }
 }
Beispiel #14
0
 public Device GetDevice(string id)
 {
     try
     {
         int DeviceId = Convert.ToInt32(id);
         iotRepository <Device> repo = new iotRepository <Device>();
         return(repo.GetById(DeviceId));
     }
     catch (Exception ex)
     {
         throw new FaultException(ex.Message);
     }
 }
 public bool TestRepoSingleRead(int id)
 {
     try
     {
         iotRepository <Location> repo = new iotRepository <Location>();
         Location locs = repo.GetById(id);
         return(locs != null);
     }
     catch (Exception ex)
     {
         return(false);
     }
 }
        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);
        }
 public DeviceType DeviceTypeWithId(int id)
 {
     try
     {
         iotRepository <DeviceType> repo = new iotRepository <DeviceType>();
         return(repo.GetById(id));
     }
     catch (Exception e)
     {
         nlogger.ErrorException(e.Message, e);
         return(new DeviceType());
     }
 }
 public bool SiteUpdate(Site domain)
 {
     try
     {
         iotRepository <Site> repo = new iotRepository <Site>();
         repo.Update(domain);
         return(true);
     }
     catch (Exception e)
     {
         nlogger.ErrorException(e.Message, e);
         return(false);
     }
 }
 public bool ActionUpdate(DeviceAction domain)
 {
     try
     {
         iotRepository <DeviceAction> repo = new iotRepository <DeviceAction>();
         repo.Update(domain);
         return(true);
     }
     catch (Exception e)
     {
         nlogger.ErrorException(e.Message, e);
         return(false);
     }
 }
 public bool ResParamUpdate(DeviceParameter domain)
 {
     try
     {
         iotRepository <DeviceParameter> repo = new iotRepository <DeviceParameter>();
         repo.Update(domain);
         return(true);
     }
     catch (Exception e)
     {
         nlogger.ErrorException(e.Message, e);
         return(false);
     }
 }
        /******************* Add ***********************/

        public bool DeviceAdd(Device dev)
        {
            try
            {
                iotRepository <Device> repo = new iotRepository <Device>();
                repo.Add(dev);
                return(true);
            }
            catch (Exception e)
            {
                nlogger.ErrorException(e.Message, e);
                return(false);
            }
        }
 public bool PropertyRemove(DeviceProperty domain)
 {
     try
     {
         iotRepository <DeviceProperty> repo = new iotRepository <DeviceProperty>();
         repo.Delete(domain);
         return(true);
     }
     catch (Exception e)
     {
         nlogger.ErrorException(e.Message, e);
         return(false);
     }
 }
        public String GetSomeJson()
        {
            try
            {
            }
            catch (Exception ex)
            {
                _logger.ErrorException(ex.Message, ex);
            }
            iotRepository <Device> repo = new iotRepository <Device>();
            Device dev = repo.GetById(52);

            return(JsonConvert.SerializeObject(dev));
        }
 public bool ReqParamRemove(ActionParameter domain)
 {
     try
     {
         iotRepository <ActionParameter> repo = new iotRepository <ActionParameter>();
         repo.Delete(domain);
         return(true);
     }
     catch (Exception e)
     {
         nlogger.ErrorException(e.Message, e);
         return(false);
     }
 }
 public bool LocationRemove(Location domain)
 {
     try
     {
         iotRepository <Location> repo = new iotRepository <Location>();
         repo.Delete(domain);
         return(true);
     }
     catch (Exception e)
     {
         nlogger.ErrorException(e.Message, e);
         return(false);
     }
 }
 public bool ActionAdd(DeviceAction action)
 {
     try
     {
         iotRepository <DeviceAction> repo = new iotRepository <DeviceAction>();
         repo.Add(action);
         return(true);
     }
     catch (Exception e)
     {
         nlogger.ErrorException(e.Message, e);
         return(false);
     }
 }
 public bool DeviceCredentialsRemove(DeviceCredentials creds)
 {
     try
     {
         iotRepository <DeviceCredentials> repo = new iotRepository <DeviceCredentials>();
         repo.Delete(creds);
         return(true);
     }
     catch (Exception e)
     {
         nlogger.ErrorException(e.Message, e);
         return(false);
     }
 }
 public bool DeviceTypeRemove(DeviceType type)
 {
     try
     {
         iotRepository <DeviceType> repo = new iotRepository <DeviceType>();
         repo.Delete(type);
         return(true);
     }
     catch (Exception e)
     {
         nlogger.ErrorException(e.Message, e);
         return(false);
     }
 }
 public bool EndpointRemove(EndpointInfo endp)
 {
     try
     {
         iotRepository <EndpointInfo> repo = new iotRepository <EndpointInfo>();
         repo.Delete(endp);
         return(true);
     }
     catch (Exception e)
     {
         nlogger.ErrorException(e.Message, e);
         return(false);
     }
 }
 public bool SiteAdd(Site site)
 {
     try
     {
         iotRepository <Site> repo = new iotRepository <Site>();
         repo.Add(site);
         return(true);
     }
     catch (Exception e)
     {
         nlogger.ErrorException(e.Message, e);
         return(false);
     }
 }