/// <summary> /// Registers the given device with Live ID /// </summary> /// <param name="applicationId">ID for the application</param> /// <returns>ClientCredentials that were registered</returns> public static DeviceCredentials RegisterDevice(Guid applicationId) { //Create the credentials DeviceCredentials credentials = GenerateCredentials(); //Execute the registration request string puid = ExecuteRegistrationRequest(LiveIdConstants.RegistrationEndpointUri, CreateRegistrationEnvelope( LiveIdConstants.DevicePrefix, applicationId, credentials.DeviceName, credentials.Password)); //Read the result return(credentials); }
public static Device GetFakeAlarmDevice() { Device fakeDevice = new Device(); DeviceCredentials fakeCredentials = new DeviceCredentials(); fakeCredentials.Fake(); fakeDevice.Credentials = fakeCredentials; EndpointInfo fakeEndpointInfo = new EndpointInfo(); fakeEndpointInfo.Fake(); fakeDevice.EndpInfo = fakeEndpointInfo; fakeDevice.Fake(); return(fakeDevice);; }
public bool DeviceCredentialsRemove(DeviceCredentials creds) { try { iotSharedEntityContext <DeviceCredentials> propCont = new iotSharedEntityContext <DeviceCredentials>(); propCont.Delete(creds); 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 DeviceCredentials DeviceCredentialWithId(int CredId) { try { iotSharedEntityContext <DeviceCredentials> devCont = new iotSharedEntityContext <DeviceCredentials>(); DeviceCredentials dev = devCont.GetById(CredId); if (dev != null) { return(dev); } return(null); } catch (Exception e) { nlogger.ErrorException(e.Message, e); return(new DeviceCredentials()); } }
public Device GetDevice() { Device dev = new Device(); UpdateSite(); LoadConfigToDevice(dev); ApplicationDbContext cont = new ApplicationDbContext(); dev.DeviceName = Guid.NewGuid().ToString(); EndpointInfo epi = (from ep in cont.Endpoints where ep.Hostname == this.site.serverIP && ep.Port == this.site.serverPort select ep).First(); if (epi != null) { dev.EndpInfo = epi; } DeviceCredentials cred = (from c in cont.Credentials where c.Password == this.site.authPasswd select c).First(); if (cred != null) { dev.Credentials = cred; } DeviceType type = (from dt in cont.Types where dt.TypeName.Equals("sconnMB") select dt).First(); if (type != null) { dev.Type = type; } else { //add type } return(dev); }
private async void StartConnect() { if (skipScan) // running on iOS. Scan is not supported { IsPairing = true; OnPropertyChanged("IsPairing"); await Pair(); return; } credentials = await(await IoTCentral.Current.GetServiceClient()).GetCredentials(IoTCentral.Current.Application.Id); credentials.DeviceId = IoTCentral.Current.Device.DeviceId; using (var hmac = new HMACSHA256(Convert.FromBase64String(credentials.PrimaryKey))) //get device key { sasKey = Convert.ToBase64String(hmac.ComputeHash(Encoding.UTF8.GetBytes(credentials.DeviceId))); } IsPairing = true; OnPropertyChanged("IsPairing"); await Scan(); }
public bool SetDeviceCredentials(DeviceCredentials creds) { try { iotSharedEntityContext <DeviceCredentials> propCont = new iotSharedEntityContext <DeviceCredentials>(); DeviceCredentials stored = propCont.GetById(creds.Id); if (stored != null) { stored = creds; propCont.UpdateWithHistory(stored); return(true); } return(false); } catch (Exception e) { nlogger.ErrorException(e.Message, e); return(false); } }
public ServiceParameter(DeviceCredentials deviceCredentials, string bLEDeviceId, Dictionary <string, string> telemetryMap) { DeviceCredentials = deviceCredentials; BLEDeviceId = bLEDeviceId; TelemetryMap = telemetryMap; }
public AlarmSystemConfigManager(EndpointInfo endp, DeviceCredentials cred) : this() { info = endp; creds = cred; }
public Device DeviceAddWithParamsEntity(string SiteId, string Name, string Host, string Port, string Login, string Pass, string Type, string Loc, string Prot, int DomainId, bool IsVirtual) { try { iotContext context = new iotContext(); iotDomain domain = context.Domains.First(d => d.Id == DomainId); if (domain != null) { int LocId = int.Parse(Loc); int DevTypeId = int.Parse(Type); Device ndev = new Device(); ndev.DeviceName = Name; List <DeviceType> types = domain.DeviceTypes.ToList(); DeviceType type = (from t in types where t.Id == DevTypeId select t).First(); List <Location> locs = domain.Locations.ToList(); Location loc = (from l in locs where l.Id == LocId select l).First(); ndev.Type = type; ndev.DeviceLocation = loc; DeviceCredentials cred = new DeviceCredentials(); cred.PasswordExpireDate = DateTime.Now.AddYears(100); cred.PermissionExpireDate = DateTime.Now.AddYears(100); cred.Password = Pass; cred.Username = Login; context.Credentials.Add(cred); context.SaveChanges(); DeviceCredentials storedCredentials = context.Credentials.First(c => c.Username.Equals(cred.Username) && c.Password.Equals(cred.Password)); EndpointInfo info = new EndpointInfo(); info.Hostname = Host; info.Port = int.Parse(Port); info.Domain = domain; //TODO //CommProtocolType protocol = (CommProtocolType)Prot; //int.Parse(Prot); //info.EnableProtocolSupport(protocol); info.SupportsSconnProtocol = true; context.Endpoints.Add(info); context.SaveChanges(); EndpointInfo storedInfo = context.Endpoints.First(e => e.Hostname.Equals(info.Hostname) && e.Port == info.Port); if (storedInfo == null) { return(null); } int siteIdNum = int.Parse(SiteId); Site siteToAppend = domain.Sites.First(s => s.Id == siteIdNum); ndev.Site = siteToAppend; ndev.Credentials = storedCredentials; ndev.EndpInfo = storedInfo; ndev.IsVirtual = IsVirtual; context.Devices.Add(ndev); context.SaveChanges(); Device stored = context.Devices.First(d => d.DeviceName.Equals(ndev.DeviceName) && d.EndpInfo.Hostname.Equals(ndev.EndpInfo.Hostname)); //update device if (!ndev.IsVirtual) { UpdateDeviceProperties(stored); } else { DeviceFillWithSampleProperties(ndev); } return(stored); } return(null); } catch (Exception e) { nlogger.ErrorException(e.Message, e); return(null); } }
/************************ ADD/REMOVE WITH PARAM ********************/ public Device DeviceAddWithParams(string SiteId, string Name, string Host, string Port, string Login, string Pass, string Type, string Loc, string Prot) { try { iotContext cont = new iotContext(); int LocId = int.Parse(Loc); int DevTypeId = int.Parse(Type); Device ndev = new Device(); ndev.DeviceName = Name; List <DeviceType> types = cont.Types.ToList(); DeviceType type = (from t in types where t.Id == DevTypeId select t).First(); List <Location> locs = cont.Locations.ToList(); Location loc = (from l in locs where l.Id == LocId select l).First(); ndev.Type = type; ndev.DeviceLocation = loc; DeviceCredentials cred = new DeviceCredentials(); cred.PasswordExpireDate = DateTime.Now.AddYears(100); cred.PermissionExpireDate = DateTime.Now.AddYears(100); cred.Password = Pass; cred.Username = Login; cont.Credentials.Add(cred); cont.SaveChanges(); List <DeviceCredentials> creds = cont.Credentials.ToList(); DeviceCredentials storedCredentials = (from c in creds where c.Username.Equals(cred.Username) select c).FirstOrDefault(); EndpointInfo info = new EndpointInfo(); info.Hostname = Host; info.Port = int.Parse(Port); //TODO //CommProtocolType protocol = (CommProtocolType)Prot; //int.Parse(Prot); //info.EnableProtocolSupport(protocol); info.SupportsSconnProtocol = true; cont.Endpoints.Add(info); cont.SaveChanges(); List <EndpointInfo> endps = cont.Endpoints.ToList(); EndpointInfo storedInfo = (from i in endps where i.Hostname.Equals(info.Hostname) && i.Port == info.Port select i).FirstOrDefault(); if (storedInfo == null) { //err return(null); } ndev.Credentials = storedCredentials; ndev.EndpInfo = storedInfo; int siteIdNum = int.Parse(SiteId); List <Site> sites = cont.Sites.ToList(); Site siteToAppend = (from s in sites where s.Id == siteIdNum select s).FirstOrDefault(); ndev.Site = siteToAppend; cont.Devices.Add(ndev); cont.SaveChanges(); List <Device> devs = cont.Devices.ToList(); Device stored = (from d in devs where d.DeviceName.Equals(ndev.DeviceName) && d.EndpInfo.Hostname.Equals(ndev.EndpInfo.Hostname) select d).FirstOrDefault(); //update device UpdateDeviceProperties(stored); return(stored); } catch (Exception e) { nlogger.ErrorException(e.Message, e); return(null); } }