private void SaveInputField() { _InputField.Name = Name.Text; if (!_InputField.IsMerchantField) { _InputField.IsRequired = Required.Checked; } _InputField.UserPrompt = UserPrompt.Text; _InputField.InputTypeId = AlwaysConvert.ToInt16(InputTypeId.SelectedValue); _InputField.Columns = AlwaysConvert.ToByte(Columns.Text); _InputField.Rows = AlwaysConvert.ToByte(Rows.Text); _InputField.MaxLength = AlwaysConvert.ToInt16(MaxLength.Text); if (_InputField.IsMerchantField) { _InputField.UseShopBy = UseShopBy.Checked; } //_InputField.IsMerchantField = (bool)ViewState["IsMerchantField"]; //LOOP THROUGH GRID ROWS AND SET MATRIX int rowIndex = 0; int selectedChoice = AlwaysConvert.ToInt(Request.Form["SelectedChoice"]); foreach (GridViewRow row in ChoicesGrid.Rows) { string choiceText = ((TextBox)row.FindControl("ChoiceText")).Text; string choiceValue = ((TextBox)row.FindControl("ChoiceValue")).Text; bool isSelected = ((CheckBox)row.FindControl("IsSelected")).Checked; InputChoice thisChoice = _InputField.InputChoices[rowIndex]; thisChoice.ChoiceText = choiceText; thisChoice.ChoiceValue = choiceValue; thisChoice.IsSelected = isSelected; rowIndex++; } _InputField.Save(); }
public InputChoiceViewModel(InputChoice i) { ModelClass = i; PreviewViewModel = new Preview.Children.InputChoiceViewModel(); (PreviewViewModel as Preview.Children.InputChoiceViewModel).SubChildren = i.SubChildren; Globals.EventAggregator.Subscribe(this); }
/// <summary> /// 添加答案选项 /// </summary> /// <param name="inputChoice">The input choice.</param> /// <exception cref="System.NotImplementedException"></exception> public void InsertInputChoice(InputChoice inputChoice) { if (inputChoice == null) { throw new ArgumentNullException(nameof(inputChoice)); } _inputChoiceRepository.Insert(inputChoice); }
public void setDifficulty(string diff) { if (diff == "easy") { player2 = InputChoice.Random; } else if (diff == "hard") { player2 = InputChoice.HeuristicOne; } }
private void lstInput_SelectedIndexChanged(object sender, EventArgs e) { if (lstComboList.SelectedIndex >= 0 && lstInput.SelectedIndex >= 0) { Combo ActiveCombo = (Combo)lstComboList.Items[lstComboList.SelectedIndex]; InputChoice ActiveInputChoice = ActiveCombo.ListInputChoice[lstInput.SelectedIndex]; cbAttackChoice.SelectedIndex = (int)ActiveInputChoice.AttackInput; cbMovementChoice.SelectedIndex = (int)ActiveInputChoice.MovementInput; txtNextInputDelay.Value = ActiveInputChoice.NextInputDelay; } }
public string ChoixJoueur(ref Personnage personnage) { Random rand = new Random(); if (MortOuRandom) { if (ChoixReponses.Count == 1) { return(ChoixReponses.ElementAt(0).Value); } else { int z = rand.Next(1, ChoixReponses.Count + 1); if (z == ChoixReponses.Count) { Console.WriteLine(ChoixReponses.ElementAt(1).Value); return("Mort"); } else { return(ChoixReponses.ElementAt(0).Value); } } } else // !MortOuRandom { foreach (var kv in ChoixReponses) { Console.Write($"{kv.Key} -- "); Console.WriteLine($"{kv.Value}"); } } int x = InputChoice.Choice(ChoixReponses.Count); string newkey = null; foreach (var c in ChoixReponses) { if (c.Key == x) { newkey = c.Value; break; } } return(newkey); }
protected void AddChoiceButton_Click(object sender, EventArgs e) { // Save the existing dat if (Page.IsValid) { SaveInputField(); } InputChoice newChoice = new InputChoice(); newChoice.InputFieldId = _InputFieldId; newChoice.ChoiceText = "Choice " + ((int)(_InputField.InputChoices.Count + 1)).ToString(); newChoice.Save(); _InputField.InputChoices.Add(newChoice); BindChoicesGrid(); }
protected void ChoicesGrid_RowCommand(object sender, System.Web.UI.WebControls.GridViewCommandEventArgs e) { if (e.CommandName.StartsWith("Move")) { _InputField.InputChoices.Sort("OrderBy"); int inputChoiceId = AlwaysConvert.ToInt(e.CommandArgument.ToString()); int index; switch (e.CommandName) { case "MoveUp": index = _InputField.InputChoices.IndexOf(inputChoiceId); if (index > 0) { InputChoice tempChoice = _InputField.InputChoices[index - 1]; _InputField.InputChoices[index - 1] = _InputField.InputChoices[index]; _InputField.InputChoices[index] = tempChoice; } break; case "MoveDown": index = _InputField.InputChoices.IndexOf(inputChoiceId); if (index < _InputField.InputChoices.Count - 1) { InputChoice tempChoice = _InputField.InputChoices[index + 1]; _InputField.InputChoices[index + 1] = _InputField.InputChoices[index]; _InputField.InputChoices[index] = tempChoice; } break; } // make sure order statuses are in order index = 0; foreach (InputChoice status in _InputField.InputChoices) { status.OrderBy = (short)index; index++; } _InputField.Save(); // rebind grid to reflect update BindChoicesGrid(); } }
private static IElement NewAction(XmlNode xmlNode, IElement parent = null) { IElement element = null; IElement ne = null; // child elements XmlElement importNode = (xmlNode as XmlElement); if (xmlNode.Name == "Action") { switch (importNode.GetAttribute("Type")) { case "AppTree": AppTree appTree = new AppTree(Globals.EventAggregator) { ApplicationVariableBase = importNode.GetAttribute("ApplicationVariableBase"), PackageVariableBase = importNode.GetAttribute("PackageVariableBase"), Title = importNode.GetAttribute("Title"), Condition = importNode.GetAttribute("Condition") }; if (!string.IsNullOrEmpty(importNode.GetAttribute("CenterTitle"))) { appTree.CenterTitle = Convert.ToBoolean(StringToBoolString(importNode.GetAttribute("CenterTitle"))); } if (!string.IsNullOrEmpty(importNode.GetAttribute("Size"))) { appTree.Size = importNode.GetAttribute("Size"); } if (!string.IsNullOrEmpty(importNode.GetAttribute("Expanded"))) { appTree.Expanded = Convert.ToBoolean(StringToBoolString(importNode.GetAttribute("Expanded"))); } if (!string.IsNullOrEmpty(importNode.GetAttribute("ShowBack"))) { appTree.ShowBack = Convert.ToBoolean(StringToBoolString(importNode.GetAttribute("ShowBack"))); } if (!string.IsNullOrEmpty(importNode.GetAttribute("ShowCancel"))) { appTree.ShowCancel = Convert.ToBoolean(StringToBoolString(importNode.GetAttribute("ShowCancel"))); } foreach (XmlNode x in importNode.ChildNodes) { ne = NewAction(x, appTree); /* This is handled by the only valid subelement in AppTree (SoftwareSets) * if(ne is IChildElement) * { * appTree.SubChildren.Add(ne as IChildElement); * } */ } element = appTree; break; case "DefaultValues": DefaultValues defaultValues = new DefaultValues(Globals.EventAggregator) { Condition = importNode.GetAttribute("Condition") }; if (!string.IsNullOrEmpty(importNode.GetAttribute("ValueTypes"))) { string[] defaultValueTypes = importNode.GetAttribute("ValueTypes").Split(','); defaultValues.ValueTypeList.Where(x => x.Name == "All").First().IsSelected = false; foreach (string defaultValueType in defaultValueTypes) { if (defaultValues.ValueTypeList.Where(x => x.Name == defaultValueType).Count() > 0) { defaultValues.ValueTypeList.Where(x => x.Name == defaultValueType).First().IsSelected = true; } } } if (!string.IsNullOrEmpty(importNode.GetAttribute("ShowProgress"))) { defaultValues.ShowProgress = Convert.ToBoolean(StringToBoolString(importNode.GetAttribute("ShowProgress"))); } element = defaultValues; break; case "ErrorInfo": ErrorInfo errorInfo = new ErrorInfo(Globals.EventAggregator) { Image = importNode.GetAttribute("Image"), InfoImage = importNode.GetAttribute("InfoImage"), Name = importNode.GetAttribute("Name"), Title = importNode.GetAttribute("Title"), Condition = importNode.GetAttribute("Condition") }; if (!string.IsNullOrEmpty(importNode.GetAttribute("CenterTitle"))) { errorInfo.CenterTitle = Convert.ToBoolean(StringToBoolString(importNode.GetAttribute("CenterTitle"))); } if (!string.IsNullOrEmpty(importNode.GetAttribute("ShowBack"))) { errorInfo.ShowBack = Convert.ToBoolean(StringToBoolString(importNode.GetAttribute("ShowBack"))); } if (!string.IsNullOrEmpty(importNode.GetAttribute("ShowCancel"))) { errorInfo.ShowCancel = Convert.ToBoolean(StringToBoolString(importNode.GetAttribute("ShowCancel"))); } element = errorInfo; break; case "ExternalCall": ExternalCall externalCall = new ExternalCall(Globals.EventAggregator) { ExitCodeVariable = importNode.GetAttribute("ExitCodeVariable"), Title = importNode.GetAttribute("Title"), Condition = importNode.GetAttribute("Condition") }; if (!string.IsNullOrEmpty(importNode.GetAttribute("ExitCodeVariable"))) { externalCall.ExitCodeVariable = importNode.GetAttribute("ExitCodeVariable"); } if (!string.IsNullOrEmpty(importNode.InnerXml)) { externalCall.Content = CDATARemover(importNode.InnerXml); } element = externalCall; break; case "FileRead": FileRead fileRead = new FileRead(Globals.EventAggregator) { FileName = importNode.GetAttribute("Filename"), Variable = importNode.GetAttribute("Variable"), Condition = importNode.GetAttribute("Condition") }; if (!string.IsNullOrEmpty(importNode.GetAttribute("DeleteLine"))) { fileRead.DeleteLine = Convert.ToBoolean(StringToBoolString(importNode.GetAttribute("DeleteLine"))); } element = fileRead; break; case "Info": Info info = new Info(Globals.EventAggregator) { Image = importNode.GetAttribute("Image"), InfoImage = importNode.GetAttribute("InfoImage"), Name = importNode.GetAttribute("Name"), Title = importNode.GetAttribute("Title"), Condition = importNode.GetAttribute("Condition") }; if (!string.IsNullOrEmpty(importNode.GetAttribute("ShowBack"))) { info.ShowBack = Convert.ToBoolean(StringToBoolString(importNode.GetAttribute("ShowBack"))); } if (!string.IsNullOrEmpty(importNode.GetAttribute("ShowCancel"))) { info.ShowCancel = Convert.ToBoolean(StringToBoolString(importNode.GetAttribute("ShowCancel"))); } if (int.TryParse(importNode.GetAttribute("Timeout"), out int infoTimeout)) { info.Timeout = infoTimeout; } if (!string.IsNullOrEmpty(importNode.GetAttribute("TimeoutAction"))) { info.TimeoutAction = importNode.GetAttribute("TimeoutAction"); } if (!string.IsNullOrEmpty(importNode.InnerXml)) { info.Content = CDATARemover(importNode.InnerXml); } element = info; break; case "InfoFullScreen": InfoFullScreen infoFullScreen = new InfoFullScreen(Globals.EventAggregator) { Image = importNode.GetAttribute("Image") }; if (!string.IsNullOrEmpty(importNode.GetAttribute("BackgroundColor"))) { infoFullScreen.BackgroundColor = importNode.GetAttribute("BackgroundColor"); } if (!string.IsNullOrEmpty(importNode.GetAttribute("TextColor"))) { infoFullScreen.TextColor = importNode.GetAttribute("TextColor"); } if (!string.IsNullOrEmpty(importNode.InnerXml)) { infoFullScreen.Content = CDATARemover(importNode.InnerXml); } break; case "Input": Input input = new Input(Globals.EventAggregator) { Name = importNode.GetAttribute("Name"), Title = importNode.GetAttribute("Title"), Condition = importNode.GetAttribute("Condition") }; if (!string.IsNullOrEmpty(importNode.GetAttribute("Size"))) { input.Size = importNode.GetAttribute("Size"); } if (!string.IsNullOrEmpty(importNode.GetAttribute("ShowBack"))) { input.ShowBack = Convert.ToBoolean(StringToBoolString(importNode.GetAttribute("ShowBack"))); } if (!string.IsNullOrEmpty(importNode.GetAttribute("ShowCancel"))) { input.ShowCancel = Convert.ToBoolean(StringToBoolString(importNode.GetAttribute("ShowCancel"))); } if (!string.IsNullOrEmpty(importNode.GetAttribute("CenterTitle"))) { input.CenterTitle = Convert.ToBoolean(StringToBoolString(importNode.GetAttribute("CenterTitle"))); } foreach (XmlNode x in importNode.ChildNodes) { ne = NewAction(x, input); if (ne is IChildElement) { input.SubChildren.Add(ne as IChildElement); } } element = input; break; case "Preflight": Preflight preflight = new Preflight(Globals.EventAggregator) { Title = importNode.GetAttribute("Title"), Condition = importNode.GetAttribute("Condition") }; if (!string.IsNullOrEmpty(importNode.GetAttribute("Size"))) { preflight.Size = importNode.GetAttribute("Size"); } if (!string.IsNullOrEmpty(importNode.GetAttribute("ShowBack"))) { preflight.ShowBack = Convert.ToBoolean(StringToBoolString(importNode.GetAttribute("ShowBack"))); } if (!string.IsNullOrEmpty(importNode.GetAttribute("ShowCancel"))) { preflight.ShowCancel = Convert.ToBoolean(StringToBoolString(importNode.GetAttribute("ShowCancel"))); } if (!string.IsNullOrEmpty(importNode.GetAttribute("CenterTitle"))) { preflight.CenterTitle = Convert.ToBoolean(StringToBoolString(importNode.GetAttribute("CenterTitle"))); } if (!string.IsNullOrEmpty(importNode.GetAttribute("ShowOnFailureOnly"))) { preflight.CenterTitle = Convert.ToBoolean(StringToBoolString(importNode.GetAttribute("ShowOnFailureOnly"))); } if (int.TryParse(importNode.GetAttribute("Timeout"), out int preflightTimeout)) { preflight.Timeout = preflightTimeout; } if (!string.IsNullOrEmpty(importNode.GetAttribute("TimeoutAction"))) { preflight.TimeoutAction = importNode.GetAttribute("TimeoutAction"); } foreach (XmlNode x in importNode.ChildNodes) { ne = NewAction(x, preflight); if (ne is IChildElement) { preflight.SubChildren.Add(ne as IChildElement); } } element = preflight; break; case "RandomString": RandomString randomString = new RandomString(Globals.EventAggregator) { Variable = importNode.GetAttribute("Variable"), Condition = importNode.GetAttribute("Condition") }; if (!string.IsNullOrEmpty(importNode.GetAttribute("AllowedChars"))) { randomString.AllowedChars = importNode.GetAttribute("AllowedChars"); } if (int.TryParse(importNode.GetAttribute("Length"), out int randomLength)) { randomString.Length = randomLength; } element = randomString; break; case "RegRead": RegRead regRead = new RegRead(Globals.EventAggregator) { Default = importNode.GetAttribute("Default"), Key = importNode.GetAttribute("Key"), Variable = importNode.GetAttribute("Variable"), Value = importNode.GetAttribute("Value"), Condition = importNode.GetAttribute("Condition") }; if (!string.IsNullOrEmpty(importNode.GetAttribute("Reg64"))) { regRead.Reg64 = Convert.ToBoolean(StringToBoolString(importNode.GetAttribute("Reg64"))); } if (!string.IsNullOrEmpty(importNode.GetAttribute("Hive"))) { regRead.Hive = importNode.GetAttribute("Hive"); } element = regRead; break; case "RegWrite": RegWrite regWrite = new RegWrite(Globals.EventAggregator) { Key = importNode.GetAttribute("Key"), Value = importNode.GetAttribute("Value"), Condition = importNode.GetAttribute("Condition") }; if (!string.IsNullOrEmpty(importNode.GetAttribute("Reg64"))) { regWrite.Reg64 = Convert.ToBoolean(StringToBoolString(importNode.GetAttribute("Reg64"))); } if (!string.IsNullOrEmpty(importNode.GetAttribute("Type"))) { regWrite.ValueType = importNode.GetAttribute("Type"); } if (!string.IsNullOrEmpty(importNode.GetAttribute("Hive"))) { regWrite.Hive = importNode.GetAttribute("Hive"); } element = regWrite; break; case "SaveItems": SaveItems saveItems = new SaveItems(Globals.EventAggregator) { Items = importNode.GetAttribute("Items"), Path = importNode.GetAttribute("Path"), Condition = importNode.GetAttribute("Condition") }; element = saveItems; break; case "SoftwareDiscovery": SoftwareDiscovery softwareDiscovery = new SoftwareDiscovery(Globals.EventAggregator) { Condition = importNode.GetAttribute("Condition"), }; foreach (XmlNode x in importNode.ChildNodes) { ne = NewAction(x, softwareDiscovery); if (ne is IChildElement) { softwareDiscovery.SubChildren.Add(ne as IChildElement); } } element = softwareDiscovery; break; case "Switch": Switch switchClass = new Switch(Globals.EventAggregator) { OnValue = importNode.GetAttribute("OnValue"), Condition = importNode.GetAttribute("Condition") }; if (!string.IsNullOrEmpty(importNode.GetAttribute("DontEval"))) { switchClass.DontEval = Convert.ToBoolean(StringToBoolString(importNode.GetAttribute("DontEval"))); } foreach (XmlNode x in importNode.ChildNodes) { ne = NewAction(x, switchClass); if (ne is IChildElement) { switchClass.SubChildren.Add(ne as IChildElement); } } element = switchClass; break; case "TSVar": TSVar tsVar = new TSVar(Globals.EventAggregator) { Condition = importNode.GetAttribute("Condition") }; if (!string.IsNullOrEmpty(importNode.GetAttribute("DontEval"))) { tsVar.DontEval = Convert.ToBoolean(StringToBoolString(importNode.GetAttribute("DontEval"))); } if (!string.IsNullOrEmpty(importNode.GetAttribute("Name"))) { tsVar.Variable = importNode.GetAttribute("Name"); } if (!string.IsNullOrEmpty(importNode.GetAttribute("Variable"))) { tsVar.Variable = importNode.GetAttribute("Variable"); } if (!string.IsNullOrEmpty(importNode.InnerXml)) { tsVar.Content = CDATARemover(importNode.InnerXml); } element = tsVar; break; case "TSVarList": TSVarList tsVarList = new TSVarList(Globals.EventAggregator) { Condition = importNode.GetAttribute("Condition") }; if (!string.IsNullOrEmpty(importNode.GetAttribute("ApplicationVariableBase"))) { tsVarList.ApplicationVariableBase = importNode.GetAttribute("ApplicationVariableBase"); } if (!string.IsNullOrEmpty(importNode.GetAttribute("PackageVariableBase"))) { tsVarList.PackageVariableBase = importNode.GetAttribute("PackageVariableBase"); } foreach (XmlNode x in importNode.ChildNodes) { ne = NewAction(x, tsVarList); if (ne is IChildElement) { tsVarList.SubChildren.Add(ne as IChildElement); } } element = tsVarList; break; case "UserAuth": UserAuth userAuth = new UserAuth(Globals.EventAggregator) { Attributes = importNode.GetAttribute("Attributes"), Domain = importNode.GetAttribute("Domain"), DomainController = importNode.GetAttribute("DomainController"), Group = importNode.GetAttribute("Group"), Title = importNode.GetAttribute("Title") }; if (int.TryParse(importNode.GetAttribute("MaxRetryCount"), out int uaMaxRetryCount)) { userAuth.MaxRetryCount = uaMaxRetryCount; } if (!string.IsNullOrEmpty(importNode.GetAttribute("DisableCancel"))) { userAuth.DisableCancel = Convert.ToBoolean(StringToBoolString(importNode.GetAttribute("DisableCancel"))); } if (!string.IsNullOrEmpty(importNode.GetAttribute("DoNotFallback"))) { userAuth.DoNotFallback = Convert.ToBoolean(StringToBoolString(importNode.GetAttribute("DoNotFallback"))); } if (!string.IsNullOrEmpty(importNode.GetAttribute("GetGroups"))) { userAuth.GetGroups = Convert.ToBoolean(StringToBoolString(importNode.GetAttribute("GetGroups"))); } if (!string.IsNullOrEmpty(importNode.GetAttribute("ShowBack"))) { userAuth.ShowBack = Convert.ToBoolean(StringToBoolString(importNode.GetAttribute("ShowBack"))); } element = userAuth; break; case "Vars": Vars vars = new Vars(Globals.EventAggregator) { Condition = importNode.GetAttribute("Condition") }; if (!string.IsNullOrEmpty(importNode.GetAttribute("Direction"))) { vars.Direction = importNode.GetAttribute("Direction"); } if (!string.IsNullOrEmpty(importNode.GetAttribute("Filename"))) { vars.Filename = importNode.GetAttribute("Filename"); } element = vars; break; case "WMIRead": WMIRead wmiRead = new WMIRead(Globals.EventAggregator) { Class = importNode.GetAttribute("Class"), Default = importNode.GetAttribute("Default"), KeyQualifier = importNode.GetAttribute("KeyQualifier"), Property = importNode.GetAttribute("Property"), Query = importNode.GetAttribute("Query"), Variable = importNode.GetAttribute("Variable"), Condition = importNode.GetAttribute("Condition") }; if (!string.IsNullOrEmpty(importNode.GetAttribute("Namespace"))) { wmiRead.Namespace = importNode.GetAttribute("Namespace"); } element = wmiRead; break; case "WMIWrite": WMIWrite wmiWrite = new WMIWrite(Globals.EventAggregator) { Class = importNode.GetAttribute("Class"), Condition = importNode.GetAttribute("Condition") }; if (!string.IsNullOrEmpty(importNode.GetAttribute("Namespace"))) { wmiWrite.Namespace = importNode.GetAttribute("Namespace"); } foreach (XmlNode x in importNode.ChildNodes) { ne = NewAction(x, wmiWrite); if (ne is IChildElement) { wmiWrite.SubChildren.Add(ne as IChildElement); } } element = wmiWrite; break; } } else { switch (xmlNode.Name) { case "ActionGroup": ActionGroup actionGroup = new ActionGroup(Globals.EventAggregator) { Name = importNode.GetAttribute("Name"), Condition = importNode.GetAttribute("Condition") }; foreach (XmlNode x in importNode.ChildNodes) { ne = NewAction(x); actionGroup.Children.Add(ne); } element = actionGroup; break; case "Case": Case caseClass = new Case(parent) { RegEx = importNode.GetAttribute("RegEx"), Condition = importNode.GetAttribute("Condition") }; if (!string.IsNullOrEmpty(importNode.GetAttribute("CaseInsensitive"))) { caseClass.CaseInsensitive = Convert.ToBoolean(StringToBoolString(importNode.GetAttribute("CaseInsensitive"))); } if (!string.IsNullOrEmpty(importNode.GetAttribute("DontEval"))) { caseClass.DontEval = Convert.ToBoolean(StringToBoolString(importNode.GetAttribute("DontEval"))); } element = caseClass; break; case "Check": Check check = new Check(parent as Preflight) { CheckCondition = importNode.GetAttribute("CheckCondition"), Description = importNode.GetAttribute("Description"), ErrorDescription = importNode.GetAttribute("ErrorDescription"), Text = importNode.GetAttribute("Text"), WarnCondition = importNode.GetAttribute("WarnCondition"), WarnDescription = importNode.GetAttribute("WarnDescription"), Condition = importNode.GetAttribute("Condition") }; element = check; break; case "Choice": Choice choice = new Choice(parent) { Option = importNode.GetAttribute("Option"), Value = importNode.GetAttribute("Value"), AlternateValue = importNode.GetAttribute("AlternateValue"), Condition = importNode.GetAttribute("Condition") }; element = choice; break; case "ChoiceList": ChoiceList choiceList = new ChoiceList(parent) { OptionList = importNode.GetAttribute("OptionList"), ValueList = importNode.GetAttribute("ValueList"), AlternateValueList = importNode.GetAttribute("AlternateValueList"), Condition = importNode.GetAttribute("Condition") }; element = choiceList; break; case "Field": Field field = new Field() { Name = importNode.GetAttribute("Name"), Hint = importNode.GetAttribute("Hint"), List = importNode.GetAttribute("List"), Prompt = importNode.GetAttribute("Prompt"), Question = importNode.GetAttribute("Question"), RegEx = importNode.GetAttribute("RegEx") }; if (!string.IsNullOrEmpty(importNode.GetAttribute("ReadOnly"))) { field.ReadOnly = Convert.ToBoolean(StringToBoolString(importNode.GetAttribute("ReadOnly"))); } element = field; break; case "InputCheckbox": case "CheckboxInput": InputCheckbox inputCheckbox = new InputCheckbox(parent as Input) { CheckedValue = importNode.GetAttribute("CheckedValue"), Default = importNode.GetAttribute("Default"), Question = importNode.GetAttribute("Question"), Variable = importNode.GetAttribute("Variable"), UncheckedValue = importNode.GetAttribute("UncheckedValue"), Condition = importNode.GetAttribute("Condition") }; element = inputCheckbox; break; case "InputChoice": case "ChoiceInput": InputChoice inputChoice = new InputChoice(parent as Input) { AlternateVariable = importNode.GetAttribute("AlternateValue"), Default = importNode.GetAttribute("Default"), Question = importNode.GetAttribute("Question"), Variable = importNode.GetAttribute("Variable"), Condition = importNode.GetAttribute("Condition") }; if (!string.IsNullOrEmpty(importNode.GetAttribute("AutoComplete"))) { inputChoice.AutoComplete = Convert.ToBoolean(StringToBoolString(importNode.GetAttribute("AutoComplete"))); } if (!string.IsNullOrEmpty(importNode.GetAttribute("Required"))) { inputChoice.Required = Convert.ToBoolean(StringToBoolString(importNode.GetAttribute("Required"))); } if (!string.IsNullOrEmpty(importNode.GetAttribute("Sort"))) { inputChoice.Sort = Convert.ToBoolean(StringToBoolString(importNode.GetAttribute("Sort"))); } if (int.TryParse(importNode.GetAttribute("DropDownSize"), out int inputChoiceDropDownSize)) { inputChoice.DropDownSize = inputChoiceDropDownSize; } foreach (XmlNode x in importNode.ChildNodes) { ne = NewAction(x, inputChoice); inputChoice.SubChildren.Add(ne as IChildElement); } element = inputChoice; break; case "InputInfo": case "InfoInput": InputInfo inputInfo = new InputInfo(parent as Input) { Condition = importNode.GetAttribute("Condition") }; if (!string.IsNullOrEmpty(importNode.GetAttribute("Color"))) { inputInfo.Color = importNode.GetAttribute("Color"); } if (int.TryParse(importNode.GetAttribute("DropDownSize"), out int inputInfoNumberOfLines)) { inputInfo.NumberOfLines = inputInfoNumberOfLines; } if (!string.IsNullOrEmpty(importNode.InnerXml)) { inputInfo.Content = CDATARemover(importNode.InnerXml); } element = inputInfo; break; case "InputText": case "TextInput": InputText inputText = new InputText(parent as Input) { Default = importNode.GetAttribute("Default"), Hint = importNode.GetAttribute("Hint"), Prompt = importNode.GetAttribute("Prompt"), Question = importNode.GetAttribute("Question"), RegEx = importNode.GetAttribute("RegEx"), Variable = importNode.GetAttribute("Variable"), Condition = importNode.GetAttribute("Condition") }; if (!string.IsNullOrEmpty(importNode.GetAttribute("ADValidate"))) { inputText.ADValidate = importNode.GetAttribute("ADValidate"); } if (!string.IsNullOrEmpty(importNode.GetAttribute("ForceCase"))) { inputText.ForceCase = importNode.GetAttribute("ForceCase"); } if (!string.IsNullOrEmpty(importNode.GetAttribute("HScroll"))) { inputText.HScroll = Convert.ToBoolean(StringToBoolString(importNode.GetAttribute("HScroll"))); } if (!string.IsNullOrEmpty(importNode.GetAttribute("Password"))) { inputText.Password = Convert.ToBoolean(StringToBoolString(importNode.GetAttribute("Password"))); } if (!string.IsNullOrEmpty(importNode.GetAttribute("ReadOnly"))) { inputText.ReadOnly = Convert.ToBoolean(StringToBoolString(importNode.GetAttribute("ReadOnly"))); } if (!string.IsNullOrEmpty(importNode.GetAttribute("Required"))) { inputText.Required = Convert.ToBoolean(StringToBoolString(importNode.GetAttribute("Required"))); } element = inputText; break; case "Match": Match match = new Match(parent as IParentElement) { DisplayName = importNode.GetAttribute("DisplayName"), Variable = importNode.GetAttribute("Variable"), Version = importNode.GetAttribute("Version"), Condition = importNode.GetAttribute("Condition") }; if (!string.IsNullOrEmpty(importNode.GetAttribute("VersionOperator"))) { match.VersionOperator = importNode.GetAttribute("VersionOperator"); } element = match; break; case "Property": Property property = new Property(parent) { Name = importNode.GetAttribute("Name"), Value = importNode.GetAttribute("Value"), Condition = importNode.GetAttribute("Condition") }; if (!string.IsNullOrEmpty(importNode.GetAttribute("Type"))) { property.Type = importNode.GetAttribute("Type"); } if (!string.IsNullOrEmpty(importNode.GetAttribute("Key"))) { property.Key = Convert.ToBoolean(StringToBoolString(importNode.GetAttribute("Key"))); } element = property; break; case "Set": Set set = new Set(parent) { Name = importNode.GetAttribute("Name"), Condition = importNode.GetAttribute("Condition") }; foreach (XmlNode x in importNode.ChildNodes) { ne = NewAction(x, set); set.SubChildren.Add(ne as IChildElement); } element = set; break; case "SoftwareGroup": SoftwareGroup softwareGroup = new SoftwareGroup(parent) { Id = importNode.GetAttribute("Id"), Label = importNode.GetAttribute("Label"), Condition = importNode.GetAttribute("Condition") }; if (!string.IsNullOrEmpty(importNode.GetAttribute("Default"))) { softwareGroup.Default = Convert.ToBoolean(StringToBoolString(importNode.GetAttribute("Default"))); } if (!string.IsNullOrEmpty(importNode.GetAttribute("Required"))) { softwareGroup.Required = Convert.ToBoolean(StringToBoolString(importNode.GetAttribute("Required"))); } foreach (XmlNode x in importNode.ChildNodes) { ne = NewAction(x, softwareGroup); softwareGroup.SubChildren.Add(ne as IChildElement); } element = softwareGroup; break; case "SoftwareListRef": SoftwareListRef softwareListRef = new SoftwareListRef(parent as IParentElement) { Id = importNode.GetAttribute("Id"), Condition = importNode.GetAttribute("Condition") }; element = softwareListRef; break; case "SoftwareRef": SoftwareRef softwareRef = new SoftwareRef(parent) { Id = importNode.GetAttribute("Id"), Condition = importNode.GetAttribute("Condition") }; if (!string.IsNullOrEmpty(importNode.GetAttribute("Hidden"))) { softwareRef.Hidden = Convert.ToBoolean(StringToBoolString(importNode.GetAttribute("Hidden"))); } if (!string.IsNullOrEmpty(importNode.GetAttribute("Default"))) { softwareRef.Default = Convert.ToBoolean(StringToBoolString(importNode.GetAttribute("Default"))); } if (!string.IsNullOrEmpty(importNode.GetAttribute("Required"))) { softwareRef.Required = Convert.ToBoolean(StringToBoolString(importNode.GetAttribute("Required"))); } element = softwareRef; break; case "SoftwareSets": AppTree at = parent as AppTree; ObservableCollection <IChildElement> e = new ObservableCollection <IChildElement>(); foreach (XmlNode x in importNode.ChildNodes) { ne = NewAction(x, at); e.Add(ne as IChildElement); } at.SubChildren = e; element = null; break; case "Text": Text text = new Text(parent as IParentElement) { Type = importNode.GetAttribute("Type"), Value = importNode.GetAttribute("Value"), Condition = importNode.GetAttribute("Condition") }; element = text; break; case "Variable": Variable variable = new Variable(parent) { Name = importNode.GetAttribute("Name"), Condition = importNode.GetAttribute("Condition") }; if (!string.IsNullOrEmpty(importNode.GetAttribute("DontEval"))) { variable.DontEval = Convert.ToBoolean(StringToBoolString(importNode.GetAttribute("DontEval"))); } if (!string.IsNullOrEmpty(importNode.InnerXml)) { variable.Content = CDATARemover(importNode.InnerXml); } element = variable; break; } } return(element); }
/// <summary> /// 题目录入,不同类型的题干和答案解析 /// </summary> /// <returns></returns> public AnswerResult TiMuFormat() { var regKong = new Regex("\\[k.*?type=\"(.*?)\"[\\s\\S]*?score=\"([0-9.]+)\"]([\\s\\S]*?)\\[/k\\]", RegexOptions.Multiline); var trunk = "";//题干 var inputs = new List <Input>(); var inputChoices = new List <InputChoice>(); var deleteInputIds = new List <Input>();//保存要被删除的input switch (_timuJsonModel.ChoiceType) { #region 单选 case (int)ChoiceType.RdoRdo: trunk = _timuJsonModel.TiGan + "<kbd></kbd>"; //题目 _timu.Trunk = trunk; _timu.Analysis = _timuJsonModel.Analyse; _timu.Answer = _timuJsonModel.Explain; _timu.Comment = _timuJsonModel.Comment; _timu.TiMuTypeId = _timuJsonModel.TimuType; _timu.Year = DateTime.Now.Year; //判断是否有答案,没有就创建对象,有就修改 if (_timu.Inputs.Any()) { var inputR = _timu.Inputs.ToList()[0]; //答案 inputR.InputType = "radio"; inputR.InputCode = _timu.Id.ToString(); inputR.InputAnswer = AlphabetToNumber(_timuJsonModel.ChoicesIput.RightAnswer); inputR.Score = decimal.Parse(_timuJsonModel.ChoicesIput.Score.ToString()); inputR.Order = 1; inputR.BaseType = "choice"; var choices = _timuJsonModel.ChoicesIput.InputChoice; //判断是否有选项,没有就创建对象,有就修改 if (_timu.Inputs.ToList()[0].InputChoice.Any()) { var choiceList = _timu.Inputs.ToList()[0].InputChoice.OrderBy(d => d.Order).ToList(); for (int i = 0; i < choiceList.Count; i++) { var choice = choiceList[i]; choice.ChoiceContent = choices[i].ChoiceContent; choice.Order = choices[i].Order; //添加选项到集合 inputChoices.Add(choice); } if (choices.Count > choiceList.Count) { //新增选项 for (int i = choiceList.Count; i < choices.Count; i++) { var choice = new InputChoice() { Id = Guid.NewGuid(), InputId = inputR.Id, ChoiceContent = choices[i].ChoiceContent, Score = decimal.Parse("0"), Order = i + 1 }; //添加选项到集合 inputChoices.Add(choice); } } } else { for (int i = 0; i < choices.Count; i++) { var choice = new InputChoice() { Id = Guid.NewGuid(), InputId = inputR.Id, ChoiceContent = choices[i].ChoiceContent, Score = decimal.Parse("0"), Order = i + 1 }; //添加选项到集合 inputChoices.Add(choice); } } //添加答案到集合 inputs.Add(inputR); } else { var inputR = new Input() { //答案 Id = Guid.NewGuid(), TmId = _timu.Id, InputCode = _timu.Id.ToString(), InputType = "radio", BaseType = "choice", InputAnswer = AlphabetToNumber(_timuJsonModel.ChoicesIput.RightAnswer), Score = decimal.Parse(_timuJsonModel.ChoicesIput.Score.ToString()), Order = 1 }; var choiceList = _timuJsonModel.ChoicesIput.InputChoice.OrderBy(d => d.Order).ToList(); for (int i = 0; i < choiceList.Count; i++) { var choice = new InputChoice() { Id = Guid.NewGuid(), InputId = inputR.Id, ChoiceContent = choiceList[i].ChoiceContent, Score = decimal.Parse("0"), Order = i + 1 }; //添加选项到集合 inputChoices.Add(choice); } //添加答案到集合 inputs.Add(inputR); } break; #endregion #region 多选 case (int)ChoiceType.RdoCk: trunk = _timuJsonModel.TiGan + "<kbd></kbd>"; //题目 _timu.Trunk = trunk; _timu.Analysis = _timuJsonModel.Analyse; _timu.Answer = _timuJsonModel.Explain; _timu.Comment = _timuJsonModel.Comment; _timu.TiMuTypeId = _timuJsonModel.TimuType; _timu.Year = DateTime.Now.Year; //判断是否有答案,没有就创建对象,有就修改 if (_timu.Inputs.Any()) { var inputR = _timu.Inputs.ToList()[0]; //答案 inputR.InputType = "checkbox-all"; inputR.BaseType = "choice"; inputR.InputCode = _timu.Id.ToString(); inputR.InputAnswer = AlphabetToNumber(_timuJsonModel.ChoicesIput.RightAnswer); inputR.Score = decimal.Parse(_timuJsonModel.ChoicesIput.Score.ToString()); inputR.Order = 1; var choices = _timuJsonModel.ChoicesIput.InputChoice; //判断是否有选项,没有就创建对象,有就修改 if (_timu.Inputs.ToList()[0].InputChoice.Any()) { var choiceList = _timu.Inputs.ToList()[0].InputChoice.OrderBy(d => d.Order).ToList(); for (int i = 0; i < choiceList.Count; i++) { var choice = choiceList[i]; choice.ChoiceContent = choices[i].ChoiceContent; choice.Order = choices[i].Order; //添加选项到集合 inputChoices.Add(choice); } if (choices.Count > choiceList.Count) { //新增选项 for (int i = choiceList.Count; i < choices.Count; i++) { var choice = new InputChoice() { Id = Guid.NewGuid(), InputId = inputR.Id, ChoiceContent = choices[i].ChoiceContent, Score = decimal.Parse("0"), Order = i + 1 }; //添加选项到集合 inputChoices.Add(choice); } } //添加答案到集合 inputs.Add(inputR); } else { for (int i = 0; i < choices.Count; i++) { var choice = new InputChoice() { Id = Guid.NewGuid(), InputId = inputR.Id, ChoiceContent = choices[i].ChoiceContent, Score = decimal.Parse("0"), Order = i + 1 }; //添加选项到集合 inputChoices.Add(choice); } } } else { var inputC = new Input() { //答案 Id = Guid.NewGuid(), TmId = _timu.Id, InputCode = _timu.Id.ToString(), InputType = "checkbox-all", BaseType = "choice", InputAnswer = AlphabetToNumber(_timuJsonModel.ChoicesIput.RightAnswer), Score = decimal.Parse(_timuJsonModel.ChoicesIput.Score.ToString()), Order = 1 }; var choiceList = _timuJsonModel.ChoicesIput.InputChoice.OrderBy(d => d.Order).ToList(); for (int i = 0; i < choiceList.Count; i++) { var choice = new InputChoice() { Id = Guid.NewGuid(), InputId = inputC.Id, ChoiceContent = choiceList[i].ChoiceContent, Score = decimal.Parse("0"), Order = i + 1 }; //添加选项到集合 inputChoices.Add(choice); } //添加答案到集合 inputs.Add(inputC); } break; #endregion #region 判断 case (int)ChoiceType.RdoTf: _timu.Trunk = _timuJsonModel.TiGan; _timu.Analysis = _timuJsonModel.Analyse; _timu.Answer = _timuJsonModel.Explain; _timu.Comment = _timuJsonModel.Comment; _timu.TiMuTypeId = _timuJsonModel.TimuType; _timu.Year = DateTime.Now.Year; //如果已经存在用户答案 if (_timu.Inputs.Any()) { var input = _timu.Inputs.ToList()[0]; input.InputAnswer = AlphabetToNumber(_timuJsonModel.ChoicesIput.RightAnswer); input.Score = decimal.Parse(_timuJsonModel.ChoicesIput.Score.ToString()); input.InputCode = _timu.Id + "_a"; input.BaseType = "choice"; input.InputType = "radio-TF"; var choices = _timuJsonModel.ChoicesIput.InputChoice; //如果有选项 if (_timu.Inputs.ToList()[0].InputChoice.Any()) { var choiceList = _timu.Inputs.ToList()[0].InputChoice.OrderBy(d => d.Order).ToList(); for (int i = 0; i < choices.Count; i++) { var choice = choiceList[i]; choice.ChoiceContent = choices.OrderBy(d => d.Order).ToList()[i].ChoiceContent; //添加选项到集合 inputChoices.Add(choice); } } else { for (int i = 0; i < choices.Count(); i++) { var choice = new InputChoice() { Id = Guid.NewGuid(), InputId = input.Id, ChoiceContent = choices[i].ChoiceContent, Score = 0, Order = choices[i].Order }; //添加选项到集合 inputChoices.Add(choice); } } //添加答案到集合 inputs.Add(input); } else { var input = new Input() { Id = Guid.NewGuid(), TmId = _timu.Id, InputCode = _timu.Id + "_a", BaseType = "choice", InputType = "radio-TF", InputAnswer = AlphabetToNumber(_timuJsonModel.ChoicesIput.RightAnswer), Score = decimal.Parse(_timuJsonModel.ChoicesIput.Score.ToString()), Order = 1, InputScore = null }; var choiceList = _timuJsonModel.ChoicesIput.InputChoice.OrderBy(d => d.Order).ToList(); for (int i = 0; i < choiceList.Count(); i++) { var choice = new InputChoice() { Id = Guid.NewGuid(), InputId = input.Id, ChoiceContent = choiceList[i].ChoiceContent, Score = 0, Order = choiceList[i].Order, }; //添加选项到集合 inputChoices.Add(choice); } //添加答案到集合 inputs.Add(input); } break; #endregion #region 填空 case (int)ChoiceType.RdoText: _timu.Analysis = _timuJsonModel.Analyse; _timu.Answer = _timuJsonModel.Explain; _timu.Comment = _timuJsonModel.Comment; _timu.TiMuTypeId = _timuJsonModel.TimuType; _timu.Year = DateTime.Now.Year; var matchCollection = regKong.Matches(_timuJsonModel.TiGan); if (matchCollection.Count < _timu.Inputs.Count) { //先更新 for (int i = 1; i <= matchCollection.Count; i++) { ClassiFication(matchCollection[i - 1], i, inputs, "update"); } //删除 deleteInputIds = DeleteInput(inputs); } else { //先更新 for (int i = 1; i <= _timu.Inputs.Count; i++) { ClassiFication(matchCollection[i - 1], i, inputs, "update"); } if (matchCollection.Count > _timu.Inputs.Count) { //添加 for (int i = _timu.Inputs.Count; i < matchCollection.Count; i++) { ClassiFication(matchCollection[i], i + 1, inputs, "add"); } } } for (int i = 0; i < matchCollection.Count; i++) { var type = matchCollection[i].Groups[1]; var score = matchCollection[i].Groups[2]; var text = matchCollection[i].Groups[3]; if (type.ToString() == "shushi") { _timuJsonModel.TiGan = regKong.Replace(_timuJsonModel.TiGan, "<kbd>" + text + "</kbd>", 1, 0); } else { _timuJsonModel.TiGan = regKong.Replace(_timuJsonModel.TiGan, "<kbd></kbd>", 1, 0); } } _timu.Trunk = _timuJsonModel.TiGan; break; #endregion } return(new AnswerResult() { TiMu = _timu, InputList = inputs, InputChoiceList = inputChoices, DeleteInputs = deleteInputIds }); }