public Experiment GetExperiment(long experimentId) { Experiment exp = new Experiment(); Coupon opCoupon = new Coupon(opHeader.coupon.issuerGuid, opHeader.coupon.couponId, opHeader.coupon.passkey); try { Ticket retrievedTicket = dbTicketing.RetrieveAndVerify(opCoupon, TicketTypes.RETRIEVE_RECORDS); exp = experimentsAPI.GetExperiment(experimentId, retrievedTicket.issuerGuid); return exp; } catch (Exception ex) { Utilities.WriteLog("GetExperiment: " + ex.Message); throw; } }
/// <summary> /// Returns the specified Experiment including the array of associated ExperimentRecords /// </summary> /// <param name="experimentId">the ID of the Experiment to be retrieved</param> /// <returns>the specified Experiment</returns> public Experiment GetExperiment(long experimentId, string sbGuid) { Experiment exp = new Experiment(); exp.experimentId = experimentId; int recordCt = 0; DbConnection myConnection = FactoryDB.GetConnection(); DbCommand myCommand = FactoryDB.CreateCommand("RetrieveExperiment", myConnection); myCommand.CommandType = CommandType.StoredProcedure; myCommand.Parameters.Add(FactoryDB.CreateParameter(myCommand, "@experimentId", experimentId, DbType.Int64)); myCommand.Parameters.Add(FactoryDB.CreateParameter(myCommand, "@issuerGuid", sbGuid, DbType.AnsiString,50)); try { myConnection.Open(); // get experiment record information from table experiments DbDataReader myReader = myCommand.ExecuteReader(); int count = 0; while (myReader.Read()) { count++; //if (myReader["creator_name"] != System.DBNull.Value) // exp.creatorName = (string)myReader["creator_name"]; if (myReader["Issuer_Guid"] != System.DBNull.Value) exp.issuerGuid = (string)myReader["Issuer_Guid"]; if (myReader["current_sequence_no"] != System.DBNull.Value) recordCt = Convert.ToInt32(myReader["current_sequence_no"]); } myReader.Close(); if (count == 0) return null; //Retrieve records for an experiment ExperimentRecord[] expRecs = new ExperimentRecord[recordCt]; DbCommand myCommand2 = FactoryDB.CreateCommand("RetrieveRecordsForExperiment", myConnection); myCommand2.CommandType = CommandType.StoredProcedure; myCommand2.Parameters.Add(FactoryDB.CreateParameter(myCommand2,"@experimentId", experimentId, DbType.Int64)); myCommand2.Parameters.Add(FactoryDB.CreateParameter(myCommand2,"@issuerGuid", sbGuid, DbType.AnsiString,50)); DbDataReader myReader2 = myCommand2.ExecuteReader(); int i = 0; //Not calling GetExperimentRecords as this is more efficient while (myReader2.Read()) { ExperimentRecord expRecord = new ExperimentRecord(); if (myReader2["sequence_no"] != System.DBNull.Value) expRecord.sequenceNum = Convert.ToInt32(myReader2["sequence_no"]); if (myReader2["record_type"] != System.DBNull.Value) expRecord.type = (string)myReader2["record_type"]; if (myReader2["submitter_name"] != System.DBNull.Value) expRecord.submitter = (string)myReader2["submitter_name"]; //if (myReader2["sponsor_GUID"] != System.DBNull.Value) // expRecord.sponsorGuid = (string)myReader2["sponsor_GUID"]; //if (myReader2["submitter_name"] != System.DBNull.Value) // expRecord.submitterName = (string)myReader2["submitter_name"]; if (myReader2["contents"] != System.DBNull.Value) expRecord.contents = (string)myReader2["contents"]; if (myReader2["time_stamp"] != System.DBNull.Value) expRecord.timestamp = DateUtil.SpecifyUTC((DateTime)myReader2["time_stamp"]); if (myReader2["is_xml_searchable"] != System.DBNull.Value) expRecord.xmlSearchable = (bool)myReader2["is_xml_searchable"]; if (recordCt > 0) expRecs[i] = expRecord; i++; } myReader2.Close(); exp.records = expRecs; } catch { throw; } finally { myConnection.Close(); } return exp; }
public Experiment RetrieveExperiment(long experimentID, int userID, int groupID) { int roles = 0; Experiment experiment = null; AuthorizationWrapperClass wrapper = new AuthorizationWrapperClass(); roles = wrapper.GetExperimentAuthorizationWrapper(experimentID, userID, groupID); if ((roles | ExperimentAccess.READ) == ExperimentAccess.READ) { experiment = new Experiment(); experiment.experimentId = experimentID; experiment.issuerGuid = ProcessAgentDB.ServiceGuid; ProcessAgentInfo ess = GetExperimentESS(experimentID); if (ess != null) { ExperimentStorageProxy essProxy = new ExperimentStorageProxy(); Coupon opCoupon = GetEssOpCoupon(experimentID, TicketTypes.RETRIEVE_RECORDS, 60, ess.agentGuid); if (opCoupon == null) { string payload = TicketLoadFactory.Instance().RetrieveRecordsPayload(experimentID, ess.webServiceUrl); opCoupon = CreateTicket(TicketTypes.RETRIEVE_RECORDS, ess.agentGuid, ProcessAgentDB.ServiceGuid, 60, payload); } essProxy.OperationAuthHeaderValue = new OperationAuthHeader(); essProxy.OperationAuthHeaderValue.coupon = opCoupon; essProxy.Url = ess.webServiceUrl; experiment.records = essProxy.GetRecords(experimentID, null); } } else { throw new AccessDeniedException("You do not have permission to read this experiment"); } return experiment; }
public Experiment RetrieveExperiment(long experimentID) { Experiment experiment = null; BrokerDB brokerDB = new BrokerDB(); int roles = 0; int userID = 0; int groupID = 0; //long[] expIDs = null; Ticket expTicket = brokerDB.RetrieveTicket(opHeader.coupon, TicketTypes.REDEEM_SESSION); if (expTicket != null && !expTicket.IsExpired()) { //Parse payload, only get what is needed XmlQueryDoc expDoc = new XmlQueryDoc(expTicket.payload); //long expID = -1; string userStr = expDoc.Query("RedeemSessionPayload/userID"); if ((userStr != null) && (userStr.Length > 0)) userID = Convert.ToInt32(userStr); string groupStr = expDoc.Query("RedeemSessionPayload/groupID"); if ((groupStr != null) && (groupStr.Length > 0)) groupID = Convert.ToInt32(groupStr); if (userID > 0) { AuthorizationWrapperClass wrapper = new AuthorizationWrapperClass(); roles = wrapper.GetExperimentAuthorizationWrapper(experimentID, userID, groupID); } if ((roles | ExperimentAccess.READ) == ExperimentAccess.READ) { experiment = new Experiment(); experiment.experimentId = experimentID; experiment.issuerGuid = ProcessAgentDB.ServiceGuid; ProcessAgentInfo ess = brokerDB.GetExperimentESS(experimentID); if (ess != null) { ExperimentStorageProxy essProxy = new ExperimentStorageProxy(); Coupon opCoupon = brokerDB.GetEssOpCoupon(experimentID, TicketTypes.RETRIEVE_RECORDS, 60, ess.agentGuid); if (opCoupon == null) { string payload = TicketLoadFactory.Instance().RetrieveRecordsPayload(experimentID, ess.webServiceUrl); opCoupon = brokerDB.CreateTicket(TicketTypes.RETRIEVE_RECORDS, ess.agentGuid, ProcessAgentDB.ServiceGuid, 60, payload); } essProxy.OperationAuthHeaderValue = new OperationAuthHeader(); essProxy.OperationAuthHeaderValue.coupon = opCoupon; essProxy.Url = ess.webServiceUrl; essProxy.GetRecords(experimentID, null); } } else { throw new AccessDeniedException("You do not have permission to read this experiment"); } } return experiment; }