protected void btnMakeReservation_Click(object sender, System.EventArgs e) { // ToDo: Add error checking DateTime startReserveTime = DateUtil.ParseUserToUtc(ddlSelectTime.SelectedItem.Text, culture, userTZ); DateTime endReserveTime = startReserveTime.AddSeconds(Double.Parse(ddlDuration.SelectedValue)); if ((endReserveTime.Minute % quantum) != 0) { DateTime dt = endReserveTime.AddMinutes(quantum - (endReserveTime.Minute % quantum)); if (dt <= endTimePeriod) { endReserveTime = dt; } else { endReserveTime = endTimePeriod; } } lblErrorMessage.Text = ddlSelectTime.SelectedItem.Text + " " + DateUtil.ToUserTime(endReserveTime, culture, -userTZ); lblErrorMessage.Visible = true; string notification = null; LabSchedulingProxy lssProxy = new LabSchedulingProxy(); lssProxy.Url = lssURL; try { // create "REQUEST RESERVATION" ticket in SB and get the coupon for the ticket. //iLabs.DataTypes.TicketingTypes.Coupon authCoupon = ticketIssuer.CreateTicket(lssGuid, "REQUEST RESERVATION", 300, ""); //assign the coupon from ticket to the soap header; OperationAuthHeader opHeader = new OperationAuthHeader(); opHeader.coupon = coupon; lssProxy.OperationAuthHeaderValue = opHeader; notification = lssProxy.ConfirmReservation(serviceBrokerGuid, groupName, ProcessAgentDB.ServiceGuid, labServerGuid, clientGuid, startReserveTime, endReserveTime); if (notification != "The reservation is confirmed successfully") { lblErrorMessage.Text = Utilities.FormatErrorMessage(notification); } else { try { int status = USSSchedulingAPI.AddReservation(userName, serviceBrokerGuid, groupName, labServerGuid, clientGuid, startReserveTime, endReserveTime); string confirm = "The reservation from<br />" + DateUtil.ToUserTime(startReserveTime,culture,userTZ) + " to " + DateUtil.ToUserTime(endReserveTime, culture, userTZ) + "<br />is confirmed."; lblErrorMessage.Text = Utilities.FormatConfirmationMessage(confirm); } catch(Exception insertEx){ lblErrorMessage.Text = Utilities.FormatErrorMessage(notification); lblErrorMessage.Visible = true; } getTimePeriods(); } lblErrorMessage.Visible = true; return; } catch (Exception ex) { string msg = "Exception: reservation can not be confirmed. " + ex.GetBaseException() + "."; lblErrorMessage.Text = Utilities.FormatErrorMessage(msg); lblErrorMessage.Visible = true; } try { if (notification == "The reservation is confirmed successfully") { int experimentInfoId = USSSchedulingAPI.ListExperimentInfoIDByExperiment(labServerGuid, clientGuid); DateTime startTimeUTC = startReserveTime.ToUniversalTime(); DateTime endTimeUTC = endReserveTime.ToUniversalTime(); } return; } catch (Exception ex) { string msg = "Exception: reservation can not be added successfully. " + ex.GetBaseException() + "."; lblErrorMessage.Text = Utilities.FormatErrorMessage(msg); lblErrorMessage.Visible = true; lssProxy.RemoveReservation(serviceBrokerGuid, groupName, ProcessAgentDB.ServiceGuid, labServerGuid, clientGuid, startReserveTime, endReserveTime); } }
public string AddReservation(string serviceBrokerGuid, string userName, string groupName, string labServerGuid, string labClientGuid, DateTime startTime, DateTime endTime) { string message = null; Coupon opCoupon = new Coupon(); UserSchedulingDB dbManager = new UserSchedulingDB(); opCoupon.couponId = opHeader.coupon.couponId; opCoupon.passkey = opHeader.coupon.passkey; opCoupon.issuerGuid = opHeader.coupon.issuerGuid; string type = TicketTypes.SCHEDULE_SESSION; try { Ticket retrievedTicket = dbManager.RetrieveAndVerify(opCoupon, type); if (retrievedTicket.IsExpired()) { throw new AccessDeniedException("The reservation ticket has expired, Please re-login."); } //used to check ticketPayload string user = null; string group = null; string labGuid = null; string clientGuid = null; string sbGuid = null; //Resolved target arguments string userTarget = null; string groupTarget = null; string labGuidTarget = null; string clientGuidTarget = null; XmlDocument payload = new XmlDocument(); payload.LoadXml(retrievedTicket.payload); sbGuid = payload.GetElementsByTagName("sbGuid")[0].InnerText; user = payload.GetElementsByTagName("userName")[0].InnerText; group = payload.GetElementsByTagName("groupName")[0].InnerText; clientGuid = payload.GetElementsByTagName("clientGuid")[0].InnerText; labGuid = payload.GetElementsByTagName("labServerGuid")[0].InnerText; userTarget = Utilities.ResolveArguments(userName, user, true); groupTarget = Utilities.ResolveArguments(groupName, group, true); clientGuidTarget = Utilities.ResolveArguments(labClientGuid, clientGuid, false); labGuidTarget = Utilities.ResolveArguments(labServerGuid, labGuid, false); string lssGuid = dbManager.ListLssIdByExperiment(labClientGuid, labServerGuid); LSSInfo lssInfo = dbManager.GetLSSInfo(lssGuid); 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(); LabSchedulingProxy lssProxy = new LabSchedulingProxy(); lssProxy.OperationAuthHeaderValue = new OperationAuthHeader(); lssProxy.OperationAuthHeaderValue.coupon = opCoupon; lssProxy.Url = lssInfo.lssUrl; message = lssProxy.ConfirmReservation( serviceBrokerGuid, groupName, ProcessAgentDB.ServiceGuid, labServerGuid, labClientGuid, targetStart, targetEnd); if(message.ToLower().Contains("success")){ int infoID = dbManager.ListExperimentInfoIDByExperiment(labServerGuid, labClientGuid); dbManager.AddReservation(userName, serviceBrokerGuid,groupName,infoID,targetStart,targetEnd); } return message; } catch (Exception e) { throw new Exception("USS: AddReservation -> ", e); } return message; }