protected void lbxSelectExperiment_SelectedIndexChanged(object sender, System.EventArgs e) { clearExperimentDisplay(); long experimentID = Int64.Parse (lbxSelectExperiment.Items [lbxSelectExperiment.SelectedIndex ].Value); try { ExperimentSummary[] expInfo = wrapper.GetExperimentSummaryWrapper (new long[] {experimentID}); if(expInfo[0] != null) { txtExperimentID.Text = expInfo[0].experimentId.ToString(); txtUsername.Text = expInfo[0].userName ; txtGroupName.Text = expInfo[0].groupName; txtLabServerName.Text = expInfo[0].labServerName; txtClientName.Text = expInfo[0].clientName; //Check if update needed from the ESS if one is used if( expInfo[0].essGuid != null){ int expStatus = expInfo[0].status; if((expStatus == StorageStatus.UNKNOWN || expStatus == StorageStatus.INITIALIZED || expStatus == StorageStatus.OPEN || expStatus == StorageStatus.REOPENED ||expStatus == StorageStatus.RUNNING ||expStatus == StorageStatus.BATCH_QUEUED ||expStatus == StorageStatus.BATCH_RUNNING ||expStatus == StorageStatus.BATCH_TERMINATED ||expStatus == StorageStatus.BATCH_TERMINATED_ERROR)) { // This operation should happen within the Wrapper BrokerDB ticketIssuer = new BrokerDB(); ProcessAgentInfo ess = ticketIssuer.GetProcessAgentInfo(expInfo[0].essGuid); if (ess == null || ess.retired) { throw new Exception("The ESS is not registered or is retired"); } Coupon opCoupon = ticketIssuer.GetEssOpCoupon(expInfo[0].experimentId, TicketTypes.RETRIEVE_RECORDS,60,ess.agentGuid); if (opCoupon != null) { ExperimentStorageProxy essProxy = new ExperimentStorageProxy(); OperationAuthHeader header = new OperationAuthHeader(); header.coupon = opCoupon; essProxy.Url = ess.webServiceUrl; essProxy.OperationAuthHeaderValue = header; StorageStatus curStatus = essProxy.GetExperimentStatus(expInfo[0].experimentId); if (expInfo[0].status != curStatus.status || expInfo[0].recordCount != curStatus.recordCount || expInfo[0].closeTime != curStatus.closeTime) { DataStorageAPI.UpdateExperimentStatus(curStatus); expInfo[0].status = curStatus.status; expInfo[0].recordCount = curStatus.recordCount; expInfo[0].closeTime = curStatus.closeTime; } } } } txtStatus.Text = DataStorageAPI.getStatusString(expInfo[0].status); txtSubmissionTime.Text = DateUtil.ToUserTime(expInfo[0].creationTime,culture,userTZ); if ((expInfo[0].closeTime != null) && (expInfo[0].closeTime != DateTime.MinValue)) { txtCompletionTime.Text = DateUtil.ToUserTime(expInfo[0].closeTime, culture, userTZ); } else{ txtCompletionTime.Text = "Experiment Not Closed!"; } txtRecordCount.Text = expInfo[0].recordCount.ToString(" 0"); txtAnnotation.Text = expInfo[0].annotation; trSaveAnnotation.Visible = true; trDeleteExperiment.Visible = true; trShowExperiment.Visible = (expInfo[0].recordCount > 0); } } catch(Exception ex) { lblResponse.Text = Utilities.FormatErrorMessage("Error retrieving experiment information. " + ex.Message); lblResponse.Visible = true; } }
private static void ExecuteExperimentExecutionRecipe(ProcessAgentInfo labServer, ref LabClient client, ref DateTime startExecution, long duration, int userTZ, int userID, int groupID, string groupName, out BrokerDB brokerDB, out Coupon coupon) { int essId = 0; ProcessAgentInfo essAgent = null; long ticketDuration = 7200; //Default to 2 hours // Add a 10 minutes to ESS ticket duration ( in seconds ) to extend beyond experiment expiration if (duration != -1) { //ticketDuration = duration + 60; // For testing only add a minute ticketDuration = duration + 600; // Add 10 minutes beyond the experiment end } else { ticketDuration = -1; } // Authorization wrapper AuthorizationWrapperClass wrapper = new AuthorizationWrapperClass(); // create ticket issuer and payload factory brokerDB = new BrokerDB(); TicketLoadFactory factory = TicketLoadFactory.Instance(); if (client.needsESS) { essId = brokerDB.FindProcessAgentIdForClient(client.clientID, ProcessAgentType.EXPERIMENT_STORAGE_SERVER); } // 1. Create Coupon for ExperimentCollection coupon = brokerDB.CreateCoupon(); // // 2. create ServiceBroker experiment record and get corresponding experiment id // This checks authorization. long experimentID = wrapper.CreateExperimentWrapper(StorageStatus.INITIALIZED, userID, groupID, labServer.agentId, client.clientID, essId, startExecution, duration); // Store a record of the Experiment Collection Coupon DataStorageAPI.InsertExperimentCoupon(experimentID, coupon.couponId); string essWebAddress = null; // If a ESS is specified Create the ESS Tickets, this should only happen if a resource is mapped if (essId > 0) { //3.A create ESS administer experiment ticket, Add 10 minutes to duration // This must be created before the ESS experiment records may be created essAgent = brokerDB.GetProcessAgentInfo(essId); if ((essAgent != null) && !essAgent.retired) { brokerDB.AddTicket(coupon, TicketTypes.ADMINISTER_EXPERIMENT, essAgent.AgentGuid, brokerDB.GetIssuerGuid(), ticketDuration, factory.createAdministerExperimentPayload(experimentID, essAgent.webServiceUrl)); //3.B create store record ticket brokerDB.AddTicket(coupon, TicketTypes.STORE_RECORDS, essAgent.agentGuid, labServer.agentGuid, ticketDuration, 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, brokerDB.GetIssuerGuid(), -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.Url = essAgent.webServiceUrl; essWebAddress = essAgent.webServiceUrl; // Call the ESS to create the ESS Records and open the experiment StorageStatus status = ess.OpenExperiment(experimentID, ticketDuration); if (status != null) DataStorageAPI.UpdateExperimentStatus(status); } } // // 4. create the execution ticket for the experiment // // 4.A create payload string payload = factory.createExecuteExperimentPayload(essWebAddress, startExecution, duration, userTZ, groupName, brokerDB.GetIssuerGuid(), experimentID); // 4.B create experiment execution ticket. brokerDB.AddTicket(coupon, TicketTypes.EXECUTE_EXPERIMENT, labServer.agentGuid, labServer.agentGuid, ticketDuration, payload); // 4.C Create sessionRedemption Ticket string sessionPayload = factory.createRedeemSessionPayload(userID, groupID, client.clientID); brokerDB.AddTicket(coupon, TicketTypes.REDEEM_SESSION, brokerDB.GetIssuerGuid(), brokerDB.GetIssuerGuid(), ticketDuration, sessionPayload); }
protected void displayRecords(long experimentId, string essGuid) { BrokerDB ticketIssuer = new BrokerDB(); ProcessAgentInfo ess = ticketIssuer.GetProcessAgentInfo(essGuid); if (ess == null || ess.retired) { throw new Exception("The ESS is not registered or is retired"); } Coupon opCoupon = ticketIssuer.GetEssOpCoupon(experimentId, TicketTypes.RETRIEVE_RECORDS, 60, ess.agentGuid); if (opCoupon != null) { ExperimentStorageProxy essProxy = new ExperimentStorageProxy(); OperationAuthHeader header = new OperationAuthHeader(); header.coupon = opCoupon; essProxy.Url = ess.webServiceUrl; essProxy.OperationAuthHeaderValue = header; ExperimentRecord[] records = essProxy.GetRecords(experimentId,null); if (records != null) { StringBuilder buf = null; if (cbxContents.Checked) { buf = new StringBuilder(); foreach (ExperimentRecord rec in records) { buf.AppendLine(rec.contents); } txtExperimentRecords.Text = buf.ToString(); txtExperimentRecords.Visible = true; grvExperimentRecords.Visible = false; } else { dtRecords = new DataTable(); dtRecords.Columns.Add("Seq_Num", typeof(System.Int32)); dtRecords.Columns.Add("Record Type", typeof(System.String)); dtRecords.Columns.Add("Contents", typeof(System.String)); foreach (ExperimentRecord rec in records) { DataRow recTmp = dtRecords.NewRow(); recTmp["Seq_Num"] = rec.sequenceNum; recTmp["Record Type"] = rec.type; recTmp["Contents"] = rec.contents; dtRecords.Rows.InsertAt(recTmp, dtRecords.Rows.Count); } grvExperimentRecords.DataSource = dtRecords; grvExperimentRecords.DataBind(); grvExperimentRecords.Visible = true; txtExperimentRecords.Visible = false; } divRecords.Visible = true; } Blob[] blobs = essProxy.GetBlobs(experimentId); if (blobs != null) { dtBlobs = new DataTable(); dtBlobs.Columns.Add("Blob_ID", typeof(System.Int64)); dtBlobs.Columns.Add("Seq_Num", typeof(System.Int32)); dtBlobs.Columns.Add("MimeType", typeof(System.String)); dtBlobs.Columns.Add("Description", typeof(System.String)); foreach (Blob b in blobs) { DataRow blobTmp = dtBlobs.NewRow(); blobTmp["Blob_ID"] = b.blobId; blobTmp["Seq_Num"] = b.recordNumber; blobTmp["MimeType"] = b.mimeType; blobTmp["Description"] = b.description; dtBlobs.Rows.InsertAt(blobTmp, dtBlobs.Rows.Count); } grvBlobs.DataSource = dtBlobs; grvBlobs.DataBind(); divBlobs.Visible = true; } } }
protected void On_BlobSelected(object sender, GridViewCommandEventArgs e) { lblResponse.Visible = false; if (Session["EssGuid"] != null) { long blobId = Convert.ToInt64(e.CommandArgument); BrokerDB brokerDB = new BrokerDB(); ProcessAgentInfo ess = brokerDB.GetProcessAgentInfo(Session["EssGuid"].ToString()); if (ess == null || ess.retired) { throw new Exception("The ESS is not registered or is retired"); } Coupon opCoupon = brokerDB.GetEssOpCoupon(Convert.ToInt64(txtExperimentID.Text), TicketTypes.RETRIEVE_RECORDS, 60, ess.agentGuid); if (opCoupon != null) { ExperimentStorageProxy essProxy = new ExperimentStorageProxy(); OperationAuthHeader header = new OperationAuthHeader(); header.coupon = opCoupon; essProxy.Url = ess.webServiceUrl; essProxy.OperationAuthHeaderValue = header; string url = essProxy.RequestBlobAccess(blobId, "http", 30); if (url != null) { string jScript = "<script language='javascript'>" + "window.open('" + url + "')" + "</script>"; Page.RegisterStartupScript("Open New Window", jScript); //Response.Redirect(url); } else{ lblResponse.Text = Utilities.FormatWarningMessage("Could not access BLOB. "); lblResponse.Visible = true; } } } else { lblResponse.Text = Utilities.FormatWarningMessage("No ESS is specified, so no records. "); lblResponse.Visible = true; } }
/// <summary> /// Retrieves an experiment's ResultReport from the ESS /// </summary> /// <param name="experimentID"></param> /// <param name="roles"></param> /// <returns>THe ResultStatus or an empty report with status set, when the experiment has not terminated that have not</returns> public static ResultReport GetResultReport(int experimentID) { ResultReport report = null; BrokerDB brokerDB = new BrokerDB(); try { ExperimentAdminInfo expInfo = InternalDataDB.SelectExperimentAdminInfo(experimentID); if (expInfo == null || expInfo.experimentID <= 0) { //experiment does not exist throw new SoapException("Invalid experiment ID. ", SoapException.ServerFaultCode); } else { ProcessAgentInfo ess = brokerDB.GetProcessAgentInfo(expInfo.essID); if(ess.retired){ throw new Exception("The requested ESS has been retired"); } ExperimentStorageProxy essProxy = new ExperimentStorageProxy(); essProxy.AgentAuthHeaderValue = new AgentAuthHeader(); essProxy.AgentAuthHeaderValue.agentGuid = ProcessAgentDB.ServiceGuid; essProxy.AgentAuthHeaderValue.coupon = ess.identOut; essProxy.Url = ess.webServiceUrl; Coupon opCoupon = brokerDB.GetEssOpCoupon(expInfo.experimentID, TicketTypes.RETRIEVE_RECORDS, 60, ess.agentGuid); OperationAuthHeader opHeader = new OperationAuthHeader(); opHeader.coupon = opCoupon; essProxy.OperationAuthHeaderValue = opHeader; if ((expInfo.status & StorageStatus.CLOSED) == 0) { ProcessAgentInfo lsInfo = brokerDB.GetProcessAgentInfo(expInfo.agentID); if (lsInfo != null) { if(lsInfo.retired){ throw new Exception("The requested batch LabServer has ben retired."); } BatchLSProxy batchLS_Proxy = new BatchLSProxy(); batchLS_Proxy.AuthHeaderValue = new AuthHeader(); batchLS_Proxy.AuthHeaderValue.identifier = ProcessAgentDB.ServiceGuid; batchLS_Proxy.AuthHeaderValue.passKey = lsInfo.identOut.passkey; batchLS_Proxy.Url = lsInfo.webServiceUrl; // retrieve resultReport from labServer LabExperimentStatus expStatus = batchLS_Proxy.GetExperimentStatus(experimentID); if (expStatus != null) { if ((expStatus.statusReport.statusCode >= 3) && (expStatus.statusReport.statusCode != 6)) { report = batchLS_Proxy.RetrieveResult(experimentID); if (report != null) { ExperimentRecord theRecord = null; List<ExperimentRecord> recordList = new List<ExperimentRecord>(); if (report.experimentResults != null && report.experimentResults.Length > 0) { theRecord = new ExperimentRecord(); theRecord.submitter = lsInfo.agentGuid; theRecord.type = BatchRecordType.RESULT; theRecord.contents = report.experimentResults; theRecord.xmlSearchable = false; recordList.Add(theRecord); } if (report.errorMessage != null && report.errorMessage.Length > 0) { theRecord = new ExperimentRecord(); theRecord.submitter = lsInfo.agentGuid; theRecord.type = BatchRecordType.EXECUTION_ERROR; theRecord.contents = report.errorMessage; theRecord.xmlSearchable = false; recordList.Add(theRecord); } if (report.warningMessages != null && report.warningMessages.Length > 0) { foreach (string s in report.warningMessages) { if (s.Length > 0) { theRecord = new ExperimentRecord(); theRecord.submitter = lsInfo.agentGuid; theRecord.type = BatchRecordType.EXECUTION_WARNING; theRecord.contents = s; theRecord.xmlSearchable = false; recordList.Add(theRecord); } } } if (report.xmlResultExtension != null && report.xmlResultExtension.Length > 0) { theRecord = new ExperimentRecord(); theRecord.submitter = lsInfo.agentGuid; theRecord.type = BatchRecordType.RESULT_EXTENSION; theRecord.contents = report.xmlResultExtension; theRecord.xmlSearchable = true; recordList.Add(theRecord); } if (report.xmlBlobExtension != null && report.xmlBlobExtension.Length > 0) { theRecord = new ExperimentRecord(); theRecord.submitter = lsInfo.agentGuid; theRecord.type = BatchRecordType.BLOB_EXTENSION; theRecord.contents = report.xmlBlobExtension; theRecord.xmlSearchable = true; recordList.Add(theRecord); } if (recordList.Count > 0) { essProxy.AddRecords(experimentID, recordList.ToArray()); } StorageStatus sStatus = essProxy.SetExperimentStatus(experimentID, report.statusCode | StorageStatus.CLOSED); DataStorageAPI.UpdateExperimentStatus(sStatus); } } } } } else { report = new ResultReport(); ExperimentRecord[] records = essProxy.GetRecords(experimentID, null); if (records != null) { List<String> execWarnings = new List<String>(); foreach (ExperimentRecord rec in records) { if (rec.type.CompareTo(BatchRecordType.EXECUTION_ERROR) == 0) { report.errorMessage = rec.contents; } else if (rec.type.CompareTo(BatchRecordType.BLOB_EXTENSION) == 0) { report.xmlBlobExtension = rec.contents; } else if (rec.type.CompareTo(BatchRecordType.RESULT_EXTENSION) == 0) { report.xmlResultExtension = rec.contents; } else if (rec.type.CompareTo(BatchRecordType.EXECUTION_WARNING) == 0) { execWarnings.Add(rec.contents); } else if (rec.type.CompareTo(BatchRecordType.RESULT) == 0) { report.experimentResults = rec.contents; } } if (execWarnings.Count > 0) { report.warningMessages = execWarnings.ToArray(); } } report.statusCode = expInfo.status & StorageStatus.BATCH_MASK; } } } catch (Exception ex) { throw new SoapException(ex.Message + ". " + ex.GetBaseException(), SoapException.ServerFaultCode, ex); } return report; }
public static ExperimentInformation[] GetExperimentInformation(int[] experimentIDs) { List<ExperimentInformation> list = new List<ExperimentInformation>(); try { long[] expIDs = new long[experimentIDs.Length]; for (int i = 0; i < experimentIDs.Length; i++) { expIDs[i] = (long)experimentIDs[i]; } ExperimentAdminInfo[] expSummaries = InternalDataDB.SelectExperimentAdminInfos(expIDs); if (expSummaries != null) foreach (ExperimentAdminInfo expSum in expSummaries) { ExperimentInformation info = new ExperimentInformation(); info.experimentID = expSum.experimentID; info.userID = expSum.userID; info.effectiveGroupID = expSum.groupID; info.labServerID = expSum.agentID; info.statusCode = expSum.status & StorageStatus.BATCH_MASK; info.submissionTime = expSum.creationTime; info.completionTime = expSum.closeTime; DateTime endTime = expSum.startTime.AddSeconds(expSum.duration); info.expirationTime = endTime; double hours = new TimeSpan(endTime.Ticks - DateTime.UtcNow.Ticks).TotalHours; info.minTimeToLive = hours > 0 ? hours : 0; info.annotation = expSum.annotation; //Get the Experiment records from the ESS if one is used if (expSum.essID > 0) { // This operation should happen within the Wrapper BrokerDB brokerDB = new BrokerDB(); ProcessAgentInfo ess = brokerDB.GetProcessAgentInfo(expSum.essID); Coupon opCoupon = brokerDB.GetEssOpCoupon( expSum.experimentID, TicketTypes.RETRIEVE_RECORDS, 60, ess.agentGuid); ExperimentStorageProxy essProxy = new ExperimentStorageProxy(); OperationAuthHeader header = new OperationAuthHeader(); header.coupon = opCoupon; essProxy.Url = ess.webServiceUrl; essProxy.OperationAuthHeaderValue = header; Criterion errors = new Criterion("record_type", "like", "*Message"); Criterion extensions = new Criterion("record_type", "like", "*Extension"); Criterion [] criteria = new Criterion[] {errors,extensions }; ExperimentRecord[] records = brokerDB.RetrieveExperimentRecords(expSum.experimentID, criteria); if (records != null) { List<String> valWarnings = new List<String>(); List<String> execWarnings = new List<String>(); foreach (ExperimentRecord rec in records) { if (rec.type.CompareTo(BatchRecordType.EXECUTION_ERROR) == 0) { info.executionErrorMessage = rec.contents; } else if (rec.type.CompareTo(BatchRecordType.VALIDATION_ERROR) == 0) { info.validationErrorMessage = rec.contents; } else if (rec.type.CompareTo(BatchRecordType.BLOB_EXTENSION) == 0) { info.xmlBlobExtension = rec.contents; } else if (rec.type.CompareTo(BatchRecordType.RESULT_EXTENSION) == 0) { info.xmlResultExtension = rec.contents; } else if (rec.type.CompareTo(BatchRecordType.EXECUTION_WARNING) == 0) { execWarnings.Add(rec.contents); } else if (rec.type.CompareTo(BatchRecordType.VALIDATION_WARNING) == 0) { valWarnings.Add(rec.contents); } } if (execWarnings.Count > 0) { info.executionWarningMessages = execWarnings.ToArray(); } if (valWarnings.Count > 0) { info.validationWarningMessages = valWarnings.ToArray(); } } } list.Add(info); } } catch { throw; } if (list.Count > 0) { return list.ToArray(); } else return null; }
public static long[] RetrieveAuthorizedExpIDs(int userID, int groupID, Criterion[] carray) { long[] expIDs = null; List<Criterion> sbList = new List<Criterion>(); List<Criterion> essList = new List<Criterion>(); if (carray != null && carray.Length > 0) { // Parse the criterion for (int i = 0; i < carray.Length; i++) { switch (carray[i].attribute.ToLower()) { //these criterion are based on external values, requiring special processing of the fields. case "username": sbList.Add(new Criterion("User_ID", carray[i].predicate, "(select user_id from users where user_name=" + carray[i].value + ")")); break; case "groupname": sbList.Add(new Criterion("Group_ID", carray[i].predicate, "(select group_id from group where group_name=" + carray[i].value + ")")); break; case "clientname": sbList.Add(new Criterion("Client_ID", carray[i].predicate, "(select client_id from lab_clients where lab_client_name=" + carray[i].value + ")")); break; case "labservername": sbList.Add(new Criterion("Agent_ID", carray[i].predicate, "(select agent_id from processAgent where agent_name=" + carray[i].value + ")")); break; case "start": sbList.Add(new Criterion("creationtime", carray[i].predicate, carray[i].value)); break; case "agent_id": // Actual SB experiment column names case "annotation": case "client_id": case "creationtime": case "ess_id": case "group_id": case "scheduledstart": case "user_id": sbList.Add(carray[i]); break; // ESS targets case "record_count": case "record_type": // Individual record criterion send to ESS case "contents": default: // any unhandled attributes are record attributes essList.Add(carray[i]); break; } } //parsing of Criterion done } if (sbList.Count == 0 && essList.Count == 0) { // No search items - Get all experiments allowed expIDs = InternalDataDB.RetrieveExperimentIDs(userID, groupID); } else { // Query SB database to find all possible Experiments and related ESS's //As there are criteria only experiments with hits will be returned bool hasEssCriteria = (essList.Count > 0); List<long> workExp = new List<long>(); Hashtable essLists = null; // DataSet contains all experimentID and ess ids that pass SB criteria, // and a set of all ess_ids for the authorized experiments DataSet results = InternalDataDB.RetrieveExperimentIDsCriteria(userID, groupID, sbList.ToArray()); if (results != null) { if (hasEssCriteria) { DataTable essids = results.Tables["ess"]; if (essids != null && essids.Rows != null && essids.Rows.Count > 0) { essLists = new Hashtable(); foreach (DataRow er in essids.Rows) { if (er[0] != DBNull.Value) { List<Int64> exps = new List<Int64>(); essLists.Add(Convert.ToInt32(er[0]), exps); } } } } DataTable hits = results.Tables["sbHits"]; if (hits != null) { // Add SB hits to list foreach (DataRow r in hits.Rows) { workExp.Add(Convert.ToInt64(r[0])); if (hasEssCriteria) { if (r[1] != DBNull.Value) { ((List<Int64>)essLists[Convert.ToInt32(r[1])]).Add(Convert.ToInt64(r[0])); } } } } if (hasEssCriteria) { // Have ESS criteria, use the workList and further filter List<Int64> essHits = new List<Int64>(); BrokerDB brokerDB = new BrokerDB(); //Process ess criteria foreach (object obj in essLists.Keys) { List<Int64> essExps = (List<Int64>)essLists[obj]; if (essExps.Count > 0) { int essId = Convert.ToInt32(obj); ProcessAgentInfo info = brokerDB.GetProcessAgentInfo(essId); if ((info != null) && !info.retired) { ExperimentStorageProxy essProxy = new ExperimentStorageProxy(); AgentAuthHeader authHeader = new AgentAuthHeader(); authHeader.agentGuid = ProcessAgentDB.ServiceGuid; authHeader.coupon = info.identOut; essProxy.AgentAuthHeaderValue = authHeader; essProxy.Url = info.webServiceUrl; long[] essExpids = essProxy.GetExperimentIDs(essExps.ToArray(), essList.ToArray()); if (essExpids != null && essExpids.Length > 0) { foreach (long e in essExpids) { essHits.Add(e); } } } } }// End of ESS processing expIDs = essHits.ToArray(); } else { expIDs = workExp.ToArray(); } } } return expIDs; }
public int RemoveTickets(List<Ticket> ticketList, BrokerDB brokerDb) { ArrayList coupons = new ArrayList(); Coupon coupon = null; int ticketCount = 0; int couponCount = 0; if (ticketList.Count > 0) { Utilities.WriteLog("RemoveTickets: expired count = " + ticketList.Count); foreach (Ticket ticket in ticketList) { if (!coupons.Contains(ticket.couponId)) { coupons.Add(ticket.couponId); } if (coupon == null || coupon.couponId != ticket.couponId) { coupon = brokerDb.GetIssuedCoupon(ticket.couponId); } switch (ticket.type) { case TicketTypes.ADMINISTER_EXPERIMENT: string payload = ticket.payload; if (payload != null) { XmlQueryDoc xDoc = new XmlQueryDoc(payload); string url = xDoc.Query("AdministerExperimentPayload/essURL"); string expStr = xDoc.Query("AdministerExperimentPayload/experimentID"); long expID = Convert.ToInt64(expStr); ExperimentStorageProxy essProxy = new ExperimentStorageProxy(); essProxy.OperationAuthHeaderValue = new OperationAuthHeader(); essProxy.OperationAuthHeaderValue.coupon = coupon; essProxy.Url = url; StorageStatus expStatus = essProxy.SetExperimentStatus(expID, (int)StorageStatus.CLOSED_TIMEOUT); DataStorageAPI.UpdateExperimentStatus(expStatus); } break; case TicketTypes.RETRIEVE_RECORDS: case TicketTypes.STORE_RECORDS: break; case TicketTypes.EXECUTE_EXPERIMENT: case TicketTypes.ALLOW_EXPERIMENT_EXECUTION: break; default: // Every other Ticket type break; } bool statusR = false; if (ticket.redeemerGuid != brokerDb.GetIssuerGuid()) { ProcessAgentInfo redeemer = brokerDb.GetProcessAgentInfo(ticket.redeemerGuid); if ((redeemer != null) && !redeemer.retired) { ProcessAgentProxy paProxy = new ProcessAgentProxy(); paProxy.AgentAuthHeaderValue = new AgentAuthHeader(); paProxy.Url = redeemer.webServiceUrl; paProxy.AgentAuthHeaderValue.coupon = redeemer.identOut; paProxy.AgentAuthHeaderValue.agentGuid = ProcessAgentDB.ServiceGuid; statusR = paProxy.CancelTicket(coupon, ticket.type, ticket.redeemerGuid); } } if (ticket.issuerGuid == brokerDb.GetIssuerGuid()) { brokerDb.DeleteIssuedTicket(ticket.ticketId); ticketCount++; } } foreach (long id in coupons) { int count = brokerDb.GetIssuedCouponCollectionCount(id); if (count == 0) { brokerDb.DeleteIssuedCoupon(id); couponCount++; } } Utilities.WriteLog("RemoveTickets: ticketCount=" + ticketCount + " \tcouponCount=" + couponCount); } return ticketCount; }
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; } }
protected void lbxSelectExperiment_SelectedIndexChanged(object sender, System.EventArgs e) { clearExperimentDisplay(); try { ExperimentSummary[] expInfo = wrapper.GetExperimentSummaryWrapper (new long[] {Int64.Parse (lbxSelectExperiment.Items [lbxSelectExperiment.SelectedIndex ].Value)}); if(expInfo[0] != null) { if( expInfo[0].essGuid != null){ int expStatus = expInfo[0].status; if ((expStatus == StorageStatus.UNKNOWN || expStatus == StorageStatus.INITIALIZED || expStatus == StorageStatus.OPEN || expStatus == StorageStatus.REOPENED || expStatus == StorageStatus.RUNNING || expStatus == StorageStatus.BATCH_QUEUED || expStatus == StorageStatus.BATCH_RUNNING || expStatus == StorageStatus.BATCH_TERMINATED || expStatus == StorageStatus.BATCH_TERMINATED_ERROR)) { // This operation should happen within the Wrapper BrokerDB ticketIssuer = new BrokerDB(); ProcessAgentInfo ess = ticketIssuer.GetProcessAgentInfo(expInfo[0].essGuid); if (ess.retired) { throw new Exception("The experiments ESS has been retired"); } Coupon opCoupon = ticketIssuer.GetEssOpCoupon(expInfo[0].experimentId, TicketTypes.RETRIEVE_RECORDS, 60, ess.agentGuid); if (opCoupon != null) { ExperimentStorageProxy essProxy = new ExperimentStorageProxy(); OperationAuthHeader header = new OperationAuthHeader(); header.coupon = opCoupon; essProxy.Url = ess.webServiceUrl; essProxy.OperationAuthHeaderValue = header; StorageStatus curStatus = essProxy.GetExperimentStatus(expInfo[0].experimentId); if (expInfo[0].status != curStatus.status || expInfo[0].recordCount != curStatus.recordCount || expInfo[0].closeTime != curStatus.closeTime) { DataStorageAPI.UpdateExperimentStatus(curStatus); expInfo[0].status = curStatus.status; expInfo[0].recordCount = curStatus.recordCount; expInfo[0].closeTime = curStatus.closeTime; } } } } txtExperimentID.Text = expInfo[0].experimentId.ToString () ; txtUserName1.Text = expInfo[0].userName ; txtLabServerName.Text =expInfo[0].labServerName; txtClientName.Text = expInfo[0].clientName; txtGroupName1.Text = expInfo[0].groupName; txtStatus.Text = DataStorageAPI.getStatusString(expInfo[0].status); txtSubmissionTime.Text = DateUtil.ToUserTime(expInfo[0].creationTime,culture,userTZ); if ((expInfo[0].closeTime != null) && (expInfo[0].closeTime != DateTime.MinValue)) txtCompletionTime.Text = DateUtil.ToUserTime(expInfo[0].closeTime, culture, userTZ); else txtCompletionTime.Text = "Not Closed!"; txtRecordCount.Text = expInfo[0].recordCount.ToString(); txtAnnotation.Text = expInfo[0].annotation; txtAnnotation.ReadOnly = false; trShowExperiment.Visible = (expInfo[0].recordCount >0); trSaveAnnotation.Visible = true; trDeleteExperiment.Visible = true; } //txtExperimentSpecification.Text = wrapper.RetrieveExperimentSpecificationWrapper (Int32.Parse (lbxSelectExperiment.Items [lbxSelectExperiment.SelectedIndex ].Value)); //txtExperimentResult.Text = wrapper.RetrieveExperimentResultWrapper (Int32.Parse (lbxSelectExperiment.Items [lbxSelectExperiment.SelectedIndex ].Value)); //txtLabconfig.Text = wrapper.RetrieveLabConfigurationWrapper (Int32.Parse (lbxSelectExperiment.Items [lbxSelectExperiment.SelectedIndex ].Value)); } catch(Exception ex) { lblResponse.Text ="<div class=errormessage><p>Exception: Error retrieving experiment information. "+ex.Message+"</p></div>"; lblResponse.Visible=true; } }
public StorageStatus ClientCloseExperiment(long experimentId) { BrokerDB ticketIssuer = new BrokerDB(); StorageStatus status = null; bool experimentClosed = false; //Coupon opCoupon = new Coupon(opHeader.coupon.issuerGuid, opHeader.coupon.couponId, // opHeader.coupon.passkey); if (ticketIssuer.AuthenticateIssuedCoupon(opHeader.coupon)) { Ticket expTicket = ticketIssuer.RetrieveTicket(opHeader.coupon, TicketTypes.EXECUTE_EXPERIMENT); if (expTicket != null) { // Check for ESS use Ticket essTicket = ticketIssuer.RetrieveTicket(opHeader.coupon, TicketTypes.ADMINISTER_EXPERIMENT); if (essTicket != null) { ProcessAgentInfo ess = ticketIssuer.GetProcessAgentInfo(essTicket.redeemerGuid); if (ess != null) { if (ess.retired) { throw new Exception("The ProcessAgent is retired"); } ExperimentStorageProxy essProxy = new ExperimentStorageProxy(); essProxy.AgentAuthHeaderValue = new AgentAuthHeader(); essProxy.AgentAuthHeaderValue.coupon = ess.identOut; essProxy.Url = ess.webServiceUrl; status = essProxy.CloseExperiment(experimentId); DataStorageAPI.UpdateExperimentStatus(status); } ticketIssuer.CancelIssuedTicket(opHeader.coupon, essTicket); } else { // Close the local Experiment records // Note: store and retrieve tickets are not cancelled. experimentClosed = DataStorageAPI.CloseExperiment(experimentId, StorageStatus.CLOSED_USER); status = DataStorageAPI.RetrieveExperimentStatus(experimentId); } } } return status; }
public override bool CancelTicket(Coupon coupon, string type, string redeemer) { bool status = false; if (dbTicketing.AuthenticateAgentHeader(agentAuthHeader)) { // Move all this into BrokerDB BrokerDB agentDB = new BrokerDB(); if (ProcessAgentDB.ServiceGuid.Equals(redeemer)) { // this ServiceBroker is the redeemer status = agentDB.CancelTicket(coupon, type, redeemer); } else { ProcessAgentInfo target = agentDB.GetProcessAgentInfo(redeemer); if (target != null) { if (target.retired) { throw new Exception("The ProcessAgent is retired"); } if (ProcessAgentDB.ServiceGuid.Equals(target.domainGuid)) { // Its a local domain processAgent ProcessAgentProxy paProxy = new ProcessAgentProxy(); paProxy.AgentAuthHeaderValue = new AgentAuthHeader(); paProxy.AgentAuthHeaderValue.coupon = target.identOut; paProxy.AgentAuthHeaderValue.agentGuid = ProcessAgentDB.ServiceGuid; paProxy.Url = target.webServiceUrl; status = paProxy.CancelTicket(coupon, type, redeemer); } else { ProcessAgentInfo remoteSB = agentDB.GetProcessAgentInfo(target.domainGuid); if (remoteSB != null) { if (remoteSB.retired) { throw new Exception("The ProcessAgent is retired"); } // Its from a known domain ProcessAgentProxy sbProxy = new ProcessAgentProxy(); sbProxy.AgentAuthHeaderValue = new AgentAuthHeader(); sbProxy.AgentAuthHeaderValue.coupon = remoteSB.identOut; sbProxy.AgentAuthHeaderValue.agentGuid = ProcessAgentDB.ServiceGuid; sbProxy.Url = remoteSB.webServiceUrl; status = sbProxy.CancelTicket(coupon, type, redeemer); } } } } } return status; }
protected override void register(string registerGuid, ServiceDescription[] info) { StringBuilder message = new StringBuilder(); message.AppendLine("Service " + ProcessAgentDB.ServiceAgent.codeBaseUrl + " recieved a 'Register' webService call."); if (info == null) { //message.AppendLine("Register called without any ServiceDescriptions"); throw new ArgumentNullException("Register called without any ServiceDescriptions"); } base.register(registerGuid, info); bool hasProvider = false; bool hasConsumer = false; //string ns = ""; BrokerDB brokerDB = new BrokerDB(); int lssID = 0; int lsID = 0; ProcessAgentInfo ls = null; ProcessAgentInfo lss = null; ProcessAgentInfo uss = null; //LabClient labClient; GroupCredential credential = null; try { ResourceDescriptorFactory rFactory = ResourceDescriptorFactory.Instance(); string jobGuid = registerGuid; message.AppendLine(" Register called at " + DateTime.UtcNow + " UTC \t registerGUID: " + registerGuid); ProcessAgent sourceAgent = brokerDB.GetProcessAgent(agentAuthHeader.agentGuid); message.AppendLine("Source Agent: " + sourceAgent.agentName); for (int i = 0; i < info.Length; i++) { Coupon coupon = null; if (info[i].coupon != null) { coupon = info[i].coupon; } if (info[i].serviceProviderInfo != null && info[i].serviceProviderInfo.Length > 0) { // ProviderInfo is simple add to database and create qualifier if (!hasProvider) { message.AppendLine("Provider Info:"); hasProvider = true; } XmlQueryDoc xdoc = new XmlQueryDoc(info[i].serviceProviderInfo); string descriptorType = xdoc.GetTopName(); if (descriptorType.Equals("processAgentDescriptor")) { string paGuid = xdoc.Query("/processAgentDescriptor/agentGuid"); string paType = xdoc.Query("/processAgentDescriptor/type"); if (paType.Equals(ProcessAgentType.LAB_SCHEDULING_SERVER)) { lssID = brokerDB.GetProcessAgentID(paGuid); if (lssID > 0) { // Already in database //message.AppendLine("Reference to existing LSS: " + lssID + " GUID: " + paGuid); } else { lss = rFactory.LoadProcessAgent(xdoc, ref message); lssID = lss.agentId; } } else if (paType.Equals(ProcessAgentType.LAB_SERVER)) { lsID = brokerDB.GetProcessAgentID(paGuid); if (lsID > 0) { // Already in database //message.AppendLine("Reference to existing LS: " + lsID + " GUID: " + paGuid); } else { ls = rFactory.LoadProcessAgent(xdoc, ref message); lsID = ls.agentId; } int myLssID = brokerDB.FindProcessAgentIdForAgent(lsID, ProcessAgentType.LAB_SCHEDULING_SERVER); if ((lssID > 0) && (myLssID <= 0) && (lssID != myLssID)) { brokerDB.AssociateLSS(lsID, lssID); } } } else if (descriptorType.Equals("clientDescriptor")) { int clientId = -1; string clientGuid = xdoc.Query("/clientDescriptor/clientGuid"); clientId = AdministrativeAPI.GetLabClientID(clientGuid); if (clientId > 0) { // Already in database message.Append(" Attempt to Register a LabClient that is already in the database. "); message.AppendLine(" GUID: " + clientGuid); } else { // LabServer should already be in the Database, once multiple LS supported may need work // LS is specified in clientDescriptor int clientID = rFactory.LoadLabClient(xdoc, ref message); message.AppendLine("Adding LabClient: GUID " + clientGuid); } } else if (descriptorType.Equals("systemSupport")) { SystemSupport ss = SystemSupport.Parse(xdoc); if (ss.agentGuid != null && ss.agentGuid.Length > 0) { int id = brokerDB.GetProcessAgentID(ss.agentGuid); if (id > 0) { brokerDB.SaveSystemSupport(ss.agentGuid, ss.contactEmail, ss.bugEmail, ss.infoUrl, ss.description, ss.location); message.AppendLine("Adding SystemSupport information for " + ss.agentGuid); } } } // Add Relationships: LSS, LS Client } // end of ServiceProvider if (info[i].consumerInfo != null && info[i].consumerInfo.Length > 0) { if (!hasConsumer) message.AppendLine("Consumer Info:"); hasConsumer = true; XmlQueryDoc xdoc = new XmlQueryDoc(info[i].consumerInfo); string descriptorType = xdoc.GetTopName(); if (descriptorType.Equals("processAgentDescriptor")) { string paGuid = xdoc.Query("/processAgentDescriptor/agentGuid"); ProcessAgentInfo paInfo = brokerDB.GetProcessAgentInfo(paGuid); if (paInfo == null) { // Not in database paInfo = rFactory.LoadProcessAgent(xdoc, ref message); message.Append("Loaded new "); } else { message.Append("Reference to existing "); if (paInfo.retired) { throw new Exception("The ProcessAgent is retired"); } } if (paInfo.agentType == ProcessAgentType.AgentType.LAB_SCHEDULING_SERVER) { lss = paInfo; message.AppendLine("LSS: " + paGuid); } else if (paInfo.agentType == ProcessAgentType.AgentType.LAB_SERVER) { ls = paInfo; message.AppendLine("LS: " + paGuid); } else if (paInfo.agentType == ProcessAgentType.AgentType.SCHEDULING_SERVER) { uss = paInfo; message.AppendLine("USS: " + paGuid); if (lss != null) { if (lss.domainGuid.Equals(ProcessAgentDB.ServiceGuid)) { message.AppendLine("Registering USSinfo on LSS: " + lss.agentName); LabSchedulingProxy lssProxy = new LabSchedulingProxy(); lssProxy.AgentAuthHeaderValue = new AgentAuthHeader(); lssProxy.AgentAuthHeaderValue.coupon = lss.identOut; lssProxy.AgentAuthHeaderValue.agentGuid = ProcessAgentDB.ServiceGuid; lssProxy.Url = lss.webServiceUrl; lssProxy.AddUSSInfo(uss.agentGuid, uss.agentName, uss.webServiceUrl, coupon); } else { message.AppendLine("LSS is not from this domain"); } } } } else if (descriptorType.Equals("clientDescriptor")) { //int newClientId = -1; string clientGuid = xdoc.Query("/clientDescriptor/clientGuid"); int clientId = AdministrativeAPI.GetLabClientID(clientGuid); if (clientId > 0) { // Already in database message.Append(" Attempt to Register a LabClient that is already in the database. "); message.AppendLine(" GUID: " + clientGuid); } else { clientId = rFactory.LoadLabClient(xdoc, ref message); message.AppendLine("Adding Lab Client GUID: " + clientGuid); } } else if (descriptorType.Equals("credentialDescriptor")) { credential = rFactory.ParseCredential(xdoc, ref message); if (lss != null) { if (lss.domainGuid.Equals(ProcessAgentDB.ServiceGuid)) { message.AppendLine("Registering Group Credentials on LSS: " + lss.agentName); message.AppendLine("Group: " + credential.groupName + " DomainServer: " + credential.domainServerName); LabSchedulingProxy lssProxy = new LabSchedulingProxy(); lssProxy.AgentAuthHeaderValue = new AgentAuthHeader(); lssProxy.AgentAuthHeaderValue.coupon = lss.identOut; lssProxy.AgentAuthHeaderValue.agentGuid = ProcessAgentDB.ServiceGuid; lssProxy.Url = lss.webServiceUrl; lssProxy.AddCredentialSet(credential.domainGuid, credential.domainServerName, credential.groupName, credential.ussGuid); } else { message.AppendLine("LSS is not from this domain"); } } } } } // End of info loop } // End of Try catch (Exception ex) { message.Append("Exception in Register: " + Utilities.DumpException(ex)); throw; } finally { // Send a mail Message //StringBuilder sb = new StringBuilder(); //MailMessage mail = new MailMessage(); //mail.To = ConfigurationManager.AppSettings["supportMailAddress"]; ////mail.To = "*****@*****.**"; //mail.From = ConfigurationManager.AppSettings["genericFromMailAddress"]; //mail.Subject = "Register called on " + ProcessAgentDB.ServiceAgent.agentName; //mail.Body = message.ToString(); //SmtpMail.SmtpServer = "127.0.0.1"; string subject = "Register called on " + ProcessAgentDB.ServiceAgent.agentName; string body = message.ToString(); string from = ConfigurationManager.AppSettings["genericFromMailAddress"]; string to = ConfigurationManager.AppSettings["supportMailAddress"]; MailMessage mailMessage = new MailMessage(from, to, subject, body); SmtpClient smtpClient = new SmtpClient(Consts.STR_LocalhostIP); try { //SmtpMail.Send(mail); smtpClient.Send(mailMessage); } catch (Exception ex) { // Report detailed SMTP Errors StringBuilder smtpErrorMsg = new StringBuilder(); smtpErrorMsg.Append("Exception: " + ex.Message); //check the InnerException if (ex.InnerException != null) smtpErrorMsg.Append("<br>Inner Exceptions:"); while (ex.InnerException != null) { smtpErrorMsg.Append("<br>" + ex.InnerException.Message); ex = ex.InnerException; } Utilities.WriteLog(smtpErrorMsg.ToString()); } } }