public IData GetDataForDevice(IOwnedDevice device) { IControlToken token; if (MemberTokens.TryGetValue(device, out token)) { return(token.GetDataForDevice(device)); } if (AutoAddDevices) { token = device.TakeControl(priority: Priority, name: Name); Add(device, token); return(token.GetDataForDevice(device)); } var sod = device as SingleOwnerDevice; if (sod != null) { return(sod.GetOwnerlessData()); } throw new ArgumentException("Unhandled device"); }
/// <summary> /// Lock if group token is configured for auto add /// </summary> /// <param name="device"></param> /// <returns>True if device is controlled by this group token</returns> public bool LockAndGetDataFromDevice(IOwnedDevice device) { if (MemberTokens.ContainsKey(device)) { return(true); } if (!AutoAddDevices) { return(false); } // Add MemberTokens.Add(device, device.TakeControl(Priority, Name)); return(true); }
protected override bool AuthorizeCore(HttpContextBase httpContext) { if (!(AppSession.Parameters.AppApiEnabled.Value == "true")) { return(false); } if (httpContext == null) { throw new ArgumentNullException("httpContext"); } String Email = httpContext.Request.Headers["X-API-MEMBER-EMAIL"]; String Token = httpContext.Request.Headers["X-API-MEMBER-TOKEN"]; if (Email == null && Token == null) { return(false); } Member Member = Web.Admin.Logic.Collections.Members.GetByEmail(Email); if (Member.MemberID > 0) { List <Role> Roles = Web.Admin.Logic.Collections.Roles.GetByMember(Member.MemberID); string[] _roles = this.Roles.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries); foreach (string role in _roles) { Role _Role = Roles.Where(t => t.Name.ToLower() == role.ToLower()).FirstOrDefault(); if (_Role != default(Role)) { MemberToken MemberToken = MemberTokens.GetByMember(Member.MemberID); if (MemberToken.Token == Token) { return(true); } } } } return(false); }
public void Add(IOwnedDevice device, IControlToken token) { MemberTokens.Add(device, token); }
//public void PushData(DataElements dataElement, object value) //{ // foreach (var memberToken in MemberTokens.Values) // memberToken.PushData(dataElement, value); //} public bool IsOwner(IControlToken checkToken) { return(MemberTokens.ContainsValue(checkToken)); }