コード例 #1
0
        public int RevokeReservation(string serviceBrokerGuid, string groupName,
            string labServerGuid, string labClientGuid, DateTime startTime, DateTime endTime, string message)
        {
            bool status = false;
            bool fromISB = false;
            int count = 0;
            Coupon opCoupon = new Coupon();
            opCoupon.couponId = opHeader.coupon.couponId;
            opCoupon.passkey = opHeader.coupon.passkey;
            opCoupon.issuerGuid = opHeader.coupon.issuerGuid;
            UserSchedulingDB dbManager = new UserSchedulingDB();
            try
            {
                Ticket retrievedTicket = dbManager.RetrieveAndVerify(opCoupon, TicketTypes.REVOKE_RESERVATION);
                if (retrievedTicket.payload != null && retrievedTicket.payload.Length > 0)
                {
                    XmlQueryDoc revokeDoc = new XmlQueryDoc(retrievedTicket.payload);
                    string sourceStr = revokeDoc.Query("RevokeReservationPayload/source");
                    if (sourceStr != null && sourceStr.CompareTo("ISB") == 0)
                    {
                        fromISB = true;
                    }
                }
                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();
                if (fromISB)
                { // Need to forward to LSS
                    string lssUrl = dbManager.ListLssUrlByExperiment(labClientGuid, labServerGuid);
                    if (lssUrl != null && lssUrl.Length > 0)
                    {
                        LabSchedulingProxy lssProxy = new LabSchedulingProxy();
                        lssProxy.OperationAuthHeaderValue = new OperationAuthHeader();
                        lssProxy.OperationAuthHeaderValue.coupon = opCoupon;
                        lssProxy.Url = lssUrl;
                        int rCount = lssProxy.RemoveReservation(serviceBrokerGuid, groupName, ProcessAgentDB.ServiceGuid,
                            labServerGuid, labClientGuid, targetStart, targetEnd);
                    }
                }

                ReservationData[] ris = dbManager.GetReservations(serviceBrokerGuid, null, groupName,
                    labServerGuid, labClientGuid, targetStart, targetEnd);

                if (ris != null && ris.Length > 0)
                {

                    InteractiveSBProxy sbProxy = new InteractiveSBProxy();
                    ProcessAgentInfo sbInfo = dbManager.GetProcessAgentInfo(ProcessAgentDB.ServiceAgent.domainGuid);
                    AgentAuthHeader header = new AgentAuthHeader();
                    header.coupon = sbInfo.identOut;
                    header.agentGuid = ProcessAgentDB.ServiceGuid;
                    sbProxy.AgentAuthHeaderValue = header;
                    sbProxy.Url = sbInfo.webServiceUrl;
                    foreach (ReservationData rd in ris)
                    {

                        status = dbManager.RevokeReservation(rd.sbGuid, rd.groupName, rd.lsGuid, rd.clientGuid,
                              rd.startTime, rd.endTime, message);
                        if (status)
                        {
                            count++;
                            status = sbProxy.RevokeReservation(rd.sbGuid, rd.userName, rd.groupName, rd.lsGuid, rd.clientGuid,
                              rd.startTime, rd.endTime, message);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                throw new Exception("USS: RevokeReservation -> ",e);
            }
            return count;
        }
コード例 #2
0
        public bool RevokeReservation(string serviceBrokerGuid, string userName, string groupName, string labServerGuid, string labClientGuid,
            DateTime startTime, DateTime endTime, string message)
        {
            bool status = false;
            int authID = -1;
            if(serviceBrokerGuid.CompareTo(ProcessAgentDB.ServiceGuid) == 0){
                authID = 0;
            }
            else{
            Authority auth = brokerDB.AuthorityRetrieve(serviceBrokerGuid);
            if (auth != null)
            {
                authID = auth.authorityID;
            }
            }

            if (brokerDB.AuthenticateAgentHeader(agentAuthHeader))
            {
                if (agentAuthHeader.coupon.issuerGuid == ProcessAgentDB.ServiceGuid)
                {

                    try
                    {
                        int userId = AdministrativeAPI.GetUserID(userName,authID);
                        if (userId > 0)
                        {
                            User[] users = AdministrativeAPI.GetUsers(new int[] { userId });
                            if (users != null && users.Length > 0)
                            {
                                if (users[0] != null && users[0].email != null)
                                {
                                    SmtpMail.SmtpServer = "127.0.0.1";
                                    MailMessage uMail = new MailMessage();
                                    uMail.To = users[0].email;
                                    uMail.From = ConfigurationManager.AppSettings["supportMailAddress"];
                                    uMail.Subject = "[iLabs] A Reservation has been revoked!";
                                    StringBuilder buf = new StringBuilder();
                                    buf.Append("Your scheduled reservation for ");
                                    buf.Append(AdministrativeAPI.GetLabClientName(AdministrativeAPI.GetLabClientID(labClientGuid)));
                                    buf.Append(", from " + DateUtil.ToUtcString(startTime) + " to " + DateUtil.ToUtcString(endTime));
                                    buf.AppendLine(" has been removed by an external service for the following reason: ");
                                    buf.AppendLine(message);
                                    buf.AppendLine("Please make a new reservation.");

                                    uMail.Body = buf.ToString(); ;
                                    SmtpMail.Send(uMail);
                                }
                            }
                        }

                    }
                    catch (Exception ex)
                    {
                        // Report detailed SMTP Errors
                        StringBuilder smtpErrorMsg = new StringBuilder();
                        smtpErrorMsg.Append("Exception: SMTP in InterativeSB:" + ex.Message);
                        //check the InnerException
                        if (ex.InnerException != null)
                            smtpErrorMsg.Append("<br>Inner Exceptions:");
                        while (ex.InnerException != null)
                        {
                            smtpErrorMsg.Append("<br>" + ex.InnerException.Message);
                            ex = ex.InnerException;
                        }
                       Logger.WriteLine(smtpErrorMsg.ToString());

                    }
                    status = true;
                }
            }
            else
            {
                ProcessAgentInfo paInfo = brokerDB.GetProcessAgentInfo(agentAuthHeader.coupon.issuerGuid);
                if (paInfo != null)
                {
                    if (paInfo.retired)
                    {
                        throw new Exception("The ProcessAgent is retired");
                    }
                    InteractiveSBProxy proxy = new InteractiveSBProxy();
                    AgentAuthHeader authHeader = new AgentAuthHeader();
                    authHeader.coupon = paInfo.identOut;
                    authHeader.agentGuid = ProcessAgentDB.ServiceGuid;
                    proxy.AgentAuthHeaderValue = authHeader;
                    proxy.Url = paInfo.webServiceUrl;
                    status = proxy.RevokeReservation(serviceBrokerGuid, userName, groupName, labServerGuid, labClientGuid,
                        startTime, endTime, message);
                }
                else
                {
                    throw new Exception("Unknown TicketIssuerDB in RedeemTicket Request");
                }
            }
            return status;
        }
コード例 #3
0
ファイル: UserScheduling.asmx.cs プロジェクト: tordf/iLabs
        public int RevokeReservation(string serviceBrokerGuid, string groupName,
            string labServerGuid, string labClientGuid, DateTime startTime, DateTime endTime, string message)
        {
            bool status = false;
            int count = 0;
            Coupon opCoupon = new Coupon();
            opCoupon.couponId = opHeader.coupon.couponId;
            opCoupon.passkey = opHeader.coupon.passkey;
            opCoupon.issuerGuid = opHeader.coupon.issuerGuid;
            string type = TicketTypes.REVOKE_RESERVATION;
            try
            {
                Ticket retrievedTicket = dbTicketing.RetrieveAndVerify(opCoupon, type);
                ReservationInfo[]ri = USSSchedulingAPI.GetReservations(serviceBrokerGuid, null, groupName,
                    labServerGuid, labClientGuid, startTime, endTime);
                if (ri != null && ri.Length > 0)
                {

                    InteractiveSBProxy sbProxy = new InteractiveSBProxy();
                    ProcessAgentInfo sbInfo = dbTicketing.GetProcessAgentInfo(ProcessAgentDB.ServiceAgent.domainGuid);
                    AgentAuthHeader header = new AgentAuthHeader();
                    header.coupon = sbInfo.identOut;
                    header.agentGuid = ProcessAgentDB.ServiceGuid;
                    sbProxy.AgentAuthHeaderValue = header;
                    sbProxy.Url = sbInfo.webServiceUrl;
                    status = sbProxy.RevokeReservation(serviceBrokerGuid, ri[0].userName, groupName, labServerGuid,
                        labClientGuid, startTime, endTime, message);
                    if (status)
                    {
                        count++;
                        USSSchedulingAPI.RevokeReservation(serviceBrokerGuid, groupName, labServerGuid, labClientGuid,
                              startTime, endTime, message);
                    }
                }
            }
            catch (Exception e)
            {
                throw new Exception("USS: RevokeReservation -> ",e);
            }
            return count;
        }