Beispiel #1
0
        /// <summary>
        /// to retrieve agent metadata for agents specified by array of agent IDs 
        /// </summary>
        public static Agent[] SelectAgents( int[] agentIDs )
        {
            Agent[] a = new Agent[agentIDs.Length ];
            for (int i=0; i<agentIDs.Length ; i++)
            {
                a[i] = new Agent();
            }

            DbConnection myConnection = FactoryDB.GetConnection();
            DbCommand myCommand = FactoryDB.CreateCommand("RetrieveAgent", myConnection);
            myCommand.CommandType = CommandType.StoredProcedure;
            myCommand.Parameters .Add(FactoryDB.CreateParameter(myCommand,"@agentID",null,DbType.Int32));

            try
            {
                myConnection.Open ();

                for (int i =0; i < agentIDs.Length ; i++)
                {
                    myCommand.Parameters["@agentID"].Value = agentIDs[i];

                    // get agent info from table agents
                    DbDataReader myReader = myCommand.ExecuteReader ();
                    while(myReader.Read ())
                    {
                        a[i].id = agentIDs[i];

                        int isGroup=0;
                        if(myReader["is_group"] != System.DBNull.Value )
                            isGroup= Convert.ToByte(myReader["is_group"]);
                        if (isGroup==1)
                            a[i].type=Agent.groupType;
                        else
                            a[i].type = Agent.userType;
                        if(myReader["agent_name"] != System.DBNull.Value )
                            a[i].type= (string)(myReader["agent_name"]);
                        /*if(myReader["date_created"] != System.DBNull .Value )
                            a[i].= (string) myReader["date_created"];*/
                    }
                    myReader.Close ();
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Exception thrown SelectGroups. " + ex.Message, ex);
            }
            finally
            {
                myConnection.Close ();
            }

            return a;
        }
Beispiel #2
0
        /// <summary>
        /// to retrieve a list of all the members of a group
        /// </summary>
        public static Agent[] SelectMembersInGroup(int groupID)
        {
            Agent[] members;

            DbConnection myConnection = FactoryDB.GetConnection();
            DbCommand myCommand = FactoryDB.CreateCommand("RetrieveGroupMembers", myConnection);
            myCommand.CommandType = CommandType.StoredProcedure;

            myCommand.Parameters.Add(FactoryDB.CreateParameter(myCommand, "@groupID", groupID, DbType.Int32));

            try
            {
                myConnection.Open ();

                // get Member IDs from table Agent_Hierarchy
                DbDataReader myReader = myCommand.ExecuteReader ();
                ArrayList mIDs = new ArrayList();

                while(myReader.Read ())
                {
                    Agent a = new Agent();
                    if(myReader["agent_id"] != System.DBNull.Value )
                        a.id = Convert.ToInt32(myReader["agent_ID"]);
                    if(myReader["agent_name"] != System.DBNull.Value )
                        a.name = ((string)myReader["agent_name"]);
                    if(Convert.ToInt16(myReader["is_group"]) ==1 )
                        a.type = "Group";
                    else
                        a.type = "User";
                //	memberIDs [i] = (string) myReader["agent_id"];

                    mIDs.Add(a);
                }
                myReader.Close ();

                // Converting to an Agent array
                members = new Agent[mIDs.Count];
                for (int i=0;i <mIDs.Count ; i++)
                {
                    members[i] = (Agent) mIDs[i];
                }

                //mIDs.ToArray();
            }
            catch (Exception ex)
            {
                throw new Exception("Exception thrown Select Group's Members",ex);
            }
            finally
            {
                myConnection.Close ();
            }

            return members;
        }