/// <summary> /// Should use the ServiceBroker to create a ticket to directly connect to the ESS for experiment records /// </summary> /// <param name="sbProxy"></param> /// <param name="expID"></param> /// <param name="cList"></param> protected ExperimentRecord[] getRecords(InteractiveSBProxy sbProxy, long expID, Criterion[] cList) { ExperimentRecord[] records = null; try { records = sbProxy.RetrieveExperimentRecords(expID, cList); } catch (Exception e) { lblResponse.Text = Utilities.FormatWarningMessage("You do not have access to this experiment!"); lblResponse.Visible = true; return null; } return records; }
/// <summary> /// Method that does the actual make reservation for the user. /// makes the basis of the parameters from the message and the application database /// </summary> /// <param name="userName"> the user who is scheduling for the lab; must be registered with the service broker</param> /// <param name="groupName">the group name authorized to do a lab</param> /// <param name="labServerGuid">lab server which holds the lab that does the actual scheduling</param> /// <param name="clientGuid">Guid of the lab being registered for</param> /// <param name="start">Start time of a particular period scheduled for</param> /// <param name="end">End time of a particular period being scheduled for</param> /// <returns>returns a message string that the application bases on for to give the feedback to the user</returns> public static string MakeReservation(string userName, string groupName, string labServerGuid, string clientGuid, DateTime start, DateTime end) { string lsGuid = null; int status = -1; string message = null; if (ProcessAgentDB.ServiceAgent != null && ProcessAgentDB.ServiceAgent.domainGuid != null) { ProcessAgentDB paDb = new ProcessAgentDB(); ProcessAgentInfo domainServer = paDb.GetProcessAgentInfo(ProcessAgentDB.ServiceAgent.domainGuid); InteractiveSBProxy isbProxy = new InteractiveSBProxy(); isbProxy.AgentAuthHeaderValue = new AgentAuthHeader(); isbProxy.AgentAuthHeaderValue.agentGuid = ProcessAgentDB.ServiceGuid; isbProxy.AgentAuthHeaderValue.coupon = domainServer.identOut; isbProxy.Url = domainServer.ServiceUrl; string[] types = new string[] { TicketTypes.SCHEDULE_SESSION }; Coupon opCoupon = isbProxy.RequestAuthorization(types, 600, userName, groupName, labServerGuid, clientGuid); if (opCoupon != null) { TicketIssuerProxy ticketProxy = new TicketIssuerProxy(); ticketProxy.AgentAuthHeaderValue = new AgentAuthHeader(); ticketProxy.AgentAuthHeaderValue.agentGuid = ProcessAgentDB.ServiceGuid; ticketProxy.AgentAuthHeaderValue.coupon = domainServer.identOut; ticketProxy.Url = domainServer.ServiceUrl; //the method call below is one which does not returns a null value //in otherwards the ticket value is not created. Ticket ticketSMS = ticketProxy.RedeemTicket(opCoupon, TicketTypes.SCHEDULE_SESSION, ProcessAgentDB.ServiceGuid); if (ticketSMS != null) { if (ticketSMS.payload != null || ticketSMS.payload.Length > 0) { XmlQueryDoc xdoc = new XmlQueryDoc(ticketSMS.payload); string ussURL = xdoc.Query("ScheduleSessionPayload/ussURL"); UserSchedulingProxy ussProxy = new UserSchedulingProxy(); ussProxy.OperationAuthHeaderValue = new OperationAuthHeader(); ussProxy.OperationAuthHeaderValue.coupon = opCoupon; ussProxy.Url = ussURL; TimePeriod[] times = ussProxy.RetrieveAvailableTimePeriods(ProcessAgentDB.ServiceAgent.domainGuid, groupName, labServerGuid, clientGuid, start, end); // Logic to check for final time DateTime resStart = start; DateTime resEnd = end; message = ussProxy.AddReservation(ProcessAgentDB.ServiceAgent.domainGuid, userName, groupName, labServerGuid, clientGuid, resStart, resEnd); } } } else { message = "coupon is null"; } } else { message = "This service is not part of a domain, please contact the administrator!"; } return message; }
protected void Page_Load(object sender, EventArgs e) { LabDB dbManager = new LabDB(); if (Session["opCouponID"] != null && Session["opIssuer"] != null && Session["opPasscode"] != null) { opCoupon = new Coupon(Session["opIssuer"].ToString(), Convert.ToInt64(Session["opCouponID"].ToString()), Session["opPasscode"].ToString()); } else { throw new AccessDeniedException("Missing credentials for BEE Lab graph."); } if (Request.QueryString["expid"] != null) experimentID = Convert.ToInt64(Request.QueryString["expid"]); if (Request.QueryString["min"] != null && Request.QueryString["min"].Length > 0) minRecord = Convert.ToInt32(Request.QueryString["min"]); if (Request.QueryString["max"] != null && Request.QueryString["max"].Length > 0) maxRecord = Convert.ToInt32(Request.QueryString["max"]) +1; if (Request.QueryString["index"] != null && Request.QueryString["index"].Length > 0) indices = Request.QueryString["index"]; InteractiveSBProxy sbProxy = new InteractiveSBProxy(); //ProcessAgentInfo sbInfo = dbManager.GetProcessAgentInfo(Session["opIssuer"].ToString()); ProcessAgentInfo sbInfo = dbManager.GetProcessAgentInfo(ProcessAgentDB.ServiceAgent.domainGuid); if (sbInfo != null) { sbProxy.OperationAuthHeaderValue = new OperationAuthHeader(); sbProxy.OperationAuthHeaderValue.coupon = opCoupon; sbProxy.Url = sbInfo.webServiceUrl; List<Criterion> criteria = new List<Criterion>(); //criteria.Add(new Criterion("experiment_ID", "=", experimentID)); criteria.Add(new Criterion("Record_Type", "=", "data")); if (minRecord > -1) criteria.Add(new Criterion("sequence_no", ">=", minRecord.ToString())); if (maxRecord > -1) criteria.Add(new Criterion("sequence_no", "<=", maxRecord.ToString())); //ExperimentSummary[] expInfo = sbProxy.RetrieveExperimentSummary(search); //if (expInfo.Length > 0) //{ // theExperiment = expInfo[0]; //} //ExperimentRecord[] profileRecords = getRecords(sbProxy, Convert.ToInt64(hdnExperimentID.Value), // new Criterion[] { new Criterion("Record_Type", "=", "profile") }); ExperimentRecord[] records = getRecords(sbProxy, experimentID, criteria.ToArray()); if (records != null) { if (records.Length > 0) { //processProfile(profileRecords); StringBuilder buf = processRecords(records, indices); int bufLen = buf.Length * 2; Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName); //Response.AddHeader("Content-Length",bufLen.ToString()); Response.ContentType = "application/octet-stream"; Response.Write(buf.ToString()); Response.Flush(); } } } }
/// <summary> /// Should use the ServiceBroker to create a ticket to directly connect to the ESS for experiment records /// </summary> /// <param name="sbProxy"></param> /// <param name="expID"></param> /// <param name="cList"></param> protected ExperimentRecord[] getRecords(InteractiveSBProxy sbProxy, long expID, Criterion[] cList) { ExperimentRecord[] records = null; records = sbProxy.RetrieveExperimentRecords(expID, cList); return records; }
public StorageStatus AgentCloseExperiment(Coupon coupon, long experimentId) { StorageStatus status = null; bool experimentClosed = false; if (brokerDB.AuthenticateAgentHeader(agentAuthHeader)) { if (coupon.issuerGuid == ProcessAgentDB.ServiceGuid) { // Check for ESS use Ticket essTicket = brokerDB.RetrieveTicket(coupon, TicketTypes.ADMINISTER_EXPERIMENT); if (essTicket != null) { ProcessAgentInfo ess = brokerDB.GetProcessAgentInfo(essTicket.redeemerGuid); if (ess != null) { if (ess.retired) { throw new Exception("The ProcessAgent is retired"); } ExperimentStorageProxy essProxy = new ExperimentStorageProxy(); essProxy.AgentAuthHeaderValue = new AgentAuthHeader(); essProxy.AgentAuthHeaderValue.coupon = ess.identOut; essProxy.AgentAuthHeaderValue.agentGuid = ProcessAgentDB.ServiceGuid; essProxy.Url = ess.webServiceUrl; status = essProxy.CloseExperiment(experimentId); DataStorageAPI.UpdateExperimentStatus(status); } brokerDB.CancelIssuedTicket(coupon, essTicket); } else { // Close the local Experiment records // Note: store and retrieve tickets are not cancelled. experimentClosed = DataStorageAPI.CloseExperiment(experimentId, StorageStatus.CLOSED_USER); status = DataStorageAPI.RetrieveExperimentStatus(experimentId); } } else { ProcessAgentInfo paInfo = brokerDB.GetProcessAgentInfo(coupon.issuerGuid); if (paInfo != null) { if (paInfo.retired) { throw new Exception("The ProcessAgent is retired"); } InteractiveSBProxy ticketProxy = new InteractiveSBProxy(); AgentAuthHeader authHeader = new AgentAuthHeader(); authHeader.coupon = paInfo.identOut; authHeader.agentGuid = ProcessAgentDB.ServiceGuid; ticketProxy.AgentAuthHeaderValue = authHeader; ticketProxy.Url = paInfo.webServiceUrl; status = ticketProxy.AgentCloseExperiment(coupon, experimentId); } else { throw new Exception("Unknown TicketIssuerDB in RedeemTicket Request"); } } } return status; }
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; }
public override eStatus Close(eStatus reason) { LabDB dbService = new LabDB(); LabViewInterface lvi = null; try { if (data != null) { XmlQueryDoc taskDoc = new XmlQueryDoc(data); string viName = taskDoc.Query("task/application"); string statusVI = taskDoc.Query("task/status"); string server = taskDoc.Query("task/server"); string portStr = taskDoc.Query("task/serverPort"); #if LabVIEW_WS lvi = new LabViewInterface(); #else if ((portStr != null) && (portStr.Length > 0) && (portStr.CompareTo("0") != 0) ) { lvi = new LabViewRemote(server, Convert.ToInt32(portStr)); } else { lvi = new LabViewInterface(); } #endif // Status VI not used if ((statusVI != null) && statusVI.Length != 0) { try { if(reason == eStatus.Expired) lvi.DisplayStatus(statusVI, "You are out of time!", "0:00"); else lvi.DisplayStatus(statusVI, "Your experiment has been cancelled", "0:00"); } catch (Exception ce) { Logger.WriteLine("Trying StatusVI: " + ce.Message); } } //Get the VI and send version specfic call to get control of the VI //VirtualInstrument vi = lvi.GetVI(viName); // LV 8.2.1 //Server takes control of RemotePanel, connection not brokenS lvi.ReleaseVI(viName); } Logger.WriteLine("TaskID = " + taskID + " has expired"); dbService.SetTaskStatus(taskID, (int)reason); status = eStatus.Closed; DataSourceManager dsManager = TaskProcessor.Instance.GetDataManager(taskID); if (dsManager != null) { dsManager.CloseDataSources(); TaskProcessor.Instance.RemoveDataManager(taskID); } dbService.SetTaskStatus(taskID, (int)status); if (couponID > 0) { // this task was created with a valid ticket, i.e. not a test. Coupon expCoupon = dbService.GetCoupon(couponID, issuerGUID); // Only use the domain ServiceBroker, do we need a test // Should only be one ProcessAgentInfo[] sbs = dbService.GetProcessAgentInfos(ProcessAgentType.SERVICE_BROKER); if ((sbs == null) || (sbs.Length < 1)) { Logger.WriteLine("Can not retrieve ServiceBroker!"); throw new Exception("Can not retrieve ServiceBroker!"); } ProcessAgentInfo domainSB = null; foreach (ProcessAgentInfo dsb in sbs) { if (!dsb.retired) { domainSB = dsb; break; } } if (domainSB == null) { Logger.WriteLine("Can not retrieve ServiceBroker!"); throw new Exception("Can not retrieve ServiceBroker!"); } InteractiveSBProxy iuProxy = new InteractiveSBProxy(); iuProxy.AgentAuthHeaderValue = new AgentAuthHeader(); iuProxy.AgentAuthHeaderValue.coupon = sbs[0].identOut; iuProxy.AgentAuthHeaderValue.agentGuid = ProcessAgentDB.ServiceGuid; iuProxy.Url = sbs[0].webServiceUrl; StorageStatus storageStatus = iuProxy.AgentCloseExperiment(expCoupon, experimentID); Logger.WriteLine("AgentCloseExperiment status: " + storageStatus.status + " records: " + storageStatus.recordCount); // currently RequestTicketCancellation always returns false // Create ticketing service interface connection to TicketService TicketIssuerProxy ticketingInterface = new TicketIssuerProxy(); ticketingInterface.AgentAuthHeaderValue = new AgentAuthHeader(); ticketingInterface.Url = sbs[0].webServiceUrl; ticketingInterface.AgentAuthHeaderValue.coupon = sbs[0].identOut; ticketingInterface.AgentAuthHeaderValue.agentGuid = ProcessAgentDB.ServiceGuid; if (ticketingInterface.RequestTicketCancellation(expCoupon, TicketTypes.EXECUTE_EXPERIMENT, ProcessAgentDB.ServiceGuid)) { dbService.CancelTicket(expCoupon, TicketTypes.EXECUTE_EXPERIMENT, ProcessAgentDB.ServiceGuid); Logger.WriteLine("Canceled ticket: " + expCoupon.couponId); } else { Logger.WriteLine("Unable to cancel ticket: " + expCoupon.couponId); } } } catch (Exception e1) { Logger.WriteLine("ProcessTasks Cancelled: exception:" + e1.Message + e1.StackTrace); } finally { lvi = null; } return base.Close(); }
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; }
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; }
protected void btnGo_Click(object sender, System.EventArgs e) { //clearExperimentDisplay(); List<Criterion> cList = new List<Criterion>(); LabDB dbManager = new LabDB(); LabAppInfo clientInfo = dbManager.GetLabApp(hdnAppkey.Value); if (clientInfo == null) { throw new Exception("Client does not exist!"); } if( clientInfo.extraInfo != null && clientInfo.extraInfo.Length > 0) cList.Add(new Criterion("clientguid", "=", clientInfo.extraInfo)); if((ddlTimeAttribute.SelectedIndex >0)) { DateTime time1 = FactoryDB.MinDbDate; try { time1 = DateUtil.ParseUserToUtc(txtTime1.Text,culture,Convert.ToInt32(Session["UserTZ"])); } catch { lblResponse.Text = Utilities.FormatErrorMessage("Please enter a valid date & time in the first time field ."); lblResponse.Visible = true; return; } if (ddlTimeAttribute.SelectedIndex == 1) { cList.Add(new Criterion("CreationTime", ">=", time1.ToString())); cList.Add(new Criterion("CreationTime", "<", time1.AddDays(1).ToString())); } else if (ddlTimeAttribute.SelectedIndex == 2) { cList.Add(new Criterion("CreationTime", "<", time1.ToString())); } else if (ddlTimeAttribute.SelectedIndex == 3) { cList.Add(new Criterion("CreationTime", ">=", time1.ToString())); } if (ddlTimeAttribute.SelectedIndex == 4) { DateTime time2 = FactoryDB.MaxDbDate; try { time2 = DateUtil.ParseUserToUtc(txtTime2.Text, culture, Convert.ToInt32(Session["UserTZ"])); } catch { lblResponse.Text = Utilities.FormatErrorMessage("Please enter a valid date & time in the second time field."); lblResponse.Visible = true; return; } cList.Add(new Criterion("CreationTime", ">=", time1.ToString())); cList.Add(new Criterion("CreationTime", "<=", time2.ToString())); } } InteractiveSBProxy sbProxy = new InteractiveSBProxy(); ProcessAgentInfo sbInfo = dbManager.GetProcessAgentInfo(hdnIssuer.Value); if (sbInfo != null) { sbProxy.OperationAuthHeaderValue = new OperationAuthHeader(); sbProxy.OperationAuthHeaderValue.coupon = new Coupon(hdnIssuer.Value, Convert.ToInt64(hdnCoupon.Value), hdnPasscode.Value); sbProxy.Url = sbInfo.webServiceUrl; List<Criterion> cri = new List<Criterion>(); cri.Add(new Criterion("clientguid", "=", clientInfo.extraInfo)); ExperimentSummary[] expSum = sbProxy.RetrieveExperimentSummary(cri.ToArray()); if (expSum.Length == 0) { string msg = "No experiment records were found for user '" + Session["UserName"] + "' in group '" + Session["GroupName"] + "'."; lblResponse.Text = Utilities.FormatErrorMessage(msg); lblResponse.Visible = true; } listSummaries(expSum); } }
protected void Page_Load(object sender, System.EventArgs e) { LabDB dbManager = new LabDB(); if (!IsPostBack) { // Query values from the request //clearSessionInfo(); hdnAppkey.Value = Request.QueryString["app"]; hdnCoupon.Value = Request.QueryString["coupon_id"]; hdnPasscode.Value = Request.QueryString["passkey"]; hdnIssuer.Value = Request.QueryString["issuer_guid"]; hdnSbUrl.Value = Request.QueryString["sb_url"]; if (hdnSbUrl.Value != null && hdnSbUrl.Value.Length > 0) Session["sbUrl"] = hdnSbUrl.Value; else Session.Remove("sbUrl"); string userName = null; string userIdStr = null; int tz = 0; if (Session["userTZ"] != null) tz = Convert.ToInt32(Session["userTZ"]); // this should be the RedeemSession & Experiment Coupon data if (!(hdnPasscode.Value != null && hdnPasscode.Value != "" && hdnCoupon.Value != null && hdnCoupon.Value != "" && hdnIssuer.Value != null && hdnIssuer.Value != "")) { Logger.WriteLine("BEEanaylsis: " + "AccessDenied missing credentials"); Response.Redirect("AccessDenied.aspx?text=missing+credentials.", true); } Coupon expCoupon = new Coupon(hdnIssuer.Value, Convert.ToInt64(hdnCoupon.Value), hdnPasscode.Value); //Check the database for ticket and coupon, if not found Redeem Ticket from // issuer and store in database. //This ticket should include group, experiment id and be valid for this moment in time?? Ticket expTicket = dbManager.RetrieveAndVerify(expCoupon, TicketTypes.EXECUTE_EXPERIMENT); if (expTicket != null) { if (expTicket.IsExpired()) { Response.Redirect("AccessDenied.aspx?text=The ExperimentExecution+ticket+has+expired.", true); } Session["exCoupon"] = expCoupon; ////Parse experiment payload, only get what is needed string payload = expTicket.payload; XmlQueryDoc expDoc = new XmlQueryDoc(payload); string expIdStr = expDoc.Query("ExecuteExperimentPayload/experimentID"); string tzStr = expDoc.Query("ExecuteExperimentPayload/userTZ"); //string userIdStr = expDoc.Query("ExecuteExperimentPayload/userID"); string groupName = expDoc.Query("ExecuteExperimentPayload/groupName"); Session["groupName"] = groupName; string sbStr = expDoc.Query("ExecuteExperimentPayload/sbGuid"); Session["brokerGUID"] = sbStr; if ((tzStr != null) && (tzStr.Length > 0)) { Session["userTZ"] = tzStr; } LabAppInfo clientInfo = dbManager.GetLabApp(hdnAppkey.Value); if (clientInfo == null) { throw new Exception("Client does not exist!"); } long experimentID = Convert.ToInt64(expIdStr); InteractiveSBProxy sbProxy = new InteractiveSBProxy(); ProcessAgentInfo sbInfo = dbManager.GetProcessAgentInfo(hdnIssuer.Value); if (sbInfo != null) { sbProxy.OperationAuthHeaderValue = new OperationAuthHeader(); sbProxy.OperationAuthHeaderValue.coupon = expCoupon; sbProxy.Url = sbInfo.webServiceUrl; // Use the extraInfo field to provide the target ClientGUID List<Criterion> cri = new List<Criterion>(); if (clientInfo.extraInfo != null && clientInfo.extraInfo.Length > 0) cri.Add(new Criterion("clientguid", "=", clientInfo.extraInfo)); ExperimentSummary[] expSum = sbProxy.RetrieveExperimentSummary(cri.ToArray()); listSummaries(expSum); } } } }
protected void lbxSelectExperiment_SelectedIndexChanged(object sender, System.EventArgs e) { LabDB dbManager = new LabDB(); //clearSessionInfo(); //clearExperimentDisplay(); long experimentID = Int64.Parse (lbxSelectExperiment.Items [lbxSelectExperiment.SelectedIndex ].Value); InteractiveSBProxy sbProxy = new InteractiveSBProxy(); ProcessAgentInfo sbInfo = dbManager.GetProcessAgentInfo(hdnIssuer.Value); if (sbInfo != null) { sbProxy.OperationAuthHeaderValue = new OperationAuthHeader(); sbProxy.OperationAuthHeaderValue.coupon = new Coupon(hdnIssuer.Value, Convert.ToInt64(hdnCoupon.Value), hdnPasscode.Value); sbProxy.Url = sbInfo.webServiceUrl; try { //ExperimentSummary[] expInfo = wrapper.GetExperimentSummaryWrapper(new long[] { experimentID }); Criterion[] search = new Criterion[] { new Criterion("experiment_ID", "=", experimentID.ToString()) }; ExperimentSummary[] expInfo = sbProxy.RetrieveExperimentSummary(search); if (expInfo[0] != null) { displayExperimentSummary(expInfo[0]); } } catch (Exception ex) { lblResponse.Text = Utilities.FormatErrorMessage("Error retrieving experiment information. " + ex.Message); lblResponse.Visible = true; } } }
protected void btnSaveAnnotation_Click(object sender, System.EventArgs e) { lblResponse.Visible=false; LabDB dbManager = new LabDB(); try { InteractiveSBProxy sbProxy = new InteractiveSBProxy(); ProcessAgentInfo sbInfo = dbManager.GetProcessAgentInfo(hdnIssuer.Value); if (sbInfo != null) { sbProxy.OperationAuthHeaderValue = new OperationAuthHeader(); sbProxy.OperationAuthHeaderValue.coupon = new Coupon(hdnIssuer.Value, Convert.ToInt64(hdnCoupon.Value), hdnPasscode.Value); sbProxy.Url = sbInfo.webServiceUrl; sbProxy.SetAnnotation(Int32.Parse(txtExperimentID.Text), txtAnnotation.Text); Criterion[] search = new Criterion[] { new Criterion("experiment_ID", "=", txtExperimentID.Text) }; ExperimentSummary[] expInfo = sbProxy.RetrieveExperimentSummary(search); if (expInfo.Length > 0) { displayExperimentSummary(expInfo[0]); } lblResponse.Text = Utilities.FormatConfirmationMessage("Annotation saved for experiment ID " + txtExperimentID.Text); lblResponse.Visible = true; } } catch (Exception ex) { lblResponse.Text = Utilities.FormatErrorMessage("Error saving experiment annotation. " + ex.Message); lblResponse.Visible = true; } }
protected void Page_Load(object sender, System.EventArgs e) { if(Session["userTZ"] != null) tz = Convert.ToInt32(Session["userTZ"]); String returnURL = (string)Session["sbUrl"]; if ((returnURL != null) && (returnURL.Length > 0)) { lnkBackSB.NavigateUrl = returnURL; lnkBackSB.Visible = true; } else{ lnkBackSB.Visible = false; } if (Session["opCouponID"] != null && Session["opIssuer"] != null && Session["opPasscode"] != null) { opCoupon = new Coupon(Session["opIssuer"].ToString(), Convert.ToInt64(Session["opCouponID"].ToString()), Session["opPasscode"].ToString()); } else { throw new AccessDeniedException("Missing credentials for BEE Lab graph."); } LabDB dbManager = new LabDB(); if (!IsPostBack) { lblResponse.Text = ""; lblResponse.Visible = false; // Query values from the request hdnExperimentID.Value = Request.QueryString["expid"]; if (hdnExperimentID.Value != null && hdnExperimentID.Value.Length > 0) hdnChannelID.Value = ChecksumUtil.ToMD5Hash("BEElab" + hdnExperimentID.Value); else hdnChannelID.Value = "experiment-channel"; if (Session["opCouponID"] != null && Session["opIssuer"] != null && Session["opPasscode"] != null) { // Save the coupon data for when the session times out ViewState["opCouponID"] = Session["opCouponID"].ToString(); ViewState["opIssuer"] = Session["opIssuer"].ToString(); ViewState["opPasscode"] = Session["opPasscode"].ToString(); } InteractiveSBProxy sbProxy = new InteractiveSBProxy(); ProcessAgentInfo sbInfo = dbManager.GetProcessAgentInfo(Session["opIssuer"].ToString()); if (sbInfo != null) { sbProxy.OperationAuthHeaderValue = new OperationAuthHeader(); sbProxy.OperationAuthHeaderValue.coupon = opCoupon; sbProxy.Url = sbInfo.webServiceUrl; //Criterion[] search = new Criterion[] { new Criterion("experiment_ID", "=", hdnExperimentID.Value) }; //ExperimentSummary[] expInfo = sbProxy.RetrieveExperimentSummary(search); //if (expInfo.Length > 0) //{ // theExperiment = expInfo[0]; //} ExperimentRecord[] profileRecords = getRecords(sbProxy, Convert.ToInt64(hdnExperimentID.Value), new Criterion[] { new Criterion("Record_Type", "=", "profile") }); ExperimentRecord[] records = getRecords(sbProxy,Convert.ToInt64(hdnExperimentID.Value), new Criterion[] { new Criterion("Record_Type", "=", "data")}); if(hdnChannelID.Value != null) writeChannelID(hdnChannelID.Value); //processProfile(profileRecords); processRecords(records); } } }
public virtual eStatus Close(eStatus reason) { LabDB dbService = new LabDB(); try { if (data != null) { XmlQueryDoc taskDoc = new XmlQueryDoc(data); string app = taskDoc.Query("task/application"); string statusName = taskDoc.Query("task/status"); string server = taskDoc.Query("task/server"); string portStr = taskDoc.Query("task/serverPort"); // Status not used if ((statusName != null) && statusName.Length != 0) { try { if (reason == eStatus.Expired) DisplayStatus(statusName, "You are out of time!", "0:00"); else DisplayStatus(statusName, "Your experiment has been cancelled", "0:00"); } catch (Exception ce) { Logger.WriteLine("Trying StatusName: " + ce.Message); } } //Stop the application & close ESS sessions } Logger.WriteLine("TaskID = " + taskID + " is being closed"); dbService.SetTaskStatus(taskID, (int)reason); status = eStatus.Closed; DataSourceManager dsManager = TaskProcessor.Instance.GetDataManager(taskID); if (dsManager != null) { dsManager.CloseDataSources(); TaskProcessor.Instance.RemoveDataManager(taskID); } dbService.SetTaskStatus(taskID, (int)status); if (couponID > 0) { // this task was created with a valid ticket, i.e. not a test. Coupon expCoupon = dbService.GetCoupon(couponID, issuerGUID); // Only use the domain ServiceBroker, do we need a test // Should only be one ProcessAgentInfo[] sbs = dbService.GetProcessAgentInfos(ProcessAgentType.SERVICE_BROKER); if ((sbs == null) || (sbs.Length < 1)) { Logger.WriteLine("Can not retrieve ServiceBroker!"); throw new Exception("Can not retrieve ServiceBroker!"); } ProcessAgentInfo domainSB = null; foreach (ProcessAgentInfo dsb in sbs) { if (!dsb.retired) { domainSB = dsb; break; } } if (domainSB == null) { Logger.WriteLine("Can not retrieve ServiceBroker!"); throw new Exception("Can not retrieve ServiceBroker!"); } InteractiveSBProxy iuProxy = new InteractiveSBProxy(); iuProxy.AgentAuthHeaderValue = new AgentAuthHeader(); iuProxy.AgentAuthHeaderValue.coupon = sbs[0].identOut; iuProxy.AgentAuthHeaderValue.agentGuid = ProcessAgentDB.ServiceGuid; iuProxy.Url = sbs[0].webServiceUrl; StorageStatus storageStatus = iuProxy.AgentCloseExperiment(expCoupon, experimentID); Logger.WriteLine("AgentCloseExperiment status: " + storageStatus.status + " records: " + storageStatus.recordCount); // currently RequestTicketCancellation always returns false // Create ticketing service interface connection to TicketService TicketIssuerProxy ticketingInterface = new TicketIssuerProxy(); ticketingInterface.AgentAuthHeaderValue = new AgentAuthHeader(); ticketingInterface.Url = sbs[0].webServiceUrl; ticketingInterface.AgentAuthHeaderValue.coupon = sbs[0].identOut; ticketingInterface.AgentAuthHeaderValue.agentGuid = ProcessAgentDB.ServiceGuid; if (ticketingInterface.RequestTicketCancellation(expCoupon, TicketTypes.EXECUTE_EXPERIMENT, ProcessAgentDB.ServiceGuid)) { dbService.CancelTicket(expCoupon, TicketTypes.EXECUTE_EXPERIMENT, ProcessAgentDB.ServiceGuid); Logger.WriteLine("Canceled ticket: " + expCoupon.couponId); } else { Logger.WriteLine("Unable to cancel ticket: " + expCoupon.couponId); } } } catch (Exception e1) { Logger.WriteLine("ProcessTasks Cancelled: exception:" + e1.Message + e1.StackTrace); } return status; }