public ResultType UpdateDoorState(Int32 deviceId, Int32 doorIndex, DoorControlOption option) { Log.Info("Invoke WebSocketOperation..."); var operation = new WebSocketOperation(deviceId); var updateDoorStateRequest = new UpdateDoorStateRequest() { Token = operation.Token, DoorIndex = doorIndex, Option = option }; string rawRequest = DataContractSerializationHelper.Serialize(updateDoorStateRequest); Log.DebugFormat("Request: {0}", rawRequest); var rawResponse = operation.Execute(rawRequest); Log.DebugFormat("Response: {0}", rawResponse); var response = DataContractSerializationHelper.Deserialize <UpdateDoorStateResponse>(rawResponse); Log.InfoFormat("Update door index:[{0}] for device id:[{1}], result:[{2}]", doorIndex, deviceId, response.ResultType); if (response.ResultType != ResultType.OK && response.ResultType != ResultType.NotSupport) { throw new Exception(string.Format("Update door index:[{0}] for device id:[{1}], result:[{2}]", doorIndex, deviceId, response.ResultType)); } return(response.ResultType); }
public bool GetDoorState(Int32 deviceId, Int32 doorIndex) { Log.Info("Invoke WebSocketOperation..."); var operation = new WebSocketOperation(deviceId); var getDoorStateRequest = new GetDoorStateRequest() { Token = operation.Token, DoorIndex = doorIndex }; string rawRequest = DataContractSerializationHelper.Serialize(getDoorStateRequest); Log.DebugFormat("Request: {0}", rawRequest); var rawResponse = operation.Execute(rawRequest); Log.DebugFormat("Response: {0}", rawResponse); var response = DataContractSerializationHelper.Deserialize <GetDoorStateResponse>(rawResponse); Log.InfoFormat("Get door state, index:[{0}] for device id:[{1}], result:[{2}]", doorIndex, deviceId, response.ResultType); if (response.ResultType != ResultType.OK) { throw new Exception(string.Format("Get door state, index:[{0}] for device id:[{1}], result:[{2}]", doorIndex, deviceId, response.ResultType)); } return(response.DoorStateInfo.Opened); }
public UserInfo TryGetUesrInfo(User user, DeviceController device) { if (user == null || device == null) { return(null); } Log.Info("Trying to get user device info..."); var deviceUserId = user.UserCode.ToInt32(); var deviceID = device.Code.ToInt32(); var deviceCode = device.Code.ToInt32(); var operation = new WebSocketOperation(deviceCode); var getUserInfoRequest = new GetUserInfoRequest() { Token = operation.Token, UserId = deviceUserId }; string rawRequest = DataContractSerializationHelper.Serialize(getUserInfoRequest); var rawResponse = operation.Execute(rawRequest); if (string.IsNullOrWhiteSpace(rawResponse)) { throw new Exception(string.Format("Getting user id:[{0}], device user id:[{1}] from device id:[{2}]. Response is empty, maybe the device is not register to device system.", user.UserID, deviceUserId, deviceID)); } var response = DataContractSerializationHelper.Deserialize <GetUserInfoResponse>(rawResponse); Log.InfoFormat("Getting user id:[{0}], device user id:[{1}] from device id:[{2}], result:[{3}]", user.UserID, deviceUserId, deviceID, response.ResultType); return(response.ResultType == ResultType.OK ?response.UserInfo : null); }
public DeviceInfo GetDeviceInfo(Int32 deviceId) { Log.Info("Invoke WebSocketOperation..."); var operation = new WebSocketOperation(deviceId); var getDeviceInfoRequest = new GetDeviceInfoRequest() { Token = operation.Token }; string rawRequest = DataContractSerializationHelper.Serialize(getDeviceInfoRequest); Log.DebugFormat("Request: {0}", rawRequest); var rawResponse = operation.Execute(rawRequest); Log.DebugFormat("Response: {0}", rawResponse); var response = DataContractSerializationHelper.Deserialize <GetDeviceInfoResponse>(rawResponse); Log.InfoFormat("Get device info for device id:[{0}], result:[{1}]", deviceId, response.ResultType); if (response.ResultType != ResultType.OK) { throw new Exception(string.Format("Get device info for device id:[{0}], result:[{1}]", deviceId, response.ResultType)); } return(response.Service); }
public List <UserInfo> QueryUsersByDevice(DeviceController device) { if (device == null) { return(null); } var deviceID = device.Code.ToInt32(); var deviceCode = device.Code.ToInt32(); var operation = new WebSocketOperation(deviceCode); var getAllUsersRequest = new GetAllUsersRequest() { Token = operation.Token }; string rawRequest = DataContractSerializationHelper.Serialize(getAllUsersRequest); var rawResponse = operation.Execute(rawRequest); if (string.IsNullOrWhiteSpace(rawResponse)) { throw new Exception(string.Format("Query users from device id:[{0}]. Response is empty, maybe the device is not register to device system.", deviceID)); } var response = DataContractSerializationHelper.Deserialize <GetAllUsersResponse>(rawResponse); Log.InfoFormat("Query users from device id:[{0}], result:[{1}]", deviceID, response.ResultType); return(response.ResultType == ResultType.OK ? response.Users.ToList() : null); }
public void ProcessRequest(HttpContext context) { var clients = WebSocketClientManager.GetInstance().GetAllClients(); Log.Debug("Read Http Request.."); String requestBody = ""; using (var reader = new System.IO.StreamReader(context.Request.InputStream, System.Text.Encoding.UTF8)) { requestBody = reader.ReadToEnd(); Log.DebugFormat("Raw request: {0}", requestBody); } var response = "response"; var token = ParseToken(requestBody); if (string.IsNullOrWhiteSpace(token)) { return; } if (clients.Any()) { var deviceID = clients.First().Id; var operation = new WebSocketOperation(deviceID); operation.Token = token; response = operation.Execute(requestBody); } context.Response.ContentType = "text/plain"; context.Response.Write(response); }
private void UpdateUserMS(User user, DeviceController deviceInfo, DeviceRole role) { var deviceId = deviceInfo.DeviceID; var devicePermission = role.DeviceRolePermissions.FirstOrDefault(x => x.DeviceID == deviceId); var deviceUser = new UserInfo(); deviceUser.UserId = user.UserCode.ToInt32(); deviceUser.Role = (Rld.DeviceSystem.Contract.Model.UserRole)devicePermission.PermissionAction.GetHashCode(); deviceUser.AccessTimeZoneId = devicePermission.AllowedAccessTimeZoneID; Log.Info("Invoke WebSocketOperation..."); var operation = new WebSocketOperation(deviceId); var updateUserInfoRequest = new UpdateUserInfoRequest() { Token = operation.Token, UserInfo = deviceUser }; string rawRequest = DataContractSerializationHelper.Serialize(updateUserInfoRequest); Log.DebugFormat("Request: {0}", rawRequest); var rawResponse = operation.Execute(rawRequest); Log.DebugFormat("Response: {0}", rawResponse); var response = DataContractSerializationHelper.Deserialize <UpdateUserInfoResponse>(rawResponse); Log.InfoFormat("Update user id:[{0}], device user id:[{1}] to device id:[{2}], result:[{3}]", user.UserID, deviceUser.UserId, deviceId, response.ResultType); if (response.ResultType != ResultType.OK) { throw new Exception(string.Format("Update user id:[{0}], device user id:[{1}] to device id:[{2}] fails]", user.UserID, deviceUser.UserId, deviceId)); } }
public IList <DeviceTrafficLog> QueryNewTrafficLogs(DeviceController device) { var operation = new WebSocketOperation(device.Code.ToInt32()); var getDeviceTrafficLogRequest = new GetDeviceTrafficLogRequest() { Token = operation.Token, BeginTime = new DateTime(2016, 1, 1), EndTime = new DateTime(2099, 12, 31), }; string rawRequest = DataContractSerializationHelper.Serialize(getDeviceTrafficLogRequest); var rawResponse = operation.Execute(rawRequest); var response = DataContractSerializationHelper.Deserialize <GetDeviceTrafficLogResponse>(rawResponse); Log.InfoFormat("GetDeviceTrafficLogResponse from device id:{0}, result ={1}", device.DeviceID, response.ResultType); if (response.ResultType != ResultType.OK) { throw new Exception(string.Format("GetDeviceTrafficLogResponse from device id:{0} fails", device.DeviceID)); } var deviceTrafficLogs = new List <DeviceTrafficLog>(); foreach (var rawlog in response.Logs) { var log = new DeviceTrafficLog() { DeviceID = device.DeviceID, DeviceUserID = rawlog.UserId, DeviceCode = device.Code, DeviceType = device.Model, DeviceSN = device.SN, RecordType = rawlog.AccessLogType.ToString(), RecordTime = rawlog.CreateTime, RecordUploadTime = DateTime.Now, Remark = rawlog.Message, }; if (rawlog.CheckInOptions.Any()) { log.AuthenticationType = 0; rawlog.CheckInOptions.ForEach(option => log.AuthenticationType += (int)option); } deviceTrafficLogs.Add(log); } return(deviceTrafficLogs); }
public IList <DeviceOperationLog> QueryNewOperationLogs(DeviceController device) { var operation = new WebSocketOperation(device.Code.ToInt32()); var getDeviceOperationLogRequest = new GetDeviceOperationLogRequest() { Token = operation.Token, BeginTime = new DateTime(2016, 1, 1), EndTime = new DateTime(2099, 12, 31), }; string rawRequest = DataContractSerializationHelper.Serialize(getDeviceOperationLogRequest); var rawResponse = operation.Execute(rawRequest); var response = DataContractSerializationHelper.Deserialize <GetDeviceOperationLogResponse>(rawResponse); Log.InfoFormat("GetDeviceOperationLogResponse from device id:{0}, result ={1}", device.DeviceID, response.ResultType); if (response.ResultType != ResultType.OK) { throw new Exception(string.Format("GetDeviceOperationLogResponse from device id:{0} fails", device.DeviceID)); } var deviceOperationLogs = new List <DeviceOperationLog>(); foreach (var rawlog in response.Logs) { deviceOperationLogs.Add(new DeviceOperationLog() { DeviceId = device.DeviceID, OperatorId = rawlog.AdminId, DeviceUserId = rawlog.UserId, DeviceCode = device.Code, DeviceType = device.Model, OperationType = rawlog.OperationType, OperationDescription = rawlog.Message, OperationContent = rawlog.Enroll.ToInt32() != ConvertorExtension.ConvertionFailureValue ? ((AuthenticationType)rawlog.Enroll.ToInt32()).ToString() : "未知", OperationTime = rawlog.CreateTime, OperationUploadTime = DateTime.Now, }); } return(deviceOperationLogs); }
private void DeleteUserMS(User user, DeviceController deviceInfo) { var deviceId = deviceInfo.DeviceID; var deviceUserId = user.UserCode.ToInt32(); Log.Info("Invoke WebSocketOperation..."); var operation = new WebSocketOperation(deviceId); var deleteUserInfoRequest = new DeleteUserInfoRequest() { Token = operation.Token, UserId = deviceUserId }; string rawRequest = DataContractSerializationHelper.Serialize(deleteUserInfoRequest); Log.DebugFormat("Request: {0}", rawRequest); var rawResponse = operation.Execute(rawRequest); Log.DebugFormat("Response: {0}", rawResponse); Log.Info("Deleting UserAuthentications from database..."); var authentications = user.UserAuthentications.FindAll(x => x.DeviceID == deviceId); authentications.ForEach(x => _userAuthenticationRepo.Delete(x.UserAuthenticationID)); }
public void DeleteUser(User user, DeviceController device) { if (user == null || device == null) { return; } var deviceID = device.DeviceID; var deviceCode = device.Code.ToInt32(); var userCode = user.UserCode.ToInt32(); Log.Info("Invoke WebSocketOperation..."); var operation = new WebSocketOperation(deviceCode); var deleteUserInfoRequest = new DeleteUserInfoRequest() { Token = operation.Token, UserId = userCode }; string rawRequest = DataContractSerializationHelper.Serialize(deleteUserInfoRequest); var rawResponse = operation.Execute(rawRequest); if (string.IsNullOrWhiteSpace(rawResponse)) { throw new Exception(string.Format("Delete user id:[{0}], device user id:[{1}] to device id:[{2}] fails. Response is empty, maybe the device is not register to device system.", user.UserID, userCode, deviceID)); } var response = DataContractSerializationHelper.Deserialize <DeleteUserInfoResponse>(rawResponse); Log.InfoFormat("Delete user id:[{0}], device user id:[{1}] to device id:[{2}], result:[{3}]", user.UserID, userCode, deviceID, response.ResultType); if (response.ResultType != ResultType.OK) { throw new Exception(string.Format("Delete user id:[{0}], device user id:[{1}] to device id:[{2}] fails.", user.UserID, userCode, deviceID)); } }
public void AddUser(User user, DeviceController device) { if (user == null || device == null) { return; } if (user.UserAuthentications == null || user.UserAuthentications.Count == 0) { return; } if (user.GetUserAccessableDeviceIds().Contains(device.DeviceID) == false) { return; } var deviceID = device.DeviceID; var deviceCode = device.Code.ToInt32(); Log.Info("Getting user authentication infos..."); var userAuthenticationsOfDevice = user.UserAuthentications.Where(a => a.DeviceID == deviceID); var authenticationsOfDevice = userAuthenticationsOfDevice as IList <UserAuthentication> ?? userAuthenticationsOfDevice.ToList(); Log.Info("Getting user permission infos..."); var deviceRoles = _deviceRole.Query(new Hashtable { { "Status", (int)GeneralStatus.Enabled } }).ToList(); var userDevicePermission = user.GetUserDeviceRoleAuthorizedPermissionByDeviceId(deviceID, deviceRoles); Log.Info("Building device user..."); var deviceUser = new UserInfo(); deviceUser.UserId = user.UserCode.ToInt32(); deviceUser.ExternalUserCode = user.UserID.ToString(); // user info deviceUser.UserName = user.Name; deviceUser.UserStatus = user.Status == GeneralStatus.Enabled; deviceUser.DepartmentId = user.DepartmentID; deviceUser.Comment = user.Remark; // user role deviceUser.Role = (Rld.DeviceSystem.Contract.Model.UserRole)userDevicePermission.PermissionAction.GetHashCode(); deviceUser.AccessTimeZoneId = userDevicePermission.AllowedAccessTimeZoneID; //user authentication foreach (var userAuthentication in authenticationsOfDevice) { switch (userAuthentication.AuthenticationType) { case AuthenticationType.FingerPrint1: case AuthenticationType.FingerPrint2: case AuthenticationType.FingerPrint3: case AuthenticationType.FingerPrint4: case AuthenticationType.FingerPrint5: case AuthenticationType.FingerPrint6: case AuthenticationType.FingerPrint7: case AuthenticationType.FingerPrint8: case AuthenticationType.FingerPrint9: case AuthenticationType.FingerPrint10: { var service = new FingerPrintService() { Index = (int)userAuthentication.AuthenticationType, Enabled = true }; service.FingerPrintData = userAuthentication.AuthenticationData; service.UseForDuress = userAuthentication.IsDuress; deviceUser.CredentialServices.Add(service); } break; case AuthenticationType.Password: { var service = new PasswordService() { Enabled = true }; service.Password = SimpleEncryption.Decode(userAuthentication.AuthenticationData); service.UseForDuress = userAuthentication.IsDuress; deviceUser.CredentialServices.Add(service); } break; case AuthenticationType.IcCard: { var service = new CredentialCardService() { Enabled = true }; service.CardNumber = userAuthentication.AuthenticationData; service.UseForDuress = userAuthentication.IsDuress; deviceUser.CredentialServices.Add(service); } break; default: break; } } Log.Info("Invoke WebSocketOperation..."); var operation = new WebSocketOperation(deviceCode); var createUserInfoRequest = new CreateUserInfoRequest() { Token = operation.Token, UserInfo = deviceUser }; string rawRequest = DataContractSerializationHelper.Serialize(createUserInfoRequest); var rawResponse = operation.Execute(rawRequest); if (string.IsNullOrWhiteSpace(rawResponse)) { throw new Exception(string.Format("Create user id:[{0}], device user id:[{1}] to device id:[{2}] fails. Response is empty, maybe the device is not register to device system.", user.UserID, deviceUser.UserId, deviceID)); } var response = DataContractSerializationHelper.Deserialize <CreateUserInfoResponse>(rawResponse); Log.InfoFormat("Create user id:[{0}], device user id:[{1}] to device id:[{2}], result:[{3}]", user.UserID, deviceUser.UserId, deviceID, response.ResultType); if (response.ResultType != ResultType.OK) { throw new Exception(string.Format("Create user id:[{0}], device user id:[{1}] to device id:[{2}] fails.", user.UserID, deviceUser.UserId, deviceID)); } }
private void AddUserMS(User user, DeviceController deviceInfo, DeviceRole role) { var deviceId = deviceInfo.DeviceID; var tryGetAuthentication = user.UserAuthentications.FirstOrDefault(x => x.DeviceID != deviceId); if (tryGetAuthentication != null) { var otherDeviceId = tryGetAuthentication.DeviceID; var otherdeviceAuthentications = user.UserAuthentications.FindAll(x => x.DeviceID == otherDeviceId); var devicePermission = role.DeviceRolePermissions.FirstOrDefault(x => x.DeviceID == deviceId); Log.Info("Building device user..."); var deviceUser = new UserInfo(); deviceUser.UserId = tryGetAuthentication.DeviceUserID; // don't know how to determine new the device user id deviceUser.ExternalUserCode = user.UserID.ToString(); deviceUser.UserName = user.Name; deviceUser.UserStatus = user.Status == GeneralStatus.Enabled; deviceUser.DepartmentId = user.DepartmentID; deviceUser.Comment = user.Remark; deviceUser.Role = (Rld.DeviceSystem.Contract.Model.UserRole)devicePermission.PermissionAction.GetHashCode(); deviceUser.AccessTimeZoneId = devicePermission.AllowedAccessTimeZoneID; foreach (AuthenticationType type in Enum.GetValues(typeof(AuthenticationType))) { switch (type) { case AuthenticationType.FingerPrint1: case AuthenticationType.FingerPrint2: case AuthenticationType.FingerPrint3: case AuthenticationType.FingerPrint4: case AuthenticationType.FingerPrint5: case AuthenticationType.FingerPrint6: case AuthenticationType.FingerPrint7: case AuthenticationType.FingerPrint8: case AuthenticationType.FingerPrint9: case AuthenticationType.FingerPrint10: { var service = new FingerPrintService() { Index = (int)type, Enabled = false }; var userAuthentication = otherdeviceAuthentications.FirstOrDefault(a => a.AuthenticationType == type); if (userAuthentication != null) { service.Enabled = true; service.FingerPrintData = userAuthentication.AuthenticationData; service.UseForDuress = userAuthentication.IsDuress; } deviceUser.CredentialServices.Add(service); } break; case AuthenticationType.Password: { var service = new PasswordService() { Enabled = false }; var userAuthentication = otherdeviceAuthentications.FirstOrDefault(a => a.AuthenticationType == type); if (userAuthentication != null) { service.Enabled = true; service.Password = userAuthentication.AuthenticationData; service.UseForDuress = userAuthentication.IsDuress; } deviceUser.CredentialServices.Add(service); } break; case AuthenticationType.IcCard: { var service = new CredentialCardService() { Enabled = false }; var userAuthentication = otherdeviceAuthentications.FirstOrDefault(a => a.AuthenticationType == type); if (userAuthentication != null) { service.Enabled = true; service.CardNumber = userAuthentication.AuthenticationData; service.UseForDuress = userAuthentication.IsDuress; } deviceUser.CredentialServices.Add(service); } break; //case AuthenticationType.FacePrint: // break; default: break; } } Log.Info("Invoke WebSocketOperation..."); var operation = new WebSocketOperation(deviceId); var createUserInfoRequest = new CreateUserInfoRequest() { Token = operation.Token, UserInfo = deviceUser }; string rawRequest = DataContractSerializationHelper.Serialize(createUserInfoRequest); Log.DebugFormat("Request: {0}", rawRequest); var rawResponse = operation.Execute(rawRequest); Log.DebugFormat("Response: {0}", rawResponse); var response = DataContractSerializationHelper.Deserialize <UpdateUserInfoResponse>(rawResponse); Log.InfoFormat("Update user id:[{0}], device user id:[{1}] to device id:[{2}], result:[{3}]", user.UserID, deviceUser.UserId, deviceId, response.ResultType); if (response.ResultType != ResultType.OK) { throw new Exception(string.Format("Update user id:[{0}], device user id:[{1}] to device id:[{2}] fails]", user.UserID, deviceUser.UserId, deviceId)); } Log.Info("Adding UserAuthentications from database..."); foreach (var au in otherdeviceAuthentications) { var a = au.WiseClone(); a.DeviceID = deviceId; a.CreateDate = DateTime.Now; a.CreateUserID = SyncUserID; _userAuthenticationRepo.Insert(a); } } }