public static MvcHtmlString ThemedChoiceListFor <TModel, TChoiceItem, TValue, TDisplay> ( this HtmlHelper <TModel> htmlHelper, Expression <Func <TModel, IEnumerable <TValue> > > expression, ChoiceList <TChoiceItem, TValue, TDisplay> choiceList, string name = "ChoiceList") where TValue : IComparable { if (expression == null) { throw (new ArgumentNullException("expression")); } if (choiceList == null) { throw (new ArgumentNullException("choiceList")); } string themeName = ThemedControlsStrings.GetTheme(); ViewDataDictionary <dynamic> dataDictionary = new ViewDataDictionary <dynamic>(htmlHelper.ViewData.Model); dataDictionary.TemplateInfo.HtmlFieldPrefix = htmlHelper.ViewData.TemplateInfo.HtmlFieldPrefix; dataDictionary["ThemeParams"] = new ChoiceListDescription { Expression = expression, ChoiceList = choiceList, HtmlHelper = htmlHelper }; MvcHtmlString res; res = htmlHelper.Partial("Themes/" + themeName + "/" + name, dataDictionary); return(res); }
private void GoodResult(ChoiceList choice) { if (choice.loot.Capacity != 0) { positiveBox.text = "You recieved "; for (int i = 0; i < choice.loot.Capacity; i++) { if (choice.loot[i].name == "Coins" || choice.loot[i].name == "Gold") { positiveBox.text += choice.loot[i].amount + " gold pieces"; items.SendCoins(choice.loot[i].amount); } else { positiveBox.text += choice.loot[i].amount + " " + choice.loot[i].name; items.UpdateItems(choice.loot[i].name, choice.loot[i].amount); if ((choice.loot.Capacity - i == 1)) { positiveBox.text += "!"; } else { positiveBox.text += ", "; } } } } }
public void AcceptChoice(ChoiceList choice, GameObject panel) { ResetPanel(); panel.SetActive(false); storyBox.text = choice.textToDisplay; resultPanel.SetActive(true); currentHealth = items.CurrentHealth(); timer = 5; if (currentHealth == 0) { Death("You stumbled, you tired but in the end you have died from a lack of food", "Even the dogs didn't want what was left"); } if (choice.badChoice) { if (choice.creatureDamage && (items.ReturnBait() > 0)) { isTimer = true; countdownText.gameObject.SetActive(true); baitButton.gameObject.SetActive(true); fightButton.gameObject.SetActive(true); choiceMade = choice; } else { BadResult(choice, 1); } } else { GoodResult(choice); } FindObjectOfType <InventoryDisplay>().UpdateItemsDisplay(); }
CreateChoiceList <VM, TItem, TValue, TDisplay>( this HtmlHelper <VM> htmlHelper, Expression <Func <VM, IEnumerable <TItem> > > expression, Expression <Func <TItem, TValue> > valueSelector, Expression <Func <TItem, TDisplay> > displaySelector, Func <TItem, object> labelAttributesSelector = null, Func <TItem, object> valueAttributesSelector = null, bool usePrompt = true, string overridePrompt = null) { if (expression == null) { throw (new ArgumentNullException("expression")); } IEnumerable <TItem> items = null; try { items = expression.Compile().Invoke(htmlHelper.ViewData.Model); } catch { } ChoiceList <TItem, TValue, TDisplay> res = new ChoiceList <TItem, TValue, TDisplay> (items, valueSelector, displaySelector, valueAttributesSelector, labelAttributesSelector, usePrompt, overridePrompt); res.origin = expression; res.isInClientBlock = htmlHelper.ClientBindings() != null; return(res); }
protected void SubmitNumberChoice_Click(object sender, EventArgs e) { //this is the submit button //to grab the contents of a control will DEPEND on the control access type //for TextBox, label, Literal use. Text //for list(RadioButton, DropdownList) you may use one of // .SelectedValue (best), SelectedIndev(physical location), SelectItem.Text //for Checkbox use Checked (boolean) //for the most part, all data from a control returns as a string //since the control (object) is on the "RIGHT" side of an assignment statement, // the object property uses its GET string submitchoice = NumberChoice.Text; if (string.IsNullOrEmpty(submitchoice)) { //"LEFT" side uses the property's SET MessageLabel.Text = "You did not enter a value for your program choice"; //clean up selection ChoiceList.ClearSelection(); //another way: //Choice.SelectedIndex = -1; //-1 is a non existent index CollectionChoiceList.SelectedIndex = 0; //has my prompt AlterLabel.ForeColor = System.Drawing.Color.Black; DisplayDataRO.Text = ""; } else { //"RIGHT" side uses the property's GET // you can set/get the radiobuttonlist choice by either using // .SelectedValue or .SelectedIndex or .SelctedItem.Text //it is BEST to use .SelectedValue for positioning ChoiceList.SelectedValue = submitchoice; //place a check mark in the check box, if the chosen course is a program if (submitchoice.Equals("2") || submitchoice.Equals("4")) { ProgrammingCourseActive.Checked = true; AlterLabel.ForeColor = System.Drawing.Color.BlueViolet; } else { ProgrammingCourseActive.Checked = false; AlterLabel.ForeColor = System.Drawing.Color.Black; } //DDL can be positioned using: // .SelectedValue or .SelectedIndex or .SelctedItem.Text //it is BEST to use .SelectedValue for positioning CollectionChoiceList.SelectedValue = submitchoice; //demonstration of what is obtaine by the different .Selectedxxxxxx DisplayDataRO.Text = CollectionChoiceList.SelectedItem.Text + " at index " + CollectionChoiceList.SelectedIndex + " having a value of " + CollectionChoiceList.SelectedValue; } }
protected void ResetFields() { DisplayDataRO.Text = ""; ProgrammingCourseActive.Checked = false; ChoiceList.ClearSelection(); //ChoiceList.SelectedIndex = -1; //This is an optional way of deselecting CollectionChoiceList.ClearSelection(); AlterLabel.ForeColor = System.Drawing.Color.Black; }
protected void ResetFields() { NumberChoice.Text = ""; ChoiceList.ClearSelection(); //ChoiceList.SelectedIndex = -1; //index -1 will not be found, optionally way CollectionChoiceList.ClearSelection(); ProgrammingCourseActive.Checked = false; AlterLabel.ForeColor = System.Drawing.Color.Black; }
public MainMenuState(CommanderConsole commander) { _commander = commander; this._choiceList = new ChoiceList( new UserInputChoice("Option 1"), new UserInputChoice("Option 2"), new UserInputChoice("Exit Program") ); }
internal static void WriteListOfChoices(ChoiceList choiceList) { // EXAMPLE: // 1: Some User Choice foreach (var choice in choiceList) { Console.Write(choice.Key); Console.Write(": "); Console.WriteLine(choice.Value.Description); } }
private void frmStdExam_Load(object sender, EventArgs e) { myCombos = new ComboBox[] { comboBox1, comboBox2, comboBox3, comboBox4, comboBox5, comboBox6, comboBox7, comboBox8, comboBox9, comboBox10 }; questions = QuestionManager.getQuestionList(Convert.ToInt32(frmLogin.StID), Convert.ToInt32(frmStudentCrs.CrsID)); qBS = new BindingSource(questions, ""); quesGrid.DataSource = qBS; quesGrid.ReadOnly = true; quesGrid.Columns["Q_Id"].Visible = false; quesGrid.Columns["Q_Ans"].Visible = false; quesGrid.Columns["State"].Visible = false; quesGrid.Columns["Q_Type"].Visible = false; quesGrid.Columns["Q_Grade"].Visible = false; quesGrid.Columns["Q_Desc"].HeaderText = "Questions:"; quesGrid.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells; quesGrid.ColumnHeadersVisible = false; quesGrid.RowHeadersVisible = false; foreach (DataGridViewRow x in quesGrid.Rows) { x.MinimumHeight = 40; } quesGrid.AdvancedCellBorderStyle.All = DataGridViewAdvancedCellBorderStyle.None; DataGridViewCellStyle columnHeaderStyle = new DataGridViewCellStyle(); columnHeaderStyle.BackColor = Color.LightSkyBlue; columnHeaderStyle.Font = new Font("Verdana", 9, FontStyle.Bold); quesGrid.EnableHeadersVisualStyles = false; quesGrid.SelectionMode = DataGridViewSelectionMode.FullRowSelect; for (int i = 0; i < myCombos.Length; i++) { int id = Convert.ToInt32(quesGrid.Rows[i].Cells[0].Value.ToString()); choices = ChoiceManager.questionChoices(id); chBS = new BindingSource(choices, ""); myCombos[i].DataSource = chBS; //string combo = c.Name; myCombos[i].DisplayMember = "Choice1"; myCombos[i].ValueMember = "Q_Id"; } formGrade = new frmCrsGrade(); exam = ExamManager.getExamDuration(Convert.ToInt32(frmStudentCrs.CrsID)); examBS = new BindingSource(exam, ""); durationLbl.DataBindings.Add("Text", examBS, "Ex_duration", true); }
protected void SubmitNumberChoice_Click(object sender, EventArgs e) { //to grab the contents of a control will DEPEND on the cntrol access type // for TextBox, label, or literal use .text // for List (RadiobuttonList, DropDownList) you may use one of: // .SelectedValue(best), .SelectedIndex(phyical location), .SelectedItem.Text // for CheckBox use .Checked (boolean) //for the most part, all data from a control returns as a string //since the control (object) is on the "right" side of an assignment (set;), statement, the object Property uses its (get;) string submitchoice = NumberChoice.Text; if (string.IsNullOrEmpty(submitchoice)) { //"left" side uses the Property's SET MessageLabel.Text = "You did not enter a value for your program choice"; ChoiceList.ClearSelection(); //ChoiceList.SelectedIndex = -1; //-1 is a non-existent index. similar, but not necessary //CollectionChoiceList.ClearSelection(); CollectionChoiceList.SelectedIndex = 0; //0 has my prompt AlterLabel.ForeColor = System.Drawing.Color.Black; DisplayDataRO.Text = ""; } else { // you can set/get the radiobuttonlist choice by either using // .SelectedValue or .SelectedIndex or SelectedItem.Text // it is BEST to use .SelectedValue for positioning (go an find the line with the proper value and display as desired) // using .SelectedIndex requires you know the exact physical location ChoiceList.SelectedValue = submitchoice; if (submitchoice.Equals("2") || submitchoice.Equals("4")) { ProgrammingCourseActive.Checked = true; AlterLabel.ForeColor = System.Drawing.Color.AliceBlue; } else { ProgrammingCourseActive.Checked = false; AlterLabel.ForeColor = System.Drawing.Color.Black; } //DDL an be positioned using // .SelectedValue or .SelectedIndex or SelectedItem.Text // it is BEST to use .SelectedValue for positioning CollectionChoiceList.SelectedValue = submitchoice; //demonstration of what is obtained by the different by the .SelectedIndex or SelectedItem.Text DisplayDataRO.Text = CollectionChoiceList.SelectedItem.Text + " at index " + CollectionChoiceList.SelectedIndex + " having a value of " + CollectionChoiceList.SelectedValue; } }
public void ImportFromModel(object model, params object[] context) { TValue input = default(TValue); if (model != null) { input = (TValue)model; } ChoiceList <TChoiceItem, TValue, TDisplay> choiceList = context[0] as ChoiceList <TChoiceItem, TValue, TDisplay>; List <MutualExclusionListItem <TValue> > items = new List <MutualExclusionListItem <TValue> >(); foreach (TChoiceItem item in choiceList.Items) { MutualExclusionListItem <TValue> mutualExclusionListItem = new MutualExclusionListItem <TValue>(); mutualExclusionListItem.Value = choiceList.ValueSelector(item); mutualExclusionListItem.Label = choiceList.DisplaySelector(item).ToString(); if (choiceList.LabelAttributesSelector != null) { mutualExclusionListItem.LabelAttributes = choiceList.LabelAttributesSelector(item); } else { mutualExclusionListItem.LabelAttributes = new { } }; if (choiceList.DisplayAttributesSelector != null) { mutualExclusionListItem.DisplayAttributes = choiceList.DisplayAttributesSelector(item); } else { mutualExclusionListItem.DisplayAttributes = new { } }; items.Add(mutualExclusionListItem); if (((IComparable)input).CompareTo(mutualExclusionListItem.Value) == 0) { mutualExclusionListItem.Selected = true; } } Items = items.ToArray(); } }
internal static ChoiceList DataTableToTitleList(DataTable Dt) { ChoiceList choices = new ChoiceList(); try { foreach (DataRow item in Dt.Rows) { choices.Add(DataRowToTitle(item)); } } catch { } return(choices); }
public override FObject[] LoadScene(screenClass screen = null) { //Resource res = Resources.GetResource("beachmoon-1.jpg"); //res.resize(800, 800); //Bitmap b = res.bmp; Bitmap b = Resources.GetResource("beachmoon-1.jpg").asBmp(); b = Resources.ResizeBmp(800, 800, b); FObject background = new FObject(0, 0, b); background.onMouseHover += Background_onMouseHover; ChoiceList menus = new ChoiceList(0, 0, 100, new string[] { "Play", "Credits" }, Resources.ResizeBmp(200, 50, Resources.GetResource("building-1.jpg").asBmp())); menus.Center(800, 400); //Reverse order as they should appear. return(new FObject[] { menus.choices[0], menus.choices[1], background }); }
DualSelectFor <TModel, TChoiceItem, TValue, TDisplay> (this HtmlHelper <TModel> htmlHelper, Expression <Func <TModel, IEnumerable <TValue> > > expression, ChoiceList <TChoiceItem, TValue, TDisplay> choiceList, IDictionary <string, object> attributeExtensions = null) { IEnumerable <TValue> values = default(IEnumerable <TValue>); if (expression == null) { throw (new ArgumentNullException("expression")); } try { values = expression.Compile().Invoke(htmlHelper.ViewData.Model); } catch { } if (choiceList == null) { throw (new ArgumentNullException("choiceList")); } if (values == null) { values = new List <TValue>(); } var fullPropertyPath = ExpressionHelper.GetExpressionText(expression); return(new DualSelect <TModel, IEnumerable <TValue>, TChoiceItem, TValue, TDisplay>() { CurrHtmlHelper = htmlHelper, Prefix = fullPropertyPath, Value = values, CurrChoiceList = choiceList, AttributeExtensions = attributeExtensions }); }
public static MvcHtmlString DropDownList <VM, TItem, TDisplay, TValue>( this HtmlHelper <VM> htmlHelper, string name, IEnumerable <TValue> value, object htmlAttributes, ChoiceList <TItem, TValue, TDisplay> items) { return(DropDownbase <VM, TItem, TDisplay, TValue>( htmlHelper, name, value, prepareItems(items, false, null), new RouteValueDictionary(htmlAttributes), true, items is IGroupedChoiceList)); }
public static MvcHtmlString MutualExclusionListFor <TModel, TValue, TChoiceItem, TDisplay> ( this HtmlHelper <TModel> htmlHelper, Expression <Func <TModel, TValue> > expression, ChoiceList <TChoiceItem, TValue, TDisplay> choiceList, bool useTemplate = false, string templateName = null) where TValue : IComparable, IConvertible { if (expression == null) { throw (new ArgumentNullException("expression")); } if (choiceList == null) { throw (new ArgumentNullException("choiceList")); } TValue value = default(TValue); try { value = expression.Compile().Invoke(htmlHelper.ViewData.Model); } catch { } var fullPropertyPath = htmlHelper.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName( ExpressionHelper.GetExpressionText(expression)); MutualExclusionList <TChoiceItem, TValue, TDisplay> displayModel = new MutualExclusionList <TChoiceItem, TValue, TDisplay>(); displayModel.ImportFromModel(value, new object[] { choiceList }); StringBuilder sb = new StringBuilder(); sb.Append(htmlHelper.Hidden(fullPropertyPath + ".$$", (typeof(MutualExclusionList <TChoiceItem, TValue, TDisplay>)).AssemblyQualifiedName).ToString()); int index = 0; foreach (MutualExclusionListItem <TValue> item in displayModel.Items) { sb.Append(htmlHelper.Hidden (EnumerableHelper.CreateSubIndexName(fullPropertyPath + ".Items", index) + ".Value", item.Value)); index++; } if (useTemplate) { if (templateName == null) { templateName = typeof(MutualExclusionList <TChoiceItem, TValue, TDisplay>).Name; } ViewDataDictionary <MutualExclusionList <TChoiceItem, TValue, TDisplay> > dataDictionary = new ViewDataDictionary <MutualExclusionList <TChoiceItem, TValue, TDisplay> >(displayModel); dataDictionary.TemplateInfo.HtmlFieldPrefix = fullPropertyPath; sb.Append(htmlHelper.Partial(templateName, dataDictionary).ToString()); } else { index = 0; foreach (MutualExclusionListItem <TValue> item in displayModel.Items) { sb.Append("<div>"); sb.Append(htmlHelper.RadioButton( EnumerableHelper.CreateSubIndexName(fullPropertyPath + ".Items", index) + ".Selected", item.Selected, item.DisplayAttributes)); sb.Append(" "); sb.Append(string.Format(CultureInfo.InvariantCulture, "<span {0}>{1}</span>", BasicHtmlHelper.GetAttributesString(item.LabelAttributes), item.Label)); sb.Append("</div>"); index++; } } return(MvcHtmlString.Create(sb.ToString())); }
private void BadResult(ChoiceList choice, int choiceMade) { if (choiceMade == 1) { int dmgTaken = 0; if (choice.damageTaken.Length > 1) { negativeBox.text = "You took " + choice.damageTaken[1].ToString() + " DMG because you had "; } if (CheckDefences(choice.protectiveItems)) { if (currentHealth - choice.damageTaken[1] <= 0 && choice.tookDamage) { if (choice.deathMessage.Length > 0) { Death(choice.textToDisplay, choice.deathMessage); } else { Death(choice.textToDisplay, "The wounds have caught up to you. You have died!"); } } else { if (choice.encounterResult.Length > 0) { encounterBox.text = choice.encounterResult; } negativeBox.text += " eqipped"; currentHealth -= choice.damageTaken[1]; dmgTaken = choice.damageTaken[1]; GoodResult(choice); } } else { if (choice.tookDamage) { currentHealth -= choice.damageTaken[0]; dmgTaken = choice.damageTaken[0]; if (currentHealth <= 0) { if (choice.deathMessage.Length > 0) { Death(choice.textToDisplay, choice.deathMessage); } else { Death(choice.textToDisplay, "The wounds have caught up to you. You have died!"); } } else { if (choice.encounterResult.Length > 0) { encounterBox.text = choice.encounterResult; } negativeBox.text = "You took " + choice.damageTaken[0].ToString() + " damage"; GoodResult(choice); } } } if (choice.lootLost.Capacity > 0) { if (choice.lootLost[0].name == "All") { for (int i = 0; i < choice.lootLost.Capacity; i++) { items.EmptyItem(choice.lootLost[i].name); } } lootBox.text = "You have lost "; for (int i = 0; i < choice.lootLost.Capacity; i++) { items.RemoveItem(choice.lootLost[i].name, choice.lootLost[i].amount); lootBox.text += choice.lootLost[i].amount + " " + choice.lootLost[i].name; if (choice.lootLost.Capacity - i == 1) { lootBox.text += "!"; } else { lootBox.text += ", "; } } } items.CurrentHealth(-dmgTaken); } if (choiceMade == 2) { encounterBox.text = ""; storyBox.text = "Throwing the meat you the creatures you quickly make your escape, unnoticed. \n \n Nice Move!"; items.RemoveItem("Bait", -1); } }
public static MvcHtmlString DropDownListFor <VM, TItem, TDisplay, TValue>( this HtmlHelper <VM> htmlHelper, Expression <Func <VM, IEnumerable <TValue> > > expression, object htmlAttributes, ChoiceList <TItem, TValue, TDisplay> items) { return(DropDownListForBase <VM, TItem, TDisplay, TValue>( htmlHelper, expression, new RouteValueDictionary(htmlAttributes), items)); }
private static List <ExtendedSelectListItem> prepareItems <TItem, TDisplay, TValue>(ChoiceList <TItem, TDisplay, TValue> choices, bool isDropDown, ModelMetadata model) { List <ExtendedSelectListItem> res = new List <ExtendedSelectListItem>(); if (choices.isInClientBlock) { return(res); } if (isDropDown && (choices.UsePrompt || choices.OverridePrompt != null)) { string prompt = choices.OverridePrompt; if (prompt == null) { prompt = model.Watermark; } if (prompt != null) { res.Add(new ExtendedSelectListItem { Value = string.Empty, Text = prompt, Attributes = choices.LabelAttributesSelector == null ? null : choices.LabelAttributesSelector(default(TItem)) }); } } foreach (TItem item in choices.Items) { res.Add(new ExtendedSelectListItem { Attributes = choices.LabelAttributesSelector == null ? null : choices.LabelAttributesSelector(item), Value = Convert.ToString(choices.ValueSelector(item), CultureInfo.CurrentCulture), Text = Convert.ToString(choices.DisplaySelector(item), CultureInfo.CurrentCulture), GroupKey = choices is IGroupedChoiceList ? Convert.ToString(((IGroupedChoiceList)choices).GroupValueSelector(item), CultureInfo.CurrentCulture) : null, GroupName = choices is IGroupedChoiceList ? Convert.ToString(((IGroupedChoiceList)choices).GroupDisplaySelector(item), CultureInfo.CurrentCulture):null, GroupAttributes = choices is IGroupedChoiceList && ((IGroupedChoiceList)choices).GroupAttributesSelector != null ? ((IGroupedChoiceList)choices).GroupAttributesSelector(item) : null }); } return(res); }
public static MvcHtmlString DropDownList <VM, TItem, TDisplay, TValue>( this HtmlHelper <VM> htmlHelper, string name, TValue value, object htmlAttributes, ChoiceList <TItem, TValue, TDisplay> items) { return(DropDownbase <VM, TItem, TDisplay, TValue>( htmlHelper, name, value, prepareItems(items, true, ModelMetadata.FromStringExpression(name, htmlHelper.ViewData)), new RouteValueDictionary(htmlAttributes), false, items is IGroupedChoiceList)); }
public static MvcHtmlString DropDownListFor <VM, TItem, TDisplay, TValue>( this HtmlHelper <VM> htmlHelper, Expression <Func <VM, TValue> > expression, IDictionary <string, object> htmlAttributes, ChoiceList <TItem, TValue, TDisplay> items) { return(DropDownListForBase(htmlHelper, expression, htmlAttributes, items)); }
public void ImportFromCsv(string path) { Database.EnsureDeleted(); Database.Migrate(); #region WalkableAreaMap var walkableAreaMapCsv = ParseCsv(Path.Combine(path, "walkableareamap.csv")); foreach (var result in walkableAreaMapCsv) { if (result.Length != 3) { continue; } WalkableAreaMap.Add(new WalkableAreaMap { Id = int.Parse(result[0]), WamFile = result[2] }); } #endregion #region Script var scriptCsv = ParseCsv(Path.Combine(path, "skript.csv")); foreach (var result in scriptCsv) { System.Diagnostics.Debug.Assert(result.Length <= 5, "SKRIPT column count failed?"); if (result.Length != 4) { continue; } Script.Add(new Skript() { SkriptId = int.Parse(result[0]), Zeilennummer = int.Parse(result[1]), SkriptAktion = result[2], Kommentar = result[3] }); } #endregion #region FrameSet var frameSetCsv = ParseCsv(Path.Combine(path, "bildfolge.csv")); foreach (var result in frameSetCsv) { System.Diagnostics.Debug.Assert(result.Length <= 4, "BILDFOLGE column count failed?"); if (result.Length != 4) { continue; } FrameSet.Add(new Bildfolge() { Id = int.Parse(result[0]), Bezeichnung = result[1], Anzeigedauer = int.Parse(result[2]), Loop = bool.Parse(result[3]) }); System.Diagnostics.Debug.Assert(!FrameSet.Any(x => x.Id == int.Parse(result[0])), "duplicate BILDFOLGE?"); } #endregion SaveChanges(); #region CharacterAnimationSet var characterAnimationSetCsv = ParseCsv(Path.Combine(path, "characteranimationset.csv")); foreach (var result in characterAnimationSetCsv) { System.Diagnostics.Debug.Assert(result.Length <= 7, "CHARACTERANIMATIONSET column count failed?"); if (result.Length != 7) { continue; } var thisSet = new CharacterAnimationSet() { SetId = int.Parse(result[0]), AktionsmodusId = int.Parse(result[1]), Bezeichnung = result[2], LinksBildfolge = FrameSet.Find(int.Parse(result[3])), RechtsBildfolge = FrameSet.Find(int.Parse(result[4])), VorneBildfolge = FrameSet.Find(int.Parse(result[5])), HintenBildfolge = FrameSet.Find(int.Parse(result[6])), }; CharacterAnimationSet.Add(thisSet); // There are various CAS with null animations //System.Diagnostics.Debug.Assert(thisSet.LinksBildfolge != null && thisSet.RechtsBildfolge != null && thisSet.VorneBildfolge != null && thisSet.HintenBildfolge != null, $"CHARACTERANIMATIONSET {thisSet.Bezeichnung} has null bildfolge?"); } #endregion #region ChoiceList var choiceListCsv = ParseCsv(Path.Combine(path, "choiceliste.csv")); foreach (var result in choiceListCsv) { System.Diagnostics.Debug.Assert(result.Length <= 5, "CHOICELISTE column count failed?"); if (result.Length != 5) { continue; } var thisSet = new ChoiceListeEntry() { ChoiceId = int.Parse(result[0]), AuswahlNummer = int.Parse(result[1]), Aktiv = bool.Parse(result[2]), AuswahlText = result[3], SkriptId = int.Parse(result[4]) }; ChoiceList.Add(thisSet); } #endregion #region Timer var timerCsv = ParseCsv(Path.Combine(path, "timer.csv")); foreach (var result in timerCsv) { System.Diagnostics.Debug.Assert(result.Length <= 4, "TIMER column count failed?"); if (result.Length != 4) { continue; } Timer.Add(new Timer() { Id = int.Parse(result[0]), SkriptId = int.Parse(result[1]), Dauer = int.Parse(result[2]), Aktiv = bool.Parse(result[3]) }); } #endregion #region ChoiceList var roomCsv = ParseCsv(Path.Combine(path, "raum.csv")); foreach (var result in roomCsv) { System.Diagnostics.Debug.Assert(result.Length <= 13, "RAUM column count failed?"); if (result.Length > 13 || result.Length < 12) { continue; } var thisRoom = new Raum { Id = int.Parse(result[0]), Bezeichnung = result[1], BildDatei = result[2], MusikDatei = result[3], WalkableAreaMap = WalkableAreaMap.Find(int.Parse(result[4])), VSpeed = ParseDouble(result[5]), HSpeed = ParseDouble(result[6]), BaseYatZeroScale = ParseDouble(result[7]), BaseYatFullScale = ParseDouble(result[8]), GuiId = int.Parse(result[9]), CharacterAnimationSetId = int.Parse(result[10]), Timer = Timer.Find(int.Parse(result[11])) }; Room.Add(thisRoom); } #endregion SaveChanges(); }
private static MvcHtmlString ClientDropDownListForBase <VM, M, TItem, TDisplay, TValue>( HtmlHelper <VM> htmlHelper, Expression <Func <VM, M> > expression, IDictionary <string, object> htmlAttributes, ChoiceList <TItem, TValue, TDisplay> items, bool isList, ModelMetadata metaData) { MVCControlsToolkit.Controls.Bindings.IBindingsBuilder <VM> bindings = htmlHelper.ClientBindings(); if (htmlAttributes == null) { htmlAttributes = new Dictionary <string, object>(); } Expression <Func <VM, IEnumerable <TItem> > > itemsExpression = items.origin as Expression <Func <VM, IEnumerable <TItem> > >; string prefix = htmlHelper.ViewData.TemplateInfo.GetFullHtmlFieldName(ExpressionHelper.GetExpressionText(expression)); string caption = null; if (!isList) { caption = items.OverridePrompt; if (caption == null) { caption = metaData.Watermark; } } if (typeof(TItem) == typeof(TValue)) { bindings.Options <VM, IEnumerable <TItem> >(itemsExpression, caption); } else { bindings.Options <VM, TItem, TValue, TDisplay>(itemsExpression, items._evalueSelector, items._edisplaySelector, caption); } if (isList) { htmlAttributes["multiple"] = "multiple"; bindings.SelectedOptions(expression); } else { bindings.Value(expression); } string prevBind = null; if (htmlAttributes.ContainsKey("data-bind")) { prevBind = htmlAttributes["data-bind"] as string; } if (string.IsNullOrWhiteSpace(prevBind)) { htmlAttributes["data-bind"] = bindings.Get(); } else { htmlAttributes["data-bind"] = prevBind + ", " + bindings.Get(); } htmlAttributes["data-nobinding"] = true; return(MvcHtmlString.Create(string.Format("<select id = '{0}' name = '{1}' {2} ></select>", BasicHtmlHelper.IdFromName(prefix), prefix, BasicHtmlHelper.GetAttributesString(htmlAttributes)))); }
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); }
private static MvcHtmlString DropDownListForBase <VM, TItem, TDisplay, TValue>( HtmlHelper <VM> htmlHelper, Expression <Func <VM, IEnumerable <TValue> > > expression, IDictionary <string, object> htmlAttributes, ChoiceList <TItem, TValue, TDisplay> items) { if (expression == null) { throw new ArgumentNullException("expression"); } if (items.isInClientBlock) { return(ClientDropDownListForBase <VM, IEnumerable <TValue>, TItem, TDisplay, TValue>( htmlHelper, expression, htmlAttributes, items, true, null)); } string name = ExpressionHelper.GetExpressionText(expression); IEnumerable <TValue> value = null; try { value = expression.Compile().Invoke(htmlHelper.ViewData.Model); } catch { } return(DropDownbase <VM, TItem, TDisplay, TValue>( htmlHelper, name, value, prepareItems(items, false, null), htmlAttributes, true, items is IGroupedChoiceList)); }
public static MvcHtmlString CheckBoxListFor <TModel, TChoiceItem, TValue, TDisplay> ( this HtmlHelper <TModel> htmlHelper, Expression <Func <TModel, IEnumerable <TValue> > > expression, ChoiceList <TChoiceItem, TValue, TDisplay> choiceList, bool useTemplate = false, object template = null, object itemTemplate = null) where TValue : IComparable { IEnumerable <TValue> values = default(IEnumerable <TValue>); if (expression == null) { throw (new ArgumentNullException("expression")); } try { values = expression.Compile().Invoke(htmlHelper.ViewData.Model); } catch {} if (values == null) { values = new List <TValue>(); } if (choiceList == null) { throw (new ArgumentNullException("choiceList")); } var fullPropertyPath = htmlHelper.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName( ExpressionHelper.GetExpressionText(expression)); var propertyPath = ExpressionHelper.GetExpressionText(expression); CheckBoxList <IEnumerable <TValue>, TChoiceItem, TValue, TDisplay> displayModel = new CheckBoxList <IEnumerable <TValue>, TChoiceItem, TValue, TDisplay>(); displayModel.ImportFromModel(values, new object[] { choiceList }); StringBuilder sb = new StringBuilder(); sb.Append(BasicHtmlHelper.RenderDisplayInfo(htmlHelper, typeof(CheckBoxList <IEnumerable <TValue>, TChoiceItem, TValue, TDisplay>), propertyPath)); int index = 0; foreach (CheckBoxListItem <TValue> item in displayModel.Items) { sb.Append(htmlHelper.Hidden (EnumerableHelper.CreateSubIndexName(BasicHtmlHelper.AddField(propertyPath, "$.Items"), index) + ".Code", item.Code)); index++; } if (useTemplate) { if (template == null && itemTemplate == null) { template = typeof(CheckBoxList <IEnumerable <TValue>, TChoiceItem, TValue, TDisplay>).Name; } if (template != null) { ViewDataDictionary <CheckBoxList <IEnumerable <TValue>, TChoiceItem, TValue, TDisplay> > dataDictionary = new ViewDataDictionary <CheckBoxList <IEnumerable <TValue>, TChoiceItem, TValue, TDisplay> >(displayModel); dataDictionary.TemplateInfo.HtmlFieldPrefix = (BasicHtmlHelper.AddField(fullPropertyPath, "$")); sb.Append(new TemplateInvoker <CheckBoxList <IEnumerable <TValue>, TChoiceItem, TValue, TDisplay> >(template).Invoke <TModel>(htmlHelper, dataDictionary)); } else { int itemIndex = 0; foreach (CheckBoxListItem <TValue> item in displayModel.Items) { ViewDataDictionary <CheckBoxListItem <TValue> > dataDictionary = new ViewDataDictionary <CheckBoxListItem <TValue> >(item); dataDictionary.TemplateInfo.HtmlFieldPrefix = (BasicHtmlHelper.AddField(fullPropertyPath, string.Format("$.Items[{0}]", itemIndex))); sb.Append(new TemplateInvoker <CheckBoxListItem <TValue> >(itemTemplate) .Invoke(htmlHelper, dataDictionary)); itemIndex++; } } } else { index = 0; foreach (CheckBoxListItem <TValue> item in displayModel.Items) { sb.Append("<div>"); sb.Append(htmlHelper.CheckBox( EnumerableHelper.CreateSubIndexName(BasicHtmlHelper.AddField(propertyPath, "$.Items"), index) + ".Selected", item.Selected, item.DisplayAttributes)); sb.Append(" "); sb.Append(string.Format(CultureInfo.InvariantCulture, "<span {0}>{1}</span>", BasicHtmlHelper.GetAttributesString(item.LabelAttributes), item.Label)); sb.Append("</div>"); index++; } } return(MvcHtmlString.Create(sb.ToString())); }
public static MvcHtmlString DropDownListFor <VM, TItem, TDisplay, TValue>( this HtmlHelper <VM> htmlHelper, Expression <Func <VM, IEnumerable <TValue> > > expression, ChoiceList <TItem, TValue, TDisplay> items) { return(DropDownListForBase <VM, TItem, TDisplay, TValue>( htmlHelper, expression, null, items)); }
public ChoiceListViewModel(ChoiceList c) { ModelClass = c; EventAggregator = Globals.EventAggregator; }
public void ImportFromModel(object model, params object[] context) { IEnumerable input = model as IEnumerable; List <TValue> inputList; if (input == null) { inputList = new List <TValue>(); } else { inputList = EnumerableHelper.CreateFrom <TValue>(typeof(List <TValue>), input, 0) as List <TValue>; inputList.Sort(); ChoiceList <TChoiceItem, TValue, TDisplay> choiceList = context[0] as ChoiceList <TChoiceItem, TValue, TDisplay>; List <CheckBoxListItem <TValue> > items = new List <CheckBoxListItem <TValue> >(); List <OrderItem <TValue> > orderer = new List <OrderItem <TValue> >(); int index = 0; foreach (TChoiceItem item in choiceList.Items) { CheckBoxListItem <TValue> checkBoxListItem = new CheckBoxListItem <TValue>(); OrderItem <TValue> orderItem = new OrderItem <TValue>(); checkBoxListItem.Code = choiceList.ValueSelector(item); checkBoxListItem.Label = choiceList.DisplaySelector(item).ToString(); if (choiceList.LabelAttributesSelector != null) { checkBoxListItem.LabelAttributes = choiceList.LabelAttributesSelector(item); } else { checkBoxListItem.LabelAttributes = new { } }; if (choiceList.DisplayAttributesSelector != null) { checkBoxListItem.DisplayAttributes = choiceList.DisplayAttributesSelector(item); } else { checkBoxListItem.DisplayAttributes = new { } }; items.Add(checkBoxListItem); orderItem.Value = checkBoxListItem.Code; orderItem.Place = index; orderer.Add(orderItem); index++; } Items = items.ToArray(); orderer.Sort(); IEnumerator <OrderItem <TValue> > ordererIterator = (orderer as IEnumerable <OrderItem <TValue> >).GetEnumerator(); ordererIterator.Reset(); ordererIterator.MoveNext(); foreach (TValue selectedValue in inputList) { while (((IComparable)selectedValue).CompareTo(ordererIterator.Current.Value) > 0) { ordererIterator.MoveNext(); } if (((IComparable)selectedValue).CompareTo(ordererIterator.Current.Value) == 0) { Items[ordererIterator.Current.Place].Selected = true; } } } } }