示例#1
0
        protected void btnModify_Click(object sender, System.EventArgs e)
        {
            bool error = false;
            StringBuilder message = new StringBuilder();
            try
            {
                if (ProcessAgentDB.ServiceAgent != null)
                {
                    string originalGuid = ProcessAgentDB.ServiceAgent.agentGuid;
                    if (!(txtServiceName.Text != null && txtServiceName.Text.Length > 0))
                    {
                        error = true;
                        message.Append(" You must enter a Service Name<br/>");
                    }
                    try
                    {
                        if (!checkGuid())
                        {
                            error = true;
                            message.Append("There is an unspecified error with the GUID string.<br/>");
                        }
                    }
                    catch (Exception ex)
                    {
                        error = true;
                        message.Append("GUID Error: ");
                        message.Append(ex.Message);
                        message.Append("<br/>");
                    }

                    if (!(txtCodebaseUrl.Text != null && txtCodebaseUrl.Text.Length > 0))
                    {
                        error = true;
                        message.Append(" You must enter the base URL for the Web Site<br/>");
                    }
                    if (!(txtServiceUrl.Text != null && txtServiceUrl.Text.Length > 0))
                    {
                        error = true;
                        message.Append(" You must enter full URL of the Web Service page<br/>");
                    }
                    if (error)
                    {
                        lblResponse.Text = Utilities.FormatErrorMessage(message.ToString());
                        lblResponse.Visible = true;
                        return;
                    }
                    if (ProcessAgentDB.ServiceAgent.domainGuid != null)
                    {
                        ProcessAgentInfo originalAgent = dbTicketing.GetProcessAgentInfo(originalGuid);
                        ProcessAgentInfo sb = dbTicketing.GetProcessAgentInfo(ProcessAgentDB.ServiceAgent.domainGuid);
                        if ((sb != null) && !sb.retired)
                        {
                            ProcessAgentProxy psProxy = new ProcessAgentProxy();
                            AgentAuthHeader header = new AgentAuthHeader();
                            header.agentGuid = ProcessAgentDB.ServiceAgent.agentGuid;
                            header.coupon = sb.identOut;
                            psProxy.AgentAuthHeaderValue = header;
                            psProxy.Url = sb.webServiceUrl;
                            ProcessAgent pa = new ProcessAgent();
                            pa.agentGuid = txtServiceGuid.Text;
                            pa.agentName = txtServiceName.Text;
                            pa.domainGuid = ProcessAgentDB.ServiceAgent.domainGuid;
                            pa.codeBaseUrl = txtCodebaseUrl.Text;
                            pa.webServiceUrl = txtServiceUrl.Text;
                            pa.type = AgentType;
                            //dbTicketing.SelfRegisterProcessAgent(pa.agentGuid, pa.agentName, agentType,
                            //    pa.domainGuid, pa.codeBaseUrl, pa.webServiceUrl);
                            //message.Append("Local information has been saved. ");
                            int returnValue = psProxy.ModifyProcessAgent(originalGuid, pa, null);
                            message.Append("The changes have been sent to the ServiceBroker");
                            if (returnValue > 0)
                            {
                                dbTicketing.SelfRegisterProcessAgent(pa.agentGuid, pa.agentName, AgentType,
                                pa.domainGuid, pa.codeBaseUrl, pa.webServiceUrl);

                                message.Append(".<br />Local information has been saved. ");
                                lblResponse.Text = Utilities.FormatConfirmationMessage(message.ToString());
                                lblResponse.Visible = true;

                            }
                            else
                            {
                                message.Append(", but did not process correctly!");
                                message.Append("<br />Local information has not been saved. ");
                                lblResponse.Text = Utilities.FormatErrorMessage(message.ToString());
                                lblResponse.Visible = true;
                            }
                        }
                    }
                    else
                    {
                        dbTicketing.SelfRegisterProcessAgent(ProcessAgentDB.ServiceAgent.agentGuid, txtServiceName.Text, AgentType,
                                null, txtCodebaseUrl.Text, txtServiceUrl.Text);
                        dbTicketing.SaveSystemSupport(ProcessAgentDB.ServiceAgent.agentGuid, txtContactInfo.Text, txtBugEmail.Text,
                           txtInfoUrl.Text, txtDescription.Text, txtLocation.Text);
                    }
                }
            }
            catch (Exception ex)
            {
                Exception ex2 = new Exception("Error in  selfRegistration.modify()", ex);
                Utilities.WriteLog(Utilities.DumpException(ex2));
                throw ex2;
            }
        }
示例#2
0
        protected void btnRetire_Click(object sender, System.EventArgs e)
        {
            bool error = false;
            StringBuilder message = new StringBuilder();
            try
            {
                if (ProcessAgentDB.ServiceAgent.domainGuid != null)
                {
                    ProcessAgentInfo originalAgent = dbTicketing.GetProcessAgentInfo(ProcessAgentDB.ServiceAgent.agentGuid);
                    ProcessAgentInfo sb = dbTicketing.GetProcessAgentInfo(ProcessAgentDB.ServiceAgent.domainGuid);
                    if ((sb != null) && !sb.retired)
                    {
                        ProcessAgentProxy psProxy = new ProcessAgentProxy();
                        AgentAuthHeader header = new AgentAuthHeader();
                        header.agentGuid = originalAgent.agentGuid;
                        header.coupon = sb.identOut;
                        psProxy.AgentAuthHeaderValue = header;
                        psProxy.Url = sb.webServiceUrl;

                        int returnValue = psProxy.RetireProcessAgent(originalAgent.domainGuid,
                            originalAgent.agentGuid, true);
                        message.Append("The changes have been sent to the ServiceBroker");
                        if (returnValue > 0)
                        {
                            dbTicketing.SetDomainGuid(null);
                            dbTicketing.SetSelfState(originalAgent.agentGuid, false);
                            dbTicketing.SetProcessAgentRetired(originalAgent.agentGuid, true);
                            dbTicketing.DeleteTickets(originalAgent.agentGuid);

                            message.Append(".<br />Local information has been saved. ");
                            lblResponse.Text = Utilities.FormatConfirmationMessage(message.ToString());
                            lblResponse.Visible = true;

                        }
                        else
                        {
                            message.Append(", but did not process correctly!");
                            message.Append("<br />Local information has not been saved. ");
                            lblResponse.Text = Utilities.FormatErrorMessage(message.ToString());
                            lblResponse.Visible = true;
                        }
                    }
                    else
                    {
                        dbTicketing.SelfRegisterProcessAgent(ProcessAgentDB.ServiceAgent.agentGuid, txtServiceName.Text, AgentType,
                                null, txtCodebaseUrl.Text, txtServiceUrl.Text);
                    }
                }
            }
            catch (Exception ex)
            {
                Exception ex2 = new Exception("Error in  selfRegistration.modify()", ex);
                Utilities.WriteLog(Utilities.DumpException(ex2));
                throw ex2;
            }
            clearForm();
        }
示例#3
0
        /// <summary>
        /// Checks the AgentAuthHeader to make sure the coupon matches the local IdentityIn Coupon for the specified agent.
        /// </summary>
        /// <param name="agentHeader"></param>
        /// <returns></returns>
        public bool AuthenticateAgentHeader(AgentAuthHeader agentHeader)
        {
            if (agentHeader.agentGuid == null)
            {
                throw new TicketingAutheticationFailedException("AgentGuid is null");
            }
            Coupon inCoupon = GetIdentityInCoupon(agentHeader.agentGuid);

            if (inCoupon == null)
            {
                return false;
            }
            else
            {
                return agentHeader.coupon == inCoupon;
            }
        }
示例#4
0
        /// <summary>
        /// Retrieves ticket from local database or the SB. Ticket type is needed to retrieve ticket from SB, 
        /// </summary>
        /// <param name="coupon">operation coupon sent by the Process Agent</param>
        /// <param name="ticketType">type of the ticket to be retrieved</param>
        /// <returns>Retrieved ticket</returns>
        public Ticket RetrieveAndVerify(Coupon coupon, string ticketType)
        {
            Ticket theTicket = RetrieveTicket(coupon, ticketType, ServiceGuid);
            if (theTicket == null)
            {
                TicketIssuerProxy ticketIssuerProxy = new TicketIssuerProxy();

                //Get the Service Broker info from the database
                ProcessAgentInfo sbInfo = GetServiceBrokerInfo();

                //get the SB web service URL, and set the proxy's URL accordingly
                ticketIssuerProxy.Url = sbInfo.webServiceUrl;

                iLabs.DataTypes.SoapHeaderTypes.AgentAuthHeader agentAuthHeader = new iLabs.DataTypes.SoapHeaderTypes.AgentAuthHeader();

                //set the SOAP header (of the proxy class) to the agentCoupon
                agentAuthHeader.coupon = sbInfo.identOut;
                agentAuthHeader.agentGuid = ServiceGuid;
                ticketIssuerProxy.AgentAuthHeaderValue = agentAuthHeader;

                //call the RetrieveTicket web service method on the SB (ticket issuer)
                theTicket = ticketIssuerProxy.RedeemTicket(coupon, ticketType, ServiceGuid);
                if (theTicket != null)
                {
                    // If the ticket is no longer valid do not insert it
                    if (!theTicket.IsExpired() && !theTicket.isCancelled)
                    {
                        if (!AuthenticateCoupon(coupon))
                        {
                            // coupon is not in the database
                            InsertCoupon(coupon);
                        }
                        InsertTicket(theTicket);
                    }
                }
            }
            //if ticket not found locally or in in the Ticket issuer (SB) database, throw exception
            if (theTicket == null)
            {
                throw new TicketNotFoundException("The requested ticket was not found. "
                    + "Ticket type: " + ticketType + ". Access denied.");
            }
            if (theTicket.IsExpired() || theTicket.isCancelled)
            {
                     throw new TicketExpiredException("The Retrieved ticket has expired. "
                    + "Ticket type: " + ticketType + ". Access denied.");
            }
            return theTicket;
        }
        private void redeemReservation(ReservationInfo res)
        {
            long duration = (res.endTime.Ticks - res.startTime.Ticks) / TimeSpan.TicksPerSecond;
            TicketLoadFactory factory = TicketLoadFactory.Instance();
            ProcessAgentDB ticketing = new ProcessAgentDB();

            string payload = factory.createAllowExperimentExecutionPayload(
                res.startTime, duration, Session["groupName"].ToString(),clientGuid);
            DateTime tmpTime = res.startTime.AddTicks(duration * TimeSpan.TicksPerSecond);
            DateTime utcNow = DateTime.UtcNow;
            long ticketDuration = (tmpTime.Ticks - utcNow.Ticks) / TimeSpan.TicksPerSecond;

            TicketIssuerProxy ticketIssuer = new TicketIssuerProxy();

            //get the SB web service URL, and set the proxy's URL accordingly
            ProcessAgentInfo sbInfo = ticketing.GetServiceBrokerInfo();
            ticketIssuer.Url = sbInfo.webServiceUrl;

            //Get the agent coupon Coupon, to be embedded in the SOAP header of the web service call to the SB
            Coupon agentOutCoupon = sbInfo.identOut;

            iLabs.DataTypes.SoapHeaderTypes.AgentAuthHeader agentAuthHeader = new iLabs.DataTypes.SoapHeaderTypes.AgentAuthHeader();

            //set the SOAP header (of the proxy class) to the agentCoupon
            agentAuthHeader.coupon = agentOutCoupon;
            agentAuthHeader.agentGuid = ProcessAgentDB.ServiceGuid;
            ticketIssuer.AgentAuthHeaderValue = agentAuthHeader;

            //call the CreateTicket web service method on the SB (ticket issuer)
            Coupon allowExecutionCoupon = ticketIssuer.CreateTicket(TicketTypes.ALLOW_EXPERIMENT_EXECUTION,
                sbInfo.agentGuid, ticketDuration, payload);

            if (allowExecutionCoupon != null)
            {
                string couponId = allowExecutionCoupon.couponId.ToString();
                string passkey = allowExecutionCoupon.passkey;
                string issuerGuid = allowExecutionCoupon.issuerGuid;

                string backToSbUrl = Session["sbUrl"].ToString() +
                    "?coupon_id=" + couponId +
                    "&passkey=" + passkey +
                    "&issuer_guid=" + issuerGuid;

                Response.Redirect(backToSbUrl, false);
            }
            else
            {
                string msg = "Exception: ExperimentExecution is not allowed.";
                lblErrorMessage.Text = Utilities.FormatErrorMessage(msg);
                lblErrorMessage.Visible = true;
            }
        }
        protected int removeSchedulingInfo(int clientId, int serverId, int ussId, int lssId, ref StringBuilder message)
        {
            int status = 1;
            int result = 1;
            DateTime start = DateTime.UtcNow;
            DateTime end = DateTime.MaxValue;
            ProcessAgent ls = ticketing.GetProcessAgent(serverId);
            ProcessAgentInfo lss = ticketing.GetProcessAgentInfo(lssId);
            ProcessAgentInfo uss = ticketing.GetProcessAgentInfo(ussId);
            if (ls == null)
            {
                message.AppendLine("LabServer is not specified!<br/>");
                status = 0;
            }
            if (lss == null)
            {
                message.AppendLine("LSS is not specified!<br/>");
                status = 0;
            }
            if (uss == null)
            {
                message.AppendLine("USS is not specified!<br/>");
                status = 0;
            }
            if (status < 1)
            {
                return status;
            }
            TicketLoadFactory tlf = TicketLoadFactory.Instance();
            string payload = tlf.createRevokeReservationPayload("ISB");
            Coupon coupon = ticketing.CreateTicket(TicketTypes.REVOKE_RESERVATION, lss.agentGuid, ProcessAgentDB.ServiceGuid, 300L, payload);
            ticketing.AddTicket(coupon, TicketTypes.REVOKE_RESERVATION, uss.agentGuid, ProcessAgentDB.ServiceGuid, 300L, payload);

            LabSchedulingProxy lssProxy = new LabSchedulingProxy();
            AgentAuthHeader agentHeader = new AgentAuthHeader();
            agentHeader.agentGuid = ProcessAgentDB.ServiceGuid;
            agentHeader.coupon = lss.identOut;
            lssProxy.AgentAuthHeaderValue = agentHeader;
            OperationAuthHeader opHeader = new OperationAuthHeader();
            opHeader.coupon = coupon;
            lssProxy.OperationAuthHeaderValue = opHeader;
            lssProxy.Url = lss.webServiceUrl;
            int count = lssProxy.RemoveReservation(ProcessAgentDB.ServiceGuid, "", uss.agentGuid, ls.agentGuid, labClient.clientGuid, start, end);
            result = lssProxy.RemoveExperimentInfo(ls.agentGuid, labClient.clientGuid);
            if (result > 0)
            {
                status = Math.Min(status, result);
            }

            UserSchedulingProxy ussProxy = new UserSchedulingProxy();
            AgentAuthHeader header = new AgentAuthHeader();
            header.agentGuid = ProcessAgentDB.ServiceGuid;
            header.coupon = uss.identOut;
            ussProxy.AgentAuthHeaderValue = header;
            OperationAuthHeader op2Header = new OperationAuthHeader();
            op2Header.coupon = coupon;
            ussProxy.OperationAuthHeaderValue = op2Header;
            ussProxy.Url = uss.webServiceUrl;
            int num = ussProxy.RevokeReservation(ProcessAgentDB.ServiceGuid, "", ls.agentGuid, labClient.clientGuid, start, end,
                "The USS is being removed from this lab client!");
            result = ussProxy.RemoveExperimentInfo(ls.agentGuid, labClient.clientGuid, lss.agentGuid);
            if (result > 0)
            {
                status = Math.Min(status, result);
            }
            return status;
        }
        protected void btnModify_Click(object sender, System.EventArgs e)
        {
            bool error = false;
            StringBuilder message = new StringBuilder();
            try
            {
                if (ProcessAgentDB.ServiceAgent != null)
                {
                    string originalGuid = ProcessAgentDB.ServiceAgent.agentGuid;
                    if (!(txtServiceName.Text != null && txtServiceName.Text.Length > 0))
                    {
                        error = true;
                        message.Append(" You must enter a Service Name<br/>");
                    }
                    try
                    {
                        if (!checkGuid())
                        {
                            error = true;
                            message.Append("There is an unspecified error with the GUID string.<br/>");
                        }
                    }
                    catch (Exception ex)
                    {
                        error = true;
                        message.Append("GUID Error: ");
                        message.Append(ex.Message);
                        message.Append("<br/>");
                    }
                    if (!(txtOutPasskey.Text != null && txtOutPasskey.Text.Length > 0))
                    {
                        error = true;
                        message.Append(" You must enter a default passkey<br/>");
                    }
                    if (!(txtCodebaseUrl.Text != null && txtCodebaseUrl.Text.Length > 0))
                    {
                        error = true;
                        message.Append(" You must enter the base URL for the Web Site<br/>");
                    }
                    else if (txtCodebaseUrl.Text.Contains("localhost"))
                    {
                        error = true;
                        message.Append(" You must not use localhost in a codebase URL, if you must test on the local machine please use '127.0.0.1'.<br/>");
                    }
                    if (!(txtServiceUrl.Text != null && txtServiceUrl.Text.Length > 0))
                    {
                        error = true;
                        message.Append(" You must enter the web Ssrvice URL for the Web Site<br/>");
                    }
                    else if (txtServiceUrl.Text.Contains("localhost"))
                    {
                        error = true;
                        message.Append(" You must not use localhost in a web service URL, if you must test only on the local machine please use '127.0.0.1'.<br/>");
                    }
                    else
                    { // Test for valid webService URL
                        ProcessAgentProxy paProxy = new ProcessAgentProxy();
                        paProxy.Url = txtServiceUrl.Text.Trim();
                        try
                        {
                            DateTime serTime = paProxy.GetServiceTime();
                        }
                        catch
                        {
                                error = true;
                                message.Append(" There is an error with the web service URL: " + txtServiceUrl.Text.Trim() + " Please check that it is valid and the web service is configured correctly.<br/>");
                        }
                    }
                    if (error)
                    {
                        lblResponse.Text = Utilities.FormatErrorMessage(message.ToString());
                        lblResponse.Visible = true;
                        return;
                    }
                    if (ProcessAgentDB.ServiceAgent.domainGuid != null)
                    {
                        ProcessAgentInfo originalAgent = dbTicketing.GetProcessAgentInfo(originalGuid);
                        ProcessAgentInfo sb = dbTicketing.GetProcessAgentInfo(ProcessAgentDB.ServiceAgent.domainGuid);
                        if ((sb != null) && !sb.retired)
                        {
                            ProcessAgentProxy psProxy = new ProcessAgentProxy();
                            AgentAuthHeader header = new AgentAuthHeader();
                            header.agentGuid = ProcessAgentDB.ServiceAgent.agentGuid;
                            header.coupon = sb.identOut;
                            psProxy.AgentAuthHeaderValue = header;
                            psProxy.Url = sb.webServiceUrl;
                            ProcessAgent pa = new ProcessAgent();
                            pa.agentGuid = txtServiceGuid.Text;
                            pa.agentName = txtServiceName.Text;
                            pa.domainGuid = ProcessAgentDB.ServiceAgent.domainGuid;
                            pa.codeBaseUrl = txtCodebaseUrl.Text;
                            pa.webServiceUrl = txtServiceUrl.Text;
                            pa.type = AgentType;
                            //dbTicketing.SelfRegisterProcessAgent(pa.agentGuid, pa.agentName, agentType,
                            //    pa.domainGuid, pa.codeBaseUrl, pa.webServiceUrl);
                            //message.Append("Local information has been saved. ");
                            int returnValue = psProxy.ModifyProcessAgent(originalGuid, pa, null);
                            message.Append("The changes have been sent to the ServiceBroker");
                            if (returnValue > 0)
                            {
                                dbTicketing.SelfRegisterProcessAgent(pa.agentGuid, pa.agentName, AgentType,
                                pa.domainGuid, pa.codeBaseUrl, pa.webServiceUrl);

                                message.Append(".<br />Local information has been saved. ");
                                lblResponse.Text = Utilities.FormatConfirmationMessage(message.ToString());
                                lblResponse.Visible = true;

                            }
                            else
                            {
                                message.Append(", but did not process correctly!");
                                message.Append("<br />Local information has not been saved. ");
                                lblResponse.Text = Utilities.FormatErrorMessage(message.ToString());
                                lblResponse.Visible = true;
                            }
                        }
                    }
                    else
                    {
                        string tmpGuid = null;
                        if (AgentType == ProcessAgentType.SERVICE_BROKER)
                        {
                            tmpGuid = ProcessAgentDB.ServiceAgent.agentGuid;
                            AuthorityUpdateSelf(txtServiceName.Text,ProcessAgentDB.ServiceAgent.agentGuid,
                                 txtCodebaseUrl.Text.Trim(), txtDescription.Text, txtContactInfo.Text,
                                 txtBugEmail.Text, txtLocation.Text);
                        }
                        dbTicketing.SelfRegisterProcessAgent(ProcessAgentDB.ServiceAgent.agentGuid, txtServiceName.Text, AgentType,
                                tmpGuid, txtCodebaseUrl.Text.Trim(), txtServiceUrl.Text.Trim());
                        dbTicketing.SaveSystemSupport(ProcessAgentDB.ServiceAgent.agentGuid, txtContactInfo.Text, txtBugEmail.Text,
                           txtInfoUrl.Text, txtDescription.Text, txtLocation.Text);
                    }
                    ProcessAgentDB.RefreshServiceAgent();
                //    if (txtOutPasskey.Text.CompareTo(ConfigurationManager.AppSettings["defaultPasskey"]) != 0)
                //    {
                //        ConfigurationManager.AppSettings.Set("defaultPasskey", txtOutPasskey.Text);
                //    }
                }
            }
            catch (Exception ex)
            {
                Exception ex2 = new Exception("Error in  selfRegistration.modify()", ex);
               Logger.WriteLine(Utilities.DumpException(ex2));
                throw ex2;
            }
        }
示例#8
0
        protected void modifyService(object sender, System.EventArgs e)
        {
            bool error = false;
            StringBuilder message = new StringBuilder();
            try
            {
                if (ProcessAgentDB.ServiceAgent != null)
                {
                    string originalGuid = ProcessAgentDB.ServiceAgent.agentGuid;
                    if (!(txtServiceName.Text != null && txtServiceName.Text.Trim().Length > 0))
                    {
                        error = true;
                        message.Append(" You must enter a Service Name<br/>");
                    }

                    if (!(txtCodebaseUrl.Text != null && txtCodebaseUrl.Text.Trim().Length > 0))
                    {
                        error = true;
                        message.Append(" You must enter the base URL for the Web Site<br/>");
                    }
                    if (!(txtWebServiceUrl.Text != null && txtWebServiceUrl.Text.Trim().Length > 0))
                    {
                        error = true;
                        message.Append(" You must enter full URL of the Web Service page<br/>");
                    }
                    if (error)
                    {
                        lblResponse.Text = Utilities.FormatErrorMessage(message.ToString());
                        lblResponse.Visible = true;
                        return;
                    }
                    if ((txtServiceName.Text.Trim().CompareTo(bakServiceName.Value) == 0)
                        && (txtCodebaseUrl.Text.Trim().CompareTo(bakCodebase.Value) == 0)
                        && (txtWebServiceUrl.Text.Trim().CompareTo(bakServiceUrl.Value) == 0))
                    {
                        lblResponse.Text = Utilities.FormatWarningMessage("No user editable fields have been changed, modify aborted!");
                        lblResponse.Visible = true;
                        return;
                    }
                    if (ProcessAgentDB.ServiceAgent.domainGuid != null)
                    {
                        ProcessAgentInfo originalAgent = dbTicketing.GetProcessAgentInfo(originalGuid);
                        ProcessAgentInfo sb = dbTicketing.GetProcessAgentInfo(ProcessAgentDB.ServiceAgent.domainGuid);
                        if ((sb != null) && !sb.retired)
                        {
                            ProcessAgentProxy psProxy = new ProcessAgentProxy();
                            AgentAuthHeader header = new AgentAuthHeader();
                            header.agentGuid = ProcessAgentDB.ServiceAgent.agentGuid;
                            header.coupon = sb.identOut;
                            psProxy.AgentAuthHeaderValue = header;
                            psProxy.Url = sb.webServiceUrl;
                            ProcessAgent pa = new ProcessAgent();
                            pa.agentGuid = txtServiceGUID.Text.Trim();
                            pa.agentName = txtServiceName.Text.Trim();
                            pa.domainGuid = ProcessAgentDB.ServiceAgent.domainGuid;
                            pa.codeBaseUrl = txtCodebaseUrl.Text.Trim();
                            pa.webServiceUrl = txtWebServiceUrl.Text.Trim();
                            pa.type = agentType;
                            //dbTicketing.SelfRegisterProcessAgent(pa.agentGuid, pa.agentName, agentType,
                            //    pa.domainGuid, pa.codeBaseUrl, pa.webServiceUrl);
                            //message.Append("Local information has been saved. ");
                            int returnValue = psProxy.ModifyProcessAgent(originalGuid, pa, null);
                            message.Append("The changes have been sent to the ServiceBroker");
                            if (returnValue > 0)
                            {
                                dbTicketing.SelfRegisterProcessAgent(pa.agentGuid, pa.agentName, agentType,
                                pa.domainGuid, pa.codeBaseUrl, pa.webServiceUrl);
                                bakServiceName.Value = pa.agentName;
                                bakCodebase.Value = pa.codeBaseUrl;
                                bakServiceUrl.Value = pa.webServiceUrl;
                                message.Append(".<br />Local information has been saved. ");
                                lblResponse.Text = Utilities.FormatConfirmationMessage(message.ToString());
                                lblResponse.Visible = true;

                            }
                            else
                            {
                                message.Append(", but did not process correctly!");
                                message.Append("<br />Local information has not been saved. ");
                                lblResponse.Text = Utilities.FormatErrorMessage(message.ToString());
                                lblResponse.Visible = true;
                            }
                        }
                    }
                    else
                    {
                        dbTicketing.SelfRegisterProcessAgent(ProcessAgentDB.ServiceAgent.agentGuid, txtServiceName.Text, agentType,
                                null, txtCodebaseUrl.Text, txtWebServiceUrl.Text);
                    }
                }
            }
            catch (Exception ex)
            {
                Exception ex2 = new Exception("Error in  selfRegistration.modify()",ex);
                Utilities.WriteLog(Utilities.DumpException(ex2));
                throw ex2;
            }
        }
        public Ticket RedeemTicket(Coupon coupon, string type, string redeemerGuid)
        {
            Ticket ticket = null;
            if (brokerDB.AuthenticateAgentHeader(agentAuthHeader))
            {
                if (coupon.issuerGuid == ProcessAgentDB.ServiceGuid)
                {
                    ticket = brokerDB.RetrieveIssuedTicket(coupon, type, redeemerGuid);
                }
                else
                {
                    ProcessAgentInfo paInfo = brokerDB.GetProcessAgentInfo(coupon.issuerGuid);
                    if (paInfo != null)
                    {
                        if (paInfo.retired)
                        {
                            throw new Exception("The ProcessAgent is retired");
                        }
                        TicketIssuerProxy ticketProxy = new TicketIssuerProxy();
                        AgentAuthHeader authHeader = new AgentAuthHeader();
                        authHeader.coupon = paInfo.identOut;
                        authHeader.agentGuid = ProcessAgentDB.ServiceGuid;
                        ticketProxy.AgentAuthHeaderValue = authHeader;
                        ticketProxy.Url = paInfo.webServiceUrl;
                        ticket = ticketProxy.RedeemTicket(coupon, type, redeemerGuid);
                    }
                    else
                    {
                        throw new Exception("Unknown TicketIssuerDB in RedeemTicket Request");
                    }
                }

            }
            return ticket;
        }
        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 StorageStatus AgentCloseExperiment(Coupon coupon, long experimentId)
        {
            StorageStatus status = null;
            bool experimentClosed = false;

            if (brokerDB.AuthenticateAgentHeader(agentAuthHeader))
            {
                if (coupon.issuerGuid == ProcessAgentDB.ServiceGuid)
                {

                    // Check for ESS use
                    Ticket essTicket = brokerDB.RetrieveTicket(coupon, TicketTypes.ADMINISTER_EXPERIMENT);
                    if (essTicket != null)
                    {
                        ProcessAgentInfo ess = brokerDB.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.AgentAuthHeaderValue.agentGuid = ProcessAgentDB.ServiceGuid;
                            essProxy.Url = ess.webServiceUrl;
                            status = essProxy.CloseExperiment(experimentId);
                            DataStorageAPI.UpdateExperimentStatus(status);
                        }
                        brokerDB.CancelIssuedTicket(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);
                    }

                }
                else
                {
                    ProcessAgentInfo paInfo = brokerDB.GetProcessAgentInfo(coupon.issuerGuid);
                    if (paInfo != null)
                    {
                        if (paInfo.retired)
                        {
                            throw new Exception("The ProcessAgent is retired");
                        }
                        InteractiveSBProxy ticketProxy = new InteractiveSBProxy();
                        AgentAuthHeader authHeader = new AgentAuthHeader();
                        authHeader.coupon = paInfo.identOut;
                        authHeader.agentGuid = ProcessAgentDB.ServiceGuid;
                        ticketProxy.AgentAuthHeaderValue = authHeader;
                        ticketProxy.Url = paInfo.webServiceUrl;
                        status = ticketProxy.AgentCloseExperiment(coupon, experimentId);
                    }
                    else
                    {
                        throw new Exception("Unknown TicketIssuerDB in RedeemTicket Request");
                    }
                }

            }
            return status;
        }
        public bool RevokeReservation(string serviceBrokerGuid, string userName, string groupName, string labServerGuid, string labClientGuid,
            DateTime startTime, DateTime endTime, string message)
        {
            bool status = false;
            int authID = -1;
            if(serviceBrokerGuid.CompareTo(ProcessAgentDB.ServiceGuid) == 0){
                authID = 0;
            }
            else{
            Authority auth = brokerDB.AuthorityRetrieve(serviceBrokerGuid);
            if (auth != null)
            {
                authID = auth.authorityID;
            }
            }

            if (brokerDB.AuthenticateAgentHeader(agentAuthHeader))
            {
                if (agentAuthHeader.coupon.issuerGuid == ProcessAgentDB.ServiceGuid)
                {

                    try
                    {
                        int userId = AdministrativeAPI.GetUserID(userName,authID);
                        if (userId > 0)
                        {
                            User[] users = AdministrativeAPI.GetUsers(new int[] { userId });
                            if (users != null && users.Length > 0)
                            {
                                if (users[0] != null && users[0].email != null)
                                {
                                    SmtpMail.SmtpServer = "127.0.0.1";
                                    MailMessage uMail = new MailMessage();
                                    uMail.To = users[0].email;
                                    uMail.From = ConfigurationManager.AppSettings["supportMailAddress"];
                                    uMail.Subject = "[iLabs] A Reservation has been revoked!";
                                    StringBuilder buf = new StringBuilder();
                                    buf.Append("Your scheduled reservation for ");
                                    buf.Append(AdministrativeAPI.GetLabClientName(AdministrativeAPI.GetLabClientID(labClientGuid)));
                                    buf.Append(", from " + DateUtil.ToUtcString(startTime) + " to " + DateUtil.ToUtcString(endTime));
                                    buf.AppendLine(" has been removed by an external service for the following reason: ");
                                    buf.AppendLine(message);
                                    buf.AppendLine("Please make a new reservation.");

                                    uMail.Body = buf.ToString(); ;
                                    SmtpMail.Send(uMail);
                                }
                            }
                        }

                    }
                    catch (Exception ex)
                    {
                        // Report detailed SMTP Errors
                        StringBuilder smtpErrorMsg = new StringBuilder();
                        smtpErrorMsg.Append("Exception: SMTP in InterativeSB:" + 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;
                        }
                       Logger.WriteLine(smtpErrorMsg.ToString());

                    }
                    status = true;
                }
            }
            else
            {
                ProcessAgentInfo paInfo = brokerDB.GetProcessAgentInfo(agentAuthHeader.coupon.issuerGuid);
                if (paInfo != null)
                {
                    if (paInfo.retired)
                    {
                        throw new Exception("The ProcessAgent is retired");
                    }
                    InteractiveSBProxy proxy = new InteractiveSBProxy();
                    AgentAuthHeader authHeader = new AgentAuthHeader();
                    authHeader.coupon = paInfo.identOut;
                    authHeader.agentGuid = ProcessAgentDB.ServiceGuid;
                    proxy.AgentAuthHeaderValue = authHeader;
                    proxy.Url = paInfo.webServiceUrl;
                    status = proxy.RevokeReservation(serviceBrokerGuid, userName, groupName, labServerGuid, labClientGuid,
                        startTime, endTime, message);
                }
                else
                {
                    throw new Exception("Unknown TicketIssuerDB in RedeemTicket Request");
                }
            }
            return status;
        }
        public int RevokeReservation(string serviceBrokerGuid, string groupName,
            string labServerGuid, string labClientGuid, DateTime startTime, DateTime endTime, string message)
        {
            bool status = false;
            bool fromISB = false;
            int count = 0;
            Coupon opCoupon = new Coupon();
            opCoupon.couponId = opHeader.coupon.couponId;
            opCoupon.passkey = opHeader.coupon.passkey;
            opCoupon.issuerGuid = opHeader.coupon.issuerGuid;
            UserSchedulingDB dbManager = new UserSchedulingDB();
            try
            {
                Ticket retrievedTicket = dbManager.RetrieveAndVerify(opCoupon, TicketTypes.REVOKE_RESERVATION);
                if (retrievedTicket.payload != null && retrievedTicket.payload.Length > 0)
                {
                    XmlQueryDoc revokeDoc = new XmlQueryDoc(retrievedTicket.payload);
                    string sourceStr = revokeDoc.Query("RevokeReservationPayload/source");
                    if (sourceStr != null && sourceStr.CompareTo("ISB") == 0)
                    {
                        fromISB = true;
                    }
                }
                DateTime targetStart = new DateTime(startTime.Year, startTime.Month, startTime.Day,
                    startTime.Hour, startTime.Minute, 0, startTime.Kind);
                if (targetStart.Kind != DateTimeKind.Utc)
                    targetStart = targetStart.ToUniversalTime();
                DateTime targetEnd = new DateTime(endTime.Year, endTime.Month, endTime.Day,
                    endTime.Hour, endTime.Minute, 0, endTime.Kind);
                if (targetEnd.Kind != DateTimeKind.Utc)
                    targetEnd = targetEnd.ToUniversalTime();
                if (fromISB)
                { // Need to forward to LSS
                    string lssUrl = dbManager.ListLssUrlByExperiment(labClientGuid, labServerGuid);
                    if (lssUrl != null && lssUrl.Length > 0)
                    {
                        LabSchedulingProxy lssProxy = new LabSchedulingProxy();
                        lssProxy.OperationAuthHeaderValue = new OperationAuthHeader();
                        lssProxy.OperationAuthHeaderValue.coupon = opCoupon;
                        lssProxy.Url = lssUrl;
                        int rCount = lssProxy.RemoveReservation(serviceBrokerGuid, groupName, ProcessAgentDB.ServiceGuid,
                            labServerGuid, labClientGuid, targetStart, targetEnd);
                    }
                }

                ReservationData[] ris = dbManager.GetReservations(serviceBrokerGuid, null, groupName,
                    labServerGuid, labClientGuid, targetStart, targetEnd);

                if (ris != null && ris.Length > 0)
                {

                    InteractiveSBProxy sbProxy = new InteractiveSBProxy();
                    ProcessAgentInfo sbInfo = dbManager.GetProcessAgentInfo(ProcessAgentDB.ServiceAgent.domainGuid);
                    AgentAuthHeader header = new AgentAuthHeader();
                    header.coupon = sbInfo.identOut;
                    header.agentGuid = ProcessAgentDB.ServiceGuid;
                    sbProxy.AgentAuthHeaderValue = header;
                    sbProxy.Url = sbInfo.webServiceUrl;
                    foreach (ReservationData rd in ris)
                    {

                        status = dbManager.RevokeReservation(rd.sbGuid, rd.groupName, rd.lsGuid, rd.clientGuid,
                              rd.startTime, rd.endTime, message);
                        if (status)
                        {
                            count++;
                            status = sbProxy.RevokeReservation(rd.sbGuid, rd.userName, rd.groupName, rd.lsGuid, rd.clientGuid,
                              rd.startTime, rd.endTime, message);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                throw new Exception("USS: RevokeReservation -> ",e);
            }
            return count;
        }
示例#14
0
        public int RevokeReservation(string serviceBrokerGuid, string groupName,
            string labServerGuid, string labClientGuid, DateTime startTime, DateTime endTime, string message)
        {
            bool status = false;
            int count = 0;
            Coupon opCoupon = new Coupon();
            opCoupon.couponId = opHeader.coupon.couponId;
            opCoupon.passkey = opHeader.coupon.passkey;
            opCoupon.issuerGuid = opHeader.coupon.issuerGuid;
            string type = TicketTypes.REVOKE_RESERVATION;
            try
            {
                Ticket retrievedTicket = dbTicketing.RetrieveAndVerify(opCoupon, type);
                ReservationInfo[]ri = USSSchedulingAPI.GetReservations(serviceBrokerGuid, null, groupName,
                    labServerGuid, labClientGuid, startTime, endTime);
                if (ri != null && ri.Length > 0)
                {

                    InteractiveSBProxy sbProxy = new InteractiveSBProxy();
                    ProcessAgentInfo sbInfo = dbTicketing.GetProcessAgentInfo(ProcessAgentDB.ServiceAgent.domainGuid);
                    AgentAuthHeader header = new AgentAuthHeader();
                    header.coupon = sbInfo.identOut;
                    header.agentGuid = ProcessAgentDB.ServiceGuid;
                    sbProxy.AgentAuthHeaderValue = header;
                    sbProxy.Url = sbInfo.webServiceUrl;
                    status = sbProxy.RevokeReservation(serviceBrokerGuid, ri[0].userName, groupName, labServerGuid,
                        labClientGuid, startTime, endTime, message);
                    if (status)
                    {
                        count++;
                        USSSchedulingAPI.RevokeReservation(serviceBrokerGuid, groupName, labServerGuid, labClientGuid,
                              startTime, endTime, message);
                    }
                }
            }
            catch (Exception e)
            {
                throw new Exception("USS: RevokeReservation -> ",e);
            }
            return count;
        }
        public bool RequestTicketCancellation(Coupon coupon,
            string type, string redeemerGuid)
        {
            TicketIssuerDB ticketIssuer = new TicketIssuerDB();
            bool status = false;
            if (ticketIssuer.AuthenticateAgentHeader(agentAuthHeader))
            {
                if (coupon.issuerGuid == ProcessAgentDB.ServiceGuid)
                {
                    return ticketIssuer.RequestTicketCancellation(coupon,
                        type, redeemerGuid);
                }
                else
                {
                    ProcessAgentInfo paInfo = ticketIssuer.GetProcessAgentInfo(coupon.issuerGuid);
                    if (paInfo != null)
                    {
                        if (paInfo.retired)
                        {
                            throw new Exception("The ProcessAgent is retired");
                        }
                        TicketIssuerProxy ticketProxy = new TicketIssuerProxy();
                        AgentAuthHeader authHeader = new AgentAuthHeader();
                        authHeader.coupon = paInfo.identOut;
                        authHeader.agentGuid = ProcessAgentDB.ServiceGuid;
                        ticketProxy.AgentAuthHeaderValue = authHeader;
                        ticketProxy.Url = paInfo.webServiceUrl;
                        status = ticketProxy.RequestTicketCancellation(coupon, type, redeemerGuid);
                    }
                    else
                    {
                        throw new Exception("Unknown TicketIssuerDB in RedeemTicket Request");
                    }
                }
            }

            return status;
        }