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.");
            }
        }
示例#2
0
        public ClientSubmissionReport Submit(string labServerID, string experimentSpecification, int priorityHint, bool emailNotification)
        {
            // Default to 24 hours duration
            long duration = TimeSpan.TicksPerDay/TimeSpan.TicksPerSecond;
            int seqNo = 0;
            ClientSubmissionReport clientSReport = null;
            try{

                // Checking if user has permission to use the lab server. The method will set headers for lab server calls
                //if authorization is successful.
                CheckAndSetLSAuthorization(labServerID);

                //Retrieve variables from session
                int userID = Convert.ToInt32(Session["UserID"]);
                int effectiveGroupID = Convert.ToInt32(Session["GroupID"]);
                int clientID = 0;
                if (Session["ClientID"] != null )
                    clientID = Convert.ToInt32(Session["ClientID"]);
                string effectiveGroup = Session["GroupName"].ToString();

                ProcessAgentInfo infoLS = dbTicketing.GetProcessAgentInfo(labServerID);
                if (infoLS.retired)
                {
                    throw new Exception("The Batch Lab Server is retired");
                }
                // get qualifier ID of labServer
                int qualifierID = AuthorizationAPI.GetQualifierID(infoLS.agentId, Qualifier.labServerQualifierTypeID);

                /* End collecting information */

                // Checking if user has permission to use the lab server
                if (!AuthorizationAPI.CheckAuthorization(userID, Function.useLabServerFunctionType, qualifierID))
                {
                    // check fails

                    throw new AccessDeniedException("Access denied using labServer '" + infoLS.agentName + "'.");
                }
                else
                {
                    int[] groupIDs = new int[1];
                    groupIDs[0] = effectiveGroupID;

                    SubmissionReport sReport = new SubmissionReport();

                    clientSReport = new ClientSubmissionReport();
                    clientSReport.vReport = new ValidationReport();
                    clientSReport.wait = new WaitEstimate();

                    BrokerDB brokerDB = new BrokerDB();
                    // 1. Create Coupon for ExperimentCollection
                    Coupon coupon = brokerDB.CreateCoupon();

                    int essID = brokerDB.FindProcessAgentIdForClient(clientID, ProcessAgentType.EXPERIMENT_STORAGE_SERVER);
                    //
                    // 2. create ServiceBroker experiment record and get corresponding experiment id
                    // This checks authorization.
                    long experimentID = wrapper.CreateExperimentWrapper(StorageStatus.INITIALIZED, userID, effectiveGroupID, infoLS.agentId, clientID,
                        essID, DateTime.UtcNow, duration);

                    // Store a record of the Experiment Collection Coupon
                    DataStorageAPI.InsertExperimentCoupon(experimentID, coupon.couponId);

                    //3.A create ESS administer experiment ticket, Add 10 minutes to duration
                    // This must be created before the ESS experiment records may be created
                    ProcessAgentInfo essAgent = brokerDB.GetProcessAgentInfo(essID);
                    if (essAgent.retired)
                    {
                        throw new Exception("The Batch Lab Server is retired");
                    }
                    TicketLoadFactory factory = TicketLoadFactory.Instance();

                    brokerDB.AddTicket(coupon,
                           TicketTypes.ADMINISTER_EXPERIMENT, essAgent.AgentGuid, ProcessAgentDB.ServiceGuid, duration, factory.createAdministerExperimentPayload(experimentID, essAgent.webServiceUrl));

                    //3.B create store record ticket, in the MergedSB the records are all saved via the serviceBroker
                    brokerDB.AddTicket(coupon,
                           TicketTypes.STORE_RECORDS, essAgent.agentGuid, ProcessAgentDB.ServiceGuid, duration, factory.StoreRecordsPayload(true, experimentID, essAgent.webServiceUrl));

                    //3.C create retrieve experiment ticket, retrieve Experiment Records never expires, unless experiment deleted
                    //    This should be changed to a long but finite period once eadExisting Expermint is in place.
                    brokerDB.AddTicket(coupon,
                           TicketTypes.RETRIEVE_RECORDS, essAgent.agentGuid, ProcessAgentDB.ServiceGuid, -1, factory.RetrieveRecordsPayload(experimentID, essAgent.webServiceUrl));

                    // 3.D Create the ESS Experiment Records
                    ExperimentStorageProxy ess = new ExperimentStorageProxy();
                    ess.AgentAuthHeaderValue = new AgentAuthHeader();
                    ess.AgentAuthHeaderValue.coupon = essAgent.identOut;
                    ess.AgentAuthHeaderValue.agentGuid = ProcessAgentDB.ServiceGuid;
                    ess.OperationAuthHeaderValue = new OperationAuthHeader();
                    ess.OperationAuthHeaderValue.coupon = coupon;
                    ess.Url = essAgent.webServiceUrl;

                    // Call the ESS to create the ESS Records and open the experiment
                    StorageStatus status = ess.OpenExperiment(experimentID, duration);
                    if (status != null)
                        DataStorageAPI.UpdateExperimentStatus(status);

                    seqNo = ess.AddRecord(experimentID, ProcessAgentDB.ServiceGuid,
                              BatchRecordType.SPECIFICATION, true, experimentSpecification, null);

                    // save lab configuration
                    string labConfiguration = batchLS_Proxy.GetLabConfiguration(effectiveGroup);
                    seqNo = ess.AddRecord(experimentID, labServerID,
                        BatchRecordType.LAB_CONFIGURATION, true, labConfiguration, null);

                    // call labServer submit
                    sReport = batchLS_Proxy.Submit(Convert.ToInt32(experimentID), experimentSpecification, effectiveGroup, priorityHint);

                    // save submission report
                    //wrapper.SaveSubmissionReportWrapper(experimentID, sReport);
                    if (sReport.vReport != null)
                        if ((sReport.vReport.errorMessage != null) && (sReport.vReport.errorMessage.CompareTo("") != 0))
                        {
                            seqNo = ess.AddRecord(experimentID, labServerID, BatchRecordType.VALIDATION_ERROR, false, sReport.vReport.errorMessage, null);

                        }

                    if (sReport.vReport.warningMessages != null)
                        foreach (string s in sReport.vReport.warningMessages)
                        {
                            if ((s != null) && (s.CompareTo("") != 0))
                                seqNo = ess.AddRecord(experimentID, labServerID, BatchRecordType.VALIDATION_WARNING, false, s, null);
                        }

                    // return clientSubmissionReport
                    if (sReport.vReport != null)
                    {
                        clientSReport.vReport.accepted = sReport.vReport.accepted;
                        clientSReport.vReport.errorMessage = sReport.vReport.errorMessage;
                        // if error exists then change status to "an experiment with a problem"
                        if ((sReport.vReport.errorMessage != null) && (!sReport.vReport.errorMessage.Equals("")))
                        {
                            StorageStatus sStatus = new StorageStatus();
                            sStatus.experimentId = experimentID;
                            //sStatus.estRuntime=sReport.vReport.estRuntime;
                            sStatus.status = StorageStatus.BATCH_TERMINATED_ERROR;
                            DataStorageAPI.UpdateExperimentStatus(sStatus);
                        }
                        clientSReport.vReport.estRuntime = sReport.vReport.estRuntime;
                        clientSReport.vReport.warningMessages = sReport.vReport.warningMessages;
                    }
                    clientSReport.experimentID = Convert.ToInt32(experimentID);
                    clientSReport.minTimeToLive = sReport.minTimetoLive;
                    if (sReport.wait != null)
                    {
                        clientSReport.wait.effectiveQueueLength = sReport.wait.effectiveQueueLength;
                        clientSReport.wait.estWait = sReport.wait.estWait;
                    }
                }

                return clientSReport;
            }

            catch
            {
                throw;
            }
        }
        private int ProcessRecords(string fullPath)
        {
            List<string> records = new List<string>();
            int count = 0;
            try
            {
                try
                {
                    // Attempt to open the file exclusively.

                    using (FileStream fs = File.Open(fullPath, FileMode.Open, FileAccess.ReadWrite,
                             FileShare.None))
                    {
                        string line;
                        StreamReader sr = new StreamReader(fs);
                        while ((line = sr.ReadLine()) != null)
                        {
                            records.Add(line);
                        }

                        fs.SetLength(0L);
                        sr.Close();
                    }
                }
                catch (IOException ioe)
                {
                    throw ioe;
                }

                // If we got this far send the data
                if (records.Count > 0)
                {
                    ExperimentStorageProxy essProxy = new ExperimentStorageProxy();
                    essProxy.OperationAuthHeaderValue = new OperationAuthHeader();
                    essProxy.OperationAuthHeaderValue.coupon = opCoupon;
                    essProxy.Url = essUrl;

                    //replace DataSocket code with 'Pusher' interface
                    IPusherProvider provider = new PusherProvider(pusherID, pusherKey, pusherSS, null);

                    foreach (string rec in records)
                    {
                        string[] vals = rec.Split(delim, 2);
                        DateTime timeStamp = new DateTime(0L, DateTimeKind.Local);
                        bool status = DateTime.TryParseExact(vals[0].Replace("\"", ""), "yyyy-MM-dd HH:mm:ss", null, DateTimeStyles.None, out timeStamp);
                        string record = "\"" + timeStamp.ToString("o") + "\"," + vals[1];
                        try
                        {
                            essProxy.AddRecord(experimentID, submitter, recordType, false, record, null);
                        }
                        catch (Exception essEx)
                        {
                            Logger.WriteLine("BeeEventHandler: OnChange ESS: " + essEx.Message);
                        }
                        try
                        {
                            string str = @"{'rawData': [" + record + "]}";
                            ObjectPusherRequest request =
                                new ObjectPusherRequest(pusherChannel, "meassurement-added", str);
                            provider.Trigger(request);
                        }
                        catch (Exception dsEx)
                        {
                            Logger.WriteLine("BeeEventHandler: OnChange DS: " + dsEx.Message);
                        }
                        count++;
                    }
                    //Pusher interface Close not needed
                }
            }
            catch (Exception e)
            {
            }
            return count;
        }