Exemplo n.º 1
0
        /// <summary>
        /// to select reservation Infos accorrding to given criterion
        /// </summary>
        public static ReservationInfo[] SelectReservationInfo(string labServerGuid, int experimentInfoID, int credentialSetID, DateTime timeAfter, DateTime timeBefore)
        {
            List<ReservationInfo> reInfos = new List<ReservationInfo>();

            StringBuilder sqlQuery = new StringBuilder();
            sqlQuery.Append("select Reservation_Info_ID, resource_ID,Start_Time, End_Time, R.Experiment_Info_ID, Credential_Set_ID, Status from Reservation_Info AS R Join Experiment_Info AS E on (R.Experiment_Info_ID = E.Experiment_Info_ID) where E.Lab_server_GUID = " + "'" + labServerGuid + "'");
            if (experimentInfoID!=-1)
            {
                sqlQuery.Append(" and R.Experiment_Info_ID = " + experimentInfoID);
            }
            if (credentialSetID !=-1)
            {
                    sqlQuery.Append(" and R.Credential_Set_ID =" + credentialSetID);
            }

            if (timeBefore.CompareTo(DateTime.MinValue)!=0)
            {

                sqlQuery.Append(" and R.Start_Time <= '"+timeBefore+"'");
            }

            if (timeAfter.CompareTo(DateTime.MinValue)!=0)
            {

                sqlQuery.Append(" and R.Start_Time >= '"+timeAfter+"'");
            }

            sqlQuery.Append("ORDER BY R.Start_Time asc");

            DbConnection myConnection = FactoryDB.GetConnection();
            DbCommand myCommand = myConnection.CreateCommand();
            myCommand.CommandType = CommandType.Text;
            myCommand.CommandText = sqlQuery.ToString(); ;

            try
            {
                myConnection.Open ();

                // get ReservationInfo info from table reservation_Info
                DbDataReader myReader = myCommand.ExecuteReader ();
                while(myReader.Read ())
                {
                    ReservationInfo ri = new ReservationInfo();
                    ri.reservationInfoId = Convert.ToInt32( myReader["Reservation_Info_ID"]); //casting to (long) didn't work
                    if (myReader["Resource_ID"] != System.DBNull.Value)
                        ri.resourceId = Convert.ToInt32(myReader["Resource_ID"]);
                    if(myReader["Start_Time"] != System.DBNull.Value )
                        ri.startTime = DateUtil.SpecifyUTC((DateTime) myReader["Start_Time"]);
                    if(myReader["End_Time"] != System.DBNull.Value )
                        ri.endTime= DateUtil.SpecifyUTC((DateTime) myReader["End_Time"]);
                    if(myReader["Resource_ID"]!=System.DBNull.Value)
                        ri.resourceId=Convert.ToInt32(myReader["Resource_ID"]);
                    if(myReader["Credential_Set_ID"] != System.DBNull.Value )
                        ri.credentialSetId = Convert.ToInt32(myReader["Credential_Set_ID"]);
                    if (myReader["Status"] != System.DBNull.Value)
                        ri.statusCode= Convert.ToInt32(myReader["Status"]);

                    reInfos.Add(ri);

                }
                myReader.Close ();

            }
            catch (Exception ex)
            {
                throw new Exception("Exception thrown in selecting reservation information",ex);
            }
            finally
            {
                myConnection.Close();
            }

            return reInfos.ToArray();
        }
Exemplo n.º 2
0
        public static int RevokeReservation(ReservationInfo ri)
        {
            int count = 0;
            LssCredentialSet[] sets = DBManager.GetCredentialSets(new int[] { ri.credentialSetId });
            LssExperimentInfo[] exps = DBManager.GetExperimentInfos(new int[] { ri.experimentInfoId });
            if (sets != null && sets.Length > 0 && exps != null && exps.Length > 0)
            {

                USSInfo uss = DBManager.GetUSSInfo(sets[0].ussGuid);
                if (uss != null)
                {
                    ProcessAgentDB paDB = new ProcessAgentDB();
                    UserSchedulingProxy ussProxy = new UserSchedulingProxy();
                    OperationAuthHeader header = new OperationAuthHeader();
                    header.coupon = paDB.GetCoupon(uss.couponId, uss.domainGuid);
                    ussProxy.OperationAuthHeaderValue = header;
                    ussProxy.Url = uss.ussUrl;

                    int num = ussProxy.RevokeReservation(sets[0].serviceBrokerGuid, sets[0].groupName,
                        exps[0].labServerGuid, exps[0].labClientGuid, ri.Start, ri.End, "The reservation time assigned to this reservation is being removed");
                    if (num > 0)
                    {
                        LSSSchedulingAPI.RemoveReservationInfoByIDs(new int[] { ri.reservationInfoId });
                        count += num;
                    }
                }
             }

            return count;
        }
Exemplo n.º 3
0
        /// <summary>
        /// returns an array of the immutable ReservationInfo objects that correspond to the supplied reservationInfoIDs
        /// </summary>
        /// <param name="reservationInfoIDs"></param>
        /// <returns></returns>an array ofimmutable objects describing the specified reservations
        public static ReservationInfo[] GetReservationInfos(int[] reservationInfoIDs)
        {
            List<ReservationInfo> reservationInfos = null;
            if (reservationInfoIDs.Length > 0)
            {
                reservationInfos = new List<ReservationInfo>();
                // create sql connection
                DbConnection connection = FactoryDB.GetConnection();

                // create sql command
                // command executes the "RetrieveReservationInfoByID" stored procedure
                DbCommand cmd = FactoryDB.CreateCommand("ReservationInfo_RetrieveByID", connection);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add(FactoryDB.CreateParameter(cmd,"@reservationInfoID", null, DbType.Int32));
                //execute the command
                try
                {
                    connection.Open();
                    for (int i = 0; i < reservationInfoIDs.Length; i++)
                    {
                        // populate the parameters
                        cmd.Parameters["@reservationInfoID"].Value = reservationInfoIDs[i];
                        DbDataReader dataReader = null;
                        dataReader = cmd.ExecuteReader();
                        while (dataReader.Read())
                        {
                            ReservationInfo reservationInfo = new ReservationInfo();
                            reservationInfo.reservationInfoId = reservationInfoIDs[i];
                            reservationInfo.resourceId = dataReader.GetInt32(0);
                            if (dataReader[1] != System.DBNull.Value)
                            {
                                DateTime test = dataReader.GetDateTime(1);
                                reservationInfo.startTime = DateUtil.SpecifyUTC(dataReader.GetDateTime(1));
                            }
                            if (dataReader[2] != System.DBNull.Value)
                                reservationInfo.endTime = DateUtil.SpecifyUTC(dataReader.GetDateTime(2));
                            if (dataReader[3] != System.DBNull.Value)
                                reservationInfo.experimentInfoId = (int)dataReader.GetInt32(3);
                            if (dataReader[4] != System.DBNull.Value)
                                reservationInfo.credentialSetId = (int)dataReader.GetInt32(4);
                            if (dataReader[5] != System.DBNull.Value)
                                reservationInfo.statusCode = (int)dataReader.GetInt32(5);
                            reservationInfos.Add(reservationInfo);

                        }
                        dataReader.Close();
                    }
                }

                catch (Exception ex)
                {
                    throw new Exception("Exception thrown in get reservationInfo", ex);
                }
                finally
                {
                    connection.Close();
                }
            }
            return reservationInfos.ToArray();
        }
Exemplo n.º 4
0
        /* TO DO */
        public int RevokeReservation(ReservationInfo ri, string message)
        {
            int count = 0;
            LssCredentialSet[] sets = GetCredentialSets(new int[] { ri.credentialSetId });
            LssExperimentInfo[] exps = GetExperimentInfos(new int[] { ri.experimentInfoId });
            if (sets != null && sets.Length > 0 && exps != null && exps.Length > 0)
            {

                USSInfo uss = GetUSSInfo(ri.ussId);
                if (uss != null)
                {

                    UserSchedulingProxy ussProxy = new UserSchedulingProxy();
                    OperationAuthHeader header = new OperationAuthHeader();
                    header.coupon = GetCoupon(uss.revokeCouponId, uss.domainGuid);
                    ussProxy.OperationAuthHeaderValue = header;
                    ussProxy.Url = uss.ussUrl;

                    int num = ussProxy.RevokeReservation(sets[0].serviceBrokerGuid, sets[0].groupName,
                        exps[0].labServerGuid, exps[0].labClientGuid, ri.Start, ri.End, message);
                    if (num > 0)
                    {
                        RemoveReservationInfoByIDs(new int[] { ri.reservationInfoId });
                        count += num;
                    }
                }
            }

            return count;
        }