示例#1
0
        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;
        }
        public ExperimentRecord[] RetrieveExperimentRecords(long experimentID, Criterion[] carray)
        {
            ExperimentRecord[] records = 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)
                {
                    records = brokerDB.RetrieveExperimentRecords(experimentID, carray);
                }
                else
                {
                    throw new AccessDeniedException("You do not have the required permission to access the experiment");
                }
            }
            return records;
        }