Exemplo n.º 1
0
        /// <summary>
        /// Parses the appInfo and experiment ticket, inserts the task into the database and
        /// creates a dataManager and dataSources defined in the appInfo.
        /// </summary>
        /// <param name="appInfo"></param>
        /// <param name="expCoupon"></param>
        /// <param name="expTicket"></param>
        /// <returns></returns>
        public virtual LabTask CreateLabTask(LabAppInfo appInfo, Coupon expCoupon, Ticket expTicket)
        {
            LabTask labTask = CreateLabTask(appInfo, expTicket);

            if (((labTask.storage != null) && (labTask.storage.Length > 0)))
            {
                // Create DataSourceManager to manage dataSources
                DataSourceManager dsManager = new DataSourceManager();

                // set up an experiment storage handler
                ExperimentStorageProxy ess = new ExperimentStorageProxy();
                ess.OperationAuthHeaderValue = new OperationAuthHeader();
                ess.OperationAuthHeaderValue.coupon = expCoupon;
                ess.Url = labTask.storage;
                dsManager.essProxy = ess;
                dsManager.ExperimentID = labTask.experimentID;
                dsManager.AppKey = appInfo.appKey;
                // Note these dataSources are written to by the application and sent to the ESS
                if ((appInfo.dataSources != null) && (appInfo.dataSources.Length > 0))
                {
                    string[] sources = appInfo.dataSources.Split(',');
                    // Use the experimentID as the storage parameter
                    foreach (string s in sources)
                    {
                       // dsManager.AddDataSource(createDataSource(s));
                    }
                }
                TaskProcessor.Instance.AddDataManager(labTask.taskID, dsManager);
            }
            TaskProcessor.Instance.Add(labTask);
            return labTask;
        }
Exemplo n.º 2
0
        public override LabTask CreateLabTask(LabAppInfo appInfo, Coupon expCoupon, Ticket expTicket)
        {

            long experimentID = -1;
            LabTask task = null;

            //Parse experiment payload 	
            string payload = expTicket.payload;
            XmlQueryDoc expDoc = new XmlQueryDoc(payload);

            string experimentStr = expDoc.Query("ExecuteExperimentPayload/experimentID");
            if ((experimentStr != null) && (experimentStr.Length > 0))
            {
                experimentID = Convert.ToInt64(experimentStr);
            }
            string sbStr = expDoc.Query("ExecuteExperimentPayload/sbGuid");



            // Check to see if an experiment with this ID is already running
            LabDB dbManager = new LabDB();
            LabTask.eStatus status = dbManager.ExperimentStatus(experimentID, sbStr);
            if (status == LabTask.eStatus.NotFound)
            {
                // Check for an existing experiment using the same resources, if found Close it

                //Create the new Task
                if(appInfo.rev.Contains("8.2")){
                   task = iLabs.LabView.LV82.LabViewTask.CreateLabTask(appInfo,expCoupon,expTicket);
                }
                else{
                     task = iLabs.LabView.LV86.LabViewTask.CreateLabTask(appInfo,expCoupon,expTicket);
                }
            }

            else
            {
                task =  TaskProcessor.Instance.GetTask(experimentID);

            }
            return task;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Retrieve a ticket from the database.
        /// The triple 
        /// </summary>
        /// <param name="duration"> minimum remaining time (seconds) to expire or -1 for never expiring tickets</param>
        /// <param name="ticketType"></param>
        /// <param name="redeemerGuid"></param>
        /// <param name="sponsorGuid"></param>
        /// <returns>Retrieved Tickets, or null if  the ticket cannot be found</returns>
        public Ticket[] RetrieveIssuedTickets(long duration, string ticketType, 
            string redeemerGuid, string sponsorGuid)
        {
            List<Ticket> tickets = new List<Ticket>();
            // create sql connection
            DbConnection connection = FactoryDB.GetConnection();

            // create sql command
            // command executes the "RetrieveTicket" stored procedure
            DbCommand cmd = FactoryDB.CreateCommand("GetIssuedTicketByFunction", connection);
            cmd.CommandType = CommandType.StoredProcedure;

            // populate the parameters
            cmd.Parameters.Add(FactoryDB.CreateParameter("@duration", duration, DbType.Int64));
            cmd.Parameters.Add(FactoryDB.CreateParameter("@ticketType", ticketType, DbType.AnsiString, 100));
            cmd.Parameters.Add(FactoryDB.CreateParameter("@redeemerGuid", redeemerGuid, DbType.AnsiString, 50));
            cmd.Parameters.Add(FactoryDB.CreateParameter("@sponsorGuid", sponsorGuid, DbType.AnsiString, 50));

            // execute the command
            DbDataReader dataReader = null;
            try
            {
                connection.Open();
                dataReader = cmd.ExecuteReader();

                while (dataReader.Read())
                {
                    Ticket ticket = new Ticket();
                    ticket.issuerGuid = ServiceGuid;
                    // read ticket id
                    ticket.ticketId = (long)dataReader.GetInt64(0);
                    ticket.type = dataReader.GetString(1);
                    // read coupon id
                    ticket.couponId = (long)dataReader.GetInt64(2);
                    // read redeemer id
                    ticket.redeemerGuid = dataReader.GetString(3);
                    // read sponsor id
                    ticket.sponsorGuid = dataReader.GetString(4);
                    // read expiration
                    ticket.creationTime = dataReader.GetDateTime(5);
                    ticket.duration = dataReader.GetInt64(6);
                    // read payload
                    if (!DBNull.Value.Equals(dataReader.GetValue(7)))
                        ticket.payload = dataReader.GetString(7);
                    // read Cancelled
                    bool cancelled = dataReader.GetBoolean(8);
                    if (!cancelled)
                        tickets.Add(ticket);
                }

            }
            catch (DbException e)
            {
                writeEx(e);
                throw;
            }

            finally
            {
                connection.Close();
            }
            if (tickets.Count > 0)
                return tickets.ToArray();
            else
                return null;
        }
Exemplo n.º 4
0
        public List<Ticket> GetExpiredIssuedTickets()
        {
            List<Ticket> tickets = new List<Ticket>();

              // create sql connection
            DbConnection connection = FactoryDB.GetConnection();

            // create sql command
            // command executes the "CancelTicket" stored procedure
            DbCommand cmd = FactoryDB.CreateCommand("GetExpiredIssuedTickets", connection);
            cmd.CommandType = CommandType.StoredProcedure;

            DbDataReader dataReader = null;
            try{
                connection.Open();
                dataReader = cmd.ExecuteReader();
                while (dataReader.Read())
                {
                    Ticket ticket = new Ticket();
                    ticket.issuerGuid = this.GetIssuerGuid();
                    ticket.ticketId = dataReader.GetInt64(0);
                    ticket.type = dataReader.GetString(1);
                    ticket.couponId = dataReader.GetInt64(2);
                    ticket.redeemerGuid = dataReader.GetString(3);
                    ticket.sponsorGuid = dataReader.GetString(4);
                    ticket.creationTime = dataReader.GetDateTime(5);
                    ticket.duration = dataReader.GetInt64(6);
                    if (!DBNull.Value.Equals(dataReader.GetValue(7)))
                        ticket.payload = dataReader.GetString(7);
                    ticket.isCancelled = !dataReader.GetBoolean(8);
                    tickets.Add(ticket);

                }
                dataReader.Close();
            }
            catch (DbException e)
            {
                writeEx(e);
                throw;
            }

            finally
            {
                connection.Close();
            }

            return tickets;
        }
Exemplo n.º 5
0
        /// <summary>
        /// Mark the ticket as cancelled in the DB
        /// </summary>
        /// <param name="ticket"></param>
        /// <returns></returns>
        public bool CancelIssuedTicket(Coupon coupon, Ticket ticket)
        {
            bool status = false;
            // create sql connection
            DbConnection connection = FactoryDB.GetConnection();

            // create sql command
            // command executes the "CancelTicket" stored procedure
            DbCommand cmd = FactoryDB.CreateCommand("CancelIssuedTicket", connection);
            cmd.CommandType = CommandType.StoredProcedure;

            // populate the parameters
            cmd.Parameters.Add(FactoryDB.CreateParameter("@couponID", coupon.couponId, DbType.Int64));
            cmd.Parameters.Add(FactoryDB.CreateParameter("@redeemer", ticket.redeemerGuid, DbType.AnsiString, 50));
            cmd.Parameters.Add(FactoryDB.CreateParameter("@ticketType", ticket.type,DbType.AnsiString, 100));

            // execute the command
            try
            {
                connection.Open();
                status = Convert.ToBoolean(cmd.ExecuteScalar());
            }
            catch (DbException e)
            {
                writeEx(e);
                throw;
            }
            finally
            {
                connection.Close();
            }

            return status;
        }
Exemplo n.º 6
0
        protected Ticket GetIssuedTicket(Coupon coupon, string type, string redeemer)
        {
            Ticket results = null;

            // create sql connection
            DbConnection connection = FactoryDB.GetConnection();

            // create sql command
            // command executes the "CancelTicket" stored procedure
            DbCommand cmd = FactoryDB.CreateCommand("GetIssuedTicketByRedeemer", connection);
            cmd.CommandType = CommandType.StoredProcedure;

            // populate the parameters
            cmd.Parameters.Add(FactoryDB.CreateParameter("@couponID", coupon.couponId,DbType.Int64));
            cmd.Parameters.Add(FactoryDB.CreateParameter("@ticketType", type, DbType.AnsiString, 100));
            cmd.Parameters.Add(FactoryDB.CreateParameter("@redeemer", redeemer,DbType.AnsiString, 50));

            DbDataReader dataReader = null;
            try
            {
                connection.Open();
                dataReader = cmd.ExecuteReader();
                while (dataReader.Read())
                {
                    Ticket ticket = new Ticket();
                    ticket.couponId = coupon.couponId;
                    ticket.issuerGuid = coupon.issuerGuid;
                    ticket.ticketId = dataReader.GetInt64(0);
                    ticket.type = dataReader.GetString(1);
                    ticket.redeemerGuid = dataReader.GetString(3);
                    ticket.sponsorGuid = dataReader.GetString(4);
                    ticket.creationTime = dataReader.GetDateTime(5);
                    ticket.duration = dataReader.GetInt64(6);
                    if (!DBNull.Value.Equals(dataReader.GetValue(7)))
                    ticket.payload = dataReader.GetString(7);
                    bool cancelled = dataReader.GetBoolean(8);
                    if (!cancelled)
                    {
                        results = ticket;
                    }
                }
                dataReader.Close();
            }
            catch (DbException e)
            {
                writeEx(e);
                throw;
            }

            finally
            {
                connection.Close();
            }

            return results;
        }
Exemplo n.º 7
0
        /// <summary>
        /// Retrieve all the tickets of a certain type from the database 
        /// </summary>
        /// <param name="ticketType"></param>
        /// <returns>Array of ticket objects</returns>
        public Ticket[] RetrieveTicketsByType(String ticketType)
        {
            ArrayList ticketsList = new ArrayList();
            Ticket ticket = null;

            // create sql connection
            DbConnection connection = FactoryDB.GetConnection();

            // create sql command
            // command executes the "RetrieveTicketsByType" stored procedure
            DbCommand cmd = connection.CreateCommand();
            cmd.CommandText= "RetrieveTicketsByType";
            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Parameters.Add(FactoryDB.CreateParameter(cmd,"@ticketType", ticketType,DbType.AnsiString,100));

            // execute the command
            DbDataReader dataReader = null;
            try
            {
                connection.Open();
                dataReader = cmd.ExecuteReader();

                while (dataReader.Read())
                {
                    ticket = new Ticket();
                    // read ticket id
                    ticket.ticketId = (long)dataReader.GetInt64(1);
                    ticket.type = dataReader.GetString(2);
                    // read coupon id
                    long couponID = (long)dataReader.GetInt64(3);
                    string issuerGUID = dataReader.GetString(4);
                    // read redeemer id
                    ticket.redeemerGuid = dataReader.GetString(5);
                    // read sponsor id
                    ticket.sponsorGuid = dataReader.GetString(6);

                    // read expiration
                    ticket.creationTime = dataReader.GetDateTime(7);
                    ticket.duration = dataReader.GetInt64(8);
                    // read payload
                    ticket.payload = dataReader.GetString(9);
                    // read Cancelled
                    bool cancelled = dataReader.GetBoolean(10);

                    // add to tickets list
                    if (!cancelled)
                        ticketsList.Add(ticket);
                }
            }
            catch (DbException e)
            {
                writeEx(e);
                throw;
            }

            finally
            {
                connection.Close();
            }

            Ticket[] tickets = (Ticket[])ticketsList.ToArray(ticket.GetType());
            return tickets;
        }
Exemplo n.º 8
0
        /// <summary>
        /// Retrieve a ticket from the database. ProcessAgent version
        /// The triple (couponID, redeemerID, type) uniquely identifies the ticket.
        /// Note the ProcessAgent must store the tickets, a null return is a valid value.
        /// </summary>
        /// <param name="coupon"></param>
        /// <param name="type"></param>
        /// <param name="redeemerGUID"></param>
        /// <returns>Retrieved Ticket, or null if  the ticket cannot be found</returns>
        public virtual Ticket RetrieveTicket(Coupon coupon, string ticketType, string redeemerGUID)
        {
            Ticket result = null;
            // create sql connection
            DbConnection connection = FactoryDB.GetConnection();

            // create sql command
            // command executes the "RetrieveTicket" stored procedure
            DbCommand cmd = connection.CreateCommand();
            cmd.CommandText =  "GetTicket";
            cmd.CommandType = CommandType.StoredProcedure;

            // populate the parameters
            cmd.Parameters.Add(FactoryDB.CreateParameter(cmd,"@couponID", coupon.couponId,DbType.Int64));
            cmd.Parameters.Add(FactoryDB.CreateParameter(cmd,"@issuer", coupon.issuerGuid,DbType.AnsiString, 50));
            cmd.Parameters.Add(FactoryDB.CreateParameter(cmd,"@redeemer", redeemerGUID,DbType.AnsiString, 50));
            cmd.Parameters.Add(FactoryDB.CreateParameter(cmd,"@ticketType", ticketType,DbType.AnsiString, 100));

            // execute the command
            DbDataReader dataReader = null;
            try
            {
                connection.Open();
                dataReader = cmd.ExecuteReader();

                while (dataReader.Read())
                {
                    Ticket ticket = new Ticket();
                    // read ticket id
                    ticket.ticketId = (long)dataReader.GetInt64(0);
                    ticket.type = dataReader.GetString(1);
                    // read coupon id
                    ticket.couponId = (long)dataReader.GetInt64(2);
                    ticket.issuerGuid = dataReader.GetString(3);
                    // read redeemer id
                    ticket.redeemerGuid = dataReader.GetString(4);
                    // read sponsor id
                    ticket.sponsorGuid = dataReader.GetString(5);
                    // read expiration
                    ticket.creationTime = dataReader.GetDateTime(6);
                    ticket.duration = dataReader.GetInt64(7);
                    // read payload
                    ticket.payload = dataReader.GetString(8);
                    // read Cancelled
                    bool cancelled = dataReader.GetBoolean(9);
                    if (!cancelled)
                        result = ticket;
                }

            }
            catch (DbException e)
            {
                writeEx(e);
                throw;
            }

            finally
            {
                connection.Close();
            }

            return result;
        }
Exemplo n.º 9
0
        /// <summary>
        /// Mark the ticket as cancelled in the DB, this cancels the local copy of the ticket if found.
        /// Should not be directly called but as the result of a successful RequestTicketCancellation call.
        /// </summary>
        /// <param name="ticket"></param>
        /// <returns><code>true</code> if the ticket has been cancelled successfully</returns>
        public bool CancelTicket(Ticket ticket)
        {
            bool status = false;
            // create sql connection
            DbConnection connection = FactoryDB.GetConnection();

            // create sql command
            // command executes the "CancelTicket" stored procedure
            DbCommand cmd = connection.CreateCommand();
            cmd.CommandText = "CancelTicketByID";
            cmd.CommandType = CommandType.StoredProcedure;
            // populate the parameters
            cmd.Parameters.Add(FactoryDB.CreateParameter(cmd,"@ticketID", ticket.ticketId, DbType.Int64));
            cmd.Parameters.Add(FactoryDB.CreateParameter(cmd,"@issuer", ticket.issuerGuid, DbType.AnsiString,50));

            // execute the command
            //DbDataReader dataReader = null;
            try
            {
                connection.Open();
                status = Convert.ToBoolean(cmd.ExecuteScalar());
            }
            catch (DbException e)
            {
                writeEx(e);
                throw;
            }

            finally
            {
                connection.Close();
            }

            return status;
        }
Exemplo n.º 10
0
        /// <summary>
        /// Insert a ticket in the Ticket table
        /// </summary>
        /// <param name="ticket"></param>
        /// <returns></returns>
        public void InsertTicket(Ticket ticket)
        {
            // create sql connection
            DbConnection connection = FactoryDB.GetConnection();

            // command executes the "InsertTicket" stored procedure
            DbCommand cmd = connection.CreateCommand();
            cmd.CommandText = "InsertTicket";
            cmd.CommandType = CommandType.StoredProcedure;

            // populate parameters
            cmd.Parameters.Add(FactoryDB.CreateParameter(cmd,"@ticketID", ticket.ticketId,DbType.Int64));
            cmd.Parameters.Add(FactoryDB.CreateParameter(cmd,"@ticketType", ticket.type,DbType.AnsiString, 100));
            cmd.Parameters.Add(FactoryDB.CreateParameter(cmd,"@couponID", ticket.couponId,DbType.Int64));
            cmd.Parameters.Add(FactoryDB.CreateParameter(cmd,"@issuerGUID", ticket.issuerGuid,DbType.AnsiString, 50));
            cmd.Parameters.Add(FactoryDB.CreateParameter(cmd,"@redeemerGUID", ticket.redeemerGuid,DbType.AnsiString, 50));
            cmd.Parameters.Add(FactoryDB.CreateParameter(cmd,"@sponsorGUID", ticket.sponsorGuid,DbType.AnsiString, 50));
            cmd.Parameters.Add(FactoryDB.CreateParameter(cmd,"@payload",ticket.payload, DbType.String));
            cmd.Parameters.Add(FactoryDB.CreateParameter(cmd,"@cancelled",0, DbType.Boolean));
            cmd.Parameters.Add(FactoryDB.CreateParameter(cmd,"@creationTime",ticket.creationTime, DbType.DateTime));
            cmd.Parameters.Add(FactoryDB.CreateParameter(cmd,"@duration", ticket.duration,DbType.Int64));

            long id = -1;
            try
            {
                connection.Open();
                id = Convert.ToInt64(cmd.ExecuteScalar());
            }
            catch (DbException e)
            {
                writeEx(e);
                throw;
            }
            finally
            {
                connection.Close();
            }
        }
        public override LabTask CreateLabTask(LabAppInfo appInfo, Coupon expCoupon, Ticket expTicket)
        {
            long experimentID = -1;
            LabTask task = null;
            string revision = null;
            //Parse experiment payload
            string payload = expTicket.payload;
            XmlQueryDoc expDoc = new XmlQueryDoc(payload);

            string experimentStr = expDoc.Query("ExecuteExperimentPayload/experimentID");
            if ((experimentStr != null) && (experimentStr.Length > 0))
            {
                experimentID = Convert.ToInt64(experimentStr);
            }
            string sbStr = expDoc.Query("ExecuteExperimentPayload/sbGuid");

            // Check to see if an experiment with this ID is already running
            LabDB dbManager = new LabDB();
            LabTask.eStatus status = dbManager.ExperimentStatus(experimentID, sbStr);
            if (status == LabTask.eStatus.NotFound)
            {
                // Check for an existing experiment using the same resources, if found Close it

                //Create the new Task
                if (appInfo.rev == null || appInfo.rev.Length < 2)
                {
                    revision = appInfo.rev;
                }
                else
                {
                    revision = ConfigurationManager.AppSettings["LabViewVersion"];
                }
                if (revision != null && revision.Length > 2)
                {
                    if (revision.Contains("8.2"))
                    {
                        task = new iLabs.LabView.LV82.LabViewInterface().CreateLabTask(appInfo, expCoupon, expTicket);
                    }
                    else if (revision.Contains("8.6"))
                    {
                        task = new iLabs.LabView.LV86.LabViewInterface().CreateLabTask(appInfo, expCoupon, expTicket);
                    }
                    else if (revision.Contains("2009"))
                    {
                        task = new iLabs.LabView.LV2009.LabViewInterface().CreateLabTask(appInfo, expCoupon, expTicket);
                    }

                    else if (revision.Contains("2010"))
                    {
                        task = new iLabs.LabView.LV2010.LabViewInterface().CreateLabTask(appInfo, expCoupon, expTicket);
                    }
                    else if (revision.Contains("2011"))
                    {
                        task = new iLabs.LabView.LV2011.LabViewInterface().CreateLabTask(appInfo, expCoupon, expTicket);
                    }
                    else if (revision.Contains("2012"))
                    {
                        task = new iLabs.LabView.LV2012.LabViewInterface().CreateLabTask(appInfo, expCoupon, expTicket);
                    }
                    else if (revision.Contains("WS"))
                    {
                        task = new iLabs.LabView.LVWS.LabViewInterface().CreateLabTask(appInfo, expCoupon, expTicket);
                    }
                }
                else // Default to LV 2009
                {
                    task = new iLabs.LabView.LV2009.LabViewInterface().CreateLabTask(appInfo, expCoupon, expTicket);
                }

            }
            else
            {
                task =  TaskProcessor.Instance.GetTask(experimentID,expCoupon.issuerGuid);
            }
            return task;
        }
Exemplo n.º 12
0
 public virtual LabTask CreateLabTask(LabAppInfo appInfo, Coupon expCoupon, Ticket expTicket)
 {
     return new LabTask();
 }
        public LabTask CreateLabTask(LabAppInfo appInfo, Coupon expCoupon, Ticket expTicket)
        {
            // set defaults
            DateTime startTime = DateTime.UtcNow;
            long duration = -1L;
            long experimentID = 0;
            int status = -1;

            string statusViName = null;
            string statusTemplate = null;
            string templatePath = null;
            LabDB dbManager = new LabDB();
            string qualName = null;
            string fullName = null;  // set defaults
            string viName = null;

            //CHeck that a labVIEW interface revision is set
            //if (appInfo.rev == null || appInfo.rev.Length < 2)
            //{
            //    appInfo.rev = ConfigurationManager.AppSettings["LabViewVersion"];
            //}

            ////Parse experiment payload, only get what is needed
            string payload = expTicket.payload;
            XmlQueryDoc expDoc = new XmlQueryDoc(payload);
            string essService = expDoc.Query("ExecuteExperimentPayload/essWebAddress");
            string startStr = expDoc.Query("ExecuteExperimentPayload/startExecution");
            string durationStr = expDoc.Query("ExecuteExperimentPayload/duration");
            string groupName = expDoc.Query("ExecuteExperimentPayload/groupName");
            string userName = expDoc.Query("ExecuteExperimentPayload/userName");
            string expIDstr = expDoc.Query("ExecuteExperimentPayload/experimentID");

            if ((startStr != null) && (startStr.Length > 0))
            {
                startTime = DateUtil.ParseUtc(startStr);
            }
            if ((durationStr != null) && (durationStr.Length > 0) && !(durationStr.CompareTo("-1") == 0))
            {
                duration = Convert.ToInt64(durationStr);
            }
            if ((expIDstr != null) && (expIDstr.Length > 0))
            {
                experimentID = Convert.ToInt64(expIDstr);
            }

            if (appInfo.extraInfo != null && appInfo.extraInfo.Length > 0)
            {
                // Note should have either statusVI or template pair
                // Add Option for VNCserver access
                try
                {
                    XmlQueryDoc viDoc = new XmlQueryDoc(appInfo.extraInfo);
                    statusViName = viDoc.Query("extra/status");
                    statusTemplate = viDoc.Query("extra/statusTemplate");
                    templatePath = viDoc.Query("extra/templatePath");
                }
                catch (Exception e)
                {
                    string err = e.Message;
                }
            }

            // log the experiment for debugging

            Logger.WriteLine("Experiment: " + experimentID + " Start: " + DateUtil.ToUtcString(startTime) + " \tduration: " + duration);
            long statusSpan = DateUtil.SecondsRemaining(startTime, duration);

            if (!IsLoaded(appInfo.application))
            {
                viName = LoadVI(appInfo.path, appInfo.application);
                if (false) // Check for controls first
                {
                    string[] names = new string[4];
                    object[] values = new object[4];
                    names[0] = "CouponId";
                    values[0] = expCoupon.couponId;
                    names[1] = "Passcode";
                    values[1] = expCoupon.passkey;
                    names[2] = "IssuerGuid";
                    values[2] = expCoupon.issuerGuid;
                    names[3] = "ExperimentId";
                    values[3] = experimentID;
                    SetControlValues(viName, names, values);
                }
                OpenFrontPanel(viName, true, LabViewTypes.eFPState.eVisible);
            }
            else
            {
                viName = LoadVI(appInfo.path, appInfo.application);
            }
            if (viName == null)
            {
                status = -1;
                string err = "Unable to Find: " + appInfo.path + @"\" + appInfo.application;
                Logger.WriteLine(err);
                throw new Exception(err);
            }
            // Get qualifiedName
            qualName = qualifiedName(viName);
            fullName = appInfo.path + @"\" + appInfo.application;

            status = GetVIStatus(viName);

            Logger.WriteLine("CreateLabTask - " + qualName + ": VIstatus: " + status);
            switch (status)
            {
                case -10:
                    throw new Exception("Error GetVIStatus: " + status);
                    break;
                case -1:
                    // VI not in memory
                    throw new Exception("Error GetVIStatus: " + status);

                    break;
                case 0: // eBad == 0
                    break;
                case 1: // eIdle == 1 vi in memory but not running
                    //LabViewTypes.eFPState fpState = GetFPStatus(viName);
                   //if (fpState != LabViewTypes.eFPState.eVisible)
                    //{
                        OpenFrontPanel(viName, true, LabViewTypes.eFPState.eVisible);
                    //}
                    ResetVI(viName);
                    break;
                case 2: // eRunTopLevel: this should be the LabVIEW application
                    break;
                case 3: // eRunning
                    //Unless the Experiment is reentrant it should be stopped and be reset.
                    if (!appInfo.reentrant)
                    {
                        int stopStatus = StopVI(viName);
                        if (stopStatus != 0)
                        {
                            AbortVI(viName);
                        }
                        ResetVI(viName);
                    }
                    break;
                default:
                    throw new Exception("Error GetVIStatus: unknown status: " + status);
                    break;
            }
            try
            {
                SetBounds(viName, 0, 0, appInfo.width, appInfo.height);
                Logger.WriteLine("SetBounds: " + appInfo.application);
            }
            catch (Exception sbe)
            {
                Logger.WriteLine("SetBounds exception: " + Utilities.DumpException(sbe));
            }
            SubmitAction("unlockvi", qualifiedName(viName));
            Logger.WriteLine("unlockvi Called: ");

            // Create the labTask & store in database;
            LabViewTask task = new LabViewTask();
            task.labAppID = appInfo.appID;
            task.experimentID = experimentID;
            task.groupName = groupName;
            task.startTime = startTime;
            if (duration > 0)
                task.endTime = startTime.AddTicks(duration * TimeSpan.TicksPerSecond);
            else
                task.endTime = DateTime.MinValue;
            task.Status = LabTask.eStatus.Scheduled;
            task.couponID = expTicket.couponId;
            task.storage = essService;
            task.data = task.constructTaskXml(appInfo.appID, fullName, appInfo.rev, statusViName, essService);
            long taskID = dbManager.InsertTaskLong(task);
            task.taskID = taskID;

            if ((statusTemplate != null) && (statusTemplate.Length > 0))
            {
                statusViName = CreateFromTemplate(templatePath, statusTemplate, task.taskID.ToString());
            }

            if (((essService != null) && (essService.Length > 0)))
            {
                // Create DataSourceManager to manage dataSocket connections
                DataSourceManager dsManager = new DataSourceManager();

                // set up an experiment storage handler
                ExperimentStorageProxy ess = new ExperimentStorageProxy();
                ess.OperationAuthHeaderValue = new OperationAuthHeader();
                ess.OperationAuthHeaderValue.coupon = expCoupon;
                ess.Url = essService;
                dsManager.essProxy = ess;
                dsManager.ExperimentID = experimentID;
                dsManager.AppKey = qualName;
                // Note these dataSources are written to by the application and sent to the ESS
                if ((appInfo.dataSources != null) && (appInfo.dataSources.Length > 0))
                {
                    string[] sockets = appInfo.dataSources.Split(',');
                    // Use the experimentID as the storage parameter
                    foreach (string s in sockets)
                    {
                        LVDataSocket reader = new LVDataSocket();
                        dsManager.AddDataSource(reader);
                        if (s.Contains("="))
                        {
                            string[] nv = s.Split('=');
                            reader.Type = nv[1];
                            reader.Connect(nv[0], LabDataSource.READ_AUTOUPDATE);

                        }
                        else
                        {
                            reader.Connect(s, LabDataSource.READ_AUTOUPDATE);
                        }
                    }
                }
                TaskProcessor.Instance.AddDataManager(task.taskID, dsManager);
            }

            TaskProcessor.Instance.Add(task);
            return task;
        }
Exemplo n.º 14
0
        /// <summary>
        /// Parses the appInfo and experiment ticket, inserts the task into the database, 
        /// but does not create the DataManager.
        /// </summary>
        /// <param name="appInfo"></param>
        /// <param name="expTicket"></param>
        /// <returns></returns>
        public virtual LabTask CreateLabTask(LabAppInfo appInfo, Ticket expTicket)
        {
            // set defaults
            DateTime startTime = DateTime.UtcNow;
            long experimentID = 0;

            string statusName = null;
            string statusTemplate = null;
            string templatePath = null;

            string qualName = null;
            string fullName = null;  // set defaults
            long duration = -1L;

            LabTask labTask = null;

            LabDB dbManager = new LabDB();

            ////Parse experiment payload, only get what is needed
            string payload = expTicket.payload;
            XmlQueryDoc expDoc = new XmlQueryDoc(payload);
            string essService = expDoc.Query("ExecuteExperimentPayload/essWebAddress");
            string startStr = expDoc.Query("ExecuteExperimentPayload/startExecution");
            string durationStr = expDoc.Query("ExecuteExperimentPayload/duration");
            string groupName = expDoc.Query("ExecuteExperimentPayload/groupName");
            string userName = expDoc.Query("ExecuteExperimentPayload/userName");
            string expIDstr = expDoc.Query("ExecuteExperimentPayload/experimentID");

            if ((startStr != null) && (startStr.Length > 0))
            {
                startTime = DateUtil.ParseUtc(startStr);
            }
            if ((durationStr != null) && (durationStr.Length > 0) && !(durationStr.CompareTo("-1") == 0))
            {
                duration = Convert.ToInt64(durationStr);
            }
            if ((expIDstr != null) && (expIDstr.Length > 0))
            {
                experimentID = Convert.ToInt64(expIDstr);
            }

            if (appInfo.extraInfo != null && appInfo.extraInfo.Length > 0)
            {
                // Note should have either statusVI or template pair
                // Add Option for VNCserver access
                try
                {
                    XmlQueryDoc viDoc = new XmlQueryDoc(appInfo.extraInfo);
                    statusName = viDoc.Query("extra/status");
                    statusTemplate = viDoc.Query("extra/statusTemplate");
                    templatePath = viDoc.Query("extra/templatePath");
                }
                catch (Exception e)
                {
                    string err = e.Message;
                }
            }

            // log the experiment for debugging

            Logger.WriteLine("Experiment: " + experimentID + " Start: " + DateUtil.ToUtcString(startTime) + " \tduration: " + duration);
            long statusSpan = DateUtil.SecondsRemaining(startTime, duration);
            //launchClient(experimentID, essService, appInfo);

            //factory constructs the correct LabTask object Type
            labTask = CreateLabTask();

            labTask.labAppID = appInfo.appID;
            labTask.experimentID = experimentID;
            labTask.groupName = groupName;
            labTask.startTime = startTime;
            if (duration > 0)
                labTask.endTime =  startTime.AddTicks(duration * TimeSpan.TicksPerSecond);
            else
                labTask.endTime = DateTime.MinValue;
            labTask.couponID = expTicket.couponId;
            labTask.issuerGUID = expTicket.issuerGuid;
            labTask.storage = essService;
            labTask.data = labTask.constructTaskXml(appInfo.appID, fullName, appInfo.rev, statusName, essService);
            // Create  & store the labTask in database and return an LabTask object;
            long taskID = dbManager.InsertTaskLong(labTask);
            labTask.taskID = taskID;
            return labTask;
        }
Exemplo n.º 15
0
        public static LabTask CreateLabTask(LabAppInfo appInfo, Coupon expCoupon, Ticket expTicket)
        {
            // set defaults
            DateTime startTime = DateTime.UtcNow;
            long duration = -1L;
            long experimentID = 0;
            int status = -1;

            string statusViName = null;
            string statusTemplate = null;
            string templatePath = null;
            LabDB dbManager = new LabDB();
            string qualName = null;
            string fullName = null;  // set defaults
           
            LabTask labTask = null;
            LabViewTask task = null;
            VirtualInstrument vi = null;
            LabViewInterface lvi = null;
            

            ////Parse experiment payload, only get what is needed 	
            string payload = expTicket.payload;
            XmlQueryDoc expDoc = new XmlQueryDoc(payload);
            string essService = expDoc.Query("ExecuteExperimentPayload/essWebAddress");
            string startStr = expDoc.Query("ExecuteExperimentPayload/startExecution");
            string durationStr = expDoc.Query("ExecuteExperimentPayload/duration");
            string groupName = expDoc.Query("ExecuteExperimentPayload/groupName");
            string userName = expDoc.Query("ExecuteExperimentPayload/userName");

            if ((startStr != null) && (startStr.Length > 0))
            {
                startTime = DateUtil.ParseUtc(startStr);
            }
            if ((durationStr != null) && (durationStr.Length > 0) && !(durationStr.CompareTo("-1") == 0))
            {
                duration = Convert.ToInt64(durationStr);
            }


            if (appInfo.extraInfo != null && appInfo.extraInfo.Length > 0)
            {
                // Note should have either statusVI or template pair
                // Add Option for VNCserver access
                try
                {
                    XmlQueryDoc viDoc = new XmlQueryDoc(appInfo.extraInfo);
                    statusViName = viDoc.Query("extra/status");
                    statusTemplate = viDoc.Query("extra/statusTemplate");
                    templatePath = viDoc.Query("extra/templatePath");
                }
                catch (Exception e)
                {
                    string err = e.Message;
                }
            }

            // log the experiment for debugging

            Utilities.WriteLog("Experiment: " + experimentID + " Start: " + DateUtil.ToUtcString(startTime) + " \tduration: " + duration);
            long statusSpan = DateUtil.SecondsRemaining(startTime, duration);



            if ((appInfo.server != null) && (appInfo.server.Length > 0) && (appInfo.port > 0))
            {
                lvi = new LabViewRemote(appInfo.server, appInfo.port);
            }
            else
            {
                lvi = new LabViewInterface();
            }
            if (!lvi.IsLoaded(appInfo.application))
            {
                vi = lvi.loadVI(appInfo.path, appInfo.application);
                vi.OpenFrontPanel(true, FPStateEnum.eVisible);
            }
            else
            {
                vi = lvi.GetVI(appInfo.path, appInfo.application);
            }
            if (vi == null)
            {
                status = -1;
                string err = "Unable to Find: " + appInfo.path + @"\" + appInfo.application;
                Utilities.WriteLog(err);
                throw new Exception(err);
            }
            // Get qualifiedName
            qualName = lvi.qualifiedName(vi);
            fullName = appInfo.path + @"\" + appInfo.application;


            status = lvi.GetVIStatus(vi);

            Utilities.WriteLog("CreateLabTask - " + qualName + ": VIstatus: " + status);
            switch (status)
            {
                case -10:
                    throw new Exception("Error GetVIStatus: " + status);
                    break;
                case -1:
                    // VI not in memory
                    throw new Exception("Error GetVIStatus: " + status);

                    break;
                case 0: // eBad == 0
                    break;
                case 1: // eIdle == 1 vi in memory but not running 
                    FPStateEnum fpState = vi.FPState;
                    if (fpState != FPStateEnum.eVisible)
                    {
                        vi.OpenFrontPanel(true, FPStateEnum.eVisible);
                    }
                    vi.ReinitializeAllToDefault();
                    break;
                case 2: // eRunTopLevel: this should be the LabVIEW application
                    break;
                case 3: // eRunning
                    //Unless the Experiment is reentrant it should be stopped and be reset.
                    if(!appInfo.reentrant){
                        int stopStatus = lvi.StopVI(vi);
                        if (stopStatus != 0)
                        {
                            lvi.AbortVI(vi);
                        }
                        vi.ReinitializeAllToDefault();
                    }
                    break;
                default:
                    throw new Exception("Error GetVIStatus: unknown status: " + status);
                    break;
            }
            try
            {
                lvi.SetBounds(vi, 0, 0, appInfo.width, appInfo.height);
                Utilities.WriteLog("SetBounds: " + appInfo.application);
            }
            catch (Exception sbe)
            {
                Utilities.WriteLog("SetBounds exception: " + Utilities.DumpException(sbe));
            }
            lvi.SubmitAction("unlockvi", lvi.qualifiedName(vi));
            Utilities.WriteLog("unlockvi Called: ");


            // Set up in-memory and database task control structures
            DataSourceManager dsManager = null;

            // Create the labTask & store in database;
            labTask = dbManager.InsertTask(appInfo.appID, experimentID,
           groupName, startTime, duration,
           LabTask.eStatus.Scheduled, expTicket.couponId, expTicket.issuerGuid, null);
            if (labTask != null)
            {
                //Convert the generic LabTask to a LabViewTask
                task = new LabViewTask(labTask);
            }
            if ((statusTemplate != null) && (statusTemplate.Length > 0))
            {
                statusViName = lvi.CreateFromTemplate(templatePath, statusTemplate, task.taskID.ToString());
            }


            if (((essService != null) && (essService.Length > 0)) && ((appInfo.dataSources != null) && (appInfo.dataSources.Length > 0)))
            {
                // Create DataSourceManager to manage dataSocket connections
                dsManager = new DataSourceManager();

                // set up an experiment storage handler
                ExperimentStorageProxy ess = new ExperimentStorageProxy();
                ess.OperationAuthHeaderValue = new OperationAuthHeader();
                ess.OperationAuthHeaderValue.coupon = expCoupon;
                ess.Url = essService;
                dsManager.essProxy = ess;
                dsManager.ExperimentID = experimentID;
                dsManager.AppKey = qualName;
                string[] sockets = appInfo.dataSources.Split(',');
                // Use the experimentID as the storage parameter
                foreach (string s in sockets)
                {
                    LVDataSocket reader = new LVDataSocket();
                    dsManager.AddDataSource(reader);
                    if (s.Contains("="))
                    {
                        string[] nv = s.Split('=');
                        reader.Type = nv[1];
                        reader.Connect(nv[0], LabDataSource.READ_AUTOUPDATE);

                    }
                    else
                    {
                        reader.Connect(s, LabDataSource.READ_AUTOUPDATE);
                    }

                }
                TaskProcessor.Instance.AddDataManager(task.taskID, dsManager);
            }
            string taskData = null;
            taskData = LabTask.constructTaskXml(appInfo.appID, fullName,appInfo.rev, statusViName, essService);
            dbManager.SetTaskData(task.taskID, taskData);
            task.data = taskData;
            TaskProcessor.Instance.Add(task);
            return task;
        }