private Int32 HandleIntList(string sCollectionName, METHOD_CODE nMethodCode, int nParam1, int nParam2)
{
Int32 nReturnValue = (int)RETURN_CODE.SUCCESS;
// Make sure the collection does (or does not) exist.
if (nMethodCode == METHOD_CODE.CREATE && m_IntList.ContainsKey(sCollectionName))
{
// This collection already exists.
return (int)RETURN_CODE.ERROR_COLLECTION_EXISTS;
}
else if (nMethodCode == METHOD_CODE.CREATE_IF_NOT_EXISTS && m_IntList.ContainsKey(sCollectionName))
{
return (int)RETURN_CODE.SUCCESS;
}
else if (nMethodCode == METHOD_CODE.DELETE_IF_EXISTS && !m_IntList.ContainsKey(sCollectionName))
{
return (int)RETURN_CODE.SUCCESS;
}
else if (nMethodCode == METHOD_CODE.EXISTS)
{
SetReturnInt(Convert.ToInt32(m_IntList.ContainsKey(sCollectionName)));
return (int)RETURN_CODE.SUCCESS;
}
// Switch out the DELETE_IF and CREATE_IF functions.
if (nMethodCode == METHOD_CODE.CREATE_IF_NOT_EXISTS) nMethodCode = METHOD_CODE.CREATE;
else if (nMethodCode == METHOD_CODE.DELETE_IF_EXISTS) nMethodCode = METHOD_CODE.DELETE;
// Unless we're creating the collection, make sure it exists.
if (nMethodCode != METHOD_CODE.CREATE && !m_IntList.ContainsKey(sCollectionName))
{
// Collection does not exist, cannot be accessed.
return (int)RETURN_CODE.ERROR_COLLECTION_DOES_NOT_EXIST;
}
// Handle the request.
switch (nMethodCode)
{
case METHOD_CODE.CREATE:
m_IntList.Add(sCollectionName, new List<int>());
break;
case METHOD_CODE.DELETE:
m_IntList.Remove(sCollectionName);
break;
case METHOD_CODE.ADD:
m_IntList[sCollectionName].Add(nParam1);
break;
case METHOD_CODE.CLEAR:
m_IntList[sCollectionName].Clear();
break;
case METHOD_CODE.CONTAINS:
SetReturnInt(Convert.ToInt32(m_IntList[sCollectionName].Contains(nParam1)));
break;
case METHOD_CODE.COUNT:
SetReturnInt(m_IntList[sCollectionName].Count());
break;
case METHOD_CODE.ELEMENT_AT:
SetReturnInt(m_IntList[sCollectionName].ElementAt(nParam1));
break;
case METHOD_CODE.FIRST:
SetReturnInt(m_IntList[sCollectionName].First());
break;
case METHOD_CODE.INDEX_OF:
SetReturnInt(m_IntList[sCollectionName].IndexOf(nParam1));
break;
case METHOD_CODE.INSERT:
m_IntList[sCollectionName].Insert(nParam1, nParam2);
break;
case METHOD_CODE.MAX:
SetReturnInt(m_IntList[sCollectionName].Max());
break;
case METHOD_CODE.MIN:
SetReturnInt(m_IntList[sCollectionName].Min());
break;
case METHOD_CODE.REMOVE:
m_IntList[sCollectionName].Remove(nParam1);
break;
case METHOD_CODE.REMOVE_AT:
m_IntList[sCollectionName].RemoveAt(nParam1);
break;
case METHOD_CODE.REMOVE_RANGE:
m_IntList[sCollectionName].RemoveRange(nParam1, nParam2);
break;
case METHOD_CODE.REVERSE:
m_IntList[sCollectionName].Reverse();
break;
case METHOD_CODE.SORT:
m_IntList[sCollectionName].Sort();
break;
case METHOD_CODE.SUM:
SetReturnInt(m_IntList[sCollectionName].Sum());
break;
default:
nReturnValue = (int)RETURN_CODE.ERROR_COLLECTION_NO_METHOD;
break;
}
return nReturnValue;
}