Exemple #1
0
        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
                }
            }
        }
Exemple #2
0
        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());
        }
Exemple #3
0
        /// <summary>
        /// Removes the private context to the processing data context
        /// </summary>
        protected virtual void UnRegisterPrivateContext()
        {
//			object current = MyDataContext.GetVariableObject(LocalParameterContextKey);
            MyDataContext.RemoveLocalValue(LocalParameterContextKey);
        }
        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);
            }
        }