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 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 TestConnectorRepo() { iotRepository <iotDomain> repo = new iotRepository <iotDomain>(); List <iotDomain> domains = repo.GetAll().ToList(); Assert.IsTrue(domains != null); }
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) { } }
public void TestRepoRead() { iotRepository <Location> repo = new iotRepository <Location>(); List <Location> locs = repo.GetAll().ToList(); Assert.IsTrue(locs != null); }
public List <Device> GetAllDevice() { try { iotRepository <Device> repo = new iotRepository <Device>(); return(repo.GetAll().ToList()); } catch (Exception ex) { throw new FaultException(ex.Message); } }
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 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>()); } }
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>()); } }
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>()); } }
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>()); } }
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>()); } }
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>()); } }
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>()); } }
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>()); } }
/**************************** 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>()); } }
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); }