コード例 #1
0
        void OnAuthGroupRemoveCommand(BasePlayer player, string groupName, string[] args)
        {
            AuthGroup group = Groups.GetByOwnerOrManager(player, groupName);

            if (group == null)
            {
                SendReply(player, Messages.YouAreNotOwnerOrManagerOfGroup, groupName);
                return;
            }

            if (args.Length == 0)
            {
                PendingInteractions.Add(player.UserIDString, new RemoveEntityFromGroup(player, group));
                SendReply(player, Messages.SelectEntityToRemoveFromGroup, group.Name);
                return;
            }

            var        playerName = args[0].Trim();
            BasePlayer member     = BasePlayerEx.FindByNameOrId(playerName);

            if (member == null)
            {
                SendReply(player, Messages.NoSuchPlayer, playerName);
                return;
            }

            if (!group.HasMember(member))
            {
                SendReply(player, Messages.CannotRemoveMemberNotMemberOfGroup, member.displayName, group.Name);
                return;
            }

            group.RemoveMember(member);
            SendReply(player, Messages.MemberRemoved, member.displayName, group.Name);
        }
コード例 #2
0
        [SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")]   // large switch statement
        private void SetInteractions(string subElementName, string value)
        {
            string[] elementParts = subElementName.Split('.');
            if (elementParts.Length < 2)
            {
                throw new InvalidOperationException(ResHelper.GetMessage(FramesetResources.CONV_SetValueInvalidName, CurrentElementName));
            }

            int index;

            if (!int.TryParse(elementParts[0], out index))
            {
                return;
            }

            Interaction interaction;

            if (index < InteractionsByIndex.Count)
            {
                // It's already in the list, so find the object
                interaction = InteractionsByIndex[index];
            }
            else
            {
                // It's a new Interaction. Add it to the list of pending Interactions and
                // add it to the mapping table.
                interaction = DataModel.CreateInteraction();
                PendingInteractions.Add(interaction);
                InteractionsByIndex.Add(index, interaction);
            }

            switch (elementParts[1])
            {
            case "id":
            {
                if (String.CompareOrdinal(value, interaction.Id) != 0)
                {
                    interaction.Id = value;
                }
            }
            break;

            case "type":
            {
                interaction.InteractionType = GetInteractionType(value);
            }
            break;

            case "objectives":
            {
                // First find 'x' in the element name interactions.n.objectives.x.id.
                if (elementParts.Length < 4)
                {
                    throw new InvalidOperationException(ResHelper.GetMessage(FramesetResources.CONV_SetValueInvalidName, CurrentElementName));
                }

                int objIndex;
                if (!int.TryParse(elementParts[2], out objIndex))
                {
                    throw new InvalidOperationException(ResHelper.GetMessage(FramesetResources.CONV_SetValueInvalidName, CurrentElementName));
                }

                InteractionObjective objective;
                bool isNewObjective = false;
                if (objIndex >= interaction.Objectives.Count)
                {
                    objective      = DataModel.CreateInteractionObjective();
                    isNewObjective = true;
                }
                else
                {
                    objective = interaction.Objectives[objIndex];
                }

                if (String.CompareOrdinal(value, objective.Id) != 0)
                {
                    objective.Id = value;
                }

                if (isNewObjective)
                {
                    interaction.Objectives.Add(objective);
                }
            }
            break;

            case "time":
            {
                interaction.Timestamp = value;
            }
            break;

            case "correct_responses":
            {
                // This is of the form: interactions.n.correct_responses.x.y

                // First find 'x' in the element name interactions.n.correct_responses.x.y.
                if (elementParts.Length < 4)
                {
                    throw new InvalidOperationException(ResHelper.GetMessage(FramesetResources.CONV_SetValueInvalidName, CurrentElementName));
                }

                int responseIndex;
                if (!int.TryParse(elementParts[2], out responseIndex))
                {
                    throw new InvalidOperationException(ResHelper.GetMessage(FramesetResources.CONV_SetValueInvalidName, CurrentElementName));
                }

                CorrectResponse response;
                bool            isNewResponse = false;
                if (responseIndex >= interaction.CorrectResponses.Count)
                {
                    // It's a new one
                    response      = DataModel.CreateCorrectResponse();
                    isNewResponse = true;
                }
                else
                {
                    // Note the assumption that the index is actually the index into the array.
                    // There's no other way to match them up (since there's no identifier).
                    response = interaction.CorrectResponses[responseIndex];
                }

                if (elementParts[3] != "pattern")
                {
                    throw new InvalidOperationException(ResHelper.GetMessage(FramesetResources.CONV_SetValueInvalidName, CurrentElementName));
                }

                response.Pattern = value;

                if (isNewResponse)
                {
                    interaction.CorrectResponses.Add(response);
                }
            }
            break;

            case "weighting":
            {
                float weighting;
                if (!float.TryParse(value, NumberStyles.Float, NumberFormatInfo.InvariantInfo, out weighting))
                {
                    throw new InvalidOperationException(ResHelper.GetMessage(FramesetResources.CONV_SetValueInvalidValue, value, CurrentElementName));
                }
                interaction.Weighting = weighting;
            }
            break;

            case "student_response":
            {
                // This must be set after InteractionType.

                switch (interaction.InteractionType)
                {
                case InteractionType.TrueFalse:
                {
                    // Unfortunately, cannot use XmlConvert because it doesn't accept 't' and 'f'.
                    if ((value == "t") || (value == "true") || (value == "1"))
                    {
                        interaction.LearnerResponse = true;
                    }
                    // 2 is for Microsoft Office 'SCORM' packages. pass 1 for true and 2 for false
                    else if ((value == "f") || (value == "false") || (value == "0") || (value == "2"))
                    {
                        interaction.LearnerResponse = false;
                    }
                    else
                    {
                        throw new InvalidOperationException(ResHelper.GetMessage(FramesetResources.CONV_SetValueInvalidValue, value, CurrentElementName));
                    }
                }
                break;

                case InteractionType.Numeric:
                {
                    interaction.LearnerResponse = (float)XmlConvert.ToDouble(value);
                }
                break;

                default:
                    interaction.LearnerResponse = value;
                    break;
                }
            }
            break;

            case "result":
            {
                switch (value)
                {
                case "correct":
                    interaction.Result.State = InteractionResultState.Correct;
                    break;

                case "wrong":
                    interaction.Result.State = InteractionResultState.Incorrect;
                    break;

                case "neutral":
                    interaction.Result.State = InteractionResultState.Neutral;
                    break;

                case "unanticipated":
                    interaction.Result.State = InteractionResultState.Unanticipated;
                    break;

                default:
                {
                    // Should be a number. If it's not, then throw a basic error that says the
                    // value is not valid.
                    float resultNumeric;
                    try
                    {
                        resultNumeric = (float)XmlConvert.ToDouble(value);
                    }
                    catch (FormatException)
                    {
                        throw new InvalidOperationException(ResHelper.GetMessage(FramesetResources.CONV_SetValueInvalidValue, value, CurrentElementName));
                    }
                    interaction.Result.NumericResult = resultNumeric;
                    interaction.Result.State         = InteractionResultState.Numeric;
                }
                break;
                }
            }
            break;

            case "latency":
            {
                interaction.Latency = TimeSpanFromRte(value);
            }
            break;

            default:
                throw new InvalidOperationException(ResHelper.GetMessage(FramesetResources.CONV_SetValueInvalidName, CurrentElementName));
            }
        }