public override void Render(TextWriter writer) { object value = GetVariableValue(); if (MyDataContext.HasVariable(VariableKey)) { MyDataContext.RemoveLocalValue(VariableKey); } if (string.IsNullOrEmpty(ScopeVariableKey)) { this.MyDataContext.RegisterDataItem(VariableKey, value); } else { Dictionary <string, object> scopeDictionary = null; if (!MyDataContext.MasterData.ContainsKey(ScopeVariableKey)) { scopeDictionary = new Dictionary <string, object>(); MyDataContext.RegisterLocalValue(ScopeVariableKey, scopeDictionary); } else { scopeDictionary = MyDataContext.GetVariableObject(ScopeVariableKey) as Dictionary <string, object>; } if (scopeDictionary != null) { scopeDictionary.Add(VariableKey, value); } else { //TODO: REGISTER ERROR } } }
/// <summary> /// Recursively checks to see if a data key is completely resolvable. /// To be resolvable, every dependent key must ultimately resolve to /// a control that has no dynamic dependencies /// </summary> /// <param name="key"></param> /// <param name="keysAlreadyUsed"></param> /// <param name="circularKey">Variable to contain key identified as circular</param> /// <returns></returns> public bool IsResolvableKey(string key, Dictionary <string, string> keysAlreadyUsed, out string circularKey) { if (!MyDataContext.HasVariable(key)) { circularKey = key; return(false); } circularKey = null; DataItem item = MyDataContext.MasterData[key]; if (null == item) { circularKey = key; return(false); } if (item.DataControl is BaseDataControl) { BaseDataControl control = (BaseDataControl)item.DataControl; if (!control.HasDynamicParameters()) { return(true); } else { bool resolvable = true; string[] requiredKeys = control.GetDynamicKeyDependencies(); for (int i = 0; i < requiredKeys.Length; i++) { if (keysAlreadyUsed.ContainsKey(requiredKeys[i])) { circularKey = requiredKeys[i]; return(false); } else { Dictionary <string, string> thisBranchKeysUsed = new Dictionary <string, string>(keysAlreadyUsed); thisBranchKeysUsed.Add(key, key); resolvable = IsResolvableKey(requiredKeys[i], thisBranchKeysUsed, out circularKey); } if (!resolvable) { return(false); } } return(true); } } else { return(true); } }
private string multiSelectDropDown(IEnumerable friendList) { LoopContext context = GetLoopContext(friendList); StringBuilder selectOption = new StringBuilder(); foreach (object item in friendList) { object realItem = item; if (item is DictionaryEntry) { realItem = ((DictionaryEntry)item).Value; } MyDataContext.RegisterLocalValue(GetCurrentLoopItemVariable(), realItem); if (MyDataContext.HasVariable("Context")) { MyDataContext.RemoveLocalValue("Context"); } MyDataContext.RegisterLocalValue("Context", context); string newRaw = multiSelectItem.Replace(REPLACE_KEY, GetCurrentLoopItemVariable()); selectOption.Append(ResolveDataContextVariables(newRaw, MyDataContext)); context.Count++; MyDataContext.RemoveLocalValue(GetCurrentLoopItemVariable()); } StringBuilder output = new StringBuilder(multiSelectContainerTemplate.Replace(ID_KEY, this.ID)); output.Append(multiSelectItemTemplate.Replace(ID_KEY, this.ID)); output = output.Replace(OPTION_KEY, selectOption.ToString()); output.Append(string.Format( scriptTemplate.Replace(ID_KEY, this.ID), ID_CONTAINER_KEY.Replace(ID_KEY, this.ID), ID_ITEMCONTAINER_KEY.Replace(ID_KEY, this.ID), this.Max, string.IsNullOrEmpty(this.OnSelectMethod) ? "null" : string.Format("typeof {0} == 'undefined' ? null : {0}", this.OnSelectMethod), this.InputName, this.Group) ); return(output.ToString()); }
public override void Render(System.IO.TextWriter writer) { IEnumerable simpleList = MyDataContext.GetEnumerableVariableObject(RepeatedDataKey); if (null == simpleList) { return; } //TODO - hunt down why repeat nested in templates not parsed. if (Controls.Count == 0 && MyOffset.ChildOffsets.Count > 0) { BuildControlTreeFromOffsets(); } bool hasPrequel = (!string.IsNullOrEmpty(LoopPrequel)); bool hasSequel = (!string.IsNullOrEmpty(LoopSequel)); //System.Collections.Hashtable LoopContext context = new LoopContext(0, 0); //resolve the count if (simpleList is IList) { context.Count = ((IList)simpleList).Count; } else { //enumerate to count items int count = 0; foreach (object item in simpleList) { count++; } context.Count = count; } //saftey check on LoopContextVariableKey if (string.IsNullOrEmpty(LoopContextVariableKey)) { LoopContextVariableKey = "Context"; } foreach (object item in simpleList) { object realItem = item; if (item is DictionaryEntry) { realItem = ((DictionaryEntry)item).Value; } MyDataContext.RegisterLocalValue(this.LoopItemKey, realItem); if (MyDataContext.HasVariable(this.LoopContextVariableKey)) { MyDataContext.RemoveLocalValue(this.LoopContextVariableKey); } MyDataContext.RegisterLocalValue(this.LoopContextVariableKey, context); //Evaluate any conditionals if (EvaluateLoopConditionalExpressionPasses()) { if (hasPrequel) { writer.Write(MyDataContext.ResolveVariables(LoopPrequel)); } RenderTemplateInstance(writer); if (hasSequel) { writer.Write(MyDataContext.ResolveVariables(LoopSequel)); } } context.Index++; MyDataContext.RemoveLocalValue(this.LoopItemKey); } //remove the final context variable if (MyDataContext.HasVariable(this.LoopContextVariableKey)) { MyDataContext.RemoveLocalValue(this.LoopContextVariableKey); } }