public DataSourceManager(LabTask task)
     : this()
 {
     taskID = task.taskID;
     experimentID = task.experimentID;
     if (task.storage != null && task.storage.Length > 0)
     {
         LabDB labDB = new LabDB();
         Coupon expCoupon = labDB.GetCoupon(task.couponID, task.issuerGUID);
         if (expCoupon != null)
         {
             essProxy = new ExperimentStorageProxy();
             essProxy.Url = task.storage;
             essProxy.OperationAuthHeaderValue = new OperationAuthHeader();
             essProxy.OperationAuthHeaderValue.coupon = expCoupon;
         }
         else
             throw new Exception("ExpCoupon not found");
     }
     else
      throw new Exception("ESS is not specified");
 }
예제 #2
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();
        }
예제 #3
0
        protected void Application_Start(Object sender, EventArgs e)
        {
            try
            {
                string path = ConfigurationManager.AppSettings["logPath"];
                if (path != null && path.Length > 0)
                {
                    Logger.LogPath = path;
                    Logger.WriteLine("");
                    Logger.WriteLine("#############################################################################");
                    Logger.WriteLine(iLabGlobal.Release);
                    Logger.WriteLine("Application_Start: starting");
                }
                ProcessAgentDB.RefreshServiceAgent();
                //Should load any active tasks and update any expired tasks
                LabDB dbService = new LabDB();

                TaskProcessor.Instance.WaitTime = 60000;
                LabTask[] activeTasks = dbService.GetActiveTasks();
                int count = 0;
                foreach (LabTask task in activeTasks)
                {
                    if (task != null)
                    {
                        if (task.storage != null && task.storage.Length > 0)
                        {
                            Coupon expCoupon = dbService.GetCoupon(task.couponID, task.issuerGUID);
                            DataSourceManager dsManager = new DataSourceManager(task);
                            BeeAPI api = new BeeAPI();
                            FileWatcherDataSource fds = api.CreateBeeDataSource(expCoupon, task, "data", false);
                            dsManager.AddDataSource(fds);
                            fds.Start();
                            TaskProcessor.Instance.AddDataManager(task.taskID, dsManager);
                        }
                        TaskProcessor.Instance.Add(new BeeTask(task));
                        count++;
                    }
                }
                taskThread = new TaskHandler(TaskProcessor.Instance);
                ticketRemover = new TicketRemover();
                if (Logger.IsLogging)
                    Logger.WriteLine("Added " + count + " active Tasks\r\n");

            }
            catch (Exception err)
            {
                if (Logger.IsLogging)
                Logger.WriteLine(Utilities.DumpException(err));
            }
        }
예제 #4
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;
        }