コード例 #1
0
        /// <summary>
        /// 添加数据库信息,当数据库信息不存在时
        /// </summary>
        /// <param name="dbName">数据库名字</param>
        /// <param name="dbType">数据库类型</param>
        /// <returns>数据库信息</returns>
        public Task <DatabaseInfo> AddWhenNotExistAsync(string dbName, string dbType)
        {
            dbName.NotNull("数据库名称不能为空");
            dbType.NotNull("数据库类型不能为空");
            var databaseInfo = new DatabaseInfo
            {
                FCreateTime   = DateTimeUtil.Now,
                FIsDeleted    = false,
                FName         = dbName,
                FCreateUserID = -1,
                FDbType       = dbType ?? string.Empty
            };

            return(LockUtil.ExecuteWithLockAsync(Lock_DatabaseModify, dbName, TimeSpan.FromMinutes(2), async() =>
            {
                var existDbInfo = await _databaseRepository.GetInfoAsync(m => m.FIsDeleted == false && m.FName == dbName && m.FDbType == databaseInfo.FDbType);
                if (existDbInfo != null)
                {
                    return existDbInfo;
                }
                else
                {
                    int dbID = (await _databaseRepository.InsertOneAsync(databaseInfo, keyName: "FID", ignoreFields: IgnoreConstant.FID)).ToSafeInt32(0);
                    databaseInfo.FID = dbID;
                    DatabaseChanged(OperateType.Add, dbID);
                    return databaseInfo;
                }
            }));
        }
コード例 #2
0
        /// <summary>
        /// 创建项目,当名字不存在时
        /// </summary>
        /// <param name="projectName">项目名字</param>
        /// <returns>项目信息</returns>
        public Task <ProjectInfo> AddWhenNotExistAsync(string projectName)
        {
            projectName.NotNull("项目名称不能为空");
            var projectInfo = new ProjectInfo
            {
                FCreateTime   = DateTimeUtil.Now,
                FIsDeleted    = false,
                FName         = projectName,
                FCreateUserID = -1
            };

            return(LockUtil.ExecuteWithLockAsync(Lock_ProjectModify, projectName, TimeSpan.FromMinutes(2), async() =>
            {
                var existProjectInfo = await _projectRepository.GetInfoAsync(m => m.FIsDeleted == false && m.FName == projectName);
                if (existProjectInfo != null)
                {
                    return existProjectInfo;
                }
                else
                {
                    int projectID = (await _projectRepository.InsertOneAsync(projectInfo, keyName: "FID", ignoreFields: IgnoreConstant.FID)).ToSafeInt32(0);
                    projectInfo.FID = projectID;
                    ProjectChanged(OperateType.Add, projectID);
                    return projectInfo;
                }
            }));
        }
コード例 #3
0
        /// <summary>
        /// 创建服务器,当名字不存在时
        /// </summary>
        /// <param name="servicerMac">Mac地址</param>
        /// <returns>项目信息</returns>
        public Task <ServicerInfo> AddWhenNotExistAsync(string servicerMac)
        {
            servicerMac.NotNull("Mac地址不能为空");
            var servicerInfo = new ServicerInfo
            {
                FCreateTime   = DateTimeUtil.Now,
                FIsDeleted    = false,
                FMacAddress   = servicerMac,
                FCreateUserID = -1
            };

            return(LockUtil.ExecuteWithLockAsync(Lock_ServicerModify, servicerMac, TimeSpan.FromMinutes(2), async() =>
            {
                var existServicerInfo = await _servicerRepository.GetInfoAsync(m => m.FIsDeleted == false && m.FMacAddress == servicerMac);
                if (existServicerInfo != null)
                {
                    return existServicerInfo;
                }
                else
                {
                    int servicerID = (await _servicerRepository.InsertOneAsync(servicerInfo, keyName: "FID", ignoreFields: IgnoreConstant.FID)).ToSafeInt32(0);
                    servicerInfo.FID = servicerID;
                    ServicerChanged(OperateType.Add, servicerID);
                    return servicerInfo;
                }
            }));
        }
コード例 #4
0
 /// <summary>
 /// 添加项目信息
 /// </summary>
 /// <param name="projectModel">项目信息</param>
 /// <returns>操作结果</returns>
 public Task <OperateResult> AddProjectAsync(ProjectModel projectModel)
 {
     return(OperateUtil.ExecuteAsync(async() =>
     {
         var projectInfo = _projectDomainService.Create(projectModel);
         int id = await LockUtil.ExecuteWithLockAsync(Lock_ProjectModify, projectInfo.FName, TimeSpan.FromMinutes(2), async() =>
         {
             await _projectDomainService.CheckAsync(projectInfo);
             int projectID = (await _projectRepository.InsertOneAsync(projectInfo, keyName: "FID", ignoreFields: FID)).ToSafeInt32(0);
             _operateLogDomainService.AddOperateLog(projectModel.OperateUserID.Value, OperateModule.Project, OperateModuleNode.Add, $"添加:{projectInfo.GetOperateDesc()}");
             _projectDomainService.ProjectChanged(OperateType.Add, projectID);
             return projectID;
         }, defaultValue: -1);
         if (id <= 0)
         {
             throw new BizException("添加失败");
         }
     }, callMemberName: "ProjectApplication-AddProjectAsync"));
 }
コード例 #5
0
 /// <summary>
 /// 修改项目信息
 /// </summary>
 /// <param name="projectModel">项目信息</param>
 /// <returns>操作结果</returns>
 public Task <OperateResult> EditProjectAsync(ProjectModel projectModel)
 {
     return(OperateUtil.ExecuteAsync(async() =>
     {
         var projectInfo = _projectDomainService.Create(projectModel);
         var flag = await LockUtil.ExecuteWithLockAsync(Lock_ProjectModify, projectInfo.FName, TimeSpan.FromMinutes(2), async() =>
         {
             await _projectDomainService.CheckAsync(projectInfo);
             await _projectRepository.UpdateAsync(projectInfo, m => m.FID == projectInfo.FID, ignoreFields: IDAndCreate);
             _operateLogDomainService.AddOperateLog(projectModel.OperateUserID.Value, OperateModule.SysConfig, OperateModuleNode.Edit, $"{projectInfo.GetOperateDesc()}");
             _projectDomainService.ProjectChanged(OperateType.Modify, projectInfo.FID);
             return true;
         }, defaultValue: false);
         if (!flag)
         {
             throw new BizException("修改失败");
         }
     }, callMemberName: "ProjectApplication-EditProjectAsync"));
 }
コード例 #6
0
 /// <summary>
 /// 添加数据库信息
 /// </summary>
 /// <param name="databaseModel">数据库信息</param>
 /// <returns>操作结果</returns>
 public Task <OperateResult> AddDatabaseAsync(DatabaseModel databaseModel)
 {
     return(OperateUtil.ExecuteAsync(async() =>
     {
         var dbInfo = _databaseDomainService.Create(databaseModel);
         int id = await LockUtil.ExecuteWithLockAsync(Lock_DatabaseModify, dbInfo.FName, TimeSpan.FromMinutes(2), async() =>
         {
             await _databaseDomainService.CheckAsync(dbInfo);
             int dbID = (await _databaseRepository.InsertOneAsync(dbInfo, keyName: "FID", ignoreFields: FID)).ToSafeInt32(0);
             _operateLogDomainService.AddOperateLog(databaseModel.OperateUserID.Value, OperateModule.Database, OperateModuleNode.Add, $"添加:{dbInfo.GetOperateDesc()}");
             _databaseDomainService.DatabaseChanged(OperateType.Add, dbID);
             return dbID;
         }, defaultValue: -1);
         if (id <= 0)
         {
             throw new BizException("添加失败");
         }
     }, callMemberName: "DatabaseApplication-AddDatabaseAsync"));
 }
コード例 #7
0
 /// <summary>
 /// 添加配置信息
 /// </summary>
 /// <param name="sysConfigModel">配置信息</param>
 /// <returns>操作结果</returns>
 public Task <OperateResult> AddConfigAsync(SysConfigModel sysConfigModel)
 {
     return(OperateUtil.ExecuteAsync(async() =>
     {
         var sysConfigInfo = _sysConfigDomainService.Create(sysConfigModel);
         int id = await LockUtil.ExecuteWithLockAsync(Lock_SysConfigModify, sysConfigInfo.FKey, TimeSpan.FromMinutes(2), async() =>
         {
             await _sysConfigDomainService.CheckAsync(sysConfigInfo);
             var configID = (await _sysConfigRepository.InsertOneAsync(sysConfigInfo, keyName: "FID", ignoreFields: FID)).ToSafeInt32(0);
             _operateLogDomainService.AddOperateLog(sysConfigModel.OperateUserID.Value, OperateModule.SysConfig, OperateModuleNode.Add, $"{sysConfigInfo.GetOperateDesc()}");
             _sysConfigDomainService.ConfigChanged(OperateType.Add, configID);
             return configID;
         }, defaultValue: -1);
         if (id <= 0)
         {
             throw new BizException("添加失败");
         }
     }, callMemberName: "SysConfigApplication-AddConfigAsync"));
 }
コード例 #8
0
 /// <summary>
 /// 修改服务器信息
 /// </summary>
 /// <param name="servicerModel">服务器信息</param>
 /// <returns>操作结果</returns>
 public Task <OperateResult> EditServicerAsync(ServicerModel servicerModel)
 {
     return(OperateUtil.ExecuteAsync(async() =>
     {
         var servicerInfo = _servcerDomainService.Create(servicerModel);
         var flag = await LockUtil.ExecuteWithLockAsync(Lock_ServicerModify, servicerInfo.FMacAddress, TimeSpan.FromMinutes(2), async() =>
         {
             await _servcerDomainService.CheckAsync(servicerInfo);
             await _servcerRepository.UpdateAsync(servicerInfo, m => m.FID == servicerInfo.FID, ignoreFields: IDAndCreate);
             _operateLogDomainService.AddOperateLog(servicerModel.OperateUserID, OperateModule.Servicer, OperateModuleNode.Edit, $"修改:{servicerInfo.GetOperateDesc()}");
             _servcerDomainService.ServicerChanged(OperateType.Modify, servicerInfo.FID);
             return true;
         }, defaultValue: false);
         if (!flag)
         {
             throw new BizException("修改失败");
         }
     }, callMemberName: "ServicerApplication-AddServicerAsync"));
 }
コード例 #9
0
 /// <summary>
 /// 添加服务器信息
 /// </summary>
 /// <param name="servicerModel">服务器信息</param>
 /// <returns>操作结果</returns>
 public Task <OperateResult> AddServicerAsync(ServicerModel servicerModel)
 {
     return(OperateUtil.ExecuteAsync(async() =>
     {
         var servicerInfo = _servcerDomainService.Create(servicerModel);
         int id = await LockUtil.ExecuteWithLockAsync(Lock_ServicerModify, servicerInfo.FMacAddress, TimeSpan.FromMinutes(2), async() =>
         {
             await _servcerDomainService.CheckAsync(servicerInfo);
             int servicerID = (await _servcerRepository.InsertOneAsync(servicerInfo, keyName: "FID", ignoreFields: FID)).ToSafeInt32(0);
             _operateLogDomainService.AddOperateLog(servicerModel.OperateUserID, OperateModule.Servicer, OperateModuleNode.Add, $"添加:{servicerInfo.GetOperateDesc()}");
             _servcerDomainService.ServicerChanged(OperateType.Add, servicerID);
             return servicerID;
         }, defaultValue: -1);
         if (id <= 0)
         {
             throw new BizException("添加失败");
         }
     }, callMemberName: "ServicerApplication-AddServicerAsync"));
 }
コード例 #10
0
        private long Merge(string srcIxFileName, string targetIxFileName)
        {
            Log.InfoFormat("merging branch {0} with trunk {1}", srcIxFileName, targetIxFileName);

            var srcIx              = SegmentInfo.Load(srcIxFileName);
            var targetIx           = SegmentInfo.Load(targetIxFileName);
            var srcDataFileName    = Path.Combine(_directory, srcIx.Version + ".rdb");
            var targetDataFileName = Path.Combine(_directory, targetIx.Version + ".rdb");

            FileStream lockFile;

            if (!LockUtil.TryAquireWriteLock(_directory, out lockFile))
            {
                throw new InvalidOperationException(
                          "Cannot merge because there are other writes in progress.");
            }

            using (lockFile)
                using (var source = new FileStream(srcDataFileName, FileMode.Open))
                    using (var target = new FileStream(targetDataFileName, FileMode.Append, FileAccess.Write, FileShare.ReadWrite))
                    {
                        var newStartIndex = targetIx.Length;
                        var fieldOffsets  = new Dictionary <ulong, long>();

                        foreach (var field in srcIx.FieldOffsets)
                        {
                            fieldOffsets[field.Key] = field.Value + newStartIndex;
                        }
                        srcIx.FieldOffsets = fieldOffsets;

                        var tree         = new byte[srcIx.PostingsOffset];
                        var postings     = new byte[srcIx.DocHashOffset - srcIx.PostingsOffset];
                        var docHashes    = new byte[srcIx.DocAddressesOffset - srcIx.DocHashOffset];
                        var docAddresses = new byte[srcIx.KeyIndexOffset - srcIx.DocAddressesOffset];
                        var documents    = new byte[srcIx.Length - srcIx.KeyIndexOffset];
                        var sum          = tree.Length + postings.Length + docHashes.Length + docAddresses.Length + documents.Length;

                        if (sum != srcIx.Length)
                        {
                            throw new DataMisalignedException("Size of segment does not compute.");
                        }

                        source.Read(tree, 0, tree.Length);
                        source.Read(postings, 0, postings.Length);
                        source.Read(docHashes, 0, docHashes.Length);
                        source.Read(docAddresses, 0, docAddresses.Length);
                        source.Read(documents, 0, documents.Length);

                        target.Write(tree, 0, tree.Length);

                        srcIx.PostingsOffset = target.Position;
                        target.Write(postings, 0, postings.Length);

                        srcIx.DocHashOffset = target.Position;
                        target.Write(docHashes, 0, docHashes.Length);

                        srcIx.DocAddressesOffset = target.Position;
                        target.Write(docAddresses, 0, docAddresses.Length);

                        srcIx.KeyIndexOffset = target.Position;
                        target.Write(documents, 0, documents.Length);

                        srcIx.Serialize(srcIxFileName);

                        Log.InfoFormat("merged {0} with {1} creating a segmented index", srcIxFileName, targetIx);
                    }
            File.Delete(srcDataFileName);
            return(srcIx.Version);
        }