public int RevokeReservation(string serviceBrokerGuid, string groupName,
            string labServerGuid, string labClientGuid, DateTime startTime, DateTime endTime, string message)
        {
            bool status = false;
            bool fromISB = false;
            int count = 0;
            Coupon opCoupon = new Coupon();
            opCoupon.couponId = opHeader.coupon.couponId;
            opCoupon.passkey = opHeader.coupon.passkey;
            opCoupon.issuerGuid = opHeader.coupon.issuerGuid;
            UserSchedulingDB dbManager = new UserSchedulingDB();
            try
            {
                Ticket retrievedTicket = dbManager.RetrieveAndVerify(opCoupon, TicketTypes.REVOKE_RESERVATION);
                if (retrievedTicket.payload != null && retrievedTicket.payload.Length > 0)
                {
                    XmlQueryDoc revokeDoc = new XmlQueryDoc(retrievedTicket.payload);
                    string sourceStr = revokeDoc.Query("RevokeReservationPayload/source");
                    if (sourceStr != null && sourceStr.CompareTo("ISB") == 0)
                    {
                        fromISB = true;
                    }
                }
                DateTime targetStart = new DateTime(startTime.Year, startTime.Month, startTime.Day,
                    startTime.Hour, startTime.Minute, 0, startTime.Kind);
                if (targetStart.Kind != DateTimeKind.Utc)
                    targetStart = targetStart.ToUniversalTime();
                DateTime targetEnd = new DateTime(endTime.Year, endTime.Month, endTime.Day,
                    endTime.Hour, endTime.Minute, 0, endTime.Kind);
                if (targetEnd.Kind != DateTimeKind.Utc)
                    targetEnd = targetEnd.ToUniversalTime();
                if (fromISB)
                { // Need to forward to LSS
                    string lssUrl = dbManager.ListLssUrlByExperiment(labClientGuid, labServerGuid);
                    if (lssUrl != null && lssUrl.Length > 0)
                    {
                        LabSchedulingProxy lssProxy = new LabSchedulingProxy();
                        lssProxy.OperationAuthHeaderValue = new OperationAuthHeader();
                        lssProxy.OperationAuthHeaderValue.coupon = opCoupon;
                        lssProxy.Url = lssUrl;
                        int rCount = lssProxy.RemoveReservation(serviceBrokerGuid, groupName, ProcessAgentDB.ServiceGuid,
                            labServerGuid, labClientGuid, targetStart, targetEnd);
                    }
                }

                ReservationData[] ris = dbManager.GetReservations(serviceBrokerGuid, null, groupName,
                    labServerGuid, labClientGuid, targetStart, targetEnd);

                if (ris != null && ris.Length > 0)
                {

                    InteractiveSBProxy sbProxy = new InteractiveSBProxy();
                    ProcessAgentInfo sbInfo = dbManager.GetProcessAgentInfo(ProcessAgentDB.ServiceAgent.domainGuid);
                    AgentAuthHeader header = new AgentAuthHeader();
                    header.coupon = sbInfo.identOut;
                    header.agentGuid = ProcessAgentDB.ServiceGuid;
                    sbProxy.AgentAuthHeaderValue = header;
                    sbProxy.Url = sbInfo.webServiceUrl;
                    foreach (ReservationData rd in ris)
                    {

                        status = dbManager.RevokeReservation(rd.sbGuid, rd.groupName, rd.lsGuid, rd.clientGuid,
                              rd.startTime, rd.endTime, message);
                        if (status)
                        {
                            count++;
                            status = sbProxy.RevokeReservation(rd.sbGuid, rd.userName, rd.groupName, rd.lsGuid, rd.clientGuid,
                              rd.startTime, rd.endTime, message);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                throw new Exception("USS: RevokeReservation -> ",e);
            }
            return count;
        }
        public Reservation[] ListReservations(string serviceBrokerGuid, string userName, 
            string labServerGuid, string labClientGuid, DateTime startTime, DateTime endTime)
        {
            UserSchedulingDB dbManager = new UserSchedulingDB();
            Ticket retrievedTicket = dbManager.RetrieveAndVerify(opHeader.coupon, TicketTypes.REDEEM_RESERVATION);
            if (retrievedTicket.IsExpired())
            {
                throw new AccessDeniedException("The reservation ticket has expired, Please re-login.");
            }
            //used to check ticketPayload
            string user = null;
            string group = null;
            string labGuid = null;
            string clientGuid = null;
            string sbGuid = null;

            //Resolved target arguments
            string userTarget = null;
            string labGuidTarget = null;
            string clientGuidTarget = null;
            string lssUrl = null;
            string lssGuid = null;
            XmlDocument payload = new XmlDocument();
            payload.LoadXml(retrievedTicket.payload);

            sbGuid = payload.GetElementsByTagName("sbGuid")[0].InnerText;
            user = payload.GetElementsByTagName("userName")[0].InnerText;
            group = payload.GetElementsByTagName("groupName")[0].InnerText;
            clientGuid = payload.GetElementsByTagName("clientGuid")[0].InnerText;
            labGuid = payload.GetElementsByTagName("labServerGuid")[0].InnerText;

            lssUrl = dbManager.ListLssUrlByExperiment(clientGuid, labServerGuid);
            lssGuid = dbManager.ListLssIdByExperiment(clientGuid, labServerGuid);

            userTarget = Utilities.ResolveArguments(userName, user, true);
            clientGuidTarget = Utilities.ResolveArguments(labClientGuid, clientGuid, false);
            labGuidTarget = Utilities.ResolveArguments(labServerGuid, labGuid, false);

            DateTime targetStart = new DateTime(startTime.Year, startTime.Month, startTime.Day,
               startTime.Hour, startTime.Minute, 0, startTime.Kind);
            if (targetStart.Kind != DateTimeKind.Utc)
                targetStart = targetStart.ToUniversalTime();
            DateTime targetEnd = new DateTime(endTime.Year, endTime.Month, endTime.Day,
                    endTime.Hour, endTime.Minute, 0, endTime.Kind);
            if (targetEnd.Kind != DateTimeKind.Utc)
                targetEnd = targetEnd.ToUniversalTime();
            ReservationInfo[] resInfos = dbManager.GetReservationInfos(serviceBrokerGuid, userTarget, group,
                labGuidTarget, clientGuidTarget, targetStart, targetEnd);
            if (resInfos != null && resInfos.Length > 0)
            {
                Reservation[] reservations = new Reservation[resInfos.Length];

                for (int i = 0; i < resInfos.Length; i++)
                {
                    reservations[i] = new Reservation(resInfos[i].startTime, resInfos[i].endTime);
                    reservations[i].userName = resInfos[i].userName;
                }
                return reservations;
            }
            else
                return null;
        }