/// <summary>
    /// Method that does the actual make reservation for the user. 
    /// makes the basis of the parameters from the message and the application database
    /// </summary>
    /// <param name="userName"> the user who is scheduling for the lab; must be registered with the service broker</param>
    /// <param name="groupName">the group name authorized to do a lab</param>
    /// <param name="labServerGuid">lab server which holds the lab that does the actual scheduling</param>
    /// <param name="clientGuid">Guid of the lab being registered for</param>
    /// <param name="start">Start time of a particular period scheduled for</param>
    /// <param name="end">End time of a particular period being scheduled for</param>
    /// <returns>returns a message string that the application bases on for to give the feedback to the user</returns>
    public static string MakeReservation(string userName, string groupName, string labServerGuid,
        string clientGuid, DateTime start, DateTime end)
    {
        string lsGuid = null;
            int status = -1;
            string message = null;
            if (ProcessAgentDB.ServiceAgent != null && ProcessAgentDB.ServiceAgent.domainGuid != null)
            {
                ProcessAgentDB paDb = new ProcessAgentDB();
                ProcessAgentInfo domainServer = paDb.GetProcessAgentInfo(ProcessAgentDB.ServiceAgent.domainGuid);

                InteractiveSBProxy isbProxy = new InteractiveSBProxy();
                isbProxy.AgentAuthHeaderValue = new AgentAuthHeader();
                isbProxy.AgentAuthHeaderValue.agentGuid = ProcessAgentDB.ServiceGuid;
                isbProxy.AgentAuthHeaderValue.coupon = domainServer.identOut;
                isbProxy.Url = domainServer.ServiceUrl;

                string[] types = new string[] { TicketTypes.SCHEDULE_SESSION };

                Coupon opCoupon = isbProxy.RequestAuthorization(types, 600, 			userName, groupName,  labServerGuid, clientGuid);
                if (opCoupon != null)
                {
                    TicketIssuerProxy ticketProxy = new TicketIssuerProxy();
                    ticketProxy.AgentAuthHeaderValue = new AgentAuthHeader();
                    ticketProxy.AgentAuthHeaderValue.agentGuid = ProcessAgentDB.ServiceGuid;
                    ticketProxy.AgentAuthHeaderValue.coupon = domainServer.identOut;
                    ticketProxy.Url = domainServer.ServiceUrl;
                    //the method call below is one which does not returns a null value
                    //in otherwards the ticket value is not created.
                    Ticket ticketSMS = ticketProxy.RedeemTicket(opCoupon, TicketTypes.SCHEDULE_SESSION, ProcessAgentDB.ServiceGuid);
                    if (ticketSMS != null)
                    {
                        if (ticketSMS.payload != null || ticketSMS.payload.Length > 0)
                        {
                            XmlQueryDoc xdoc = new XmlQueryDoc(ticketSMS.payload);
                            string ussURL = xdoc.Query("ScheduleSessionPayload/ussURL");
                            UserSchedulingProxy ussProxy = new UserSchedulingProxy();
                            ussProxy.OperationAuthHeaderValue = new OperationAuthHeader();
                            ussProxy.OperationAuthHeaderValue.coupon = opCoupon;
                            ussProxy.Url = ussURL;

                            TimePeriod[] times = ussProxy.RetrieveAvailableTimePeriods(ProcessAgentDB.ServiceAgent.domainGuid, groupName, labServerGuid,
                                clientGuid, start, end);
                            // Logic to check for final time
                            DateTime resStart = start;
                            DateTime resEnd = end;

                            message = ussProxy.AddReservation(ProcessAgentDB.ServiceAgent.domainGuid, userName, groupName, labServerGuid, clientGuid, resStart, resEnd);
                        }
                    }
                }
                else
                {
                    message = "coupon is null";
                }
            }
            else
            {
                message = "This service is not part of a domain, please contact the administrator!";

            }
            return message;
    }
Example #2
0
        /// <summary>
        /// Retrieves ticket from local database or the SB. Ticket type is needed to retrieve ticket from SB, 
        /// </summary>
        /// <param name="coupon">operation coupon sent by the Process Agent</param>
        /// <param name="ticketType">type of the ticket to be retrieved</param>
        /// <returns>Retrieved ticket</returns>
        public Ticket RetrieveAndVerify(Coupon coupon, string ticketType)
        {
            Ticket theTicket = RetrieveTicket(coupon, ticketType, ServiceGuid);
            if (theTicket == null)
            {
                TicketIssuerProxy ticketIssuerProxy = new TicketIssuerProxy();

                //Get the Service Broker info from the database
                ProcessAgentInfo sbInfo = GetServiceBrokerInfo();

                //get the SB web service URL, and set the proxy's URL accordingly
                ticketIssuerProxy.Url = sbInfo.webServiceUrl;

                iLabs.DataTypes.SoapHeaderTypes.AgentAuthHeader agentAuthHeader = new iLabs.DataTypes.SoapHeaderTypes.AgentAuthHeader();

                //set the SOAP header (of the proxy class) to the agentCoupon
                agentAuthHeader.coupon = sbInfo.identOut;
                agentAuthHeader.agentGuid = ServiceGuid;
                ticketIssuerProxy.AgentAuthHeaderValue = agentAuthHeader;

                //call the RetrieveTicket web service method on the SB (ticket issuer)
                theTicket = ticketIssuerProxy.RedeemTicket(coupon, ticketType, ServiceGuid);
                if (theTicket != null)
                {
                    // If the ticket is no longer valid do not insert it
                    if (!theTicket.IsExpired() && !theTicket.isCancelled)
                    {
                        if (!AuthenticateCoupon(coupon))
                        {
                            // coupon is not in the database
                            InsertCoupon(coupon);
                        }
                        InsertTicket(theTicket);
                    }
                }
            }
            //if ticket not found locally or in in the Ticket issuer (SB) database, throw exception
            if (theTicket == null)
            {
                throw new TicketNotFoundException("The requested ticket was not found. "
                    + "Ticket type: " + ticketType + ". Access denied.");
            }
            if (theTicket.IsExpired() || theTicket.isCancelled)
            {
                     throw new TicketExpiredException("The Retrieved ticket has expired. "
                    + "Ticket type: " + ticketType + ". Access denied.");
            }
            return theTicket;
        }
        public Ticket RedeemTicket(Coupon coupon, string type, string redeemerGuid)
        {
            Ticket ticket = null;
            if (brokerDB.AuthenticateAgentHeader(agentAuthHeader))
            {
                if (coupon.issuerGuid == ProcessAgentDB.ServiceGuid)
                {
                    ticket = brokerDB.RetrieveIssuedTicket(coupon, type, redeemerGuid);
                }
                else
                {
                    ProcessAgentInfo paInfo = brokerDB.GetProcessAgentInfo(coupon.issuerGuid);
                    if (paInfo != null)
                    {
                        if (paInfo.retired)
                        {
                            throw new Exception("The ProcessAgent is retired");
                        }
                        TicketIssuerProxy ticketProxy = new TicketIssuerProxy();
                        AgentAuthHeader authHeader = new AgentAuthHeader();
                        authHeader.coupon = paInfo.identOut;
                        authHeader.agentGuid = ProcessAgentDB.ServiceGuid;
                        ticketProxy.AgentAuthHeaderValue = authHeader;
                        ticketProxy.Url = paInfo.webServiceUrl;
                        ticket = ticketProxy.RedeemTicket(coupon, type, redeemerGuid);
                    }
                    else
                    {
                        throw new Exception("Unknown TicketIssuerDB in RedeemTicket Request");
                    }
                }

            }
            return ticket;
        }