/// <summary>
 /// Aplica a propriedade à saída de um controle.
 /// </summary>
 /// <param name="target">Controle alvo</param>
 /// <param name="property">Propriedade sendo aplicada</param>
 /// <param name="value">Valor da propriedade sendo aplicada</param>
 /// <param name="result">Resultado da saida da renderização atual.</param>
 public void ApplyProperty(HtmlObject target, ControlProperty property, object value, ControlPropertyApplyResult result)
 {
     if (value != null && value.AsString() != DefaultValue.AsString())
     {
         result.Styles[CssProperty] = CssConfig.GetItemNameFromEnum(property.PropertyType, value);
     }
 }
예제 #2
0
 internal ControlPropertyChangedEventArgs(HtmlObject target, ControlProperty property, Object currentvalue, Object newValue)
 {
     this.Target   = target;
     this.Property = property;
     this.OldValue = currentvalue;
     this.NewValue = newValue;
 }
예제 #3
0
 protected override void ApplyValueProperty(HtmlObject target, ControlProperty property, object value, ControlPropertyApplyResult result)
 {
     if (value.AsString().HasValue())
     {
         result.Attributes[HtmlAttr.Value] = value.AsString();
     }
 }
예제 #4
0
 internal static void ExtendControl(HtmlObject control, ExtensionStage stage)
 {
     foreach (IControlBuildExtension extender in _extenders)
     {
         extender.Extend(control, stage);
     }
 }
예제 #5
0
        public static void Render(this HtmlObject control, ControllerBase controller, ViewDataDictionary viewData, bool writeLog = true)
        {
            RenderOutputWriter renderer = new RenderOutputWriter(controller, viewData, false);

            renderer.Render(control);
            renderer.WriteBodyContent();
            renderer.WriteScripts();
        }
예제 #6
0
 internal void NotifyPropertyChanged(HtmlObject htmlObject, object oldValue, object newValue)
 {
     if (this.PropertyChangedCallback != null)
     {
         var args = new ControlPropertyChangedEventArgs(htmlObject, this, oldValue, newValue);
         this.PropertyChangedCallback.Invoke(args);
     }
 }
        public void ApplyProperty(HtmlObject target, ControlProperty property, object value, ControlPropertyApplyResult result)
        {
            if (value.AsString().IsEmpty() || value.AsString() == DefaultValue.AsString())
            {
                return;
            }

            result.Attributes[Attribute.ToString().ToLower()] = value.AsString();
        }
        public void ApplyProperty(HtmlObject target, ControlProperty property, object value, ControlPropertyApplyResult result)
        {
            var boolValue = ConversionHelper.ToBoolean(value);

            if (boolValue == DefaultValue)
            {
                return;
            }
            result.Attributes[Attribute] = boolValue ? ValueIfTrue : ValueIfFalse;
        }
예제 #9
0
 /// <summary>
 /// Aplica a propriedade à saída de um controle.
 /// </summary>
 /// <param name="target">Controle alvo</param>
 /// <param name="property">Propriedade sendo aplicada</param>
 /// <param name="value">Valor da propriedade sendo aplicada</param>
 /// <param name="result">Resultado da saida da renderização atual.</param>
 public void ApplyProperty(HtmlObject target, ControlProperty property, object value, ControlPropertyApplyResult result)
 {
     if (value != null && value.AsString() != DefaultValue.AsString())
     {
         var strValue = (value ?? "").ToString();
         if (strValue.HasValue())
         {
             result.Styles[CssProperty] = strValue.ToLowerInvariant();
         }
     }
 }
예제 #10
0
        internal static void PerformExtensionDelegates(HtmlObject control)
        {
            if (!_extensionDelegatesMap.ContainsKey(control.GetType()))
            {
                return;
            }
            var delegates = _extensionDelegatesMap[control.GetType()];

            foreach (var delegateItem in delegates)
            {
                delegateItem.Invoke(control);
            }
        }
예제 #11
0
 public virtual void ApplyTemplate(HtmlObject source)
 {
     InitInternal(source.CurrentContext);
     if (this._templateBindings != null && this._templateBindings.Count > 0)
     {
         foreach (var binding in _templateBindings)
         {
             var slot = source.GetSlot(binding.SourceProperty, true);
             slot.LastTemplateBindingSessionId = CurrentContext.RenderSessionId;
             this.SetValue(binding.TargetProperty, slot.CurrentValue);
         }
     }
 }
예제 #12
0
 public void Render(HtmlObject control)
 {
     try
     {
         var renderStart = DateTime.Now;
         control.Render(Context);
         RenderCost = DateTime.Now - renderStart;
     }
     catch (Exception e)
     {
         //gravar na saida mais dados sobre o erro.
         Exception ex = new Exception(String.Format("Erro ao renderizar o controle: \n Pilha: {0}", GetStackString()), e);
         throw ex;
     }
 }
        public void ApplyProperty(HtmlObject target, ControlProperty property, object value, ControlPropertyApplyResult result)
        {
            Object getParams = null;
            var    urlStr    = value.AsString();
            var    uri       = new Uri(urlStr, UriKind.RelativeOrAbsolute);

            //url.
            if (GetParamsProperty != null)
            {
                getParams = target.GetValue(GetParamsProperty);
            }
            if (getParams != null)
            {
                IDictionary <String, Object> dict = null;
                if (!(getParams is IDictionary <String, Object>))
                {
                    dict = ReflectionHelper.AnonymousToDictionary(getParams);
                }
                else
                {
                    dict = (IDictionary <String, Object>)getParams;
                }
                if (uri.Query.HasValue())
                {
                    urlStr += urlStr + "&" + Utils.EncodeGetParams(dict);
                }
                else
                {
                    urlStr += uri.ToString() + "?" + Utils.EncodeGetParams(dict);
                }
            }
            if (urlStr != null)
            {
                result.Attributes[HtmlAttr.Href] = urlStr;
            }
        }
예제 #14
0
 internal ControlPropertySlot(HtmlObject owner, ControlProperty property)
 {
     _owner        = new WeakReference(owner);
     this.Property = property;
 }
예제 #15
0
 protected void AddControlToCurrentContext(HtmlObject obj)
 {
     obj.InitInternal(CurrentContext);
 }
예제 #16
0
 public void ApplyProperty(HtmlObject target, ControlProperty property, object value, ControlPropertyApplyResult result)
 {
 }
예제 #17
0
 protected override void ApplyValueProperty(HtmlObject target, ControlProperty property, object value, ControlPropertyApplyResult result)
 {
     result.InnerText.Append(value.AsString());
 }
 /// <summary>
 /// Aplica a propriedade à saída de um controle.
 /// </summary>
 /// <param name="target">Controle alvo</param>
 /// <param name="property">Propriedade sendo aplicada</param>
 /// <param name="value">Valor da propriedade sendo aplicada</param>
 /// <param name="result">Resultado da saida da renderização atual.</param>
 public void ApplyProperty(HtmlObject target, ControlProperty property, object value, ControlPropertyApplyResult result)
 {
     Callback.Invoke(target, property, value, result);
 }
 internal ControlPropertyApplyResult(HtmlObject target)
 {
     this.Target     = target;
     this.Attributes = new HtmlAttributeCollection();
     this.Styles     = new HtmlStyleCollection();
 }
예제 #20
0
 public static void Render <TModel>(this HtmlHelper <TModel> htmlHelper, HtmlObject control) where TModel : class
 {
     control.Render(htmlHelper.ViewContext.Controller, htmlHelper.ViewData, false);
 }
예제 #21
0
 public static void Render(this HtmlHelper htmlHelper, HtmlObject control)
 {
     control.Render(htmlHelper.ViewContext.Controller, htmlHelper.ViewData, false);
 }
예제 #22
0
 /// <summary>
 /// Remove um controle convidado de um container.
 /// </summary>
 /// <typeparam name="T">Container concreto</typeparam>
 /// <param name="control">Container</param>
 /// <param name="guestControl">Controle convidado</param>
 /// <returns>O container</returns>
 public static T RemoveGuestControl <T>(this T control, HtmlObject guestControl) where T : ContainerControlBase
 {
     control._RemoveGuestControl(guestControl);
     return(control);
 }
예제 #23
0
 /// <summary>
 /// Adiciona um controle em um container sem que esse controle faça parte da coleção de filhos do container.
 /// A esse aspecto dizemos que o controle é um convidado do container, mas não faz parte dele.
 /// </summary>
 /// <typeparam name="T">Container concreto</typeparam>
 /// <param name="control">Container</param>
 /// <param name="guestControl">Controle convidado</param>
 /// <param name="beforeChildren">Adicionar antes ou depois dos filhos. Se 'true', indica que o controle deve ser renderizado antes dos
 /// filhos do container, se 'false' então o controle será renderizado após a renderização dos filhos</param>
 /// <returns>O container</returns>
 /// <example>
 /// O exemplo abaixo cria um novo controle chamado HeaderedBox, onde é possível incluir outros controles.
 /// Como o nome diz, o box contém uma area onde o usuário pode incluir um cabeçalho. Para que isso seja possivel
 /// vamos adicionar a area do cabeçalho como um guest do container. Dessa forma o cabeçalho fica separado dos filhos
 /// que serão incluídos pelo usuário.
 /// <code>
 /// public class HeaderedBox : PanelControl
 /// {
 ///     private PanelControl _header;
 ///
 ///     public HeaderedBox()
 ///     {
 ///         //criar o cabeçalho do box
 ///         _header = new PanelControl().AddClass("box-header");
 ///         // adicionar o  header como guest
 ///         this.AddGuestControl(guestControl: header, beforeChildren: true);
 ///     }
 ///
 ///     //expor o header
 ///     public PanelControl Header
 ///     {
 ///         get { return _header; }
 ///     }
 /// }
 /// </code>
 /// <para>
 /// No exemplo abaixo, criamos uma classe HeaderedBox com o cabeçalho customizavel pelo usuário.
 /// Para isso criamos um propriedade do controle e nos inscrevemos no seu evento PropertyChanged.
 /// Caso o valor da propriedade seja alterado, nós removemos o antigo controle da lista de convidados
 /// e adicionamos o novo controle.
 /// </para>
 /// <code>
 /// public class HeaderedBox : PanelControl
 /// {
 ///     // registrar a propriedade no controle.
 ///     public static readonly ControlProperty HeaderTemplateProperty = ControlProperty.Register("HeaderTemplate",
 ///          typeof(HtmlObject),
 ///          typeof(HeaderedBox),
 ///          null,
 ///          HeaderTemplatePropertyChanged);
 ///
 ///     // remover o controle antigo como convidado e adicionar o novo.
 ///     private static void HeaderTemplatePropertyChanged(ControlPropertyChangedEventArgs args)
 ///     {
 ///        var targetContainer = args.Target as HeaderedBox;
 ///        if (targetContainer != null)
 ///         {
 ///             if (args.OldValue != null)
 ///                 targetContainer.RemoveGuestControl((HtmlObject)args.OldValue);
 ///             if (args.NewValue != null)
 ///                 targetContainer.AddGuestControl((HtmlObject)args.NewValue, true);
 ///         }
 ///     }
 ///
 ///     //atalho para a propriedade HeaderTemplateProperty
 ///     public HtmlObject HeaderTemplate
 ///     {
 ///          get { return (HtmlObject)GetValue(HeaderTemplateProperty); }
 ///          set { SetValue(HeaderTemplateProperty, value); }
 ///     }
 ///  }
 /// </code>
 /// </example>
 public static T AddGuestControl <T>(this T control, HtmlObject guestControl, bool beforeChildren) where T : ContainerControlBase
 {
     control._AddGuestControl(guestControl, beforeChildren);
     return(control);
 }
예제 #24
0
        internal void Resolve(HtmlObject instance, ControlProperty targetProperty)
        {
            Object value = null;

            if (ValueProvider != null)
            {
                value = ValueProvider.GetValue(instance.DataItem);
            }
            else if (_pathParts != null || _resolvePending)
            {
                if (_resolvePending)
                {
                    CompilePropertyPath();
                }
                var data = instance.DataItem;
                for (var i = 0; i < _pathParts.Length; i++)
                {
                    var key = _pathParts[i];
                    try
                    {
                        switch (_resolveMethods[i])
                        {
                        case ResolveMethod.PropertyValue:
                            data = ReflectionHelper.ReadProperty(data, key); break;

                        case ResolveMethod.ViewDataEntry:
                            data = instance.CurrentContext[key]; break;

                        case ResolveMethod.MethodCall:
                            data = ReflectionHelper.InvokeInstanceMethod(data, key); break;

                        case ResolveMethod.CurrentDataItem:
                            data = instance.DataItem; break;

                        case ResolveMethod.VisualTreeObject:
                            throw new NotImplementedException();
                        }
                        if (data == null)
                        {
                            break;
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new BindingException(String.Format("Error on resolve property path {0} to property {1}.{2}", PropertyPath, instance.GetType().Name, targetProperty.Name), ex);
                    }
                }
                value = data;
            }
            else
            {
                value = instance.DataItem;
            }

            if (Formatter != null)
            {
                value = Formatter.Format(value);
                if (Formatter.Align != TextAlignment.Default)
                {
                    instance.SetValue(HtmlControl.TextAlignProperty, Formatter.Align);
                }
            }
            if (!String.IsNullOrEmpty(FormatString))
            {
                value = String.Format(FormatString, value);
            }

            instance.SetValue(targetProperty, value);
        }
예제 #25
0
 internal void PushControl(HtmlObject control)
 {
     _innerRenderStack.Add(control);
 }