Esempio n. 1
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;
        }
        public override bool CancelTicket(Coupon coupon, string type, string redeemer)
        {
            bool status = false;
            if (brokerDB.AuthenticateAgentHeader(agentAuthHeader))
            {
                // Move all this into BrokerDB

                if (ProcessAgentDB.ServiceGuid.Equals(redeemer))
                {
                    // this ServiceBroker is the redeemer
                    status = brokerDB.CancelTicket(coupon, type, redeemer);
                }
                else
                {
                    ProcessAgentInfo target = brokerDB.GetProcessAgentInfo(redeemer);
                    if (target != null)
                    {
                        if (target.retired)
                        {
                            throw new Exception("The ProcessAgent is retired");
                        }
                        if (ProcessAgentDB.ServiceGuid.Equals(target.domainGuid))
                        {
                            // Its a local domain processAgent
                            ProcessAgentProxy paProxy = new ProcessAgentProxy();
                            paProxy.AgentAuthHeaderValue = new AgentAuthHeader();
                            paProxy.AgentAuthHeaderValue.coupon = target.identOut;
                            paProxy.AgentAuthHeaderValue.agentGuid = ProcessAgentDB.ServiceGuid;
                            paProxy.Url = target.webServiceUrl;
                            status = paProxy.CancelTicket(coupon, type, redeemer);

                        }
                        else
                        {
                            ProcessAgentInfo remoteSB = brokerDB.GetProcessAgentInfo(target.domainGuid);
                            if (remoteSB != null)
                            {
                                if (remoteSB.retired)
                                {
                                    throw new Exception("The ProcessAgent is retired");
                                }
                                // Its from a known domain
                                ProcessAgentProxy sbProxy = new ProcessAgentProxy();
                                sbProxy.AgentAuthHeaderValue = new AgentAuthHeader();
                                sbProxy.AgentAuthHeaderValue.coupon = remoteSB.identOut;
                                sbProxy.AgentAuthHeaderValue.agentGuid = ProcessAgentDB.ServiceGuid;
                                sbProxy.Url = remoteSB.webServiceUrl;
                                status = sbProxy.CancelTicket(coupon, type, redeemer);

                            }
                        }
                    }
                }
            }
            return status;
        }