Exemple #1
0
        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));
            }
        }
Exemple #2
0
        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);
        }
Exemple #3
0
        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);
        }
Exemple #4
0
        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);
        }
Exemple #5
0
        public void LogVersion(TextContent content)
        {
            VersionInfo versionInfo = new VersionInfo()
            {
                CommitUser    = content.UserId,
                UtcCommitDate = content.UtcLastModificationDate,
                TextContent   = new Dictionary <string, object>(content)
            };

            if (!string.IsNullOrEmpty(content.FolderName))
            {
                versionInfo.Categories = ServiceFactory.TextContentManager
                                         .QueryCategories(content.GetRepository(), content.FolderName, content.UUID)
                                         .Select(it => new Category()
                {
                    FolderName = it.CategoryFolder.FullName,
                    Contents   = it.Contents.Select(c => new CategoryContent()
                    {
                        UUID = c.UUID, DisplayName = c.GetSummary()
                    }).ToArray()
                })
                                         .ToArray();
            }

            DataContractSerializationHelper.Serialize(versionInfo, GetNextVersionFile(content));
        }
Exemple #6
0
        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);
        }
Exemple #7
0
        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);
        }
Exemple #8
0
        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);
        }
Exemple #9
0
        protected virtual void Save(Kooboo.CMS.Membership.Models.Membership membership, List <T> list)
        {
            var file = GetDataFile(membership);

            GetLocker().EnterWriteLock();
            try
            {
                DataContractSerializationHelper.Serialize <List <T> >(list, file);
            }
            finally
            {
                GetLocker().ExitWriteLock();
            }
        }
Exemple #10
0
        private void listener_ReceiveHandler(object sender, ReceiveEventArg e)
        {
            Record record            = e.record;
            var    logInfo           = DeviceAccessLogMapper.ToModel(record);
            var    deviceAccessEvent = new DeviceTrafficEvent()
            {
                DeviceTrafficLog = logInfo
            };
            var message = DataContractSerializationHelper.Serialize(deviceAccessEvent);

            Log.Info(message);

            //var logInfo2 = DeviceAdminLogMapper.ToModel(record);
            //var message2 = DataContractSerializationHelper.Serialize(logInfo2);
            //Log.Info(message2);

            ReportMessage(message);
        }
Exemple #11
0
        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);
        }
Exemple #12
0
        public bool Save(Connect.User account)
        {
            if (string.IsNullOrEmpty(account.Name))
            {
                throw new ArgumentNullException("The user name can not be null");
            }
            string userFile = Path.Combine(UserDir, account.Name + ".config");

            userLocker.EnterWriteLock();
            try
            {
                DataContractSerializationHelper.Serialize(account, userFile);
            }
            finally
            {
                userLocker.ExitWriteLock();
            }

            return(true);
        }
Exemple #13
0
        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));
        }
Exemple #14
0
        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 static void Save(SiteOnAzureTableSettings instance)
        {
            string settingFile = GetSettingFile();

            DataContractSerializationHelper.Serialize(instance, settingFile);
        }
 protected virtual void Serialize(T item, string filePath)
 {
     DataContractSerializationHelper.Serialize(item, filePath, KnownTypes);
 }
Exemple #17
0
        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);
                }
            }
        }
        public static void Save(SiteEntitySetting instance)
        {
            string settingFile = GetSettingFile();

            DataContractSerializationHelper.Serialize(instance, settingFile);
        }
Exemple #19
0
        public static void Save(AzureBlobServiceSettings instance)
        {
            string settingFile = GetSettingFile();

            DataContractSerializationHelper.Serialize(instance, settingFile);
        }
        public static void SetModuleSettings(this ModuleContext moduleContext, ModuleSettings moduleSettings)
        {
            var settingFile = moduleContext.ModulePath.GetModuleLocalFilePath("settings.config").PhysicalPath;

            DataContractSerializationHelper.Serialize(moduleSettings, settingFile);
        }
Exemple #21
0
        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));
            }
        }
        public void Save(CasServerConfiguration config, string configname)
        {
            var settingFile = GetSettingFile(configname);

            DataContractSerializationHelper.Serialize <CasServerConfiguration>(config, settingFile);
        }
Exemple #23
0
        public static void Save(FileServerProviderSettings instance)
        {
            string settingFile = GetSettingFile();

            DataContractSerializationHelper.Serialize(instance, settingFile);
        }
Exemple #24
0
        public static void Save(ModuleInfo moduleInfo)
        {
            ModuleItemPath moduleInfoPath = GetModuleInfoPath(moduleInfo.ModuleName);

            DataContractSerializationHelper.Serialize(moduleInfo, moduleInfoPath.PhysicalPath);
        }
Exemple #25
0
        public static void SaveModuleSetting(string moduleName, string siteName, ModuleSettings moduleSettings)
        {
            var siteModuleSettingFile = GetSiteModuleSettingFile(moduleName, siteName);

            DataContractSerializationHelper.Serialize(moduleSettings, siteModuleSettingFile);
        }
Exemple #26
0
        public static void Save(ModuleInfo moduleInfo)
        {
            var moduleInfoPath = GetModuleInfoPath(moduleInfo.ModuleName);

            DataContractSerializationHelper.Serialize(moduleInfo, moduleInfoPath);
        }
Exemple #27
0
        public void SaveModuleSettings(Site site, ModuleSettings moduleSettings)
        {
            var settingFile = GetModuleSettingFile(site);

            DataContractSerializationHelper.Serialize(moduleSettings, settingFile);
        }
Exemple #28
0
        public void Save()
        {
            string settingFile = GetSettingFile();

            DataContractSerializationHelper.Serialize <DatabaseSettings>(this, settingFile);
        }
Exemple #29
0
        public string ProcessReceiveEvent(string message)
        {
            if (message.Contains("GetUserInfoRequest"))
            {
                var request  = DataContractSerializationHelper.Deserialize <GetUserInfoRequest>(message);
                var response = new GetUserOp().Process(request);
                return(DataContractSerializationHelper.Serialize(response));
            }
            if (message.Contains("GetAllUsersRequest"))
            {
                var request  = DataContractSerializationHelper.Deserialize <GetAllUsersRequest>(message);
                var response = new GetAllUsersOp().Process(request);
                return(DataContractSerializationHelper.Serialize(response));
            }
            else if (message.Contains("UpdateUserInfoRequest"))
            {
                var request  = DataContractSerializationHelper.Deserialize <UpdateUserInfoRequest>(message);
                var response = new UpdateUserOp().Process(request);
                return(DataContractSerializationHelper.Serialize(response));
            }
            else if (message.Contains("CreateUserInfoRequest"))
            {
                var request  = DataContractSerializationHelper.Deserialize <CreateUserInfoRequest>(message);
                var response = new CreateUserOp().Process(request);
                return(DataContractSerializationHelper.Serialize(response));
            }
            else if (message.Contains("DeleteUserInfoRequest"))
            {
                var request  = DataContractSerializationHelper.Deserialize <DeleteUserInfoRequest>(message);
                var response = new DeleteUserOp().Process(request);
                return(DataContractSerializationHelper.Serialize(response));
            }

            else if (message.Contains("GetSystemInfoRequest"))
            {
                var request  = DataContractSerializationHelper.Deserialize <GetSystemInfoRequest>(message);
                var response = new GetSystemInfoOp().Process(request);
                return(DataContractSerializationHelper.Serialize(response));
            }
            else if (message.Contains("UpdateSystemInfoRequest"))
            {
                var request  = DataContractSerializationHelper.Deserialize <UpdateSystemInfoRequest>(message);
                var response = new UpdateSystemInfoOp().Process(request);
                return(DataContractSerializationHelper.Serialize(response));
            }

            else if (message.Contains("GetDeviceInfoRequest"))
            {
                var request  = DataContractSerializationHelper.Deserialize <GetDeviceInfoRequest>(message);
                var response = new GetDeviceInfoOp().Process(request);
                return(DataContractSerializationHelper.Serialize(response));
            }
            else if (message.Contains("UpdateDeviceInfoRequest"))
            {
                var request  = DataContractSerializationHelper.Deserialize <UpdateDeviceInfoRequest>(message);
                var response = new UpdateDeviceInfoOp().Process(request);
                return(DataContractSerializationHelper.Serialize(response));
            }

            else if (message.Contains("GetAllTimeSegmentsRequest"))
            {
                var request  = DataContractSerializationHelper.Deserialize <GetAllTimeSegmentsRequest>(message);
                var response = new GetAllTimeSegmentsOp().Process(request);
                return(DataContractSerializationHelper.Serialize(response));
            }
            else if (message.Contains("BatchUpdateTimeSegmentsRequest"))
            {
                var request  = DataContractSerializationHelper.Deserialize <BatchUpdateTimeSegmentsRequest>(message);
                var response = new BatchUpdateTimeSegmentsOp().Process(request);
                return(DataContractSerializationHelper.Serialize(response));
            }
            else if (message.Contains("GetAllTimeGroupsRequest"))
            {
                var request  = DataContractSerializationHelper.Deserialize <GetAllTimeGroupsRequest>(message);
                var response = new GetAllTimeGroupsOp().Process(request);
                return(DataContractSerializationHelper.Serialize(response));
            }
            else if (message.Contains("BatchUpdateTimeGroupsRequest"))
            {
                var request  = DataContractSerializationHelper.Deserialize <BatchUpdateTimeGroupsRequest>(message);
                var response = new BatchUpdateTimeGroupsOp().Process(request);
                return(DataContractSerializationHelper.Serialize(response));
            }
            else if (message.Contains("GetAllTimeZonesRequest"))
            {
                var request  = DataContractSerializationHelper.Deserialize <GetAllTimeZonesRequest>(message);
                var response = new GetAllTimeZonesOp().Process(request);
                return(DataContractSerializationHelper.Serialize(response));
            }
            else if (message.Contains("BatchUpdateTimeZonesRequest"))
            {
                var request  = DataContractSerializationHelper.Deserialize <BatchUpdateTimeZonesRequest>(message);
                var response = new BatchUpdateTimeZonesOp().Process(request);
                return(DataContractSerializationHelper.Serialize(response));
            }

            else if (message.Contains("GetDeviceTrafficLogRequest"))
            {
                var request  = DataContractSerializationHelper.Deserialize <GetDeviceTrafficLogRequest>(message);
                var response = new GetDeviceTrafficLogOp().Process(request);
                return(DataContractSerializationHelper.Serialize(response));
            }
            else if (message.Contains("GetDeviceOperationLogRequest"))
            {
                var request  = DataContractSerializationHelper.Deserialize <GetDeviceOperationLogRequest>(message);
                var response = new GetDeviceOperationLogOp().Process(request);
                return(DataContractSerializationHelper.Serialize(response));
            }
            else if (message.Contains("GetDoorStateRequest"))
            {
                var request  = DataContractSerializationHelper.Deserialize <GetDoorStateRequest>(message);
                var response = new GetDoorStateOp().Process(request);
                return(DataContractSerializationHelper.Serialize(response));
            }
            else if (message.Contains("UpdateDoorStateRequest"))
            {
                var request  = DataContractSerializationHelper.Deserialize <UpdateDoorStateRequest>(message);
                var response = new UpdateDoorStateOp().Process(request);
                return(DataContractSerializationHelper.Serialize(response));
            }

            return(string.Empty);
        }