Пример #1
0
        public ResourceMapping AddResourceMapping(ResourceMappingKey key, ResourceMappingValue[] values)
        {
            string[] valueTypes = new string[values.Length];
            object[] valueObjs = new object[values.Length];

            for (int i = 0; i < valueTypes.Length; i++)
            {
                valueTypes[i] = values[i].type;
                valueObjs[i] = values[i].entry;
            }

            return AddResourceMapping(key.type, key.entry, valueTypes, valueObjs);
        }
Пример #2
0
        // Error recovery must be added to this method
        protected void btnSaveChange_Click(object sender, EventArgs e)
        {
            int id = int.Parse(ddlLabClient.SelectedValue);
            if (id > 0)
            {
                LabClient[] clients = wrapper.GetLabClientsWrapper(new int[] { id });
                if (clients.Length > 0 && clients[0].clientID > 0)
                {
                    theClient = clients[0];
                }
            }
            // objects used in try block may be required for recovery if  errors
            bool noError = true;
            ProcessAgentInfo labServer = null;
            ProcessAgentInfo uss = null;
            ProcessAgentInfo lss = null;
            long rmUss = 0;

            lblResponse.Visible = false;
            lblResponse.Text = "";
            try
            {
                if (ddlUserGroup.SelectedIndex <= 0)
                {
                    lblResponse.Visible = true;
                    lblResponse.Text = Utilities.FormatWarningMessage("Please select a user group from the corresponding drop-down list.");
                    return;
                }
                int groupID = Convert.ToInt32(ddlUserGroup.SelectedValue);
                if (groupID <= 0)
                {
                    lblResponse.Visible = true;
                    lblResponse.Text = Utilities.FormatWarningMessage("The user group is invalid.");
                    return;
                }
                //Get the user Group Name to be displayed in the repeater
                Group[] userGroup = wrapper.GetGroupsWrapper(new int[] { groupID });
                string userGroupName = userGroup[0].GroupName;

                if (theClient.labServerIDs != null && theClient.labServerIDs.Length > 0)
                {
                    labServer = issuer.GetProcessAgentInfo(theClient.labServerIDs[0]);
                }
                if (labServer == null)
                {
                    lblResponse.Visible = true;
                    lblResponse.Text = Utilities.FormatWarningMessage("Lab Client should first be associated with a Lab Server");
                    return;
                }

                if (theClient.needsScheduling)
                {
                    if (ddlAdminGroup.SelectedIndex <= 0 || ddlUserGroup.SelectedIndex <= 0)
                    {
                        lblResponse.Visible = true;
                        lblResponse.Text = Utilities.FormatWarningMessage("Please select a user and management group from the corresponding drop-down lists.");
                        return;
                    }
                    int manageID = Convert.ToInt32(ddlAdminGroup.SelectedValue);
                    if (manageID <= 0)
                    {
                        lblResponse.Visible = true;
                        lblResponse.Text = Utilities.FormatWarningMessage("The management group is invalid.");
                        return;
                    }

                    int ussId = issuer.FindProcessAgentIdForClient(theClient.clientID, ProcessAgentType.SCHEDULING_SERVER);
                    if (ussId <= 0)
                    {
                        lblResponse.Visible = true;
                        lblResponse.Text = Utilities.FormatWarningMessage("Lab Client should first be associated with a USS");
                        return;
                    }
                    int lssId = issuer.FindProcessAgentIdForAgent(theClient.labServerIDs[0], ProcessAgentType.LAB_SCHEDULING_SERVER);
                    if (lssId <= 0)
                    {
                        lblResponse.Visible = true;
                        lblResponse.Text = Utilities.FormatWarningMessage("Lab Server should first be associated with an LSS");
                        return;
                    }

                    else
                    {

                        uss = issuer.GetProcessAgentInfo(ussId);
                        if (uss.retired)
                        {
                            throw new Exception("The USS is retired");
                        }
                        lss = issuer.GetProcessAgentInfo(lssId);
                        if (lss.retired)
                        {
                            throw new Exception("The LSS is retired");
                        }

                        //Object keyObj = groupID;
                        //string keyType = ResourceMappingTypes.GROUP;
                        ResourceMappingKey key = new ResourceMappingKey(ResourceMappingTypes.GROUP, groupID);
                        ResourceMappingValue[] values = new ResourceMappingValue[3];
                        values[0] = new ResourceMappingValue(ResourceMappingTypes.CLIENT, theClient.clientID);
                        values[1] = new ResourceMappingValue(ResourceMappingTypes.TICKET_TYPE,
                            TicketTypes.GetTicketType(TicketTypes.MANAGE_USS_GROUP));
                        values[2] = new ResourceMappingValue(ResourceMappingTypes.GROUP,manageID);

                        //values[0] = new ResourceMappingValue(ResourceMappingTypes.RESOURCE_TYPE, ProcessAgentType.SCHEDULING_SERVER);
                        //values[1] = new ResourceMappingValue(ResourceMappingTypes.PROCESS_AGENT, ussId);

                        ResourceMapping newMapping = issuer.AddResourceMapping(key, values);
                        rmUss = newMapping.MappingID;

                        // add mapping to qualifier list
                        int qualifierType = Qualifier.resourceMappingQualifierTypeID;
                        string name = issuer.ResourceMappingToString(newMapping);
                        int qualifierID = AuthorizationAPI.AddQualifier(newMapping.MappingID, qualifierType, name, Qualifier.ROOT);

                        //Give the Manager Group a Grant "MANAGE_USS_GROUP" on the created resource mapping
                        string function = Function.manageUSSGroup;
                        int grantID = wrapper.AddGrantWrapper(manageID, function, qualifierID);

                        //Get the management Group Name to be displayed in the repeater
                        Group[] adminGroup = wrapper.GetGroupsWrapper(new int[] { manageID });
                        string adminGroupName = adminGroup[0].GroupName;

                        //Create the Map between user and management group
                        GroupManagerUserMap groupMap = new GroupManagerUserMap(adminGroupName, userGroupName, grantID, newMapping.MappingID);

                        TicketLoadFactory factory = TicketLoadFactory.Instance();
                        //long duration = 60;
                        // Get this SB's domain Guid
                        string domainGuid = ProcessAgentDB.ServiceGuid;
                        string sbName = ProcessAgentDB.ServiceAgent.agentName;

                        //Add Credential set on the USS

                        //string ussPayload = factory.createAdministerUSSPayload(Convert.ToInt32(Session["userTZ"]));
                        //Coupon ussCoupon = issuer.CreateTicket(TicketTypes.ADMINISTER_USS, uss.agentGuid,
                        //    issuer.GetIssuerGuid(), duration, ussPayload);
                        UserSchedulingProxy ussProxy = new UserSchedulingProxy();
                        ussProxy.Url = uss.webServiceUrl;
                        ussProxy.AgentAuthHeaderValue = new AgentAuthHeader();
                        ussProxy.AgentAuthHeaderValue.coupon = uss.identOut;
                        ussProxy.AgentAuthHeaderValue.agentGuid = domainGuid;

                        ussProxy.AddCredentialSet(domainGuid, sbName, userGroupName);

                        // Check for existing RevokeReservation ticket redeemer = USS, sponsor = LSS
                        Coupon[] revokeCoupons = issuer.RetrieveIssuedTicketCoupon(
                            TicketTypes.REVOKE_RESERVATION, uss.agentGuid, lss.agentGuid);
                        Coupon revokeCoupon = null;
                        if (revokeCoupons != null && revokeCoupons.Length > 0)
                        {
                            revokeCoupon = revokeCoupons[0];
                        }
                        else
                        {
                            // Create RevokeReservation ticket
                            revokeCoupon = issuer.CreateTicket(TicketTypes.REVOKE_RESERVATION,
                                 uss.agentGuid, lss.agentGuid, -1L, factory.createRevokeReservationPayload());
                        }

                        //Add Credential set on the LSS

                        // check if this domain
                        if (ProcessAgentDB.ServiceGuid.Equals(lss.domainGuid))
                        {
                            LabSchedulingProxy lssProxy = new LabSchedulingProxy();
                            lssProxy.Url = lss.webServiceUrl;
                            lssProxy.AgentAuthHeaderValue = new AgentAuthHeader();
                            lssProxy.AgentAuthHeaderValue.coupon = lss.identOut;
                            lssProxy.AgentAuthHeaderValue.agentGuid = domainGuid;
                            // Add the USS to the LSS, this may be called multiple times with duplicate data
                            lssProxy.AddUSSInfo(uss.AgentGuid, uss.agentName, uss.webServiceUrl, revokeCoupon);
                            int credentialSetAdded = lssProxy.AddCredentialSet(domainGuid,
                                sbName, userGroupName, uss.agentGuid);
                        }
                        else
                        { // Cross-Domain Registration needed
                            ProcessAgentInfo remoteSB = issuer.GetProcessAgentInfo(lss.domainGuid);
                            if(remoteSB.retired){
                                throw new Exception("The remote service broker is retired");
                            }
                            ResourceDescriptorFactory resourceFactory = ResourceDescriptorFactory.Instance();
                            string ussDescriptor = resourceFactory.CreateProcessAgentDescriptor(ussId);
                            string lssDescriptor = resourceFactory.CreateProcessAgentDescriptor(lssId);
                            string groupDescriptor = resourceFactory.CreateGroupCredentialDescriptor(domainGuid, sbName, userGroupName, uss.agentGuid, lss.agentGuid);

                            ServiceDescription[] info = new ServiceDescription[3];
                            info[0] = new ServiceDescription(null, revokeCoupon, ussDescriptor);
                            info[1] = new ServiceDescription(null, null, lssDescriptor);
                            info[2] = new ServiceDescription(null, null, groupDescriptor);

                            ProcessAgentProxy sbProxy = new ProcessAgentProxy();
                            sbProxy.AgentAuthHeaderValue = new AgentAuthHeader();
                            sbProxy.AgentAuthHeaderValue.agentGuid = domainGuid;
                            sbProxy.AgentAuthHeaderValue.coupon = remoteSB.identOut;
                            sbProxy.Url = remoteSB.webServiceUrl;
                            sbProxy.Register(Utilities.MakeGuid(), info);
                        }
                    }
                }

                /*Update Lab Client grants*/

                //Get qualifier for labclient
                int lcQualifierID = AuthorizationAPI.GetQualifierID(theClient.clientID, Qualifier.labClientQualifierTypeID);
                //Get all "uselabclient" grants for this labclient
                int[] lcGrantIDs = wrapper.FindGrantsWrapper(-1, Function.useLabClientFunctionType, lcQualifierID);
                Grant[] lcGrants = wrapper.GetGrantsWrapper(lcGrantIDs);
                //Get list of agents that can use labclient
                ArrayList lcAgents = new ArrayList();
                foreach (Grant g in lcGrants)
                    lcAgents.Add(g.agentID);

                //if that agent doesn't already have the uselabclient permission
                if (!lcAgents.Contains(groupID))
                    //add lab client grant
                    wrapper.AddGrantWrapper(groupID, Function.useLabClientFunctionType, lcQualifierID);

                /*Update Lab Servers grant*/

                //Update grants for each of the associated lab servers
                foreach (int lsID in theClient.labServerIDs)
                {
                    //Get qualifier for labserver
                    int lsQualifierID = AuthorizationAPI.GetQualifierID(lsID, Qualifier.labServerQualifierTypeID);
                    //Get all "uselabserver" grants for this labserver
                    int[] lsGrantIDs = wrapper.FindGrantsWrapper(-1, Function.useLabServerFunctionType, lsQualifierID);
                    Grant[] lsGrants = wrapper.GetGrantsWrapper(lsGrantIDs);
                    //Get list of agents that can use labserver
                    ArrayList lsAgents = new ArrayList();
                    foreach (Grant g in lsGrants)
                        lsAgents.Add(g.agentID);

                    //int groupID = Convert.ToInt32(ddlUserGroup.SelectedValue);

                    //if that agent doesn't already have the uselabclient permission
                    if (!lsAgents.Contains(groupID))
                        //add lab server grant
                        wrapper.AddGrantWrapper(groupID, Function.useLabServerFunctionType, lsQualifierID);
                }

                //Refresh the repeater
                RefreshAdminUserGroupsRepeater();
                LoadListBoxes();

                lblResponse.Visible = true;
                lblResponse.Text = Utilities.FormatConfirmationMessage("Lab client (& corresponding lab servers) successfully updated. ");
            }
            catch (Exception ex)
            {
                lblResponse.Visible = true;
                lblResponse.Text = Utilities.FormatErrorMessage("Cannot update Lab Client. " + ex.GetBaseException());
            }
        }
Пример #3
0
        private int CheckAssociatedLSSForLS(int lsId)
        {
            int lssId = 0;
            ddlLSS.ClearSelection();
            ddlLSS.SelectedIndex = 0;
            ddlLSS.BackColor = enabled;
            ddlLSS.Enabled = true;
            ddlManageLSS.ClearSelection();
            ddlManageLSS.SelectedIndex = 0;
            ddlManageLSS.BackColor = enabled;
            ddlManageLSS.Enabled = true;
            ResourceMappingValue[] values = new ResourceMappingValue[2];
            values[0] = new ResourceMappingValue(ResourceMappingTypes.RESOURCE_TYPE, ProcessAgentType.LAB_SCHEDULING_SERVER);
            values[1] = new ResourceMappingValue(ResourceMappingTypes.TICKET_TYPE,
                TicketTypes.GetTicketType(TicketTypes.MANAGE_LAB));

            List<ResourceMapping> maps = ResourceMapManager.Find(new ResourceMappingKey(ResourceMappingTypes.PROCESS_AGENT, lsId), values);
            if (maps != null && maps.Count > 0)
            {
                foreach (ResourceMapping rm in maps)
                {
                    for (int i = 0; i < rm.values.Length; i++)
                    {
                        if (rm.values[i].Type == ResourceMappingTypes.PROCESS_AGENT)
                        {
                            lssId = (int)rm.values[i].Entry;
                            ddlLSS.ClearSelection();
                            ddlLSS.SelectedValue = lssId.ToString();
                            ddlLSS.Enabled = false;
                            ddlLSS.BackColor = disabled;
                            btnAssociateLSS.Text = "Disassociate";
                            btnAssociateLSS.CommandName = "disassociate";
                            Session["LS_LSSmapID"] = rm.MappingID;

                            // Find any manageLab grants
                            int qualID = AuthorizationAPI.GetQualifierID(rm.MappingID, Qualifier.resourceMappingQualifierTypeID);
                            Grant[] grants = AuthorizationAPI.GetGrants(AuthorizationAPI.FindGrants(-1, Function.manageLAB, qualID));
                            foreach (Grant g in grants)
                            {
                                if (ddlManageLSS.Items.FindByValue(g.agentID.ToString()) != null)
                                {
                                    ddlManageLSS.ClearSelection();
                                    ddlManageLSS.Items.FindByValue(g.agentID.ToString()).Selected = true;
                                    ddlManageLSS.Enabled = false;
                                    ddlManageLSS.BackColor = disabled;
                                    break;
                                }

                            }
                            break;
                        }
                    }
                }
            }

            else
            {
                ddlLSS.Enabled = true;
                ddlLSS.SelectedIndex = 0;
                ddlLSS.BackColor = enabled;
                Session.Remove("LS_LSSmapID");
                btnAssociateLSS.Text = "Associate";
                btnAssociateLSS.CommandName = "associate";
                ddlManageLSS.Enabled = true;
            }

            return lssId;
        }
        /// <summary>
        /// Add new resource mapping to the database 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnAddResource_Click(object sender, EventArgs e)
        {
            // check that a key type is selected
            if (keyTypeDropdown.SelectedIndex == 0)
            {
                // Show Error Message
                string jScript = "<script language='javascript'>" +
                    "alert('Please select a key type')" + "</script>";
                Page.RegisterStartupScript("Error Window", jScript);
                return;
            }

            // if a value is selected but not added to the list of values, add it
            if (valueTypeDropdown.SelectedValue.Equals(ResourceMappingTypes.PROCESS_AGENT) && value_ProcessAgentDropdown.SelectedIndex != 0 ||
                valueTypeDropdown.SelectedValue.Equals(ResourceMappingTypes.CLIENT) && value_ClientDropdown.SelectedIndex != 0 ||
                valueTypeDropdown.SelectedValue.Equals(ResourceMappingTypes.TICKET_TYPE) && value_TicketTypeDropdown.SelectedIndex != 0 ||
                valueTypeDropdown.SelectedValue.Equals(ResourceMappingTypes.RESOURCE_MAPPING) && value_MappingDropdown.SelectedIndex != 0 ||
                valueTypeDropdown.SelectedValue.Equals(ResourceMappingTypes.GROUP) && value_GroupDropdown.SelectedIndex != 0 ||
                valueTypeDropdown.SelectedValue.Equals(ResourceMappingTypes.STRING) && !value_StringText.Text.Equals("") && value_StringText.Text != null ||
                valueTypeDropdown.SelectedValue.Equals(ResourceMappingTypes.RESOURCE_TYPE) && !value_ResourceTypeText.Text.Equals("") && value_ResourceTypeText.Text != null)
            {

                // create a new Resource Mapping Value
                string selectedValueType = valueTypeDropdown.SelectedValue;
                Object valueObj = null;
                if (selectedValueType.Equals(ResourceMappingTypes.PROCESS_AGENT))
                {
                    if (value_ProcessAgentDropdown.SelectedIndex == 0)
                    {
                        // Show Error Message
                        string jScript = "<script language='javascript'>" +
                            "alert('Please select a process agent')" + "</script>";
                        Page.RegisterStartupScript("Error Window", jScript);
                        return;
                    }
                    valueObj = int.Parse(value_ProcessAgentDropdown.SelectedValue);
                }
                else if (selectedValueType.Equals(ResourceMappingTypes.CLIENT))
                {
                    if (value_ClientDropdown.SelectedIndex == 0)
                    {
                        // Show Error Message
                        string jScript = "<script language='javascript'>" +
                            "alert('Please select a client')" + "</script>";
                        Page.RegisterStartupScript("Error Window", jScript);
                        return;
                    }
                    valueObj = int.Parse(value_ClientDropdown.SelectedValue);
                }
                else if (selectedValueType.Equals(ResourceMappingTypes.RESOURCE_MAPPING))
                {
                    if (value_MappingDropdown.SelectedIndex == 0)
                    {
                        // Show Error Message
                        string jScript = "<script language='javascript'>" +
                            "alert('Please select a Resource Mapping')" + "</script>";
                        Page.RegisterStartupScript("Error Window", jScript);
                        return;
                    }
                    valueObj = brokerDB.GetResourceMapping(int.Parse(value_MappingDropdown.SelectedValue));
                }
                else if (selectedValueType.Equals(ResourceMappingTypes.STRING))
                {
                    if (value_StringText.Text == null || value_StringText.Text.Equals(""))
                    {
                        // Show Error Message
                        string jScript = "<script language='javascript'>" +
                            "alert('Please enter a string value')" + "</script>";
                        Page.RegisterStartupScript("Error Window", jScript);
                        return;
                    }
                    valueObj = value_StringText.Text;
                }
                else if (selectedValueType.Equals(ResourceMappingTypes.TICKET_TYPE))
                {
                    if (value_TicketTypeDropdown.SelectedIndex == 0)
                    {
                        // Show Error Message
                        string jScript = "<script language='javascript'>" +
                            "alert('Please select a ticket type')" + "</script>";
                        Page.RegisterStartupScript("Error Window", jScript);
                        return;
                    }
                    valueObj = TicketTypes.GetTicketType(value_TicketTypeDropdown.SelectedValue);
                }
                else if (selectedValueType.Equals(ResourceMappingTypes.GROUP))
                {
                    if (value_GroupDropdown.SelectedIndex == 0)
                    {
                        // Show Error Message
                        string jScript = "<script language='javascript'>" +
                            "alert('Please select a group')" + "</script>";
                        Page.RegisterStartupScript("Error Window", jScript);
                        return;
                    }
                    valueObj = int.Parse(value_GroupDropdown.SelectedValue);
                }

                else if (selectedValueType.Equals(ResourceMappingTypes.RESOURCE_TYPE))
                {
                    if (value_ResourceTypeText.Text == null || value_ResourceTypeText.Text.Equals(""))
                    {
                        // Show Error Message
                        string jScript = "<script language='javascript'>" +
                            "alert('Please enter a string value')" + "</script>";
                        Page.RegisterStartupScript("Error Window", jScript);
                        return;
                    }
                    valueObj = value_ResourceTypeText.Text;
                }

                ResourceMappingValue value = new ResourceMappingValue(valueTypeDropdown.SelectedValue, valueObj);

                // add value to list of values and refresh the value repeater
                if (valuesList == null)
                    valuesList = new ArrayList();
                valuesList.Add(value);
            }

            if (valuesList.Count < 1)
            {
                // Show Error Message
                string jScript = "<script language='javascript'>" +
                    "alert('Please create a mapping value')" + "</script>";
                Page.RegisterStartupScript("Error Window", jScript);
                return;
            }

            // create key object
            string selectedKeyType = keyTypeDropdown.SelectedValue;
            Object keyObj = null;
            if (selectedKeyType.Equals(ResourceMappingTypes.PROCESS_AGENT))
            {
                if (key_ProcessAgentDropdown.SelectedIndex == 0)
                {
                    // Show Error Message
                    string jScript = "<script language='javascript'>" +
                        "alert('Please select a process agent')" + "</script>";
                    Page.RegisterStartupScript("Error Window", jScript);
                    return;
                }
                keyObj = int.Parse(key_ProcessAgentDropdown.SelectedValue);
            }
            else if (selectedKeyType.Equals(ResourceMappingTypes.CLIENT))
            {
                if (key_ClientDropdown.SelectedIndex == 0)
                {
                    // Show Error Message
                    string jScript = "<script language='javascript'>" +
                        "alert('Please select a client')" + "</script>";
                    Page.RegisterStartupScript("Error Window", jScript);
                    return;
                }
                keyObj = int.Parse(key_ClientDropdown.SelectedValue);
            }
            else if (selectedKeyType.Equals(ResourceMappingTypes.TICKET_TYPE))
            {
                if (key_TicketTypeDropdown.SelectedIndex == 0)
                {
                    // Show Error Message
                    string jScript = "<script language='javascript'>" +
                        "alert('Please select a ticket type')" + "</script>";
                    Page.RegisterStartupScript("Error Window", jScript);
                    return;
                }
                keyObj = TicketTypes.GetTicketType(key_TicketTypeDropdown.SelectedValue);
            }
            else if (selectedKeyType.Equals(ResourceMappingTypes.GROUP))
            {
                if (key_GroupDropdown.SelectedIndex == 0)
                {
                    // Show Error Message
                    string jScript = "<script language='javascript'>" +
                        "alert('Please select a group')" + "</script>";
                    Page.RegisterStartupScript("Error Window", jScript);
                    return;
                }
                keyObj = int.Parse(key_GroupDropdown.SelectedValue);
            }

            ResourceMappingKey key = new ResourceMappingKey(selectedKeyType, keyObj);

            // create values
            ResourceMappingValue[] values = (ResourceMappingValue[])valuesList.ToArray((new ResourceMappingValue()).GetType());

            //create resource mapping
            ResourceMapping newMapping = brokerDB.AddResourceMapping(key, values);
            // test to see if a qualifier is needed
            if (true)
            {
                // add mapping to qualifier list
                int qualifierType = Qualifier.resourceMappingQualifierTypeID;
                string name = brokerDB.ResourceMappingToString(newMapping);
                int qualId = AuthorizationAPI.AddQualifier(newMapping.MappingID, qualifierType, name, Qualifier.ROOT);
            }
            // reset value list
            valuesList = new ArrayList();
            // refresh values repeater
            repValues.DataSource = valuesList;
            repValues.DataBind();

            // refresh mappings dropdown
            value_MappingDropdown.Items.Clear();
            value_MappingDropdown.Items.Add(new ListItem(" ------------- select Resource Mapping ------------ ", "0"));
            //ResourceMapping[] mappings = brokerDB.GetResourceMappings();
            //for (int i = 0; i < mappings.Length; i++)
            //    value_MappingDropdown.Items.Add(new ListItem(brokerDB.ResourceMappingToString(mappings[i]), mappings[i].MappingID.ToString()));
            List<ResourceMapping> mappings = ResourceMapManager.Get();
            foreach (ResourceMapping rm in mappings)
            {
                value_MappingDropdown.Items.Add(new ListItem(brokerDB.ResourceMappingToString(rm), rm.MappingID.ToString()));
            }

            // refresh repeater
            refreshMappingsRepeater();

            // reset controls
            keyTypeDropdown.SelectedIndex = 0;
            key_ProcessAgentDropdown.Visible = false;
            key_ClientDropdown.Visible = false;
            key_TicketTypeDropdown.Visible = false;
            key_GroupDropdown.Visible = false;

            valueTypeDropdown.SelectedIndex = 0;
            value_ClientDropdown.Visible = false;
            value_MappingDropdown.Visible = false;
            value_StringText.Visible = false;
            value_TicketTypeDropdown.Visible = false;
            value_GroupDropdown.Visible = false;
            value_ResourceTypeText.Visible = false;
        }
Пример #5
0
        /// <summary>
        /// Find a Process Agent (an LSS) associated with a particular LS, given a matrix of values
        /// </summary>
        /// <param name="lsId"></param>
        /// <param name="values"></param>
        /// <param name="processAgentType"></param>
        /// <returns></returns>
        //public int FindProcessAgentIdForLS(int lsId, ResourceMappingValue[][] values,
        //    string processAgentType)
        //{
        //    int paId = 0;
        //    if (values == null || values.Length == 0 || lsId == 0)
        //        return paId;
        //    ResourceMappingValue searchValue = null;
        //    if (processAgentType.Equals(ProcessAgentType.LAB_SCHEDULING_SERVER))
        //        searchValue = new ResourceMappingValue(ResourceMappingTypes.RESOURCE_TYPE, ProcessAgentType.LAB_SCHEDULING_SERVER);
        //    bool foundProcessAgent = false;
        //    int row = 0;
        //    //the number of "set of values" (array of values) associated with this client
        //    int numSetOfValues = values.GetLength(0);
        //    for (row = 0; row < numSetOfValues && !foundProcessAgent; row++)
        //    {
        //        int numValues = values[row].Length;
        //        for (int column = 0; column < numValues; column++)
        //        {
        //            if (values[row][column].Equals(searchValue))
        //            {
        //                foundProcessAgent = true;
        //                break;
        //            }
        //        }
        //    }
        //    if (foundProcessAgent)
        //    {
        //        ResourceMappingValue[] associatedPA = values[row - 1];
        //        for (int i = 0; i < associatedPA.Length; i++)
        //        {
        //            if (associatedPA[i].Type.Equals(ResourceMappingTypes.PROCESS_AGENT))
        //            {
        //                paId = (int)associatedPA[i].Entry;
        //                break;
        //            }
        //        }
        //    }
        //    return paId;
        //}
        /// <summary>
        /// Finds an USS or ESS associated with a particular client, given an matrix of values
        /// </summary>
        /// <param name="clientID"></param>
        /// <param name="values"></param>
        /// <param name="processAgentType"></param>
        /// <returns></returns>
        public int FindProcessAgentIdForClient(int clientID, string processAgentType)
        {
            int paId = 0;

            ResourceMappingKey key = new ResourceMappingKey(ResourceMappingTypes.CLIENT, clientID);
            ResourceMappingValue[] searchValue = new ResourceMappingValue[1];

            if (processAgentType.Equals(ProcessAgentType.SCHEDULING_SERVER))
                searchValue[0] = new ResourceMappingValue(ResourceMappingTypes.RESOURCE_TYPE, ProcessAgentType.SCHEDULING_SERVER);
            else if (processAgentType.Equals(ProcessAgentType.EXPERIMENT_STORAGE_SERVER))
                searchValue[0] = new ResourceMappingValue(ResourceMappingTypes.RESOURCE_TYPE, ProcessAgentType.EXPERIMENT_STORAGE_SERVER);
            List<ResourceMapping> found = ResourceMapManager.Find(key, searchValue);

            if (found != null && found.Count > 0)
            {
                foreach (ResourceMapping rm in found)
                {
                    for (int i = 0; i < rm.values.Length; i++)
                    {
                        if (rm.values[i].type.Equals(ResourceMappingTypes.PROCESS_AGENT))
                        {
                            paId = (int)rm.values[i].entry;
                            break;
                        }
                    }
                }

            }

            //bool foundProcessAgent = false;
            //int row = 0;

            ////the number of "set of values" (array of values) associated with this client
            //int numSetOfValues = values.GetLength(0);

            //for (row = 0; row < numSetOfValues && !foundProcessAgent; row++)
            //{
            //    int numValues = values[row].Length;
            //    for (int column = 0; column < numValues; column++)
            //    {
            //        if (values[row][column].Equals(searchValue))
            //        {
            //            foundProcessAgent = true;
            //            break;
            //        }
            //    }
            //}

            //if (foundProcessAgent)
            //{

            //    ResourceMappingValue[] associatedPA = values[row - 1];
            //    for (int i = 0; i < associatedPA.Length; i++)
            //    {
            //        if (associatedPA[i].Type.Equals(ResourceMappingTypes.PROCESS_AGENT))
            //        {
            //            paId = (int)associatedPA[i].Entry;
            //            break;
            //        }
            //    }
            //}

            return paId;
        }
Пример #6
0
        public int FindProcessAgentIdForAgent(int keyId, string type)
        {
            int result = -1;
            ResourceMappingKey key = new ResourceMappingKey(ResourceMappingTypes.PROCESS_AGENT, keyId);
            ResourceMappingValue[] search = new ResourceMappingValue[1];
            search[0] = new ResourceMappingValue(ResourceMappingTypes.RESOURCE_TYPE, type);
            List<ResourceMapping> found = ResourceMapManager.Find(key, search);
            if (found != null && found.Count > 0)
            {
                foreach (ResourceMapping rm in found)
                {
                    for (int i = 0; i < rm.values.Length; i++)
                    {
                        if (rm.values[i].type.Equals(ResourceMappingTypes.PROCESS_AGENT))
                        {
                            result = (int)rm.values[i].entry;
                            break;
                        }
                    }
                }

            }

            //Hashtable mappingsTable = GetResourceMappingsForKey(keyId, ResourceMappingTypes.PROCESS_AGENT);
            //if (mappingsTable != null)
            //{
            //    ResourceMappingValue[][] values = GetResourceMappingValues(mappingsTable);
            //    result = FindProcessAgentIdForLS(keyId, values,
            //        ProcessAgentType.LAB_SCHEDULING_SERVER);
            //}
            return result;
        }
Пример #7
0
        protected ResourceMapping InsertResourceMapping(DbConnection connection, string keyType, object key, string[] valueTypes, object[] values)
        {
            if (valueTypes == null || values == null)
                throw new ArgumentException("Arguments cannot be null", "valueTypes and values");

            if (valueTypes.Length != values.Length)
                throw new ArgumentException("Parameter Arrays \"valueTypes\" and \"values\" should be of the same length");

            ResourceMappingKey mappingKey = new ResourceMappingKey(keyType, key);
            // insert key into database

            try
            {
                connection.Open();
                DbCommand cmd = FactoryDB.CreateCommand("ResourceMapKey_Insert", connection);
                cmd.CommandType = CommandType.StoredProcedure;

                // Get the key type id
                int keyTypeID = ResourceMappingTypes.GetResourceMappingTypeID(keyType);
                if (keyTypeID == -1)
                    throw new ArgumentException("Value for key type is invalid");

                int keyID = -1;

                // if the key is a string, add the string to the strings table
                if (keyType.Equals(ResourceMappingTypes.STRING))
                {
                    DbCommand cmd2 = FactoryDB.CreateCommand("ResourceMapString_Insert", connection);
                    cmd2.CommandType = CommandType.StoredProcedure;

                    // populate parameters
                    cmd2.Parameters.Add(FactoryDB.CreateParameter("@string_Value", key, DbType.String, 2048));

                    keyID = Convert.ToInt32(cmd2.ExecuteScalar());
                }

                // if the key is a Resource Type, add the string to the ResourceTypes table
                else if (keyType.Equals(ResourceMappingTypes.RESOURCE_TYPE))
                {
                    DbCommand cmd2 = FactoryDB.CreateCommand("ResourceMapResourceType_Insert", connection);
                    cmd2.CommandType = CommandType.StoredProcedure;

                    cmd2.Parameters.Add(FactoryDB.CreateParameter("@resourceType_Value", key, DbType.String, 256));

                    keyID = Convert.ToInt32(cmd2.ExecuteScalar());
                }

                else
                    keyID = ResourceMappingEntry.GetId(key);

                if (keyID == -1)
                    throw new ArgumentException("Value for key is invalid");

                // populate stored procedure parameters
                cmd.Parameters.Add(FactoryDB.CreateParameter( "@MappingKey_Type", keyTypeID, DbType.Int32));
                cmd.Parameters.Add(FactoryDB.CreateParameter( "@MappingKey", keyID, DbType.Int32));

                // execute the command
                int mappingID = Convert.ToInt32(cmd.ExecuteScalar());

                //
                // insert mapping values
                //
                ResourceMappingValue[] mappingValues = new ResourceMappingValue[values.Length];
                for (int i = 0; i < mappingValues.Length; i++)
                {
                    mappingValues[i] = new ResourceMappingValue(valueTypes[i], values[i]);

                    // Get the value type id
                    int valueTypeID = ResourceMappingTypes.GetResourceMappingTypeID(valueTypes[i]);
                    if (valueTypeID == -1)
                        throw new ArgumentException("Value for value type \"" + i + "\" is invalid");

                    int valueID = -1;

                    // if the value is a string, add the string to the strings table
                    if (valueTypes[i].Equals(ResourceMappingTypes.STRING))
                    {
                        DbCommand cmd2 = FactoryDB.CreateCommand("ResourceMapString_Insert", connection);
                        cmd2.CommandType = CommandType.StoredProcedure;

                        // populate parameters
                        cmd2.Parameters.Add(FactoryDB.CreateParameter("@string_Value", (string)values[i], DbType.String, 2048));

                        valueID = Convert.ToInt32(cmd2.ExecuteScalar());
                    }

                    // if the key is a Resource Type, add the string to the ResourceTypes table
                    else if (valueTypes[i].Equals(ResourceMappingTypes.RESOURCE_TYPE))
                    {
                        DbCommand cmd2 = FactoryDB.CreateCommand("ResourceMapResourceType_Insert", connection);
                        cmd2.CommandType = CommandType.StoredProcedure;

                        cmd2.Parameters.Add(FactoryDB.CreateParameter("@resourceType_Value", (string)values[i], DbType.String, 256));
                        valueID = Convert.ToInt32(cmd2.ExecuteScalar());
                    }

                    else
                        valueID = ResourceMappingEntry.GetId(values[i]);

                    if (valueID == -1)
                        throw new ArgumentException("Value \"" + i + "\" is invalid");

                    cmd = FactoryDB.CreateCommand("ResourceMapValue_Insert", connection);
                    cmd.CommandType = CommandType.StoredProcedure;
                    //cmd.Parameters.Clear();

                    // populate stored procedure parameters
                    cmd.Parameters.Add(FactoryDB.CreateParameter( "@Mapping_ID", mappingID, DbType.Int32));
                    cmd.Parameters.Add(FactoryDB.CreateParameter( "@MappingValue_Type", valueTypeID, DbType.Int32));
                    cmd.Parameters.Add(FactoryDB.CreateParameter( "@MappingValue", valueID, DbType.Int32));

                    // execute the command
                    int mapValueID = Convert.ToInt32(cmd.ExecuteScalar());
                }

                // create new mapping object
                ResourceMapping mapping = new ResourceMapping(mappingID, mappingKey, mappingValues);

                return mapping;
            }

            catch (DbException e)
            {
                writeEx(e);
                throw;
            }

            finally
            {
                connection.Close();
            }
        }
Пример #8
0
        /// <summary>
        /// Creates the resourceMapping for this relationship and adds a qualifier.
        /// </summary>
        /// <param name="lsId"></param>
        /// <param name="lssId"></param>
        /// <returns>the qualifierID</returns>
        public int AssociateLSS(int lsId, int lssId)
        {
            Object keyObj = lsId;
            string keyType = ResourceMappingTypes.PROCESS_AGENT;

            ArrayList valuesList = new ArrayList();
            Object valueObj = null;

            ResourceMappingValue value = new ResourceMappingValue(ResourceMappingTypes.RESOURCE_TYPE,
                ProcessAgentType.LAB_SCHEDULING_SERVER);
            valuesList.Add(value);

            value = new ResourceMappingValue(ResourceMappingTypes.PROCESS_AGENT,
                lssId);
            valuesList.Add(value);

            value = new ResourceMappingValue(ResourceMappingTypes.TICKET_TYPE,
                TicketTypes.GetTicketType(TicketTypes.MANAGE_LAB));
            valuesList.Add(value);

            ResourceMappingKey key = new ResourceMappingKey(keyType, keyObj);
            ResourceMappingValue[] values = (ResourceMappingValue[])valuesList.ToArray((new ResourceMappingValue()).GetType());
            ResourceMapping newMapping = AddResourceMapping(key, values);

            // add mapping to qualifier list
            int qualifierType = Qualifier.resourceMappingQualifierTypeID;
            string name = ResourceMappingToString(newMapping);
            int qualifierID = AuthorizationAPI.AddQualifier(newMapping.MappingID, qualifierType, name, Qualifier.ROOT);

            // Should a grant be created here

            return qualifierID;
        }
Пример #9
0
 public static List<ResourceMapping> Find(ResourceMappingEntry key, ResourceMappingValue[] values)
 {
     List<ResourceMapping> returnList = null;
     //if (needsRefresh)
     //    Refresh();
     List<ResourceMapping> list = Get(key);
     if (list != null && list.Count > 0)
     {
         returnList = new List<ResourceMapping>();
         foreach (ResourceMapping rm in list)
         {
             if (CheckMappingValues(values, rm.values))
             {
                 returnList.Add(rm);
             }
         }
     }
     return returnList;
 }
Пример #10
0
 /// <summary>
 /// Checks if an array of Resource Mapping values is Equal to another one
 /// </summary>
 /// <param name="v1"></param>
 /// <param name="v2"></param>
 /// <returns></returns>
 public static bool EqualMappingValues(ResourceMappingValue[] v1, ResourceMappingValue[] v2)
 {
     if (v1.Length != v2.Length)
         return false;
     else
         return CheckMappingValues(v1, v2);
 }
Пример #11
0
        /// <summary>
        /// Checks if the first array of Resource Mapping values finds matches in the second array of values.
        /// Arrays may have different counts but array two's length must be greater than or equal to array one's length.
        /// </summary>
        /// <param name="v1"></param>
        /// <param name="v2"></param>
        /// <returns></returns>
        public static bool CheckMappingValues(ResourceMappingValue[] v1, ResourceMappingValue[] v2)
        {
            if (v1.Length > v2.Length)
            {
                return false;
            }
            else
            {
                int num1Values = v1.Length;
                int[] found = new int[num1Values];
                for (int n = 0; n < num1Values; n++)
                {
                    found[n] = -1;
                }

                for (int i = 0; i < num1Values; i++)
                {
                    for (int j = 0; j < v2.Length; j++)
                    {
                        if (v1[i].Equals(v2[j]))
                        {
                            found[i] = j;
                            break;
                        }
                    }
                }
                bool areEqual = true;
                foreach (int k in found)
                {
                    if (k == -1)
                    {
                        areEqual = false;
                        break;
                    }
                }
                return areEqual;
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="rmt">ResourceMappingType</param>
        /// <param name="sourceID">the id of the source object</param>
        /// <param name="pat">The ProcessAgentType of the associated object</param>
        /// <returns>AZero if not found</returns>
        public static int FindResourceProcessAgentID(string rmt, int sourceID, string pat)
        {
            int targetId = 0;
            ResourceMappingValue[] values = new ResourceMappingValue[1];

            values[0] = new ResourceMappingValue(ResourceMappingTypes.RESOURCE_TYPE, pat);
            //values[1] = new ResourceMappingValue(ResourceMappingTypes.TICKET_TYPE,
            //       TicketTypes.GetTicketType(TicketTypes.SCHEDULE_SESSION));
            List<ResourceMapping> mapList = ResourceMapManager.Find(new ResourceMappingKey(rmt, sourceID), values);
            if (mapList != null && mapList.Count > 0)
            {
                foreach (ResourceMapping rm in mapList)
                {
                    for (int i = 0; i < rm.values.Length; i++)
                    {
                        if (rm.values[i].Type == ResourceMappingTypes.PROCESS_AGENT)
                        {
                            targetId = (int)rm.values[i].Entry;
                            if (targetId > 0)
                                break;
                        }
                    }
                }
            }
            return targetId;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="rmt">ResourceMappingType</param>
        /// <param name="sourceID">the id of the source object</param>
        /// <param name="pat">The ProcessAgentType of the associated object</param>
        /// <returns></returns>
        //public static int FindMapID(string rmt, int sourceID, string pat)
        //{
        //    return FindMapID(rmt, sourceID, ResourceMappingTypes.RESOURCE_TYPE, pat);
        //}
        /// <summary>
        /// 
        /// </summary>
        /// <param name="rmt">ResourceMappingType</param>
        /// <param name="sourceID">the id of the source object</param>
        /// <param name="pat">The ProcessAgentType of the associated object</param>
        /// <returns></returns>
        public static int FindMapID(string rmt, int sourceID, string targetType, string target)
        {
            int targetId = 0;
            ResourceMappingValue[] values = new ResourceMappingValue[1];

            values[0] = new ResourceMappingValue(targetType, target);

            List<ResourceMapping> mapList = ResourceMapManager.Find(new ResourceMappingKey(rmt, sourceID), values);
            if (mapList != null && mapList.Count > 0)
            {
                foreach (ResourceMapping rm in mapList)
                {
                    for (int i = 0; i < rm.values.Length; i++)
                    {
                        if (rm.values[i].Type == ResourceMappingTypes.PROCESS_AGENT)
                        {
                            targetId = (int)rm.MappingID;
                            break;
                        }
                    }
                }
            }
            return targetId;
        }
        private void repValues_ItemBound(Object sender, RepeaterItemEventArgs e)
        {
            if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
            {
                // get the current mapping value
                Object o = e.Item.DataItem;
                curValue = (ResourceMappingValue)o;

                // set value label
                Label lbl = (Label)e.Item.FindControl("valueLabel");
                lbl.Text = brokerDB.GetMappingEntryString(curValue,false);
            }
        }
Пример #15
0
        /// <summary>
        /// method to get all maps between Manage and User Groups
        /// </summary>
        /// <returns></returns>
        private ArrayList GetGroupManagerUserMaps()
        {
            ArrayList mapList = new ArrayList();
            if (theClient.clientID > 0)
            {
                // Only get the authorizing groups
                int[] assocGroupIDs = AdministrativeUtilities.GetLabClientGroups(theClient.clientID,false);
                Group[] assocGroups = wrapper.GetGroupsWrapper(assocGroupIDs);

               // if (theClient.needsScheduling)
               // {
                    int ussId = issuer.FindProcessAgentIdForClient(theClient.clientID, ProcessAgentType.SCHEDULING_SERVER);

                    if (ussId > 0) // HasScheduling
                    {
                        ArrayList ussList = new ArrayList();
                        ussList.Add(issuer.GetProcessAgentInfo(ussId)); ;

                        repUSS.DataSource = ussList;
                        repUSS.DataBind();

                    ResourceMappingValue[] values = new ResourceMappingValue[2];
                    values[0] = new ResourceMappingValue(ResourceMappingTypes.CLIENT, theClient.clientID);
                    values[1] = new ResourceMappingValue(ResourceMappingTypes.TICKET_TYPE, TicketTypes.GetTicketType(TicketTypes.MANAGE_USS_GROUP));
                    //values[1] = new ResourceMappingValue(ResourceMappingTypes.PROCESS_AGENT, ussId);

                    foreach (Group g in assocGroups)
                    {
                        ResourceMappingKey rmKey = new ResourceMappingKey(ResourceMappingTypes.GROUP, g.groupID);
                        List<int> rmIds = ResourceMapManager.FindMapIds(rmKey, values);
                        if (rmIds != null)
                        {
                            foreach (int rm in rmIds)
                            {
                                int qualId = AuthorizationAPI.GetQualifierID(rm, Qualifier.resourceMappingQualifierTypeID);
                                int[] grantIDs = AuthorizationAPI.FindGrants(-1, Function.manageUSSGroup, qualId);
                                if (grantIDs.Length > 0)
                                {
                                    Grant[] grants = AuthorizationAPI.GetGrants(grantIDs);
                                    foreach (Grant grant in grants)
                                    {
                                        Group[] managerGroups = AdministrativeAPI.GetGroups(new int[] { grant.agentID });
                                        foreach (Group mg in managerGroups)
                                        {
                                            mapList.Add(new GroupManagerUserMap(mg.groupName, g.groupName, grant.grantID, rm));
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                else // No scheduling
                {
                    foreach (Group g in assocGroups)
                    {
                        mapList.Add(new GroupManagerUserMap("", g.groupName, 0, 0));
                    }
               }
            }
            //return the array list of "ManagerGroup" -> "UserGroup"
            return mapList;
        }
Пример #16
0
        /// <summary>
        /// Loads a new ProcessAgent into the database, without any Ident coupons, creates Qualifier.
        /// </summary>
        /// <param name="xdoc"></param>
        /// <param name="message"></param>
        /// <returns></returns>
        public ProcessAgentInfo LoadProcessAgent(XmlQueryDoc xdoc, ref StringBuilder message)
        {
            ProcessAgent pa = new ProcessAgent();
            pa.agentGuid = xdoc.Query("/processAgentDescriptor/agentGuid");
            pa.type = xdoc.Query("/processAgentDescriptor/type");
            pa.agentName = xdoc.Query("/processAgentDescriptor/agentName");
            pa.domainGuid = xdoc.Query("/processAgentDescriptor/domainGuid");
            pa.codeBaseUrl = xdoc.Query("/processAgentDescriptor/codeBaseUrl");
            pa.webServiceUrl = xdoc.Query("/processAgentDescriptor/webServiceUrl");
            int newID = brokerDb.InsertProcessAgent(pa, null, null);

            SystemSupport systemSupport = new SystemSupport();
            systemSupport.agentGuid = xdoc.Query("/processAgentDescriptor/systemSupport/agentGuid");
            systemSupport.bugEmail = xdoc.Query("/processAgentDescriptor/systemSupport/bugEmail");
            systemSupport.contactEmail = xdoc.Query("/processAgentDescriptor/systemSupport/contactEmail");
            systemSupport.infoUrl = xdoc.Query("/processAgentDescriptor/systemSupport/infoUrl");
            systemSupport.description = xdoc.Query("/processAgentDescriptor/systemSupport/desciption");
            systemSupport.location = xdoc.Query("/processAgentDescriptor/systemSupport/loction");
            if (systemSupport != null && systemSupport.agentGuid.CompareTo(pa.agentGuid) == 0)
            {
                brokerDb.SaveSystemSupport(systemSupport.agentGuid, systemSupport.contactEmail, systemSupport.bugEmail,
                    systemSupport.infoUrl, systemSupport.description, systemSupport.location);
            }

            // deal with resources later, need to decode resource Names
            XPathNodeIterator pathIter = xdoc.Select("/processAgentDescriptor/resources/*");
            if (pathIter != null && pathIter.Count > 0)
            {
                while (pathIter.MoveNext())
                {
                    string key = pathIter.Current.GetAttribute("key", ns);
                    string value = pathIter.Current.GetAttribute("value", ns);
                    // Create ResourceMapping
                    ResourceMappingKey mapKey = new ResourceMappingKey(ResourceMappingTypes.PROCESS_AGENT, newID);

                    // create values
                    ResourceMappingValue[] values = new ResourceMappingValue[2];
                    values[0] = new ResourceMappingValue(ResourceMappingTypes.RESOURCE_TYPE, key);
                    values[1] = new ResourceMappingValue(ResourceMappingTypes.STRING, value);
                    ResourceMapping newMapping = brokerDb.AddResourceMapping(mapKey, values);
                }
            }
            message.AppendLine("Registered a new " + pa.type + ": " + newID + ": "
                    + pa.agentName + " -> " + pa.codeBaseUrl);
            //Add Qualifiers
            if (pa.type.Equals(ProcessAgentType.LAB_SCHEDULING_SERVER))
            {
                int lssQualID = AuthorizationAPI.AddQualifier(newID, Qualifier.labSchedulingQualifierTypeID,
                    pa.agentName, Qualifier.ROOT);

            }
            else if (pa.type.Equals(ProcessAgentType.LAB_SERVER))
            {
                int lsQualID = AuthorizationAPI.AddQualifier(newID, Qualifier.labServerQualifierTypeID, pa.agentName, Qualifier.ROOT);
                string lssGuid = xdoc.Query("/processAgentDescriptor/lssGuid");
                if (lssGuid != null && lssGuid.Length > 0)
                {
                    int lssForLsId = brokerDb.GetProcessAgentID(lssGuid);
                    if (lssForLsId > 0)
                    {
                        brokerDb.AssociateLSS(newID, lssForLsId);
                    }
                }
            }
            return brokerDb.GetProcessAgentInfo(pa.agentGuid);
        }
Пример #17
0
 public static List<int> FindMapIds(ResourceMappingEntry key, ResourceMappingValue[] values)
 {
     List<int> returnList = null;
     List<ResourceMapping> list = Get(key);
     if (list != null && list.Count > 0)
     {
         returnList = new List<int>();
         foreach (ResourceMapping rm in list)
         {
             if (CheckMappingValues(values, rm.values))
             {
                 returnList.Add(rm.MappingID);
             }
         }
     }
     return returnList;
 }
Пример #18
0
        //Returns a hashtable of (mappingID, ResourceMappingValue[]) pairs
        //public Hashtable GetResourceMappingsForKey(object searchKey, string type)
        //{
        //    ResourceMappingKey key = null;
        //    if (type.Equals(ResourceMappingTypes.CLIENT))
        //    {
        //        key = new ResourceMappingKey(type, (int)searchKey);
        //    }
        //    else if (type.Equals(ResourceMappingTypes.PROCESS_AGENT))
        //    {
        //        key = new ResourceMappingKey(type, (int)searchKey);
        //    }
        //    else if (type.Equals(ResourceMappingTypes.TICKET_TYPE))
        //    {
        //        key = new ResourceMappingKey(type, (TicketType)searchKey);
        //    }
        //    else if (type.Equals(ResourceMappingTypes.GROUP))
        //    {
        //        key = new ResourceMappingKey(type, (int)searchKey);
        //    }
        //    List<ResourceMapping> list = ResourceMapManager.Get(key);
        //    if (list != null && list.Count > 0)
        //    {
        //        Hashtable mappingsTable = new Hashtable();
        //        foreach (ResourceMapping rm in list)
        //        {
        //            mappingsTable.Add(rm.MappingID, rm);
        //        }
        //        return mappingsTable;
        //    }
        //    else
        //    {
        //        return null;
        //    }
        //}
        //Gets the resource mapping values as a 2D array from a mappings HashTable
        public ResourceMappingValue[][] GetResourceMappingValues(Hashtable mappingsTable)
        {
            if (mappingsTable == null || mappingsTable.Count == 0)
                return null;

            ResourceMappingValue[][] values = new ResourceMappingValue[mappingsTable.Count][];
            int i = 0;
            foreach (DictionaryEntry entry in mappingsTable)
            {
                values[i++] = ((ResourceMapping)entry.Value).values;

            }
            return values;
        }
Пример #19
0
        protected void btnRegisterESS_Click(object sender, EventArgs e)
        {
            lblResponse.Visible = false;
            lblResponse.Text = "";

            try
            {
                if (ddlLabClient.SelectedIndex == 0)
                {
                    lblResponse.Visible = true;
                    lblResponse.Text = Utilities.FormatErrorMessage("Please save the Lab Client information before attempting to associate it with a resource");
                    return;
                }

                if (ddlAssociatedESS.SelectedIndex == 0)
                {
                    lblResponse.Visible = true;
                    lblResponse.Text = Utilities.FormatErrorMessage("Please select a desired ESS to be associated with the client.");
                    return;
                }

                LabClient lc = new LabClient();
                lc = labClients[ddlLabClient.SelectedIndex - 1];

                Object keyObj = int.Parse(ddlLabClient.SelectedValue);
                string keyType = ResourceMappingTypes.CLIENT;

                ArrayList valuesList = new ArrayList();
                Object valueObj = null;

                ResourceMappingValue value = new ResourceMappingValue(ResourceMappingTypes.RESOURCE_TYPE, ProcessAgentType.EXPERIMENT_STORAGE_SERVER);
                valuesList.Add(value);

                value = new ResourceMappingValue(ResourceMappingTypes.PROCESS_AGENT,
                    int.Parse(ddlAssociatedESS.SelectedValue));
                valuesList.Add(value);

                value = new ResourceMappingValue(ResourceMappingTypes.TICKET_TYPE,
                    TicketTypes.GetTicketType(TicketTypes.ADMINISTER_EXPERIMENT));
                valuesList.Add(value);

                ResourceMappingKey key = new ResourceMappingKey(keyType, keyObj);
                ResourceMappingValue[] values = (ResourceMappingValue[])valuesList.ToArray((new ResourceMappingValue()).GetType());
                ResourceMapping newMapping = ticketing.AddResourceMapping(key, values);

                // add mapping to qualifier list
                int qualifierType = Qualifier.resourceMappingQualifierTypeID;
                string name = ticketing.ResourceMappingToString(newMapping);
                int qualId = AuthorizationAPI.AddQualifier(newMapping.MappingID, qualifierType, name, Qualifier.ROOT);

                // No Grant required for ESS

                Session["ClientEssMappingID"] = newMapping.MappingID;

                btnRegisterESS.Visible = false;
                btnDissociateESS.Visible = true;
                ddlAssociatedESS.Enabled = false;

                lblResponse.Visible = true;
                lblResponse.Text = Utilities.FormatConfirmationMessage("Experiment Storage Server \"" + ddlAssociatedESS.SelectedItem.Text + "\" succesfully "
                    + "associated with client \"" + ddlLabClient.SelectedItem.Text + "\".");

                //wrapper.ModifyLabClientWrapper(lc.clientID, lc.clientName, lc.version, lc.clientShortDescription,
                //    lc.clientLongDescription, lc.notes, lc.loaderScript, lc.clientType,
                //    lc.labServerIDs, lc.contactEmail, lc.contactFirstName, lc.contactLastName,
                //    lc.needsScheduling, lc.needsESS, lc.IsReentrant, lc.clientInfos);

            }
            catch
            {
                throw;
            }
        }
Пример #20
0
        /// <summary>
        /// Checks if an array of Resource Mapping values is Equal to another one
        /// </summary>
        /// <param name="v1"></param>
        /// <param name="v2"></param>
        /// <returns></returns>
        public bool EqualMappingValues(ResourceMappingValue[] v1, ResourceMappingValue[] v2)
        {
            int num1Values = v1.GetLength(0);
            int num2Values = v2.GetLength(0);

            if (num1Values != num2Values)
                return false;

            bool areNotEqual = false;
            bool areEqual = false;

            for (int i = 0; i < num1Values; i++)
            {
                if (!v1[i].Equals(v2[i]))
                {
                    areNotEqual = true;
                    break;
                }
            }

            //for (int i = 0; i < num1Values; i++)
            //{
            //    areEqual = false;

            //    for (int j = 0; j < num2Values; j++)
            //    {
            //        if (v1[i].Equals(v1[j]))
            //        {
            //            areEqual = true;
            //            break;
            //        }
            //    }

            //    if (areEqual == false)
            //        break;
            //}

            //return (areEqual);

            return (!areNotEqual);
        }
Пример #21
0
        protected void btnRegisterUSS_Click(object sender, EventArgs e)
        {
            lblResponse.Visible = false;
            lblResponse.Text = "";

            StringBuilder message = new StringBuilder();
            try
            {
                if (ddlLabClient.SelectedIndex == 0)
                {
                    lblResponse.Visible = true;
                    lblResponse.Text = Utilities.FormatErrorMessage("Please save the Lab Client information before attempting to dissociate it from a resource");
                    return;
                }

                if (ddlAssociatedUSS.SelectedIndex == 0)
                {
                    lblResponse.Visible = true;
                    lblResponse.Text = Utilities.FormatErrorMessage("Please select a desired USS to be associated with the client.");
                    return;
                }

                LabClient lc = new LabClient();
                lc = labClients[ddlLabClient.SelectedIndex - 1];

                Object keyObj = int.Parse(ddlLabClient.SelectedValue);
                string keyType = ResourceMappingTypes.CLIENT;

                ArrayList valuesList = new ArrayList();
                Object valueObj = null;

                ResourceMappingValue value = new ResourceMappingValue(ResourceMappingTypes.RESOURCE_TYPE, ProcessAgentType.SCHEDULING_SERVER);
                valuesList.Add(value);

                int ussId = int.Parse(ddlAssociatedUSS.SelectedValue);

                if (ussId > 0)
                {
                    value = new ResourceMappingValue(ResourceMappingTypes.PROCESS_AGENT, ussId);
                    valuesList.Add(value);

                    value = new ResourceMappingValue(ResourceMappingTypes.TICKET_TYPE,
                        TicketTypes.GetTicketType(TicketTypes.SCHEDULE_SESSION));
                    valuesList.Add(value);

                    ResourceMappingKey key = new ResourceMappingKey(keyType, keyObj);
                    ResourceMappingValue[] values = (ResourceMappingValue[])valuesList.ToArray((new ResourceMappingValue()).GetType());

                    // Add the mapping to the database & cache
                    ResourceMapping newMapping = ticketing.AddResourceMapping(key, values);

                    // add mapping to qualifier list
                    int qualifierType = Qualifier.resourceMappingQualifierTypeID;
                    string name = ticketing.ResourceMappingToString(newMapping);
                    int qualifierID = AuthorizationAPI.AddQualifier(newMapping.MappingID, qualifierType, name, Qualifier.ROOT);

                    // Moved to ManageLabGroups
                    //Give the Manager Group a Grant "MANAGE_USS_GROUP" on the created resource mapping
                    //int agentID = Convert.ToInt32(ddlAdminGroup.SelectedValue);
                    //string function = Function.manageUSSGroup;
                    //int grantID = wrapper.AddGrantWrapper(agentID, function, qualifierID);

                    Session["ClientUssMappingID"] = newMapping.MappingID;

                    btnRegisterUSS.Visible = false;
                    btnDissociateUSS.Visible = true;
                    ddlAssociatedUSS.Enabled = false;

                    message.AppendLine("User-side Scheduling Server \"" + ddlAssociatedUSS.SelectedItem.Text + "\" succesfully "
                        + "associated with client \"" + ddlLabClient.SelectedItem.Text + "\".");

                    //wrapper.ModifyLabClientWrapper(lc.clientID, lc.clientName, lc.version, lc.clientShortDescription,
                    //    lc.clientLongDescription, lc.notes, lc.loaderScript, lc.clientType,
                    //    lc.labServerIDs, lc.contactEmail, lc.contactFirstName, lc.contactLastName,
                    //    lc.needsScheduling, lc.needsESS, lc.IsReentrant, lc.clientInfos);

                    TicketLoadFactory factory = TicketLoadFactory.Instance();
                    ProcessAgentInfo uss = ticketing.GetProcessAgentInfo(ussId);
                    if (uss.retired)
                    {
                        throw new Exception("The specified USS is retired");
                    }
                    //this should be in a loop
                    for(int i = 0;i<lc.labServerIDs.Length;i++){

                        if (lc.labServerIDs[i] > 0)
                        {
                            ProcessAgentInfo labServer = ticketing.GetProcessAgentInfo(lc.labServerIDs[i]);
                            if (labServer.retired)
                            {
                                throw new Exception("The lab server is retired");
                            }
                            int lssId = ticketing.FindProcessAgentIdForAgent(lc.labServerIDs[i], ProcessAgentType.LAB_SCHEDULING_SERVER);

                            if (lssId > 0)
                            {

                                ProcessAgentInfo lss = ticketing.GetProcessAgentInfo(lssId);
                                if (lss.retired)
                                {
                                    throw new Exception("The LSS is retired");
                                }
                                // The REVOKE_RESERVATION ticket
                                string revokePayload = factory.createRevokeReservationPayload();
                                Coupon ussCoupon = ticketing.CreateTicket(TicketTypes.REVOKE_RESERVATION, uss.agentGuid,
                                    lss.agentGuid, -1L, revokePayload);

                                // Is this in the domain or cross-domain
                                if (lss.domainGuid.Equals(ProcessAgentDB.ServiceGuid))
                                {
                                    // this domain
                                    //Add USS on LSS

                                    //string lssPayload = factory.createAdministerLSSPayload(Convert.ToInt32(Session["UserTZ"]));
                                    //long duration = 60; //seconds for the LSS to redeem the ticket of this coupon and Add LSS Info
                                    //ticketing.AddTicket(lssCoupon, TicketTypes.ADMINISTER_LSS, lss.agentGuid,
                                    //    ticketing.ServiceGuid(), duration, lssPayload);

                                    LabSchedulingProxy lssProxy = new LabSchedulingProxy();
                                    lssProxy.Url = lss.webServiceUrl;
                                    lssProxy.AgentAuthHeaderValue = new AgentAuthHeader();
                                    lssProxy.AgentAuthHeaderValue.coupon = lss.identOut;
                                    lssProxy.AgentAuthHeaderValue.agentGuid = ProcessAgentDB.ServiceGuid;
                                    int ussAdded = lssProxy.AddUSSInfo(uss.agentGuid, uss.agentName, uss.webServiceUrl, ussCoupon);
                                    lssProxy.AddExperimentInfo(labServer.agentGuid, labServer.agentName, lc.clientGuid, lc.clientName, lc.version, lc.contactEmail);
                                }
                                else
                                {
                                    // cross-domain
                                    // send consumerInfo to remote SB
                                    int remoteSbId = ticketing.GetProcessAgentID(lss.domainGuid);
                                    message.AppendLine(RegistrationSupport.RegisterClientUSS(remoteSbId, null, lss.agentId, null, labServer.agentId,
                                        ussCoupon, uss.agentId, null, lc.clientID));

                                }
                                //ADD LSS on USS
                                string ussPayload = factory.createAdministerUSSPayload(Convert.ToInt32(Session["UserTZ"]));

                                UserSchedulingProxy ussProxy = new UserSchedulingProxy();
                                ussProxy.Url = uss.webServiceUrl;
                                ussProxy.AgentAuthHeaderValue = new AgentAuthHeader();
                                ussProxy.AgentAuthHeaderValue.coupon = uss.identOut;
                                ussProxy.AgentAuthHeaderValue.agentGuid = ProcessAgentDB.ServiceGuid;
                                int lssAdded = ussProxy.AddLSSInfo(lss.agentGuid, lss.agentName, lss.webServiceUrl);

                                //Add Experiment Information on USS
                                int expInfoAdded = ussProxy.AddExperimentInfo(labServer.agentGuid, labServer.agentName,
                                    lc.clientGuid, lc.clientName, lc.version, lc.contactEmail, lss.agentGuid);

                                // Group Credentials MOVED TO THE MANAGE LAB GROUPS PAGE
                            }
                        }
                    }
                }
            }
            catch
            {
                throw;
            }
            lblResponse.Visible = true;
            lblResponse.Text = Utilities.FormatConfirmationMessage(message.ToString());
        }
Пример #22
0
        //Checks whether there are a USS and/or an ESS associated with the selected client
        private void CheckAssociatedResources(LabClient client)
        {
            int clientID = client.clientID;

            if (client.needsScheduling)
            {
                int ussId = 0;
                 ResourceMappingValue [] ussValues = new ResourceMappingValue[2];

                 ussValues[0] = new ResourceMappingValue(ResourceMappingTypes.RESOURCE_TYPE, ProcessAgentType.SCHEDULING_SERVER);
                 ussValues[1] = new ResourceMappingValue(ResourceMappingTypes.TICKET_TYPE,
                        TicketTypes.GetTicketType(TicketTypes.SCHEDULE_SESSION));
                List<ResourceMapping> ussList = ResourceMapManager.Find(
                    new ResourceMappingKey(ResourceMappingTypes.CLIENT,clientID),ussValues);
                if(ussList != null && ussList.Count > 0){
                    foreach(ResourceMapping rm in ussList){
                        for(int i=0; i<rm.values.Length;i++){
                            if(rm.values[i].Type == ResourceMappingTypes.PROCESS_AGENT){
                                ussId = (int) rm.values[i].Entry;
                                Session["ClientUssMappingID"] = rm.MappingID;
                                break;
                            }
                        }
                    }
                }
                if (ussId > 0)
                {
                    //ResourceMappingValue [] ussValues = new ResourceMappingValue[2];
                    //ussValues[0] = new ResourceMappingValue(ResourceMappingTypes.RESOURCE_TYPE, ProcessAgentType.SCHEDULING_SERVER);
                    ////valuesList.Add(new ResourceMappingValue(ResourceMappingTypes.PROCESS_AGENT, ussId));
                    //ussValues[1] = new ResourceMappingValue(ResourceMappingTypes.TICKET_TYPE,
                    //    TicketTypes.GetTicketType(TicketTypes.SCHEDULE_SESSION));
                    //ResourceMappingValue[] valuesForKey = (ResourceMappingValue[])valuesList.ToArray((new ResourceMappingValue()).GetType());

                    //foreach (DictionaryEntry entry in mappingsTable)
                    //{
                    //    if (ticketing.EqualMappingValues((ResourceMappingValue[])entry.Value, valuesForKey))
                    //        (int)entry.Key;
                    //}

                    //int[] id = { ticketing.GetProcessAgentID(uss.agentGuid) };
                    //IntTag[] ussTag = ticketing.GetProcessAgentTags(id);
                    btnRegisterUSS.Visible = false;
                    btnDissociateUSS.Visible = true;
                    ddlAssociatedUSS.SelectedValue = ussId.ToString();
                    ddlAssociatedUSS.Enabled = false;
                }

                else
                {
                    btnRegisterUSS.Visible = true && client.labServerIDs.Length > 0;
                    btnDissociateUSS.Visible = false;
                    ddlAssociatedUSS.Enabled = true && client.labServerIDs.Length > 0;
                    Session.Remove("ClientUssMappingID");
                }
            }
            else{
                btnRegisterUSS.Visible = false;
                btnDissociateUSS.Visible = false;
                ddlAssociatedUSS.Enabled = false;
                Session.Remove("ClientUssMappingID");

            }
            if(client.needsESS){
               int essId = 0;
                 ResourceMappingValue [] essValues = new ResourceMappingValue[2];

                 essValues[0] = new ResourceMappingValue(ResourceMappingTypes.RESOURCE_TYPE, ProcessAgentType.EXPERIMENT_STORAGE_SERVER);
                 essValues[1] = new ResourceMappingValue(ResourceMappingTypes.TICKET_TYPE,
                        TicketTypes.GetTicketType(TicketTypes.ADMINISTER_EXPERIMENT));
                List<ResourceMapping> essList = ResourceMapManager.Find(
                    new ResourceMappingKey(ResourceMappingTypes.CLIENT,clientID),essValues);
                if(essList != null && essList.Count > 0){
                    foreach(ResourceMapping rm in essList){
                        for(int j=0; j<rm.values.Length;j++){
                            if(rm.values[j].Type == ResourceMappingTypes.PROCESS_AGENT){
                                essId = (int) rm.values[j].Entry;
                                Session["ClientEssMappingID"] = rm.MappingID;
                                break;
                            }
                        }
                    }
                }

                if (essId > 0)
                {
                    //int[] id = { ticketing.GetProcessAgentID(ess.agentGuid) };
                    btnRegisterESS.Visible = false;
                    btnDissociateESS.Visible = true;
                    ddlAssociatedESS.SelectedValue = essId.ToString();
                    ddlAssociatedESS.Enabled = false;
                }

                else
                {
                    btnRegisterESS.Visible = true;
                    btnDissociateESS.Visible = false;
                    ddlAssociatedESS.Enabled = true;
                    Session.Remove("ClientEssMappingID");
                }
            }

            else
            {

                btnRegisterESS.Visible = false;
                btnDissociateESS.Visible = false;
                ddlAssociatedESS.Enabled = false;

                Session.Remove("ClientEssMappingID");

            }
        }
Пример #23
0
        protected void btnAssociateLSS_Click(object sender, EventArgs e)
        {
            if(btnAssociateLSS.CommandName.CompareTo("associate") == 0){

            try
            {
                if (ddlLSS.SelectedIndex == 0)
                {
                    lblErrorMessage.Visible = true;
                    lblErrorMessage.Text = Utilities.FormatErrorMessage("Please select a desired LSS to be associated with the lab server.");
                    return;
                }
                if (ddlManageLSS.SelectedIndex == 0)
                {
                    lblErrorMessage.Visible = true;
                    lblErrorMessage.Text = Utilities.FormatErrorMessage("Please select a group to manage the Lab Server on the lab scheduling server.");
                    return;
                }
                int lsID = Int32.Parse(ddlService.SelectedValue);
                int lssID = Int32.Parse(ddlLSS.SelectedValue);
                int manageGroupID = Int32.Parse(ddlManageLSS.SelectedValue);
                brokerDB.AssociateLSS(lsID,lssID );
                try
                {
                    // This has been moved to ManageServices
                    // This should be only for LS/LSS in the domain
                    // Add LabServer LSS ManageLab Grant

                    ResourceMappingKey key = new ResourceMappingKey(ResourceMappingTypes.PROCESS_AGENT, lsID);
                    ResourceMappingValue[] values = new ResourceMappingValue[3];
                    values[0] = new ResourceMappingValue(ResourceMappingTypes.RESOURCE_TYPE, ProcessAgentType.LAB_SCHEDULING_SERVER);
                    values[1] = new ResourceMappingValue(ResourceMappingTypes.PROCESS_AGENT, lssID);
                    values[2] = new ResourceMappingValue(ResourceMappingTypes.TICKET_TYPE,
                        TicketTypes.GetTicketType(TicketTypes.MANAGE_LAB));
                    List<int> mapIDS = ResourceMapManager.FindMapIds(key, values);
                    if (mapIDS.Count > 0)
                    {

                        int labQualifierID = AuthorizationAPI.GetQualifierID(mapIDS[0], Qualifier.resourceMappingQualifierTypeID);
                        int labGrantID = wrapper.AddGrantWrapper(manageGroupID, Function.manageLAB, labQualifierID);
                    }

                }
                catch(Exception ex)
                {
                    Utilities.WriteLog(ex.Message);
                }
                btnAssociateLSS.Text = "Disassociate";
                btnAssociateLSS.CommandName = "disassociate";
                ddlLSS.Enabled = false;
                ddlLSS.BackColor = disabled;
                ddlManageLSS.Enabled = false;
                ddlManageLSS.BackColor = disabled;
                lblErrorMessage.Visible = true;
                lblErrorMessage.Text = Utilities.FormatConfirmationMessage("Lab-side Scheduling Server \"" + ddlLSS.SelectedItem.Text + "\" succesfully "
                    + "associated with lab server \"" + ddlService.SelectedItem.Text + "\".");

            }
            catch
            {
                throw;
            }
            }
            else if(btnAssociateLSS.CommandName.CompareTo("disassociate") == 0){
                try
            {
                brokerDB.DeleteResourceMapping( (int) Session["LS_LSSmapID"]);
                Session.Remove("LS_LSSmapID");

                lblErrorMessage.Visible = true;
                lblErrorMessage.Text = Utilities.FormatConfirmationMessage("Lab-side Scheduling Server \"" + ddlLSS.SelectedItem.Text + "\" succesfully "
                    + "dissociated from lab server \"" + ddlService.SelectedItem.Text + "\".");

                ddlLSS.Enabled = true;
                ddlLSS.BackColor = enabled;
                ddlLSS.SelectedIndex = 0;
                ddlManageLSS.SelectedIndex = 0;
                ddlManageLSS.Enabled = true;
                ddlManageLSS.BackColor = enabled;
                btnAssociateLSS.CommandName = "associate";
                btnAssociateLSS.Text = "Associate";
            }

            catch
            {
                throw;
            }
            }
        }
Пример #24
0
        /// <summary>
        /// Find a ResourceMapping entry, given a matrix of values
        /// </summary>
        /// <param name="searchValue"></param>
        /// <param name="values"></param>
        /// <returns></returns>
        public object FindResourceEntry(ResourceMappingValue searchValue, ResourceMappingValue[][] values, string dataType)
        {
            if (values == null || values.Length == 0 || searchValue == null)
                return null;

            object target = null;
            bool found = false;
            int row = 0;

            //the number of "set of values" (array of values) associated with this client
            int numSetOfValues = values.GetLength(0);

            for (row = 0; row < numSetOfValues && !found; row++)
            {
                int numValues = values[row].Length;
                for (int column = 0; column < numValues; column++)
                {
                    if (values[row][column].Equals(searchValue))
                    {
                        found = true;
                        break;
                    }
                }
            }
            if (found)
            {
                ResourceMappingValue[] mappingValue = values[row - 1];
                for (int i = 0; i < mappingValue.Length; i++)
                {
                    if (mappingValue[i].Type.Equals(dataType))
                    {
                        target = mappingValue[i].Entry;
                        break;
                    }
                }
            }
            return target;
        }
        /// <summary>
        /// Add a new value entry to the list of temporary values
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnAddValue_Click(object sender, System.EventArgs e)
        {
            if (valueTypeDropdown.SelectedIndex == 0)
            {
                // Show Error Message
                string jScript = "<script language='javascript'>" +
                    "alert('Please select a value type')" + "</script>";
                Page.RegisterStartupScript("Error Window", jScript);
                return;
            }

            // create a new Resource Mapping Value
            string selectedValueType = valueTypeDropdown.SelectedValue;
            Object valueObj = null;
            if (selectedValueType.Equals(ResourceMappingTypes.PROCESS_AGENT))
            {
                if (value_ProcessAgentDropdown.SelectedIndex == 0)
                {
                    // Show Error Message
                    string jScript = "<script language='javascript'>" +
                        "alert('Please select a process agent')" + "</script>";
                    Page.RegisterStartupScript("Error Window", jScript);
                    return;
                }
                valueObj = int.Parse(value_ProcessAgentDropdown.SelectedValue);
            }
            else if (selectedValueType.Equals(ResourceMappingTypes.CLIENT))
            {
                if (value_ClientDropdown.SelectedIndex == 0)
                {
                    // Show Error Message
                    string jScript = "<script language='javascript'>" +
                        "alert('Please select a client')" + "</script>";
                    Page.RegisterStartupScript("Error Window", jScript);
                    return;
                }
                valueObj = int.Parse(value_ClientDropdown.SelectedValue);
            }
            else if (selectedValueType.Equals(ResourceMappingTypes.RESOURCE_MAPPING))
            {
                if (value_MappingDropdown.SelectedIndex == 0)
                {
                    // Show Error Message
                    string jScript = "<script language='javascript'>" +
                        "alert('Please select a Resource Mapping')" + "</script>";
                    Page.RegisterStartupScript("Error Window", jScript);
                    return;
                }
                // value object is resource mapping ID
                valueObj = int.Parse(value_MappingDropdown.SelectedValue);
            }
            else if (selectedValueType.Equals(ResourceMappingTypes.STRING))
            {
                if (value_StringText.Text == null || value_StringText.Text.Equals(""))
                {
                    // Show Error Message
                    string jScript = "<script language='javascript'>" +
                        "alert('Please enter a string value')" + "</script>";
                    Page.RegisterStartupScript("Error Window", jScript);
                    return;
                }
                valueObj = value_StringText.Text;
            }
            else if (selectedValueType.Equals(ResourceMappingTypes.TICKET_TYPE))
            {
                if (value_TicketTypeDropdown.SelectedIndex == 0)
                {
                    // Show Error Message
                    string jScript = "<script language='javascript'>" +
                        "alert('Please select a ticket type')" + "</script>";
                    Page.RegisterStartupScript("Error Window", jScript);
                    return;
                }
                valueObj = TicketTypes.GetTicketType(value_TicketTypeDropdown.SelectedValue);
            }
            else if (selectedValueType.Equals(ResourceMappingTypes.GROUP))
            {
                if (value_GroupDropdown.SelectedIndex == 0)
                {
                    // Show Error Message
                    string jScript = "<script language='javascript'>" +
                        "alert('Please select a Group')" + "</script>";
                    Page.RegisterStartupScript("Error Window", jScript);
                    return;
                }
                valueObj = int.Parse(value_GroupDropdown.SelectedValue);
            }

            else if (selectedValueType.Equals(ResourceMappingTypes.RESOURCE_TYPE))
            {
                if (value_ResourceTypeText.Text == null || value_ResourceTypeText.Text.Equals(""))
                {
                    // Show Error Message
                    string jScript = "<script language='javascript'>" +
                        "alert('Please enter a string value')" + "</script>";
                    Page.RegisterStartupScript("Error Window", jScript);
                    return;
                }
                valueObj = value_ResourceTypeText.Text;
            }

            ResourceMappingValue value = new ResourceMappingValue(valueTypeDropdown.SelectedValue, valueObj);

            // add value to list of values and refresh the value repeater
            valuesList.Add(value);
            repValues.DataSource = valuesList;
            repValues.DataBind();

            // reset dropdown lists
            valueTypeDropdown.SelectedIndex = 0;
            value_ProcessAgentDropdown.SelectedIndex = 0;
            value_TicketTypeDropdown.SelectedIndex = 0;
            value_ClientDropdown.SelectedIndex = 0;
            value_TicketTypeDropdown.SelectedIndex = 0;
            value_GroupDropdown.SelectedIndex = 0;
            value_StringText.Text = "";
            value_ResourceTypeText.Text = "";

            value_ProcessAgentDropdown.Visible = false;
            value_ClientDropdown.Visible = false;
            value_StringText.Visible = false;
            value_TicketTypeDropdown.Visible = false;
            value_GroupDropdown.Visible = false;
            value_ResourceTypeText.Visible = false;
        }