예제 #1
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="username"></param>
        /// <param name="groupName"></param>
        /// <param name="labClientName"></param>
        /// <param name="labClientVersion"></param>
        /// <returns>The redirect url where the user should be redirected, with the coupon appended to it</returns>
        public string ExecuteExerimentSchedulingRecipe(string ussGuid, string lssGuid, string username, string groupName, 
            string labServerGuid, string clientGuid, string labClientName, string labClientVersion, long duration, int userTZ)
        {
            try
            {
                BrokerDB issuer = new BrokerDB();
                TicketLoadFactory factory = TicketLoadFactory.Instance();

                string ticketType = TicketTypes.SCHEDULE_SESSION;

                //the uss is the redeemer of the scheduling ticket
                //string redeemerId = uss.agentGuid;

                //the SB is the sponsor of the scheduling ticket
                //string sponsorId = issuer.GetIssuerGuid();

                string payload1 = factory.createScheduleSessionPayload(username, groupName, issuer.GetIssuerGuid(),
                    labServerGuid, clientGuid, labClientName, labClientVersion, userTZ);
                string payload2 = factory.createRequestReservationPayload();

                Coupon schedulingCoupon = issuer.CreateTicket(TicketTypes.SCHEDULE_SESSION, ussGuid,
                    issuer.GetIssuerGuid(), duration, payload1);
                issuer.AddTicket(schedulingCoupon, TicketTypes.REQUEST_RESERVATION, lssGuid, ussGuid,
                    duration, payload2);

                //
                // construct the redirection url
                //
                string issuerGuid = schedulingCoupon.issuerGuid;
                string passkey = schedulingCoupon.passkey;
                string couponId = schedulingCoupon.couponId.ToString();

                // obtain the reservation URL from the admin URLs table
                string schedulingUrl = issuer.RetrieveAdminURL(ussGuid, TicketTypes.SCHEDULE_SESSION).Url;
                schedulingUrl += "?coupon_id=" + couponId + "&issuer_guid=" + issuerGuid + "&passkey=" + passkey;

                return schedulingUrl;
            }
            catch
            {
                throw;
            }
        }
        public Experiment RetrieveExperiment(long experimentID)
        {
            Experiment experiment = null;
            BrokerDB brokerDB = new BrokerDB();
            int roles = 0;
            int userID = 0;
            int groupID = 0;
            //long[] expIDs = null;
            Ticket expTicket = brokerDB.RetrieveTicket(opHeader.coupon, TicketTypes.REDEEM_SESSION);
            if (expTicket != null && !expTicket.IsExpired())
            {
                //Parse payload, only get what is needed

                XmlQueryDoc expDoc = new XmlQueryDoc(expTicket.payload);
                //long expID = -1;

                string userStr = expDoc.Query("RedeemSessionPayload/userID");
                if ((userStr != null) && (userStr.Length > 0))
                    userID = Convert.ToInt32(userStr);
                string groupStr = expDoc.Query("RedeemSessionPayload/groupID");
                if ((groupStr != null) && (groupStr.Length > 0))
                    groupID = Convert.ToInt32(groupStr);

                if (userID > 0)
                {

                    AuthorizationWrapperClass wrapper = new AuthorizationWrapperClass();
                    roles = wrapper.GetExperimentAuthorizationWrapper(experimentID, userID, groupID);
                }
                if ((roles | ExperimentAccess.READ) == ExperimentAccess.READ)
                {
                    experiment = new Experiment();
                    experiment.experimentId = experimentID;
                    experiment.issuerGuid = ProcessAgentDB.ServiceGuid;
                    ProcessAgentInfo ess = brokerDB.GetExperimentESS(experimentID);
                    if (ess != null)
                    {
                        ExperimentStorageProxy essProxy = new ExperimentStorageProxy();
                        Coupon opCoupon = brokerDB.GetEssOpCoupon(experimentID, TicketTypes.RETRIEVE_RECORDS, 60, ess.agentGuid);
                        if (opCoupon == null)
                        {
                            string payload = TicketLoadFactory.Instance().RetrieveRecordsPayload(experimentID, ess.webServiceUrl);
                            opCoupon = brokerDB.CreateTicket(TicketTypes.RETRIEVE_RECORDS, ess.agentGuid, ProcessAgentDB.ServiceGuid,
                                60, payload);
                        }
                        essProxy.OperationAuthHeaderValue = new OperationAuthHeader();
                        essProxy.OperationAuthHeaderValue.coupon = opCoupon;
                        essProxy.Url = ess.webServiceUrl;
                        essProxy.GetRecords(experimentID, null);
                    }

                }
                else
                {
                    throw new AccessDeniedException("You do not have permission to read this experiment");
                }
            }
            return experiment;
        }