Inheritance: ObservableDirectEvent
Exemple #1
0
        internal void FireAsyncEvent(string eventName, ParameterCollection extraParams)
        {
            ComponentDirectEvents directevents = this.GetDirectEvents();

            if (directevents == null)
            {
                throw new HttpException("The control has no DirectEvents");
            }

            PropertyInfo eventListenerInfo = directevents.GetType().GetProperty(eventName);

            if (eventListenerInfo.PropertyType != typeof(ComponentDirectEvent))
            {
                throw new HttpException("The control '{1}' does not have an DirectEvent with the name '{0}'".FormatWith(eventName, this.ClientID));
            }

            ComponentDirectEvent directevent = eventListenerInfo.GetValue(directevents, null) as ComponentDirectEvent;

            if (directevent == null || directevent.IsDefault)
            {
                throw new HttpException("The control '{1}' does not have an DirectEvent with the name '{0}' or the handler is absent".FormatWith(eventName, this.ClientID));
            }

            DirectEventArgs e = new DirectEventArgs(extraParams);

            directevent.Owner = this;
            directevent.OnEvent(e);
        }
 public DirectEventTriplet(string name, ComponentDirectEvent directEvent, ConfigOptionAttribute attribute, PropertyInfo propertyInfo)
 {
     this.name         = name;
     this.directEvent  = directEvent;
     this.attribute    = attribute;
     this.propertyInfo = propertyInfo;
 }
Exemple #3
0
        public override void LoadViewState(object state)
        {
            object[] states = state as object[];

            ResourceManager rm = this.ResourceManager;

            if (rm != null && !rm.ManageEventsViewState)
            {
                base.LoadViewState(state);
            }

            if (states != null)
            {
                foreach (Pair pair in states)
                {
                    string directEventName  = (string)pair.First;
                    object directEventState = pair.Second;

                    if (directEventName == "base")
                    {
                        base.LoadViewState(directEventState);
                    }
                    else
                    {
                        PropertyInfo property = this.GetType().GetProperty(directEventName);

                        if (property == null)
                        {
                            throw new InvalidOperationException("Can't find the property '{0}'".FormatWith(directEventName));
                        }

                        ComponentDirectEvent componentDirectEvent = (ComponentDirectEvent)property.GetValue(this, null);

                        if (componentDirectEvent != null)
                        {
                            componentDirectEvent.LoadViewState(directEventState);
                        }
                    }
                }
            }
            else
            {
                base.LoadViewState(state);
            }
        }
 public DirectEventTriplet(string name, ComponentDirectEvent directEvent, ConfigOptionAttribute attribute, PropertyInfo propertyInfo)
 {
     this.name = name;
     this.directEvent = directEvent;
     this.attribute = attribute;
     this.propertyInfo = propertyInfo;
 }
Exemple #5
0
        public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, JsonSerializer serializer)
        {
            if (value != null && value is ComponentDirectEvent)
            {
                ComponentDirectEvent directEvent = (ComponentDirectEvent)value;

                if (!directEvent.IsDefault)
                {
                    Control owner = null;
                    MessageBusDirectEvent busEvent = directEvent as MessageBusDirectEvent;

                    if (this.Owner is BaseItem)
                    {
                        owner = ((BaseItem)this.Owner).Owner;
                    }
                    else if (this.Owner is Control)
                    {
                        owner = (Control)this.Owner;
                    }

                    directEvent.Owner             = owner;
                    directEvent.ExtraParams.Owner = owner;

                    foreach (Parameter param in directEvent.ExtraParams)
                    {
                        param.Owner = owner;
                    }

                    string configObject = new ClientConfig().SerializeInternal(directEvent, directEvent.Owner);

                    StringBuilder cfgObj = new StringBuilder(configObject.Length + 64);

                    cfgObj.Append(configObject);
                    cfgObj.Remove(cfgObj.Length - 1, 1);
                    cfgObj.AppendFormat("{0}control:this", configObject.Length > 2 ? "," : "");

                    if (busEvent != null)
                    {
                        cfgObj.Append(",eventType:'bus'");
                    }

                    if (this.PropertyName != "Click")
                    {
                        cfgObj.AppendFormat(",action:'{0}:'+name", busEvent != null ? busEvent.Name : this.PropertyName);
                    }

                    cfgObj.Append("}");

                    if (this.PropertyName.IsNotEmpty())
                    {
                        directEvent.SetArgumentList(this.Owner.GetType().GetProperty(this.PropertyName));
                    }

                    JFunction     jFunction = new JFunction("Ext.net.directRequest(".ConcatWith(cfgObj.ToString(), ");"), directEvent.ArgumentList.ToArray());
                    HandlerConfig cfg       = directEvent.GetListenerConfig();
                    string        scope     = directEvent.Scope.IsEmpty() || directEvent.Scope == "this" ? "" : directEvent.Scope;

                    StringBuilder sb = new StringBuilder();

                    sb.Append("{");
                    sb.Append("fn:").Append(jFunction.ToScript()).Append(",");

                    if (scope.Length > 0)
                    {
                        sb.Append("scope:").Append(scope).Append(",");
                    }

                    if (busEvent != null)
                    {
                        if (busEvent.Bus.IsNotEmpty())
                        {
                            sb.Append("bus:'").Append(busEvent.Bus).Append("',");
                        }
                        if (busEvent.Name.IsNotEmpty())
                        {
                            sb.Append("name:'").Append(busEvent.Name).Append("',");
                        }
                    }

                    string cfgStr = cfg.Serialize();

                    if (cfgStr != "{}")
                    {
                        sb.Append(cfgStr.Chop());
                    }

                    if (sb[sb.Length - 1] == ',')
                    {
                        sb.Remove(sb.Length - 1, 1);
                    }

                    sb.Append("}");

                    writer.WriteRawValue(sb.ToString());

                    return;
                }
            }

            writer.WriteRawValue("{}");
        }
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            if (value != null && value is ComponentDirectEvent)
            {
                ComponentDirectEvent directEvent = (ComponentDirectEvent)value;
                if (!directEvent.IsDefault)
                {
                    Control owner = null;
                    if (this.Owner is StateManagedItem)
                    {
                        owner = ((StateManagedItem)this.Owner).Owner;
                    }
                    else if (this.Owner is Control)
                    {
                        owner = (Control)this.Owner;
                    }

                    directEvent.Owner             = owner;
                    directEvent.ExtraParams.Owner = owner;

                    foreach (Parameter param in directEvent.ExtraParams)
                    {
                        param.Owner = owner;
                    }

                    string configObject = new ClientConfig().SerializeInternal(directEvent, directEvent.Owner);

                    StringBuilder cfgObj = new StringBuilder(configObject.Length + 64);

                    cfgObj.Append(configObject);
                    cfgObj.Remove(cfgObj.Length - 1, 1);
                    cfgObj.AppendFormat("{0}control:this", configObject.Length > 2 ? "," : "");

                    if (this.PropertyName != "Click")
                    {
                        cfgObj.AppendFormat(",action:'{0}'", this.PropertyName);
                    }

                    cfgObj.Append("}");

                    directEvent.SetArgumentList(this.Owner.GetType().GetProperty(this.PropertyName));

                    JFunction     jFunction = new JFunction("var params=arguments;Ext.net.DirectEvent.confirmRequest(".ConcatWith(cfgObj.ToString(), ");"), directEvent.ArgumentList.ToArray());
                    HandlerConfig cfg       = directEvent.GetListenerConfig();
                    string        scope     = directEvent.Scope.IsEmpty() || directEvent.Scope == "this" ? "" : directEvent.Scope;

                    StringBuilder sb = new StringBuilder();
                    sb.Append("{");

                    sb.Append("fn:").Append(jFunction.ToScript()).Append(",");

                    if (scope.Length > 0)
                    {
                        sb.Append("scope:").Append(scope).Append(",");
                    }

                    string cfgStr = cfg.ToJsonString();
                    if (cfgStr != "{}")
                    {
                        sb.Append(cfgStr.Chop());
                    }

                    if (sb[sb.Length - 1] == ',')
                    {
                        sb.Remove(sb.Length - 1, 1);
                    }

                    sb.Append("}");

                    writer.WriteRawValue(sb.ToString());
                    return;
                }
            }
            writer.WriteRawValue("{}");
        }
Exemple #7
0
 private void __BuildControl__control20(ComponentDirectEvent __ctrl)
 {
     this.__BuildControl__control21(__ctrl.EventMask);
     __ctrl.Event -= btnLogin_DirectClick;
     __ctrl.Event += btnLogin_DirectClick;
 }