Esempio n. 1
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);
        }
Esempio n. 2
0
        public static Dictionary <string, MediaFolder> GetList(Repository repository)
        {
            var container = MediaBlobHelper.InitializeRepositoryContainer(repository);

            var blobClient = CloudStorageAccountHelper.GetStorageAccount().CreateCloudBlobClient();

            var folderBlob = container.GetBlobReference(MediaBlobHelper.MediaDirectoryName);

            Dictionary <string, MediaFolder> folders = null;

            try
            {
                folderBlob.FetchAttributes();
                if (folderBlob.CheckIfMediaFolder())
                {
                    var xml = folderBlob.DownloadText();
                    folders = DataContractSerializationHelper.DeserializeFromXml <Dictionary <string, MediaFolder> >(xml);
                }
            }
            catch { }

            if (folders == null)
            {
                folders = new Dictionary <string, MediaFolder>();
            }
            return(new Dictionary <string, MediaFolder>(folders, StringComparer.OrdinalIgnoreCase));
        }
Esempio n. 3
0
        private static void SaveList(Repository repository, Dictionary <string, MediaFolder> folders)
        {
            if (folders != null && folders.Count > 0)
            {
                var xml = DataContractSerializationHelper.SerializeAsXml(folders);

                var container = MediaBlobHelper.InitializeRepositoryContainer(repository);

                var blobClient = CloudStorageAccountHelper.GetStorageAccount().CreateCloudBlobClient();

                var folderBlob = container.GetBlobReference(MediaBlobHelper.MediaDirectoryName);

                folderBlob.SetMediaFolderContentType();

                BlobRequestOptions header = new BlobRequestOptions();

                folderBlob.UploadText(xml);
            }
            else
            {
                var container = MediaBlobHelper.InitializeRepositoryContainer(repository);

                var blobClient = CloudStorageAccountHelper.GetStorageAccount().CreateCloudBlobClient();

                var folderBlob = container.GetBlobReference(MediaBlobHelper.MediaDirectoryName);

                folderBlob.DeleteIfExists();
            }
        }
Esempio n. 4
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);
        }
Esempio n. 5
0
        public static T ToPageEntity <T>(this Page model, T entity)
            where T : IPageEntity
        {
            if (string.IsNullOrEmpty(entity.SiteName))
            {
                entity.SiteName = model.Site.FullName;
            }
            if (string.IsNullOrEmpty(entity.FullName))
            {
                entity.FullName = model.FullName;
            }

            entity.IsDefault = model.IsDefault;

            if (model.Parent != null)
            {
                entity.ParentPage = model.Parent.FullName;
            }
            else
            {
                entity.ParentPage = "";
            }
            entity.ObjectXml = DataContractSerializationHelper.SerializeAsXml(model, KnownTypes);
            return(entity);
        }
Esempio n. 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);
        }
Esempio n. 7
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);
        }
Esempio n. 8
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));
        }
Esempio n. 9
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);
        }
Esempio n. 10
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));
            }
        }
Esempio n. 11
0
 public static T ToUrlRedirectEntity <T>(this UrlRedirect model, T entity)
     where T : IUrlRedirectEntity
 {
     entity.SiteName  = model.Site.FullName;
     entity.UUID      = model.UUID;
     entity.ObjectXml = DataContractSerializationHelper.SerializeAsXml(model, KnownTypes);
     return(entity);
 }
Esempio n. 12
0
 public static T ToSiteSettingEntity <T>(this Site model, T entity)
     where T : ISiteSettingEntity
 {
     entity.FullName = model.FullName;
     if (null != model.Parent)
     {
         entity.ParentName = model.Parent.FullName;
     }
     entity.ObjectXml = DataContractSerializationHelper.SerializeAsXml(model, KnownTypes);
     return(entity);
 }
Esempio n. 13
0
        public static T ToABPageSettingEntity <T>(this ABPageSetting model, T entity)
            where T : IABPageSettingEntity
        {
            entity.UUID = model.UUID;
            if (null != model.Site)
            {
                entity.SiteName = model.Site.FullName;
            }

            entity.ObjectXml = DataContractSerializationHelper.SerializeAsXml(model, KnownTypes);
            return(entity);
        }
Esempio n. 14
0
        public static T ToABSiteSettingEntity <T>(this ABSiteSetting model, T entity)
            where T : IABSiteSettingEntity
        {
            entity.UUID = model.UUID;
            if (!String.IsNullOrEmpty(model.MainSite))
            {
                entity.SiteName = model.MainSite;
            }

            entity.ObjectXml = DataContractSerializationHelper.SerializeAsXml(model, KnownTypes);
            return(entity);
        }
Esempio n. 15
0
        public static T ToCustomErrorEntity <T>(this CustomError model, T entity)
            where T : ICustomErrorEntity
        {
            entity.UUID = model.UUID;
            if (string.IsNullOrEmpty(entity.SiteName))
            {
                entity.SiteName = model.Site.FullName;
            }

            entity.ObjectXml = DataContractSerializationHelper.SerializeAsXml(model, KnownTypes);
            return(entity);
        }
Esempio n. 16
0
        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);
        }
Esempio n. 17
0
        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);
            }
        }
Esempio n. 18
0
        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);
        }
Esempio n. 19
0
        public ModuleSettings GetModuleSettings(Site site)
        {
            var settingFile = GetModuleSettingFile(site);

            if (File.Exists(settingFile))
            {
                return(DataContractSerializationHelper.Deserialize <ModuleSettings>(settingFile));
            }
            else
            {
                return(this.DefaultSettings);
            }
        }
Esempio n. 20
0
        public static SiteUserEntity ToEntity(this Kooboo.CMS.Sites.Models.User user, SiteUserEntity entity = null)
        {
            if (entity == null)
            {
                entity = new SiteUserEntity();
            }
            entity.SiteName = user.Site.Name;
            entity.UserName = user.UserName;

            entity.ObjectXml = DataContractSerializationHelper.SerializeAsXml(user);

            return(entity);
        }
Esempio n. 21
0
        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);
        }
Esempio n. 22
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();
            }
        }
Esempio n. 23
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);
        }
Esempio n. 24
0
        public static Page ToPage(this IPageEntity entity)
        {
            if (entity == null)
            {
                return(null);
            }
            var dummy = new Page(new Site(entity.SiteName), entity.FullName);

            var page = DataContractSerializationHelper.DeserializeFromXml <Page>(entity.ObjectXml, KnownTypes);

            ((IPersistable)page).Init(dummy);

            return(page);
        }
Esempio n. 25
0
        /// <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);
        }
Esempio n. 26
0
        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);
        }
Esempio n. 27
0
        public static Kooboo.CMS.Sites.Models.User ToUser(this SiteUserEntity entity)
        {
            if (entity == null)
            {
                return(null);
            }
            var dummy = new Kooboo.CMS.Sites.Models.User()
            {
                Site = new Site(entity.SiteName), UserName = entity.UserName
            };

            var user = DataContractSerializationHelper.DeserializeFromXml <Kooboo.CMS.Sites.Models.User>(entity.ObjectXml);

            ((IPersistable)user).Init(dummy);

            return(user);
        }
Esempio n. 28
0
        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);
            }
        }
Esempio n. 29
0
        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);
            }
        }
Esempio n. 30
0
        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();
            }
        }