예제 #1
0
        public override eStatus Close(eStatus reason)
        {
            LabDB dbService = new LabDB();
            LabViewInterface lvi = null;
            try
            {
                if (data != null)
                {
                    XmlQueryDoc taskDoc = new XmlQueryDoc(data);
                    string viName = taskDoc.Query("task/application");
                    string statusVI = taskDoc.Query("task/status");
                    string server = taskDoc.Query("task/server");
                    string portStr = taskDoc.Query("task/serverPort");
#if LabVIEW_WS
                     lvi = new LabViewInterface();
#else
                    if ((portStr != null) && (portStr.Length > 0) && (portStr.CompareTo("0") != 0) )
                    {
                        lvi = new LabViewRemote(server, Convert.ToInt32(portStr));
                    }
                    else
                    {
                        lvi = new LabViewInterface();
                    }
#endif

                    // Status VI not used 
                    if ((statusVI != null) && statusVI.Length != 0)
                    {
                        try
                        {
                            if(reason == eStatus.Expired)
                                lvi.DisplayStatus(statusVI, "You are out of time!", "0:00");
                            else
                                lvi.DisplayStatus(statusVI, "Your experiment has been cancelled", "0:00");
                        }
                        catch (Exception ce)
                        {
                           Logger.WriteLine("Trying StatusVI: " + ce.Message);
                        }
                    }


                    //Get the VI and send version specfic call to get control of the VI
                   //VirtualInstrument vi = lvi.GetVI(viName);
                    // LV 8.2.1
                    //Server takes control of RemotePanel, connection not brokenS
                    lvi.ReleaseVI(viName);
                }
               Logger.WriteLine("TaskID = " + taskID + " has expired");
                dbService.SetTaskStatus(taskID, (int)reason);
                status = eStatus.Closed;
               
                    DataSourceManager dsManager = TaskProcessor.Instance.GetDataManager(taskID);
                    if (dsManager != null)
                    {
                        dsManager.CloseDataSources();
                        TaskProcessor.Instance.RemoveDataManager(taskID);
                    }
                
                dbService.SetTaskStatus(taskID, (int)status);
                if (couponID > 0)
                { // this task was created with a valid ticket, i.e. not a test.
                    Coupon expCoupon = dbService.GetCoupon(couponID, issuerGUID);

                    // Only use the domain ServiceBroker, do we need a test
                    // Should only be one
                    ProcessAgentInfo[] sbs = dbService.GetProcessAgentInfos(ProcessAgentType.SERVICE_BROKER);

                    if ((sbs == null) || (sbs.Length < 1))
                    {
                       Logger.WriteLine("Can not retrieve ServiceBroker!");
                        throw new Exception("Can not retrieve ServiceBroker!");
                    }
                    ProcessAgentInfo domainSB = null;
                    foreach (ProcessAgentInfo dsb in sbs)
                    {
                        if (!dsb.retired)
                        {
                            domainSB = dsb;
                            break;
                        }
                    }
                    if (domainSB == null)
                    {
                       Logger.WriteLine("Can not retrieve ServiceBroker!");
                        throw new Exception("Can not retrieve ServiceBroker!");
                    }
                    InteractiveSBProxy iuProxy = new InteractiveSBProxy();
                    iuProxy.AgentAuthHeaderValue = new AgentAuthHeader();
                    iuProxy.AgentAuthHeaderValue.coupon = sbs[0].identOut;
                    iuProxy.AgentAuthHeaderValue.agentGuid = ProcessAgentDB.ServiceGuid;
                    iuProxy.Url = sbs[0].webServiceUrl;
                    StorageStatus storageStatus = iuProxy.AgentCloseExperiment(expCoupon, experimentID);
                   Logger.WriteLine("AgentCloseExperiment status: " + storageStatus.status + " records: " + storageStatus.recordCount);


                    // currently RequestTicketCancellation always returns false
                    // Create ticketing service interface connection to TicketService
                    TicketIssuerProxy ticketingInterface = new TicketIssuerProxy();
                    ticketingInterface.AgentAuthHeaderValue = new AgentAuthHeader();
                    ticketingInterface.Url = sbs[0].webServiceUrl;
                    ticketingInterface.AgentAuthHeaderValue.coupon = sbs[0].identOut;
                    ticketingInterface.AgentAuthHeaderValue.agentGuid = ProcessAgentDB.ServiceGuid;
                    if (ticketingInterface.RequestTicketCancellation(expCoupon, TicketTypes.EXECUTE_EXPERIMENT, ProcessAgentDB.ServiceGuid))
                    {
                        dbService.CancelTicket(expCoupon, TicketTypes.EXECUTE_EXPERIMENT, ProcessAgentDB.ServiceGuid);
                       Logger.WriteLine("Canceled ticket: " + expCoupon.couponId);
                    }
                    else
                    {
                       Logger.WriteLine("Unable to cancel ticket: " + expCoupon.couponId);
                    }
                }
            }
            catch (Exception e1)
            {
               Logger.WriteLine("ProcessTasks Cancelled: exception:" + e1.Message + e1.StackTrace);
            }
            finally
            {
                lvi = null;
            }
            return base.Close();
        }
        protected void goButton_Click(object sender, System.EventArgs e)
        {
            LabDB labDB = new LabDB();

            // Update Task data for graph page. Note XmlQueryDocs are read-only
            LabTask task = labDB.GetTask(Convert.ToInt64(hdnExpId.Value), Session["opIssuer"].ToString());
            if (task != null)
            {
                Coupon opCoupon = new Coupon(task.issuerGUID, task.couponID, Session["opPasscode"].ToString());
               ExperimentStorageProxy essProxy = new ExperimentStorageProxy();
               essProxy.OperationAuthHeaderValue = new OperationAuthHeader();
               essProxy.OperationAuthHeaderValue.coupon = opCoupon;
               essProxy.Url = task.storage;
               essProxy.AddRecord(task.experimentID, "BEElab", "profile", false, hdnProfile.Value, null);
               essProxy.AddRecord(task.experimentID, "BEElab", "climateProfile", false, hdnClimateProfile.Value, null);
               essProxy.AddRecord(task.experimentID, "BEElab", "sunLamp", false, hdnSunLamp.Value, null);

               // send The CR1000 programs
               sendProfile(ConfigurationManager.AppSettings["climateController"],
                   hdnProfile.Value, hdnSunProfile, ConfigurationManager.AppSettings["climateServer"]);
               sendFile(ConfigurationManager.AppSettings["chamberController"],
                  ConfigurationManager.AppSettings["chamberFile"],
                  ConfigurationManager.AppSettings["chamberServer"]);
                StringBuilder buf = new StringBuilder("BEEgraph.aspx?expid=");

                sendEwsCientProfile(hdnClientProfile.Value,hdnExpLength.Value);
                buf.Append(task.experimentID);
                task.Status = LabTask.eStatus.Running;
                TaskProcessor.Instance.Modify(task);
                labDB.SetTaskStatus(task.taskID, (int) LabTask.eStatus.Running);
                Session["opCouponID"] = hdnCoupon.Value;
                Session["opIssuer"] = hdnIssuer.Value;
                Session["opPasscode"] = hdnPasscode.Value;
                Response.Redirect(buf.ToString(), true);
            }
            else
            {
                throw new Exception("Task was not found.");
            }
        }
예제 #3
0
        public virtual eStatus Close(eStatus reason)
        {
            LabDB dbService = new LabDB();

            try
            {
                if (data != null)
                {
                    XmlQueryDoc taskDoc = new XmlQueryDoc(data);
                    string app = taskDoc.Query("task/application");
                    string statusName = taskDoc.Query("task/status");
                    string server = taskDoc.Query("task/server");
                    string portStr = taskDoc.Query("task/serverPort");

                    // Status not used
                    if ((statusName != null) && statusName.Length != 0)
                    {
                        try
                        {
                            if (reason == eStatus.Expired)
                                DisplayStatus(statusName, "You are out of time!", "0:00");
                            else
                                DisplayStatus(statusName, "Your experiment has been cancelled", "0:00");
                        }
                        catch (Exception ce)
                        {
                            Logger.WriteLine("Trying StatusName: " + ce.Message);
                        }
                    }

                   //Stop the application & close ESS sessions

                }
                Logger.WriteLine("TaskID = " + taskID + " is being closed");
                dbService.SetTaskStatus(taskID, (int)reason);
                status = eStatus.Closed;

                DataSourceManager dsManager = TaskProcessor.Instance.GetDataManager(taskID);
                if (dsManager != null)
                {
                    dsManager.CloseDataSources();
                    TaskProcessor.Instance.RemoveDataManager(taskID);
                }

                dbService.SetTaskStatus(taskID, (int)status);
                if (couponID > 0)
                { // this task was created with a valid ticket, i.e. not a test.
                    Coupon expCoupon = dbService.GetCoupon(couponID, issuerGUID);

                    // Only use the domain ServiceBroker, do we need a test
                    // Should only be one
                    ProcessAgentInfo[] sbs = dbService.GetProcessAgentInfos(ProcessAgentType.SERVICE_BROKER);

                    if ((sbs == null) || (sbs.Length < 1))
                    {
                        Logger.WriteLine("Can not retrieve ServiceBroker!");
                        throw new Exception("Can not retrieve ServiceBroker!");
                    }
                    ProcessAgentInfo domainSB = null;
                    foreach (ProcessAgentInfo dsb in sbs)
                    {
                        if (!dsb.retired)
                        {
                            domainSB = dsb;
                            break;
                        }
                    }
                    if (domainSB == null)
                    {
                        Logger.WriteLine("Can not retrieve ServiceBroker!");
                        throw new Exception("Can not retrieve ServiceBroker!");
                    }
                    InteractiveSBProxy iuProxy = new InteractiveSBProxy();
                    iuProxy.AgentAuthHeaderValue = new AgentAuthHeader();
                    iuProxy.AgentAuthHeaderValue.coupon = sbs[0].identOut;
                    iuProxy.AgentAuthHeaderValue.agentGuid = ProcessAgentDB.ServiceGuid;
                    iuProxy.Url = sbs[0].webServiceUrl;
                    StorageStatus storageStatus = iuProxy.AgentCloseExperiment(expCoupon, experimentID);
                    Logger.WriteLine("AgentCloseExperiment status: " + storageStatus.status + " records: " + storageStatus.recordCount);

                    // currently RequestTicketCancellation always returns false
                    // Create ticketing service interface connection to TicketService
                    TicketIssuerProxy ticketingInterface = new TicketIssuerProxy();
                    ticketingInterface.AgentAuthHeaderValue = new AgentAuthHeader();
                    ticketingInterface.Url = sbs[0].webServiceUrl;
                    ticketingInterface.AgentAuthHeaderValue.coupon = sbs[0].identOut;
                    ticketingInterface.AgentAuthHeaderValue.agentGuid = ProcessAgentDB.ServiceGuid;
                    if (ticketingInterface.RequestTicketCancellation(expCoupon, TicketTypes.EXECUTE_EXPERIMENT, ProcessAgentDB.ServiceGuid))
                    {
                        dbService.CancelTicket(expCoupon, TicketTypes.EXECUTE_EXPERIMENT, ProcessAgentDB.ServiceGuid);
                        Logger.WriteLine("Canceled ticket: " + expCoupon.couponId);
                    }
                    else
                    {
                        Logger.WriteLine("Unable to cancel ticket: " + expCoupon.couponId);
                    }
                }
            }
            catch (Exception e1)
            {
                Logger.WriteLine("ProcessTasks Cancelled: exception:" + e1.Message + e1.StackTrace);
            }

            return status;
        }