예제 #1
0
        private void reenterLabClient()
        {
            if (Session["UserID"] == null)
            {
                Response.Redirect("login.aspx");
            }
            BrokerDB brokerDB = new BrokerDB();
            StringBuilder message = new StringBuilder("Message: clientID = ");
            int[] labIds = new int[1];
            message.Append(btnReenter.CommandArgument + " ");
            long expid = Convert.ToInt64(btnReenter.CommandArgument);
            LabClient client = AdministrativeAPI.GetLabClient(Convert.ToInt32(Session["ClientID"]));
            if (client.clientID > 0)
            {
                if (client.clientType == LabClient.INTERACTIVE_HTML_REDIRECT || client.clientType == LabClient.INTERACTIVE_APPLET)
                {
                    long[] coupIDs = InternalDataDB.RetrieveExperimentCouponIDs(expid);
                    Coupon coupon = brokerDB.GetIssuedCoupon(coupIDs[0]);

                    if (client.clientType == LabClient.INTERACTIVE_HTML_REDIRECT)
                    {
                        // construct the redirect query
                        StringBuilder url = new StringBuilder(client.loaderScript.Trim());
                        if (url.ToString().IndexOf("?") == -1)
                            url.Append('?');
                        else
                            url.Append('&');
                        url.Append("coupon_id=" + coupon.couponId + "&passkey=" + coupon.passkey
                            + "&issuer_guid=" + brokerDB.GetIssuerGuid());

                        // Add the return url to the redirect
                        url.Append("&sb_url=");
                        url.Append(Utilities.ExportUrlPath(Request.Url));

                        // Now open the lab within the current Window/frame
                        Response.Redirect(url.ToString(), true);
                    }
                    else if (client.clientType == LabClient.INTERACTIVE_APPLET)
                    {
                        // we have the coupon what do we need now to lauch the lab....?
                        // the whole loader script part should have run... so we should be
                        // able to skip that part.

                        // one question would be is the coupon the same...
                        // if they're not the same we need to change it.
                        // It seems that it is the same.
                        // then we just need to launch the client...

                        string jScript = @"<script language='javascript'>parent.theapplet.location.href = '"
             + "applet.aspx" + @"'</script>";
                        Page.RegisterStartupScript("ReloadFrame", jScript);

                    }

                }
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            StringBuilder buf;
            long couponID = -1L;
            int userID = -1;
            int groupID = -1;
            int clientID = -1;
            int labServerID = -1;
            int userTZ = 0;

            string clientGuid = null;
            string serverGuid = null;
            string groupName = null;
            string userName = null;
            string authKey = null;
            string startStr = null;
            string durStr = null;
            Coupon initCoupon = null;
            LabClient client = null;

            BrokerDB brokerDB = new BrokerDB();
            buf = new StringBuilder();

            string cidStr = Request.QueryString["cid"];
            string authStr = Request.QueryString["ss"];

            if (!String.IsNullOrEmpty(cidStr))
            {
                string test =hdnUserTZ.Value;
                couponID = Int64.Parse(cidStr);
                initCoupon = brokerDB.GetIssuedCoupon(couponID);
                if (initCoupon != null)
                {
                    Ticket launchTicket = brokerDB.RetrieveIssuedTicket(initCoupon, TicketTypes.LAUNCH_CLIENT, ProcessAgentDB.ServiceGuid);
                    if (launchTicket != null && !launchTicket.isCancelled && !launchTicket.IsExpired())
                    {
                        XmlQueryDoc xDoc = new XmlQueryDoc(launchTicket.payload);

                        //Check that the coupon matches the passcode in the ticket payload
                        string passChk = xDoc.Query("LaunchClient/passcode");
                        string ssChk = xDoc.Query("LaunchClient/ss");
                        if (String.IsNullOrEmpty(passChk) || passChk.CompareTo(initCoupon.passkey) != 0)
                        {
                            buf.AppendLine("Passkey Error");
                            processError(buf);
                        }
                        if (String.IsNullOrEmpty(ssChk) || passChk.CompareTo(authStr) != 0)
                        {
                            buf.AppendLine("ss_key Error");
                            processError(buf);
                        }
                        clientGuid = xDoc.Query("LaunchClient/clientGuid");
                        serverGuid = xDoc.Query("LaunchClient/serverGuid");
                        groupName = xDoc.Query("LaunchClient/groupName");
                        authKey = xDoc.Query("LaunchClient/authorityKey");
                        string userIdStr = xDoc.Query("LaunchClient/userId");
                        userName = xDoc.Query("LaunchClient/userName");
                        if (String.IsNullOrEmpty(authKey))
                        {
                            buf.AppendLine("authority Error");
                            processError(buf);
                        }
                        if (!String.IsNullOrEmpty(userIdStr))
                        {
                            userID = Int32.Parse(userIdStr);
                            if (userID <= 0)
                            {
                                buf.AppendLine("userID invalid value");
                                processError(buf);
                            }
                        }
                        else
                        {
                            buf.AppendLine("userID not specified");
                            processError(buf);
                        }
                        if (!String.IsNullOrEmpty(groupName))
                        {
                            groupID = AdministrativeAPI.GetGroupID(groupName);
                            if (groupID <= 0)
                            {
                                buf.AppendLine("groupName invalid value");
                                processError(buf);
                            }
                        }
                        else
                        {
                            buf.AppendLine("groupName not specified");
                            processError(buf);
                        }
                        startStr = xDoc.Query("LaunchClient/start");
                        durStr = xDoc.Query("LaunchClient/duration");

                        if (!String.IsNullOrEmpty(clientGuid))
                        {
                            clientID = AdministrativeAPI.GetLabClientID(clientGuid);
                            if (clientID > 0)
                            {
                                // do the real work
                                IntTag results = brokerDB.ProcessLaunchClientRequest(initCoupon, clientID, labServerID, groupID, userID, userTZ);

                                // Checks for different status values
                                //TODO Check for Scheduling redirect -- May be checked before we get here
                                if (results.id > -1)
                                {
                                   long sessionID = AdministrativeAPI.InsertUserSession(userID, groupID, clientID, userTZ, Session.SessionID);
                                    //add Session cookie
                                    HttpCookie cookie = new HttpCookie(ConfigurationManager.AppSettings["isbAuthCookieName"], sessionID.ToString());
                                    Response.AppendCookie(cookie);
                                    Response.AddHeader("Access-Control-Allow-Origin", "*");
                                    if ((results.id & LabClient.APPLET_BIT) == LabClient.APPLET_BIT)
                                    {
                                        Session["LoaderScript"] = results.tag;
                                        Response.Redirect("applet2.aspx", true);
                                    }
                                    else if ((results.id & LabClient.REDIRECT_BIT) == LabClient.REDIRECT_BIT)
                                    {
                                        string url = results.tag;
                                        Response.Redirect(url, true);
                                    }
                                    else
                                    {
                                        buf.AppendLine("Client type not supported");
                                    }
                                }
                                else
                                {
                                    buf.AppendLine("Client not found");
                                }
                            }
                            else
                            {
                                buf.AppendLine("client not specified");
                                processError(buf);
                            }

                        }
                    }
                    else
                    {
                        buf.AppendLine("Ticket Error");
                    }
                }
            }
            else
            {
                buf.AppendLine("Missing cid");
            }
            // If the code above does not complete fall through to processError()
            processError(buf);
        }
예제 #3
0
        public int RemoveTickets(List<Ticket> ticketList, BrokerDB brokerDb)
        {
            ArrayList coupons = new ArrayList();
            Coupon coupon = null;
            int ticketCount = 0;
            int couponCount = 0;
            if (ticketList.Count > 0)
            {
                Utilities.WriteLog("RemoveTickets: expired count = " + ticketList.Count);

                foreach (Ticket ticket in ticketList)
                {
                    if (!coupons.Contains(ticket.couponId))
                    {
                        coupons.Add(ticket.couponId);
                    }
                    if (coupon == null || coupon.couponId != ticket.couponId)
                    {
                        coupon = brokerDb.GetIssuedCoupon(ticket.couponId);
                    }
                    switch (ticket.type)
                    {
                        case TicketTypes.ADMINISTER_EXPERIMENT:

                            string payload = ticket.payload;
                            if (payload != null)
                            {
                                XmlQueryDoc xDoc = new XmlQueryDoc(payload);
                                string url = xDoc.Query("AdministerExperimentPayload/essURL");
                                string expStr = xDoc.Query("AdministerExperimentPayload/experimentID");
                                long expID = Convert.ToInt64(expStr);
                                ExperimentStorageProxy essProxy = new ExperimentStorageProxy();
                                essProxy.OperationAuthHeaderValue = new OperationAuthHeader();
                                essProxy.OperationAuthHeaderValue.coupon = coupon;
                                essProxy.Url = url;
                                StorageStatus expStatus = essProxy.SetExperimentStatus(expID, (int)StorageStatus.CLOSED_TIMEOUT);
                                DataStorageAPI.UpdateExperimentStatus(expStatus);
                            }
                            break;
                        case TicketTypes.RETRIEVE_RECORDS:
                        case TicketTypes.STORE_RECORDS:
                            break;
                        case TicketTypes.EXECUTE_EXPERIMENT:
                        case TicketTypes.ALLOW_EXPERIMENT_EXECUTION:
                            break;
                        default: // Every other Ticket type
                            break;
                    }
                    bool statusR = false;

                    if (ticket.redeemerGuid != brokerDb.GetIssuerGuid())
                    {
                        ProcessAgentInfo redeemer = brokerDb.GetProcessAgentInfo(ticket.redeemerGuid);
                        if ((redeemer != null) && !redeemer.retired)
                        {
                            ProcessAgentProxy paProxy = new ProcessAgentProxy();
                            paProxy.AgentAuthHeaderValue = new AgentAuthHeader();
                            paProxy.Url = redeemer.webServiceUrl;
                            paProxy.AgentAuthHeaderValue.coupon = redeemer.identOut;
                            paProxy.AgentAuthHeaderValue.agentGuid = ProcessAgentDB.ServiceGuid;
                            statusR = paProxy.CancelTicket(coupon, ticket.type, ticket.redeemerGuid);
                        }
                    }
                    if (ticket.issuerGuid == brokerDb.GetIssuerGuid())
                    {
                        brokerDb.DeleteIssuedTicket(ticket.ticketId);
                        ticketCount++;
                    }
                }
                foreach (long id in coupons)
                {
                    int count = brokerDb.GetIssuedCouponCollectionCount(id);
                    if (count == 0)
                    {
                        brokerDb.DeleteIssuedCoupon(id);
                        couponCount++;
                    }
                }
                Utilities.WriteLog("RemoveTickets: ticketCount=" + ticketCount + " \tcouponCount=" + couponCount);
            }
            return ticketCount;
        }
예제 #4
0
        private void reenterLabClient()
        {
            if (Session["UserID"] == null)
            {
                Response.Redirect("login.aspx");
            }
            BrokerDB brokerDB = new BrokerDB();
            StringBuilder message = new StringBuilder("Message: clientID = ");
            int[] labIds = new int[1];
            message.Append(btnReenter.CommandArgument + " ");
            iLabParser parser = new iLabParser();
            long expid = Convert.ToInt64(btnReenter.CommandArgument);
            LabClient client = AdministrativeAPI.GetLabClient(Convert.ToInt32(Session["ClientID"]));
            if (client.clientID > 0)
            {
                if (client.clientType == LabClient.INTERACTIVE_HTML_REDIRECT)
                {
                    iLabProperties properties = new iLabProperties();
                    properties.Add("sb",ProcessAgentDB.ServiceAgent);
                    long[] coupIDs = InternalDataDB.RetrieveExperimentCouponIDs(expid);
                    Coupon coupon = brokerDB.GetIssuedCoupon(coupIDs[0]);
                    if(coupon != null)
                        properties.Add("op", coupon);
                    // construct the redirect query
                    ProcessAgentInfo lsInfo = getLabServer(client.clientID,effectiveGroupID);
                    if(lsInfo != null)
                        properties.Add("ls",lsInfo);

                    StringBuilder url = new StringBuilder(client.loaderScript.Trim());
                    // Add the return url to the redirect
                    if (url.ToString().IndexOf("?") == -1)
                        url.Append('?');
                    else
                        url.Append('&');
                    url.Append("sb_url=");
                    url.Append(Utilities.ExportUrlPath(Request.Url));
                    string targetURL = parser.Parse(url,properties,true);
                    // Now open the lab within the current Window/frame
                    Response.Redirect(targetURL, true);
                }
            }
        }