public TimePeriod[] RetrieveAvailableTimePeriods(string serviceBrokerGuid, string groupName,
            string labServerGuid, string clientGuid, DateTime startTime, DateTime endTime)
        {
            Coupon opCoupon = new Coupon();
            opCoupon.couponId = opHeader.coupon.couponId;
            opCoupon.passkey = opHeader.coupon.passkey;
            opCoupon.issuerGuid = opHeader.coupon.issuerGuid;
            try
            {
                UserSchedulingDB dbManager = new UserSchedulingDB();
                Ticket ssTicket = dbManager.RetrieveAndVerify(opCoupon, TicketTypes.SCHEDULE_SESSION);

                string lssGuid = dbManager.ListLssIdByExperiment(clientGuid, labServerGuid);
                LSSInfo  lssInfo = dbManager.GetLSSInfo(lssGuid);
                LabSchedulingProxy lssProxy = new LabSchedulingProxy();
                lssProxy.OperationAuthHeaderValue = new OperationAuthHeader();
                lssProxy.OperationAuthHeaderValue.coupon = opCoupon;
                lssProxy.Url = lssInfo.lssUrl;
                TimePeriod[] array = lssProxy.RetrieveAvailableTimePeriods( serviceBrokerGuid, groupName, ProcessAgentDB.ServiceGuid,
                    labServerGuid, clientGuid, startTime, endTime);
                return array;
            }
            catch
            {
                throw;
            }
        }
        public string AddReservation(string serviceBrokerGuid, string userName, string groupName,
            string labServerGuid, string labClientGuid, DateTime startTime, DateTime endTime)
        {
            string message = null;
             Coupon opCoupon = new Coupon();
             UserSchedulingDB dbManager = new UserSchedulingDB();
            opCoupon.couponId = opHeader.coupon.couponId;
            opCoupon.passkey = opHeader.coupon.passkey;
            opCoupon.issuerGuid = opHeader.coupon.issuerGuid;
            string type = TicketTypes.SCHEDULE_SESSION;
            try
            {
                Ticket retrievedTicket = dbManager.RetrieveAndVerify(opCoupon, type);
                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 groupTarget = null;
                string labGuidTarget = null;
                string clientGuidTarget = 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;

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

                string lssGuid = dbManager.ListLssIdByExperiment(labClientGuid, labServerGuid);
                LSSInfo lssInfo = dbManager.GetLSSInfo(lssGuid);
                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();

                LabSchedulingProxy lssProxy = new LabSchedulingProxy();
                lssProxy.OperationAuthHeaderValue = new OperationAuthHeader();
                lssProxy.OperationAuthHeaderValue.coupon = opCoupon;
                lssProxy.Url = lssInfo.lssUrl;
                message = lssProxy.ConfirmReservation( serviceBrokerGuid, groupName, ProcessAgentDB.ServiceGuid,
                    labServerGuid, labClientGuid, targetStart, targetEnd);
                if(message.ToLower().Contains("success")){
                    int infoID = dbManager.ListExperimentInfoIDByExperiment(labServerGuid, labClientGuid);
                    dbManager.AddReservation(userName, serviceBrokerGuid,groupName,infoID,targetStart,targetEnd);
                }
                return message;
            }

            catch (Exception e)
            {
                throw new Exception("USS: AddReservation -> ", e);
            }
            return message;
        }