Make your own free website on Tripod.com
EPolWS
OrganisationView
Home
Account
ep_test.txt
SerializableBase
DbConnectionBase
EPolESForm
DbSTable
EmailFactory.cs
epmain
EPolES
DbVariableView.cs
ProfileView
EPolLOcal Main
Page Main Example
EPolWS EPolWS.asmx
EPolWS EPolWS.cs
CommandManager
CommandFactory
CommandFactoryBase
OrganisationView
EPolConsole Main
DbEPBase.cs
DbRecordArray
DbTable

Enter subhead content here

using System; using System.Text; using System.Collections; using System.Diagnostics; using System.Runtime.Serialization; using System.Runtime.Serialization.Formatters; using System.Runtime.Serialization.Formatters.Binary; using System.IO; using EXCommon; using EXDb97; //###2 namespace EPol { //---------------------------------------------------------------------------------------------------------------------------------------------- /// /// Summary description for GroupDbTable. /// //---------------------------------------------------------------------------------------------------------------------------------------------- public class COrganisationMemberView : CDbJoinView { public COrganisationMemberView(string sDatabaseName) : base(new CDbTableView(ORGANISATION_PREFIXE, new COrganisationDbTable(sDatabaseName)), new CDbTableView(MEMBER_PREFIXE, new COrganisationMemberDbTable(sDatabaseName))) { vAddLinkIndex(ORGANISATION_PREFIXE, MASTER_INDEX_FIELD, MEMBER_PREFIXE, ORGANISATION_INDEX_FIELD); vAddLinkIndex(ORGANISATION_PREFIXE, MASTER_SUB_INDEX_FIELD, MEMBER_PREFIXE, ORGANISATION_SUB_INDEX_FIELD); } public COrganisationDbTable GetOrganisationTable { get { return (COrganisationDbTable)((CDbTableView)this.GetMasterView).oGetTable; } } public COrganisationMemberDbTable GetMemberTable { get { return (COrganisationMemberDbTable)((CDbTableView)this.GetSlaveView).oGetTable; } } public ec dDelete(SIndex oOrganisationIndex) { ec dErrorCode = GetMemberTable.dRemoveAllMembers(oOrganisationIndex); if (dErrorCode == ec.ST_SUCCEED) { dErrorCode = GetOrganisationTable.dDelete(oOrganisationIndex); } return dErrorCode; } public ec dAddOrganisation(string csName, SIndex oParentOrganisationIndex, bool bVirtualOrganisation, SIndex oCreatorProfileIndex, P dLanguage) { ec dErrorCode; if (IsUsed(oParentOrganisationIndex)) { dErrorCode = GetOrganisationTable.dAdd(csName, dLanguage, oParentOrganisationIndex, bVirtualOrganisation); } else { dErrorCode = GetOrganisationTable.dAdd(csName, dLanguage, bVirtualOrganisation); } if (dErrorCode == ec.ST_SUCCEED) { SIndex oOrganisationIndex = GetOrganisationTable.dGetIndex(csName); dErrorCode = GetMemberTable.dAdd(oOrganisationIndex, iGetPublicProfileIfLoginProfile(oCreatorProfileIndex), P.ADMINISTRATOR_ORGANISATION); } CTrace.i().vWriteLn(ENMessage.Organisation, GetOrganisationTable.csDumpTable()); CTrace.i().vWriteLn(ENMessage.Organisation, GetMemberTable.csDumpTable()); return dErrorCode; } /* public ec dGetAccessableProfile(int dReaderProfileIndex, out SIndex[] oAvatarOfAuthorIndexArray) { vResetSelect(); bAddWhere(MEMBER_PREFIXE, PROFILE_INDEX_FIELD, dReaderProfileIndex); bAddDisplayColumn(MEMBER_PREFIXE, PROFILE_INDEX_FIELD); bAddDisplayColumn(MEMBER_PREFIXE, PROFILE_SUB_INDEX_FIELD); CTrace.i().vWriteLn(ENMessage.Organisation,"m_oOrganisationMemberView dump = " + sql(sGetFieldList)); CTrace.i().vWriteLn(ENMessage.Organisation,"m_oOrganisationAvatarView dump = " + csDumpTable()); ArrayList oFieldOutputArray; ec dRC = dGetSelect(out oFieldOutputArray); if (oFieldOutputArray == null) { dRC = ec.ST_PROFILE_CAN_NOT_ACCESS_ANY_OTHER_PROFILE; oAvatarOfAuthorIndexArray = null; } else { oAvatarOfAuthorIndexArray = new SIndex[oFieldOutputArray.Count]; if (dRC == ec.ST_SUCCEED) { for (int dLn = 0; dLn < oFieldOutputArray.Count; dLn++) { object[] oOutputArray = (object[])oFieldOutputArray[dLn]; oAvatarOfAuthorIndexArray[dLn].dIndex = Convert.ToInt32(oOutputArray[0]); oAvatarOfAuthorIndexArray[dLn].dSubIndex = Convert.ToInt32(oOutputArray[1]); } } } CTrace.i().vWriteLn(ENMessage.Access, " dGetAccessableProfile profile by organisation(" + dReaderProfileIndex + ")=" + ToString(oAvatarOfAuthorIndexArray)); return dRC; } */ } //---------------------------------------------------------------------------------------------------------------------------------------------- /// /// Summary description for GroupDbTable. /// //---------------------------------------------------------------------------------------------------------------------------------------------- /// public class COrganisationView : CCommandFactoryBase { public COrganisationView(P dLanguage, string sDatabaseName) { m_dLanguage = dLanguage; m_oProfileView = new CProfileView(dLanguage, sDatabaseName); m_oOrganisationMemberView = new COrganisationMemberView(sDatabaseName); m_oMyOrganisationMemberView = new CDbJoinView( new CDbTableView(PROFILE_PREFIXE, m_oProfileView.GetMasterTable), m_oOrganisationMemberView); m_oMyOrganisationMemberView.vAddLinkIndex(PROFILE_PREFIXE, MASTER_INDEX_FIELD, COrganisationMemberView.MEMBER_PREFIXE, PROFILE_INDEX_FIELD); m_oMyOrganisationMemberView.vAddLinkIndex(PROFILE_PREFIXE, MASTER_SUB_INDEX_FIELD, COrganisationMemberView.MEMBER_PREFIXE, PROFILE_SUB_INDEX_FIELD); m_oOrganisationRelationDbTable = new COrganisationRelationDbTable(sDatabaseName); // m_oAvatarAuthorAccess = NOT_USED_SINDEX; } P m_dLanguage; const string PROFILE_PREFIXE = "prof"; COrganisationRelationDbTable m_oOrganisationRelationDbTable; CProfileView m_oProfileView; CDbJoinView m_oMyOrganisationMemberView; COrganisationMemberView m_oOrganisationMemberView; public void vCleanAllData() { m_oOrganisationMemberView.vCleanAllData(); m_oMyOrganisationMemberView.vCleanAllData(); m_oOrganisationRelationDbTable.dDropTable(); m_oProfileView.vCleanAllData(); } public COrganisationDbTable GetOrganisationTable { get { return m_oOrganisationMemberView.GetOrganisationTable; } } public CProfileView GetProfileView { get { return m_oProfileView; } } public COrganisationMemberDbTable GetMemberTable { get { return m_oOrganisationMemberView.GetMemberTable; } } public ec dDelete(SIndex oOrganisationIndex, SIndex oCreatorIndex) { ec dErrorCode = ec.ST_SUCCEED; if (oCreatorIndex.dIndex != dGetCreatorProfileIndex(oOrganisationIndex).dIndex) { dErrorCode = ec.ST_ORGANISATION_DELETE_NOT_THE_ADMINISTRATOR; } else if (GetMemberTable.dCountRegisteredMember(oOrganisationIndex) > 0) { dErrorCode = ec.ST_ORGANISATION_DELETE_AT_LEAST_ONE_MEMBER_DID_NOT_REMOVE_HIS_GRANT_ACCESS; } else { dErrorCode = m_oOrganisationRelationDbTable.dRemoveAllRelationsAbout(oOrganisationIndex); if (dErrorCode == ec.ST_SUCCEED) { dErrorCode = m_oOrganisationMemberView.dDelete(oOrganisationIndex); } } return dErrorCode; } public SIndex dGetCreatorProfileIndex(SIndex oOrganisationIndex) { return GetMemberTable.dGetCreator(oOrganisationIndex); } public ec dAddOrganisation(string csName, SIndex oParentOrganisationIndex, bool bVirtualOrganisation, SIndex oCreatorProfileIndex) { P dLanguage = m_oProfileView.dGetLanguage(oCreatorProfileIndex); if (dLanguage == P.LANGUAGE) { return ec.ST_ORGANISATION_LANGUAGE_OPTION_SHOULD_BE_SPECIFIED; } ec dErrorCode = m_oOrganisationMemberView.dAddOrganisation(csName, oParentOrganisationIndex, bVirtualOrganisation, oCreatorProfileIndex, dLanguage); return dErrorCode; } public SIndex dGetOrganisationIndex(string csName) { return GetOrganisationTable.dGetIndex(csName); } public ec dAddOrganisation(string csName, bool bVirtualOrganisation, SIndex oCreatorProfileIndex) { if (IsNotUsed(oCreatorProfileIndex)) { return ec.ST_ORGANISATION_CREATION_AVATAR_SHOULD_BE_SPECIFIED; } P dLanguage = m_oProfileView.dGetLanguage(oCreatorProfileIndex); if (dLanguage == P.LANGUAGE) { return ec.ST_ORGANISATION_LANGUAGE_OPTION_SHOULD_BE_SPECIFIED; } ec dErrorCode = m_oOrganisationMemberView.dAddOrganisation(csName, NOT_USED_SINDEX, bVirtualOrganisation, oCreatorProfileIndex, dLanguage); return dErrorCode; } public ec dAddMember(SIndex oOrganisationIndex, SIndex oCommandCallerIndex, SIndex oMemberProfileIndex) { ec dRC = ec.ST_SUCCEED; if (IsNotUsed(oOrganisationIndex)) { return ec.ST_ORGANISATION_NAME_IS_NOT_KNOWN; } else if (oMemberProfileIndex.dSubIndex == PRIVATE_PROFILE_SUB_INDEX) { dRC = ec.ST_ORGANISATION_CREATION_MEMBER_SECRET_PROFILE_CAN_NOT_BE_ADDED; } else { SIndex oCreatorIndex = dGetCreatorProfileIndex(oOrganisationIndex); if (oCommandCallerIndex.dIndex != oCreatorIndex.dIndex) { dRC = ec.ST_ORGANISATION_DELETE_NOT_THE_ADMINISTRATOR; } else { P dMemberLanguage = m_oProfileView.dGetLanguage(oMemberProfileIndex); if (dMemberLanguage == P.LANGUAGE) { dRC = ec.ST_ORGANISATION_LANGUAGE_LANGUAGE_ERROR; } else if (dMemberLanguage != GetOrganisationTable.dGetLanguage(oOrganisationIndex)) { dRC = ec.ST_ORGANISATION_LANGUAGE_MISMATCH_WITH_MEMBER; } else { dRC = GetMemberTable.dAdd(oOrganisationIndex, oMemberProfileIndex, P.MEMBER); } } } CTrace.i().vWriteLn(ENMessage.Organisation,"dRC = " + dRC + GetMemberTable.csDumpTable()); return dRC; } public ec dGetListMember(SIndex oOrganisationIndex, out string sTextMessage) { SIndex[] oProfileIndexArray; P[] dPositionArray; bool[] bGrantAccessArray; ec dRC = GetMemberTable.dGetMember(oOrganisationIndex, out oProfileIndexArray, out dPositionArray, out bGrantAccessArray); sTextMessage = null; CTrace.i().vWriteLn(ENMessage.Organisation,GetMemberTable.csDumpTable()); CTrace.i().vWriteLn(ENMessage.Organisation,m_oProfileView.GetMasterTable.csDumpTable()); if (dRC == ec.ST_SUCCEED) { CVariableListReport oVariableListReport = new CVariableListReport("Name", "Position", "GrantAccess"); for (int dLn = 0; dLn < oProfileIndexArray.Length; dLn++) { string sAvatarName = m_oProfileView.GetMasterTable.sGetName(oProfileIndexArray[dLn]); oVariableListReport.vAdd(sAvatarName, CEntityManager.Instance(this.m_dLanguage).sGetEntityName( dPositionArray[dLn]), bGrantAccessArray[dLn].ToString()); } sTextMessage = oVariableListReport.sText; } return dRC; } /* public bool bReaderHasAReadAccessToAuthor(int dReaderProfileIndex, SIndex oAuthorAuthorizedToReadDocumentAvatarIndex) { SIndex[] oAuthorAuthorizedToReadDocumentAvatarIndexArray= new SIndex[1]; oAuthorAuthorizedToReadDocumentAvatarIndexArray[0]=oAuthorAuthorizedToReadDocumentAvatarIndex; return bReaderHasAReadAccessToAuthor(dReaderProfileIndex, oAuthorAuthorizedToReadDocumentAvatarIndexArray); } * */ // public SIndex m_oAvatarAuthorAccess; public bool bHasAPublicProfile(SIndex[] oAuthorAuthorizedToReadDocumentAvatarIndexArray) { if (oAuthorAuthorizedToReadDocumentAvatarIndexArray != null) { for (int i = 0; i < oAuthorAuthorizedToReadDocumentAvatarIndexArray.Length; i++) { if (oAuthorAuthorizedToReadDocumentAvatarIndexArray[i].dSubIndex == PUBLIC_PROFILE_SUB_INDEX) { return true; } } } return false; } public bool bReaderHasAReadAccessToAuthor(int dReaderProfileIndex, SIndex[] oAuthorAuthorizedToReadDocumentAvatarIndexArray, out SIndex oAvatarAuthorAccess) { CTrace.i().vWriteLn(ENMessage.Access, "bReaderHasAReadAccessToAuthor oAuthorAuthorizedToReadDocumentAvatarIndexArray= " + ToString(oAuthorAuthorizedToReadDocumentAvatarIndexArray)); oAvatarAuthorAccess = NOT_USED_SINDEX; if (oAuthorAuthorizedToReadDocumentAvatarIndexArray== null || (dReaderProfileIndex == oAuthorAuthorizedToReadDocumentAvatarIndexArray[0].dIndex ) || IsNotUsed(oAuthorAuthorizedToReadDocumentAvatarIndexArray[0])) { oAvatarAuthorAccess = new SIndex(dReaderProfileIndex, PUBLIC_PROFILE_SUB_INDEX); return true; } else if ( bHasAPublicProfile(oAuthorAuthorizedToReadDocumentAvatarIndexArray)) { oAvatarAuthorAccess = new SIndex(oAuthorAuthorizedToReadDocumentAvatarIndexArray[0].dIndex, PUBLIC_PROFILE_SUB_INDEX); return true; } else { SIndex[] oAvatarOfAuthorIndexArray; dGetAccessableProfile(dReaderProfileIndex, oAuthorAuthorizedToReadDocumentAvatarIndexArray[0].dIndex, out oAvatarOfAuthorIndexArray); CTrace.i().vWriteLn(ENMessage.Access, " oAvatarOfAuthorIndexArray = " + ToString(oAvatarOfAuthorIndexArray)); for (int i = 0; i < oAuthorAuthorizedToReadDocumentAvatarIndexArray.Length; i++) { if (dReaderProfileIndex == oAuthorAuthorizedToReadDocumentAvatarIndexArray[i].dIndex || IsNotUsed(oAuthorAuthorizedToReadDocumentAvatarIndexArray[i])) { oAvatarAuthorAccess = new SIndex(dReaderProfileIndex, PUBLIC_PROFILE_SUB_INDEX); return true; } for (int j = 0; j < oAvatarOfAuthorIndexArray.Length; j++) { if ( m_oProfileView.GetMasterTable.bIsChildOf(oAvatarOfAuthorIndexArray[j], oAuthorAuthorizedToReadDocumentAvatarIndexArray[i])) { oAvatarAuthorAccess = oAuthorAuthorizedToReadDocumentAvatarIndexArray[i]; return true; } } } return false; } } public ec dGetAccessableProfile(int dReaderProfileIndex, int dAuthorProfileIndex, out SIndex[] oAvatarOfAuthorIndexArray) { SIndex[] oFriendAvatarOfAuthorIndexArray, oAccessibleFromOrganisationArray; ec dRC = m_oProfileView.dGetSelectFriendAvatarAccess(dReaderProfileIndex, dAuthorProfileIndex, out oFriendAvatarOfAuthorIndexArray); dRC = dGetListAccessibleProfileThroughOrganisation(dReaderProfileIndex, out oAccessibleFromOrganisationArray); oAvatarOfAuthorIndexArray = oConcat(oFriendAvatarOfAuthorIndexArray, Extract(dAuthorProfileIndex, oAccessibleFromOrganisationArray)); CTrace.i().vWriteLn(ENMessage.Access, " dGetAccessableProfile Friend and Organisation) = " + ToString(oAvatarOfAuthorIndexArray)); return dRC; } public ec dGetListAccessibleProfileThroughOrganisation(int dReadingProfileIndex, out SIndex[] oAccessibleAvatarArray) { ArrayList oFieldOutputArray; m_oMyOrganisationMemberView.vResetSelect(); m_oMyOrganisationMemberView.bAddReflexiveWhere(MEMBER_PREFIXE, PROFILE_INDEX_FIELD, dReadingProfileIndex); m_oMyOrganisationMemberView.bAddDisplayReflexiveColumn(PROFILE_PREFIXE, MASTER_INDEX_FIELD); m_oMyOrganisationMemberView.bAddDisplayReflexiveColumn(PROFILE_PREFIXE, MASTER_SUB_INDEX_FIELD); CTrace.i().vWriteLn(ENMessage.Organisation, "m_oMyOrganisationMemberView dump = " + m_oMyOrganisationMemberView.sqlReflexive(m_oMyOrganisationMemberView.sGetFieldList)); // CTrace.i().vWriteLn(ENMessage.Organisation,"m_oMyOrganisationAvatarView dump = " + m_oMyOrganisationMemberView.csDumpTable()); ec dRC = m_oMyOrganisationMemberView.dGetReflexiveSelect(out oFieldOutputArray); oAccessibleAvatarArray = ToSIndexArray(oFieldOutputArray, 0); CTrace.i().vWriteLn(ENMessage.Access, " dGetListAccessibleProfileThroughOrganisation Organisation) = " + oAccessibleAvatarArray); return dRC; } public ec dGetListAvatarWithPrivilegeAccess(SIndex oClaimingProfileIndex, out string sTextMessage) { ArrayList oFieldOutputArray; m_oMyOrganisationMemberView.vResetSelect(); m_oMyOrganisationMemberView.bAddReflexiveWhere(MEMBER_PREFIXE, PROFILE_INDEX_FIELD, oClaimingProfileIndex.dIndex); m_oMyOrganisationMemberView.bAddDisplayReflexiveColumn(PROFILE_PREFIXE, MASTER_NAME_FIELD); m_oMyOrganisationMemberView.bAddDisplayReflexiveColumn(ORGANISATION_PREFIXE, MASTER_NAME_FIELD); m_oMyOrganisationMemberView.bAddDisplayColumn(PROFILE_PREFIXE, MASTER_NAME_FIELD); CTrace.i().vWriteLn(ENMessage.Organisation,"m_oMyOrganisationMemberView dump = " + m_oMyOrganisationMemberView.sqlReflexive(m_oMyOrganisationMemberView.sGetFieldList)); // CTrace.i().vWriteLn(ENMessage.Organisation,"m_oMyOrganisationAvatarView dump = " + m_oMyOrganisationMemberView.csDumpTable()); ec dRC = m_oMyOrganisationMemberView.dGetReflexiveSelect(out oFieldOutputArray); sTextMessage = null; CVariableListReport oVariableListReport = new CVariableListReport("Avatar", "Organisation", "MyAvatar"); if (dRC == ec.ST_SUCCEED) { for (int dLn = 0; dLn < oFieldOutputArray.Count; dLn++) { oVariableListReport.vAddRow((object[])oFieldOutputArray[dLn]); } } CTrace.i().vWriteLn(ENMessage.Organisation,m_oProfileView.GetMasterTable.csDumpTable()); CTrace.i().vWriteLn(ENMessage.Organisation,m_oProfileView.GetFriendTable.csDumpTable()); ArrayList oAvatarNameArrayList; dRC = m_oProfileView.dGetSelectFriendAvatarAccess(oClaimingProfileIndex, out oAvatarNameArrayList); if (dRC == ec.ST_SUCCEED) { for (int dLn = 0; dLn < oAvatarNameArrayList.Count; dLn++) { oVariableListReport.vAdd(((object[])oAvatarNameArrayList[dLn])[0], "friend", ((object[])oAvatarNameArrayList[dLn])[1] ); } } sTextMessage = oVariableListReport.sText; return dRC; } public ec dGetListFriend(SIndex oClaimingProfileIndex, out string sTextMessage) { CTrace.i().vWriteLn(ENMessage.Organisation,m_oProfileView.GetMasterTable.csDumpTable()); CTrace.i().vWriteLn(ENMessage.Organisation,m_oProfileView.GetFriendTable.csDumpTable()); CVariableListReport oVariableListReport = new CVariableListReport("Friend", "MyAvatar", "Date Modified"); ArrayList oAvatarNameArrayList; ec dRC = m_oProfileView.dGetSelectFriend(oClaimingProfileIndex, out oAvatarNameArrayList); if (dRC == ec.ST_SUCCEED) { for (int dLn = 0; dLn < oAvatarNameArrayList.Count; dLn++) { oVariableListReport.vAddRow((object[])oAvatarNameArrayList[dLn]); } } sTextMessage = oVariableListReport.sText; return dRC; } public void vGetMemeContent(int dReaderProfileIndex, CMemeArray oMemeArray, out SMemeDisplay[] oContentArray) { oContentArray = new SMemeDisplay[oMemeArray.Length]; for (int i = 0; i < oMemeArray.Length; i++) { oContentArray[i].iMeme = oMemeArray[i].m_iMemeIndex; m_oProfileView.GetIdentifierView.dConvert(oMemeArray[i].oGetAddress, true, out oContentArray[i].sAddress); SIndex oAvatarAuthorAccess; if (bReaderHasAReadAccessToAuthor(dReaderProfileIndex, oMemeArray[i].m_iAvatarAuthorAccessArray, out oAvatarAuthorAccess)) { // sTextMessage += m_oProfileView.GetMasterTable.sGetName(m_oOrganisationView.m_oAvatarAuthorAccess) + " has " + sOptionAddress; // sTextMessage += " is " + oMemeArray[i].ToString() + '\n'; oContentArray[i].sContent = oMemeArray[i].ToString(); } else { oContentArray[i].sContent = null; // sTextMessage += m_oProfileView.GetMasterTable.sGetName(m_oOrganisationView.m_oAvatarAuthorAccess) + " has " + sOptionAddress; // sTextMessage += ": You have no access authorisation to this content\n"; } CTrace.i().vWriteLn(ENMessage.Attribute, " (oMemeArray[i].oGetAddress= " + oMemeArray[i].oGetAddress.csDump() + " m_oOrganisationView.m_oAvatarAutorAccess = " + oAvatarAuthorAccess); oContentArray[i].sAuthorName = m_oProfileView.GetMasterTable.sGetName(oAvatarAuthorAccess); } } } //---------------------------------------------------------------------------------------------------------------------------------------------- /// /// Summary description for GroupDbTable. /// //---------------------------------------------------------------------------------------------------------------------------------------------- /// public class COrganisationDbTable : CDbMasterTable { public COrganisationDbTable(string strDatabaseName) : base(ORGANISATION_LIST_TABLE_NAME, strDatabaseName) { vAddColumn(LANGUAGE_FIELD, ENTITY_TYPE, false); vAddColumn("IsVirtual", BOOLEAN_TYPE, false); } static string csLanguageZoneName(int dLanguage) { return "Zone." + dLanguage.ToString(); } public SIndex dGetLanguageZone(int dLanguage) { return base.dGetIndex(csLanguageZoneName(dLanguage)); } public P dGetLanguage(SIndex oOrganisationIndex) { return (P)this.GetInteger(LANGUAGE_FIELD, sqlIsIndex(oOrganisationIndex.dIndex)); } const int LANGUAGE_ZONE_PARENT_INDEX = 0; public ec dAddVirtual(string csName, P dLanguage) { return dAdd(csName, dLanguage, true); } public SIndex dAddFirstProfile(string sProfileID) { SIndex oMainIndex; if (bHasOnlyAuthorizeCharacter(sProfileID) == false) { return NOT_USED_SINDEX; } oMainIndex = dAddProfileIndexValues(ORGANISATION_ROOT_SUB_INDEX, NOT_USED); vAddValue(sProfileID); return oMainIndex; } public ec dAdd(string csName, P dLanguage, bool bVirtualOrganisation) { this.dAddFirstProfile(csName); vAddValue((int)dLanguage); vAddValue(bVirtualOrganisation); return base.dInsertIntoTable() == ec.ST_SUCCEED ? ec.ST_SUCCEED : ec.ST_ORGANISATION_CREATION_FAILED; } public ec dAdd(string csName, P dLanguage, SIndex oParentOrganisationIndex, bool bVirtualOrganisation) { P dParentLanguage = dGetLanguage(oParentOrganisationIndex); if (dLanguage != dParentLanguage) { return ec.ST_ORGANISATION_PARENT_ORGANISATION_LANGUAGE_CAN_NOT_BE_DIFFERENT_THAN_CURRENT_ORGANISATION; } dAddNewSubProfile(csName, oParentOrganisationIndex); vAddValue(dLanguage); vAddValue(bVirtualOrganisation); return base.dInsertIntoTable() == ec.ST_SUCCEED ? ec.ST_SUCCEED : ec.ST_ORGANISATION_CREATION_FAILED; } } ///---------------------------------------------------------------------------------------------------------------------------------------------- /// /// Summary description for GroupDbTable. /// ///---------------------------------------------------------------------------------------------------------------------------------------------- public class COrganisationRelationDbTable : CDbSTable { public COrganisationRelationDbTable(string strDatabaseName) : base("OrganisationRelationTable", strDatabaseName) { vAddColumn(ORGANISATION_INDEX_FIELD, INTEGER_TYPE, true); vAddColumn(ORGANISATION_SUB_INDEX_FIELD, INTEGER_TYPE, true); vAddColumn(ORGANISATION_RELATION_FIELD, INTEGER_TYPE, true); vAddColumn("OrganisationTargetIndex", INTEGER_TYPE, false); vAddColumn("OrganisationTargetSubIndex", INTEGER_TYPE, false); } public string sqlIsIndex(SIndex oOrganisationIndex) { return sFieldEqual(ORGANISATION_INDEX_FIELD, oOrganisationIndex.dIndex) + AND + sFieldEqual(ORGANISATION_SUB_INDEX_FIELD, oOrganisationIndex.dSubIndex); } public ec dRemoveAllRelationsAbout(SIndex oOrganisationIndex) { ec dRet = dDelete(sqlIsIndex(oOrganisationIndex)); if (dRet != ec.ST_SUCCEED) return ec.ST_ORGANISATION_DELETE_RELATION_PROBLEM; dRet = dDelete(sFieldEqual("OrganisationTargetIndex", oOrganisationIndex.dIndex) + AND + sFieldEqual("OrganisationTargetSubIndex", oOrganisationIndex.dSubIndex)); if (dRet != ec.ST_SUCCEED) return ec.ST_ORGANISATION_DELETE_RELATION_PROBLEM; return ec.ST_SUCCEED; } } ///---------------------------------------------------------------------------------------------------------------------------------------------- /// /// Summary description for GroupDbTable. /// ///---------------------------------------------------------------------------------------------------------------------------------------------- public class COrganisationMemberDbTable : CDbSTable { public COrganisationMemberDbTable(string strDatabaseName) : base("OrganisationMemberTable", strDatabaseName) { vAddColumn(ORGANISATION_INDEX_FIELD, INTEGER_TYPE, true); vAddColumn(ORGANISATION_SUB_INDEX_FIELD, INTEGER_TYPE, true); vAddColumn(PROFILE_INDEX_FIELD, INTEGER_TYPE, true); vAddColumn(PROFILE_SUB_INDEX_FIELD, INTEGER_TYPE, false); vAddColumn(POSITION_FIELD, INTEGER_TYPE, false); vAddColumn(GRANT_ACCESS_FIELD, BOOLEAN_TYPE, false); } public ec dRemoveAllMembers(SIndex oOrganisationIndex) { ec dRet = dDelete(sqlIsIndex(oOrganisationIndex)); if (dRet == ec.ST_SUCCEED) return ec.ST_ORGANISATION_DELETE_MEMBER_PROBLEM; return ec.ST_SUCCEED; } public const string GRANT_ACCESS_FIELD = "HasGrantAccess"; public ec dAdd(SIndex oOrganisationIndex, SIndex oProfileIndex, P dPosition) { EPAssert(oOrganisationIndex.dSubIndex >= 0, "Organisation subindex should be more than one"); vAddValue(oOrganisationIndex.dIndex); vAddValue(oOrganisationIndex.dSubIndex); vAddValue(oProfileIndex.dIndex); vAddValue(oProfileIndex.dSubIndex); vAddValue((int)dPosition); vAddValue(false); return base.dInsertIntoTable() == ec.ST_SUCCEED ? ec.ST_SUCCEED : ec.ST_ORGANISATION_CREATION_MEMBER_FAILED; } public SIndex dGetCreator(SIndex oOrganisationIndex) { SIndex[] oProfileIndexArray; CTrace.i().vWriteLn(ENMessage.Organisation,csDumpTable()); if (dGetMember(oOrganisationIndex, P.ADMINISTRATOR_ORGANISATION, out oProfileIndexArray) != ec.ST_SUCCEED || oProfileIndexArray.Length <= 0) { EPAssert(false, "Can not return any profile index"); return NOT_USED_SINDEX; } return oProfileIndexArray[0]; } public string sqlIsIndex(SIndex oOrganisationIndex) { return sFieldEqual(ORGANISATION_INDEX_FIELD, oOrganisationIndex.dIndex) + AND + sFieldEqual(ORGANISATION_SUB_INDEX_FIELD, oOrganisationIndex.dSubIndex); } public string sqlIsIndex(SIndex oOrganisationIndex, int dProfileIndex) { return sqlIsIndex(oOrganisationIndex) + AND + sFieldEqual(PROFILE_INDEX_FIELD, dProfileIndex); } public bool bGetMember(SIndex oOrganisationIndex, SIndex oProfileIndex, out int dRegisterAvatarSubIndex, out int dPosition, out bool bIsGranted) { return bGetSelect(PROFILE_SUB_INDEX_FIELD, POSITION_FIELD, GRANT_ACCESS_FIELD, sqlIsIndex(oOrganisationIndex, oProfileIndex.dIndex), out dRegisterAvatarSubIndex, out dPosition, out bIsGranted); } public ec dGetMember(SIndex oOrganisationIndex, P dPositionType, out SIndex[] oProfileIndexArray) { ArrayList oOutputArray; ec dRC = dGetSelect(sqlIsIndex(oOrganisationIndex) + AND + sFieldEqual(POSITION_FIELD, dPositionType), out oOutputArray, PROFILE_INDEX_FIELD, PROFILE_SUB_INDEX_FIELD); oProfileIndexArray = new SIndex[oOutputArray.Count]; for (int i = 0; i < oOutputArray.Count; i++) { oProfileIndexArray[i].dIndex = (int)((object[])oOutputArray[i])[0]; oProfileIndexArray[i].dSubIndex = (int)((object[])oOutputArray[i])[1]; } return dRC == ec.ST_SUCCEED ? ec.ST_SUCCEED : ec.ST_ORGANISATION_MEMBER_EXTRACTION_FAILED; ; } public ec dGetMember(SIndex oOrganisationIndex, out SIndex[] oProfileIndexArray, out P[] dPositionArray, out bool[] bGrantAccessArray) { ArrayList oOutputArray; ec dRC = dGetSelect(sqlIsIndex(oOrganisationIndex), out oOutputArray, PROFILE_INDEX_FIELD, PROFILE_SUB_INDEX_FIELD, POSITION_FIELD, GRANT_ACCESS_FIELD); oProfileIndexArray = new SIndex[oOutputArray.Count]; dPositionArray = new P[oOutputArray.Count]; bGrantAccessArray = new bool[oOutputArray.Count]; for (int i = 0; i < oOutputArray.Count; i++) { oProfileIndexArray[i].dIndex = (int)((object[])oOutputArray[i])[0]; oProfileIndexArray[i].dSubIndex = (int)((object[])oOutputArray[i])[1]; dPositionArray[i] = (P)((object[])oOutputArray[i])[2]; bGrantAccessArray[i] = (bool)((object[])oOutputArray[i])[3]; } return dRC == ec.ST_SUCCEED ? ec.ST_SUCCEED : ec.ST_ORGANISATION_MEMBER_EXTRACTION_FAILED; } public int dCountRegisteredMember(SIndex oOrganisationIndex) { int dCount; dGetRecordCount(sqlIsIndex(oOrganisationIndex) + AND + sFieldEqual(GRANT_ACCESS_FIELD, true), out dCount); return dCount; } public ec dSetAccess(SIndex oOrganisationIndex, SIndex oProfileIndex, bool bIsNewGranted) { int dProfileSubIndex, dPosition; bool bIsGranted; bool bRet = bGetMember(oOrganisationIndex, oProfileIndex, out dProfileSubIndex, out dPosition, out bIsGranted); if (bRet == false) { return ec.ST_ORGANISATION_CAN_NOT_FIND_PROFILE; } if (bIsNewGranted && bIsGranted) { return ec.ST_ORGANISATION_MEMBER_ALREADY_GRANT; } return dUpdate(GRANT_ACCESS_FIELD, bIsNewGranted.ToString(), sqlIsIndex(oOrganisationIndex, oProfileIndex.dIndex)) == ec.ST_SUCCEED ? ec.ST_SUCCEED : ec.ST_ORGANISATION_MEMBER_UPDATE_FAILED; } } ///--------------------------------------------------------------------------------------------------------------------------------------------------- /// /// Summary description for Class1. /// ///--------------------------------------------------------------------------------------------------------------------------------------------------- public class CRankVoting : CVoting { public CRankVoting(SVoteRight[] oVoteRight) : base( oVoteRight) { //m_oVoteRight = oVoteRight; m_oRankVotingList = new SortedList(); m_oMemeIndexList = new SortedList(); } SortedList m_oRankVotingList, m_oMemeIndexList; public void vAdd(int dProfileIndex, SMemeCompare[] oMemeCompare) { if (oMemeCompare != null) { CProfileRankVoting oProfileRankVoting = new CProfileRankVoting(dProfileIndex); for (int j = 0; j < oMemeCompare.Length; j++) { if (oMemeCompare[j].dProfileIndexIndex == dProfileIndex) { if (m_oMemeIndexList.Contains(oMemeCompare[j].dMemeIndex) == false) { m_oMemeIndexList.Add(oMemeCompare[j].dMemeIndex, null); } if (m_oMemeIndexList.Contains(oMemeCompare[j].dMemeReferenceIndex) == false) { m_oMemeIndexList.Add(oMemeCompare[j].dMemeReferenceIndex, null); } oProfileRankVoting.vAdd(oMemeCompare[j], oMemeCompare[j].dExecutionFeature); } } m_oRankVotingList.Add(dProfileIndex, oProfileRankVoting); } } public void vAdd(SMemeCompare[] oMemeCompareArray) { for (int i = 0; i < m_oVoteRight.Length; i++) { vAdd(m_oVoteRight[i].dProfileIndex, oMemeCompareArray); } } public struct SBottomCount { public int dMemeIndex; // public int dMainIndex; public int dCount; /* public SIndex iMemeIndex { get { if (CDbEPBase.IsUsed(dMainIndex)) { return new SIndex(dMainIndex, dMemeIndex); } else { return new SIndex(dMemeIndex, CDbEPBase.NOT_USED); } } }*/ } public struct SMemeRank { public SMemeRank(SBottomCount _oMeme) { oMeme = _oMeme; dExecutiveRestriction = ENExecution.Independant; dMemeWinnerIndex = -999; } public SBottomCount oMeme; public ENExecution dExecutiveRestriction; public int dMemeWinnerIndex; } public void vRemove(ref SortedList oRankVotingList, int dMemeIndex) { for (int i = 0; i < oRankVotingList.Count; i++) { ((CProfileRankVoting)oRankVotingList.GetByIndex(i)).vRemove(dMemeIndex); } } public void vVoteSelection(SBottomCount[] oIndexMemeRankList, out SMemeRank[] oMemeRankList, ref CTraceReport oTraceReport) { if (oIndexMemeRankList.Length == 0) { CTrace.i().vWriteLn(ENMessage.Organisation,"oIndexMemeRankList empty"); oMemeRankList = null; } else { SortedList oRankVotingList = m_oRankVotingList; oMemeRankList = new SMemeRank[oRankVotingList.Count]; oMemeRankList[0].oMeme = oIndexMemeRankList[oIndexMemeRankList.Length - 1]; oMemeRankList[0].dExecutiveRestriction = ENExecution.Independant; oMemeRankList[0].dMemeWinnerIndex = NOT_USED; int dMemeRankListCount = 1; for (int i = oIndexMemeRankList.Length - 2; i >= 0; i--) { SMemeRank oMemeToEvaluatuate = new SMemeRank(oMemeRankList[oIndexMemeRankList.Length - i].oMeme); oMemeToEvaluatuate.dExecutiveRestriction = ENExecution.Independant; CListReport oSummaryReport = new CListReport(5); oSummaryReport.Active = oTraceReport.Active; oSummaryReport.vSetTitle("Exclusion Meme Rank =" + oIndexMemeRankList.Length); oSummaryReport.vSetHeader("Bottom_Meme", "Compare_Meme", "Vote", "Count", "Exclusion"); int dIndexRank=0, dCount=0; for (int j = 0; j < dMemeRankListCount; j++) { CListReport oDetailProfileReport = new CListReport(4); oDetailProfileReport.Active = oTraceReport.Active; oDetailProfileReport.vSetTitle("Exclusion Meme Rank =" + oIndexMemeRankList.Length); oDetailProfileReport.vSetHeader("Bottom_Meme", "Compare_Meme", "Profile", "Vote"); dCount = dIndexRank = 0; oMemeToEvaluatuate.dMemeWinnerIndex = oMemeRankList[j].oMeme.dMemeIndex; foreach(DictionaryEntry oMemeRankEntry in m_oRankVotingList) { int dProfileIndex= (int)oMemeRankEntry.Key; dCount++; CProfileRankVoting oProfileGradeVoting = (CProfileRankVoting)oMemeRankEntry.Value; ENExecution dExecutiveRestriction = oProfileGradeVoting.dGetExecutionFeatureIndex(oMemeRankList[j].oMeme.dMemeIndex, oMemeToEvaluatuate.oMeme.dMemeIndex); if (dExecutiveRestriction == ENExecution.Exclusive) { dIndexRank += 2; } else if (dExecutiveRestriction == ENExecution.DoneOnlyIfOtherDone) { dIndexRank += 1; } else { dExecutiveRestriction = oProfileGradeVoting.dGetExecutionFeatureIndex(oMemeToEvaluatuate.oMeme.dMemeIndex, oMemeRankList[j].oMeme.dMemeIndex); if (dExecutiveRestriction == ENExecution.Exclusive) { dIndexRank += 2; } } oDetailProfileReport.vAdd(oMemeToEvaluatuate.oMeme.dMemeIndex, oMemeRankList[j].oMeme.dMemeIndex, dProfileIndex, dIndexRank); } int dRankVote = CFeatureTypeFactory.Instance().oGet(P.EXECUTIVE_FEATURE).dGetRoundOnIndex((double)dIndexRank / dCount); if (dRankVote > 0) { if (dRankVote == 0) { oMemeToEvaluatuate.dExecutiveRestriction = ENExecution.Independant; } else if (dRankVote == 1) { oMemeToEvaluatuate.dExecutiveRestriction = ENExecution.DoneOnlyIfOtherDone; } else { oMemeToEvaluatuate.dExecutiveRestriction = ENExecution.Exclusive; } oMemeToEvaluatuate.dMemeWinnerIndex = oMemeRankList[j].oMeme.dMemeIndex; oTraceReport.vAdd(oDetailProfileReport); break; } } oMemeRankList[oIndexMemeRankList.Length - i] = oMemeToEvaluatuate; oSummaryReport.vAdd(oMemeToEvaluatuate.oMeme.dMemeIndex, oMemeToEvaluatuate.dMemeWinnerIndex, dCount>0 ? (double)dIndexRank / dCount: -999, dCount,oMemeToEvaluatuate.dExecutiveRestriction.ToString()); oTraceReport.vAdd(oSummaryReport); } } } //dGetExecutionRelation(int[] dMemeArray, int dMemeIndex) public void vVote(out SBottomCount[] oIndexMemeRankList, ref CTraceReport oTraceReport) { SortedList oRankVotingList = m_oRankVotingList; oIndexMemeRankList = new SBottomCount[m_oMemeIndexList.Count]; int dMemeRankIndex = 0; while (m_oMemeIndexList.Count > 0) { SBottomCount[] oMemeCountArray = new SBottomCount[m_oMemeIndexList.Count]; CListReport oDetailProfileReport = new CListReport(3); oDetailProfileReport.Active = oTraceReport.Active; oDetailProfileReport.vSetTitle("Bottom popularity detail report meme total=" + oRankVotingList.Count); oDetailProfileReport.vSetHeader("Bottom_Meme", "Profile", "Vote_right"); CListReport oDetailReport = new CListReport(2); oDetailReport.Active = oTraceReport.Active; oDetailReport.vSetTitle("Bottom popularity detail report meme total=" + oRankVotingList.Count); oDetailReport.vSetHeader("Meme", "Bottom_count"); for (int i = 0; i < m_oMemeIndexList.Count; i++) { oMemeCountArray[i].dMemeIndex = (int)m_oMemeIndexList.GetKey(i); oMemeCountArray[i].dCount = 0; foreach (DictionaryEntry oRankVotingEntry in oRankVotingList) { CProfileRankVoting oProfileGradeVoting = (CProfileRankVoting)oRankVotingEntry.Value; int dProfileIndex = (int)oRankVotingEntry.Key; if (oProfileGradeVoting.bIsAtPopularityBottom(oMemeCountArray[i].dMemeIndex)) { oMemeCountArray[i].dCount += dGetVoteRight(dProfileIndex); oDetailProfileReport.vAdd(CReport.MEME + oMemeCountArray[i].dMemeIndex, CReport.MEMBER + dProfileIndex, dGetVoteRight(dProfileIndex)); } } oDetailReport.vAdd(CReport.MEME + oMemeCountArray[i].dMemeIndex, oMemeCountArray[i].dCount); } oTraceReport.vAdd(oDetailProfileReport); oTraceReport.vAdd(oDetailReport); if (oMemeCountArray.Length >= 1) { SBottomCount oBottomCountMax = oMemeCountArray[0]; for (int j = 1; j < oMemeCountArray.Length; j++) { if (oBottomCountMax.dCount < oMemeCountArray[j].dCount) { oBottomCountMax = oMemeCountArray[j]; } } oIndexMemeRankList[dMemeRankIndex] = oBottomCountMax; oTraceReport.vAddLine(dMemeRankIndex + ":Remove meme " + CReport.MEME + oBottomCountMax.dMemeIndex + " Count=" + oBottomCountMax.dCount); dMemeRankIndex++; vRemove(ref oRankVotingList, oBottomCountMax.dMemeIndex); m_oMemeIndexList.Remove(oBottomCountMax.dMemeIndex); } } } } ///--------------------------------------------------------------------------------------------------------------------------------------------------- /// /// Summary description for Class1. /// ///--------------------------------------------------------------------------------------------------------------------------------------------------- public class CProfileRankVoting : CProfileVoting { public CProfileRankVoting(int dVoteRight) : base(dVoteRight) { m_oMemeList = new SortedList(); } SortedList m_oMemeList; public class CMemeLink { public CMemeLink(int _dLessPopularIndex, ENExecution _dExecutionFeatureIndex) { m_oMostPopularMeme = new ArrayList(); m_dLessPopularIndex = _dLessPopularIndex; m_dExecutionFeatureIndex = _dExecutionFeatureIndex; } public void vAdd(int dMemeSupIndex) { m_oMostPopularMeme.Add(dMemeSupIndex); } public int m_dLessPopularIndex; public ENExecution m_dExecutionFeatureIndex; public ArrayList m_oMostPopularMeme; } public void vAdd(SMemeCompare oMemeCompare, ENExecution _dExecutionFeatureIndex) { m_oMemeList.Add(oMemeCompare.dMemeIndex, new CMemeLink(oMemeCompare.dMemeReferenceIndex, _dExecutionFeatureIndex)); CMemeLink oMemeLink = (CMemeLink)m_oMemeList[oMemeCompare.dMemeReferenceIndex]; if (oMemeLink != null) { oMemeLink.vAdd(oMemeCompare.dMemeIndex); m_oMemeList.RemoveAt(oMemeCompare.dMemeReferenceIndex); m_oMemeList.Add(oMemeCompare.dMemeReferenceIndex, oMemeLink); } } public bool bIsAtPopularityBottom(int dMemeIndex) { return m_oMemeList[dMemeIndex] == null; } public void vRemove(int dMemeIndex) { CMemeLink oMemeLink = (CMemeLink)m_oMemeList[dMemeIndex]; if (oMemeLink != null) { for (int i = 0; i < oMemeLink.m_oMostPopularMeme.Count; i++) { int dMostPopularMemeIndex= (int)oMemeLink.m_oMostPopularMeme[i]; CMemeLink oMemeSupLink = ((CMemeLink)m_oMemeList[dMostPopularMemeIndex]); if (oMemeSupLink != null) { oMemeSupLink.m_dLessPopularIndex = oMemeLink.m_dLessPopularIndex; m_oMemeList.RemoveAt(dMostPopularMemeIndex); m_oMemeList.Add(dMostPopularMemeIndex, oMemeSupLink); } } } } public ENExecution dGetExecutionFeatureIndex(int dMemeIndex1, int dMemeIndex2) { int _dMemeIndex1 = dMemeIndex1; while (true) { CMemeLink oMeme1 = ((CMemeLink)m_oMemeList[_dMemeIndex1]); if (oMeme1 == null) { return ENExecution.Independant; } if (dMemeIndex2 == oMeme1.m_dLessPopularIndex) { return oMeme1.m_dExecutionFeatureIndex; } else { _dMemeIndex1 = oMeme1.m_dLessPopularIndex; } } } } ///--------------------------------------------------------------------------------------------------------------------------------------------------- /// /// Summary description for Class1. /// ///--------------------------------------------------------------------------------------------------------------------------------------------------- public class CVoting : CVoteBase { public CVoting( SVoteRight[] oVoteRight) { m_oVoteRight = oVoteRight; } protected SVoteRight[] m_oVoteRight; public int dGetVoteRight(int dProfileIndex) { return dGetVoteRight(m_oVoteRight, dProfileIndex); } } ///--------------------------------------------------------------------------------------------------------------------------------------------------- public abstract class CGradeVoting : CVoting { public CGradeVoting( SVoteRight[] oVoteRight) : base( oVoteRight) { m_oGradeVotingList = new SortedList(); m_oMemeIndexList = new SortedList(); } protected void vAdd(int dProfileIndex, SVoteGrade[] oVoteGradeArray) { CProfileGradeVoting oProfileGradeVoting = new CProfileGradeVoting(dGetVoteRight(dProfileIndex)); for (int j = 0; j < oVoteGradeArray.Length; j++) { if (oVoteGradeArray[j].dProfileIndexIndex == dProfileIndex) { m_oMemeIndexList.Add(oVoteGradeArray[j].dMemeIndex, null); oProfileGradeVoting.vAdd(new CProfileGradeVoting.SGrade(oVoteGradeArray[j].dMemeIndex, oVoteGradeArray[j].dGrade)); } } m_oGradeVotingList.Add(dProfileIndex, oProfileGradeVoting); } protected SortedList m_oGradeVotingList, m_oMemeIndexList; public abstract void vVote(out SVoteGradeResult[] oVoteGradeResultArray, ref CTraceReport oTraceReport); public void vAdd(SVoteGrade[] oVoteGradeArray) { for (int i = 0; i < m_oVoteRight.Length; i++) { vAdd(m_oVoteRight[i].dProfileIndex, oVoteGradeArray); } } public int dBallotCount { get { int dBallotCount = 0; foreach (DictionaryEntry oGradeVotingEntry in m_oGradeVotingList) { CProfileGradeVoting oProfileGradeVoting = (CProfileGradeVoting)oGradeVotingEntry.Value; dBallotCount += oProfileGradeVoting.dVoteRight; } return dBallotCount; } } } ///--------------------------------------------------------------------------------------------------------------------------------------------------- public class CGradeAverageVoting : CGradeVoting { public CGradeAverageVoting(ENPonderation enPonderation, SVoteRight[] oVoteRight) : base( oVoteRight) { m_enPonderation = enPonderation; } ENPonderation m_enPonderation; public enum ENPonderation { Normal, Ponderate, Normalized } public override void vVote(out SVoteGradeResult[] oVoteGradeResultArray, ref CTraceReport oTraceReport) { oVoteGradeResultArray = new SVoteGradeResult[m_oMemeIndexList.Count]; CListReport oDetailReport = new CListReport(4); oDetailReport.Active = oTraceReport.Active; oDetailReport.vSetTitle("Detail vote by grade"); oDetailReport.vSetHeader("Meme", "Profile", "Vote right", "Grade"); int i = 0; foreach (DictionaryEntry oMemeIndexEntry in m_oMemeIndexList) { int dMemeIndex = (int)oMemeIndexEntry.Key; foreach (DictionaryEntry oGradeVotingEntry in m_oGradeVotingList) { int dProfileIndex = (int)oGradeVotingEntry.Key; CProfileGradeVoting oProfileGradeVoting = (CProfileGradeVoting)oGradeVotingEntry.Value; if (oProfileGradeVoting != null) { double dbGrade; if (m_enPonderation == ENPonderation.Ponderate) { dbGrade= oProfileGradeVoting.dbGetPonderation(dMemeIndex); } else if (m_enPonderation == ENPonderation.Normalized) { dbGrade= oProfileGradeVoting.dbGetNormalizedGrade(dMemeIndex); } else { dbGrade= oProfileGradeVoting.dbGetGrade(dMemeIndex); } if (IsUsed(dbGrade)) { oVoteGradeResultArray[i].dCount += oProfileGradeVoting.dVoteRight; oVoteGradeResultArray[i].dSumGrade += oProfileGradeVoting.dVoteRight * dbGrade; oDetailReport.vAdd(CReport.MEME + dMemeIndex, CReport.MEMBER + dProfileIndex, oProfileGradeVoting.dVoteRight, dbGrade); } } } i++; } oTraceReport.vAdd(oDetailReport); CListReport oVoteGradeReport = new CListReport(2); oVoteGradeReport.Active = oTraceReport.Active; oVoteGradeReport.vSetTitle("Result vote"); oVoteGradeReport.vSetHeader("Meme", "Average Grade"); for (int j = 0; j < oVoteGradeResultArray.Length; j++) { oVoteGradeReport.vAdd(CReport.MEME + oVoteGradeResultArray[j].dMemeIndex, oVoteGradeResultArray[j].dbAvg); } oTraceReport.vAdd(oVoteGradeReport); //SVoteGradeResult } } ///--------------------------------------------------------------------------------------------------------------------------------------------------- public class CGradeRankVoting : CGradeVoting { public CGradeRankVoting( SVoteRight[] oVoteRight) : base( oVoteRight) { } public override void vVote(out SVoteGradeResult[] oVoteGradeResultArray, ref CTraceReport oTraceReport) { oVoteGradeResultArray = new SVoteGradeResult[m_oMemeIndexList.Count]; CListReport oDetailReport = new CListReport(4); oDetailReport.Active = oTraceReport.Active; oDetailReport.vSetTitle("Detail vote by grade"); oDetailReport.vSetHeader("Meme", "Profile", "Vote right", "Grade"); int i = 0; foreach (DictionaryEntry oMemeEntry in m_oMemeIndexList) { int dMemeIndex = (int)oMemeEntry.Key; foreach (DictionaryEntry oGradeVotingEntry in m_oGradeVotingList) { int dProfileIndex = (int)oGradeVotingEntry.Key; CProfileGradeVoting oProfileGradeVoting = (CProfileGradeVoting)oGradeVotingEntry.Value; if (oProfileGradeVoting != null) { double dbRank = oProfileGradeVoting.dGetRank(dMemeIndex); if (dbRank == oProfileGradeVoting.dCount) { dbRank = (m_oMemeIndexList.Count - oProfileGradeVoting.dCount) / 2 + oProfileGradeVoting.dCount; } oVoteGradeResultArray[i].dCount += oProfileGradeVoting.dVoteRight; oVoteGradeResultArray[i].dSumGrade += oProfileGradeVoting.dVoteRight * dbRank / m_oMemeIndexList.Count; oDetailReport.vAdd(CReport.MEME + dMemeIndex, CReport.MEMBER + dProfileIndex, oProfileGradeVoting.dVoteRight, dbRank / m_oMemeIndexList.Count); } } i++; } oTraceReport.vAdd(oDetailReport); CListReport oVoteGradeReport = new CListReport(2); oVoteGradeReport.Active = oTraceReport.Active; oVoteGradeReport.vSetTitle("Result vote"); oVoteGradeReport.vSetHeader("Meme", "Average Grade"); for (int j = 0; j < oVoteGradeResultArray.Length; j++) { oVoteGradeReport.vAdd(CReport.MEME + oVoteGradeResultArray[j].dMemeIndex, oVoteGradeResultArray[j].dbAvg); } oTraceReport.vAdd(oVoteGradeReport); } } ///--------------------------------------------------------------------------------------------------------------------------------------------------- /// /// Summary description for Class1. /// ///--------------------------------------------------------------------------------------------------------------------------------------------------- public class CProfileVoting : CVoteBase { public CProfileVoting(int dVoteRight) { m_dVoteRight = dVoteRight; } int m_dVoteRight; public int dVoteRight { get { return m_dVoteRight; } } } ///--------------------------------------------------------------------------------------------------------------------------------------------------- public class CProfileGradeVoting : CProfileVoting { public CProfileGradeVoting(int dVoteRight) : base(dVoteRight) { m_oMemeList = new SortedList(); m_dSum = m_dSquareSum = 0; } public struct SGrade { public SGrade(int _dIndex, double _dbGrade) { dIndex = _dIndex; dbGrade = _dbGrade; dRank = NOT_USED; } public int dIndex; public double dbGrade; public int dRank; } public void vAdd(SGrade oGrade) { m_oMemeList.Add(oGrade.dIndex, oGrade); } SortedList m_oMemeList; //, m_oMemeGradeRankList; public int dProfileIndex; double m_dSum; double m_dSquareSum; public int dCount { get { return m_oMemeList.Count; } } public double dSum { get { if (m_dSum == 0) { for (int i = 0; i < m_oMemeList.Count; i++) { m_dSum += ((SGrade)m_oMemeList[i]).dbGrade; } } return m_dSum; } } public double dAvg { get { if (m_oMemeList.Count > 0) { return dSum / m_oMemeList.Count; } return NOT_USED; } } public double dStd { get { if (m_dSquareSum == 0) { foreach (SGrade oMemGrade in m_oMemeList) { double dEcard = oMemGrade.dbGrade - dAvg; m_dSquareSum += dEcard * dEcard; } } if (m_oMemeList.Count > 1) { return Math.Sqrt(m_dSquareSum / m_oMemeList.Count); } return NOT_USED; } } public double dbGetGrade(int dMemeIndex) { if (dMemeIndex >= 0 && dMemeIndex < m_oMemeList.Count) { return ((SGrade)m_oMemeList[dMemeIndex]).dbGrade; } return NOT_USED; } public double dbGetNormalizedGrade(int dMemeIndex) { double dbGrade = dbGetGrade(dMemeIndex); if (dbGrade == NOT_USED) { return NOT_USED; } return dbNormalizedGrade(dbGrade); } public int dGetRank(int dMemeIndex) { if (m_oMemeList.Count > 0 && IsNotUsed(((SGrade)m_oMemeList[dMemeIndex]).dRank)) { SortedList oMemeGradeRankList = new SortedList(); for (int i = 0; i < m_oMemeList.Count; i++) { oMemeGradeRankList.Add(((SGrade)m_oMemeList[i]).dbGrade, ((SGrade)m_oMemeList[i]).dIndex); } for (int i = 0; i < oMemeGradeRankList.Count; i++) { int dNewMemeIndex = (int)oMemeGradeRankList.GetByIndex(i); SGrade oGrade = ((SGrade)m_oMemeList[dNewMemeIndex]); oGrade.dRank = i; m_oMemeList[dNewMemeIndex] = oGrade; } } return m_oMemeList.Contains(dMemeIndex) ? ((SGrade)m_oMemeList[dMemeIndex]).dRank : m_oMemeList.Count; } public double dbNormalizedGrade(double dbGrade) { return Math.Sqrt((dbGrade - dAvg) * (dbGrade - dAvg)) / m_dSquareSum; } public double dbGetPonderation(int dMemeIndex) { double dbGrade = dbGetGrade(dMemeIndex); if (dbGrade == NOT_USED) { return NOT_USED; } return dbGrade/ dSum; } } ///--------------------------------------------------------------------------------------------------------------------------------------------------- /// /// Summary description for Class1. /// ///--------------------------------------------------------------------------------------------------------------------------------------------------- public class CVoteBase : CCommandFactoryBase { static public string ToString(SVoteRight[] oVoteRightArray) { if (oVoteRightArray.Length == 0) return null; StringBuilder sResult = new StringBuilder(oVoteRightArray[0].dProfileIndex.ToString()); for (int i = 1; i < oVoteRightArray.Length; i++) { sResult.Append(','); sResult.Append(oVoteRightArray[i].dProfileIndex.ToString()); } return sResult.ToString(); } public struct SVoteRight { public int dProfileIndex; public int dVoteCoefficient; } public struct SProfile { public int dIndex; public string sDisplayName; } static public ArrayList ToArrayList(SVoteRight[] oVoteRight) { ArrayList oVoteArray = new ArrayList(oVoteRight.Length); for (int i = 0; i < oVoteRight.Length; i++) { SProfile oProfile; oProfile.dIndex = oVoteRight[i].dProfileIndex; oProfile.sDisplayName = "Profile" + oVoteRight[i].dProfileIndex; oVoteArray.Add(oProfile); } return oVoteArray; } public static SVoteGrade[] ToVoteGrade(ArrayList oArray) { SVoteGrade[] oVoteGradeArray = new SVoteGrade[oArray.Count]; for (int i = 0; i < oArray.Count; i++) { object[] oObjArray = (object[])oArray[i]; oVoteGradeArray[i].dProfileIndexIndex = Convert.ToInt32(oObjArray[0]); oVoteGradeArray[i].dMemeIndex = Convert.ToInt32(oObjArray[1]); oVoteGradeArray[i].dGrade = Convert.ToInt32(oObjArray[2]); } return oVoteGradeArray; } public static SMemeCompare[] ToMemeCompareArray(int dMemeIndex, ArrayList oArrayList) { if (oArrayList == null || oArrayList.Count == 0) return null; SMemeCompare[] oMemeCompare = new SMemeCompare[oArrayList.Count]; for (int i = 0; i < oArrayList.Count; i++) { object[] oObjectArray = (object[])oArrayList[i]; oMemeCompare[i].vSet(dMemeIndex, oObjectArray); } return oMemeCompare; } public struct SVoteRegister { public SIndex oOrganisationIndex; public int dVoteIdentifier; public int dMemeIndex; public int dEntityIndex; public CIdentifier oIdentifier; public byte[] m_oVoteResultBinary; } public struct SMemeCompare { /* public SMemeCompare(int dMemeIndex, object[] oObjectArray) { vSet(dMemeIndex, oObjectArray); }*/ public void vSet(int dMemeIndex, object[] oObjectArray) { m_dMemeIndex = dMemeIndex; m_dProfileIndexIndex = Convert.ToInt32(oObjectArray[0]); m_dIndex = Convert.ToInt32(oObjectArray[1]); m_dReferenceIndex = Convert.ToInt32(oObjectArray[2]); P dComparator = (P)Convert.ToInt32(oObjectArray[3]); EPAssert(m_dMemeIndex != m_dReferenceIndex, "You can not compare a meme with himself"); switch (dComparator) { case P.EXCLUSIVE_EXECUTION: m_dExecutionFeature = ENExecution.Exclusive; break; case P.DEPENDANT_EXECUTION: m_dExecutionFeature = ENExecution.DoneOnlyIfOtherDone; break; case P.INDEPENDANT_EXECUTION: default: m_dExecutionFeature = ENExecution.Independant; break; } } int m_dMemeIndex; public int dMemeIndex { get { return m_dIndex; } } public int dMemeReferenceIndex { get { return m_dReferenceIndex; } } public SIndex iMemeIndex { get { if (IsUsed(m_dMemeIndex)) { return new SIndex(m_dMemeIndex, m_dIndex); } else { return new SIndex( m_dIndex, NOT_USED); } } } public SIndex iMemeReferenceIndex { get { if (IsUsed(m_dMemeIndex)) { return new SIndex(m_dMemeIndex, m_dReferenceIndex); } else { return new SIndex(m_dReferenceIndex, NOT_USED); } } } public ENExecution dExecutionFeature { get { return m_dExecutionFeature; } } public int dProfileIndexIndex { get { return m_dProfileIndexIndex; } } private int m_dProfileIndexIndex; private int m_dIndex; private int m_dReferenceIndex; private ENExecution m_dExecutionFeature; } public struct SVoteGrade { public int dProfileIndexIndex; public int dMemeIndex; public int dGrade; } public struct SVoteGradeResult { public SVoteGradeResult(int _dMemeIndex) { dMemeIndex = _dMemeIndex; dSumGrade = dCount = 0; } public int dMemeIndex; public double dSumGrade; public int dCount; public double dbAvg { get { return dSumGrade / dCount; } } } static SVoteGradeResult NOT_USED_VOTE_GRADE_RESULT = new SVoteGradeResult(NOT_USED); static public SVoteGradeResult dGetWinner(SVoteGradeResult[] oVoteGradeResultArray) { if (oVoteGradeResultArray.Length == 0) return NOT_USED_VOTE_GRADE_RESULT; SVoteGradeResult oSVoteGradeResult = oVoteGradeResultArray[0]; for (int i = 0; i < oVoteGradeResultArray.Length; i++) { if (oVoteGradeResultArray[i].dbAvg > oSVoteGradeResult.dbAvg) { oSVoteGradeResult = oVoteGradeResultArray[i]; } } return oSVoteGradeResult; } static public int dGetVoteRight(SVoteRight[] oVoteRightArray, int dProfileIndex) { if (oVoteRightArray != null) { for (int i = 0; i < oVoteRightArray.Length; i++) { if (oVoteRightArray[i].dProfileIndex == dProfileIndex) { return oVoteRightArray[i].dVoteCoefficient; } } } return 0; } } ///--------------------------------------------------------------------------------------------------------------------------------------------------- /// /// Summary description for Class1. /// ///--------------------------------------------------------------------------------------------------------------------------------------------------- public class CVoteView : CDbJoinView { public CVoteView(string sViewName, string sDatabaseName) : base(new CDbTableView(RESULT_PREFIXE, new CVoteResultTable(sDatabaseName)), new CDbTableView(DETAIL_PREFIXE, new CDbSTable(DETAIL_PREFIXE + '_' + sViewName, sDatabaseName))) { VoteDetailTable.vAddColumn(ORGANISATION_INDEX_FIELD, INTEGER_TYPE, true); VoteDetailTable.vAddColumn(VOTE_UNIT_IDENTIFIER, INTEGER_TYPE, true); VoteDetailTable.vAddColumn(SUPPORT_FIELD, INTEGER_TYPE, false); vAddLinkIndex(RESULT_PREFIXE, ORGANISATION_INDEX_FIELD, DETAIL_PREFIXE, ORGANISATION_INDEX_FIELD); vAddLinkIndex(RESULT_PREFIXE, VOTE_UNIT_IDENTIFIER, DETAIL_PREFIXE, VOTE_UNIT_IDENTIFIER); } public CVoteResultTable VoteResultTable { get { return (CVoteResultTable)((CDbTableView)this.GetMasterView).oGetTable; } } public CDbSTable VoteDetailTable { get { return (CDbSTable)((CDbTableView)this.GetSlaveView).oGetTable; } } public string sqlIsIndex(SIndex oOrganisationIndex, int dVoteIdentifier) { return VoteResultTable.sqlIsOrganisation(oOrganisationIndex) + AND + VoteDetailTable.sFieldEqual(VOTE_UNIT_IDENTIFIER, dVoteIdentifier); } public ec dGetSelectBallot(SIndex oOrganisationIndex, int dVoteIdentifier, out ArrayList oBallotArray) { ec dRC = VoteDetailTable.dGetSelect(sqlIsIndex(oOrganisationIndex, dVoteIdentifier), out oBallotArray, PROFILE_INDEX_FIELD, CVoteResultTable.SUPPORT_FIELD); return dRC; } } ///--------------------------------------------------------------------------------------------------------------------------------------------------- public class CVoteBooleanView : CVoteView { public CVoteBooleanView(string sViewName, string sDatabaseName) : base(sViewName, sDatabaseName) { } public ec dVote(SIndex oOrganisationIndex, P dVoteIdentifier, CVoteBase.SVoteRight[] oVoteRight, TimeSpan oNextElectionSpan, SBallot[] oBallotArray, out SBallotResult oBallotResult, ref CTraceReport oTraceReport) { bVoteCount(oVoteRight, oBallotArray, out oBallotResult, ref oTraceReport); ec dRC = VoteResultTable.dSetResult(oOrganisationIndex, dVoteIdentifier, oBallotResult.bWon ? 1 : 0, oNextElectionSpan, GetSerializedValue(oBallotResult)); return dRC; } static public bool bVoteCount(CVoteBase.SVoteRight[] oVoteRight, SBallot[] oBallotArray, out SBallotResult oBallotResult, ref CTraceReport oTraceReport) { oBallotResult.dVoteInFavor = oBallotResult.dVoteAgainst = 0; CListReport oDetailReport = new CListReport(4); oDetailReport.Active = oTraceReport.Active; oDetailReport.vSetTitle("Detail vote by grade"); oDetailReport.vSetHeader("Profile", "Vote Right"); for (int i = 0; i < oBallotArray.Length; i++) { int dVotingRight = CVoteBase.dGetVoteRight(oVoteRight, oBallotArray[i].dProfileIndexIndex); if (oBallotArray[i].bVote) { oBallotResult.dVoteInFavor += dVotingRight; } else { oBallotResult.dVoteAgainst += dVotingRight; } oDetailReport.vAdd(CReport.MEMBER + oBallotArray[i].dProfileIndexIndex, oBallotArray[i].bVote ? dVotingRight : -dVotingRight); } oTraceReport.vAdd(oDetailReport); return oBallotResult.bWon; } public struct SBallot { public int dProfileIndexIndex; public bool bVote; } public struct SBallotResult { public int dVoteInFavor; public int dVoteAgainst; public bool bWon { get { return dVoteInFavor > dVoteAgainst; } } } public ec dGetSelectBallot(SIndex oOrganisationIndex, int dVoteIdentifier, out SBallot[] oBallotArray) { ArrayList oArrayList; ec dRC = base.dGetSelectBallot(oOrganisationIndex, dVoteIdentifier, out oArrayList); oBallotArray = new SBallot[oArrayList.Count]; if (dRC != ec.ST_SUCCEED) { for (int i = 0; i < oArrayList.Count; i++) { object[] oVote = (object[])oArrayList[i]; oBallotArray[i].dProfileIndexIndex = Convert.ToInt32(oVote[0]); oBallotArray[i].bVote = Convert.ToBoolean(oVote[1]); } } return dRC; } } ///--------------------------------------------------------------------------------------------------------------------------------------------------- public class CVoteFeatureView : CVoteView { public CVoteFeatureView( string sViewName, string sDatabaseName) : base(sViewName, sDatabaseName) { } public ec dVote(SIndex oOrganisationIndex, P dVoteIdentifier, CVoteBase.SVoteRight[] oVoteRight, TimeSpan oNextElectionSpan, CVoteBase.SVoteGrade[] oBallotArray, out CVoteBase.SVoteGradeResult oBallotResult, ref CTraceReport oTraceReport) { CGradeRankVoting oGradeRankVoting = new CGradeRankVoting( oVoteRight); oGradeRankVoting.vAdd(oBallotArray); CVoteBase.SVoteGradeResult[] oBallotResultArray; oGradeRankVoting.vVote(out oBallotResultArray, ref oTraceReport); EPAssert(oBallotResultArray.Length == 1, " Should have only one result"); oBallotResult = oBallotResultArray[0]; ec dRC = VoteResultTable.dSetResult(oOrganisationIndex, dVoteIdentifier, CCommandFactoryBase.CFeatureTypeFactory.Instance().oGet(dVoteIdentifier).dGetRoundOnIndex(oBallotResult.dbAvg), oNextElectionSpan, GetSerializedValue(oBallotResult)); return dRC; } public ec dGetSelectBallot(SIndex oOrganisationIndex, int dVoteIdentifier, out CVoteBase.SVoteGrade[] oBallotArray) { ArrayList oArrayList; base.bAddDisplayColumn(MEMBER_PREFIXE, PROFILE_INDEX_FIELD); base.bAddDisplayColumn(SUPPORT_FIELD, SUPPORT_FIELD); ec dRC = base.dGetSelect(sqlIsIndex(oOrganisationIndex, dVoteIdentifier), out oArrayList); oBallotArray = new CVoteBase.SVoteGrade[oArrayList.Count]; if (dRC != ec.ST_SUCCEED) { for (int i = 0; i < oArrayList.Count; i++) { object[] oVote = (object[])oArrayList[i]; oBallotArray[i].dProfileIndexIndex = Convert.ToInt32(oVote[0]); oBallotArray[i].dGrade = Convert.ToInt32(oVote[1]); oBallotArray[i].dMemeIndex = dVoteIdentifier; } } return dRC; } } ///--------------------------------------------------------------------------------------------------------------------------------------------------- /// /// Summary description for Class1. /// ///--------------------------------------------------------------------------------------------------------------------------------------------------- public class CVoteResultTable : CDbSTable { public CVoteResultTable(string sDatabaseName) : base(RESULT_TABLE_NAME, sDatabaseName) { vAddColumn(ORGANISATION_INDEX_FIELD, INTEGER_TYPE, true); vAddColumn(ORGANISATION_SUB_INDEX_FIELD, INTEGER_TYPE, true); vAddColumn(VOTE_UNIT_IDENTIFIER, INTEGER_TYPE, true); vAddColumn(RESULT_FIELD, INTEGER_TYPE, false); vAddColumn(LAST_VOTE_DATE_FIELD, DATE_TYPE, false); vAddColumn(NEXT_VOTE_DATE_FIELD, DATE_TYPE, false); vAddColumn(LAST_VOTE_CHANGE_DATE_FIELD, DATE_TYPE, false); vAddColumn(LAST_VOTE_RESULT_FIELD, BINARY_TYPE, false); } public bool bIsDayToDoElection(SIndex oOrganisationIndex, P dVoteIdentifier) { return bIsDayToDoElection(sqlIsIndex(oOrganisationIndex, dVoteIdentifier)); } public ec dSelectPendingVote(SIndex oOrganisationIndex, TimeSpan oNextElectionSpan, out int[] dVoteUnitArray) { ArrayList oResultArray; ec dRC = base.dGetSelect(sFieldCompare(ENSQLRelation.infeq, NEXT_VOTE_DATE_FIELD, DateTime.Now.ToString()) + AND + sqlIsOrganisation(oOrganisationIndex), out oResultArray, VOTE_UNIT_IDENTIFIER); dVoteUnitArray = ToIntegerArray(oResultArray); return dRC; } public bool bIsDayToDoElection(string sIndexWhere) { ArrayList oOutputArray; ec dRC = dGetSelect(sIndexWhere, out oOutputArray, LAST_VOTE_DATE_FIELD, NEXT_VOTE_DATE_FIELD, LAST_VOTE_CHANGE_DATE_FIELD); if (oOutputArray.Count == 0) { return false; } object[] oObjs = (object[])oOutputArray[0]; DateTime oLastVoteDate = Convert.ToDateTime(oObjs[0]); DateTime oNextVoteDate = Convert.ToDateTime(oObjs[1]); DateTime oLastVoteChangeDate = Convert.ToDateTime(oObjs[2]); return IsUsed(oLastVoteChangeDate) && oLastVoteChangeDate > oLastVoteDate && oNextVoteDate < DateTime.UtcNow; } public ec dSetResult(SIndex oOrganisationIndex, P dVoteIdentifier, int dResult, TimeSpan oNextElectionSpan, byte[] byteElectionResult) { ec dRC = dSetElectionDate(oOrganisationIndex, dVoteIdentifier, dResult, oNextElectionSpan, byteElectionResult); if (dRC != ec.ST_SUCCEED) { dRC = dAddElection(oOrganisationIndex, dVoteIdentifier, dResult, oNextElectionSpan, byteElectionResult); } return dRC; } public string sqlIsIndex(SIndex oOrganisationIndex, P dVoteIdentifier) { return sqlIsOrganisation(oOrganisationIndex) + AND + sFieldEqual(VOTE_UNIT_IDENTIFIER, dVoteIdentifier); } public ec dSetElectionDate(SIndex oOrganisationIndex, P dVoteIdentifier, int dResult, TimeSpan oNextElectionInterval, byte[] oElectionResult) { return dSetElectionDate(sqlIsIndex(oOrganisationIndex, dVoteIdentifier), dResult, oNextElectionInterval, oElectionResult); } public ec dSetElectionDate(string sVoteKey, int dResult, TimeSpan oNextElectionInterval, byte[] oElectionResult) { DateTime oNextElectionDate = DateTime.UtcNow + oNextElectionInterval; ec dRC = this.dUpdate(LAST_VOTE_DATE_FIELD, NEXT_VOTE_DATE_FIELD, RESULT_FIELD, DateTime.UtcNow.ToShortDateString(), oNextElectionDate.ToShortDateString(), dResult.ToString(), sVoteKey); dRC = this.dUpdateBinary(LAST_VOTE_RESULT_FIELD, oElectionResult); return dRC; } public ec dRefresh(SIndex oOrganisationIndex, P dVoteIdentifier) { return this.dUpdate(LAST_VOTE_CHANGE_DATE_FIELD, DateTime.UtcNow.ToString(), sqlIsIndex(oOrganisationIndex, dVoteIdentifier)); } public ec dAddElection(SIndex oOrganisationIndex, P dVoteIdentifier, int dResult, TimeSpan oNextElectionInterval, byte[] oElectionResult) { base.vAddValue(oOrganisationIndex); base.vAddValue(dVoteIdentifier); base.vAddValue(dResult); base.vAddValue(DateTime.UtcNow); base.vAddValue(DateTime.UtcNow + oNextElectionInterval); base.vAddValue(NOT_USED_DATE); base.vAddValue(oElectionResult); return base.dInsertIntoTable(); } } ///--------------------------------------------------------------------------------------------------------------------------------------------------- /* public class CVoteSubMemeResultTable : CVoteResultTable { public CVoteSubMemeResultTable(string sDatabaseName) : base(ENBallotType.Meme, "SubMemeResultTable", sDatabaseName) { } protected override void vAddColumnKey() { vAddColumn(MEME_INDEX_FIELD, INTEGER_TYPE, true); } public int dAddElection(SIndex oOrganisationIndex, int dVoteIdentifier, SIndex oMemeIndex, TimeSpan oNextElectionInterval, byte[] oElectionResult) { base.vAddValue(oMemeIndex.dIndex); return base.dAddElection(oOrganisationIndex, dVoteIdentifier, oMemeIndex.dSubIndex, oNextElectionInterval, ElectionResult); } public string sqlIsIndex(SIndex oOrganisationIndex, int dVoteIdentifier, int dMemeIndex) { return sqlIsOrganisation(oOrganisationIndex) + AND + sFieldEqual(VOTE_UNIT_IDENTIFIER, dVoteIdentifier) + AND + sFieldEqual(MEME_INDEX_FIELD, dMemeIndex); } public int dSetElectionDate(SIndex oOrganisationIndex, int dVoteIdentifier, SIndex oMemeIndex, TimeSpan oNextElectionInterval, byte[] oElectionResult) { return dSetElectionDate(sqlIsIndex(oOrganisationIndex, dVoteIdentifier, oMemeIndex.dIndex), oMemeIndex.dSubIndex, oNextElectionInterval, oElectionResult); } public int dSetResult(SIndex oOrganisationIndex, int dVoteIdentifier, SIndex oMemeIndex, TimeSpan oNextElectionInterval, byte[] oElectionResult) { ec dRC = dSetElectionDate(oOrganisationIndex, dVoteIdentifier, oMemeIndex, oNextElectionSpan, byteElectionResult); if (dRC != ec.ST_SUCCEED) { dRC = dAddElection(oOrganisationIndex, dVoteIdentifier, oMemeIndex, oNextElectionSpan, byteElectionResult); } return dRC; } } */ ///--------------------------------------------------------------------------------------------------------------------------------------------------- public class CVoteSubMemeView : CDbJoinView { public CVoteSubMemeView(P dLanguage, string sDatabaseName) : base(new CMemberVoteView( sDatabaseName), new CDbTableView(DETAIL_PREFIXE, new CMemeSubAgreementTable(DETAIL_PREFIXE + "SubAgreementTable", sDatabaseName))) { m_dLanguage = dLanguage; vAddLinkIndex(MEMBER_PREFIXE, PROFILE_INDEX_FIELD, DETAIL_PREFIXE, PROFILE_INDEX_FIELD); vAddLinkIndex(RESULT_PREFIXE, VOTE_UNIT_IDENTIFIER, DETAIL_PREFIXE, MEME_INDEX_FIELD); } P m_dLanguage; public CMemberVoteView MemberVoteView { get { return (CMemberVoteView)this.GetMasterView; } } public CMemeSubAgreementTable VoteMemeSubAgreementTable { get { return (CMemeSubAgreementTable)((CDbTableView)this.GetSlaveView).oGetTable; } } public ec dGetSelectBallot(SIndex oOrganisationIndex, int dMemeIndex, out CVoteBase.SVoteGrade[] oBallotArray) { ArrayList oArrayList; base.bAddDisplayColumn(MEMBER_PREFIXE, PROFILE_INDEX_FIELD); base.bAddDisplayColumn(DETAIL_PREFIXE, MEME_SUB_INDEX_FIELD); base.bAddDisplayColumn(RESULT_PREFIXE, GRADE_FIELD); base.bAddWhereOrganisation(MEMBER_PREFIXE, oOrganisationIndex); base.bAddWhere(MEMBER_PREFIXE, MEME_INDEX_FIELD, dMemeIndex); ec dRC = base.dGetSelect(out oArrayList); oBallotArray = CVoteBase.ToVoteGrade(oArrayList); return dRC; } public ec dVote(SIndex oOrganisationIndex, P dVoteIdentifier, CVoteBase.SVoteRight[] oVoteRight, TimeSpan oNextElectionSpan, CVoteBase.SVoteGrade[] oBallotArray, out CVoteBase.SVoteGradeResult oBallotResult, ref CTraceReport oTraceReport) { CGradeRankVoting oGradeRankVoting = new CGradeRankVoting( oVoteRight); oGradeRankVoting.vAdd(oBallotArray); CVoteBase.SVoteGradeResult[] oBallotResultArray; oGradeRankVoting.vVote(out oBallotResultArray, ref oTraceReport); oBallotResult = CVoteBase.dGetWinner(oBallotResultArray); ec dRC = MemberVoteView.VoteResultTable.dSetResult(oOrganisationIndex, dVoteIdentifier, oBallotResult.dMemeIndex, oNextElectionSpan, GetSerializedValue(oBallotResult)); return dRC; } } ///--------------------------------------------------------------------------------------------------------------------------------------------------- /// /// Summary description for Class1. /// ///--------------------------------------------------------------------------------------------------------------------------------------------------- public class CMemberVoteView : CDbJoinView { public CMemberVoteView( string sDatabaseName) : base(new CDbTableView(RESULT_PREFIXE, new CVoteResultTable(sDatabaseName)), new COrganisationMemberView(sDatabaseName)) { vAddLinkIndex(RESULT_PREFIXE, ORGANISATION_INDEX_FIELD, COrganisationMemberView.ORGANISATION_PREFIXE, ORGANISATION_INDEX_FIELD); vAddLinkIndex(RESULT_PREFIXE, ORGANISATION_SUB_INDEX_FIELD, COrganisationMemberView.ORGANISATION_PREFIXE, ORGANISATION_SUB_INDEX_FIELD); //vAddLinkIndex(RESULT_PREFIXE, VOTE_UNIT_IDENTIFIER, DETAIL_PREFIXE, VOTE_UNIT_IDENTIFIER); } public CVoteResultTable VoteResultTable { get { return (CVoteResultTable)((CDbTableView)this.GetMasterView).oGetTable; } } public COrganisationMemberView OrganisationMemberView { get { return (COrganisationMemberView)this.GetSlaveView; } } public string sqlIsIndex(SIndex oOrganisationIndex, int dVoteIdentifier) { return VoteResultTable.sqlIsOrganisation(oOrganisationIndex) + AND + VoteResultTable.sFieldEqual(VOTE_UNIT_IDENTIFIER, dVoteIdentifier); } /* public int dGetSelectBallot(SIndex oOrganisationIndex, int dVoteIdentifier, out ArrayList oBallotArray) { ArrayList oArrayList; return VoteDetailTable.dGetSelect(sqlIsIndex( oOrganisationIndex, dVoteIdentifier), out oArrayList, PROFILE_INDEX_FIELD, SUPPORT_FIELD); }*/ } ///--------------------------------------------------------------------------------------------------------------------------------------------------- /// /// Summary description for Class1. /// ///--------------------------------------------------------------------------------------------------------------------------------------------------- public class CMemeSubAgreementTable : CGradeTable { public CMemeSubAgreementTable(string sTableName, string sDatabaseName) : base(sTableName, sDatabaseName) { vAddColumn(MEME_SUB_INDEX_FIELD, INTEGER_TYPE, true); } public ec dSelect(SIndex oProfileIndex, int dMemeIndex, out CVoteBase.SVoteGrade[] oVoteGradeArray) { ArrayList oOutputArray; ec dRC = base.dGetSelect(sqlIsIndex(oProfileIndex, dMemeIndex), out oOutputArray, PROFILE_INDEX_FIELD, MEME_SUB_INDEX_FIELD, GRADE_FIELD); oVoteGradeArray = CVoteBase.ToVoteGrade(oOutputArray); return dRC; } } ///--------------------------------------------------------------------------------------------------------------------------------------------------- public class CGradeTable : CDbSTable { public CGradeTable(string sTableName, string sDatabaseName) : base(sTableName, sDatabaseName) { vAddColumn(PROFILE_INDEX_FIELD, INTEGER_TYPE, true); vAddColumn(MEME_INDEX_FIELD, INTEGER_TYPE, true); vAddColumn(GRADE_FIELD, INTEGER_TYPE, false); } public string sqlIsIndex(SIndex oProfileIndex, int dMemeIndex) { return sFieldEqual(PROFILE_INDEX_FIELD, oProfileIndex.dIndex) + AND + sFieldEqual(MEME_INDEX_FIELD, dMemeIndex); } public ec dSelect(int dProfileIndex, SIndex[] oMemeList, out CVoteBase.SVoteGrade[] oVoteGradeArray) { string sWhere = sFieldEqual(PROFILE_INDEX_FIELD, dProfileIndex) + AND + MEME_INDEX_FIELD + "in(" + ToString(ToIndex(oMemeList)) + ") "; ArrayList oOutputArray; ec dRC = base.dGetSelect(sWhere, out oOutputArray, PROFILE_INDEX_FIELD, MEME_INDEX_FIELD, GRADE_FIELD); oVoteGradeArray = CVoteBase.ToVoteGrade(oOutputArray); return dRC; } } ///--------------------------------------------------------------------------------------------------------------------------------------------------- /// /// Summary description for Class1. /// ///--------------------------------------------------------------------------------------------------------------------------------------------------- public class CComparisonAgreementTable: CDbSTable { public CComparisonAgreementTable(string sTableName, string sDatabaseName) : base(sTableName, sDatabaseName) { vAddColumn(PROFILE_INDEX_FIELD, INTEGER_TYPE, true); vAddColumn(FIRST_INDEX_FIELD, INTEGER_TYPE, true); vAddColumn(REFERENCE_INDEX_FIELD, INTEGER_TYPE, true); vAddColumn(COMPARATOR_CONDITION_FIELD, ENTITY_TYPE, false); } public virtual ec dAdd(SIndex oProfileIndex, SIndex oMemeIndex, SIndex oMemeReferenceIndex, P dComparator, int dCriteriaMeme, string sComment) { vAddValue(oProfileIndex.dIndex); vAddValue(oMemeIndex.dIndex); vAddValue(oMemeReferenceIndex.dIndex); vAddValue(dComparator); return dInsertIntoTable(); } public ec dAdd(SIndex oProfileIndex, SIndex oMemeIndex, P dComparator, bool bSupport, int dCriteriaMemeIndex, string sComment) { if (bSupport) { return dAdd(oProfileIndex, oMemeIndex, NULL_SINDEX, dComparator, dCriteriaMemeIndex, sComment); } else { return dAdd(oProfileIndex, NULL_SINDEX, oMemeIndex, dComparator, dCriteriaMemeIndex, sComment); } } public virtual ec dSelect(int dProfileIndex, SIndex[] oIdentifierIndexArray, out CVoteBase.SMemeCompare[] oMemeCompareArray) { string sIdentifierList = ToString(ToIndex(oIdentifierIndexArray)); string sExtraCondition = "(" + FIRST_INDEX_FIELD + " in(" + sIdentifierList + ")or ( " + REFERENCE_INDEX_FIELD + " in(" + sIdentifierList + "))"; return dSelect(dProfileIndex, NOT_USED, sExtraCondition, out oMemeCompareArray); } protected ec dSelect(int dProfileIndex, int dMemeIndex, string sExtraCondition, out CVoteBase.SMemeCompare[] oMemeCompareArray) { string sWhere = sFieldEqual(PROFILE_INDEX_FIELD, dProfileIndex); if (sExtraCondition != null) { sWhere += AND + sExtraCondition; } ArrayList oOutputArray; ec dRC = base.dGetSelect(sWhere, out oOutputArray, PROFILE_INDEX_FIELD, FIRST_INDEX_FIELD, REFERENCE_INDEX_FIELD, COMPARATOR_CONDITION_FIELD); oMemeCompareArray = CVoteBase.ToMemeCompareArray(dMemeIndex, oOutputArray); return dRC; } } ///--------------------------------------------------------------------------------------------------------------------------------------------------- /// /// Summary description for Class1. /// ///--------------------------------------------------------------------------------------------------------------------------------------------------- public class CMemeSubComparisonAgreementTable : CComparisonAgreementTable { public CMemeSubComparisonAgreementTable(string sTableName, string sDatabaseName) : base(sTableName, sDatabaseName) { vAddColumn(MEME_INDEX_FIELD, INTEGER_TYPE, true); } // protected override void vAddFirstColumns() {} public override ec dAdd(SIndex oProfileIndex, SIndex oMemeIndex, SIndex oMemeReferenceIndex, P dComparator, int dCriteriaMeme, string sComment) { EPAssert(oMemeIndex.dIndex == oMemeReferenceIndex.dIndex, "This table has same meme and meme reference"); vAddValue(oProfileIndex.dIndex); vAddValue(oMemeIndex.dSubIndex); vAddValue(oMemeReferenceIndex.dSubIndex); vAddValue(dComparator); vAddValue(oMemeIndex.dIndex); return dInsertIntoTable(); } public override ec dSelect(int dProfileIndex, SIndex[] oIdentifierIndexArray, out CVoteBase.SMemeCompare[] oMemeCompareArray) { EPAssert(oIdentifierIndexArray.Length == 1, "Should have only one meme"); return dSelect(dProfileIndex, oIdentifierIndexArray[0].dIndex, sFieldEqual(MEME_INDEX_FIELD, oIdentifierIndexArray[0].dIndex), out oMemeCompareArray); } } ///--------------------------------------------------------------------------------------------------------------------------------------------------- public class CCriteriaAgreementTable : CComparisonAgreementTable { public CCriteriaAgreementTable(string sTableName, string sDatabaseName) : base(sTableName, sDatabaseName) { vAddColumn(CRITERIA_FIELD, INTEGER_TYPE, true); vAddColumn(ANNOTATION_FIELD, STRING_TYPE, false); } // protected override void vAddFirstColumns(){} public override ec dAdd(SIndex oProfileIndex, SIndex oMemeIndex, SIndex oMemeReferenceIndex, P dComparator, int dCriteriaMemeIndex, string sComment) { vAddValue(oProfileIndex.dIndex); vAddValue(oMemeIndex.dIndex); vAddValue(oMemeReferenceIndex.dIndex); vAddValue(dComparator); vAddValue(dCriteriaMemeIndex); vAddValue(sComment); return dInsertIntoTable(); } } ///--------------------------------------------------------------------------------------------------------------------------------------------------- /// /// Summary description for Class1. /// ///--------------------------------------------------------------------------------------------------------------------------------------------------- public class CRuleAgreementView : CDbJoinView { public CRuleAgreementView(CComparisonAgreementTable oRuleAgreementTable, string sDatabaseName) : base(new CMemberVoteView( sDatabaseName), new CDbTableView(DETAIL_PREFIXE, oRuleAgreementTable )) { vAddLinkIndex(COrganisationMemberView.MEMBER_PREFIXE, PROFILE_INDEX_FIELD, DETAIL_PREFIXE, PROFILE_INDEX_FIELD); vAddLinkIndex(CMemberVoteView.RESULT_PREFIXE, VOTE_UNIT_IDENTIFIER, DETAIL_PREFIXE, VOTE_UNIT_IDENTIFIER); } public CMemberVoteView MemberVoteView { get { return (CMemberVoteView)this.GetMasterView; } } public CComparisonAgreementTable AgreementTable { get { return (CComparisonAgreementTable)((CDbTableView)this.GetSlaveView).oGetTable; } } /* public int dSelect(SIndex oOrganisationIndex, P dEntity, out CVoteBase.SMemeCompare[] oMemeCompareArray) { this.bAddDisplayColumn(DETAIL_PREFIXE, PROFILE_INDEX_FIELD); this.bAddDisplayColumn(DETAIL_PREFIXE, MEME_INDEX_FIELD); this.bAddDisplayColumn(DETAIL_PREFIXE, MEME_REFERENCE_INDEX_FIELD); this.bAddDisplayColumn(DETAIL_PREFIXE, COMPARATOR_CONDITION_FIELD); this.bAddWhereOrganisation(COrganisationMemberView.MEMBER_PREFIXE, oOrganisationIndex); return base.dSelect(oProfileIndex, COMPARATOR_FIELD + " in(" + CEntityManager.Instance().sGetChildList(CCommandFactoryBase.EXCLUSIVE_EXECUTIVE_RESTRICTION) + ")", dMemeList, out oMemeCompareArray); } else { return AgreementTable.dSelect(oProfileIndex, AgreementTable.sFieldEqual(COMPARATOR_FIELD, dComparatorType), dMemeList, out oMemeCompareArray); } } * */ /* * public string sqlIsIndex(SIndex oProfileIndex, SIndex oMeme) { return sFieldEqual(PROFILE_INDEX_FIELD, oProfileIndex.dIndex) + AND + sFieldEqual(MEME_INDEX_FIELD, oMeme.dIndex); } protected int dSelect(SIndex oProfileIndex, string sComplementWhere, SIndex[] oMemeList, out CVoteBase.SMemeCompare[] oMemeCompareArray) { string sWhere = oProfileIndex.dIndex.ToString() + " in(" + ToString(ToIndex(oMemeList)) + ") "; if (sComplementWhere != null) { sWhere += AND + sComplementWhere; } ArrayList oOutputArray; ec dRC = base.dGetSelect(sWhere, out oOutputArray, MEME_PREFERED_INDEX_FIELD, MEME_LESS_PREFERED_INDEX_FIELD); oMemeCompareArray = CVoteBase.ToMemeCompareArray(oOutputArray); return dRC; } * */ /* */ } ///--------------------------------------------------------------------------------------------------------------------------------------------------- /// /// Summary description for Class1. /// ///--------------------------------------------------------------------------------------------------------------------------------------------------- public class CVotingFactoryBase : CVoteBase { public CVotingFactoryBase(SVoteRight[] oVoteRightArray, int[] oMemeIndexArray, string sDatabaseName) { m_sDatabaseName = sDatabaseName; m_oVoteRightArray = oVoteRightArray; m_oMemeIndexArray = oMemeIndexArray; m_oVoteResultSortedList = new SortedList(); } string m_sDatabaseName; protected SVoteRight[] m_oVoteRightArray; int[] m_oMemeIndexArray; SortedList m_oVoteResultSortedList; } ///--------------------------------------------------------------------------------------------------------------------------------------------------- /// /// Summary description for Class1. /// ///--------------------------------------------------------------------------------------------------------------------------------------------------- public class CVoteRegisterTable : CDbSTable { public CVoteRegisterTable(string sDatabaseName) : base(VOTE_UNIT_IDENTIFIER_TABLE, sDatabaseName) { vAddColumn(ORGANISATION_INDEX_FIELD, INTEGER_TYPE, true); vAddColumn(VOTE_UNIT_IDENTIFIER, INTEGER_TYPE, true); vAddColumn(ORGANISATION_SUB_INDEX_FIELD, INTEGER_TYPE, false); vAddColumn(MEME_ADDRESS_FIELD, STRING_TYPE, false); } public const string VOTE_UNIT_IDENTIFIER_TABLE = "VoteUnitIdentifierTable"; public override ec dCreateIndex() { base.dCreateIndexMultipleField(2, MEME_ADDRESS_FIELD); return base.dCreatePrimaryIndex(); } public int dGetNextVoteIdentifier(SIndex oOrganisationIndex) { return dGetNext(VOTE_UNIT_IDENTIFIER, sFieldEqual(ORGANISATION_INDEX_FIELD, oOrganisationIndex.dIndex)); } public int dGetVoteIdentifierOfProperty(SIndex oOrganisationIndex, CEntityArray oEntityArray) { int dVoteIdentifier = GetInteger(VOTE_UNIT_IDENTIFIER, sFieldEqual(ORGANISATION_INDEX_FIELD, oOrganisationIndex.dIndex) + AND + sFieldEqual(MEME_ADDRESS_FIELD, oEntityArray.ToString() )); /* if (IsNotUsed(dPropertyValue)) { return CCommandFactoryBase.dGetDefaultValueOfProperty(dPropertyType); }*/ return dVoteIdentifier; } public ec dRegisterVote(SIndex oOrganisationIndex, CEntityArray oEntityArray) { ec dRC = ec.ST_SUCCEED; int dVoteIntifier= dGetVoteIdentifierOfProperty(oOrganisationIndex, oEntityArray ); if (IsNotUsed(dVoteIntifier)) { vAddValue(oOrganisationIndex.dIndex); vAddValue(dGetNextVoteIdentifier(oOrganisationIndex)); vAddValue(oOrganisationIndex.dSubIndex); vAddValue(oEntityArray.ToString()); dRC = dInsertIntoTable(); } return dRC; } } ///---------------------------------------------------------------------------------------------------------------------------------------------- public class CVoteRegisterView : CDbJoinView { public CVoteRegisterView(P dLanguage, string sDatabaseName) : base(new CDbTableView(REGISTER_PREFIXE, new CVoteRegisterTable(sDatabaseName)), new CDbTableView(RESULT_PREFIXE, new CVoteResultTable(sDatabaseName))) { m_dLanguage = dLanguage; vAddLinkIndex(REGISTER_PREFIXE, ORGANISATION_INDEX_FIELD, RESULT_PREFIXE, ORGANISATION_INDEX_FIELD); vAddLinkIndex(REGISTER_PREFIXE, VOTE_UNIT_IDENTIFIER, RESULT_PREFIXE, VOTE_UNIT_IDENTIFIER); } public const string REGISTER_PREFIXE = "reg"; P m_dLanguage; public ec dGetSelectVoteRegister(SIndex oOrganisationIndex, int dEntityIndex, CIdentifier oIdentifier, bool bVotingPendingOnly, out CVoteBase.SVoteRegister[] oRegisterArray) { ArrayList oArrayList; base.bAddDisplayColumn(REGISTER_PREFIXE, ORGANISATION_SUB_INDEX_FIELD); base.bAddDisplayColumn(REGISTER_PREFIXE, MEME_INDEX_FIELD); base.bAddDisplayColumn(REGISTER_PREFIXE, VOTE_UNIT_IDENTIFIER); base.bAddDisplayColumn(REGISTER_PREFIXE, MEME_ADDRESS_FIELD); base.bAddDisplayColumn(RESULT_PREFIXE, ENTITY_INDEX_FIELD); base.bAddWhereOrganisation(REGISTER_PREFIXE, oOrganisationIndex); base.bAddWhere(REGISTER_PREFIXE, MEME_ADDRESS_FIELD, ENSQLRelation.eq, oIdentifier.Index.dIndex); base.bAddWhere(REGISTER_PREFIXE, MEME_INDEX_FIELD, dEntityIndex); if (bVotingPendingOnly) { base.bAddWhere(RESULT_PREFIXE, LAST_VOTE_CHANGE_DATE_FIELD, ENSQLRelation.sup, RESULT_PREFIXE, LAST_VOTE_DATE_FIELD); base.bAddWhere(RESULT_PREFIXE, NEXT_VOTE_DATE_FIELD, ENSQLRelation.inf, DateTime.UtcNow.ToString()); } ec dRC = base.dGetSelect(out oArrayList); oRegisterArray = new CVoteBase.SVoteRegister[oArrayList.Count]; for (int i = 0; i < oArrayList.Count; i++) { object[] oObjs = (object[])oArrayList[i]; oRegisterArray[i].oOrganisationIndex.dIndex = oOrganisationIndex.dIndex; oRegisterArray[i].oOrganisationIndex.dSubIndex = Convert.ToInt32(oObjs[0]); oRegisterArray[i].dMemeIndex = Convert.ToInt32(oObjs[1]); oRegisterArray[i].dVoteIdentifier = Convert.ToInt32(oObjs[2]); dRC = CDbEntityManager.Instance(this.sDatabaseName,m_dLanguage).dConvert(oObjs[3].ToString(), out oRegisterArray[i].oIdentifier); oRegisterArray[i].dEntityIndex = Convert.ToInt32(oObjs[4]); } return dRC; } public ec dGetSelectVoteRule(SIndex oOrganisationIndex, int dRuleEntity, CIdentifier oIdentifier) { CVoteBase.SVoteRegister[] oRegisterArray; oOrganisationIndex.dSubIndex = NOT_USED; ec dRC = dGetSelectVoteRegister(oOrganisationIndex, dRuleEntity, oIdentifier, false, out oRegisterArray); return dRC; } } ///--------------------------------------------------------------------------------------------------------------------------------------------------- public class CVoteManager : CVoteBase { public CVoteManager(P dLanguage, string sDatabaseName) { m_dLanguage = dLanguage; m_oPrincipleAgreementView = new CRuleAgreementView(new CComparisonAgreementTable("RuleAgreementTable", sDatabaseName), sDatabaseName); m_oMemeAgreementView = new CRuleAgreementView(new CMemeSubComparisonAgreementTable("MemeAgreementTable", sDatabaseName), sDatabaseName); m_oVoteRegisterView = new CVoteRegisterView(dLanguage, sDatabaseName); m_oOrganisationMemberView = new COrganisationMemberView(sDatabaseName); m_oIdentifierView = new CDbIdentifierView(dLanguage, sDatabaseName); m_oProfileView = new CProfileView(dLanguage, sDatabaseName); m_oOrganisationView = new COrganisationView(dLanguage, sDatabaseName); } P m_dLanguage; CRuleAgreementView m_oPrincipleAgreementView, m_oMemeAgreementView; CVoteRegisterView m_oVoteRegisterView; COrganisationMemberView m_oOrganisationMemberView; CProfileView m_oProfileView; COrganisationView m_oOrganisationView; protected CDbIdentifierView m_oIdentifierView; public void vCleanAllData() { m_oOrganisationMemberView.vCleanAllData(); m_oPrincipleAgreementView.vCleanAllData(); m_oVoteRegisterView.vCleanAllData(); m_oIdentifierView.vCleanAllData(); m_oProfileView.vCleanAllData(); m_oMemeAgreementView.vCleanAllData(); m_oOrganisationView.vCleanAllData(); } public void vRegister() { m_oIdentifierView.vRegister(); } public ec dGetVoteRight(SIndex oOrganisationIndex, CIdentifier oSpeciality, out SVoteRight[] oVoteRight) { ec dRC = ec.ST_SUCCEED; SIndex[] oProfileIndexArray;P[] dPositionArray; bool[] bGrantAccessArray; m_oOrganisationMemberView.GetMemberTable.dGetMember(oOrganisationIndex, out oProfileIndexArray, out dPositionArray, out bGrantAccessArray); oVoteRight = new SVoteRight[oProfileIndexArray.Length]; for (int i = 0; i < oProfileIndexArray.Length; i++) { oVoteRight[i].dProfileIndex = oProfileIndexArray[i].dIndex; oVoteRight[i].dVoteCoefficient = 1; } return dRC; } public CVoteRegisterTable VoteRegisterTable { get { return (CVoteRegisterTable)(((CDbTableView)m_oVoteRegisterView.GetMasterView).oGetTable); } } public ec dAddOpinion(CCommandLine oCommandLine, CIdentifier oMainAttribute, CIdentifier oOItherIdentification2 , out string sOutputText) { sOutputText = null; ec dRC = ec.ST_SUCCEED; SIndex m_oCriteriaMemeIndex= NOT_USED_SINDEX; SIndex m_oMemeReference, m_oMainMeme; m_oMemeReference = m_oMainMeme = NULL_SINDEX; CIdentifier oCriteriaPrincipleId = oCommandLine.idFind(P.PRINCIPLE); if (oCriteriaPrincipleId != null) { SIndex[] dIdentifierIndexArray; dRC = m_oIdentifierView.dGet(MAX_MEME_IDENTIFIER_RETURN_COUNT, true, oCriteriaPrincipleId, out dIdentifierIndexArray); if (dIdentifierIndexArray.Length >= 1) { m_oCriteriaMemeIndex = dIdentifierIndexArray[0]; } } CMemeArray oMemeArray; int dCount; //dRC = m_oIdentifierView.dGet(MAX_MEME_IDENTIFIER_RETURN_COUNT, true, oMainAttribute, out dIdentifierIndexArray3); dRC = m_oProfileView.dGetMeme(oCommandLine, oMainAttribute, out oMemeArray, out dCount); if (oMemeArray.Length >= 1) { m_oMainMeme = oMemeArray[0].m_iMemeIndex; } else { return ec.ST_ATTRIBUTE_SUPPORT_MEME_DOES_NOT_EXIST; } /*CIdentifier oOItherIdentification2 = oCommandLine.idFind(P.TO); if ( oOItherIdentification2 != null) { oOItherIdentification2 = oCommandLine.idFind(P.AGAINST); }*/ if (oOItherIdentification2 != null) { SIndex[] dIdentifierIndexArray2; dRC = m_oIdentifierView.dGet(MAX_MEME_IDENTIFIER_RETURN_COUNT, true, oOItherIdentification2, out dIdentifierIndexArray2); if (dIdentifierIndexArray2.Length >= 1) { m_oMemeReference = dIdentifierIndexArray2[0]; } } dRC = dAddOpinion( oCommandLine, m_oMainMeme, m_oMemeReference, m_oCriteriaMemeIndex); /* //ec dRC = ec.ST_SUCCEED; if (oCommandLine.Command == P.SUPPORT) { dRC = m_oMemeAgreementView.AgreementTable.dAdd(oCommandLine.SenderIndex, m_oMainMeme, m_oMemeReference, oCommandLine.pFind(P.COMPARATOR), m_oCriteriaMemeIndex.dIndex, oCommandLine.sFind(P.COMMENT)); } else if (oCommandLine.Command == P.OPPOSE) { dRC = m_oMemeAgreementView.AgreementTable.dAdd(oCommandLine.SenderIndex, m_oMemeReference, m_oMainMeme, oCommandLine.pFind(P.COMPARATOR), m_oCriteriaMemeIndex.dIndex, oCommandLine.sFind(P.COMMENT)); } else { dRC = ec.ST_COMMAND_NOT_SUPPORTED_FOR_THIS_ENTITY; } */ return dRC; } public ec dAddOpinion( CCommandLine oCommandLine, SIndex oMainMeme, SIndex oAgainstMain, SIndex oCriteriaMemeIndex) { ec dErrorCode = ec.ST_COMMAND_NOT_SUPPORTED_FOR_THIS_ENTITY; CIdentifier oCriteriaPrincipleId = oCommandLine.idFind(P.PRINCIPLE); if (IsNotUsed(oMainMeme) || IsNotUsed(oAgainstMain)) { return ec.ST_OPINION_UNDEFINED_MEME; } if ( oMainMeme.dIndex == oAgainstMain.dIndex) { if (oCommandLine.Command == P.SUPPORT) { dErrorCode = m_oMemeAgreementView.AgreementTable.dAdd(oCommandLine.SenderIndex, oCommandLine.ContentIndex, oCommandLine.iFind(P.AGAINST), oCommandLine.pFind(P.COMPARATOR), oCriteriaMemeIndex.dIndex, oCommandLine.sFind(P.COMMENT)); } else if (oCommandLine.Command == P.OPPOSE) { dErrorCode = m_oMemeAgreementView.AgreementTable.dAdd(oCommandLine.SenderIndex, oCommandLine.iFind(P.AGAINST), oCommandLine.ContentIndex, oCommandLine.pFind(P.COMPARATOR), oCriteriaMemeIndex.dIndex, oCommandLine.sFind(P.COMMENT)); } } else { if (oCommandLine.Command == P.SUPPORT) { dErrorCode = m_oPrincipleAgreementView.AgreementTable.dAdd(oCommandLine.SenderIndex, oCommandLine.ContentIndex, oCommandLine.iFind(P.AGAINST), oCommandLine.pFind(P.COMPARATOR), oCriteriaMemeIndex.dIndex, oCommandLine.sFind(P.COMMENT)); } else if (oCommandLine.Command == P.OPPOSE) { dErrorCode = m_oPrincipleAgreementView.AgreementTable.dAdd(oCommandLine.SenderIndex, oCommandLine.iFind(P.AGAINST), oCommandLine.ContentIndex, oCommandLine.pFind(P.COMPARATOR), oCriteriaMemeIndex.dIndex, oCommandLine.sFind(P.COMMENT)); } } return dErrorCode; } public ec dAddOpinion(CCommandLine oCommandLine, SIndex iRuleMemeIndex, bool bSupport, out string sOutputText) { sOutputText = null; CIdentifier oCriteriaPrincipleId = oCommandLine.idFind(P.PRINCIPLE); //ec dRC = ec.ST_SUCCEED; ec dRC = m_oPrincipleAgreementView.AgreementTable.dAdd(oCommandLine.SenderIndex, iRuleMemeIndex, oCommandLine.pFind(P.COMPARATOR), bSupport, oCriteriaPrincipleId.Index.dIndex, oCommandLine.sFind(P.COMMENT)); return dRC; } public ec dVoteCountReport(CCommandLine oCommandLine, CIdentifier oIdentifierAdress, out string sOutputText) { SIndex[] oMemeClassement; CRankVoting.SBottomCount[] oIndexMemeRankList; SIndex[] dIdentifierIndexArray; CTraceReport oTraceReport = new CTraceReport(); ec dRC = dVoteCount(oCommandLine, oIdentifierAdress,ref oTraceReport, out dIdentifierIndexArray,out oIndexMemeRankList, out oMemeClassement); if (dRC == ec.ST_SUCCEED) { if (oIndexMemeRankList == null || oIndexMemeRankList.Length == 0) { sOutputText = "There is no results"; dRC = ec.ST_VOTE_EMPTY_RESULTS; } else { CMemeArray oMemeArray; int dCount; dRC = m_oProfileView.dGetMeme(oCommandLine, oIdentifierAdress, out oMemeArray, out dCount); dRC = oMemeArray.dExtract(oMemeClassement, out oMemeArray); if (dRC != ec.ST_SUCCEED) { CListReport oReport = new CListReport(3); // oReport.Active = true; oReport.vSetTitle("Vote Result"); oReport.vSetHeader("Rank", "Meme_Index", "Neg_Count"); for (int i = oIndexMemeRankList.Length - 1; i >= 0; i--) { SIndex oIndex = dGetSIndex(dIdentifierIndexArray, oIndexMemeRankList[i].dMemeIndex); oReport.vAdd(oIndexMemeRankList.Length - i, dGetSIndex(dIdentifierIndexArray, oIndexMemeRankList[i].dMemeIndex), oIndexMemeRankList[i].dCount); } sOutputText = oReport.sText; sOutputText += oTraceReport.sText; } else { SMemeDisplay[] oContentArray; m_oOrganisationView.vGetMemeContent(oCommandLine.SenderIndex.dIndex, oMemeArray, out oContentArray); CListReport oReport = new CListReport(5); //oReport.Active = true; oReport.vSetTitle("Vote Result"); oReport.vSetHeader("Rank", "Identifier", "Content", "Author", "Neg_Count"); for (int i = 0; i < oContentArray.Length; i++ ) { oReport.vAdd(i + 1, oContentArray[i].sAddress, oContentArray[i].sContent, oContentArray[i].sAuthorName, oIndexMemeRankList[i].dCount); } sOutputText = oReport.sText; sOutputText += oTraceReport.sText; } } } else { sOutputText = " The vote count got get " + dRC + "\n"; } if (oCommandLine.bHasOption(P.TRACE)) { sOutputText += oTraceReport.sText; } return dRC; } public ec dVoteCount(CCommandLine oCommandLine, CIdentifier oIdentifierAdress, ref CTraceReport oTraceReport, out SIndex[] dIdentifierIndexArray, out CRankVoting.SBottomCount[] oIndexMemeRankList, out SIndex[] oMemeClassement) { SVoteRight[] oVoteRight; oMemeClassement = null; oIndexMemeRankList = null; // CIdentifier oIdentifierAdress= oCommandLine.idFind(P.IDENTIFIER); ec dRC = m_oIdentifierView.dGet(MAX_MEME_IDENTIFIER_RETURN_COUNT, true, oIdentifierAdress, out dIdentifierIndexArray); if (dIdentifierIndexArray.Length == 0) { return ec.ST_VOTE_NO_OBJECT_TO_SELECT_BY_VOTE; } dRC = dGetVoteRight(oCommandLine.OrganisationIndex, oIdentifierAdress.oGetRoot(P.SPECIALITY_CLASS), out oVoteRight); if (dRC== ec.ST_SUCCEED) { //if (oIdentifierAdress.bIsA(P.PRINCIPLE)) //{ Debug.WriteLine("m_oMemeAgreementView.AgreementTable = " + m_oMemeAgreementView.AgreementTable.csDumpTable()); CRankVoting oRankVoting = new CRankVoting(oVoteRight); for(int i=0; i < oVoteRight.Length;i++) { SMemeCompare[] oMemeCompareArray; if ((dIdentifierIndexArray.Length == 1 )) { m_oMemeAgreementView.AgreementTable.dSelect(oVoteRight[i].dProfileIndex, dIdentifierIndexArray, out oMemeCompareArray); } else { m_oPrincipleAgreementView.AgreementTable.dSelect(oVoteRight[i].dProfileIndex, dIdentifierIndexArray, out oMemeCompareArray); } oRankVoting.vAdd(oVoteRight[i].dProfileIndex, oMemeCompareArray); } oTraceReport.Active = oCommandLine.bHasOption(P.TRACE); oTraceReport.dLoadProfile(ToArrayList(oVoteRight)); oRankVoting.vVote(out oIndexMemeRankList, ref oTraceReport); if (oCommandLine.bHasOption(P.ENCRYPT) ) { oTraceReport.dReplaceProfileIndexByRamdomIndex(); } if (oIndexMemeRankList == null || oIndexMemeRankList.Length == 0) { oMemeClassement = null; dRC = ec.ST_VOTE_EMPTY_RESULTS; } else { oMemeClassement = new SIndex[oIndexMemeRankList.Length]; for (int i = oIndexMemeRankList.Length - 1; i >= 0; i--) { oMemeClassement[oIndexMemeRankList.Length - i - 1] = dGetSIndex(dIdentifierIndexArray, oIndexMemeRankList[i].dMemeIndex); } } // } } return dRC; } private SIndex dGetSIndex(SIndex[] dIdentifierIndexArray, int dMemeIndex) { SIndex oIndex; if ((dIdentifierIndexArray.Length == 1)) { oIndex.dIndex = dIdentifierIndexArray[0].dIndex; oIndex.dSubIndex = dMemeIndex; } else { oIndex.dIndex = dMemeIndex; oIndex.dSubIndex = NOT_USED; } return oIndex; } } ///--------------------------------------------------------------------------------------------------------------------------------------------------- public class CVoteMemeView : CVoteView { public CVoteMemeView(P dLanguage, string sViewName, string sDatabaseName) : base(sViewName, sDatabaseName) { m_dLanguage = dLanguage; } public ec dVote(SIndex oOrganisationIndex, P dVoteIdentifier, CVoteBase.SVoteRight[] oVoteRight, TimeSpan oNextElectionSpan, CVoteBase.SMemeCompare[] oBallotArray, out CRankVoting.SBottomCount[] oIndexMemeRankList, ref CTraceReport oTraceReport) { CRankVoting oGradeRankVoting = new CRankVoting( oVoteRight); oGradeRankVoting.vAdd(oBallotArray); oGradeRankVoting.vVote(out oIndexMemeRankList, ref oTraceReport); ec dRC = VoteResultTable.dSetResult(oOrganisationIndex, dVoteIdentifier, oIndexMemeRankList.Length > 0 ? oIndexMemeRankList[0].dMemeIndex : NOT_USED, oNextElectionSpan, GetSerializedValue(oIndexMemeRankList)); return dRC; } P m_dLanguage; public ec dGetSelectBallot(SIndex oOrganisationIndex, int dVoteIdentifier, out CVoteBase.SVoteGrade[] oBallotArray) { string sWhere = VoteResultTable.sqlIsOrganisation(oOrganisationIndex); sWhere += AND + VoteDetailTable.sFieldEqual(VOTE_UNIT_IDENTIFIER, dVoteIdentifier); ArrayList oArrayList; ec dRC = VoteDetailTable.dGetSelect(sWhere, out oArrayList, PROFILE_INDEX_FIELD, SUPPORT_FIELD, MEME_INDEX_FIELD); oBallotArray = new CVoteBase.SVoteGrade[oArrayList.Count]; if (dRC != ec.ST_SUCCEED) { for (int i = 0; i < oArrayList.Count; i++) { object[] oVote = (object[])oArrayList[i]; oBallotArray[i].dProfileIndexIndex = Convert.ToInt32(oVote[0]); oBallotArray[i].dGrade = Convert.ToInt32(oVote[1]); oBallotArray[i].dMemeIndex = Convert.ToInt32(oVote[2]); } } return dRC; } } } ///---------------------------------------------------------------------------------------------------------------------------------------------- /*public class CAgreementWithComparatorTable : CAgreementTable { public CAgreementWithComparatorTable(string sTableName, string sDatabaseName) : base(sTableName, sDatabaseName) { vAddColumn(COMPARATOR_FIELD, INTEGER_TYPE, false); } public const string COMPARATOR_FIELD = "[Comparator]"; public int dSelect(SIndex oProfileIndex, int dComparatorType, SIndex[] dMemeList, out CVoteBase.SMemeCompare[] oMemeCompareArray) { if (CEntityManager.Instance().bIsA(dComparatorType, EXCLUSIVE_EXECUTIVE_RESTRICTION)) { return dSelect(oProfileIndex, COMPARATOR_FIELD + " in(" + CEntityManager.Instance().sGetChildList(EXCLUSIVE_EXECUTIVE_RESTRICTION) + ')', dMemeList, out oMemeCompareArray); } else { return dSelect(oProfileIndex, sFieldEqual(COMPARATOR_FIELD, dComparatorType), dMemeList, out oMemeCompareArray); } } } public class CAgreementWithPrincipleTable : CAgreementTable { public CAgreementWithPrincipleTable(string sTableName, string sDatabaseName) : base(sTableName, sDatabaseName) { vAddColumn(PRINCIPLE_FIELD, ENTITY_TYPE, true); } public const string PRINCIPLE_FIELD = "[Principle]"; public int dSelect(SIndex oProfileIndex, int dPrincipeType, SIndex[] dMemeList, out CVoteBase.SMemeCompare[] oMemeCompareArray) { return dSelect(oProfileIndex, sFieldEqual(PRINCIPLE_FIELD, dPrincipeType), dMemeList, out oMemeCompareArray); } } */ /* ///--------------------------------------------------------------------------------------------------------------------------------------------------- /// /// Summary description for Class1. /// //---------------------------------------------------------------------------------------------------------------------------------------------- /// /// Summary description for GroupDbTable. /// //---------------------------------------------------------------------------------------------------------------------------------------------- /// public class CObjectDbView : CVoteBooleanView { public CObjectDbView(string sDatabaseName) : base("ObjectOfOrganisation", sDatabaseName) { this.vAddKeyOrganisation(); VoteResultTable.vAddColumn(sColumnName, INTEGER_TYPE, true); this.vAddKeyColumn(IDENTIFIER_INDEX, INTEGER_TYPE); VoteResultTable.vAddColumn(IDENTIFIER_SUB_INDEX, INTEGER_TYPE, false); } public string sGetIdentifierKey(int dIdentifierIndex) { return this.VoteResultTable.sFieldEqual(IDENTIFIER_INDEX, dIdentifierIndex); } } */

Enter supporting content here