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 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 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 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 VersionInfo GetVersion(TextContent content, int version) { string versionFile = GetVersionFile(content, version); if (File.Exists(versionFile)) { var versionInfo = DataContractSerializationHelper.Deserialize <VersionInfo>(versionFile); versionInfo.Version = version; return(versionInfo); } return(null); }
public static ModuleSettings GetSiteModuleSettings(string moduleName, string siteName) { if (!string.IsNullOrEmpty(siteName)) { var siteModuleSettingFile = GetSiteModuleSettingFile(moduleName, siteName); if (File.Exists(siteModuleSettingFile)) { return(DataContractSerializationHelper.Deserialize <ModuleSettings>(siteModuleSettingFile)); } } return(Get(moduleName).DefaultSettings); }
public ModuleSettings GetModuleSettings(Site site) { var settingFile = GetModuleSettingFile(site); if (File.Exists(settingFile)) { return(DataContractSerializationHelper.Deserialize <ModuleSettings>(settingFile)); } else { return(this.DefaultSettings); } }
public static ModuleSettings GetModuleSettings(this ModuleContext moduleContext) { var settingFile = moduleContext.ModulePath.GetModuleLocalFilePath("settings.config").PhysicalPath; if (File.Exists(settingFile)) { return(DataContractSerializationHelper.Deserialize <ModuleSettings>(settingFile)); } else { return(moduleContext.ModuleInfo.DefaultSettings); } }
public static ModuleInfo Get(string moduleName) { ModulePath modulePath = new ModulePath(moduleName); if (!Directory.Exists(modulePath.PhysicalPath)) { throw new Exception(string.Format("The module does not exist.Module name:{0}".Localize(), moduleName)); } ModuleItemPath moduleInfoPath = GetModuleInfoPath(moduleName); var moduleInfo = DataContractSerializationHelper.Deserialize <ModuleInfo>(moduleInfoPath.PhysicalPath); moduleInfo.ModuleName = moduleName; return(moduleInfo); }
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 static ModuleInfo Get(string moduleName) { ModulePath modulePath = new ModulePath(moduleName); if (!Directory.Exists(modulePath.PhysicalPath)) { return(null); } string moduleInfoPath = GetModuleInfoPath(moduleName); var moduleInfo = DataContractSerializationHelper.Deserialize <ModuleInfo>(moduleInfoPath); moduleInfo.ModuleName = moduleName; return(moduleInfo); }
/// <summary> /// Alls this instance. /// </summary> /// <returns></returns> public IEnumerable <ProductType> All() { List <ProductType> list = new List <ProductType>(); if (Directory.Exists(baseDataPath)) { foreach (var item in IO.IOUtility.EnumerateDirectoriesExludeHidden(baseDataPath)) { var pt = (ProductType)DataContractSerializationHelper.Deserialize(typeof(ProductType), KnownTypes, GetSettingFilePath(item.Name)); list.Add(pt); } } return(list); }
static SiteOnSQLServerSettings() { string settingFile = GetSettingFile(); if (File.Exists(settingFile)) { instance = DataContractSerializationHelper.Deserialize <SiteOnSQLServerSettings>(settingFile); } else { instance = new SiteOnSQLServerSettings() { ConnectionString = "Server=.\\SQLExpress;Database=Kooboo_CMS; Trusted_Connection=Yes;" }; Save(instance); } }
public Connect.User LoadUser(string name) { string userfile = GetUserFilePath(name); if (File.Exists(userfile)) { userLocker.EnterReadLock(); try { return(DataContractSerializationHelper.Deserialize <Connect.User>(userfile)); } finally { userLocker.ExitReadLock(); } } return(null); }
static MysqlSettings() { string settingFile = GetSettingFile(); if (File.Exists(settingFile)) { instance = DataContractSerializationHelper.Deserialize <MysqlSettings>(settingFile); } else { instance = new MysqlSettings() { DEFAULT_CHARSET = "utf8", ConnectionString = "Server=127.0.0.1;Database=Kooboo_CMS;Uid=root;Pwd=;" }; Save(instance); } }
static DatabaseSettings() { string settingFile = GetSettingFile(); if (File.Exists(settingFile)) { instance = DataContractSerializationHelper.Deserialize <DatabaseSettings>(settingFile); } else { instance = new DatabaseSettings() { SharingDatabase = false, ConnectionString = "mongodb://localhost" }; instance.Save(); } }
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); }
/// <summary> /// Gets the specified dummy. /// </summary> /// <param name="dummy">The dummy.</param> /// <returns></returns> public ProductType Get(ProductType dummy) { var filepath = GetSettingFilePath(dummy.Name); if (File.Exists(filepath)) { locker.EnterReadLock(); try { var item = (ProductType)DataContractSerializationHelper.Deserialize(dummy.GetType(), KnownTypes, filepath); return(item); } finally { locker.ExitReadLock(); } } return(default(ProductType)); }
static FileServerProviderSettings() { string settingFile = GetSettingFile(); if (File.Exists(settingFile)) { instance = DataContractSerializationHelper.Deserialize <FileServerProviderSettings>(settingFile); } else { instance = new FileServerProviderSettings() { Endpoint = "http://localhost:8626/", AccountName = "devstoreaccount1", AccountKey = "Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==" }; Save(instance); } }
static AzureBlobServiceSettings() { string settingFile = GetSettingFile(); if (File.Exists(settingFile)) { instance = DataContractSerializationHelper.Deserialize <AzureBlobServiceSettings>(settingFile); } else { instance = new AzureBlobServiceSettings() { Endpoint = "http://127.0.0.1:10000/devstoreaccount1/", AccountName = "devstoreaccount1", AccountKey = "Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==" }; Save(instance); } }
static SiteEntitySetting() { string settingFile = GetSettingFile(); if (File.Exists(settingFile)) { instance = DataContractSerializationHelper.Deserialize <SiteEntitySetting>(settingFile); } else { instance = new SiteEntitySetting() { ConnectionString = "Server=.\\SQLExpress;Database=Kooboo_CMS; Trusted_Connection=Yes;", ProviderInvariantName = "System.Data.SqlClient", ProviderManifestToken = "2008" }; Save(instance); } }
static SqlServerSettings() { string settingFile = GetSettingFile(); if (File.Exists(settingFile)) { instance = DataContractSerializationHelper.Deserialize <SqlServerSettings>(settingFile); } else { instance = new SqlServerSettings() { SharingDatabaseConnectionString = "Server=.\\SQLExpress;Database=Kooboo_CMS; Trusted_Connection=Yes;", Connections = new[] { new ConnectionSetting() { Name = "Sample", ConnectionString = "Server=.\\SQLExpress;Database=Kooboo_CMS; Trusted_Connection=Yes;" } } }; instance.Save(); } }
public static void ProcessDeviceTrafficEvent(string message) { var ev = DataContractSerializationHelper.Deserialize <DeviceTrafficEvent>(message); PersistenceOperation.Process("", () => { var deviceControllerRepo = RepositoryManager.GetRepository <IDeviceControllerRepository>(); var deviceTrafficLogRepo = RepositoryManager.GetRepository <IDeviceTrafficLogRepository>(); var logInfo = new Rld.Acs.Model.DeviceTrafficLog(); logInfo.DeviceID = -1; logInfo.DeviceCode = ev.DeviceTrafficLog.DeviceId.ToString(); logInfo.DeviceUserID = ev.DeviceTrafficLog.UserId; logInfo.RecordType = ev.DeviceTrafficLog.AccessLogType.ToString(); logInfo.RecordTime = ev.DeviceTrafficLog.CreateTime; logInfo.RecordUploadTime = DateTime.Now; logInfo.Remark = ev.DeviceTrafficLog.Message; if (ev.DeviceTrafficLog.CheckInOptions.Any()) { logInfo.AuthenticationType = 0; ev.DeviceTrafficLog.CheckInOptions.ForEach(option => logInfo.AuthenticationType += (int)option); } var deviceInfo = deviceControllerRepo.Query(new Hashtable() { { "Code", ev.DeviceTrafficLog.DeviceId } }).FirstOrDefault(); if (deviceInfo != null) { logInfo.DeviceID = deviceInfo.DeviceID; logInfo.DeviceType = deviceInfo.Model; logInfo.DeviceSN = deviceInfo.SN; } deviceTrafficLogRepo.Insert(logInfo); return(new Message.ResponseBase()); }); }
public CommConfiguration Get(string configname) { CommConfiguration instance; var xmlFile = GetSettingFile(configname); if (File.Exists(xmlFile)) { instance = DataContractSerializationHelper.Deserialize <CommConfiguration>(xmlFile); } else { instance = new CommConfiguration { //CurrentUrl = "http://caslocal.xxxxxxx.com", SmsApi = "http://192.168.0.188:9595", TuanApibase = "http://apilocal.xxxxxxx.com" }; this.Save(instance, configname); } return(instance); }
public virtual IEnumerable <T> All(Kooboo.CMS.Membership.Models.Membership membership) { var filePath = GetDataFile(membership); if (!File.Exists(filePath)) { return(new T[0]); } GetLocker().EnterReadLock(); try { var list = DataContractSerializationHelper.Deserialize <List <T> >(filePath) ?? new List <T>(); foreach (var item in list) { item.Membership = membership; } return(list); } finally { GetLocker().ExitReadLock(); } }
public CasServerConfiguration Get(string configname) { CasServerConfiguration instance; var xmlFile = GetSettingFile(configname); if (File.Exists(xmlFile)) { instance = DataContractSerializationHelper.Deserialize <CasServerConfiguration>(xmlFile); } else { instance = new CasServerConfiguration { ClientList = new Client[] { new Client { Url = "localhost" } }, DefaultUrl = "/" }; this.Save(instance, configname); } return(instance); }
static DatabaseSettings() { string settingFile = GetSettingFile(); if (File.Exists(settingFile)) { instance = DataContractSerializationHelper.Deserialize <DatabaseSettings>(settingFile); } else { instance = new DatabaseSettings() { Username = "******", Password = "******", BucketRAM = 100,//RamQuotaMB must be at least 100 Urls = new List <Uri>() { new Uri("http://127.0.0.1:8091/pools") } }; instance.Save(); } }
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)); } }