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 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 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 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 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 bool DeleteDevice(string id) { try { int DeviceId = Convert.ToInt32(id); iotRepository <Device> repo = new iotRepository <Device>(); Device dev = repo.GetById(DeviceId); repo.Delete(dev); return(true); } catch (Exception ex) { throw new FaultException(ex.Message); } }
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); }