Make your own free website on Tripod.com
EPolWS
DbVariableView.cs
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

DbTable

using System; using System.Diagnostics; using System.Collections; using EXDb97; using EXCommon; //using EXTree; //###2 namespace EPol { ///------------------------------------------------------------------------------------------------------------------------- /// /// Summary description for CDbEntityNameTable /// ///------------------------------------------------------------------------------------------------------------------------- public class CDbEntityManager : CDbEPBase { public CDbEntityManager(string sDatabaseName, P dLanguage) { m_dLanguage = dLanguage; m_oDbEntityNameView = new CDbEntityNameView(sDatabaseName); m_dEntityCount = (int)P.FIRST_KEYWORD_INDEX + EntityNameTable.GetRecordCount(); vLoad(m_dEntityCount); } static CDbEntityManager s_oDbEntityManager = null; public static CDbEntityManager Instance(string sDatabaseName, P dLanguage) { if (s_oDbEntityManager == null) { s_oDbEntityManager = new CDbEntityManager(sDatabaseName, dLanguage); } return (CDbEntityManager)s_oDbEntityManager; } CDbEntityNameTable EntityNameTable { get { return m_oDbEntityNameView.GetMasterTable; } } CDbEntityNameView m_oDbEntityNameView; int m_dEntityCount; P m_dLanguage; public void vCleanAllData() { m_oDbEntityNameView.vCleanAllData(); } public string sGetName(P dEntity) { return m_oDbEntityNameView.sGetName(dEntity, m_dLanguage); } public P dGetType(P dEntity) { return CEntityManager.Instance(m_dLanguage).dGetType(dEntity); } public ec dUpdateClass(P dName, P dClass) { CEntityManager.Instance(m_dLanguage).vSetClass(dName, dClass); return EntityNameTable.dUpdate(CLASS_FIELD, (int)dClass, EntityNameTable.sFieldEqual(ENTITY_INDEX_FIELD, dName)); } public ec dUpdateParent(P dEntity, P dParent) { CEntityManager.Instance(m_dLanguage).vSetParent(dEntity, dParent); return EntityNameTable.dUpdate(PARENT_ENTITY_INDEX_FIELD, (int)dParent, EntityNameTable.sFieldEqual(ENTITY_INDEX_FIELD, dEntity)); } public ec dUpdateIdParent(P dEntity, P dParent) { CEntityManager.Instance(m_dLanguage).vSetIdParent(dEntity, dParent); return EntityNameTable.dUpdate(PARENT_ENTITY_ID_INDEX_FIELD, (int)dParent, EntityNameTable.sFieldEqual(ENTITY_INDEX_FIELD, dEntity)); } public ec dUpdateId(P dName, char cRelation, P dEntityProperty) { CEntityManager.Instance(m_dLanguage).vSet(dName, cRelation, dEntityProperty); return EntityNameTable.dUpdateBinary(PROPERTY_FIELD, GetSerializedValue(CEntityManager.Instance(m_dLanguage).GetPropertyArray(dName)), EntityNameTable.sFieldEqual(ENTITY_INDEX_FIELD, dName)); } public virtual void vSet(P dName, char cRelation, P dEntityProperty1, P dEntityProperty2) { CEntityManager.Instance(m_dLanguage).vSet(dName, cRelation, dEntityProperty1); CEntityManager.Instance(m_dLanguage).vSet(dName, cRelation, dEntityProperty2); } public virtual void vSet(P dName, char cRelation, P dEntityProperty) { CEntityManager.Instance(m_dLanguage).vSet(dName, cRelation, dEntityProperty); } public void vLoad(int dEntityTotal) { CEntityManager.Instance(m_dLanguage).vLoad( dEntityTotal); m_oDbEntityNameView.bAddDisplayColumn(CDbEntityNameView.ENTITY_PREFIXE, ENTITY_INDEX_FIELD); m_oDbEntityNameView.bAddDisplayColumn(CDbEntityNameView.ENTITY_PREFIXE, CLASS_FIELD); m_oDbEntityNameView.bAddDisplayColumn(CDbEntityNameView.ENTITY_PREFIXE, PARENT_ENTITY_INDEX_FIELD); m_oDbEntityNameView.bAddDisplayColumn(CDbEntityNameView.ENTITY_PREFIXE, PARENT_ENTITY_ID_INDEX_FIELD); m_oDbEntityNameView.bAddDisplayColumn(CDbEntityNameView.ENTITY_PREFIXE, PROPERTY_FIELD); ArrayList oEntityArray; m_oDbEntityNameView.dGetSelect(out oEntityArray); if (oEntityArray != null) { for (int i = 0; i < oEntityArray.Count; i++) { object[] oValueArray = (object[])oEntityArray[i]; P dName = (P)oValueArray[0]; CEntityManager.Instance(m_dLanguage).vSetClass(dName, (P)oValueArray[1]); CEntityManager.Instance(m_dLanguage).vSetParent(dName, (P)oValueArray[2]); CEntityManager.Instance(m_dLanguage).vSetIdParent(dName, (P)oValueArray[3]); CEntityManager.Instance(m_dLanguage).vLoadProperty(dName, (SProperty[])Deserialize((byte[])oValueArray[4])); } } } public CEntityArray oConcat(string sClassKeyword, string sInstanceKeyword, CEntityArray oEntityArray) { SEntity oEntity; if (dConvert(sClassKeyword, sInstanceKeyword, out oEntity) == ec.ST_SUCCEED) { oEntityArray.vAdd(oEntity); return oEntityArray; } else { return oEntityArray; } } public P dGet(P dLanguage, string sAttributeName) { return m_oDbEntityNameView.dGet(sAttributeName, dLanguage); } public CDbEntityManager.CDbEntityNameView GetKeywordView { get { return m_oDbEntityNameView; } } /* public SEntity oAddAttributeIdentifier(P dAttributeClass, P dLanguage, string sAttributeName) { SEntity oAttribute = new SEntity(); oAttribute.dClass = dAttributeClass; oAttribute.Instance = dGet(dLanguage, sAttributeName); P dIndex = P.NOT_USED; if (IsNotUsed(oAttribute)) { m_oDbEntityNameView.dAdd(dAttributeClass, P.NOT_USED, P.ATTRIBUTE, dLanguage, sAttributeName, out dIndex); } oAttribute.Instance = (P)dIndex; return oAttribute; }*/ protected ec dConvert(string sClassKeyword, string sInstanceKeyword, out SEntity oEntity) { oEntity = new SEntity(); oEntity.dClass = dGet(m_dLanguage, sClassKeyword); if (sInstanceKeyword.Length < 2) { oEntity.Instance = dGet(m_dLanguage, sInstanceKeyword); } else { oEntity.vSetInstanceFromTypeAndIntegerString(sInstanceKeyword); /* string sType = sInstanceKeyword.Substring(0, 2); string sContent = sInstanceKeyword.Substring(2, sInstanceKeyword.Length - 2); if (sType == "i:") { try { oEntity.iInstance = Convert.ToInt32(sInstanceKeyword); } catch { oEntity.Instance = P.CONVERTION_FAILED; } } else if (sType == "s:") { oEntity.sInstance = sContent; } else { oEntity.Instance = dGet(m_dLanguage, sInstanceKeyword); }*/ } return IsNotUsed(oEntity.dClass) || oEntity.IsNotUsed ? ec.ST_ATTRIBUTE_CONTENT_IS_MISSING : ec.ST_SUCCEED; } public ec dConvert(string sAddressTotal, out CIdentifier oIdentifier) { oIdentifier = null; if (sAddressTotal == null) return ec.ST_ATTRIBUTE_CONTENT_IS_MISSING; ec dRet = ec.ST_SUCCEED; int dIndexOfSubMeme = sAddressTotal.IndexOf(IDENTIFIER_MEME_SEPARATOR); int dSubMeme = NOT_USED; string sAddress; if ( dIndexOfSubMeme >= 0) { sAddress = sAddressTotal.Substring(0, dIndexOfSubMeme); dSubMeme = Convert.ToInt32( sAddressTotal.Substring(dIndexOfSubMeme+1)); } else { sAddress = sAddressTotal; } int dNextEntity = sAddress.LastIndexOf(IDENTIFIER_CHILD_SEPARATOR); string sAddressChild, sAddressAncestorTail; if (dNextEntity >= 0) { sAddressAncestorTail = sAddress.Substring(0, dNextEntity); sAddressChild = sAddress.Substring(dNextEntity + 1, sAddress.Length - dNextEntity - 1); } else { sAddressChild = sAddress; sAddressAncestorTail = null; } int dAttributeIndex = sAddressChild.IndexOf(IDENTIFIER_PROPERTY_SEPARATOR); string sAttributeAdress = null, sAddressChildEntity = null; if (dAttributeIndex >= 0) { sAttributeAdress = sAddressChild.Substring(dAttributeIndex + 1, sAddressChild.Length - dAttributeIndex - 1); sAddressChildEntity = sAddressChild.Substring(0, dAttributeIndex); } else { sAddressChildEntity =sAddressChild; } CEntityArray oEntityArray; dRet = dConvert(sAttributeAdress, out oEntityArray); P dEntity = dGet(m_dLanguage, sAddressChildEntity); if (IsNotUsed(dEntity)) { dRet = ec.ST_ATTRIBUTE_NAME_IS_NOT_CORRECTLY_SPECIFY; } CIdentifier oIdentifierParent = null; if (sAddressAncestorTail != null) { dRet = dConvert(sAddressAncestorTail, out oIdentifierParent); } oIdentifier = new CIdentifier(dEntity, oIdentifierParent, oEntityArray); oIdentifier.vSetSubMeme(dSubMeme); CTrace.i().vWriteLn(ENMessage.Convert, oIdentifier.csDump()); return dRet; } public ec dConvert(string sAddress, out CEntityArray oEntityArray) { oEntityArray = new CEntityArray(); if (sAddress == null) return ec.ST_ATTRIBUTE_CONTENT_IS_MISSING; ArrayList sClassArray = new ArrayList(); ArrayList sInstanceArray = new ArrayList(); ArrayList bExactComparatorArray = new ArrayList(); string sKeyword = ""; string sClass = ""; bool bExact = true; for (int i = 0; i < sAddress.Length; i++) { char cChar = sAddress[i]; if (cChar.ToString() == IDENTIFIER_PROPERTY_SEPARATOR || i == sAddress.Length - 1) { if (i == sAddress.Length - 1) sKeyword += cChar; if (sClass == "") { sClassArray.Add(P.IDENTIFIER.ToString()); sInstanceArray.Add(sKeyword); } else { sClassArray.Add(sClass); sInstanceArray.Add(sKeyword); bExactComparatorArray.Add(bExact); } sClass = sKeyword = ""; } else if (cChar == '=') { if (sKeyword.LastIndexOf('*') == sKeyword.Length - 1) { sClass = sKeyword.Remove(sKeyword.Length - 1, 1); bExact = false; } else { sClass = sKeyword; } sKeyword = ""; } else { sKeyword += cChar; } } return dConvert((string[])sClassArray.ToArray(typeof(String)), (string[])sInstanceArray.ToArray(typeof(String)), (bool[])bExactComparatorArray.ToArray(typeof(bool)), out oEntityArray); } public ec dConvert(string[] sKeywordClassArray, string[] sKeywordInstanceArray, bool[] bExactComparatorArray, out CEntityArray oEntityArrayOutput) { ec dRC = ec.ST_SUCCEED; SEntity[] oEntityArray = null; if (sKeywordClassArray.Length != sKeywordInstanceArray.Length) { dRC = ec.ST_ATTRIBUTE_CONTENT_IS_MISSING; } else { oEntityArray = new SEntity[sKeywordClassArray.Length]; for (int i = 0; i < sKeywordClassArray.Length; i++) { dRC = dConvert(sKeywordClassArray[i], sKeywordInstanceArray[i], out oEntityArray[i]); oEntityArray[i].bExact = bExactComparatorArray[i]; } } oEntityArrayOutput = new CEntityArray(oEntityArray); return dRC; } public P dGetClass(P dEntityClass) { return CEntityManager.Instance(m_dLanguage).dGetClass(dEntityClass); } public SEntity oGetEntity(P dLanguage, P dEntityClass, string sAttributeName) { SEntity oEntity = new SEntity(); oEntity.vSet(dEntityClass, sAttributeName, dLanguage); return oEntity; } /* public ec dConvertHead(CIdentifier oIdentifier, out string sEntityKey) { sEntityKey = ""; ec dRet = ec.ST_SUCCEED; if (IsNotUsed(oIdentifier.Entity)) { dRet = m_oIdentifierView.dGetSelect(oIdentifier.dIndex, out oIdentifier); } if (oIdentifier == null) { return dRet; } else { dRet = dConvert(oIdentifier.ParentIdentifier, out sEntityKey); if (sEntityKey != "") { sEntityKey += IDENTIFIER_CHILD_SEPARATOR; } sEntityKey += sGetName(oIdentifier.Entity); if (oIdentifier.EntityArray != null) { string sAttributeKey; dRet = dConvert(oIdentifier.EntityArray, out sAttributeKey); if (sAttributeKey != "") { sEntityKey += ';' + sAttributeKey; } } } return dRet; } */ public ec dConvertHead(CIdentifier oIdentifier, out string sEntityKey) { sEntityKey = ""; ec dRet = ec.ST_SUCCEED; if (oIdentifier == null) { return dRet; } else { sEntityKey += sGetName(oIdentifier.Entity); if (oIdentifier.dGetEntityArray(false) != null) { string sAttributeKey; dRet = dConvert(oIdentifier.dGetEntityArray(false), out sAttributeKey); if (sAttributeKey != "") { sEntityKey += ';' + sAttributeKey; } } } return dRet; } public ec dConvert(CEntityArray oEntityArray, out string sEntityKey) { ec dRC = oEntityArray.dSort(); SEntity[] oOutPutArray = oEntityArray.EntityExtraArray; sEntityKey = ""; for (int i = 0; i < oOutPutArray.Length; i++) { if (sEntityKey != "") sEntityKey += IDENTIFIER_PROPERTY_SEPARATOR; string sInstance; if ( oOutPutArray[i].bIsType(P.INTEGER_TYPE) ) { sInstance = "i:" + oOutPutArray[i].dInstance.ToString(); } else if (oOutPutArray[i].bIsType(P.STRING_TYPE)) { sInstance = "s:" + oOutPutArray[i].sInstance; } else if (oOutPutArray[i].bIsType(P.SINDEX_TYPE)) { sInstance = "si:" + oOutPutArray[i].sInstance; } else if (oOutPutArray[i].bIsType(P.ENTITY_ARRAY_TYPE)) { string sEntityKey2; dRC = dConvert((CEntityArray)oOutPutArray[i].EntityArrayInstance, out sEntityKey2); sInstance = "ea:" + sEntityKey2; } else { sInstance = sGetName((P)oOutPutArray[i].Instance); } sEntityKey += sGetName(oOutPutArray[i].dClass) + "=" + sInstance; } //} return dRC; } /// /// //////////////////Embedded /// public class CDbEntityView : CCommandFactoryBase { public CDbEntityView(P dLanguage, string sDatabaseName) { m_dLanguage = dLanguage; m_oEntityNameTable = new CDbEntityNameTable(sDatabaseName); m_oEntityRelation = new CDbSTable(ENTITY_RELATION_TABLE, sDatabaseName); m_oEntityRelation.vAddColumn(ENTITY_INDEX_FIELD, INTEGER_TYPE, true); m_oEntityRelation.vAddColumn(RELATION_FIELD, BIT_TYPE, true); m_oEntityRelation.vAddColumn(ENTITY_TARGET_FIELD, INTEGER_TYPE, false); m_oEntityRelationView = new CDbJoinView(new CDbTableView(ENTITY_PREFIXE, m_oEntityNameTable), new CDbTableView(ENTITY_RELATION_PREFIXE, m_oEntityRelation)); m_oEntityRelationView.vAddLinkIndex(ENTITY_PREFIXE, KEYWORD_TABLE_NAME, ENTITY_RELATION_PREFIXE, ENTITY_RELATION_TABLE); } P m_dLanguage; public void vCleanAllData() { m_oEntityRelationView.vCleanAllData(); } public CDbEntityNameTable GetMasterTable { get { return m_oEntityNameTable; } } public P dGetClass(P dEntity) { return CEntityManager.Instance(m_dLanguage).dGetClass(dEntity); } public P dGetType(P dEntity) { return CEntityManager.Instance(m_dLanguage).dGetType(dEntity); } public P dGet(P dEntity, char cRelation) { return CEntityManager.Instance(m_dLanguage).dGet(dEntity, cRelation); /* else { if (cRelation == CCommandFactoryBase.HAS_CLASS_RELATION) { string sWhere = m_oEntityRelation.sFieldEqual(ENTITY_INDEX_FIELD, dEntity); return (P)m_oEntityNameTable.GetInteger(CLASS_FIELD, sWhere); } else { return (P)m_oEntityRelation.GetInteger(ENTITY_TARGET_FIELD, m_oEntityRelation.sFieldEqual(RELATION_FIELD, cRelation) + AND + m_oEntityRelation.sFieldEqual(ENTITY_INDEX_FIELD, dEntity)); } }*/ } CDbEntityNameTable m_oEntityNameTable; CDbJoinView m_oEntityRelationView; CDbSTable m_oEntityRelation; public const string ENTITY_RELATION_TABLE = "RelationTable"; } ///------------------------------------------------------------------------------------------------------------------------- public class CDbEntityNameView : CDbJoinView { public CDbEntityNameView(string sDatabaseName) : base(new CDbTableView(ENTITY_PREFIXE, new CDbEntityNameTable(sDatabaseName)), new CDbTableView(NAME_PREFIXE, new CDbSTable("EntityNameKeyword", sDatabaseName))) { GetSlaveTable.vAddColumn(ENTITY_INDEX_FIELD, INTEGER_TYPE, true); GetSlaveTable.vAddColumn(LANGUAGE_FIELD, INTEGER_TYPE, false); GetSlaveTable.vAddColumn(KEYWORD_FIELD, STRING_50_TYPE, false); GetSlaveTable.dCreateTable(); if (GetSlaveTable.dCreateTable() == ec.ST_SUCCEED) { GetSlaveTable.dCreateIndexMultipleField(2, LANGUAGE_FIELD, KEYWORD_FIELD); } vAddLinkIndex(ENTITY_PREFIXE, ENTITY_INDEX_FIELD, NAME_PREFIXE, ENTITY_INDEX_FIELD); } public CDbSTable GetSlaveTable { get { return ((CDbTableView)GetSlaveView).oGetTable; } } public CDbEntityNameTable GetMasterTable { get { return (CDbEntityNameTable)((CDbTableView)GetMasterView).oGetTable; } } public const string NAME_PREFIXE = "name"; public string sGetName(CCommandArrayFactory.P dEntityIndex, P dLanguage) { return CEntityManager.Instance(dLanguage).m_oEntityNameCommandArray.sGetName(dEntityIndex, dLanguage); } public CCommandArrayFactory.P dGetClass(CCommandArrayFactory.P dEntityIndex) { return CEntityManager.Instance(P.ENGLISH).dGetClass(dEntityIndex); /* if (dEntityIndex < CCommandArrayFactory.P.ENTITY_COUNT) { return CEntityManager.Instance(P.ENGLISH).dGetClass(dEntityIndex); } else { return (CCommandArrayFactory.P)GetMasterTable.GetInteger(CLASS_FIELD, GetSlaveTable.sFieldEqual(ENTITY_INDEX_FIELD, dEntityIndex)); }*/ } public CCommandArrayFactory.P dGet(string sKeyword, P dLanguage) { if (sKeyword == null) return CCommandArrayFactory.P.NOT_USED; CCommandArrayFactory.P dEntityIndex = CEntityManager.Instance(P.ENGLISH).dFindEntity(sKeyword); if (IsNotUsed(dEntityIndex)) { dEntityIndex = (CCommandArrayFactory.P)GetSlaveTable.GetInteger(ENTITY_INDEX_FIELD, GetSlaveTable.sFieldEqual(KEYWORD_FIELD, sKeyword) + AND + GetSlaveTable.sFieldEqual(LANGUAGE_FIELD, dLanguage)); } return dEntityIndex; } public ec dAdd(P dClass, P dParent, P dParentID, P dLanguage, string sKeyword, SProperty[] oPropertyArray, out CCommandArrayFactory.P dIndex) { CTrace.i().vWriteLn(ENMessage.Attribute, "dClass=" + dClass + " dParent=" + dParent + " dParentID=" + dParentID + " sKeyword=" + sKeyword); dIndex = dGet( sKeyword, dLanguage); ec dRet = ec.ST_SUCCEED; if (IsNotUsed(dIndex)) { dRet = GetMasterTable.dAdd(dClass, dParent, dParentID, oPropertyArray, out dIndex); if (IsUsed(dIndex)) { GetSlaveTable.vAddValue(dIndex); GetSlaveTable.vAddValue(dLanguage); GetSlaveTable.vAddValue(sKeyword); dRet = GetSlaveTable.dInsertIntoTable(); } } return dRet; } public ec dAdd(int dMemeParentIndex, P dLanguage, string sKeyword) { GetSlaveTable.vAddValue(dMemeParentIndex); GetSlaveTable.vAddValue(dLanguage); GetSlaveTable.vAddValue(sKeyword); ec dRet = GetSlaveTable.dInsertIntoTable(); return dRet; } } ///------------------------------------------------------------------------------------------------------------------------- public class CDbEntityNameTable : CDbSTable { public CDbEntityNameTable(string sDatabaseName) : base(KEYWORD_TABLE_NAME, sDatabaseName) { vAddColumn(ENTITY_INDEX_FIELD, INTEGER_TYPE, true); vAddColumn(CLASS_FIELD, ENTITY_TYPE, false); vAddColumn(PARENT_ENTITY_INDEX_FIELD, INTEGER_TYPE, false); vAddColumn(PARENT_ENTITY_ID_INDEX_FIELD, ENTITY_TYPE, false); vAddColumn(PROPERTY_FIELD, BINARY_TYPE, false); // s_oEntityNameEnglishTable = null; } public ec dAdd(P dClass, P dParent, P dParentID, SProperty[] oPropertyType, out P dIndexP) { int dIndex; vAddAutoIncrement((int)P.FIRST_KEYWORD_INDEX, out dIndex); vAddValue(dClass); vAddValue(dParent); vAddValue(dParentID); vAddValue(oPropertyType); dIndexP = (P)dIndex; return this.dInsertIntoTable() == ec.ST_SUCCEED ? ec.ST_SUCCEED : ec.ST_ATTRIBUTE_KEY_WORD_CAN_NOT_BE_ADDED; } public override ec dCreateIndex() { this.dCreateIndexMultipleField(2, KEYWORD_FIELD); return dCreatePrimaryIndex(); } /* static CDbEntityNameTable s_oEntityNameEnglishTable; public static CDbEntityNameTable Instance(string sDatabaseName) { if (s_oEntityNameEnglishTable == null) { s_oEntityNameEnglishTable = new CDbEntityNameTable(sDatabaseName); } return s_oEntityNameEnglishTable; } */ } } ///------------------------------------------------------------------------------------------------------------------------- /// /// Summary description for CDbEntityNameTable /// ///------------------------------------------------------------------------------------------------------------------------- public class CDbIdentifierHeadTable : CDbSTable { public CDbIdentifierHeadTable(string sName, string strDatabaseName) : base(sName, strDatabaseName) { vAddColumn(MASTER_PARENT_INDEX_FIELD, INTEGER_TYPE, true); vAddColumn(MASTER_PARENT_SUB_INDEX_FIELD, INTEGER_TYPE, true); vAddColumn(ENTITY_INDEX_FIELD, INTEGER_TYPE, true); vAddColumn(MASTER_INDEX_FIELD, INTEGER_TYPE, false); vAddColumn(DATE_FIELD, DATE_TYPE, false); } public override ec dCreateIndex() { ec dRC = base.dCreateIndex(); this.dCreateIndexMultipleField(2, MASTER_INDEX_FIELD); return dRC; } public ec dStoreIdentifier(P dEntity, SIndex iIdentifierParent, out int dIdentifierIndex) { CTrace.i().vWriteLn(ENMessage.Attribute, "dStoreIdentifier dEntity=" + dEntity + " iIdentifierParent= " + iIdentifierParent.ToString()); int[] dMasterIndexFieldArray; dGetSelect(dEntity, iIdentifierParent, out dMasterIndexFieldArray); if (dMasterIndexFieldArray == null) { dIdentifierIndex = dGetNext(MASTER_INDEX_FIELD, null); vAddValue(iIdentifierParent); vAddValue((int)dEntity); vAddValue(dIdentifierIndex); vAddValue(DateTime.UtcNow); return dInsertIntoTable(); } else { dIdentifierIndex = dMasterIndexFieldArray[0]; return ec.ST_ENTITY_IDENTIFIER_ALREADY_INSERTED; } } public string sqlIsIndex(int dMasterIndex) { return sFieldEqual(MASTER_INDEX_FIELD, dMasterIndex); } public string sqlIsIndex(P dEntity, SIndex iIdentifierParent) { string sOutput = sFieldEqual(ENTITY_INDEX_FIELD, dEntity); if (IsUsed(iIdentifierParent.dIndex)) { sOutput += AND + sFieldEqual(MASTER_PARENT_INDEX_FIELD, iIdentifierParent.dIndex); } if (IsUsed(iIdentifierParent.dSubIndex)) { sOutput += AND + sFieldEqual(MASTER_PARENT_SUB_INDEX_FIELD, iIdentifierParent.dSubIndex); } return sOutput; } public ec dGetSelect(P dEntity, SIndex iIdentifierParent, out int[] dMasterIndexFieldArray) { ArrayList oOutputArray; ec dRet = dGetSelect(sqlIsIndex(dEntity,iIdentifierParent), out oOutputArray, MASTER_INDEX_FIELD); dMasterIndexFieldArray = ToIntegerArray(oOutputArray); //dMasterIndexFieldArray = ToIntegerArray(oOutputArray, 0); //iParentMasterIndexFieldArray = ToSIndexArray(oOutputArray, 1); return dRet; } /* public ec dGetSelect(P dEntity, SIndex iIdentifierParent, out int[] dMasterIndexFieldArray, out SIndex[] iParentMasterIndexFieldArray) { ArrayList oOutputArray; ec dRet = dGetSelect(sqlIsIndex(dEntity, iIdentifierParent), out oOutputArray, MASTER_INDEX_FIELD, MASTER_PARENT_INDEX_FIELD, MASTER_PARENT_SUB_INDEX_FIELD); dMasterIndexFieldArray = ToIntegerArray(oOutputArray, 0); iParentMasterIndexFieldArray = ToSIndexArray(oOutputArray, 1); return dRet; }*/ } ///------------------------------------------------------------------------------------------------------------------------- /// /// Summary description for CDbEntityNameTable /// ///------------------------------------------------------------------------------------------------------------------------- public class CDbIdentifierJoinView : CDbMultiJoinView { public CDbIdentifierJoinView(string strDatabaseName) : base(new CDbTableView(MASTER_PREF, new CDbIdentifierHeadTable(ATRIBUTE_INDEX_TABLE_NAME, strDatabaseName)), new CDbTableViewArray(SLAVE_PREF, ATRIBUTE_INDEX_TABLE_NAME + "_slave", SINDEX_ATT_TABLE +1, strDatabaseName)) { m_oSlaveViewArray.vAddColumn(MASTER_PARENT_INDEX_FIELD, INTEGER_TYPE, true); m_oSlaveViewArray.vAddColumn(MASTER_PARENT_SUB_INDEX_FIELD, INTEGER_TYPE, true); vAddLinkIndex(MASTER_PREF, MASTER_PARENT_INDEX_FIELD, SLAVE_PREF, MASTER_PARENT_INDEX_FIELD); vAddLinkIndex(MASTER_PREF, MASTER_PARENT_SUB_INDEX_FIELD, SLAVE_PREF, MASTER_PARENT_SUB_INDEX_FIELD); m_oSlaveViewArray.vAddColumn(ENTITY_CLASS_INDEX_FIELD, ENTITY_TYPE, true); GetSlaveTable(INT_ATT_TABLE).vAddColumn(ENTITY_INDEX_FIELD, ENTITY_TYPE, false); if (GetSlaveTable(INT_ATT_TABLE).dCreateTable() == ec.ST_SUCCEED) { GetSlaveTable(INT_ATT_TABLE).dCreateIndexMultipleField(2, ENTITY_CLASS_INDEX_FIELD, ENTITY_INDEX_FIELD); } GetSlaveTable(SINDEX_ATT_TABLE).vAddColumn(INDEX_FIELD, INTEGER_TYPE, false); GetSlaveTable(SINDEX_ATT_TABLE).vAddColumn(SUB_INDEX_FIELD, INTEGER_TYPE, false); if (GetSlaveTable(SINDEX_ATT_TABLE).dCreateTable() == ec.ST_SUCCEED) { GetSlaveTable(SINDEX_ATT_TABLE).dCreateIndexMultipleField(2, ENTITY_CLASS_INDEX_FIELD, INDEX_FIELD, SUB_INDEX_FIELD); } } public const int INT_ATT_TABLE = 0, SINDEX_ATT_TABLE=1; public const string MASTER_PREF="head", SLAVE_PREF="slave"; public CDbIdentifierHeadTable GetMasterTable { get { return (CDbIdentifierHeadTable)((CDbTableView)GetMasterView).oGetTable; } } public CDbSTable GetSlaveTable(int i) { return ((CDbTableView)GetSlaveView(i)).oGetTable; } public override string sDatabaseName { get { return GetMasterTable.sDatabaseName; } } public string sqlIsIndex(int dMasterIndex) { return GetMasterTable.sFieldEqual(MASTER_INDEX_FIELD, dMasterIndex); } public string sqlIsParentIndex(SIndex oParentIndex) { return GetMasterTable.sFieldEqual(MASTER_PARENT_INDEX_FIELD, oParentIndex.dIndex) + AND + GetMasterTable.sFieldEqual(MASTER_PARENT_SUB_INDEX_FIELD, oParentIndex.dSubIndex); } public ec dGetSelect(SIndex oParentIdentifierIndex, out CEntityArray oEntityArray) { ArrayList oEntityArrayList1, oEntityArrayList2; ec dRet = GetSlaveTable(INT_ATT_TABLE).dGetSelect( sqlIsParentIndex(oParentIdentifierIndex), out oEntityArrayList1, ENTITY_CLASS_INDEX_FIELD, ENTITY_INDEX_FIELD); dRet = GetSlaveTable(SINDEX_ATT_TABLE).dGetSelect( sqlIsParentIndex(oParentIdentifierIndex), out oEntityArrayList2, ENTITY_CLASS_INDEX_FIELD, INDEX_FIELD, SUB_INDEX_FIELD); oEntityArray = new CEntityArray(CEntityArray.FromClassAndPTypeToEntityArray(oEntityArrayList1), CEntityArray.FromClassAndSIndexToEntityArray(oEntityArrayList2)); return dRet; } public void vAddIdentifierQuery(SIndex iParentMemeIndex, P dEntity, CEntityArray oEntityArray) { vResetSelect(); if (IsUsed(iParentMemeIndex.dIndex)) { bAddWhere(MASTER_PREF, MASTER_PARENT_INDEX_FIELD, iParentMemeIndex.dIndex); } if (IsUsed(iParentMemeIndex.dSubIndex)) { bAddWhere(MASTER_PREF, MASTER_PARENT_INDEX_FIELD, iParentMemeIndex.dSubIndex); } if (IsUsed(dEntity)) { bAddWhere(MASTER_PREF, ENTITY_INDEX_FIELD, (int)dEntity); } bAddWhere(ALL_SLAVE_VIEW, oEntityArray); } public ec dGetSelect(int dMaxItemRetrieved, SIndex iParentMemeIndex, P dEntity, CEntityArray oEntityArray, out ArrayList oArrayOutput) { ec dRet; if (oEntityArray == null) { dRet = GetMasterTable.dGetSelect( GetMasterTable.sFieldEqual(ENTITY_INDEX_FIELD, dEntity), out oArrayOutput, MASTER_INDEX_FIELD, ENTITY_INDEX_FIELD, MASTER_PARENT_INDEX_FIELD, MASTER_PARENT_SUB_INDEX_FIELD); } else { vAddIdentifierQuery(iParentMemeIndex, dEntity, oEntityArray); bAddDisplayColumn(CDbIdentifierJoinView.MASTER_PREF, MASTER_INDEX_FIELD); bAddDisplayColumn(CDbIdentifierJoinView.MASTER_PREF, ENTITY_INDEX_FIELD); bAddDisplayColumn(CDbIdentifierJoinView.MASTER_PREF, MASTER_PARENT_INDEX_FIELD); bAddDisplayColumn(CDbIdentifierJoinView.MASTER_PREF, MASTER_PARENT_SUB_INDEX_FIELD); dRet = dGetSelect(dMaxItemRetrieved, out oArrayOutput); } return dRet; } public ec dGetSelect(int dMaxItemRetrieved, int dIdentifierIndex, CEntityArray oEntityArray, out SIndex[] oIdentifierSIndex) { ec dRet; bAddWhere(MASTER_PREF, MASTER_INDEX_FIELD, dIdentifierIndex); bAddDisplayColumn(CDbIdentifierJoinView.MASTER_PREF, MASTER_PARENT_INDEX_FIELD); bAddDisplayColumn(CDbIdentifierJoinView.MASTER_PREF, MASTER_PARENT_SUB_INDEX_FIELD); ArrayList oArrayOutput; dRet = dGetSelect(dMaxItemRetrieved, out oArrayOutput); oIdentifierSIndex = ToSIndexArray(oArrayOutput,0); return dRet; } public int dGetAttIndexTable(SEntity oEntity) { if (oEntity.bIsType(P.P_TYPE )|| oEntity.bIsType(P.INDEX_TYPE) ) { return INT_ATT_TABLE; } else if (oEntity.bIsType(P.SINDEX_TYPE)) { return SINDEX_ATT_TABLE; } return NOT_USED; } public ec dStoreValue(SIndex iIdentifier, SEntity oEntity) { CTrace.i().vWriteLn(ENMessage.Attribute, "iIdentifier= " + iIdentifier + " oEntity=" + oEntity); this.m_oSlaveViewArray.GetTable( dGetAttIndexTable(oEntity)).vAddValue(iIdentifier); this.m_oSlaveViewArray.GetTable( dGetAttIndexTable(oEntity)).vAddValue(oEntity); return m_oSlaveViewArray.GetTable(dGetAttIndexTable(oEntity)).dInsertIntoTable(); } /* public override bool bAddWhere( string sPrefixe, SEntity iValue) { string sSqlNotExist = GetSlaveTable.sFieldEqual(ENTITY_CLASS_INDEX_FIELD, (int)iValueArray.dClass); string sSql = " not exists(" + sSqlNotExist + ") "; string sSqlExactSql = "(" + GetSlaveTable.sFieldEqual(ENTITY_CLASS_INDEX_FIELD, (int)iValueArray.dClass) + AND + GetSlaveTable.sFieldEqual(ENTITY_INDEX_FIELD, (int)iValueArray.iInstance); return ((CDbTableView)GetSlaveView).bAddWhere(" not exists(" + "select " + sPrefixe + "." + ENTITY_CLASS_INDEX_FIELD + sSqlNotExist += this.sqlFrom + this.sqlGetIndexJoin(sPrefixe) + AND + sSqlNotExist + ") " + OR + sSqlExactSql); }*/ } ///------------------------------------------------------------------------------------------------------------------------- /// /// Summary description for CDbEntityNameTable /// ///------------------------------------------------------------------------------------------------------------------------- public class CDbIdentifierEquivalentTable : CDbSTable { public CDbIdentifierEquivalentTable(string strDatabaseName) : base("IdentifierEquivalentTable", strDatabaseName) { vAddColumn(IDENTIFIER_INDEX_FIELD, INTEGER_TYPE, true); vAddColumn(IDENTIFIER_REFERENCE_INDEX_FIELD, INTEGER_TYPE, false); } public ec dGetReference(int dIdentifierIndex, out int dIdentifierReferenceIndex) { ArrayList oOutputArray; ec dRet = dGetSelect(sFieldEqual(IDENTIFIER_REFERENCE_INDEX_FIELD, dIdentifierIndex), out oOutputArray, IDENTIFIER_INDEX_FIELD); if (oOutputArray== null) { dIdentifierReferenceIndex = dIdentifierIndex; } else { dIdentifierReferenceIndex = (int)oOutputArray[0]; } return dRet; } public ec dAddValue(int dIdentifierIndex, int dIdentifierReferenceIndex) { int dRootReference; dGetReference(dIdentifierReferenceIndex, out dRootReference); vAddValue(dIdentifierIndex); vAddValue(dRootReference); return dInsertIntoTable(); } } ///------------------------------------------------------------------------------------------------------------------------- /// /// Summary description for CDbEntityNameTable /// ///------------------------------------------------------------------------------------------------------------------------- public class CDbIdentifierView : CCommandFactoryBase { public CDbIdentifierView(P dLanguage, string strDatabaseName) { m_oIdentifierJoinView = new CDbIdentifierJoinView(strDatabaseName); m_dLanguage = dLanguage; m_oDbIdentifierEquivalentTable = new CDbIdentifierEquivalentTable(strDatabaseName); m_dLastEntityComputed = P.NOT_USED; } CDbIdentifierEquivalentTable m_oDbIdentifierEquivalentTable; P m_dLanguage; CDbIdentifierJoinView m_oIdentifierJoinView; public const int IDENTIFIER_ROOT_SUB_INDEX = 0; public SBIndex ToReferenceIndex(SIndex dIndex) { SBIndex iIndex; iIndex.dMainSIndex = dIndex; m_oDbIdentifierEquivalentTable.dGetReference(iIndex.dMainSIndex.dIndex, out iIndex.dReferenceIndex); return iIndex; } public SBIndex ToReferenceIndex(int dIndex) { return ToReferenceIndex(new SIndex(dIndex,NOT_USED) ); } public string sDatabaseName { get { return m_oIdentifierJoinView.sDatabaseName; } } public void vRegister() { SIndex dNewIdentifierIndex; dAddIndentifier(new CIdentifier(P.PROFILE_ATTRIBUTE), out dNewIdentifierIndex); dAddIndentifier(new CIdentifier(P.MEMBER_IN_ORGANISATION_ATTRIBUTE), out dNewIdentifierIndex); dAddIndentifier(new CIdentifier(P.MEMBER_IN_COMMITTEE_ATTRIBUTE), out dNewIdentifierIndex); dAddIndentifier(new CIdentifier(P.MEMBER_ATTRIBUTE), out dNewIdentifierIndex); } public CDbIdentifierHeadTable GetIdentifierHeadTable { get { return (CDbIdentifierHeadTable)(m_oIdentifierJoinView.GetMasterTable); } } public CDbSTable GetSlaveTable(int i) { return (CDbSTable)(m_oIdentifierJoinView.GetSlaveTable(i)); } public void vCleanAllData() { m_oIdentifierJoinView.vCleanAllData(); // m_oKeywordView.vCleanAllData(); m_oDbIdentifierEquivalentTable.dDropTable(); CDbEntityManager.Instance(m_oDbIdentifierEquivalentTable.sDatabaseName, m_dLanguage).vCleanAllData(); } public ec dAddKeyWordsToExistingIdentifier(CIdentifier dNewIdentifier, int dExistingIndex) { CIdentifier oExistingIdentifier; ec dRet = dGetSelect(dExistingIndex, out oExistingIdentifier); if (dRet == ec.ST_SUCCEED) { if (oExistingIdentifier == null) { return ec.ST_ENTITY_INDEX_DO_NOT_CORRESPOND_TO_ANY_IDENTIFIER; } else if (dNewIdentifier.dGetEntityArray(true) != null) { return ec.ST_ENTITY_CAN_NOT_LINK_TO_A_REFERENCE_IF_THE_IDENTIFIER_HAS_ATTRIBUTE; } else { SIndex dNewIdentifierIndex; dRet = dAddIndentifier(dNewIdentifier, out dNewIdentifierIndex); if (IsUsed(dNewIdentifierIndex)) { dRet = this.m_oDbIdentifierEquivalentTable.dAddValue(dNewIdentifierIndex.dIndex, dExistingIndex); } } } return dRet; } public ec dAddIndentifier(CIdentifier oIdentifier, out SIndex dIdentifierIndex) { CTrace.i().vWrite(ENMessage.Attribute, "dAddIndentifier oIdentifier:" + oIdentifier); dIdentifierIndex = NOT_USED_SINDEX; SIndex[] dIdentifierIndexArray; ec dRet = ec.ST_SUCCEED; dGet(2, true, oIdentifier, out dIdentifierIndexArray); if (dIdentifierIndexArray == null) { if (oIdentifier.ParentIdentifier == null) { CTrace.i().vWriteLn(ENMessage.Attribute, "dAddIndentifier oIdentifier.Entity:" + oIdentifier.Entity + "oIdentifier.dGetEntityArray(false):" + oIdentifier.dGetEntityArray(false)); dRet = dAddIndentifier(oIdentifier.Entity, ROOT_ENTITY_SINDEX, oIdentifier.dGetEntityArray(false), out dIdentifierIndex); } /* else if (IsUsed(oIdentifier.ParentIdentifier.dReferenceIndex)) { CTrace.i().vWriteLn(ENMessage.Attribute, "dAddIndentifier oIdentifier.Entity:" + oIdentifier.Entity + " oIdentifier.dGetEntityArray(false):" + oIdentifier.dGetEntityArray(false)); dRet = dAddIndentifier(oIdentifier.Entity, oIdentifier.ParentIdentifier.dReferenceIndex, oIdentifier.dGetEntityArray(false), out dIdentifierIndex); }*/ else { dRet = dGet(2, true, oIdentifier.ParentIdentifier, out dIdentifierIndexArray); if (dIdentifierIndexArray.Length > 1) { dRet = ec.ST_ENTITY_AMBIGUOUS_MORE_THAN_ONE_ENTITY_WITH_THIS_ROOT; } else if (dIdentifierIndexArray.Length == 0) { dRet= ec.ST_ENTITY_NO_ENTITY_WITH_THIS_ROOT; } else { CTrace.i().vWriteLn(ENMessage.Attribute, "dAddIndentifier oIdentifier.Entity:" + oIdentifier.Entity + " oIdentifier.ParentEntityArray:" + oIdentifier.ParentEntityArray); return dAddIndentifier(oIdentifier.Entity, dIdentifierIndexArray[0], oIdentifier.dGetEntityArray(false), out dIdentifierIndex); } } } return dRet; } public ec dConvert(CIdentifier oIdentifier, bool bHadVersion, out string sEntityKey) { sEntityKey = ""; ec dRet = ec.ST_SUCCEED; if (oIdentifier != null && IsNotUsed(oIdentifier.Entity)) { dRet = dGetSelect(oIdentifier.Index, out oIdentifier); } if (oIdentifier!= null) { dRet = dConvert(oIdentifier.ParentIdentifier, false, out sEntityKey); string sEntityKeyHead; dRet = CDbEntityManager.Instance(sDatabaseName, m_dLanguage).dConvertHead(oIdentifier, out sEntityKeyHead); if (sEntityKey != "") { sEntityKey += IDENTIFIER_CHILD_SEPARATOR; } sEntityKey += sEntityKeyHead; if (bHadVersion && IsUsed( oIdentifier.Index.dSubIndex)) { sEntityKey += IDENTIFIER_MEME_SEPARATOR + oIdentifier.Index.dSubIndex.ToString(); } } return dRet; } public ec dCreateIdentifier(P dAttributeClass, P[] dCategoryIDArray, string sAttributeNameInEnglish, CIdentifier oIdentifierParent, P dLanguage, out CIdentifier oIdentifier) { P dEntityItem; ec dRC; if (dCategoryIDArray == null || dCategoryIDArray.Length== 0) { dRC = dAddAttributeKeyword(dAttributeClass, dLanguage, sAttributeNameInEnglish, out dEntityItem); } else { dRC = dAddAttributeKeyword(dCategoryIDArray[dCategoryIDArray.Length-1], dLanguage, sAttributeNameInEnglish, out dEntityItem); } if (IsUsed(dEntityItem)) { dRC = dGetChildIdentifier(dAdd(dCategoryIDArray, dEntityItem), oIdentifierParent, out oIdentifier); } else { oIdentifier = null; } return dRC; } public ec dCreateAttributeIdentifier(P dAttribute, CCommandLine oCommandLine, out CIdentifier oIdentifier) { P[] oParameter; CEntityManager.Instance( P.ENGLISH).dGetArray(dAttribute, HAS_MANDATORY_PARAMETER_RELATION, out oParameter); CEntityArray ea; oIdentifier = null; ec dRet = oCommandLine.dExtract(oParameter, out ea); if (dRet == ec.ST_SUCCEED) { oIdentifier = new CIdentifier(dAttribute, null, ea); SIndex dIdentifierIndex; dRet = dAddIndentifier(oIdentifier, out dIdentifierIndex); if (dRet == ec.ST_SUCCEED || dRet == ec.ST_ENTITY_IDENTIFIER_ALREADY_INSERTED) { oIdentifier.Index = dIdentifierIndex; } CTrace.i().vWrite(ENMessage.Attribute, "dCreateAttributeIdentifier dAttribute:" + dAttribute + "Parameter=" + ToString(oParameter) + " ea= " + ea + " oIdentifier= " + oIdentifier != null ? oIdentifier.csDump() : "null"); } return dRet; } /* public ec dGetOrganisationAttributeIdentifier(int dProfileIndex, SIndex oOrganisationIndex, out CIdentifier oIdentifier) { CEntityArray ea = new CEntityArray(P.PROFILE_INDEX_TYPE, dProfileIndex); ea.vAppend(new SEntity(P.ORGANISATION_INDEX_TYPE, oOrganisationIndex.dIndex)); oIdentifier = new CIdentifier(P.MEMBER_IN_ORGANISATION_ATTRIBUTE, null, ea); int dIdentifierIndex; ec dRet = dAddIndentifier(oIdentifier, out dIdentifierIndex); CTrace.i().vWrite(ENMessage.Attribute, "dGetProfileAttributeIdentifier dProfileIndex=" + dProfileIndex + " oOrganisationIndex = " + oOrganisationIndex + " oIdentifier= " + oIdentifier != null ? oIdentifier.csDump() : "null"); if (dRet == ec.ST_SUCCEED) { oIdentifier.dIndex = dIdentifierIndex; } else { oIdentifier = null; } return dRet; } */ public ec dAddAttributeKeyword(P dParentID, P dLanguage, string sAttributeName, out P dIndex) { CTrace.i().vWrite(ENMessage.Attribute, "dAddAttributeKeyword=" + dParentID + " sAttributeName= " + sAttributeName); ec dRet = ec.ST_SUCCEED; dIndex = P.NOT_USED; dRet = CDbEntityManager.Instance(sDatabaseName, m_dLanguage).GetKeywordView.dAdd(P.ATTRIBUTE, P.ATTRIBUTE, dParentID, dLanguage, sAttributeName, null, out dIndex); CEntityManager.Instance(m_dLanguage).vSetName(dIndex, sAttributeName, dLanguage); CEntityManager.Instance(m_dLanguage).vSetClass(dIndex, P.ATTRIBUTE); CEntityManager.Instance(m_dLanguage).vSetParent(dIndex, P.ATTRIBUTE); CEntityManager.Instance(m_dLanguage).vSetIdParent(dIndex, dParentID); CTrace.i().vWriteLn(ENMessage.Attribute, dIndex + ":" + CEntityManager.Instance(m_dLanguage).FindEntityName(dIndex).csDump()); CTrace.i().vWriteLn(ENMessage.Attribute, " dIndex = " + dIndex); return dRet; } public bool bIsADescentOf(CIdentifier oIdentifier, P dEntity) { if ( oIdentifier== null) { return CEntityManager.Instance(P.ENGLISH).dGetClass(dEntity) == P.ENTITY_ROOT; } else { return CEntityManager.Instance(P.ENGLISH).bIsADescentOf(dEntity, oIdentifier.Entity); } } public ec dGetChildIdentifier(P[] dEntityArray, CIdentifier oParentIdentifier, out CIdentifier oIdentifier) { CTrace.i().vWriteLn(ENMessage.Attribute, "dGetChildIdentifier=" + ToString(dEntityArray) + " oParentIdentifier=" + (oParentIdentifier!=null? oParentIdentifier.csDump() : "null") ); oIdentifier = null; ec dRet = ec.ST_SUCCEED; if (CEntityManager.Instance(P.ENGLISH).bIsParentIDHierarchy(dEntityArray)) { if (bIsADescentOf(oParentIdentifier, dEntityArray[0])) { for (int i = 0; i < dEntityArray.Length; i++) { oIdentifier = new CIdentifier(dEntityArray[i], oParentIdentifier); SIndex[] dIdentifierIndexArray; dRet = dGet(2, true, oIdentifier, out dIdentifierIndexArray); if (dIdentifierIndexArray != null && dIdentifierIndexArray.Length == 1) { oIdentifier.Index = dIdentifierIndexArray[0]; } else { SIndex dIdentifierIndex; this.dAddIndentifier(oIdentifier, out dIdentifierIndex); oIdentifier.Index = dIdentifierIndex; dRet= ec.ST_SUCCEED; } oParentIdentifier = oIdentifier; } } else { oIdentifier = null; dRet = ec.ST_ENTITY_THE_LIST_OF_DESCENT_DO_NOT_INCLUDE_ID_DESCENT_WITH_PARENT; } } else { oIdentifier = null; dRet= ec.ST_ENTITY_THE_LIST_OF_DESCENT_DO_NOT_INCLUDE_ID_DESCENT; } return dRet; } protected ec dAddIndentifier(P dEntity, SIndex iRootIdentifierIndex, CEntityArray eEntityArray, out SIndex iIdentifierIndex) { CTrace.i().vWriteLn(ENMessage.Attribute, "dEntity=" + dEntity + " iRootIdentifierIndex= " + iRootIdentifierIndex + "EntityArray=" + eEntityArray); CIdentifier[] oIdentifierArray; iIdentifierIndex = NOT_USED_SINDEX; dGetSelect(2, iRootIdentifierIndex, dEntity, eEntityArray, out oIdentifierArray); ec dRet = ec.ST_SUCCEED; if (oIdentifierArray == null) { dRet = GetIdentifierHeadTable.dStoreIdentifier(dEntity, iRootIdentifierIndex, out iIdentifierIndex.dIndex); iIdentifierIndex.dSubIndex = m_oIdentifierJoinView.GetSlaveArrayView.dGetNext(MASTER_PARENT_SUB_INDEX_FIELD, m_oIdentifierJoinView.GetSlaveArrayView.GetTable(0).sFieldEqual(MASTER_PARENT_INDEX_FIELD, iIdentifierIndex.dIndex)); CTrace.i().vWriteLn(ENMessage.Attribute, " iIdentifierIndex= " + iIdentifierIndex); if (eEntityArray != null) { for (int i = 0; i < eEntityArray.Length; i++) { if (IsUsed(eEntityArray[i])) { if (m_oIdentifierJoinView.dStoreValue(iIdentifierIndex, eEntityArray[i]) != ec.ST_SUCCEED) { dRet = ec.ST_ATTRIBUTE_CAN_NOT_INSERT_THE_ATTRIBUTE_NEW_ATTRIBUTE; } } } } } else { iIdentifierIndex = oIdentifierArray[0].Index; dRet = ec.ST_ENTITY_IDENTIFIER_ALREADY_INSERTED; } return dRet; } public ec dGetRecordCount(SIndex iParentMemeIndex, P dEntity, CEntityArray dEntityArray, out int dCount) { if (dEntityArray == null) { string sWhere = m_oIdentifierJoinView.GetMasterTable.sFieldEqual(ENTITY_INDEX_FIELD, dEntity); if (IsUsed(iParentMemeIndex.dIndex)) { sWhere += AND + m_oIdentifierJoinView.GetMasterTable.sFieldEqual(MASTER_PARENT_INDEX_FIELD, iParentMemeIndex.dIndex); if (IsUsed(iParentMemeIndex.dSubIndex)) { sWhere += AND + m_oIdentifierJoinView.GetMasterTable.sFieldEqual(MASTER_PARENT_SUB_INDEX_FIELD, iParentMemeIndex.dSubIndex); } } return m_oIdentifierJoinView.GetMasterTable.dGetRecordCount(sWhere, out dCount); } else { m_oIdentifierJoinView.vAddIdentifierQuery(iParentMemeIndex, dEntity, dEntityArray); return m_oIdentifierJoinView.dGetRecordCount(m_oIdentifierJoinView.sqlCount(), out dCount); } } public ec dGetSelect(int dMaxItemRetrieved, SIndex iParentIdentifierIndex, P dEntity, CEntityArray dParentEntityArray, out CIdentifier[] oIdentifierArray) { ArrayList oArrayOutput; ec dRet = ec.ST_SUCCEED; dRet = m_oIdentifierJoinView.dGetSelect(dMaxItemRetrieved, iParentIdentifierIndex, dEntity, dParentEntityArray, out oArrayOutput); CTrace.i().vWriteLn(ENMessage.Attribute, "dGetSelect iParentMemeIndex =" + iParentIdentifierIndex + "ent=" + dEntity + " dParentEntityArray=" + (dParentEntityArray != null ? dParentEntityArray.ToString() : "null")); if (oArrayOutput != null && oArrayOutput.Count > 0) { oIdentifierArray = new CIdentifier[oArrayOutput.Count]; for (int i = 0; i < oArrayOutput.Count; i++) { object[] oLineArray = (object[])oArrayOutput[i]; oIdentifierArray[i] = new CIdentifier((int)oLineArray[1]); oIdentifierArray[i].Index = new SIndex(Convert.ToInt32(oLineArray[0]), NOT_USED); SIndex iParentNewIdentifierIndex; iParentNewIdentifierIndex.dIndex = Convert.ToInt32(oLineArray[2]); iParentNewIdentifierIndex.dSubIndex = Convert.ToInt32(oLineArray[3]); oIdentifierArray[i].vSetParentIndentifierPrincipalIndex(iParentNewIdentifierIndex); CEntityArray oEntityArray=null; dRet = m_oIdentifierJoinView.dGetSelect(iParentNewIdentifierIndex, out oEntityArray); oIdentifierArray[i].vSetEntityArray(oEntityArray); int dReferenceIndex; dRet = m_oDbIdentifierEquivalentTable.dGetReference(oIdentifierArray[i].Index.dIndex, out dReferenceIndex); oIdentifierArray[i].dReferenceIndex = dReferenceIndex; CTrace.i().vWriteLn(ENMessage.Attribute, "oIdentifierArray[i]=" + oIdentifierArray[i].csDump() ); } } else { oIdentifierArray = null; } return dRet; } /* public ec dGetSelect(SIndex oParentIdentifierIndex, out CEntityArray oEntityArray) { ArrayList oEntityArrayList; ec dRet = m_oIdentifierJoinView.GetSlaveTable.dGetSelect( m_oIdentifierJoinView.sqlIsParentIndex(oParentIdentifierIndex), out oEntityArrayList, ENTITY_CLASS_INDEX_FIELD, ENTITY_INDEX_FIELD); if (oEntityArrayList == null) { oEntityArray = null; } else { oEntityArray = new CEntityArray(oEntityArrayList); } return dRet; }*/ public ec dGetSelect(int dIdentifierIndex, out CIdentifier oIndentifier) { return dGetSelect(new SIndex(dIdentifierIndex, NOT_USED), out oIndentifier); } public ec dGetSelect(SIndex dIdentifierIndex, out CIdentifier oIndentifier) { CTrace.i().vWrite(ENMessage.Attribute, "dGetSelect dIdentifierIndex=" + dIdentifierIndex); oIndentifier = null; ec dRC = ec.ST_SUCCEED; if (dIdentifierIndex.dIndex > ROOT_ENTITY_SINDEX.dIndex) { ArrayList oEntityArrayList = new ArrayList(); ArrayList oOutputArray; dRC = GetIdentifierHeadTable.dGetSelect(GetIdentifierHeadTable.sqlIsIndex(dIdentifierIndex.dIndex), out oOutputArray, ENTITY_INDEX_FIELD, MASTER_PARENT_INDEX_FIELD, MASTER_PARENT_SUB_INDEX_FIELD); if (oOutputArray.Count >= 1) { object[] oColumns = (object[])oOutputArray[0]; P dEntity = (P)oColumns[0]; SIndex oParentIndex; oParentIndex.dIndex = (int)oColumns[1]; oParentIndex.dSubIndex = (int)oColumns[2]; CEntityArray oEntityArray=null; if (IsUsed(dIdentifierIndex.dSubIndex)) { dRC = m_oIdentifierJoinView.dGetSelect(dIdentifierIndex, out oEntityArray); CTrace.i().vWrite(ENMessage.Attribute, "oEntityArray=" + oEntityArray); } oIndentifier = new CIdentifier(dEntity, new CIdentifier(new SBIndex(oParentIndex)), oEntityArray); oIndentifier.Index = dIdentifierIndex; CTrace.i().vWrite(ENMessage.Attribute, "oIndentifier=" + oIndentifier ); } } return dRC; } /* public ec dGet(int dMaxItem, bool bExactMatch, CIdentifier oIdentifier, out int[] oMasterIndexFieldArray) { SIndex[] oMasterSIndexFieldArray; ec dRet = dGet(dMaxItem, bExactMatch, oIdentifier, out oMasterSIndexFieldArray); oMasterIndexFieldArray = ToIndex(oMasterSIndexFieldArray); return dRet; }*/ public ec dGet(int dMaxItem, bool bExactMatch, CIdentifier oIdentifier, out SIndex[] oMasterSIndexFieldArray) { CTrace.i().vWrite(ENMessage.Attribute, "dGet dMaxItem=" + dMaxItem + " bExactMatch= " + bExactMatch + " oIdentifier = " + (oIdentifier != null ? oIdentifier.csDump() : null) + "| " ); ec dRet = ec.ST_SUCCEED; oMasterSIndexFieldArray = null; m_dLastEntityComputed = P.NOT_USED; if (IsUsed(oIdentifier.iIndex)) { oMasterSIndexFieldArray = new SIndex[1]; oMasterSIndexFieldArray[0] = oIdentifier.Index; } else { //SIndex[] iMasterParentIndexFieldArray; if (oIdentifier.ParentIdentifier == null) { // int[] dMasterParentIndexFieldArray; m_dLastEntityComputed = oIdentifier.Entity; int[] oMasterIndexFieldArray; dRet = m_oIdentifierJoinView.GetMasterTable.dGetSelect(oIdentifier.Entity, NOT_USED_SINDEX, out oMasterIndexFieldArray); if (oMasterIndexFieldArray == null || oMasterIndexFieldArray.Length == 0) { dRet= ec.ST_ENTITY_NO_ENTITY_WITH_THIS_ROOT; } else if (oMasterIndexFieldArray.Length > 1) { dRet= ec.ST_ENTITY_AMBIGUOUS_MORE_THAN_ONE_ENTITY_WITH_THIS_ROOT; } else { dRet= ec.ST_SUCCEED; } } else { SIndex[] oParentMasterIndexSFieldArray; dRet = dGet(dMaxItem, bExactMatch, oIdentifier.ParentIdentifier, out oParentMasterIndexSFieldArray); if (dRet == ec.ST_SUCCEED && oParentMasterIndexSFieldArray != null) { for (int i = 0; i < oParentMasterIndexSFieldArray.Length; i++) { SIndex[] oSIndexOutputArray; CEntityArray oEntityArray = oIdentifier.dGetEntityArray(bExactMatch); m_dLastEntityComputed = oIdentifier.Entity; dRet = m_oIdentifierJoinView.dGetSelect(dMaxItem, oParentMasterIndexSFieldArray[0].dIndex, oEntityArray, out oSIndexOutputArray); oMasterSIndexFieldArray = oConcat(oMasterSIndexFieldArray, oSIndexOutputArray); } } } } CTrace.i().vWriteLn(ENMessage.Attribute, " m_dLastEntityComputed=" + m_dLastEntityComputed); if (oMasterSIndexFieldArray != null && oMasterSIndexFieldArray.Length == 0) { oMasterSIndexFieldArray = null; } return dRet; } public P m_dLastEntityComputed; } //---------------------------------------------------------------------------------------------------------------------------------------------- /// /// Summary description for DbVariableTable. /// /// //---------------------------------------------------------------------------------------------------------------------------------------------- public class CDbMemeView : CDbConnectionBase { public CDbMemeView( string strDatabaseName) : base() { m_oAttributeInstanceTable = new CDbTreeTable(MEME_TABLE_NAME, strDatabaseName); m_oAttributeInstanceTable.vAddColumn(ATTRIBUTE_TYPE_FIELD, INTEGER_TYPE, false); if (m_oAttributeInstanceTable.dCreateTable() == ec.ST_SUCCEED) { m_oAttributeInstanceTable.dCreateIndexMultipleField(2, ATTRIBUTE_TYPE_FIELD); } m_oString255AttributeView = new CDbJoinOnSIndexView(ATTRIBUTE_INDEX_PREFIXE, m_oAttributeInstanceTable, STRING255_PREFIXE, MEME_TABLE_NAME + STRING255_PREFIXE); m_oString255AttributeView.oGetSlaveTable.vAddColumn(VALUE_FIELD, STRING_255_TYPE, false); m_oString4000AttributeView = new CDbJoinOnSIndexWithBackupView(ATTRIBUTE_INDEX_PREFIXE, m_oAttributeInstanceTable, STRING4000_PREFIXE, MEME_TABLE_NAME + STRING4000_PREFIXE); m_oString4000AttributeView.oGetSlaveTable.vAddColumn(VALUE_FIELD, STRING_4000_TYPE, false); m_oTitleAndTextAttributeView = new CDbJoinOnSIndexWithBackupView(ATTRIBUTE_INDEX_PREFIXE, m_oAttributeInstanceTable, TITLE_AND_TEXT_PREFIXE, MEME_TABLE_NAME + TITLE_AND_TEXT_PREFIXE); m_oTitleAndTextAttributeView.oGetSlaveTable.vAddColumn(TITLE_FIELD, STRING_255_TYPE, false); m_oTitleAndTextAttributeView.oGetSlaveTable.vAddColumn(VALUE_FIELD, STRING_4000_TYPE, false); m_oIntegerAttributeView = new CDbJoinOnSIndexView(ATTRIBUTE_INDEX_PREFIXE, m_oAttributeInstanceTable, INTERGER_PREFIXE, MEME_TABLE_NAME + INTERGER_PREFIXE); m_oIntegerAttributeView.oGetSlaveTable.vAddColumn(VALUE_FIELD, INTEGER_TYPE, false); } public override string sDatabaseName { get { return m_oAttributeInstanceTable.sDatabaseName; } } public const string STRING255_PREFIXE = "s255"; public const string STRING4000_PREFIXE = "s4000"; public const string INTERGER_PREFIXE = "int"; public const string TITLE_AND_TEXT_PREFIXE = "title_text"; protected CDbJoinOnSIndexView m_oString255AttributeView, m_oIntegerAttributeView; //, m_oCriticTypeAttributeView; protected CDbJoinOnSIndexWithBackupView m_oString4000AttributeView, m_oTitleAndTextAttributeView; protected CDbTreeTable m_oAttributeInstanceTable; public virtual void vCleanAllData() { m_oAttributeInstanceTable.dDropTable(); m_oString255AttributeView.vCleanAllData(); m_oIntegerAttributeView.vCleanAllData(); m_oString4000AttributeView.vCleanAllData(); m_oTitleAndTextAttributeView.vCleanAllData(); } public ec dAddNewAttributeVersion(int dMemeIndex, P dAttributeType, object oValue, out SIndex oMeme) { oMeme = m_oAttributeInstanceTable.dGetNewSubProfileIndexValues(dMemeIndex); return dAddAttribute(oMeme, dAttributeType, oValue); } public ec dAddAttribute(SIndex oMeme, P dAttributeType, object oValue) { if (dAttributeType == P.STRING_TYPE) { if (oValue.ToString().Length <= 255) { dAttributeType = P.STRING_255_TYPE; } } m_oAttributeInstanceTable.dAddIndexValues(oMeme, NOT_USED); m_oAttributeInstanceTable.vAddValue(dAttributeType); ec dRC = m_oAttributeInstanceTable.dInsertIntoTable(); if ( dRC== ec.ST_SUCCEED) { CDbJoinOnSIndexView oView = oGetView(dAttributeType); if (oView == null) { EPAssert(false, "Unknow attribute type = " + dAttributeType); return ec.ST_ATTRIBUTE_THIS_ATTRIBUTE_TYPE_IS_UNKNOWN; } else { dRC = oView.dAddAttribute(oMeme, dAttributeType, oValue); } } return dRC; } public ec dUpdateAttribute(SIndex oIndex, object oValue) { P dAttributeType = (P)m_oAttributeInstanceTable.GetInteger(ATTRIBUTE_TYPE_FIELD, m_oAttributeInstanceTable.sqlIsIndex(oIndex)); if (IsNotUsed(dAttributeType)) { return ec.ST_ATTRIBUTE_THIS_ATTRIBUTE_NAME_IS_UNKNOWN; } ec dRC = ec.ST_SUCCEED; CDbJoinOnSIndexView oView = oGetView(dAttributeType); if (oView == null) { EPAssert(false, "Not in Attribute table = " + dAttributeType); return ec.ST_ATTRIBUTE_THIS_ATTRIBUTE_NAME_IS_UNKNOWN; } else { oView.vResetDate(oIndex); dRC = oView.dUpdate(oIndex, VALUE_FIELD, oValue); } return dRC; } public ec dGetAttribute(SIndex oIndex, out CMeme oMeme) { P dAttributeType = (P)m_oAttributeInstanceTable.GetInteger(ATTRIBUTE_TYPE_FIELD, m_oAttributeInstanceTable.sqlIsIndex(oIndex)); ec dRC = ec.ST_SUCCEED; CDbJoinOnSIndexView oView = oGetView(dAttributeType); oMeme = null; if (IsNotUsed(dAttributeType)) { return ec.ST_ATTRIBUTE_THIS_ATTRIBUTE_NAME_IS_UNKNOWN; } if (oView == null) { EPAssert(false, "Not in Attribute table = " + dAttributeType); return ec.ST_ATTRIBUTE_THIS_ATTRIBUTE_NAME_IS_UNKNOWN; } else { ArrayList oOutputArray; dRC = oView.dGetSelect(oIndex, out oOutputArray, null, sGetParameters(VALUE_FIELD) ); if (oOutputArray.Count >= 1) { /* int dAuthorIndex; dRC = dGetAuthorship(oIndex, out dAuthorIndex); if ( dRC == ec.ST_SUCCEED) { */ object[] oObjectArray= (object[])oOutputArray[0]; oMeme = new CMeme(Convert.ToString(oObjectArray[0]), dAttributeType, oIndex); // } } } return dRC; } public CDbJoinOnSIndexView oGetView(P dAttributeType) { if (dAttributeType == P.INTEGER_TYPE) { return m_oIntegerAttributeView; } else if (dAttributeType == P.STRING_255_TYPE) { return m_oString255AttributeView; } else if (dAttributeType == P.STRING_4000_TYPE) { return m_oString4000AttributeView; } else if (dAttributeType == P.TITLE_AND_TEXT_TYPE) { return m_oTitleAndTextAttributeView; } return null; } } //---------------------------------------------------------------------------------------------------------------------------------------------- /// /// Summary description for DbVariableTable. /// /// //---------------------------------------------------------------------------------------------------------------------------------------------- public class CDbMasterTable : CDbTreeTable { public CDbMasterTable(string strTableName, string strDatabaseName) : base(strTableName, strDatabaseName) { vAddColumn(MASTER_NAME_FIELD, "String 50", false); } public ec dRename(SIndex oProfileIndex, string sNewName) { ec dRet = dUpdate(MASTER_NAME_FIELD, sNewName, sqlIsIndex(oProfileIndex)); return dRet== ec.ST_SUCCEED ? ec.ST_SUCCEED : ec.ST_PROFILE_CAN_NOT_RENAME_THE_AVATAR; } public SIndex dAddNewSubProfile(string sProfileID, SIndex oParentIndex) { SIndex oNewIndex = dAddNewSubProfileIndexValues(oParentIndex ); vAddValue(sProfileID); return oNewIndex; } public string sGetName(SIndex oIndex) { if (IsNotUsed(oIndex)) return "unknown"; string strUserId = GetString(MASTER_NAME_FIELD, sqlIsIndex(oIndex)); /* if (strUserId == null || strUserId == "") { SIndex oNewIndex = oIndex; oNewIndex.dSubIndex = 0; return GetString(MASTER_NAME_FIELD, sqlIsIndex(oNewIndex)) + "." + oNewIndex.dSubIndex; }*/ return strUserId; } public override ec dCreateIndex() { // if (m_bIsTableExist== false) return ec.ST_SQL_INDEX_ALREADY_EXIST; dCreateIndex(2, MASTER_NAME_FIELD); return base.dCreatePrimaryIndex(); } } //---------------------------------------------------------------------------------------------------------------------------------------------- /// /// Summary description for DbVariableView. /// //---------------------------------------------------------------------------------------------------------------------------------------------- public class CDbSIndexTable : CDbSTable { public CDbSIndexTable(string strTableName, string strDatabaseName) : base(strTableName, strDatabaseName) { vAddColumn(MASTER_INDEX_FIELD, INTEGER_TYPE, true); vAddColumn(MASTER_SUB_INDEX_FIELD, INTEGER_TYPE, true); vAddColumn(DATE_FIELD, DATE_TYPE, false); } public void vPutIndexColumnsTo(CDbSTable oTable) { oTable.vAddColumn(MASTER_INDEX_FIELD, INTEGER_TYPE, true); oTable.vAddColumn(MASTER_SUB_INDEX_FIELD, INTEGER_TYPE, true); } public SIndex dAddProfileIndexValues(CDbSTable oTable, SIndex oMainIndex) { oTable.vAddValue(oMainIndex.dIndex); oTable.vAddValue(oMainIndex.dSubIndex); return oMainIndex; } public virtual ec dDelete(SIndex oProfileIndex) { ec dRet = base.dDelete(sqlIsIndex(oProfileIndex)); return dRet == ec.ST_SUCCEED ? ec.ST_SUCCEED : ec.ST_DB_CAN_NOT_DELETE_THE_SINDEX_KEY; } public int dGetNewProfileIndexValues() { int dIndex = Convert.ToInt32(GetMax(MASTER_INDEX_FIELD, null)); if (IsNotUsed(dIndex)) dIndex = 0; return ++dIndex; } public SIndex dGetNewSubProfileIndexValues(int dMemeIndex) { SIndex oIndex; oIndex.dIndex = dMemeIndex; oIndex.dSubIndex = Convert.ToInt32(GetMax(MASTER_SUB_INDEX_FIELD, sqlIsIndex(oIndex.dIndex))); if (oIndex.dSubIndex < 0) { oIndex.dSubIndex = 0; } else { oIndex.dSubIndex++; } return oIndex; } public virtual SIndex dAddIndexValues(SIndex oIndex) { vAddValue(oIndex.dIndex); vAddValue(oIndex.dSubIndex); vAddValue(DateTime.UtcNow); return oIndex; } public virtual SIndex dAddNewSubProfileIndexValues(int dMemeIndex) { return dAddIndexValues(dGetNewSubProfileIndexValues(dMemeIndex)); } public string sqlIsIndex(int dProfileIndex) { if (IsNotUsed(dProfileIndex)) { return ""; } return sFieldEqual(MASTER_INDEX_FIELD, dProfileIndex); } public string sqlIsIndex(SIndex oIndex) { if (IsNotUsed(oIndex)) { return ""; } return sFieldEqual(MASTER_INDEX_FIELD, oIndex.dIndex) +AND + sFieldEqual(MASTER_SUB_INDEX_FIELD, oIndex.dSubIndex); } public int dGetInteger(string strValueColumn, SIndex oProfileIndex) { string sValue = GetString(strValueColumn, m_strTableName, this.sqlIsIndex(oProfileIndex)); if (sValue == null) return NOT_USED; return Convert.ToInt32(sValue); } } //---------------------------------------------------------------------------------------------------------------------------------------------- /// /// Summary description for DbVariableView. /// //---------------------------------------------------------------------------------------------------------------------------------------------- public class CDbTreeTable : CDbSIndexTable { public CDbTreeTable(string strTableName, string strDatabaseName) : base(strTableName, strDatabaseName) { vAddColumn(MASTER_PARENT_SUB_INDEX_FIELD, INTEGER_TYPE, false); } public override ec dDelete(SIndex oProfileIndex) { CSubIndexArray oSubIndexArray = new CSubIndexArray(); ec dRet = dGetChildSubIndex(oProfileIndex, ref oSubIndexArray); if (dRet != ec.ST_SUCCEED) return dRet; if (oSubIndexArray.dGetCountWithout(oProfileIndex) > 0) { return ec.ST_DB_TREE_CAN_NOT_DELETE_IF_THERE_IS_CHILD_KEY; } return base.dDelete( oProfileIndex); } public SIndex dAddProfileIndexValues(int dInitialSubIndex, int dParentSubIndex) { return dAddIndexValues(new SIndex(dGetNewProfileIndexValues(), dInitialSubIndex), dParentSubIndex); } public SIndex dGetIndex(string sUserID) { ArrayList oIndexArray; if (dGetSelect(sFieldEqual(MASTER_NAME_FIELD, sUserID), out oIndexArray, MASTER_INDEX_FIELD, MASTER_SUB_INDEX_FIELD) == ec.ST_SUCCEED && oIndexArray != null && oIndexArray.Count > 0) { SIndex oIndex; oIndex.dIndex = (int)((object[])oIndexArray[0])[0]; oIndex.dSubIndex = (int)((object[])oIndexArray[0])[1]; return oIndex; } return NOT_USED_SINDEX; } public SIndex dAddNewSubProfileIndexValues(SIndex oMemeIndex) { return dAddIndexValues(dGetNewSubProfileIndexValues(oMemeIndex.dIndex), oMemeIndex.dSubIndex); } public SIndex dAddIndexValues(SIndex oIndex, int dParentSubIndex) { base.dAddIndexValues(oIndex); vAddValue(dParentSubIndex); return oIndex; } public SIndex dGetParentSubIndex(SIndex oIndex) { SIndex oParentSubIndex = oIndex; oParentSubIndex.dSubIndex = GetInteger(MASTER_PARENT_SUB_INDEX_FIELD, sqlIsIndex(oIndex)); return oParentSubIndex; } public bool bIsChildOf(SIndex oChildIndex, SIndex iParentSubIndex) { SIndex[] iParentSubIndexArray = new SIndex[1]; iParentSubIndexArray[0] = iParentSubIndex; return bIsChildOf(oChildIndex, iParentSubIndexArray); } public bool bIsChildOf(SIndex oChildIndex, SIndex[] iParentSubIndexArray) { if (iParentSubIndexArray == null) { return false; } SIndex oParent; return bIsChildOf(oChildIndex, iParentSubIndexArray, out oParent); } public bool bIsChildOf(SIndex oChildIndex, SIndex[] iParentSubIndexArray, out SIndex oParent) { CSubIndexArray oSubIndexArray = new CSubIndexArray(); ec dRC = dGetAllSubIndex(oChildIndex, ref oSubIndexArray); if (dRC== ec.ST_SUCCEED) { for (int i = 0; i < iParentSubIndexArray.Length; i++) { if (oSubIndexArray.bIsChildOf(oChildIndex.dSubIndex, iParentSubIndexArray[i].dSubIndex)) { oParent = iParentSubIndexArray[i]; return true; } } } oParent = NOT_USED_SINDEX; return false; } ec dGetChildSubIndex(SIndex oProfileIndex, ref CSubIndexArray oSubIndexArray) { ArrayList oSubIndexArrayList; ec dRC = ec.ST_SUCCEED; dRC = dGetSelect(sqlIsIndex(oProfileIndex.dIndex) + AND + sFieldEqual(MASTER_PARENT_SUB_INDEX_FIELD, oProfileIndex.dSubIndex), out oSubIndexArrayList, oSubIndexArray.ParameterArray); if (dRC != ec.ST_SUCCEED) { oSubIndexArray = null; return ec.ST_PROFILE_CAN_GET_SUB_AVATAR; } oSubIndexArray.vLoad(oSubIndexArrayList); return ec.ST_SUCCEED; } public ec dGetAllSubIndex(SIndex oProfileIndex, ref CSubIndexArray oSubIndexArray) { ArrayList oSubIndexArrayList; ec dRC = ec.ST_SUCCEED; dRC = dGetSelect( sFieldEqual(MASTER_INDEX_FIELD, oProfileIndex.dIndex), out oSubIndexArrayList, oSubIndexArray.ParameterArray); if (dRC != ec.ST_SUCCEED) { oSubIndexArray = null; return ec.ST_PROFILE_CAN_GET_SUB_AVATAR; } oSubIndexArray.vLoad(oSubIndexArrayList); return dRC; } public ec dGetSubIndex(SIndex oProfileIndex, bool bRecursive, ref CSubIndexArray oSubIndexArray) { if (bRecursive == false) { return dGetChildSubIndex(oProfileIndex, ref oSubIndexArray); } ArrayList oSubIndexArrayList; ec dRC = ec.ST_SUCCEED; dRC = dGetSelect(sqlIsIndex(oProfileIndex.dIndex), out oSubIndexArrayList, oSubIndexArray.ParameterArray); if (dRC != ec.ST_SUCCEED) { oSubIndexArray = null; return ec.ST_PROFILE_CAN_GET_SUB_AVATAR; } oSubIndexArray.vLoad(oSubIndexArrayList); CTrace.i().vWriteLn(ENMessage.Report, oSubIndexArray.csDump()); if (oProfileIndex.dSubIndex > 0) { oSubIndexArray = oSubIndexArray.oGetChild(oProfileIndex.dSubIndex, bRecursive); CTrace.i().vWriteLn(ENMessage.Report, oSubIndexArray.csDump()); } return dRC; } } //---------------------------------------------------------------------------------------------------------------------------------------------- /// /// Summary description for DbVariableTable. /// /// //---------------------------------------------------------------------------------------------------------------------------------------------- public class CSubIndexArray : CDbEPBase { public CSubIndexArray(string[] sParameterArray) { m_sParameterArray = sConcatParameterArray(sGetParameters(MASTER_SUB_INDEX_FIELD, MASTER_PARENT_SUB_INDEX_FIELD, DATE_FIELD), sParameterArray); } public CSubIndexArray() { m_sParameterArray = sGetParameters(MASTER_SUB_INDEX_FIELD, MASTER_PARENT_SUB_INDEX_FIELD, DATE_FIELD); } public void vLoad(ArrayList oSubIndexArrayList) { m_oSubIndexArrayList = oSubIndexArrayList; } public void vAdd(ref ArrayList oArrayList, CSubIndexArray oSubIndexArray2) { for (int j = 0; j < oSubIndexArray2.Count; j++) { object[] oLineObjectArray = oSubIndexArray2.oGetLine(j); if (oLineObjectArray != null) { oArrayList.Add(oLineObjectArray); } } } ArrayList m_oSubIndexArrayList; protected string[] m_sParameterArray; public const int SUB_INDEX_POSITION = 0; public const int PARENT_SUB_INDEX_POSITION = 1; public const int DATE_POSITION = 2; public string[] ParameterArray { get { return m_sParameterArray; } } public int Count { get { if (m_oSubIndexArrayList == null) return 0; return m_oSubIndexArrayList.Count; } } public int dGetCountWithout(SIndex oIndex) { int j = 0; for (int i = 0; i < Count; i++) { if (oIndex.dSubIndex != dGetSubIndex(i)) j++; } return j; } public object[] oGetLine(int i) { return (object[])m_oSubIndexArrayList[i]; } public object[] oFindLineFromSubIndex(int dSubIndex) { int i = dGetIndexFromSubIndex(dSubIndex); if (IsUsed(i)) { return (object[])m_oSubIndexArrayList[i]; } return null; } public bool bIsChildOf(int dChildSubIndex, int dParentSubIndex) { int dNextSubIndex = dChildSubIndex; while (dNextSubIndex > dParentSubIndex) { dNextSubIndex = dGetParentSubIndexFromSubIndex(dNextSubIndex); } return dNextSubIndex == dParentSubIndex; } public int dGetSubIndex(int i) { if (i < 0 || i > Count) return NOT_USED; return (int)((object[])m_oSubIndexArrayList[i])[SUB_INDEX_POSITION]; } public int dGetIndexFromSubIndex(int dSubIndex) { if (dSubIndex < Count && dGetSubIndex(dSubIndex) == dSubIndex) return dSubIndex; for (int i = 0; i < Count; i++) { if (dGetSubIndex(i) == dSubIndex) { return i; } } return NOT_USED; ; } public object oGetParameter(int i, int dPosition) { if (IsUsed(i) && i < Count) { return ((object[])m_oSubIndexArrayList[i])[dPosition]; } return null; } protected int dGetParentSubIndexFromSubIndex(int dSubIndex) { return dGetParentSubIndex(dGetIndexFromSubIndex(dSubIndex)); } protected int dGetParentSubIndex(int i) { if (IsUsed(i) && i < Count) { return (int)((object[])m_oSubIndexArrayList[i])[PARENT_SUB_INDEX_POSITION]; } return NOT_USED; } public string csDump() { if (m_oSubIndexArrayList == null) return "null"; string sOutput = "count=" + m_oSubIndexArrayList.Count + "\n"; for (int i = 0; i < m_oSubIndexArrayList.Count; i++) { object[] oObjectArray= (object[])m_oSubIndexArrayList[i]; sOutput += ToString(oObjectArray); } sOutput += "\n"; return sOutput; } public CSubIndexArray oGetChild(int dSubIndex, bool bRecursive) { ArrayList oArray = new ArrayList(); for (int j = 0; j < m_oSubIndexArrayList.Count; j++) { if (dSubIndex == dGetParentSubIndex(j)) { oArray.Add(m_oSubIndexArrayList[j]); if (bRecursive) { vAdd(ref oArray, oGetChild(dGetSubIndex(j), bRecursive)); } } } CSubIndexArray oChildArray= Create(); oChildArray.vLoad(oArray); return oChildArray; } public virtual CSubIndexArray Create() { return new CSubIndexArray(ParameterArray); } } ///--------------------------------------------------------------------------------------------------------------------------------------------------- /// /// Summary description for Class1. /// ///--------------------------------------------------------------------------------------------------------------------------------------------------- public class CMeme : CCommandFactoryBase { public CMeme(object oValue, P dAttributeType, SIndex oMemeIndex) { m_oValue = oValue; m_dAttributeType = dAttributeType; m_oIdentifier = null; m_iMemeIndex = oMemeIndex; m_iAvatarAuthorAccessArray = null; m_dAuthorProfileIndex = NOT_USED; } object m_oValue; P m_dAttributeType; CIdentifier m_oIdentifier; public SIndex m_iMemeIndex; public int m_dAuthorProfileIndex; public bool bIsAuthor(int dAuthorProfileIndex) { return IsUsed(dAuthorProfileIndex) && dAuthorProfileIndex == m_dAuthorProfileIndex; } public bool bHasAuthorRight(SIndex oAgentIndex) { return m_iAvatarAuthorAccessArray != null && m_iAvatarAuthorAccessArray.Length > 0 && oAgentIndex.dIndex == m_iAvatarAuthorAccessArray[0].dIndex; } public SIndex[] m_iAvatarAuthorAccessArray; public bool bIsString() { return CEntityManager.Instance(P.ENGLISH).bIsA(m_dAttributeType, P.STRING_TYPE); } public override string ToString() { return m_oValue.ToString(); } public int ToInt32() { int dValue; if (m_dAttributeType == P.INTEGER_TYPE) { dValue = Convert.ToInt32(m_oValue); } else { dValue = NOT_USED; } return dValue; } public void vSet(CIdentifier oIdentifier) { m_oIdentifier = oIdentifier; } public void vSet(SIndex oMemeIndex) { m_iMemeIndex = oMemeIndex; } public bool bIsValid { get { return IsUsed(m_dAttributeType) && m_oValue != null; } } public P dType { get { return m_dAttributeType; } } public CIdentifier oGetAddress { get { return m_oIdentifier; } } public string csDump() { string sOutput = "MemeIndex:" + m_iMemeIndex.csDump(); if (m_oIdentifier != null) { sOutput += " Id:" + m_oIdentifier.csDump(); } sOutput += "content:" + ToString(); if (m_iAvatarAuthorAccessArray != null) { sOutput += " | Access"; for (int i = 0; i < m_iAvatarAuthorAccessArray.Length; i++) { if (i > 0) sOutput += ","; sOutput += m_iAvatarAuthorAccessArray[i]; } } return sOutput; } } ///--------------------------------------------------------------------------------------------------------------------------------------------------- /// /// Summary description for Class1. /// ///--------------------------------------------------------------------------------------------------------------------------------------------------- public class CMemeArray : CDbEPBase { public CMemeArray(ArrayList oMemeArrayList) { m_oMemeArray = (CMeme[])oMemeArrayList.ToArray(typeof(CMeme)); } public CMemeArray(CMeme oMeme) { m_oMemeArray = new CMeme[1]; m_oMemeArray[0] = oMeme; } CMeme[] m_oMemeArray; public int Length { get { return m_oMemeArray.Length; } } public CMeme this[int i] { get { return m_oMemeArray[i]; } } public ec dExtract(SIndex[] oMemeClassement, out CMemeArray oMemeArray) { ec dRC= ec.ST_SUCCEED; if ( m_oMemeArray.Length < oMemeClassement.Length) { oMemeArray= null; return ec.ST_VOTE_MEME_NOT_IN_THE_MEME_ARRAY; } ArrayList oMemeArrayList = new ArrayList(); for (int i = 0; i < oMemeClassement.Length; i++) { CMeme oMeme = oFind(oMemeClassement[i]); EPAssert( oMeme != null, " Meme null for " + oMemeClassement[i] ); if ( oMeme != null) { oMemeArrayList.Add(oMeme); } else { dRC= ec.ST_VOTE_MEME_NOT_IN_THE_MEME_ARRAY; } } oMemeArray = new CMemeArray(oMemeArrayList); return dRC; } public CMeme oFind(SIndex oIndex) { for (int i = 0; i < m_oMemeArray.Length; i++) { if ( bIsEqual(m_oMemeArray[i].m_iMemeIndex, oIndex) ) { return m_oMemeArray[i]; } } return null; } public string csDump() { string sOutput=""; for (int i = 0; i < m_oMemeArray.Length; i++) { sOutput += m_oMemeArray[i].csDump(); } return sOutput; } public CMemeArray dFilterOnAuthorShip(int dAuthorIndex) { if (m_oMemeArray == null) return null; ArrayList oMemeArrayList = new ArrayList(); for (int i = 0; i < m_oMemeArray.Length; i++) { if (m_oMemeArray[i].bIsAuthor(dAuthorIndex)) { oMemeArrayList.Add(m_oMemeArray[i]); } } if (oMemeArrayList.Count == 0) { return null; } return new CMemeArray(oMemeArrayList); } } }

Enter supporting content here