Exemplo n.º 1
0
        /// <summary>
        /// Returns all scheduled <c>IImagingTask</c>s for the <c>plateID</c>.
        /// </summary>
        IImagingTask[] IImagingTaskProvider.GetImagingTasks(Formulatrix.Integrations.ImagerLink.IRobot robot, string plateID)
        {
            // Check arguments - do it up front to avoid possible inconsistencies later
            if (null == robot)
            {
                throw new System.NullReferenceException("robot must not be null");
            }
            if (null == plateID)
            {
                throw new System.NullReferenceException("plateID must not be null");
            }

            // Log the call to the method
            if (_log.IsDebugEnabled)
            {
                string msg = "Called " + this + ".GetImagingTasks(robot=" + RobotUtils.iRobotToString(robot) + ", plateID=\"" + plateID + "\")";
                _log.Debug(msg);
            }

            // Declare the array that will be populated and returned - default to a zero-length array
            IImagingTask[] iImagingTasks = new IImagingTask[0];

            // Ensure connected to database - may throw an exception but we don't need/want to catch it
            if (System.Data.ConnectionState.Closed.Equals(_platedbConnection.State))
            {
                connectToDB();
            }

            // Try and read the imaging tasks from the db
            try
            {
                // TODO - unnecessary check? Can connectToDB fail without throwing an exception?
                if (System.Data.ConnectionState.Open.Equals(_platedbConnection.State))
                {
                    // Update the parameters
                    _command.Parameters["@p1"].Value = plateID;
                    _command.Parameters["@p2"].Value = robot.Name;

                    // Execute the select
                    OdbcDataReader dataReader = _command.ExecuteReader();

                    // Read the data reader's rows into the ProjectList
                    if (dataReader.HasRows)
                    {
                        // Get an ArrayList to hold the tasks
                        System.Collections.ArrayList tasks = new System.Collections.ArrayList();

                        // Loop over all the returned rows
                        while (dataReader.Read())
                        {
                            // Create and populate a new ImagingTask
                            OPPF.Integrations.ImagerLink.Scheduling.ImagingTask task = new OPPF.Integrations.ImagerLink.Scheduling.ImagingTask();
                            // .NET < 2.0
                            //task.DateToImage = dataReader.GetDateTime(0);
                            // .NET >= 2.0 Only!
                            task.SetDateToImage(DateTime.SpecifyKind(dataReader.GetDateTime(0), DateTimeKind.Utc));
                            if (dataReader.IsDBNull(1))
                            {
                                task.SetDateImaged(DateTime.MinValue);
                            }
                            else
                            {
                                // .NET < 2.0
                                //task.DateImaged = dataReader.GetDateTime(1);
                                // .NET >= 2.0 Only!
                                task.SetDateImaged(DateTime.SpecifyKind(dataReader.GetDateTime(1), DateTimeKind.Utc));
                                //task.DateImaged = dataReader.GetDateTime(1).ToLocalTime();
                            }
                            task.SetPriority(dataReader.GetInt32(2));
                            task.SetState((Formulatrix.Integrations.ImagerLink.Scheduling.ImagingState)dataReader.GetInt32(3));
                            task.SetInQueue(true);

                            // Store this task in the ArrayList
                            tasks.Add(task);

                            //_log.Debug("> Got task: DateToImage=" + task.DateToImage + ", Priority=" + task.Priority + ", State=" + task.State + ", InQueue= " + task.InQueue);
                        }

                        // Convert ArrayList to IImagingTask[]
                        iImagingTasks = (IImagingTask[])tasks.ToArray(typeof(IImagingTask));
                    }

                    // Close the dataReader
                    dataReader.Close();
                }
            }
            catch (Exception e)
            {
                // Log it
                string msg = "Exception " + e.Message + " during direct db part of getImagingTasks() for plate " + plateID + " - will fail down to webservice call";
                _log.Error(msg, e);

                // Don't rethrow - fail down to webservice call
            }

            // If we got no or not enough tasks
            if ((null == iImagingTasks) || (iImagingTasks.GetLength(0) < MIN_IMAGING_TASKS))
            {
                // Hit the webservice, which may cause a schedule to be created
                iImagingTasks = GetImagingTasksFromWebService(robot, plateID);
            }

            // Set an appropriate value for InQueue
            setInQueue(iImagingTasks);

            // Ensure we never return null
            if (null == iImagingTasks)
            {
                // Fix it
                iImagingTasks = new IImagingTask[0];

                // Log it
                _log.Warn("Fixed null iImagingTasks at end of WSPlate.getImagingTasks() for plate " + plateID);
            }

            // Return the array of IImagingTasks
            return(iImagingTasks);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Web service version of GetImagingTasks - useful because it will
        /// cause a full schedule to be written if one doesn't already
        /// exist.
        ///
        /// Warning - this is a lot slower than going straight to platedb!
        /// </summary>
        /// <param name="robot">The robot</param>
        /// <param name="plateID">The barcode of the plate</param>
        /// <returns></returns>
        public IImagingTask[] GetImagingTasksFromWebService(Formulatrix.Integrations.ImagerLink.IRobot robot, string plateID)
        {
            // Check arguments - do it up front to avoid possible inconsistencies later
            if (null == robot)
            {
                throw new System.NullReferenceException("robot must not be null");
            }
            if (null == plateID)
            {
                throw new System.NullReferenceException("plateID must not be null");
            }

            // Log the call
            if (_log.IsInfoEnabled)
            {
                string msg = "Calling WSPlate.getImagingTasks() for plate " + plateID + ", robot " + RobotUtils.iRobotToString(robot);
                _log.Info(msg);
            }

            // Declare the array that will be populated and returned
            // - default to a zero-length array
            IImagingTask[] iImagingTasks = new IImagingTask[0];

            // Set the request
            getImagingTasks request = new getImagingTasks();

            request.robot   = OPPF.Utilities.RobotUtils.createProxy(robot);
            request.plateID = plateID;

            // Make the call
            getImagingTasksResponse response = null;

            try
            {
                WSPlate wsPlate = new WSPlate();
                response = wsPlate.getImagingTasks(request);
            }
            catch (Exception e)
            {
                // Log it
                string msg = "WSPlate.getImagingTasks threw " + e.GetType() + ": " + e.Message + " for plateid \"" + plateID + "\" in robot \"" + robot.Name + "\" - returning empty IImagingTask[]";
                if (e is System.Web.Services.Protocols.SoapException)
                {
                    System.Web.Services.Protocols.SoapException ee = (System.Web.Services.Protocols.SoapException)e;
                    msg = msg + "\n\n" + ee.Detail.InnerXml;
                }
                _log.Error(msg, e);

                // Don't rethrow - just return empty array
                return(iImagingTasks);
            }

            // If we got a response
            if (null != response)
            {
                // Get the array of ImagingTasks from the response
                OPPF.Proxies.ImagingTask[] wrapper = response.wrapper;

                // Convert to IImagingTasks
                iImagingTasks = new IImagingTask[wrapper.GetLength(0)];
                for (int i = 0; i < wrapper.GetLength(0); i++)
                {
                    OPPF.Integrations.ImagerLink.Scheduling.ImagingTask task = new OPPF.Integrations.ImagerLink.Scheduling.ImagingTask();
                    task.SetDateImaged(wrapper[i].dateImaged);
                    task.SetDateToImage(wrapper[i].dateToImage);
                    task.SetInQueue(wrapper[i].inQueue);
                    task.SetPriority(wrapper[i].priority);
                    task.SetState((Formulatrix.Integrations.ImagerLink.Scheduling.ImagingState)wrapper[i].state);

                    iImagingTasks[i] = task;
                }
            }

            // Return the IImagingTask array
            return(iImagingTasks);
        }