|
|
Enter subhead content here
|
|
using System;
using System.Text;
//using System.Collections.Generic;
using System.Collections;
using System.Diagnostics;
using EXDb97;
using EXCommon;
//###2
namespace EPol
{
public class CCommandManager : CCommandFactoryBase
{
public CCommandManager(P dLanguage)
{
m_dLanguage = dLanguage;
m_oCommandContext = new CCommandContext();
m_oCommandLine = new CCommandLine(ref m_oCommandContext);
}
CCommandContext m_oCommandContext;
public CCommandLine m_oCommandLine;
public string m_sDatabaseName;
public bool bInitDatabase(string sDatabaseName)
{
m_sDatabaseName = sDatabaseName;
bool bRet = CDbConnectionManagement.CreateDatabase(sDatabaseName);
if (bRet)
{
m_oOrganisationView = new COrganisationView(m_dLanguage, sDatabaseName);
m_oProfileView = new CProfileView(m_dLanguage, sDatabaseName);
m_oVoteManager = new CVoteManager(m_dLanguage, sDatabaseName);
m_oCommandLineFactory = new CCommandLineFactory(sDatabaseName);
}
CTrace.i().vWriteSqlLn( "bInitDatabase bRet=" + bRet);
return bRet;
}
public string sDatabaseName
{
get
{
return this.m_sDatabaseName;
}
}
public P Language
{
get
{
return m_dLanguage;
}
set
{
m_dLanguage = value;
}
}
public P m_dLanguage;
COrganisationView m_oOrganisationView;
CVoteManager m_oVoteManager;
CCommandLineFactory m_oCommandLineFactory;
public void vRegister()
{
m_oProfileView.vRegister();
m_oCommandLineFactory.vRegister();
}
public SIndex SenderProfileIndex
{
get
{
return m_oCommandLine.SenderIndex;
}
}
CProfileView m_oProfileView;
public void vCleanAllData()
{
m_oProfileView.vCleanAllData();
m_oOrganisationView.vCleanAllData();
m_oVoteManager.vCleanAllData();
CDbEntityManager.Instance(this.m_sDatabaseName, m_dLanguage).vCleanAllData();
}
public CDbEntityManager DbEntityManager {
get {
return CDbEntityManager.Instance(this.m_sDatabaseName, m_dLanguage);
}
}
public bool bIsEmailRegistered(string sEmailAdress)
{
SIndex oAvatar = m_oProfileView.dGetProfileIndex(sEmailAdress);
m_oCommandContext.vClear();
m_oCommandContext.SenderIndex = oAvatar;
return IsUsed(oAvatar);
}
public bool bRegister(string sEmailAdress, P dLanguage, out string sPublicProfile)
{
SIndex oProfileIndex = m_oProfileView.dAddProfileFromEmail(sEmailAdress, dLanguage);
if (IsUsed(oProfileIndex))
{
string sUserID = csUsedIDFromEmailAdress(sEmailAdress) + ".public.";
int dCounter = 0;
ec dRC;
do
{
sPublicProfile = sUserID + dCounter.ToString();
dRC = m_oProfileView.dAddPublicProfile(oProfileIndex, sPublicProfile, dLanguage);
dCounter++;
if (dCounter > 50)
{
return false;
}
}
while (dRC != ec.ST_SUCCEED);
m_oCommandContext.SenderIndex = oProfileIndex;
CTrace.i().vWriteLn(ENMessage.Avatar,"m_oProfileView.GetMasterTable=" + m_oProfileView.GetMasterTable.csDumpTable());
return true;
}
sPublicProfile = null;
return false;
}
public void vAdd(object oEvent, ec dStatus)
{
this.m_oCommandLine.vAdd(oEvent, dStatus);
}
public ec dAddRecipient(string sRecipient)
{
ec dErrorCode = ec.ST_SUCCEED;
if (sRecipient != "root" )
{
SIndex oRecipientProfileIndex = m_oProfileView.GetMasterTable.dGetIndex(sRecipient);
this.m_oCommandContext.MemberIndex = oRecipientProfileIndex;
if (IsNotUsed(oRecipientProfileIndex))
{
SIndex oOrganisationIndex = this.m_oOrganisationView.GetOrganisationTable.dGetIndex(sRecipient);
if (IsNotUsed(oOrganisationIndex))
{
return ec.ST_RECIPIENT_UNKNOWN;
}
else
{
this.m_oCommandContext.m_iOrganisation = oOrganisationIndex;
}
}
}
return dErrorCode;
}
public string Synopsis
{
get {
return m_oCommandLineFactory.sGetSynopsis(m_oCommandLine);
}
}
public CDbEntityManager.CDbEntityNameView GetKeywordView
{
get
{
return CDbEntityManager.Instance(this.m_sDatabaseName, m_dLanguage).GetKeywordView;
}
}
public ec dExecute(P dCommand, P dEntity, string sEntityContent, string sOptionString, out string sTextMessage)
{
sTextMessage = "";
/*
if ( sEntityContent != null && sEntityContent.Substring(0,1) == "$" )
{
CIdentifier oIdentifier = m_oCommandContext.idGetVariable(sEntityContent);
}*/
CTrace.i().vWriteLn(ENMessage.CommandManager, "dExecute Command=" + dCommand + " dEntity=" + dEntity + " sEntityContent="
+ sEntityContent + " sOptionString=" + sOptionString);
EPAssert(m_oCommandLineFactory != null, "m_oCommandLineFactory should be null");
m_oCommandLineFactory.vSet(ref m_oCommandContext);
ec dErrorCode = m_oCommandLineFactory.dLoadOption(dCommand, dEntity, sEntityContent, sOptionString, out m_oCommandLine);
CTrace.i().vWriteLn(ENMessage.CommandManager,"m_oCommandLine = " + m_oCommandLine.csDump());
if (IsNotUsed(m_oCommandLine.SenderIndex ) || m_oProfileView == null)
{
dErrorCode = ec.ST_PROFILE_UNDEFINED;
}
else if (m_oCommandLine.ExecutedEntity == P.AVATAR)
{
dErrorCode = dExecuteAvatar( out sTextMessage);
}
else if (m_oCommandLine.ExecutedEntity == P.ORGANISATION)
{
dErrorCode = dExecuteOrganisation( out sTextMessage);
}
else if (m_oCommandLine.ExecutedEntity == P.MEMBER)
{
dErrorCode = dExecuteMember(out sTextMessage);
}
else if (m_oCommandLine.ExecutedEntity == P.ACCESS)
{
dErrorCode = dExecuteAccess(out sTextMessage);
}
else if (m_oCommandLine.ExecutedEntity == P.FRIEND)
{
dErrorCode = dExecuteFriend(out sTextMessage);
}
else if (m_oCommandLine.ExecutedEntity == P.LINK)
{
dErrorCode = dExecuteLink(out sTextMessage);
}
else if (m_oCommandLine.ExecutedEntity == P.TRADUCTION)
{
dErrorCode = dExecuteTraduction(out sTextMessage);
}
else if (m_oCommandLine.ExecutedEntity == P.FUNCTION )
{
dErrorCode = dExecuteFunction(m_oCommandLine, out sTextMessage);
}
else if (m_oCommandLine.ExecutedEntity == P.MEME)
{
dErrorCode = dExecuteMeme(m_oCommandLine, out sTextMessage);
}
else if ( bIsA( dEntity, P.RULE) )
{
dErrorCode = dExecuteRule(out sTextMessage);
}
else if (m_oCommandLine.ExecutedEntity == P.IDENTIFIER)
{
dErrorCode = dExecuteIdentifier( out sTextMessage);
}
else if ((m_oCommandLine.ExecutedEntity >= P.FIRST_KEYWORD_INDEX) || bIsA(m_oCommandLine.ExecutedEntity, P.ATTRIBUTE) || GetKeywordView.dGetClass(m_oCommandLine.ExecutedEntity)
== P.ATTRIBUTE)
{
CIdentifier oIdentifier;
dErrorCode = dExecuteAttribute(m_oCommandLine, out oIdentifier, out sTextMessage);
}
else
{
dErrorCode = ec.ST_ENTITY_NOT_SUPPORTED;
}
m_oCommandContext.vSet(m_oCommandLine);
return dErrorCode;
}
protected static bool bIsA(P dEntity, P dEntityParent) {
return CEntityManager.Instance(P.ENGLISH).bIsA(dEntity, dEntityParent);
}
protected ec dExecuteLink(out string sTextMessage)
{
ec dErrorCode = ec.ST_COMMAND_NOT_SUPPORTED_FOR_THIS_ENTITY;
sTextMessage = "";
if (bIsA(m_oCommandLine.Command,P.CREATE))
{
dErrorCode = m_oProfileView.dLink(m_oCommandLine.idFind(P.IDENTIFIER),
m_oCommandLine.idFind(P.IDENTIFIER_RESULT));
}
return dErrorCode;
}
protected ec dExecuteTraduction( out string sTextMessage)
{
ec dErrorCode = ec.ST_COMMAND_NOT_SUPPORTED_FOR_THIS_ENTITY;
sTextMessage = "";
if (bIsA(m_oCommandLine.Command, P.CREATE))
{
dErrorCode = m_oProfileView.dAddLinkTraduction(m_oCommandLine,
m_oCommandLine.idFind(P.IDENTIFIER_RESULT), m_oCommandLine.AttributeType, m_oCommandLine.ContentName);
}
return dErrorCode;
}
protected ec dExecuteIdentifier(out string sTextMessage)
{
ec dRC = ec.ST_SUCCEED;
sTextMessage = "";
CTrace.i().vWriteLn(ENMessage.Identifier, "m_oCommandLine.ContentIdentifier= " + m_oCommandLine.ContentIdentifier);
if (bIsA(m_oCommandLine.Command, P.VOTE_COUNT))
{
dRC = m_oVoteManager.dVoteCountReport( m_oCommandLine, m_oCommandLine.ContentIdentifier, out sTextMessage);
}
else if (bIsA(m_oCommandLine.Command, P.SUPPORT))
{
dRC = m_oVoteManager.dAddOpinion(m_oCommandLine, m_oCommandLine.ContentIdentifier, m_oCommandLine.idFind(P.AGAINST), out sTextMessage);
}
return dRC;
}
protected ec dExecuteRule(out string sTextMessage)
{
ec dRC = ec.ST_SUCCEED;
sTextMessage = "";
if (bIsA(m_oCommandLine.Command, P.VOTE_COUNT))
{
m_oVoteManager.dVoteCountReport( m_oCommandLine, m_oCommandLine.idFind(P.IDENTIFIER), out sTextMessage);
}
else
{
CIdentifier oIdentifier = new CIdentifier(m_oCommandLine.ExecutedEntity, new CIdentifier(P.RULE_CLASS),
new CEntityArray(CDbEntityManager.Instance(m_sDatabaseName,m_dLanguage).oGetEntity(m_dLanguage, P.NAME, m_oCommandLine.ContentName
)));
oIdentifier.vAdd(P.LANGUAGE, (int)m_oCommandLine.Language);
// string sRuleDescription = m_oCommandLine.sFind(P.COMMENT);
if (oIdentifier.Language != P.ENGLISH)
{
dRC = ec.ST_RULE_SHOULD_HAVE_AT_LEAST_A_VERSION_IN_ENGLISH;
}
else
{
if (m_oCommandLine.ExecutedEntity == P.PRINCIPLE)
{
// oAvatarIndex.dSubIndex = PUBLIC_PROFILE_SUB_INDEX;
}
if (bIsA(m_oCommandLine.Command, P.CREATE))
{
dRC = m_oProfileView.dAddRule(m_oCommandLine, m_oCommandLine.ExecutedEntity,
m_oCommandLine.ContentName, oIdentifier, m_oCommandLine.sFind(P.COMMENT));
if (dRC == ec.ST_SUCCEED)
{
m_oVoteManager.dAddOpinion(m_oCommandLine, m_oProfileView.LastMemeVersion, true, out sTextMessage);
}
}
else if (bIsA(m_oCommandLine.Command , P.VOTE) )
{
int dRuleIdentifierIndex;
dRC = m_oProfileView.dGetRule(oIdentifier, m_oCommandLine.ContentName, out dRuleIdentifierIndex);
if (dRC == ec.ST_SUCCEED)
{
m_oVoteManager.dAddOpinion(m_oCommandLine, new SIndex(dRuleIdentifierIndex), m_oCommandLine.Command == P.SUPPORT, out sTextMessage);
}
}
}
}
return dRC;
}
/*
protected int dExecutePrinciple(SCommand oCommand, SIndex oOrganisationIndex, SEntity[] oCategoryOption)
{
ec dRC = ec.ST_SUCCEED;
dRC = m_oProfileView.dAddAttribute(m_oCommandLine.SenderIndex, oOrganisationIndex, P.RULE, sAttributeName,
STRING_4000_TYPE, sAttributeContent, oCategoryOption);
return dRC;
}
*/
protected ec dExecuteFunction(CCommandLine oCommandLine, out string sTextMessage)
{
ec dErrorCode = ec.ST_COMMAND_NOT_SUPPORTED_FOR_THIS_ENTITY;
sTextMessage = "";
if (bIsA(m_oCommandLine.Command, P.CREATE))
{
if (m_oCommandLine.ContentCommandLine == null)
{
return ec.ST_VARIABLE_NO_COMMAND_LINE_ASSOCIATED_TO_THE_VARIABLE;
}
CIdentifier oAttributeIdentifier;
//dErrorCode = m_oProfileView.dCreateAttributeIdentifier(m_oCommandLine.ContentCommandLine.AttributeClass, m_oCommandLine.ContentCommandLine,
out oAttributeIdentifier);
dErrorCode = dExecuteAttribute(m_oCommandLine.ContentCommandLine, out oAttributeIdentifier, out sTextMessage);
if ( oAttributeIdentifier != null)
{
/* CMemeArray oMemeArray; int dCount;
dErrorCode = m_oProfileView.dGetMeme(m_oCommandLine.ContentCommandLine, oAttributeIdentifier,
out oMemeArray, out dCount);
CTrace.i().vWriteLn(ENMessage.Function, "oMemeArray " + oMemeArray.ToString() + " dCount = " + dCount );
CTrace.i().vWriteLn(ENMessage.Function, " m_oCommandLine.CommandContext.vAdd ContentName = " + m_oCommandLine.ContentCommandLine.ContentName
+ " " + oAttributeIdentifier.csDump() );
*/
m_oCommandLine.CommandContext.vAdd(m_oCommandLine.ContentCommandLine.ContentName, oAttributeIdentifier);
}
}
else if (bIsA(m_oCommandLine.Command, P.SUPPORT))
{
CTrace.i().vWriteLn(ENMessage.Function, "dExecuteFunction oCommandLine = " + oCommandLine.csDump() );
if ( oCommandLine.bIsAVariable && oCommandLine.ContentCommandLine != null )
{
CCommandLine oWinningCommandLine = oCommandLine.ContentCommandLine;
CIdentifier oWinningAttributeIdentifier; // oLosingAttributeIdentifier;
dErrorCode = dExecuteAttribute(m_oCommandLine.ContentCommandLine, out oWinningAttributeIdentifier, out sTextMessage);
if ( oWinningAttributeIdentifier != null)
{
CCommandLine oCommandLineLosing = oCommandLine.clFind(P.AGAINST);
CIdentifier oLosingAttributeIdentifier=null;
if ( oCommandLineLosing != null)
{
string sTextMessage2;
dErrorCode = dExecuteAttribute(oCommandLineLosing, out oLosingAttributeIdentifier, out sTextMessage2);
sTextMessage += sTextMessage2;
CTrace.i().vWriteLn(ENMessage.Function, "dExecuteFunction oWinningAttributeIdentifier = " + oWinningAttributeIdentifier.csDump()
);
CTrace.i().vWriteLn(ENMessage.Function, "dExecuteFunction oLosingAttributeIdentifier = " + oLosingAttributeIdentifier.csDump()
);
}
dErrorCode = m_oVoteManager.dAddOpinion(m_oCommandLine, oWinningAttributeIdentifier, oLosingAttributeIdentifier, out
sTextMessage);
}
//dErrorCode = dExecuteAttribute() , out sTextMessage);
}
}
return dErrorCode;
}
protected ec dExecuteMeme( CCommandLine oCommandLine, out string sTextMessage)
{
sTextMessage = null;
ec dErrorCode = m_oVoteManager.dAddOpinion(oCommandLine, oCommandLine.ContentIndex, oCommandLine.iFind(P.AGAINST), oCommandLine.iFind(P.PRINCIPLE));
return dErrorCode;
}
protected ec dExecuteAttribute( CCommandLine oCommandLine, out CIdentifier oAttributeIdentifier, out string sTextMessage)
{
ec dErrorCode = ec.ST_COMMAND_NOT_SUPPORTED_FOR_THIS_ENTITY;
sTextMessage = "";
if (bIsA(oCommandLine.Command, P.CREATE))
{
EPAssert(IsUsed(oCommandLine.AttributeType), "Forget to specify attribute type of " + oCommandLine.AttributeType.ToString());
if (IsNotUsed(oCommandLine.AttributeType))
{
oAttributeIdentifier = null;
dErrorCode = ec.ST_ATTRIBUTE_CREATE_TYPE_SHOULD_BE_SPECIFIED;
}
else {
dErrorCode = m_oProfileView.dAddAttribute( oCommandLine.AttributeClass, oCommandLine, oCommandLine.ContentText, out oAttributeIdentifier);
}
}
else {
dErrorCode = m_oProfileView.dCreateAttributeIdentifier( oCommandLine.AttributeClass, oCommandLine, out oAttributeIdentifier);
EPAssert( oCommandLine.Command > P.NONE, oCommandLine.Command + " should be found");
if ( oCommandLine.Command<= P.NONE)
{
dErrorCode = ec.ST_ATTRIBUTE_COMMAND_IS_UNKNOWN;
return dErrorCode;
}
if (bIsA( oCommandLine.Command,P.DISPLAY) )
{
CMemeArray oMemeArray; int dCount;
if ( oCommandLine.bIsAVariable )
{
oMemeArray = m_oCommandLine.CommandContext.maGetVariable(m_oCommandLine.ContentName);
dCount = oMemeArray.Length;
}
else
{
dErrorCode = m_oProfileView.dGetMeme(oCommandLine, oAttributeIdentifier,
out oMemeArray, out dCount);
}
string sOptionAddress;
m_oProfileView.GetIdentifierView.dConvert(oAttributeIdentifier, true, out sOptionAddress);
sTextMessage = sOptionAddress + "->\n";
SMemeDisplay[] oContentArray;
m_oOrganisationView.vGetMemeContent( oCommandLine.SenderIndex.dIndex, oMemeArray, out oContentArray);
for (int i = 0; i < oContentArray.Length; i++)
{
sTextMessage += oContentArray[i].iMeme + " " + oContentArray[i].sAuthorName + " has " + oContentArray[i].sAddress;
if (oContentArray[i].sContent != null)
{
sTextMessage += " is " + oContentArray[i].sContent + '\n';
}
else
{
sTextMessage += ": You have no access authorization to this content\n";
}
}
string sVariableName = oCommandLine.sFind(P.VARIABLE);
if ( oMemeArray != null && sVariableName != null ) {
m_oCommandContext.vAdd(sVariableName, oMemeArray);
}
}
else
{
if (bIsA( oCommandLine.Command, P.UPDATE))
{
dErrorCode = m_oProfileView.dUpdateMeme( oCommandLine, oAttributeIdentifier, oCommandLine.ContentText);
}
else if (bIsA( oCommandLine.Command, P.SHOW) )
{
dErrorCode = m_oProfileView.dShowToAvatar( oCommandLine, oAttributeIdentifier);
}
else if (bIsA(oCommandLine.Command, P.HIDE) )
{
SIndex oSender;
dErrorCode = m_oProfileView.dHideToAvatar( oCommandLine, oAttributeIdentifier,
out oSender);
}
else if (bIsA( oCommandLine.Command, P.VOTE))
{
dErrorCode = m_oVoteManager.dAddOpinion( oCommandLine, oAttributeIdentifier, null, out sTextMessage);
}
else if (bIsA( oCommandLine.Command, P.VOTE_COUNT))
{
dErrorCode = m_oVoteManager.dVoteCountReport( oCommandLine, oAttributeIdentifier, out sTextMessage);
}
}
}
return dErrorCode;
}
///
/// /////////////////////////////////////////////////////
///
///
///
protected ec dExecuteAvatar(out string sTextMessage)
{
ec dErrorCode = ec.ST_SUCCEED;
sTextMessage = "";
if ( m_oCommandLine.Command== P.CREATE)
{
if (dErrorCode == ec.ST_SUCCEED)
{
if (IsNotUsed( m_oCommandLine.iFind(P.PARENT)))
{
SIndex oPublicProfile= m_oCommandLine.SenderIndex;
oPublicProfile.dSubIndex = PUBLIC_PROFILE_SUB_INDEX;
dErrorCode = m_oProfileView.dAddAvatar(m_oCommandLine.ContentName, oPublicProfile, m_oCommandLine.Language, out oPublicProfile);
}
else
{
SIndex oSenderIndex;
dErrorCode = m_oProfileView.dAddAvatar(m_oCommandLine.ContentName, m_oCommandLine.iFind(P.PARENT), m_oCommandLine.Language,
out oSenderIndex);
m_oCommandLine.SenderIndex = oSenderIndex;
}
CTrace.i().vWriteLn(ENMessage.Avatar,"m_oProfileView = " + m_oProfileView.GetMasterTable.csDumpTable());
if (IsNotUsed(m_oCommandLine.SenderIndex))
{
sTextMessage = "Failed";
dErrorCode = ec.ST_PROFILE_AVATAR_NOT_CREATED;
m_oCommandLine.SenderProfileSubIndex = m_oCommandLine.iFind(P.PARENT).dSubIndex;
}
else
{
m_oCommandContext.SenderIndex = m_oCommandContext.SenderIndex;
}
}
}
else if (bIsA(m_oCommandLine.Command, P.LIST))
{
dErrorCode = dGetListReport(m_oCommandLine.NoodIndex, true, m_oProfileView.GetMasterTable, out sTextMessage);
}
else if (bIsA(m_oCommandLine.Command, P.UPDATE))
{
dErrorCode = m_oProfileView.dCheckIfAvatarOfEmail(m_oCommandLine.iFind(P.AVATAR), m_oCommandLine.SenderIndex);
if (dErrorCode == ec.ST_SUCCEED)
{
m_oCommandContext.SenderIndex = m_oCommandLine.SenderIndex = m_oCommandLine.iFind(P.AVATAR);
dErrorCode = m_oProfileView.dUpdateLanguage(m_oCommandLine.SenderIndex, m_oCommandLine.Language);
string csNewName = m_oCommandLine.sFind(P.NAME);
if (csNewName != null)
{
// dErrorCode = dIsNotLegalNameToUse(csNewName);
if (dErrorCode == ec.ST_SUCCEED)
{
if (csNewName != null) dErrorCode = m_oProfileView.dRename(m_oCommandLine.SenderIndex, csNewName);
}
}
}
}
else if (bIsA(m_oCommandLine.Command, P.REMOVE))
{
dErrorCode = m_oProfileView.dCheckIfAvatarOfEmail(m_oCommandLine.iFind(P.AVATAR), m_oCommandLine.SenderIndex);
m_oCommandLine.SenderProfileSubIndex = CDbEPBase.PUBLIC_PROFILE_SUB_INDEX;
m_oCommandContext.SenderIndex = m_oCommandLine.SenderIndex;
if (dErrorCode == ec.ST_SUCCEED)
{
dErrorCode = m_oProfileView.dDelete(m_oCommandLine.iFind(P.AVATAR));
m_oCommandLine.vClear(P.AVATAR);
}
}
else if (bIsA(m_oCommandLine.Command, P.MOVE))
{
dErrorCode = m_oProfileView.dCheckIfAvatarOfEmail(m_oCommandLine.iFind(P.AVATAR), m_oCommandLine.SenderIndex);
if (dErrorCode == ec.ST_SUCCEED)
{
m_oCommandLine.SenderIndex = m_oCommandLine.iFind(P.AVATAR);
}
}
else if (m_oCommandLine.Command == P.ADD)
{
return dExecuteMember( out sTextMessage);
}
else
{
sTextMessage = " The command " + m_oCommandLine.Command + " is not supported the avatar entity";
dErrorCode = ec.ST_COMMAND_NOT_SUPPORTED_FOR_THIS_ENTITY;
}
return dErrorCode;
}
protected ec dExecuteMember( out string sTextMessage)
{
ec dErrorCode = ec.ST_COMMAND_NOT_SUPPORTED_FOR_THIS_ENTITY;
sTextMessage = "";
SIndex oMemberIndex = m_oCommandLine.MemberIndex;
if (bIsA(m_oCommandLine.Command , P.CREATE))
{
if (IsNotUsed(oMemberIndex))
{
dErrorCode = ec.ST_RECIPIENT_UNKNOWN;
}
else if (oMemberIndex.dSubIndex == -1)
{
dErrorCode = ec.ST_ORGANISATION_ADD_MEMBER_THE_LOGIN_PROFILE_CAN_NOT_BE_ADDED;
}
else
{
dErrorCode = m_oOrganisationView.dAddMember(m_oCommandLine.OrganisationIndex, m_oCommandLine.SenderIndex, oMemberIndex);
}
EPAssert(dErrorCode == ec.ST_SUCCEED, "Adding member failed");
}
else if (bIsA(m_oCommandLine.Command,P.LIST))
{
if (IsUsed(m_oCommandLine.OrganisationIndex))
{
dErrorCode = m_oOrganisationView.dGetListMember(m_oCommandLine.OrganisationIndex, out sTextMessage);
}
else {
dErrorCode = ec.ST_RECIPIENT_UNKNOWN;
}
}
return dErrorCode;
}
protected ec dExecuteAccess( out string sTextMessage)
{
ec dErrorCode = ec.ST_COMMAND_NOT_SUPPORTED_FOR_THIS_ENTITY;
sTextMessage = "";
if (bIsA(m_oCommandLine.Command,P.CREATE))
{
SIndex oOrganisationIndex = m_oOrganisationView.GetOrganisationTable.dGetIndex(m_oCommandLine.ContentName);
if (IsNotUsed(oOrganisationIndex))
{
dErrorCode = ec.ST_RECIPIENT_UNKNOWN;
}
else
{
dErrorCode = m_oOrganisationView.GetMemberTable.dSetAccess(oOrganisationIndex, m_oCommandLine.SenderIndex, true);
}
}
else if (bIsA(m_oCommandLine.Command, P.REMOVE))
{
if (IsNotUsed(m_oCommandLine.OrganisationIndex))
{
dErrorCode = ec.ST_RECIPIENT_UNKNOWN;
}
else
{
dErrorCode = m_oOrganisationView.GetMemberTable.dSetAccess(m_oCommandLine.OrganisationIndex, m_oCommandLine.SenderIndex, false);
}
}
else if (bIsA(m_oCommandLine.Command, P.LIST))
{
dErrorCode = m_oOrganisationView.dGetListAvatarWithPrivilegeAccess(m_oCommandLine.SenderIndex, out sTextMessage);
}
return dErrorCode;
}
protected ec dExecuteFriend( out string sTextMessage)
{
ec dErrorCode = ec.ST_COMMAND_NOT_SUPPORTED_FOR_THIS_ENTITY;
sTextMessage = null;
if (bIsA(m_oCommandLine.Command,P.LIST))
{
dErrorCode = m_oOrganisationView.dGetListFriend(m_oCommandLine.SenderIndex, out sTextMessage);
}
else if (bIsA(m_oCommandLine.Command, P.CREATE))
{
if (IsUsed(m_oCommandLine.ContentIndex))
{
if (IsUsed(m_oCommandLine.SenderIndex))
{
dErrorCode = m_oOrganisationView.GetProfileView.GetFriendTable.dGrantAccess(m_oCommandLine.SenderIndex, m_oCommandLine.ContentIndex);
}
}
else if (m_oCommandLine.ContentIndex.dSubIndex == PRIVATE_PROFILE_SUB_INDEX)
{
dErrorCode = ec.ST_PROFILE_NOBODY_CAN_HAVE_ACCESS_TO_YOUR_PRIVATE_PROFILE;
}
else
{
dErrorCode = ec.ST_RECIPIENT_UNKNOWN;
}
CTrace.i().vWriteLn(ENMessage.Avatar,"m_oOrganisationView.GetProfileView.GetFriendTable = " + m_oOrganisationView.GetProfileView.GetFriendTable.csDumpTable());
}
else if (bIsA(m_oCommandLine.Command,P.REMOVE))
{
if (IsUsed(m_oCommandLine.ContentIndex))
{
dErrorCode = m_oOrganisationView.GetProfileView.GetFriendTable.dRevokeAccess(m_oCommandLine.SenderIndex, m_oCommandLine.ContentIndex);
}
else
{
dErrorCode = ec.ST_RECIPIENT_UNKNOWN;
}
}
return dErrorCode;
}
protected ec dExecuteOrganisation( out string sTextMessage)
{
ec dErrorCode = ec.ST_SUCCEED;
sTextMessage = "";
if (bIsA(m_oCommandLine.Command, P.CREATE))
{
if (IsNotUsed(m_oCommandLine.SenderIndex))
{
dErrorCode = ec.ST_ORGANISATION_CREATION_AVATAR_SHOULD_BE_SPECIFIED;
}
SIndex oActorProfile = iGetPublicProfileIfLoginProfile(m_oCommandLine.SenderIndex);
if (m_oCommandLine.ContentName == null || m_oCommandLine.ContentName == "")
{
dErrorCode = ec.ST_ORGANISATION_CREATION_ORGANISATION_NAME_UNKNOWN;
}
if ( IsUsed(m_oCommandLine.Language) && m_oCommandLine.Language != m_oOrganisationView.GetProfileView.dGetLanguage(oActorProfile))
{
return ec.ST_ORGANISATION_LANGUAGE_SHOULD_BE_THE_SAME_THAN_THE_AVATAR_LANGUAGE;
}
else
{
if (dErrorCode == ec.ST_SUCCEED)
{
SIndex oParentOrganisationIndex = m_oCommandLine.iFind(P.PARENT);
if (IsNotUsed(oParentOrganisationIndex))
{
dErrorCode = m_oOrganisationView.dAddOrganisation(m_oCommandLine.ContentName, m_oCommandLine.bHasOption(P.VIRTUAL), oActorProfile);
}
else
{
dErrorCode = m_oOrganisationView.dAddOrganisation(m_oCommandLine.ContentName, oParentOrganisationIndex, m_oCommandLine.bHasOption(P.VIRTUAL),
iGetPublicProfileIfLoginProfile(oActorProfile));
}
if (dErrorCode == ec.ST_SUCCEED)
{
m_oCommandLine.OrganisationIndex = m_oOrganisationView.dGetOrganisationIndex(m_oCommandLine.ContentName);
}
}
}
}
else
{
if (bIsA(m_oCommandLine.Command,P.LIST))
{
dErrorCode = dGetListReport(m_oCommandLine.NoodIndex, true, m_oOrganisationView.GetOrganisationTable, out sTextMessage);
}
else if (bIsA(m_oCommandLine.Command,P.REMOVE))
{
dErrorCode = m_oOrganisationView.dDelete(m_oCommandLine.ContentIndex, m_oCommandLine.SenderIndex);
}
else
{
sTextMessage = " The command " + m_oCommandLine.Command + " is not supported the avatar entity";
dErrorCode = ec.ST_COMMAND_NOT_SUPPORTED_FOR_THIS_ENTITY;
}
}
return dErrorCode;
}
ec dGetListReport(SIndex oParentIndex, bool bIsRecursive, CDbTreeTable oTreeTable, out string sText)
{
CTrace.i().vWriteLn(ENMessage.Report, "oTreeTable=" + oTreeTable.csDumpTable());
ec dError = ec.ST_SUCCEED;
CTreeListReport oListReport;
CSubIndexArray oSubIndexArray;
if (m_oCommandLine.bHasOption(P.LANGUAGE) == false)
{
oSubIndexArray = new CSubIndexWithNameArray();
oTreeTable.dGetSubIndex(oParentIndex, bIsRecursive, ref oSubIndexArray);
oListReport = new CTreeListReport();
}
else
{
oSubIndexArray = new CSubIndexWithNameArray(LANGUAGE_FIELD);
oTreeTable.dGetSubIndex(oParentIndex, bIsRecursive, ref oSubIndexArray);
oListReport = new CTreeListReport("Language");
}
if (oSubIndexArray == null)
{
sText = null;
dError = ec.ST_REPORT_EMPTY;
}
else
{
oListReport.vConstruct((CSubIndexWithNameArray)oSubIndexArray);
sText = oListReport.sText;
}
return dError;
}
}
///
/// Summary description for DbVariableTable.
///
///
public class CTreeListReport : CListReport
{
public CTreeListReport()
: base(3)
{
m_sComplementField = null;
}
public CTreeListReport(int dSize)
: base(dSize)
{
m_sComplementField = null;
}
public CTreeListReport(string sComplementField)
: base(4)
{
m_sComplementField = sComplementField;
}
string m_sComplementField;
public virtual void vConstruct(CSubIndexWithNameArray oSubIndexArray)
{
vSetHeader(0, "Name"); vSetHeader(1, "Parent"); vSetHeader(2, "Modified");
if (m_sComplementField != null)
{
vSetHeader(3, m_sComplementField);
}
for (int dLn = 0; dLn < oSubIndexArray.Count; dLn++)
{
vAddRow();
vSetLastRow(0, oSubIndexArray.sGetName(dLn));
vSetLastRow(1, oSubIndexArray.sGetParentName(dLn));
vSetLastRow(2, oSubIndexArray.oGetParameter(dLn, CSubIndexArray.DATE_POSITION));
if (m_sComplementField != null)
{
vSetLastRow(3, oSubIndexArray.oGetComplement(dLn)); CTrace.i().vWriteLn(ENMessage.Report,"oGetComplement(dLn)=" + oSubIndexArray.oGetComplement(dLn));
CTrace.i().vWriteLn(ENMessage.Report, "sGetRow =" + ((CArrayLineReport)m_oReportArray[dLn]).sText);
}
}
}
/*
protected virtual string sDateValue(object oValue)
{
if (oValue == null) return "";
string sDate = "";
try
{
DateTime oDate = Convert.ToDateTime(oValue);
sDate = oDate.ToShortDateString();
}
catch
{
sDate = "unknown";
}
return sDate;
}
protected virtual string sComplementValue(object oValue)
{
if (oValue == null) return "null";
if (oValue is P)
{
return ((P)oValue).ToString().ToLower();
}
else
{
return oValue.ToString();
}
}
* */
}
///-------------------------------------------------------------------------------------------------------------------------
public class CVariableListReport : CListReport
{
public CVariableListReport(params string[] sHeaderArray)
: base(sHeaderArray.Length)
{
for (int dCl = 0; dCl < sHeaderArray.Length; dCl++)
{
vSetHeader(dCl, sHeaderArray[dCl]);
}
}
}
///-------------------------------------------------------------------------------------------------------------------------
public class CListReport : CRecusiveReport
{
public CListReport(int dColumnCount)
{
m_oHeader = new CArrayLineReport(dColumnCount);
}
protected CArrayLineReport m_oHeader;
public void vSetHeader(params string[] strValueArray)
{
EPAssert(strValueArray.Length == m_oHeader.Length, "Unmatch header with column number");
for (int i = 0; i < strValueArray.Length; i++)
{
m_oHeader[i] = strValueArray[i];
}
}
public void vSetHeader(int i, string strValue)
{
m_oHeader[i]= strValue;
}
public void vSetLastRow(int i, object oValue)
{
if (m_oReportArray != null && m_oReportArray.Count > 0)
{
string sValue;
if (oValue is P)
{
sValue = ((P)oValue).ToString().ToLower();
}
else if (oValue == null)
{
sValue = "null";
}
else if (oValue is DateTime)
{
try
{
DateTime oDate = Convert.ToDateTime(oValue);
sValue = oDate.ToShortDateString();
}
catch
{
sValue = "bad date";
}
}
else
{
sValue = oValue.ToString();
}
((CArrayLineReport)m_oReportArray[m_oReportArray.Count - 1])[i] = sValue;
}
}
public void vSetLastRow(object[] oValues)
{
if (m_oReportArray != null && m_oReportArray.Count > 0)
{
for (int i = 0; i < oValues.Length; i++)
{
vSetLastRow(i, oValues[i] );
}
}
}
int dComputeColumnLength(out int[] dColumnLength)
{
dColumnLength = new int[m_oHeader.Length];
int dRowLength = 0;
for (int dCol = 0; dCol < m_oHeader.Length; dCol++)
{
int dLength = m_oHeader[dCol].Length;
for (int dLn = 0; dLn < m_oReportArray.Count; dLn++)
{
if (m_oReportArray[dLn] is CArrayLineReport)
{
string sDisplay = ((CArrayLineReport)m_oReportArray[dLn])[dCol];
if (sDisplay != null && dLength < sDisplay.Length)
{
dLength = sDisplay.Length;
}
}
}
dColumnLength[dCol] = dLength;
dRowLength += dLength + 1;
CTrace.i().vWriteLn(ENMessage.Report, " m_dColumnLength[dCol] = " + dColumnLength[dCol]);
}
return dRowLength;
}
public void vAdd(params object[] oValueArray)
{
vAddRow(oValueArray);
}
public void vAddRow(object[] oValueArray)
{
if (m_oReportArray != null)
{
vAddRow();
vSetLastRow(oValueArray);
}
}
protected void vAddRow()
{
if (m_oReportArray != null)
{
m_oReportArray.Add(new CArrayLineReport(m_oHeader.Length));
}
}
public override string sGetText(int dColPos)
{
int[] dColumnLengthArray;
int dRowLength = dComputeColumnLength(out dColumnLengthArray);
StringBuilder sReport = new StringBuilder();
sReport.Append(m_oHeader.sGetTextWithBorder(dColPos, dColumnLengthArray) + "\n");
for (int dLn = 0; dLn < m_oReportArray.Count; dLn++)
{
if (m_oReportArray[dLn] is CArrayLineReport)
{
sReport.Append(((CArrayLineReport)m_oReportArray[dLn]).sGetText(dColPos, dColumnLengthArray) + "\n");
}
}
return sReport.ToString();
}
}
///-------------------------------------------------------------------------------------------------------------------------
public abstract class CSingleLineReport : CReport
{
public CSingleLineReport()
{
}
static public string sTextWithBorder(int dColPos, string _sText)
{
string sIdentation = sGetString(' ', dColPos);
string sInterLine = sGetString('-', _sText.Length);
StringBuilder sReport = new StringBuilder();
sReport.Append(sIdentation); sReport.Append(sInterLine + "\n");
sReport.Append(sIdentation); sReport.Append(_sText + "\n");
sReport.Append(sIdentation); sReport.Append(sInterLine + "\n");
return sReport.ToString();
}
/*
public override string sGetText(int dColPos)
{
return sGetString(' ', dColPos) + sReport.sText;
}
*/
}
///-------------------------------------------------------------------------------------------------------------------------
public class CTextLineReport : CSingleLineReport
{
public CTextLineReport()
{
m_enStyle = ENStyle.Normal;
}
ENStyle m_enStyle;
public enum ENStyle {
Normal,
Title
}
public ENStyle Style
{
get
{
return m_enStyle;
}
set
{
m_enStyle = value;
}
}
string m_sTextLine;
/*public void vSetText(int dProfileIndex, string sText)
{
m_sTextLine = MEMBER + dProfileIndex + ' ' + sText;
}*/
public void vSetText( string sText)
{
m_sTextLine = sText;
}
public override string sGetText(int dColPos)
{
if (m_enStyle == ENStyle.Normal)
{
return sGetString(' ', dColPos) + m_sTextLine;
}
else if (m_enStyle == ENStyle.Title)
{
return sTextWithBorder(dColPos, m_sTextLine);
}
return null;
}
public override ec dReplace(string sPrefixe, string sNewPrefixe, SortedList oMapList)
{
return dReplace(sPrefixe, sNewPrefixe, oMapList, ref m_sTextLine);
}
}
///-------------------------------------------------------------------------------------------------------------------------
public class CArrayLineReport : CSingleLineReport
{
public CArrayLineReport(int dColumnCount)
{
m_oColumnArray = new string[dColumnCount];
}
string[] m_oColumnArray;
public int Length
{
get
{
return m_oColumnArray.Length;
}
}
public string this[int i]
{
get
{
return m_oColumnArray[i];
}
set
{
m_oColumnArray[i] = value;
}
}
public override ec dReplace(string sPrefixe, string sNewPrefixe, SortedList oMapList)
{
ec dRC=ec.ST_SUCCEED;
for (int i = 0; i < m_oColumnArray.Length; i++)
{
dRC = dReplace( sPrefixe, sNewPrefixe, oMapList, ref m_oColumnArray[i]);
if ( dRC != ec.ST_SUCCEED) break;
}
return dRC;
}
public string sGetTextWithBorder(int dColPos, int[] dColumnLengthArray)
{
string _sText = sGetText(0, dColumnLengthArray);
return sTextWithBorder(dColPos, _sText);
}
public string sGetText(int dColPos, int[] dColumnLengthArray)
{
StringBuilder sRow = new StringBuilder();
sRow.Append(sGetString(' ',dColPos));
int dCurrentColPos = dColPos;
for (int dCol = 0; dCol < m_oColumnArray.Length && (IsNotUsed(LastColPos) || dCurrentColPos < LastColPos); dCol++)
{
sRow.Append(m_oColumnArray[dCol]);
int dColumnItemLength = 0;
if (m_oColumnArray[dCol] != null)
{
dColumnItemLength = m_oColumnArray[dCol].Length;
}
if (dColumnLengthArray == null)
{
sRow.Append( ' ');
dCurrentColPos += dColumnItemLength + 1;
}
else
{
dCurrentColPos += dColumnLengthArray[dCol];
sRow.Append(sGetString(' ', dColumnLengthArray[dCol] - dColumnItemLength + 1));
}
}
return sRow.ToString();
}
public override string sGetText(int dColPos)
{
return sGetText(dColPos, null);
}
public void vSet(object[] oValueArray)
{
EPAssert(oValueArray != null, "Should not be null");
for (int dCol = 0; dCol < oValueArray.Length; dCol++)
{
m_oColumnArray[dCol] = oValueArray[dCol].ToString();
}
}
}
///-------------------------------------------------------------------------------------------------------------------------
public abstract class CReport : CDbEPBase
{
public CReport()
{
m_dFirstColPos = 0;
m_dLastColPos = NOT_USED;
}
public static string sGetString(char cChar, int dLength)
{
StringBuilder sRow = new StringBuilder();
for (int j = 0; j < dLength; j++)
{
sRow.Append(cChar);
}
return sRow.ToString();
}
protected int m_dFirstColPos, m_dLastColPos;
public virtual int FirstColPos
{
get
{
return m_dFirstColPos;
}
set
{
m_dFirstColPos = value;
}
}
public virtual int LastColPos
{
get
{
return m_dLastColPos;
}
set
{
m_dLastColPos = value;
}
}
public virtual string sText
{
get
{
return sGetText(m_dFirstColPos);
}
}
public const string MEMBER = "member_";
public const string MEME = "meme_";
public abstract string sGetText(int dColPos);
public abstract ec dReplace(string sPrefixe, string sNewPrefixe, SortedList oMapList);
public static ec dReplace(string sPrefixe, string sNewPrefixe, SortedList oMapList, ref string str)
{
try
{
int dIndex = 0;
while ((dIndex = str.IndexOf(sPrefixe, dIndex)) >= 0)
{
int dBlankIndex = str.IndexOf(' '); if (dBlankIndex < 0) dBlankIndex = str.Length - 1;
string sKey = str.Substring(dIndex + sPrefixe.Length, dBlankIndex - dIndex - sPrefixe.Length);
string sNewValue = oMapList[Convert.ToInt32(sKey)].ToString();
if (sNewValue == null)
{
CTrace.i().vWriteLn(ENMessage.Report, "dReaplece can not find sKey " + sKey);
return ec.ST_REPORT_THE_PROFILE_IS_NOT_MAP;
}
str.Replace(sPrefixe + sKey, sNewPrefixe + sNewValue);
}
}
catch(Exception e) {
CTrace.i().vWriteLn(ENMessage.Report, "dReplace conversion failure from " + sPrefixe + " to " + sNewPrefixe + " : " + e.Message);
}
return ec.ST_SUCCEED;
}
}
///-------------------------------------------------------------------------------------------------------------------------
public class CRecusiveReport : CReport
{
public CRecusiveReport()
{
m_oReportArray = new ArrayList(10);
m_dDefaultLineIdentation = 0;
}
int m_dDefaultLineIdentation;
public int DefaultLineIdentation
{
set
{
m_dDefaultLineIdentation = value;
}
get
{
return m_dDefaultLineIdentation;
}
}
public bool Active
{
set
{
if (value)
{
m_oReportArray = new ArrayList(10);
}
else
{
m_oReportArray = null;
}
}
get
{
return m_oReportArray != null;
}
}
protected ArrayList m_oReportArray;
public override int FirstColPos
{
get
{
return m_dFirstColPos;
}
set
{
m_dFirstColPos = value;
for (int i = 0; i < m_oReportArray.Count; i++)
{
((CReport)m_oReportArray[i]).FirstColPos = ((CReport)m_oReportArray[i]).FirstColPos + value;
}
}
}
public void vSetTitle(string sTitle)
{
if (m_oReportArray != null)
{
CTextLineReport oTextLineReport = new CTextLineReport();
oTextLineReport.Style = CTextLineReport.ENStyle.Title;
oTextLineReport.vSetText(sTitle);
m_oReportArray.Add(oTextLineReport);
}
}
public void vAdd(CReport oReport)
{
if (m_oReportArray != null)
{
m_oReportArray.Add(oReport);
}
}
public override ec dReplace(string sPrefixe, string sNewPrefixe, SortedList oMapList)
{
ec dRC = ec.ST_SUCCEED;
for (int i = 0; i < m_oReportArray.Count; i++)
{
dRC = ((CReport)m_oReportArray[i]).dReplace(sPrefixe, sNewPrefixe, oMapList);
if (dRC != ec.ST_SUCCEED) break;
}
return dRC;
}
public override string sGetText(int dColPos)
{
if (m_oReportArray != null)
{
StringBuilder sRow = new StringBuilder();
for (int i = 0; i < m_oReportArray.Count; i++)
{
sRow.Append(((CReport)m_oReportArray[i]).sGetText( dColPos));
}
return sRow.ToString();
}
return null;
}
public override string sText
{
get
{
return sGetText(0);
}
}
}
///-------------------------------------------------------------------------------------------------------------------------
public class CRandomIndex
{
public CRandomIndex(int dCount)
{
m_oRandomIndex = new ArrayList();
for (int i = 0; i < dCount; i++)
{
m_oRandomIndex.Add(i);
}
}
ArrayList m_oRandomIndex;
public int dRandomIndex
{
get
{
Random oRandom = new Random();
int dIndex = oRandom.Next(m_oRandomIndex.Count - 1);
int dRandomIndex = (int)m_oRandomIndex[dIndex];
m_oRandomIndex.RemoveAt(dIndex);
return dRandomIndex;
}
}
}
///-------------------------------------------------------------------------------------------------------------------------
public class CTraceReport : CRecusiveReport
{
public CTraceReport()
{
m_oProfileList = new SortedList();
m_oMemeList = new SortedList();
}
SortedList m_oProfileList, m_oMemeList;
public ec dLoadProfile(ArrayList oArrayList)
{
if (Active)
{
return dLoad(ref m_oProfileList, oArrayList);
}
else
{
return ec.ST_TRACE_NOT_ACTIVE;
}
}
public ec dLoadMeme(ArrayList oArrayList)
{
return dLoad(ref m_oMemeList, oArrayList);
}
static public ec dLoad(ref SortedList oSortedList, ArrayList oArrayList)
{
for (int i = 0; i < oArrayList.Count; i++)
{
CVoteBase.SProfile oProfile = (CVoteBase.SProfile)oArrayList[i];
// int dIndex = Convert.ToInt32(oRecord[0]);
if (oSortedList.ContainsKey(oProfile.dIndex))
{
oSortedList[oProfile.dIndex] = oProfile.sDisplayName;
}
else {
CTrace.i().vWriteLn(ENMessage.TraceManager, "dLoad no Index= " + oProfile.dIndex);
}
}
for (int j = 0; j < oSortedList.Count; j++)
{
if (oSortedList.GetByIndex(j).ToString() == NOT_USED_STR)
{
CTrace.i().vWriteLn(ENMessage.TraceManager, "oSortedList unknown profile = " + oSortedList.GetKey(j));
return ec.ST_REPORT_THE_PROFILE_IS_NOT_MAP;
}
}
return ec.ST_SUCCEED;
}
public ec dReplaceProfileIndexByRamdomIndex()
{
if (Active)
{
CRandomIndex oRandomIndex = new CRandomIndex(m_oProfileList.Count);
for (int i = 0; i < m_oProfileList.Count; i++)
{
m_oProfileList.SetByIndex(i, CTextLineReport.MEMBER + (oRandomIndex.dRandomIndex + 1));
}
return ec.ST_SUCCEED;
}
else
{
return ec.ST_TRACE_NOT_ACTIVE;
}
}
public override string sText
{
get
{
if (m_oReportArray != null)
{
dReplace( CTextLineReport.MEMBER, "", m_oProfileList);
dReplace(CTextLineReport.MEME, "", m_oMemeList);
return base.sText;
}
return null;
}
}
public void vAddLine( string sMessage)
{
/* if (m_oProfileList.ContainsKey(dProfileIndex )== false) {
m_oProfileList.Add(dProfileIndex, NOT_IN_STRING);
}*/
if (m_oReportArray != null)
{
CTextLineReport oTextLineReport = new CTextLineReport();
oTextLineReport.FirstColPos = this.DefaultLineIdentation;
oTextLineReport.vSetText(sMessage + "\n");
m_oReportArray.Add(oTextLineReport);
}
}
}
///---------------------------------------------------------------------------------------------------------------------
//
public class CCommandParser : CCommandFactoryBase
{
public CCommandParser(P dLanguage)
: base()
{
m_dLanguage = dLanguage;
}
P m_dLanguage;
static CCommandParser s_oCommandParser = null;
static public CCommandParser Instance(P dLanguage, string csText)
{
if (s_oCommandParser == null)
{
s_oCommandParser = new CCommandParser(dLanguage);
}
s_oCommandParser.m_dLanguage = dLanguage;
/*int dIndex = 0; ec dErrorCode = ec.ST_SUCCEED; char cEndChar;*/
// csText = GetTextIntoApostrophe(csText, cEndChar, ref dIndex, ref dErrorCode);
csText = GetContentFromBracket(csText);
s_oCommandParser.vReset(GetContentFromBracket(csText));
return s_oCommandParser;
}
public bool bIsBeginningOfCommand(string csText, ref int dIndex)
{
int dPos = dIndex;
while (dPos < csText.Length)
{
if (csText[dPos] == '\n' || csText[dPos] == ';')
{
dPos++;
dIndex = dPos;
return true;
}
if (CDbEPBase.bIsACharOfAWord(csText[dPos]) || CDbEPBase.bStartOfEnclosing(csText[dPos] ))
{
return false;
}
dPos++;
}
return false;
}
static public ec dMoveToWordBeginning(string csText, ref int dIndex)
{
while (dIndex < csText.Length &&
(CDbEPBase.bIsACharOfAWord(csText[dIndex]) == false &&
CDbEPBase.bStartOfEnclosing(csText[dIndex]) == false))
{
if (csText[dIndex] == '\n' || csText[dIndex] == ';')
{
dIndex++;
return ec.ST_PARSER_END_OF_LINE;
}
if (csText[dIndex] == '-')
{
return ec.ST_PARSER_BEGINNING_OF_OPTION;
}
dIndex++;
}
return dIndex < csText.Length ? ec.ST_SUCCEED : ec.ST_PARSER_EOM;
}
static string GetContentFromBracket(string csText)
{
CTrace.i().vWriteLn(ENMessage.Parser, "GetContentFromBracket = " + csText);
int dIndex=0;
dMoveToWordBeginning(csText, ref dIndex);
csText = csText.Substring(dIndex);
dIndex=0;
if (csText != "")
{
char cChar = csText[0];
char cEndChar = cGetEndChar(csText[0]);
if (cEndChar != '\0')
{
ec dErrorCode = ec.ST_SUCCEED;
csText = GetTextIntoApostrophe(csText[0] + GetContentFromBracket(csText.Substring(1)), cEndChar, ref dIndex, ref dErrorCode);
return csText;
}
}
return csText;
}
static string GetTextIntoApostrophe(string csText, char cEndChar, ref int dIndex, ref ec dRC)
{
string csReturnText = null;
if (cGetEndChar(csText.Substring(dIndex, 1).ToCharArray()[0]) == cEndChar) dIndex++;
int i;
for (i = dIndex; i < csText.Length; i++)
{
char cCurrentChar = csText.Substring(i, 1).ToCharArray()[0];
if (cCurrentChar == cEndChar)
{
csReturnText = csText.Substring(dIndex, i - dIndex);
dIndex = i + 1;
return csReturnText;
}
}
dRC = ec.ST_PARSER_CAN_NOT_FIND_APOSTROPHE_END;
return csReturnText;
}
public ec dGetOption(string csText, ref int dIndex, out string csReturnText)
{
csReturnText = "";
while (true)
{
ec dEC = dMoveToWordBeginning(csText, ref dIndex);
if (dEC != ec.ST_SUCCEED && dEC != ec.ST_PARSER_BEGINNING_OF_OPTION) return dEC;
char cCurrentChar = csText.Substring(dIndex, 1).ToCharArray()[0];
if (cCurrentChar != '-') break;
csReturnText += csGetWord(csText, ref dIndex);
if (bIsLastChar(csReturnText, ':', '='))
{
csReturnText += '\'' + csGetText(csText, ref dIndex, ref dEC) + '\'';
}
}
return ec.ST_SUCCEED;
}
static public string csGetWord(string csText, ref int dIndex)
{
string csReturnText = null;
int i;
for (i = dIndex; i < csText.Length; i++)
{
char cCurrentChar = csText.Substring(i, 1).ToCharArray()[0];
if (bIsACharOfAWord(cCurrentChar) || cCurrentChar == '-' || cCurrentChar == ':' || cCurrentChar == '=' || cCurrentChar ==
',' || cCurrentChar == '$')
{
csReturnText += cCurrentChar;
}
else
{
break;
}
}
dIndex = i;
CTrace.i().vWriteLn(ENMessage.Parser, "csGetWord = " + csText.Substring(dIndex) + "->csReturnText=" + csReturnText);
return csReturnText;
}
static public string csGetText(string csText, ref int dIndex, ref ec dErrorCode)
{
CTrace.i().vWriteLn(ENMessage.Parser, "csGetText = " + csText.Substring(dIndex));
string csReturnText = null;
dErrorCode = dMoveToWordBeginning(csText, ref dIndex);
if (dErrorCode != ec.ST_SUCCEED && dErrorCode != ec.ST_PARSER_END_OF_LINE) return "";
char cCurrentChar = csText.Substring(dIndex, 1).ToCharArray()[0];
char cEndChar = cGetEndChar(cCurrentChar);
if (cEndChar != '\0')
{
csReturnText = GetTextIntoApostrophe(csText, cEndChar, ref dIndex, ref dErrorCode);
}
else
{
csReturnText = csGetWord(csText, ref dIndex);
if (bIsLastChar(csReturnText, ':', '='))
{
csReturnText += '(' + csGetText(csText, ref dIndex, ref dErrorCode) + ')' ;
}
}
return csReturnText;
}
public ec dParseCommand(string csText, ref int dIndex, out P dCommand, out string csEntityName)
{
//oCommand=CCommandArrayFactory.Instance().m_oNullCommand;
dCommand = P.NOT_USED;
csEntityName = null;
ec dEC = dMoveToWordBeginning(csText, ref dIndex);
CTrace.i().vWriteLn(ENMessage.Parser, "csText=" + csText.Substring(dIndex) + " dCommand=" + dCommand + " csEntityName="
+ csEntityName + " ec=" + dEC);
if (dEC != ec.ST_SUCCEED)
{
return dEC;
}
string csCommand = csGetWord(csText, ref dIndex);
dCommand = CEntityManager.Instance(m_dLanguage).dFindCommand(csCommand);
CTrace.i().vWriteLn(ENMessage.Parser, "csText=" + csText.Substring(dIndex) + " dCommand=" + dCommand + " csEntityName=");
if (IsNotUsed(dCommand))
{
CTrace.i().vWriteLn(ENMessage.Parser, csEntityName + " ec=" + ec.ST_PARSER_CANNOT_FIND_THE_NEXT_COMMAND);
return ec.ST_PARSER_CANNOT_FIND_THE_NEXT_COMMAND;
}
dEC = dMoveToWordBeginning(csText, ref dIndex);
CTrace.i().vWriteLn(ENMessage.Parser, "csText=" + csText.Substring(dIndex));
if (dEC != ec.ST_SUCCEED)
{
return dEC;
}
if (csText != null && csText.Substring(dIndex,1) == "$" )
{
csEntityName = "function";
}
else {
csEntityName = csGetWord(csText, ref dIndex);
}
CTrace.i().vWriteLn(ENMessage.Parser, "csText=" + csText.Substring(dIndex) + " csEntityName=" + csEntityName);
dEC = dMoveToWordBeginning(csText, ref dIndex);
CTrace.i().vWriteLn(ENMessage.Parser, "csText=" + csText.Substring(dIndex));
if (dCommand == P.DISPLAY)
{
dEC = ec.ST_SUCCEED;
}
return dEC;
}
public void vReset(string csText)
{
m_csText = csText;
m_dIndex = 0;
}
string m_csText;
int m_dIndex;
public ec dNext(out P dCommand, out string sEntityName, out string csEntityContent, out string csOptionString)
{
ec dErrorCode = ec.ST_SUCCEED;
csOptionString = ""; sEntityName = null;
csEntityContent = null;
dCommand = P.NOT_USED;
//oCommand = CCommandArrayFactory.Instance().m_oNullCommand;
if (m_csText == "") return ec.ST_PARSER_EOM;
ec dEC = dMoveToWordBeginning(m_csText, ref m_dIndex);
if (dEC != ec.ST_SUCCEED) return dEC;
CTrace.i().vWrite(ENMessage.Parser, " dNext m_csText=" + m_csText);
dErrorCode = dParseCommand(m_csText, ref m_dIndex, out dCommand, out sEntityName);
if ((dErrorCode == ec.ST_SUCCEED || dErrorCode == ec.ST_PARSER_BEGINNING_OF_OPTION) && sEntityName != null)
{
CTrace.i().vWriteLn(ENMessage.Parser, " dCommand=" + dCommand + " sEntityName=" + sEntityName);
// if (this.bIsBeginningOfCommand(m_csText, ref m_dIndex) == false)
// {
dErrorCode = dGetOption(m_csText, ref m_dIndex, out csOptionString);
if (dErrorCode == ec.ST_PARSER_EOM || dErrorCode == ec.ST_PARSER_END_OF_LINE) return ec.ST_SUCCEED;
csEntityContent = csGetText(m_csText, ref m_dIndex, ref dErrorCode);
string csOptions; dGetOption(m_csText, ref m_dIndex, out csOptions);
csOptionString += csOptions;
// }
}
if ((dErrorCode == ec.ST_PARSER_EOM || dErrorCode == ec.ST_PARSER_END_OF_LINE) && CEntityManager.Instance(P.LANGUAGE).dGet(dCommand,
IS_SYNOPSIS) == P.COMMAND_ENTITY_COMMAND_SYNOPSIS)
{
dErrorCode = ec.ST_SUCCEED;
}
return dErrorCode;
}
}
///-------------------------------------------------------------------------------------------------------------------------
public class CCommandLineFactory : CCommandFactoryBase
{
public CCommandLineFactory(string sDatabaseName)
{
m_oOrganisationView = new COrganisationView(m_dLanguage, sDatabaseName);
m_oProfileView = new CProfileView(m_dLanguage, sDatabaseName);
m_oCommandContext = null;
}
COrganisationView m_oOrganisationView;
CProfileView m_oProfileView;
public string sDatabaseName
{
get
{
return m_oProfileView.sDatabaseName;
}
}
P m_dLanguage;
public void vRegister()
{
m_oProfileView.vRegister();
}
public CDbEntityManager EntityManager {
get
{
return CDbEntityManager.Instance(m_oProfileView.sDatabaseName, m_dLanguage);
}
}
CCommandContext m_oCommandContext;
public void vSet(ref CCommandContext oCommandContext) {
m_oCommandContext = oCommandContext;
}
public string ToString(P dEntity)
{
return CEntityManager.Instance(m_dLanguage).sGetEntityName(dEntity).ToLower();
}
public ec dIsNotLegalNameToUse(string sName)
{
ec dError = ec.ST_SUCCEED;
if (sName == null || sName == "") return ec.ST_ENTITY_NOT_SUPPORTED;
sName = sName.ToLower();
if (bHasOnlyAuthorizeCharacter(sName) == false)
{
dError = ec.ST_NAME_CONTAINING_SPACE_OR_OTHER_ILLICITE_CHARACTER;
}
else
{
SIndex oProfileIndex = m_oProfileView.GetMasterTable.dGetIndex(sName);
if (IsUsed(oProfileIndex))
{
dError = ec.ST_NAME_USED_ALREADY_FOR_A_PROFILE;
}
else
{
SIndex oOrganisationIndex = m_oOrganisationView.dGetOrganisationIndex(sName);
if (IsUsed(oOrganisationIndex))
{
dError = ec.ST_NAME_USED_ALREADY_FOR_AN_ORGANISATION;
}
}
}
return dError;
}
public ec dLoadOption( string sAttributeContent, out CCommandLine oVariableCommandLine)
{
string sVariableEntityName;
P dVariableCommand; string sVariableEntityContent, sVariableOptionString;
CCommandParser.Instance(m_dLanguage, sAttributeContent).dNext(out dVariableCommand,
out sVariableEntityName, out sVariableEntityContent, out sVariableOptionString);
CCommandLineFactory oCommandLineFactory = new CCommandLineFactory(sDatabaseName);
P dVariableEntityName = CDbEntityManager.Instance(
sDatabaseName, CDbEPBase.P.ENGLISH).dGet(CDbEPBase.P.ENGLISH,sVariableEntityName);
oCommandLineFactory.vSet(ref m_oCommandContext);
return oCommandLineFactory.dLoadOption(dVariableCommand, dVariableEntityName, sVariableEntityContent, sVariableOptionString,
out oVariableCommandLine);
}
public ec dLoadOption(P dCommand, P dExecutedEntity, string sEntityContent, string sOptionString,
out CCommandLine oCommandLine)
{
ec dErrorCode = ec.ST_SUCCEED;
oCommandLine = new CCommandLine(dCommand, dExecutedEntity, ref m_oCommandContext);
P dExecutedEntityType = CEntityManager.Instance(m_dLanguage).dGetType(dExecutedEntity);
CTrace.i().vWriteLn(ENMessage.CommandParsing, "dExecutedEntityType =" + dExecutedEntityType + " type="
+ EntityManager.dGetType(dExecutedEntityType) );
if (bIsA(dCommand, P.CREATE))
{
if (bIsA(dExecutedEntity, P.ATTRIBUTE))
{
P dExistingType; string sAttributeName, sAttributeContent;
dErrorCode = dFindAttribute(dExecutedEntity, sEntityContent, out sAttributeName, out sAttributeContent, out dExistingType);
if (IsUsed(dExistingType) && IsUsed(oCommandLine.AttributeType) && dExistingType != oCommandLine.AttributeType)
{
dErrorCode = ec.ST_ATTRIBUTE_TYPE_MISMATCH;
}
else
{
oCommandLine.ContentName = sAttributeName;
oCommandLine.ContentText = sAttributeContent;
oCommandLine.AttributeType = dExistingType;
}
}
else if (bIsA(dExecutedEntity, P.AGENT))
{
if (dExecutedEntity == P.AVATAR)
{
oCommandLine.ContentName = sEntityContent;
}
else
{
oCommandLine.ContentIndex = m_oProfileView.dGetProfileIndex(sEntityContent);
}
}
else if (bIsA(dExecutedEntity, P.ORGANISATION))
{
SIndex iOrganisation = m_oOrganisationView.GetOrganisationTable.dGetIndex(sEntityContent);
if (sEntityContent != null && IsUsed(iOrganisation))
{
oCommandLine.OrganisationIndex = m_oCommandContext.m_iOrganisation = iOrganisation;
}
oCommandLine.ContentName = sEntityContent;
}
else if (bIsA(dExecutedEntity, P.FUNCTION ))
{
P dExistingType; string sAttributeName, sAttributeContent;
dErrorCode = dFindAttribute(dExecutedEntity, sEntityContent, out sAttributeName, out sAttributeContent, out dExistingType);
if (IsUsed(dExistingType) && IsUsed(oCommandLine.AttributeType) && dExistingType != oCommandLine.AttributeType)
{
dErrorCode = ec.ST_ATTRIBUTE_TYPE_MISMATCH;
}
else
{
// oCommandLine.ContentName = sAttributeName;
CCommandLine oVariableCommandLine;
if (dLoadOption( sAttributeContent, out oVariableCommandLine)== ec.ST_SUCCEED)
{
oCommandLine.vAddFunctionAndCommandLine(sAttributeName, oVariableCommandLine);
//dExecuteFunction(oVariableCommandLine, out sMessage)
//oCommandLine.ContentCommandLine = oVariableCommandLine;
/* oCommandLine.AttributeType = P.IDENTIFIER_TYPE;
CIdentifier oAttributeIdentifier;
dErrorCode = m_oProfileView.dCreateAttributeIdentifier(oVariableCommandLine.AttributeClass, oVariableCommandLine, out
oAttributeIdentifier);
CTrace.i().vWriteLn(ENMessage.Function, "oAttributeIdentifier = " + oAttributeIdentifier.csDump());
*/
//oCommandLine.ContentIdentifier = oAttributeIdentifier;
}
else
{
CIdentifier oIdentifierObjects;
ec dRC= EntityManager.dConvert(sAttributeContent, out oIdentifierObjects);
if (dErrorCode == ec.ST_SUCCEED)
{
oCommandLine.ContentIdentifier = oIdentifierObjects;
oCommandLine.AttributeType = P.IDENTIFIER_TYPE;
}
else
{
oCommandLine.ContentText = sAttributeContent;
oCommandLine.AttributeType = P.STRING_TYPE;
}
}
}
}
else
{
oCommandLine.ContentName = sEntityContent;
}
}
else if (bIsA(dCommand, P.LIST))
{
if (sEntityContent != null)
{
sEntityContent = sEntityContent.ToLower();
dErrorCode = dIsNotLegalNameToUse(sEntityContent);
if (dErrorCode != ec.ST_NAME_USED_ALREADY_FOR_AN_ORGANISATION)
{
if (dExecutedEntity == P.ORGANISATION)
{
return ec.ST_ORGANISATION_CREATION_ORGANISATION_NAME_UNKNOWN;
}
else
{
return ec.ST_NAME_UNKNOWN;
}
}
else
{
dErrorCode = ec.ST_SUCCEED;
}
}
P dExecutedEntitySetType = CEntityManager.Instance( m_dLanguage).dGetSetType(dExecutedEntity);
if (bIsA(dExecutedEntitySetType, P.IDENTIFIER_TYPE))
{
CEntityArray oIdentifierObjects;
dErrorCode = EntityManager.dConvert(sEntityContent, out oIdentifierObjects);
if (dErrorCode == ec.ST_SUCCEED)
{
oCommandLine.vAdd(P.IDENTIFIER, oIdentifierObjects);
}
}
else if (bIsA(dExecutedEntitySetType, P.SINDEX_TYPE))
{
oCommandLine.ContentIndex = ToSIndex(sEntityContent);
}
else if (bIsA(dExecutedEntitySetType, P.AVATAR_SINDEX_TYPE))
{
SIndex oAvatarIndex = m_oProfileView.dGetProfileIndex(sEntityContent);
if (sEntityContent != null && IsNotUsed(oAvatarIndex))
{
dErrorCode = ec.ST_AVATAR_LIST_NAME_IS_UNKNOWN;
}
else
{
m_oCommandContext.SenderIndex = oCommandLine.SenderIndex = oAvatarIndex;
}
}
else if (bIsA(dExecutedEntitySetType, P.COMMITTEE_SINDEX_TYPE) )
{
m_oCommandContext.m_iOrganisation = m_oOrganisationView.GetOrganisationTable.dGetIndex(sEntityContent);
if (sEntityContent != null && IsNotUsed(m_oCommandContext.m_iOrganisation))
{
dErrorCode = ec.ST_ORGANISATION_LIST_ORGANISATION_NAME_UNKNOWN;
}
else
{
oCommandLine.OrganisationIndex= m_oCommandContext.m_iOrganisation;
}
}
else if (bIsA(dExecutedEntitySetType, P.ORGANISATION_INDEX_TYPE))
{
m_oCommandContext.m_iOrganisation = m_oOrganisationView.GetOrganisationTable.dGetIndex(sEntityContent);
if (sEntityContent != null && IsNotUsed(m_oCommandContext.m_iOrganisation))
{
dErrorCode = ec.ST_ORGANISATION_LIST_ORGANISATION_NAME_UNKNOWN;
}
else
{
oCommandLine.OrganisationIndex = m_oCommandContext.m_iOrganisation;
}
}
else if (dExecutedEntity >= P.FIRST_KEYWORD_INDEX)
{
oCommandLine.ExecutedEntity = GetKeywordView.dGetClass(dExecutedEntity);
oCommandLine.ContentName = GetKeywordView.sGetName(dExecutedEntity, m_dLanguage);
}
else if (bIsA(dExecutedEntity, P.ATTRIBUTE))
{
oCommandLine.ExecutedEntity = dExecutedEntity;
oCommandLine.ContentName = sEntityContent;
}
else
{
oCommandLine.ContentName = sEntityContent;
}
}
else
{
if (bIsA(dExecutedEntity, P.IDENTIFIER))
{
CIdentifier oIdentifierObject;
dErrorCode = EntityManager.dConvert(sEntityContent, out oIdentifierObject);
if (dErrorCode == ec.ST_SUCCEED)
{
oCommandLine.vAdd(P.IDENTIFIER, oIdentifierObject);
}
}
else if (bIsA(dExecutedEntity, P.AGENT))
{
oCommandLine.ContentIndex = m_oProfileView.dGetProfileIndex(sEntityContent);
if (IsNotUsed(oCommandLine.ContentIndex)) {
dErrorCode = ec.ST_ORGANISATION_ADD_MEMBER_NAME_IS_NOT_KNOWN;
}
}
else if (bIsA(dExecutedEntity, P.ORGANISATION))
{
oCommandLine.ContentIndex = m_oOrganisationView.GetOrganisationTable.dGetIndex(sEntityContent);
if (IsNotUsed(oCommandLine.ContentIndex))
{
dErrorCode = ec.ST_ORGANISATION_CREATION_ORGANISATION_NAME_UNKNOWN;
}
}
else if (bIsA(dExecutedEntity, P.MEME))
{
oCommandLine.ContentIndex = ToSIndex(sEntityContent);
if (IsNotUsed(oCommandLine.ContentIndex))
{
dErrorCode = ec.ST_OPINION_UNDEFINED_MEME;
}
}
else if (dExecutedEntity >= P.FIRST_KEYWORD_INDEX)
{
oCommandLine.ExecutedEntity = GetKeywordView.dGetClass(dExecutedEntity);
oCommandLine.ContentName = GetKeywordView.sGetName(dExecutedEntity, m_dLanguage);
oCommandLine.ContentText = sEntityContent;
}
else if (bIsA(dExecutedEntity, P.ATTRIBUTE) )
{
oCommandLine.ExecutedEntity = dExecutedEntity;
oCommandLine.ContentName = sEntityContent;
}
else if (bIsA(dExecutedEntity, P.FUNCTION ))
{
oCommandLine.ExecutedEntity = dExecutedEntity;
oCommandLine.ContentName = sEntityContent;
}
}
oCommandLine.vAdd(dExecutedEntity, dErrorCode); dErrorCode = ec.ST_SUCCEED;
P[] dOptionArray = CEntityManager.Instance(m_dLanguage).OptionEntityArray;
for (int i = 0; i < dOptionArray.Length; i++)
{
CTrace.i().vWriteLn(ENMessage.CommandParsing, "dOptionArray[i]=" + dOptionArray[i]
+ " dExecutedEntity = " + dExecutedEntity + " Type=" + EntityManager.dGetType(dExecutedEntity));
P dOptionParameter = CEntityManager.Instance(m_dLanguage).dGet(dOptionArray[i], IS_OPTION_RELATION);
if (dOptionArray[i] != dExecutedEntity)
{
if (bIsA(dOptionParameter, P.EXECUTED_ENTITY_TYPE))
{
dOptionParameter = dExecutedEntityType;
}
if (bIsA(dOptionParameter, P.STRING_TYPE))
{
oCommandLine.vAdd(dOptionArray[i], sGetOptionParameter(dOptionArray[i], sOptionString));
}
else if (bIsA(dOptionParameter, P.P_TYPE))
{
oCommandLine.vAdd(dOptionArray[i], dGetOptionParameter(dOptionArray[i], sOptionString));
}
else if (bIsA(dOptionParameter, P.AVATAR_SINDEX_TYPE))
{
if (dOptionArray[i] == P.AVATAR)
{
string sName;
oCommandLine.vAdd(P.SENDER, iGetAgentOption(dOptionArray[i], sOptionString, m_oCommandContext, out sName));
oCommandLine.vAdd(CEntityManager.Instance(P.ENGLISH).dGet(dOptionArray[i], HAS_NAME_RELATION), sName);
}
else
{
string sName;
oCommandLine.vAdd(dOptionArray[i], iGetAgentOption(dOptionArray[i], sOptionString, m_oCommandContext, out sName));
oCommandLine.vAdd(CEntityManager.Instance(P.ENGLISH).dGet(dOptionArray[i], HAS_NAME_RELATION), sName);
}
}
else if (bIsA(dOptionParameter, P.COMMITTEE_SINDEX_TYPE) || bIsA(dOptionParameter, P.ORGANISATION_INDEX_TYPE))
{
string sName;
SIndex oCommitteIndex = iGetOrganisationOption(dOptionArray[i], sOptionString, out sName);
oCommandLine.OrganisationIndex = oCommitteIndex;
if (oCommitteIndex.dSubIndex == ORGANISATION_ROOT_SUB_INDEX)
{
oCommandLine.vAdd(CEntityManager.Instance(P.ENGLISH).dGet(P.ORGANISATION, HAS_NAME_RELATION), sName);
}
else
{
oCommandLine.vAdd(CEntityManager.Instance(P.ENGLISH).dGet(P.COMMITTEE, HAS_NAME_RELATION), sName);
}
}
else if (bIsA(dOptionParameter, P.ENTITY_ARRAY_TYPE))
{
oCommandLine.vAppend(dOptionArray[i], this.eaGetOptionParameter(dOptionArray[i], sOptionString));
}
else if (bIsA(dOptionParameter, P.SINDEX_TYPE))
{
oCommandLine.vAdd(dOptionArray[i], ToSIndex(this.sGetOptionParameter(dOptionArray[i], sOptionString)));
}
else if (bIsA(dOptionParameter, P.IDENTIFIER_TYPE))
{
CTrace.i().vWriteLn(ENMessage.Function, "oContext = " + m_oCommandContext.csDump() );
CIdentifier oIdentifier= this.idGetOptionParameter(dOptionArray[i], sOptionString);
if (dOptionArray[i] == P.THEME || dOptionArray[i] == P.CATEGORY)
{
oCommandLine.vAdd(P.IDENTIFIER, oIdentifier );
}
else if ((dOptionArray[i] == P.TO || dOptionArray[i] == P.AGAINST) && oIdentifier != null)
{
// CTrace.i().vWriteLn(ENMessage.Function, oIdentifier.csDump());
oCommandLine.vAdd(P.IDENTIFIER_RESULT, oIdentifier );
}
else
{
oCommandLine.vAdd(dOptionArray[i],oIdentifier);
}
}
else if (bIsA(dOptionParameter, P.COMMAND_LINE_TYPE))
{
oCommandLine.vAdd(dOptionArray[i], oCommandLine.ContentCommandLine);
}
else if (dOptionParameter != P.NONE)
{
dErrorCode = ec.ST_OPTION_PARAMETER_TYPE_IS_UNKNOWN;
}
oCommandLine.vAdd(dOptionParameter, dErrorCode); dErrorCode = ec.ST_SUCCEED;
}
}
CTrace.i().vWriteLn(ENMessage.CommandParsing, oCommandLine.csDump());
return dErrorCode;
}
public bool bIsA(P dEntity, P dEntityParent) {
return CEntityManager.Instance( m_dLanguage).bIsA(dEntity, dEntityParent);
}
public bool bIsType(P dEntity, P dType)
{
return CEntityManager.Instance(m_dLanguage).bIsA(CEntityManager.Instance(m_dLanguage).dGetType(dEntity), dType);
}
public CDbEntityManager.CDbEntityNameView GetKeywordView
{
get
{
return CDbEntityManager.Instance(this.sDatabaseName, m_dLanguage).GetKeywordView;
}
}
public ec dFindAttribute(P dExecutedEntity, string sEntityContent, out string sAttributeName, out string sAttributeContent,
out P dExistingType)
{
sAttributeName = "";
sAttributeContent = "";
ec dErrorCode = ec.ST_SUCCEED;
P dExecutedEntityClass = GetKeywordView.dGetClass(dExecutedEntity);
dExistingType = P.NOT_USED;
P dKindOfEntity;
if (dExecutedEntityClass == P.ENTITY_ROOT)
{
dKindOfEntity = dExecutedEntity;
dErrorCode = dGetEquation(sEntityContent, out sAttributeName, out sAttributeContent);
dExistingType = P.NOT_USED;
}
else
{
dKindOfEntity = GetKeywordView.dGetClass(dExecutedEntity);
if (IsNotUsed(dKindOfEntity))
{
dErrorCode = ec.ST_ATTRIBUTE_THE_CLASS_ATTRIBUTE_IS_UNKNOWN;
}
else {
sAttributeName = EntityManager.sGetName(dExecutedEntity);
sAttributeContent = sEntityContent;
dExistingType = EntityManager.dGetType(dExecutedEntity);
}
}
sAttributeName = sAttributeName.ToLower();
sAttributeContent = sAttributeContent.ToLower();
return dErrorCode;
}
public string sGetOptionParameter(P dOption1, P dOption2, string csOptionString)
{
string sOption = sGetOptionParameter(dOption1, csOptionString);
if (sOption == null)
{
sOption = sGetOptionParameter(dOption2, csOptionString);
}
return sOption;
}
public string sGetOptionParameter(P dOption, string csOptionString)
{
string sOptionValue =CCommandFactoryBase.csGetParameter(ToString(dOption), csOptionString);
if (sOptionValue== null )
{
sOptionValue = CCommandFactoryBase.csGetParameter(CEntityManager.Instance(P.ENGLISH).sGetEntityAbreviation(dOption), csOptionString);
string sOptionValueIfVariable = m_oCommandContext.sGetVariable(sOptionValue);
if (sOptionValueIfVariable != null)
{
sOptionValue = sOptionValueIfVariable;
}
}
CTrace.i().vWriteLn(ENMessage.CommandParsing, "sGetOptionParameter dOption=" + dOption + " sOptionValue =" + sOptionValue);
return sOptionValue;
}
public CCommandLine clGetOptionParameter(P dOption, string csOptionString)
{
string sOptionValue = sGetOptionParameter( dOption, csOptionString);
CCommandLine oCommandLine =m_oCommandContext.clGetVariable(sOptionValue);
if ( oCommandLine== null)
{
CCommandLine oVariableCommandLine;
CCommandLineFactory oCommandLineFactory = new CCommandLineFactory(sDatabaseName);
oCommandLineFactory.vSet(ref m_oCommandContext);
if(oCommandLineFactory.dLoadOption(sOptionValue,
out oVariableCommandLine) == ec.ST_SUCCEED) {
return oVariableCommandLine;
}
}
return null;
}
public CEntityArray eaGetOptionParameter(P dOption, string csOptionString)
{
string sCategoryOption = sGetOptionParameter(dOption, csOptionString);
if (sCategoryOption== null)
{
return null;
}
else
{
CEntityArray oCategoryOption;
EntityManager.dConvert(sCategoryOption, out oCategoryOption);
return oCategoryOption;
}
}
public CIdentifier idGetOptionParameter(P dOption, string csOptionString)
{
string sCategoryOption = sGetOptionParameter(dOption, csOptionString);
CIdentifier oCategoryIdentifier = m_oCommandContext.idGetVariable(sCategoryOption);
if ( oCategoryIdentifier == null)
{
EntityManager.dConvert(sCategoryOption, out oCategoryIdentifier);
}
return oCategoryIdentifier;
}
public SEntity eGetOptionParameter(P dOption, string csOptionString)
{
P dParameter = dGetOptionParameter(dOption, csOptionString);
if (IsUsed(dOption))
{
return new SEntity(dOption, (int)dParameter);
}
return CEntityManager.NOT_USED_SENTITY;
}
public P dGetOptionParameter(P dOption, string csOptionString)
{
if (dOption == P.LANGUAGE)
{
return dGetLanguageOption(csOptionString);
}
else
{
string csEntityIndex = sGetOptionParameter(dOption, csOptionString);
P dEntityIndex = CEntityManager.Instance(P.ENGLISH).dFindEntity(csEntityIndex);
return dEntityIndex;
}
}
public SIndex iGetAgentOption(P dOption, string sOptionString, CCommandContext oContext, out string sAgentName)
{
SIndex oAgentIndex = CDbEPBase.NOT_USED_SINDEX;
sAgentName = sGetOptionParameter(dOption, sOptionString);
if ( sAgentName == ToString(P.MYSELF)) {
oAgentIndex = oContext.SenderIndex;
}
else if (sAgentName == ToString(P.PRIVATE))
{
oAgentIndex = oContext.SenderIndex;
oAgentIndex.dSubIndex = PRIVATE_PROFILE_SUB_INDEX;
}
else if (sAgentName == ToString(P.PUBLIC))
{
oAgentIndex = oContext.SenderIndex;
oAgentIndex.dSubIndex = PUBLIC_PROFILE_SUB_INDEX;
}
else if (sAgentName != null)
{
oAgentIndex = m_oProfileView.dGetProfileIndex(sAgentName);
}
/* else
{
oAgentIndex = oContext.SenderIndex;
}*/
CTrace.i().vWriteLn(ENMessage.CommandParsing, "iGetAgentOption( " + dOption + ")= " + sAgentName + "(" + oAgentIndex + ")");
return oAgentIndex;
}
protected SIndex iGetOrganisationOption(P dOption, string sOptionString, out string sOrganisationName)
{
sOrganisationName = sGetOptionParameter(dOption, sOptionString);
SIndex oOrganisationIndex = NOT_USED_SINDEX;
if (sOrganisationName != null)
{
oOrganisationIndex = m_oOrganisationView.dGetOrganisationIndex(sOrganisationName);
CTrace.i().vWriteLn(ENMessage.CommandParsing, " iGetOrganisationOption( " + dOption + ")= " + sOrganisationName + "(" + oOrganisationIndex
+ ")");
}
return oOrganisationIndex;
}
protected P dGetLanguageOption(string sOptionString)
{
string csLanguageOption = sGetOptionParameter(P.LANGUAGE, sOptionString);
m_dLanguage = CEntityManager.Instance(P.ENGLISH).dFindEntity(csLanguageOption);
if (m_dLanguage == P.LANGUAGE) m_dLanguage = P.ENGLISH;
return m_dLanguage;
}
string m_sSynopsisUsed;
public string sGetSynopsis(CCommandLine oCommandLine)
{
m_sSynopsisUsed = "";
m_sSynopsisUsed = oCommandLine.Command.ToString().ToLower() + ' ';
P dSynopsisEntity;
if (oCommandLine.ExecutedEntity== P.MEME)
{
dSynopsisEntity = P.IDENTIFIER;
}
else {
dSynopsisEntity = oCommandLine.ExecutedEntity;
}
m_sSynopsisUsed += dSynopsisEntity.ToString().ToLower();
if (oCommandLine.ContentType == typeof(CEntityArray))
{
string sAddressConvert;
ec dErrorCode = m_oProfileView.GetIdentifierView.dConvert(oCommandLine.idFind(P.IDENTIFIER), true, out sAddressConvert);
m_sSynopsisUsed += ' ' + sAddressConvert;
}
else if (oCommandLine.ContentType == typeof(string))
{
m_sSynopsisUsed += ' ' + oCommandLine.ContentName;
if (oCommandLine.ContentText != null)
{
m_sSynopsisUsed += "=" + oCommandLine.ContentText;
}
}
else if (oCommandLine.ContentType == typeof(CCommandLine))
{
m_sSynopsisUsed += ' ' + oCommandLine.ContentName;
if (oCommandLine.ContentCommandLine != null)
{
m_sSynopsisUsed += "=(" + sGetSynopsis(oCommandLine.ContentCommandLine) + ')';
}
}
else if (oCommandLine.ContentType == typeof(SIndex))
{
string sContentName = null;
if (bIsA(oCommandLine.ExecutedEntity, P.AGENT))
{
SIndex oAvatarIndex = oCommandLine.ContentIndex;
sContentName = m_oProfileView.GetMasterTable.sGetName(oAvatarIndex);
}
else if (bIsA(oCommandLine.ExecutedEntity, P.ORGANISATION))
{
sContentName = m_oOrganisationView.GetOrganisationTable.sGetName(oCommandLine.ContentIndex);
}
else if (bIsA(oCommandLine.ExecutedEntity, P.MEME))
{
SIndex oIndex = oCommandLine.ContentIndex;
CIdentifier oIdentifier;
m_oProfileView.GetIdentifierView.dGetSelect(oIndex, out oIdentifier);
Debug.WriteLine("oIdentifier= " + oIdentifier.csDump());
m_oProfileView.GetIdentifierView.dConvert( oIdentifier, true, out sContentName);
Debug.WriteLine("sContentName = " + sContentName );
}
if (sContentName == null) sContentName = oCommandLine.ContentName;
m_sSynopsisUsed += ' ' + sContentName;
}
if (oCommandLine.ExecutedEntity == P.AVATAR)
{
vAddAgentToSynopsis(P.PARENT, oCommandLine.iFind(P.PARENT));
}
else if (oCommandLine.ExecutedEntity == P.ORGANISATION)
{
vAddOrganisationToSynopsis(P.PARENT, oCommandLine.iFind(P.PARENT));
}
vAddAgentToSynopsis(P.AVATAR, oCommandLine.SenderIndex);
vAddAgentToSynopsis(P.MEMBER, oCommandLine.MemberIndex);
vAddAgentToSynopsis(P.AUTHOR, oCommandLine.AuthorIndex);
vAddToSynopsis(P.LANGUAGE, oCommandLine.Language);
/* vAddToSynopsis(P.TYPE, oCommandLine.AttributeType);
vAddToSynopsis(oCommandLine.pFind(P.TRACE));
vAddToSynopsis(oCommandLine.pFind(P.ENCRYPTED));
* */
SortedList oOptionList = oCommandLine.GetSortedList();
foreach (DictionaryEntry oOption in oOptionList)
{
/* if (oOption.Value.GetType() == typeof(Boolean) && ((bool)oOption.Value))
{
vAddToSynopsis( (P)oOption.Key);
}
else
* */
if (oOption.Value.GetType() == typeof(P))
{
if ((P)oOption.Key != P.LANGUAGE)
{
vAddToSynopsis((P)oOption.Key, (P)oOption.Value);
}
}
else if (oOption.Value.GetType() == typeof(string))
{
vAddToSynopsis((P)oOption.Key, (string)oOption.Value);
}
else if (oOption.Value.GetType() == typeof(CEntityArray))
{
vAddToSynopsis((P)oOption.Key, (CEntityArray)oOption.Value);
}
else if (oOption.Value.GetType() == typeof(CIdentifier))
{
vAddToSynopsis((P)oOption.Key, (CIdentifier)oOption.Value);
}
else if (oOption.Value.GetType() == typeof(SIndex))
{
if (bIsA(oCommandLine.ExecutedEntity, P.MEME) && (P)oOption.Key == P.AGAINST)
{
SIndex oIndex = (SIndex)oOption.Value;
CIdentifier oIdentifier;string sOptionValue;
m_oProfileView.GetIdentifierView.dGetSelect(oIndex, out oIdentifier);
m_oProfileView.GetIdentifierView.dConvert( oIdentifier, true, out sOptionValue);
Debug.WriteLine("oIdentifier= " + oIdentifier.csDump());
vAddToSynopsis((P)oOption.Key, sOptionValue);
}
else {
Debug.WriteLine("(P)oOption.Key= " + (P)oOption.Key + "sOptionValue = " + oOption.Value);
}
}
else if (oOption.Value.GetType() == typeof(Int32))
{
int dValue= (int)oOption.Value;
if ( IsUsed(dValue))
{
vAddToSynopsis((P)oOption.Key, dValue.ToString() );
}
}
else
{
Debug.Assert(false, oOption.Value.GetType().ToString() + " is unknown oOption.Value=" + oOption.Value);
}
}
return m_sSynopsisUsed;
}
protected void vAddToSynopsis(P dOption, string sParameter)
{
string sOptionName = ToString(dOption);
if (IsUsed(dOption) && sParameter != null && sParameter != "" && m_sSynopsisUsed.IndexOf(sOptionName) <= 0)
{
m_sSynopsisUsed += " -" + sOptionName + ":" + sParameter;
}
}
protected void vAddToSynopsis(P dOption)
{
vAddToSynopsis(dOption, P.NONE);
}
protected void vAddToSynopsis(P dOption, CEntityArray oEntityArray)
{
string sOptionName = ToString(dOption);
string sAddressConvert;
ec dErrorCode = EntityManager.dConvert(oEntityArray, out sAddressConvert);
if (IsUsed(dOption) && sAddressConvert != null && m_sSynopsisUsed.IndexOf(sOptionName) <= 0 && m_sSynopsisUsed.IndexOf(sAddressConvert)
<=0)
{
m_sSynopsisUsed += " -" + sOptionName + ":" + sAddressConvert;
}
}
protected void vAddToSynopsis(P dOption, CIdentifier idIdentifier)
{
string sOptionName = ToString(dOption);
string sAddressConvert;
ec dErrorCode = m_oProfileView.GetIdentifierView.dConvert(idIdentifier, true, out sAddressConvert);
if (IsUsed(dOption) && sAddressConvert != null && m_sSynopsisUsed.IndexOf(sOptionName) <= 0 && m_sSynopsisUsed.IndexOf(sAddressConvert)
<= 0)
{
m_sSynopsisUsed += " -" + sOptionName + ":" + sAddressConvert;
}
}
protected void vAddToSynopsis(P dOption, P dEntityId)
{
string sOptionName = ToString(dOption);
if (IsUsed(dOption) && IsUsed(dEntityId) && m_sSynopsisUsed.IndexOf(sOptionName) <= 0)
{
m_sSynopsisUsed += " -" + sOptionName;
if (dEntityId != P.NONE)
{
m_sSynopsisUsed +=":" + ToString(dEntityId);
}
}
}
protected void vAddAgentToSynopsis(P dOption, SIndex oAvatarID)
{
if (IsUsed(oAvatarID) && m_sSynopsisUsed.IndexOf(ToString(dOption)) <= 0)
{
m_sSynopsisUsed += " -" + ToString(dOption) + ":" + m_oProfileView.GetMasterTable.sGetName(oAvatarID);
}
}
protected void vAddOrganisationToSynopsis(P dOption, SIndex oOrganisation)
{
if (IsUsed(oOrganisation) && m_sSynopsisUsed.IndexOf(ToString(dOption)) <= 0)
{
m_sSynopsisUsed += " -" + ToString(dOption) + ":" + m_oOrganisationView.GetOrganisationTable.sGetName(oOrganisation);
}
}
}
}
|
|
|
|
|
|
|
|
Enter supporting content here
|
|
|
|