/// <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;
 }
Exemple #2
0
        protected void btnDeleteExperiment_Click(object sender, System.EventArgs e)
        {
            ArrayList aList = new ArrayList();

            try
            {
                lbxSelectExperiment.Items.Clear();
                wrapper.RemoveExperimentsWrapper(new long[] {Convert.ToInt32(txtExperimentID.Text)});
                if(Session["UserID"] != null)
                {
                    aList.Add(new Criterion ("User_ID", "=", Session["UserID"].ToString() ));
                }

                if(Session["GroupID"] != null)
                {
                    aList.Add(new Criterion ("Group_ID", "=", Session["GroupID"].ToString()));
                }

                Criterion[] carray = new Criterion [aList.Count];

                for(int i=0; i< aList.Count ; i++)
                {
                    carray[i] = ( Criterion ) aList[i];
                }

                long[] eIDs = wrapper.FindExperimentIDsWrapper(carray);
                LongTag [] eTags = DataStorageAPI.RetrieveExperimentTags(eIDs,userTZ,culture);

                for(int i =0; i< eTags.Length ; i++)
                {
                    System.Web.UI.WebControls.ListItem item = new System.Web.UI.WebControls.ListItem(eTags[i].tag, eTags[i].id.ToString()) ;
                    lbxSelectExperiment.Items .Add(item);
                }

                if(eIDs.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;
                }
            }
            catch (Exception ex)
            {
                lblResponse.Text = Utilities.FormatErrorMessage("Error deleting experiment. "+ ex.Message);
                lblResponse.Visible = true;
            }
        }
        public static long[] RetrieveAuthorizedExpIDs(int userID, int groupID, Criterion[] carray)
        {
            long[] expIDs = null;
            List<Criterion> sbList = new List<Criterion>();
            List<Criterion> essList = new List<Criterion>();

            if (carray != null && carray.Length > 0)
            {
                // Parse the criterion
                for (int i = 0; i < carray.Length; i++)
                {
                    switch (carray[i].attribute.ToLower())
                    {
                        //these criterion are based on external values, requiring special processing of the fields.
                        case "username":
                            sbList.Add(new Criterion("User_ID", carray[i].predicate,
                            "(select user_id from users where user_name=" + carray[i].value + ")"));
                            break;
                        case "groupname":
                            sbList.Add(new Criterion("Group_ID", carray[i].predicate,
                            "(select group_id from group where group_name=" + carray[i].value + ")"));
                            break;
                        case "clientname":
                            sbList.Add(new Criterion("Client_ID", carray[i].predicate,
                                "(select client_id from lab_clients where lab_client_name=" + carray[i].value + ")"));
                            break;
                        case "labservername":
                            sbList.Add(new Criterion("Agent_ID", carray[i].predicate,
                                "(select agent_id from processAgent where agent_name=" + carray[i].value + ")"));
                            break;
                        case "start":
                            sbList.Add(new Criterion("creationtime", carray[i].predicate, carray[i].value));
                            break;
                        case "agent_id":    // Actual SB experiment column names
                        case "annotation":
                        case "client_id":
                        case "creationtime":
                        case "ess_id":
                        case "group_id":
                        case "scheduledstart":
                        case "user_id":
                            sbList.Add(carray[i]);
                            break;
                        // ESS targets
                        case "record_count":
                        case "record_type": // Individual record criterion send to ESS
                        case "contents":
                        default: // any unhandled attributes are record attributes
                            essList.Add(carray[i]);
                            break;
                    }
                } //parsing of Criterion done
            }
            if (sbList.Count == 0 && essList.Count == 0)
            {
                // No search items - Get all experiments allowed
                expIDs = InternalDataDB.RetrieveExperimentIDs(userID, groupID);
            }
            else
            { // Query SB database to find all possible Experiments and related ESS's
                //As there are criteria only experiments with hits will be returned
                bool hasEssCriteria = (essList.Count > 0);
                 List<long> workExp = new List<long>();
                 Hashtable essLists = null;

                // DataSet contains all experimentID and ess ids that pass SB criteria,
                // and a set of all ess_ids for the authorized experiments
                DataSet results = InternalDataDB.RetrieveExperimentIDsCriteria(userID, groupID, sbList.ToArray());
                if (results != null)
                {
                    if (hasEssCriteria)
                    {

                        DataTable essids = results.Tables["ess"];
                        if (essids != null && essids.Rows != null && essids.Rows.Count > 0)
                        {
                            essLists = new Hashtable();
                            foreach (DataRow er in essids.Rows)
                            {
                                if (er[0] != DBNull.Value)
                                {
                                    List<Int64> exps = new List<Int64>();
                                    essLists.Add(Convert.ToInt32(er[0]), exps);
                                }
                            }
                        }
                    }
                    DataTable hits = results.Tables["sbHits"];
                    if (hits != null)
                    {
                        // Add SB hits to list
                        foreach (DataRow r in hits.Rows)
                        {
                            workExp.Add(Convert.ToInt64(r[0]));
                            if (hasEssCriteria)
                            {
                                if (r[1] != DBNull.Value)
                                {
                                    ((List<Int64>)essLists[Convert.ToInt32(r[1])]).Add(Convert.ToInt64(r[0]));
                                }
                            }
                        }
                    }
                    if (hasEssCriteria)
                    { // Have ESS criteria, use the workList and further filter
                        List<Int64> essHits = new List<Int64>();
                        BrokerDB brokerDB = new BrokerDB();

                        //Process ess criteria
                        foreach (object obj in essLists.Keys)
                        {
                            List<Int64> essExps = (List<Int64>)essLists[obj];
                            if (essExps.Count > 0)
                            {
                                int essId = Convert.ToInt32(obj);

                                ProcessAgentInfo info = brokerDB.GetProcessAgentInfo(essId);
                                if ((info != null) && !info.retired)
                                {
                                    ExperimentStorageProxy essProxy = new ExperimentStorageProxy();
                                    AgentAuthHeader authHeader = new AgentAuthHeader();
                                    authHeader.agentGuid = ProcessAgentDB.ServiceGuid;
                                    authHeader.coupon = info.identOut;
                                    essProxy.AgentAuthHeaderValue = authHeader;
                                    essProxy.Url = info.webServiceUrl;
                                    long[] essExpids = essProxy.GetExperimentIDs(essExps.ToArray(), essList.ToArray());
                                    if (essExpids != null && essExpids.Length > 0)
                                    {
                                        foreach (long e in essExpids)
                                        {
                                            essHits.Add(e);
                                        }
                                    }
                                }
                            }
                        }// End of ESS processing
                        expIDs = essHits.ToArray();
                    }
                    else
                    {
                        expIDs = workExp.ToArray();
                    }
                }

            }
            return expIDs;
        }
        /*
        /// <summary>
        /// retrieves all ExperimentIds that the specified user and group has access to
        /// and that match the Criterion. The criterion has been limited to actual ISB experiment fields.
        /// </summary>
        /// <param name="userID"></param>
        /// <param name="groupID"
        /// <param name="carray">The criterion have been limited to ServiceBroker fields</param>
        /// <returns></returns>
        public static DataSet RetrieveExperimentIds(long[] experiments, Criterion[] carray)
        {
            DataSet results = new DataSet();
            StringBuilder whereClause = null;
            List<long> expIDs = new List<long>();

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

                whereClause = new StringBuilder();

                for (int i = 0; i < carray.Length; i++)
                {
                    if(i > 0)
                        whereClause.Append(" AND ");

                    switch (carray[i].attribute.ToLower())
                    {

                        case "agent_id":    // Actual SB experiment column names
                        case "annotation":
                        case "client_id":
                        case "creationtime":
                        case "ess_id":
                        case "group_id":
                        case "record_count":
                        case "scheduledstart":
                        case "status":
                        case "user_id":
                            whereClause.Append(carray[i].ToSQL());
                            break;
                        default: // any unhandled attributes are ignored
                            break;
                    }
                }
                if(whereClause.Length > 7000){
                    throw new Exception("Please reduce the number of criteria for this query, too many arguments!");
                }

              }
                DbConnection myConnection = FactoryDB.GetConnection();
                DbCommand cmd = FactoryDB.CreateCommand("Authorization_RetrieveExpIDsCriteria", myConnection);
                cmd.CommandType = CommandType.StoredProcedure;
                DbParameter userParam = cmd.Parameters.Add(FactoryDB.CreateParameter("@userID", DbType.Int);
                userParam.Value = userID;
                DbParameter groupParam = cmd.Parameters.Add(FactoryDB.CreateParameter("@groupID", DbType.Int);
                groupParam.Value = userID;
                DbParameter whereParam = cmd.Parameters.Add(FactoryDB.CreateParameter(FactoryDB.CreateParameter("@whereClause",DbType.AnsiString,7000));
                if(whereClause != null && whereClause.Length == 0)
                    whereParam.Value = DBNull.Value;
                else
                    whereParam.Value = whereClause.ToString();

            try
            {
                myConnection.Open();
                DbDataReader myReader = cmd.ExecuteReader();
                while (myReader.Read())
                {
                    expIDs.Add(myReader.GetInt64(0));
                }
            }
            catch{}
            finally{
                myConnection.Close();
            }
           return expIDs.ToArray();
        }
        */
        /// <summary>
        /// retrieves all ExperimentIds that the specified user and group has access to
        /// and that match the Criterion. The criterion has been limited to actual ISB experiment fields.
        /// </summary>
        /// <param name="userID"></param>
        /// <param name="groupID"
        /// <param name="carray">The criterion have been limited to ServiceBroker fields</param>
        /// <returns></returns>
        public static DataSet RetrieveExperimentIDsCriteria(int userID, int groupID, Criterion[] carray)
        {
            StringBuilder whereClause = null;
            DataSet results = new DataSet();

            if (carray != null && carray.Length > 0)
            {
                whereClause = new StringBuilder();

                for (int i = 0; i < carray.Length; i++)
                {
                    if (i > 0)
                        whereClause.Append(" AND ");

                    switch (carray[i].attribute.ToLower())
                    {
                        case "agent_id":    // Actual SB experiment column names
                        case "annotation":
                        case "client_id":
                        case "creationtime":
                        case "duration":
                        case "ess_id":
                        case "experiment_id":
                        case "group_id":
                        case "record_count":
                        case "scheduledstart":
                        case "status":
                            whereClause.Append(carray[i].ToSQL());
                            break;
                        case "user_id":
                            whereClause.Append(carray[i].ToSQL());
                            break;
                        //these criterion are based on external values, requiring special processing of the fields.
                        case "username":
                            whereClause.Append("User_ID " + carray[i].predicate);
                            whereClause.Append(" (select user_id from users where user_name='" + carray[i].value + "')");
                            break;
                        case "groupname":
                            whereClause.Append("Group_ID " + carray[i].predicate);
                            whereClause.Append(" (select group_id from group where group_name='" + carray[i].value + "')");
                            break;
                        case "clientguid":
                            whereClause.Append("Client_ID " +carray[i].predicate);
                            whereClause.Append(" (select client_id from lab_clients where client_guid='" + carray[i].value + "')");
                            break;
                        case "clientname":
                            whereClause.Append("Client_ID " + carray[i].predicate);
                            whereClause.Append(" (select client_id from lab_clients where lab_client_name='" + carray[i].value + "')");
                            break;
                        case "labservername":
                            whereClause.Append("Agent_ID " + carray[i].predicate);
                            whereClause.Append(" (select agent_id from processAgent where agent_name='" + carray[i].value + "')");
                            break;
                        case "start":
                            whereClause.Append("creationtime " + carray[i].predicate + " " + carray[i].value);
                            break;
                        // any unhandled attributes are ignored
                        default:
                            break;
                    }
                }
                if (whereClause.Length > 7000)
                {
                    throw new Exception("Please reduce the number of criteria for this query, too many arguments!");
                }

                DbConnection myConnection = FactoryDB.GetConnection();
                DbCommand cmd = FactoryDB.CreateCommand("Authorization_RetrieveExpIDsCriteria", myConnection);
                cmd.CommandType = CommandType.StoredProcedure;

                cmd.Parameters.Add(FactoryDB.CreateParameter("@userID",userID, DbType.Int32));
                cmd.Parameters.Add(FactoryDB.CreateParameter("@groupID", groupID,DbType.Int32));
                cmd.Parameters.Add(FactoryDB.CreateParameter("@criteria", whereClause.ToString(), DbType.AnsiString, 7000));

                try
                {
                    myConnection.Open();
                    DbDataReader myReader = cmd.ExecuteReader();
                    if (myReader.HasRows)
                    {

                        DataTable exp = new DataTable("sbHits");
                        exp.Columns.Add("expid", typeof(System.Int64));
                        exp.Columns.Add("essid", typeof(System.Int32));
                        results.Tables.Add(exp);

                        while (myReader.Read())
                        {
                            DataRow row = exp.NewRow();
                            row["expid"] = myReader.GetInt64(0);
                            if (!myReader.IsDBNull(1))
                                row["essid"] = myReader.GetInt32(1);
                            else
                                row["essid"] = DBNull.Value;
                            exp.Rows.Add(row);
                        }
                    }

                    if (myReader.NextResult())
                    {
                        if (myReader.HasRows)
                        {
                            DataTable ess = new DataTable("ess");
                            ess.Columns.Add("essid", typeof(System.Int32));
                            results.Tables.Add(ess);

                            while (myReader.Read())
                            {
                                if (!myReader.IsDBNull(0))
                                {
                                    DataRow essRow = ess.NewRow();
                                    essRow["essid"] = myReader.GetInt32(0);
                                    ess.Rows.Add(essRow);
                                }
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                   Logger.WriteLine("Error: " + e.Message);
                    throw;
                }
                finally
                {
                    myConnection.Close();
                }

            }
            return results;
        }
Exemple #5
0
        /*
        /// <summary>
        /// retrieves all ExperimentIds that the specified user and group has access to
        /// and that match the Criterion. The criterion has been limited to actual ISB experiment fields.
        /// </summary>
        /// <param name="userID"></param>
        /// <param name="groupID"
        /// <param name="carray">The criterion have been limited to ServiceBroker fields</param>
        /// <returns></returns>
        public static DataSet RetrieveExperimentIds(long[] experiments, Criterion[] carray)
        {
            DataSet results = new DataSet();
            StringBuilder whereClause = null;
            List<long> expIDs = new List<long>();

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

                whereClause = new StringBuilder();

                for (int i = 0; i < carray.Length; i++)
                {
                    if(i > 0)
                        whereClause.Append(" AND ");

                    switch (carray[i].attribute.ToLower())
                    {

                        case "agent_id":    // Actual SB experiment column names
                        case "annotation":
                        case "client_id":
                        case "creationtime":
                        case "ess_id":
                        case "group_id":
                        case "record_count":
                        case "scheduledstart":
                        case "status":
                        case "user_id":
                            whereClause.Append(carray[i].ToSQL());
                            break;
                        default: // any unhandled attributes are ignored
                            break;
                    }
                }
                if(whereClause.Length > 7000){
                    throw new Exception("Please reduce the number of criteria for this query, too many arguments!");
                }

              }
                DbConnection myConnection = FactoryDB.GetConnection();
                DbCommand cmd = FactoryDB.CreateCommand("RetrieveAuthorizedExpIDsCriteria", myConnection);
                cmd.CommandType = CommandType.StoredProcedure;
                DbParameter userParam = cmd.Parameters.Add(FactoryDB.CreateParameter(cmd,"@userID", DbType.Int);
                userParam.Value = userID;
                DbParameter groupParam = cmd.Parameters.Add(FactoryDB.CreateParameter(cmd,"@groupID", DbType.Int);
                groupParam.Value = userID;
                DbParameter whereParam = cmd.Parameters.Add(FactoryDB.CreateParameter(cmd,FactoryDB.CreateParameter("@whereClause",DbType.AnsiString,7000));
                if(whereClause != null && whereClause.Length == 0)
                    whereParam.Value = DBNull.Value;
                else
                    whereParam.Value = whereClause.ToString();

            try
            {
                myConnection.Open();
                DbDataReader myReader = cmd.ExecuteReader();
                while (myReader.Read())
                {
                    expIDs.Add(myReader.GetInt64(0));
                }
            }
            catch{}
            finally{
                myConnection.Close();
            }
           return expIDs.ToArray();
        }
        */
        /// <summary>
        /// retrieves all ExperimentIds that the specified user and group has access to
        /// and that match the Criterion. The criterion has been limited to actual ISB experiment fields.
        /// </summary>
        /// <param name="userID"></param>
        /// <param name="groupID"
        /// <param name="carray">The criterion have been limited to ServiceBroker fields</param>
        /// <returns></returns>
        public static DataSet RetrieveExperimentIDsCriteria(int userID, int groupID, Criterion[] carray)
        {
            //if (carray == null || carray.Length == 0)
            //{
            //    throw new Exception("Method requires Criteria");
            //}
            StringBuilder whereClause = null;
            DataSet results = new DataSet();

            if (carray != null && carray.Length > 0)
            {
                whereClause = new StringBuilder();

                for (int i = 0; i < carray.Length; i++)
                {
                    if (i > 0)
                        whereClause.Append(" AND ");

                    switch (carray[i].attribute.ToLower())
                    {
                        case "agent_id":    // Actual SB experiment column names
                        case "client_id":
                        case "ess_id":
                        case "group_id":
                        case "record_count":
                        case "status":
                        case "user_id":
                            whereClause.Append(carray[i].ToSQL());
                            break;
                        case "annotation":
                        case "creationtime":
                        case "scheduledstart":
                            whereClause.Append(carray[i].ToSQL());
                            break;
                        default: // any unhandled attributes are ignored
                            break;
                    }
                }
                if (whereClause.Length > 7000)
                {
                    throw new Exception("Please reduce the number of criteria for this query, too many arguments!");
                }

                DbConnection myConnection = FactoryDB.GetConnection();
                DbCommand cmd = FactoryDB.CreateCommand("RetrieveAuthorizedExpIDsCriteria", myConnection);
                cmd.CommandType = CommandType.StoredProcedure;

                cmd.Parameters.Add(FactoryDB.CreateParameter(cmd,"@userID",userID, DbType.Int32));
                cmd.Parameters.Add(FactoryDB.CreateParameter(cmd,"@groupID", groupID,DbType.Int32));
                cmd.Parameters.Add(FactoryDB.CreateParameter(cmd,"@criteria", whereClause.ToString(), DbType.AnsiString, 7000));

                try
                {
                    myConnection.Open();
                    DbDataReader myReader = cmd.ExecuteReader();
                    if (myReader.HasRows)
                    {

                        DataTable exp = new DataTable("sbHits");
                        exp.Columns.Add("expid", typeof(System.Int64));
                        exp.Columns.Add("essid", typeof(System.Int32));
                        results.Tables.Add(exp);

                        while (myReader.Read())
                        {
                            DataRow row = exp.NewRow();
                            row["expid"] = myReader.GetInt64(0);
                            if (!myReader.IsDBNull(1))
                                row["essid"] = myReader.GetInt32(1);
                            else
                                row["essid"] = DBNull.Value;
                            exp.Rows.Add(row);
                        }
                    }

                    if (myReader.NextResult())
                    {
                        if (myReader.HasRows)
                        {
                            DataTable ess = new DataTable("ess");
                            ess.Columns.Add("essid", typeof(System.Int32));
                            results.Tables.Add(ess);

                            while (myReader.Read())
                            {
                                if (!myReader.IsDBNull(0))
                                {
                                    DataRow essRow = ess.NewRow();
                                    essRow["essid"] = myReader.GetInt32(0);
                                    ess.Rows.Add(essRow);
                                }
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    Utilities.WriteLog("Error: " + e.Message);
                    throw;
                }
                finally
                {
                    myConnection.Close();
                }

            }
            return results;
        }
 /// <remarks/>
 public void RetrieveExperimentSummaryAsync(Criterion[] carray)
 {
     this.RetrieveExperimentSummaryAsync(carray, null);
 }
 /// <remarks/>
 public System.IAsyncResult BeginRetrieveExperimentRecords(long experimentID, Criterion[] carray, System.AsyncCallback callback, object asyncState)
 {
     return this.BeginInvoke("RetrieveExperimentRecords", new object[] {
                 experimentID,
                 carray}, callback, asyncState);
 }
 public ExperimentRecord[] RetrieveExperimentRecords(long experimentID, Criterion[] carray)
 {
     object[] results = this.Invoke("RetrieveExperimentRecords", new object[] {
                 experimentID,
                 carray});
     return ((ExperimentRecord[])(results[0]));
 }
 /// <remarks/>
 public void RetrieveExperimentRecordsAsync(long experimentID, Criterion[] carray, object userState)
 {
     if ((this.RetrieveExperimentRecordsOperationCompleted == null)) {
         this.RetrieveExperimentRecordsOperationCompleted = new System.Threading.SendOrPostCallback(this.OnRetrieveExperimentRecordsOperationCompleted);
     }
     this.InvokeAsync("RetrieveExperimentRecords", new object[] {
                 experimentID,
                 carray}, this.RetrieveExperimentRecordsOperationCompleted, userState);
 }
        public ExperimentRecord[] RetrieveExperimentRecords(long experimentID, int userID, int groupID, Criterion[] criteria)
        {
            int roles = 0;
            ExperimentRecord[] records = null;
            AuthorizationWrapperClass wrapper = new AuthorizationWrapperClass();
            roles = wrapper.GetExperimentAuthorizationWrapper(experimentID, userID, groupID);

            if ((roles | ExperimentAccess.READ) == ExperimentAccess.READ)
            {
                records = RetrieveExperimentRecords(experimentID, criteria);

            }
            else
            {
                throw new AccessDeniedException("You do not have permission to read this experiment");
            }

            return records;
        }
Exemple #11
0
        public long[] GetExperimentIDs(long[] expSet,Criterion[] filter)
        {
            long[] results = null;
            if (dbTicketing.AuthenticateAgentHeader(agentAuthHeader))
            {
                try
                {
                    results = experimentsAPI.GetExperimentIDs(expSet, agentAuthHeader.coupon.issuerGuid, filter);

                }

                catch (Exception ex)
                {
                    Utilities.WriteLog("GetExperimentIDs: " + ex.Message);
                    throw;
                }
            }
            return results;
        }
Exemple #12
0
        /// <summary>
        /// Get an array of experimentIDs from the specified set that match the criterian.
        /// </summary>
        /// <param name="expSet"></param>
        /// <param name="issuerGuid"></param>
        /// <param name="filter"></param>
        /// <returns></returns>
        public long[] GetExperimentIDs(long[] expSet, string issuerGuid, Criterion[] filter)
        {
            string expIds = Utilities.ToCSV(expSet);
            List<long> essIds = new List<long>();
            StringBuilder sql = new StringBuilder();
            sql.AppendLine("select Experiment_id from experiments where EssExp_id in ");

            // Only use the expSet
            sql.AppendLine("( select EssExp_ID from experiments where experiment_id in ( ");
            sql.Append(expIds);
            sql.Append(") AND issuer_guid = '");
            sql.Append(issuerGuid);
            sql.AppendLine("' ) ");

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

                StringBuilder fields = new StringBuilder();
                StringBuilder attributes = new StringBuilder();
                int fieldCount = 0;
                int attributeCount = 0;
                foreach (Criterion c in filter)
                {
                    if (c.attribute.ToLower().CompareTo("record_count") == 0){
                        sql.Append(" AND EssExp_id in ( select essExp_id from experiments where Current_Sequence_No ");
                        sql.Append(c.predicate);
                        sql.Append( c.value );
                        sql.AppendLine(")");
                    }
                    else if ((c.attribute.ToLower().CompareTo("record_type") == 0)
                        || (c.attribute.ToLower().CompareTo("contents") == 0))
                    {
                        if (fieldCount > 0)
                        {
                            fields.Append(" AND");
                        }
                        fields.Append(" " + c.attribute);
                        fields.Append(c.predicate + " ");
                        fields.Append("'" + c.value + "' ");
                        fieldCount++;
                    }
                    else
                    {
                        if (attributeCount > 0)
                        {
                            attributes.Append(" AND ");
                        }
                        attributes.Append(" ( attribute_name = '" + c.attribute + "' AND attribute_value ");
                        attributes.Append(c.predicate + " ");
                        attributes.Append("'" + c.value + "' )");
                        attributeCount++;
                    }

                }
                if (fieldCount > 0)
                {
                    sql.AppendLine(" AND EssExp_id in ( Select Distinct ESSExp_id from Experiment_Records where ");
                    sql.Append(fields.ToString());
                    sql.AppendLine(")");
                }

                if (attributeCount > 0)
                {
                    sql.AppendLine(" AND EssExp_id in ( Select Distinct ESSExp_id from Record_Attributes where ");

                    sql.AppendLine(attributes.ToString() + " )");
                }

                //sql.AppendLine(") ");
            }
            //sql.AppendLine(")");
            DbConnection connection = FactoryDB.GetConnection();
            Utilities.WriteLog(sql.ToString());
            DbCommand myCommand = FactoryDB.CreateCommand(sql.ToString(), connection);

            try
            {
                connection.Open();
                // get experiment ids from table experiments
                DbDataReader myReader = myCommand.ExecuteReader();

                while (myReader.Read())
                {
                    if (!myReader.IsDBNull(0))
                        essIds.Add(myReader.GetInt64(0));
                }

                myReader.Close();

            }
            finally
            {
                connection.Close();
            }
            return essIds.ToArray();
        }
Exemple #13
0
        /*
         * declare @essID bigint
         * select @essID=EssExp_ID from experiments where Experiment_id = @exp_id and issuer_guid = @issuerGuid
         *
         select sequence_no from Experiment_Records
         * where (EssExp_ID = @essID AND ( (contents like 'data%') OR (record_type = "image"))
         * OR ( record_id in ( select record_id from record_attributes
         * where record_id in ( select record_id from experiment_records where essExp_id=@essID
         * AND( (attribute_name='attribute' and attribute_value ='value')
         *     OR (attribute_name='attributeN' and attribute_value ='valueN')
         * */
        /// <summary>
        /// Returns the specified ExperimentRecord sequence numbers
        /// </summary>
        /// <param name="experimentId">the ID of the Experiment whose record is to be retrieved</param>
        /// <param name="sequenceNum">the sequence number of the record to be retrieved</param>
        /// <returns>the specified ExperimentRecord</returns>
        public int[] GetRecordNumbers(long experimentId, string sbGuid, Criterion[] criteria)
        {
            List<int> records = new List<int>();

            if (criteria != null && criteria.Length > 0)
            {
                bool hasFields = false;
                bool hasAttributes = false;
                StringBuilder sql = new StringBuilder();
                StringBuilder attributes = new StringBuilder();

                for (int i = 0; i < criteria.Length; i++)
                {
                    switch (criteria[i].attribute.ToLower())
                    {
                        //these criterion are based on fields.
                        case "record_type":
                        case "contents":
                        case "submitter_name":
                            if(hasFields)
                                sql.Append(" AND ");
                            sql.Append(criteria[i].ToSQL());
                            hasFields = true;
                            break;
                        default: // it's an attribute
                            if(hasAttributes)
                            attributes.Append(" AND ");
                            attributes.Append("(attribute_name = '" + criteria[i].attribute + "' ");
                            attributes.Append(" AND attribute_value ");
                           attributes.Append(criteria[i].predicate);
                            attributes.Append(" '" + criteria[i].value + "')");
                            hasAttributes = true;
                            break;
                    }
                 }
                 DbConnection myConnection = FactoryDB.GetConnection();
            DbCommand myCommand = FactoryDB.CreateCommand("RetrieveExperimentRecordNumbersCriteria", 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));
            if (hasFields)
                myCommand.Parameters.Add(FactoryDB.CreateParameter(myCommand,"@fieldQuery",sql.ToString(), DbType.AnsiString,2000));
            else
                myCommand.Parameters.Add(FactoryDB.CreateParameter(myCommand,"@fieldQuery",null, DbType.AnsiString,2000));
            if (hasAttributes)
                myCommand.Parameters.Add(FactoryDB.CreateParameter(myCommand,"@attributeQuery", attributes.ToString(), DbType.AnsiString, 2000));
            else
                myCommand.Parameters.Add(FactoryDB.CreateParameter(myCommand,"@attributeQuery", null, DbType.AnsiString, 2000));
            try{
                myConnection.Open();

                // get experiment record information from table experiment_records
                DbDataReader myReader = myCommand.ExecuteReader();

                while (myReader.Read())
                {
                    records.Add(myReader.GetInt32(0));
                }
                }
                catch(Exception ex){
                }
                finally{
                    myConnection.Close();
                }
            }
            else{ // get all the sequence numbers
            DbConnection myConnection = FactoryDB.GetConnection();
            DbCommand myCommand = FactoryDB.CreateCommand("RetrieveExperimentRecordNumbers", 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 experiment_records
                DbDataReader myReader = myCommand.ExecuteReader();

                while (myReader.Read())
                {
                     records.Add(myReader.GetInt32(0));
                }

                myReader.Close();

            }
            catch
            {
                throw;
            }
            finally
            {
                myConnection.Close();
            }
            }
            return records.ToArray(); ;
        }
Exemple #14
0
        /// <summary>
        /// Returns the specified ExperimentRecord sequence numbers
        /// </summary>
        /// <param name="experimentId">the ID of the Experiment whose record is to be retrieved</param>
        /// <param name="sequenceNum">the sequence number of the record to be retrieved</param>
        /// <returns>the specified ExperimentRecord</returns>
        public ExperimentRecord[] GetRecords(long experimentId, string sbGuid, Criterion[] criteria)
        {
            List<ExperimentRecord> records = new List<ExperimentRecord>();
            ExperimentRecord expRecord = null;
            if (criteria != null && criteria.Length > 0)
            {
                bool hasFields = false;
                bool hasAttributes = false;
                StringBuilder sql = new StringBuilder();
                StringBuilder attributes = new StringBuilder();

                for (int i = 0; i < criteria.Length; i++)
                {
                    switch (criteria[i].attribute.ToLower())
                    {
                        //these criterion are based on fields.
                        case "record_type":
                        case "contents":
                        case "submitter_name":
                            if (hasFields)
                                sql.Append(" AND ");
                            sql.Append(criteria[i].ToSQL());
                            hasFields = true;
                            break;
                        default: // it's an attribute
                            if (hasAttributes)
                                attributes.Append(" AND ");
                            attributes.Append("(attribute_name = '" + criteria[i].attribute + "' ");
                            attributes.Append(" AND attribute_value ");
                            attributes.Append(criteria[i].predicate);
                            attributes.Append(" '" + criteria[i].value + "')");
                            hasAttributes = true;
                            break;
                    }
                }
                DbConnection myConnection = FactoryDB.GetConnection();
                DbCommand myCommand = FactoryDB.CreateCommand("RetrieveExperimentRecordsCriteria", 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));
                if (hasFields)
                    myCommand.Parameters.Add(FactoryDB.CreateParameter(myCommand,"@fieldQuery", sql.ToString(), DbType.AnsiString,2000));
                else
                    myCommand.Parameters.Add(FactoryDB.CreateParameter(myCommand,"@fieldQuery", null, DbType.AnsiString,2000));
                if (hasAttributes)
                    myCommand.Parameters.Add(FactoryDB.CreateParameter(myCommand,"@attributeQuery", attributes.ToString(), DbType.AnsiString,2000));
                else
                    myCommand.Parameters.Add(FactoryDB.CreateParameter(myCommand,"@attributeQuery", null, DbType.AnsiString,2000));
                try
                {
                    myConnection.Open();

                    // get experiment record information from table experiment_records
                    DbDataReader myReader = myCommand.ExecuteReader();

                    while (myReader.Read())
                    {
                        expRecord = new ExperimentRecord();
                        if (myReader["record_type"] != System.DBNull.Value)
                            expRecord.type = (string)myReader["record_type"];

                        if (myReader["submitter_Name"] != System.DBNull.Value)
                            expRecord.submitter = (string)myReader["submitter_Name"];

                        if (myReader["contents"] != System.DBNull.Value)
                            expRecord.contents = (string)myReader["contents"];

                        if (myReader["time_stamp"] != System.DBNull.Value)
                            expRecord.timestamp = DateUtil.SpecifyUTC((DateTime)myReader["time_stamp"]);

                        if (myReader["is_xml_searchable"] != System.DBNull.Value)
                            expRecord.xmlSearchable = (bool)myReader["is_xml_searchable"];

                        if (myReader["sequence_no"] != System.DBNull.Value)
                            expRecord.sequenceNum = (int)myReader["sequence_no"];
                        records.Add(expRecord);
                    }
                }
                catch (Exception ex)
                {
                }
                finally
                {
                    myConnection.Close();
                }
            }
            else
            { // get all the sequence numbers
                DbConnection myConnection = FactoryDB.GetConnection();
                DbCommand myCommand = FactoryDB.CreateCommand("RetrieveExperimentRecords", 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 experiment_records
                    DbDataReader myReader = myCommand.ExecuteReader();

                    while (myReader.Read())
                    {
                        expRecord = new ExperimentRecord();

                        if (myReader["sequence_no"] != System.DBNull.Value)
                            expRecord.sequenceNum = (int)myReader["sequence_no"];

                        if (myReader["record_type"] != System.DBNull.Value)
                            expRecord.type = (string)myReader["record_type"];

                        if (myReader["submitter_Name"] != System.DBNull.Value)
                            expRecord.submitter = (string)myReader["submitter_Name"];

                        if (myReader["contents"] != System.DBNull.Value)
                            expRecord.contents = (string)myReader["contents"];

                        if (myReader["time_stamp"] != System.DBNull.Value)
                            expRecord.timestamp = DateUtil.SpecifyUTC((DateTime)myReader["time_stamp"]);

                        if (myReader["is_xml_searchable"] != System.DBNull.Value)
                            expRecord.xmlSearchable = (bool)myReader["is_xml_searchable"];

                        records.Add(expRecord);
                    }

                    myReader.Close();

                }
                catch
                {
                    throw;
                }
                finally
                {
                    myConnection.Close();
                }
            }
            return records.ToArray(); ;
        }
        protected long[] getExperimentIDs(Coupon opCoupon, Criterion[] carray)
        {
            int userID = 0;
            int groupID = 0;
            long[] expIDs = null;
            Ticket expTicket = brokerDB.RetrieveTicket(opCoupon, 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)
                {

                    expIDs = DataStorageAPI.RetrieveAuthorizedExpIDs(userID, groupID, carray);
                }
            }
            return expIDs;
        }
        public ExperimentSummary[] RetrieveExperimentSummary(Criterion[] carray)
        {
            ExperimentSummary[] summaries = null;
            if (brokerDB.AuthenticateIssuedCoupon(opHeader.coupon))
            {
                long[] expIds = getExperimentIDs(opHeader.coupon, carray);
                summaries = InternalDataDB.SelectExperimentSummaries(expIds);

            }
            return summaries;
        }
 public ExperimentRecord[] RetrieveExperimentRecords(long experimentID, Criterion[] carray)
 {
     ExperimentRecord[]  records = null;
     int roles = 0;
     int userID = 0;
     int groupID = 0;
     int clientID = 0;
     long[] expIDs = null;
     if (brokerDB.RedeemSessionInfo(opHeader.coupon, out userID, out groupID, out clientID))
     {
         if (userID > 0)
         {
             if (InternalAuthorizationDB.CanReadExperiment(userID, groupID, experimentID))
             {
                 records = brokerDB.RetrieveExperimentRecords(experimentID, carray);
             }
             else
             {
                 throw new AccessDeniedException("You do not have the required permission to access the experiment");
             }
         }
     }
     return records;
 }
 public long[] RetrieveExperimentIds(Criterion[] carray)
 {
     long[] expIds = null;
     if (brokerDB.AuthenticateIssuedCoupon(opHeader.coupon))
     {
         expIds = getExperimentIDs(opHeader.coupon, carray);
     }
     return expIds;
 }
        /// <summary>
        /// Retrive records from the experiment. It is assummed that read permissons have been checked and passed.
        /// A new coupon is created for this request.
        /// </summary>
        /// <param name="experimentID"></param>
        /// <param name="criteria"></param>
        /// <returns></returns>
        public ExperimentRecord[] RetrieveExperimentRecords(long experimentID, Criterion[] criteria)
        {
            ExperimentRecord[] records = null;
            ProcessAgentInfo ess = GetExperimentESS(experimentID);
            if (ess != null)
            {
                ExperimentStorageProxy essProxy = new ExperimentStorageProxy();
                Coupon opCoupon = CreateCoupon();

                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;
                records = essProxy.GetRecords(experimentID, criteria);
            }
            return records;
        }
 /// <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;
 }
Exemple #21
0
        public ExperimentRecord[] GetRecords(long experimentId, Criterion[] target )
        {
            ExperimentRecord[] expRecords = null;

            Coupon opCoupon = new Coupon(opHeader.coupon.issuerGuid, opHeader.coupon.couponId,
                 opHeader.coupon.passkey);

            try
            {
                Ticket retrievedTicket = dbTicketing.RetrieveAndVerify(opCoupon, TicketTypes.RETRIEVE_RECORDS);
                expRecords = experimentsAPI.GetRecords(experimentId, retrievedTicket.issuerGuid, target);

                return expRecords;
            }

            catch (Exception ex)
            {
                Utilities.WriteLog("GetRecord: " + ex.Message);
                throw;
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="qualifierReferenceID">the ID of the resource represented by the qualifier (null if not necessary);</param>
        /// <param name="type">one of the statically configured qualifierTypes registered with the Service Broker; the qualifier type is used to check type compatibility between function and qualifier in grants</param>
        /// <param name="name">A semantically meaningful string describing the purpose of the qualifier</param>
        /// <param name="parentQualifierID">the ID of a previously created Qualifier to serve as the parent of the Qualifier being added; the parentID locates the new Qualifier in the hierarchy; additional parents may be added by the AddQualifier-Parent() method</param>
        /// <returns>the ID of the new qualifier if it is successfully created, null otherwise</returns>
        public static int AddQualifier( int qualifierReferenceID, int type, string name, int parentQualifierID )
        {
            Qualifier q = new Qualifier();
            q.qualifierReferenceID = qualifierReferenceID;
            q.qualifierType = type;
            q.qualifierName = name;
            bool qualifierReferenceIDValid = false;

            int qualifierID = -1;
            ProcessAgentDB db = new ProcessAgentDB();
            ProcessAgent agent = null;
            //need to check whether the qualifierReferenceID for a particular qualifierType
            //actually exists before it is added to the table
            switch (type)
            {
                    // LabServerfo
                    // Replace with case for all processAgent types an use exits for the combination of ID & type
                case Qualifier.labServerQualifierTypeID:
                {
                    agent = db.GetProcessAgent(qualifierReferenceID);
                    if(agent != null && ((agent.type.Equals(ProcessAgentType.BATCH_LAB_SERVER))
                        ||(agent.type.Equals(ProcessAgentType.LAB_SERVER)))){
                            qualifierReferenceIDValid = true;
                    }
                    break;
                }

                    //LabClient

            case Qualifier.serviceBrokerQualifierTypeID:
                {
                    agent = db.GetProcessAgent(qualifierReferenceID);
                    if (agent != null && ((agent.type.Equals(ProcessAgentType.SERVICE_BROKER))
                          ||(agent.type.Equals(ProcessAgentType.BATCH_SERVICE_BROKER))
                          || (agent.type.Equals(ProcessAgentType.REMOTE_SERVICE_BROKER))))
                    {
                        qualifierReferenceIDValid = true;
                    }
                    break;
                }

            case Qualifier.labSchedulingQualifierTypeID:
                {
                    agent = db.GetProcessAgent(qualifierReferenceID);
                    if (agent != null && agent.type.Equals(ProcessAgentType.LAB_SCHEDULING_SERVER))
                    {
                        qualifierReferenceIDValid = true;
                    }
                    break;
                }
            case Qualifier.userSchedulingQualifierTypeID:
                {
                    agent = db.GetProcessAgent(qualifierReferenceID);
                    if (agent != null && agent.type.Equals(ProcessAgentType.SCHEDULING_SERVER))
                    {
                        qualifierReferenceIDValid = true;
                    }
                    break;
                }
            case Qualifier.storageServerQualifierTypeID:
                {
                    agent = db.GetProcessAgent(qualifierReferenceID);
                    if (agent != null && agent.type.Equals(ProcessAgentType.EXPERIMENT_STORAGE_SERVER))
                    {
                        qualifierReferenceIDValid = true;
                    }
                    break;
                }
            case Qualifier.labClientQualifierTypeID:
                {
                    int[] labClientIDs = InternalAdminDB.SelectLabClientIDs();
                    foreach (int labClientID in labClientIDs)
                    {
                        if (labClientID == qualifierReferenceID)
                        {
                            qualifierReferenceIDValid = true;
                            break;
                        }
                    }
                    break;
                }
                    //Group
                case Qualifier.groupQualifierTypeID:
                {
                    int[] groupIDs = InternalAdminDB.SelectGroupIDs();
                    foreach(int groupID in groupIDs)
                    {
                        if(groupID == qualifierReferenceID)
                        {
                            qualifierReferenceIDValid = true;
                            break;
                        }
                    }
                    break;
                }

                    //Experiment Collection
                case Qualifier.experimentCollectionQualifierTypeID:
                {
                    int[] groupIDs = InternalAdminDB.SelectGroupIDs();
                    foreach(int groupID in groupIDs)
                    {
                        if(groupID == qualifierReferenceID)
                        {
                            qualifierReferenceIDValid = true;
                            break;
                        }
                    }
                    break;
                }

                //Experiment
                case Qualifier.experimentQualifierTypeID:
                {
                    Criterion c = new Criterion("experiment_id","=",qualifierReferenceID.ToString());
                    if (InternalDataDB.SelectExperimentIDs(new Criterion[] { c }).Length > 0)
                        qualifierReferenceIDValid = true;
                    break;
                }

                // Resource Mapping
                case Qualifier.resourceMappingQualifierTypeID:
                {
                    BrokerDB brokerDb = new BrokerDB();
                    ResourceMapping mapping = brokerDb.GetResourceMapping(qualifierReferenceID);
                    if (mapping != null)

                            qualifierReferenceIDValid = true;
                            break;
                }
            }

            if(qualifierReferenceIDValid)
            {
                try
                {
                    qualifierID = InternalAuthorizationDB.InsertQualifier(q);

                    if(qualifierID != -1)
                    {
                        InternalAuthorizationDB.InsertQualifierHierarchy(qualifierID,parentQualifierID);
                    }
                }
                catch(Exception ex)
                {
                    throw;
                }
            }

            return qualifierID;
        }
 /// <remarks/>
 public void RetrieveExperimentRecordsAsync(long experimentID, Criterion[] carray)
 {
     this.RetrieveExperimentRecordsAsync(experimentID, carray, null);
 }
        /// <summary>
        /// owner, readExperiment and superUser privilege
        /// </summary>
        /// <param name="criteria"></param>
        public long[] FindExperimentIDsWrapper(Criterion [] criteria)
        {
            // first, retrieve all experiment IDs which satisfy criteria
            //long[] expIDs = InternalDataDB.SelectExperimentIDs(criteria);

            //then check permissons
            int loginUserID = Convert.ToInt32(Session["UserID"]);
            int sessionGroupID = Convert.ToInt32(Session["GroupID"]);
            return FindExperimentIDsWrapper(loginUserID, sessionGroupID, criteria);
        }
 public ExperimentSummary[] RetrieveExperimentSummary(Criterion[] carray)
 {
     object[] results = this.Invoke("RetrieveExperimentSummary", new object[] {
                 carray});
     return ((ExperimentSummary[])(results[0]));
 }
 /// <summary>
 /// owner, readExperiment and superUser privilege
 /// </summary>
 /// <param name="criteria"></param>
 public long[] FindExperimentIDsWrapper(int loginUserID, int sessionGroupID, Criterion[] criteria)
 {
     // first, retrieve all experiment IDs which satisfy criteria
     long[] expIDs = InternalDataDB.SelectExperimentIDs(criteria);
     return FilterExperimentIDs(loginUserID, sessionGroupID,Function.readExperimentFunctionType, expIDs).ToArray();
 }
 /// <remarks/>
 public void RetrieveExperimentSummaryAsync(Criterion[] carray, object userState)
 {
     if ((this.RetrieveExperimentSummaryOperationCompleted == null)) {
         this.RetrieveExperimentSummaryOperationCompleted = new System.Threading.SendOrPostCallback(this.OnRetrieveExperimentSummaryOperationCompleted);
     }
     this.InvokeAsync("RetrieveExperimentSummary", new object[] {
                 carray}, this.RetrieveExperimentSummaryOperationCompleted, userState);
 }
        public static ExperimentInformation[] GetExperimentInformation(int[] experimentIDs)
        {
            List<ExperimentInformation> list = new List<ExperimentInformation>();
            try
            {
               long[] expIDs = new long[experimentIDs.Length];
               for (int i = 0; i < experimentIDs.Length; i++)
               {
                   expIDs[i] = (long)experimentIDs[i];
               }

                ExperimentAdminInfo[] expSummaries = InternalDataDB.SelectExperimentAdminInfos(expIDs);

                if (expSummaries != null)
                    foreach (ExperimentAdminInfo expSum in expSummaries)
                    {
                        ExperimentInformation info = new ExperimentInformation();
                        info.experimentID = expSum.experimentID;
                        info.userID = expSum.userID;
                        info.effectiveGroupID = expSum.groupID;
                        info.labServerID = expSum.agentID;
                        info.statusCode = expSum.status & StorageStatus.BATCH_MASK;
                        info.submissionTime = expSum.creationTime;
                        info.completionTime = expSum.closeTime;
                        DateTime endTime = expSum.startTime.AddSeconds(expSum.duration);
                        info.expirationTime = endTime;
                        double hours = new TimeSpan(endTime.Ticks - DateTime.UtcNow.Ticks).TotalHours;
                        info.minTimeToLive = hours > 0 ? hours : 0;
                        info.annotation = expSum.annotation;

                      //Get the Experiment records from the ESS if one is used
                        if (expSum.essID > 0)
                        {

                            // This operation should happen within the Wrapper
                            BrokerDB brokerDB = new BrokerDB();
                            ProcessAgentInfo ess = brokerDB.GetProcessAgentInfo(expSum.essID);
                            Coupon opCoupon = brokerDB.GetEssOpCoupon( expSum.experimentID, TicketTypes.RETRIEVE_RECORDS, 60, ess.agentGuid);

                            ExperimentStorageProxy essProxy = new ExperimentStorageProxy();
                            OperationAuthHeader header = new OperationAuthHeader();
                            header.coupon = opCoupon;
                            essProxy.Url = ess.webServiceUrl;
                            essProxy.OperationAuthHeaderValue = header;
                            Criterion errors = new Criterion("record_type", "like", "*Message");
                            Criterion extensions = new Criterion("record_type", "like", "*Extension");
                            Criterion [] criteria = new Criterion[] {errors,extensions };
                            ExperimentRecord[] records = brokerDB.RetrieveExperimentRecords(expSum.experimentID, criteria);
                            if (records != null)
                            {
                                List<String> valWarnings = new List<String>();
                                List<String> execWarnings = new List<String>();
                                foreach (ExperimentRecord rec in records)
                                {
                                    if (rec.type.CompareTo(BatchRecordType.EXECUTION_ERROR) == 0)
                                    {
                                        info.executionErrorMessage = rec.contents;
                                    }
                                    else if (rec.type.CompareTo(BatchRecordType.VALIDATION_ERROR) == 0)
                                    {
                                        info.validationErrorMessage = rec.contents;
                                    }
                                    else if (rec.type.CompareTo(BatchRecordType.BLOB_EXTENSION) == 0)
                                    {
                                        info.xmlBlobExtension = rec.contents;
                                    }
                                    else if (rec.type.CompareTo(BatchRecordType.RESULT_EXTENSION) == 0)
                                    {
                                        info.xmlResultExtension = rec.contents;
                                    }
                                    else if (rec.type.CompareTo(BatchRecordType.EXECUTION_WARNING) == 0)
                                    {
                                        execWarnings.Add(rec.contents);
                                    }
                                    else if (rec.type.CompareTo(BatchRecordType.VALIDATION_WARNING) == 0)
                                    {
                                        valWarnings.Add(rec.contents);
                                    }

                                }
                                if (execWarnings.Count > 0)
                                {
                                    info.executionWarningMessages = execWarnings.ToArray();
                                }
                                if (valWarnings.Count > 0)
                                {
                                    info.validationWarningMessages = valWarnings.ToArray();
                                }
                            }
                        }
                        list.Add(info);
                    }
            }
            catch
            {
                throw;
            }
            if (list.Count > 0)
            {
                return list.ToArray();
            }
            else
                return null;
        }
 /// <remarks/>
 public System.IAsyncResult BeginRetrieveExperimentSummary(Criterion[] carray, System.AsyncCallback callback, object asyncState)
 {
     return this.BeginInvoke("RetrieveExperimentSummary", new object[] {
                 carray}, callback, asyncState);
 }
Exemple #30
0
        /// <summary>
        /// finds all of those Experiments specified in experimentIDs which possess attributes that match the logical AND of conditions expressed in the Criterion array. The search is limited to those experiments that the current user created or for which he or she has a “ReadExperiment” grant. The Criterion conditions must be satisfied elements of the Experiment’s administrative data model such as its ownerID or by the RecordAttributes of a single ExperimentRecord belonging to the experiment for it to qualify. 
        /// </summary>
        /// <param name="criteria">The array of Criterion objects that specify the attributes of the requested experiments; all experimentIDs match if null.</param>
        /// <returns>an array of the IDs of Experiments that match the search criteria</returns>
        // Need to stub in alternate predicates and attribute hash maps. - CV 07/08/04
        public static long[] SelectExperimentIDs(Criterion[] criteria)
        {
            StringBuilder sqlQuery = new StringBuilder("select experiment_id from experiments");

            long[] experimentIDs;

            for (int i = 0; i < criteria.Length; i++)
            {
                if (i == 0)
                {
                    sqlQuery.Append(" where ");
                }
                else {
                    sqlQuery.Append(" AND ");
                }
                sqlQuery.Append(criteria[i].attribute + " " + criteria[i].predicate + " '" + criteria[i].value + "'");

            }

            DbConnection myConnection = FactoryDB.GetConnection();
            DbCommand myCommand = myConnection.CreateCommand();
            myCommand.CommandType = CommandType.Text;
            myCommand.CommandText = sqlQuery.ToString();

            try
            {
                myConnection.Open();
                // get experiment ids from table experiments
                DbDataReader myReader = myCommand.ExecuteReader();
                ArrayList eIDs = new ArrayList();

                while (myReader.Read())
                {
                    if (myReader["experiment_id"] != System.DBNull.Value)
                        eIDs.Add(myReader["experiment_id"]);
                }

                myReader.Close();
                // Converting to a string array
                experimentIDs = new long[eIDs.Count];
                for (int i = 0; i < eIDs.Count; i++)
                {
                    experimentIDs[i] = Convert.ToInt64(eIDs[i]);
                }

            }
            catch (Exception ex)
            {
                throw new Exception("Exception thrown finding experiment", ex);
            }
            finally
            {
                myConnection.Close();
            }

            return experimentIDs;
        }