protected override void ExcuteSelf() { try { using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required)) { int parentId = 0; if (_ParentDeptId.HasValue) { parentId = _ParentDeptId.Value; } else { Department parentDept = DalInstance.DeptDalInstance.GetDepartmentById(_Department.Id); parentId = parentDept != null && parentDept.ParentDepartment != null ? parentDept.ParentDepartment.Id : 0; } DalInstance.DeptDalInstance.UpdateDepartment(parentId, _Department); ts.Complete(); } } catch { throw MessageKeys.AppException(MessageKeys._DbError); } }
protected override void Validation() { if (DalInstance.PositionDalInstance.CountPositionByNatureId(_PositionNatureId) > 0) { throw MessageKeys.AppException(MessageKeys._PositionNature_HasPosition); } }
protected override void ExcuteSelf() { try { if (_WorkTaskQA.Pkid == 0) { DalInstance.WorkTaskDalInstance.AddWorkTaskQA(_WorkTaskQA); } else { DalInstance.WorkTaskDalInstance.UpdateWorkTaskQA(_WorkTaskQA); } if (_IfEmail) { string subject = _WorkTaskQA.QAccount.Name + "´ð¸´ÁËÄãµÄÁôÑÔ"; List <string> to = new List <string>(); Account account = DalInstance.AccountDalInstance.GetAccountById(_WorkTaskQA.WorkTask.Account.Id); if (account != null && account.Id > 0) { to.Add(account.Email1); } new WorkTaskEmail(subject, WorkTaskEmail.BuildQuestionWorkTaskMailBody(_WorkTaskQA), to).SendMail(); } } catch { throw MessageKeys.AppException(MessageKeys._DbError); } }
protected override void ExcuteSelf() { try { using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required)) { //新增新闻基本信息 //新增新闻附件AddAppendix int bulletinID = DalInstance.BulletinDalInstance.InsertBulletin(_Bulletin); if (_Bulletin.AppendixList != null) { foreach (Appendix appendix in _Bulletin.AppendixList) { appendix.BulletinID = bulletinID; DalInstance.BulletinDalInstance.InsertAppendix(appendix); } } ts.Complete(); } } catch { throw MessageKeys.AppException(MessageKeys._DbError); } }
protected override void Validation() { if (_NewAccount.Id == _LoginUser.Id) { return; } //权限验证 if (!Powers.HasAuth(_LoginUser.Auths, AuthType.SEP, Powers.A101)) { throw MessageKeys.AppException(MessageKeys._NoAuth); } //用户名唯一性验证 if (DalInstance.AccountDalInstance.ValidationLoginName(_NewAccount.Id, _NewAccount.LoginName)) { throw MessageKeys.AppException(MessageKeys._Account_Not_Repeat); } //姓名唯一性验证 if (DalInstance.AccountDalInstance.ValidationName(_NewAccount.Id, _NewAccount.Name)) { throw MessageKeys.AppException(MessageKeys._Employee_Name_Repeat); } }
protected override void Validation() { if (DalInstance.BulletinDalInstance.GetAppendixCountByBulletinIDAndTitle(_Appendix.BulletinID, _Appendix.Title) > 0) { throw MessageKeys.AppException(MessageKeys._Appendix_Title_Repeat); } }
private MessageKeys getOrCreateMessageKeys(SessionState sessionState, ECPublicKey theirEphemeral, ChainKey chainKey, uint counter) { if (chainKey.getIndex() > counter) { if (sessionState.hasMessageKeys(theirEphemeral, counter)) { return(sessionState.removeMessageKeys(theirEphemeral, counter)); } else { throw new DuplicateMessageException($"Received message with old counter: {chainKey.getIndex()} , {counter}"); } } if (counter - chainKey.getIndex() > 2000) { throw new InvalidMessageException("Over 2000 messages into the future!"); } while (chainKey.getIndex() < counter) { MessageKeys messageKeys = chainKey.getMessageKeys(); sessionState.setMessageKeys(theirEphemeral, messageKeys); chainKey = chainKey.getNextChainKey(); } sessionState.setReceiverChainKey(theirEphemeral, chainKey.getNextChainKey()); return(chainKey.getMessageKeys()); }
private byte[] Decrypt(SessionState sessionState, SignalMessage ciphertextMessage) { if (!sessionState.HasSenderChain()) { throw new InvalidMessageException("Uninitialized session!"); } if (sessionState.GetStructure().SenderChain.SenderRatchetKey.Length <= 0) { throw new InvalidMessageException("SenderRatchetKey is empty!"); } if (ciphertextMessage.GetMessageVersion() != sessionState.GetSessionVersion()) { throw new InvalidMessageException($"Message version {ciphertextMessage.GetMessageVersion()}, but session version {sessionState.GetSessionVersion()}"); } IEcPublicKey theirEphemeral = ciphertextMessage.GetSenderRatchetKey(); uint counter = ciphertextMessage.GetCounter(); ChainKey chainKey = GetOrCreateChainKey(sessionState, theirEphemeral); MessageKeys messageKeys = GetOrCreateMessageKeys(sessionState, theirEphemeral, chainKey, counter); ciphertextMessage.VerifyMac(sessionState.GetRemoteIdentityKey(), sessionState.GetLocalIdentityKey(), messageKeys.GetMacKey()); byte[] plaintext = GetPlaintext(messageKeys, ciphertextMessage.GetBody()); sessionState.ClearUnacknowledgedPreKeyMessage(); return(plaintext); }
public void SavePositionGradeList(List <PositionGrade> grades, List <int> delItems, Account loginUser) { try { using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required)) { foreach (int i in delItems) { DeletePositionGrade(i, loginUser); } for (int i = 0; i < grades.Count; i++) { grades[i].Sequence = i; if (grades[i].Id == -1) { CreatePositionGrade(grades[i], loginUser); } else { UpdatePositionGrade(grades[i], loginUser); } } ts.Complete(); } } catch (Exception ex) { throw MessageKeys.AppException(ex.Message); } }
private byte[] decrypt(SessionState sessionState, WhisperMessage ciphertextMessage) { if (!sessionState.hasSenderChain()) { throw new InvalidMessageException("Uninitialized session!"); } if (ciphertextMessage.getMessageVersion() != sessionState.getSessionVersion()) { throw new InvalidMessageException($"Message version {ciphertextMessage.getMessageVersion()}, but session version {sessionState.getSessionVersion()}"); } uint messageVersion = ciphertextMessage.getMessageVersion(); ECPublicKey theirEphemeral = ciphertextMessage.getSenderRatchetKey(); uint counter = ciphertextMessage.getCounter(); ChainKey chainKey = getOrCreateChainKey(sessionState, theirEphemeral); MessageKeys messageKeys = getOrCreateMessageKeys(sessionState, theirEphemeral, chainKey, counter); ciphertextMessage.verifyMac(messageVersion, sessionState.getRemoteIdentityKey(), sessionState.getLocalIdentityKey(), messageKeys.getMacKey()); byte[] plaintext = getPlaintext(messageVersion, messageKeys, ciphertextMessage.getBody()); sessionState.clearUnacknowledgedPreKeyMessage(); return(plaintext); }
/** * Encrypt a message. * * @param paddedMessage The plaintext message bytes, optionally padded to a constant multiple. * @return A ciphertext message encrypted to the recipient+device tuple. */ public CiphertextMessage encrypt(byte[] paddedMessage) { lock (SESSION_LOCK) { SessionRecord sessionRecord = sessionStore.loadSession(remoteAddress); SessionState sessionState = sessionRecord.getSessionState(); ChainKey chainKey = sessionState.getSenderChainKey(); MessageKeys messageKeys = chainKey.getMessageKeys(); ECPublicKey senderEphemeral = sessionState.getSenderRatchetKey(); uint previousCounter = sessionState.getPreviousCounter(); uint sessionVersion = sessionState.getSessionVersion(); byte[] ciphertextBody = getCiphertext(sessionVersion, messageKeys, paddedMessage); CiphertextMessage ciphertextMessage = new WhisperMessage(sessionVersion, messageKeys.getMacKey(), senderEphemeral, chainKey.getIndex(), previousCounter, ciphertextBody, sessionState.getLocalIdentityKey(), sessionState.getRemoteIdentityKey()); if (sessionState.hasUnacknowledgedPreKeyMessage()) { SessionState.UnacknowledgedPreKeyMessageItems items = sessionState.getUnacknowledgedPreKeyMessageItems(); uint localRegistrationId = sessionState.getLocalRegistrationId(); ciphertextMessage = new PreKeyWhisperMessage(sessionVersion, localRegistrationId, items.getPreKeyId(), items.getSignedPreKeyId(), items.getBaseKey(), sessionState.getLocalIdentityKey(), (WhisperMessage)ciphertextMessage); } sessionState.setSenderChainKey(chainKey.getNextChainKey()); sessionStore.storeSession(remoteAddress, sessionRecord); return(ciphertextMessage); } }
/// <summary> /// 修改职位层级有效性判断: /// 1、修改的职位层级已经存在 /// 2、职位层级不能与已有的其他职位层级重名 /// 3、职位层级在使用中 /// </summary> protected override void Validation() { if (DalInstance.PositionDalInstance.CountPositionNatureByNameDiffPKID(_PositionNature.Pkid, _PositionNature.Name) > 0) { throw MessageKeys.AppException(MessageKeys._PositionNature_Name_Repeat); } }
public void SaveCompanyRegulations(CompanyRegulation companyRegulations, Account loginUser) { Validation(companyRegulations); using (TransactionScope ts = new TransactionScope(TransactionScopeOption.RequiresNew)) { try { // 删除公司规章 if (companyRegulations.CompanyRegulationsID > 0) { DalInstance.CompanyRegulationDalInstance.DeleteCompanyReguAppendixByCompanyRegulationsID(companyRegulations.CompanyRegulationsID); DalInstance.CompanyRegulationDalInstance.DeleteCompanyRegulationsByPKID(companyRegulations.CompanyRegulationsID); } // 新增公司规章 int companyReguID = DalInstance.CompanyRegulationDalInstance.InsertCompanyRegulations(companyRegulations); if (companyRegulations.AppendixList != null) { foreach (CompanyReguAppendix companyReguAppendix in companyRegulations.AppendixList) { companyReguAppendix.CompanyReguID = companyReguID; //新增公司规章附件 DalInstance.CompanyRegulationDalInstance.InsertCompanyReguAppendix(companyReguAppendix); } } ts.Complete(); } catch { throw MessageKeys.AppException(MessageKeys._DbError); } } }
/** * Encrypt a message. * * @param paddedMessage The plaintext message bytes, optionally padded to a constant multiple. * @return A ciphertext message encrypted to the recipient+device tuple. */ public CiphertextMessage Encrypt(byte[] paddedMessage) { lock (SessionLock) { SessionRecord sessionRecord = _sessionStore.LoadSession(_remoteAddress); SessionState sessionState = sessionRecord.GetSessionState(); ChainKey chainKey = sessionState.GetSenderChainKey(); MessageKeys messageKeys = chainKey.GetMessageKeys(); IEcPublicKey senderEphemeral = sessionState.GetSenderRatchetKey(); uint previousCounter = sessionState.GetPreviousCounter(); uint sessionVersion = sessionState.GetSessionVersion(); byte[] ciphertextBody = GetCiphertext(sessionVersion, messageKeys, paddedMessage); CiphertextMessage ciphertextMessage = new SignalMessage(sessionVersion, messageKeys.GetMacKey(), senderEphemeral, chainKey.GetIndex(), previousCounter, ciphertextBody, sessionState.GetLocalIdentityKey(), sessionState.GetRemoteIdentityKey()); if (sessionState.HasUnacknowledgedPreKeyMessage()) { SessionState.UnacknowledgedPreKeyMessageItems items = sessionState.GetUnacknowledgedPreKeyMessageItems(); uint localRegistrationId = sessionState.GetLocalRegistrationId(); ciphertextMessage = new PreKeySignalMessage(sessionVersion, localRegistrationId, items.GetPreKeyId(), items.GetSignedPreKeyId(), items.GetBaseKey(), sessionState.GetLocalIdentityKey(), (SignalMessage)ciphertextMessage); } sessionState.SetSenderChainKey(chainKey.GetNextChainKey()); _sessionStore.StoreSession(_remoteAddress, sessionRecord); return(ciphertextMessage); } }
private MessageKeys GetOrCreateMessageKeys(SessionState sessionState, IEcPublicKey theirEphemeral, ChainKey chainKey, uint counter) { if (chainKey.GetIndex() > counter) { if (sessionState.HasMessageKeys(theirEphemeral, counter)) { return(sessionState.RemoveMessageKeys(theirEphemeral, counter)); } else { throw new DuplicateMessageException($"Received message with old counter: {chainKey.GetIndex()} , {counter}"); } } //Avoiding a uint overflow uint chainKeyIndex = chainKey.GetIndex(); if ((counter > chainKeyIndex) && (counter - chainKeyIndex > 2000)) { throw new InvalidMessageException("Over 2000 messages into the future!"); } while (chainKey.GetIndex() < counter) { MessageKeys messageKeys = chainKey.GetMessageKeys(); sessionState.SetMessageKeys(theirEphemeral, messageKeys); chainKey = chainKey.GetNextChainKey(); } sessionState.SetReceiverChainKey(theirEphemeral, chainKey.GetNextChainKey()); return(chainKey.GetMessageKeys()); }
protected override void Validation() { //权限验证 if (!Powers.HasAuth(_LoginUser.Auths, AuthType.SEP, Powers.A503)) { throw MessageKeys.AppException(MessageKeys._NoAuth); } }
public List <Auth> GetAccountAllAuth(int accountId, Account loginUser) { if (!Powers.HasAuth(loginUser.Auths, AuthType.SEP, Powers.A103) && accountId != loginUser.Id) { throw MessageKeys.AppException(MessageKeys._NoAuth); } return(DalInstance.AuthDalInstance.GetAccountAuthTree(accountId)); }
protected override void Validation() { //该附件是否存在 if (DalInstance.BulletinDalInstance.GetAppendixByPKID(_AppendixID) == null) { throw MessageKeys.AppException(MessageKeys._Appendix_Not_Exist); } }
protected override void Validation() { //验证字段:标题不能重名 if (DalInstance.BulletinDalInstance.GetBulletinCountByTitle(_Bulletin.Title) > 0) { throw MessageKeys.AppException(MessageKeys._Bulletin_Title_Repeat); } }
protected override void Validation() { //该公告是否存在 if (DalInstance.BulletinDalInstance.GetBulletinByBulletinID(_BulletinID) == null) { throw MessageKeys.AppException(MessageKeys._Bulletin_Not_Exist); } }
public List <Auth> GetAllAuth(Account loginUser) { if (!Powers.HasAuth(loginUser.Auths, AuthType.SEP, Powers.A103)) { throw MessageKeys.AppException(MessageKeys._NoAuth); } return(GetAllAuth()); }
protected override void Validation() { //验证字段:记录存在 _Bulletin = _BulletinDal.GetBulletinByBulletinID(_BulletinID); if (_Bulletin == null) { throw MessageKeys.AppException(MessageKeys._Bulletin_Not_Exist); } }
protected override void ExcuteSelf() { try { DalInstance.BulletinDalInstance.DeleteAppendixByPKID(_AppendixID); } catch { throw MessageKeys.AppException(MessageKeys._DbError); } }
protected override void ExcuteSelf() { try { DalInstance.PositionDalInstance.DeletePosition(_PositionId); } catch { throw MessageKeys.AppException(MessageKeys._DbError); } }
protected override void ExcuteSelf() { try { DalInstance.GoalDalInstance.UpdateCompanyGoal(_CompanyGoal); } catch { throw MessageKeys.AppException(MessageKeys._DbError); } }
protected override void ExcuteSelf() { try { DalInstance.GoalDalInstance.InsertPersonalGoal(_PersonalGoal); } catch { throw MessageKeys.AppException(MessageKeys._DbError); } }
protected override void Validation() { //if(!Powers.HasAuth(_LoginUser.Auths, Powers.A401)) // throw MessageKeys.AppException(MessageKeys._NoAuth); //该目标是否存在 if (DalInstance.GoalDalInstance.GetGoalByPKID(_GoalId) == null) { throw MessageKeys.AppException(MessageKeys._Goal_NotExist); } }
protected override void ExcuteSelf() { try { DalInstance.GoalDalInstance.DeleteGoalByPKID(_GoalId); } catch { throw MessageKeys.AppException(MessageKeys._DbError); } }
protected override void ExcuteSelf() { try { DalInstance.PositionDalInstance.InsertPositionNature(_PositionNature); } catch { throw MessageKeys.AppException(MessageKeys._DbError); } }
protected override void ExcuteSelf() { try { DalInstance.WorkTaskDalInstance.DeleteWorkTaskQA(_WorkTaskQAId); } catch { throw MessageKeys.AppException(MessageKeys._DbError); } }
public BaseHeader(MessageKeys key) { Key = key; }
public static Type GetMessageType(MessageKeys key) { return _types[key]; }