Пример #1
0
        /// <summary>
        ///     Initialize the handler and generates the needed Javascript code
        /// </summary>
        /// <param name="bridge">The <see cref="BridgeController" /> object requesting initialization</param>
        public virtual void Initialize(BridgeController bridge)
        {
            var builder = new StringBuilder();

            builder.Append(ClassBridge.GenerateNameSpace(GenericType));
            builder.Append(ClassBridge.GenerateProxyClass(Identification, true));
            lock (Lock)
            {
                if (Methods != null)
                {
                    if (Fields != null)
                    {
                        foreach (var field in Fields)
                        {
                            builder.Append(ClassBridge.GenerateProxyField(Identification, field));
                        }
                    }
                    foreach (var method in Methods)
                    {
                        builder.Append(ClassBridge.GenerateProxyMethod(Identification, method.Key, method.Value));
                    }
                }
            }
            OnPushJavascript(new FireJavascriptEventArgs(builder.ToString(), bridge));
        }
Пример #2
0
        /// <summary>
        ///     Initialize the handler and generates the needed Javascript code
        /// </summary>
        /// <param name="bridge">The <see cref="BridgeController" /> object requesting initialization</param>
        public virtual void Initialize(BridgeController bridge)
        {
            var builder = new StringBuilder();

            builder.Append(ClassBridge.GenerateNameSpace(GenericType));
            builder.Append(ClassBridge.GenerateProxyClass(Identification, false));
            lock (Lock)
            {
                if (Fields != null)
                {
                    foreach (var field in Fields)
                    {
                        builder.Append(ClassBridge.GenerateProxyField(Identification, field));
                    }
                }
                if (Methods != null)
                {
                    if (Properties != null)
                    {
                        foreach (var property in Properties)
                        {
                            var get = property.GetGetMethod();
                            if ((get != null) && !Methods.ContainsKey(get))
                            {
                                get = null;
                            }
                            var set = property.GetSetMethod();
                            if ((set != null) && !Methods.ContainsKey(set))
                            {
                                set = null;
                            }
                            builder.Append(ClassBridge.GenerateProxyProperty(Identification, property, get, set));
                        }
                    }
                    foreach (
                        var method in
                        Methods.Where(
                            pair =>
                            (Events == null) ||
                            !Events.Any(
                                info => (pair.Key == info.GetAddMethod()) || (pair.Key == info.GetRemoveMethod()))))
                    {
                        builder.Append(ClassBridge.GenerateProxyMethod(Identification, method.Key, method.Value));
                    }
                }
                if (Events != null)
                {
                    foreach (var info in Events)
                    {
                        var isStatic = info.GetAddMethod().IsStatic || info.GetRemoveMethod().IsStatic;
                        builder.Append(ClassBridge.GenerateProxyField(Identification, info.Name, isStatic, true,
                                                                      new object[0]));
                        builder.Append(ClassBridge.GenerateProxyEventMethods(Identification, info, isStatic));
                    }
                }
            }
            foreach (var instance in Instances.Where(pair => pair.Key != null).ToArray())
            {
                var instanceId = GlobalPool.GetInstanceId(instance.Key);
                if (instanceId != null)
                {
                    builder.AppendLine(ClassBridge.GenerateInstanceChange(Identification, instanceId, false));
                    foreach (var variableName in instance.Value.Where(s => !string.IsNullOrWhiteSpace(s)))
                    {
                        builder.AppendLine(ClassBridge.GenerateInstanceVariable(Identification, instanceId, variableName));
                    }
                }
            }
            OnPushJavascript(new FireJavascriptEventArgs(builder.ToString(), bridge));
            lock (Lock)
            {
                if (SubEnumerations != null)
                {
                    foreach (var subEnum in SubEnumerations)
                    {
                        subEnum.Initialize(bridge);
                    }
                }
                if (SubClasses != null)
                {
                    foreach (var subClass in SubClasses)
                    {
                        subClass.Initialize(bridge);
                    }
                }
            }
        }
Пример #3
0
        /// <summary>
        ///     Initialize the handler and generates the needed Javascript code
        /// </summary>
        /// <param name="bridge">The <see cref="BridgeController" /> object requesting initialization</param>
        public virtual void Initialize(BridgeController bridge)
        {
            var identification = typeof(ProxyClass).FullName.Replace('+', '.');
            var builder        = new StringBuilder();

            HybridMessagingBridge.Initialize(bridge);
            builder.Append(ClassBridge.GenerateProxyField(identification, "__subscriptions", false, true,
                                                          new Dictionary <string, object>()));
            builder.Append(ClassBridge.GenerateProxyMethod(identification, "Subscribe",
                                                           new[]
            {
                new ClassBridge.InternalParameterInfo("messageString"),
                new ClassBridge.InternalParameterInfo("callback")
            }, @"
    var_messageString = var_messageString.toLowerCase().trim();
    if (this.__subscriptions[var_messageString] === undefined) {
        this.__subscriptions[var_messageString] = [];
    }
    var index = this.__subscriptions[var_messageString].indexOf(var_callback);
    if (index < 0) {
        this.__subscriptions[var_messageString].push(var_callback);
        return true;
    }
    return false;", false));
            builder.Append(ClassBridge.GenerateProxyMethod(identification, "UnSubscribe",
                                                           new[]
            {
                new ClassBridge.InternalParameterInfo("messageString"),
                new ClassBridge.InternalParameterInfo("callback")
            }, @"
    var_messageString = var_messageString.toLowerCase().trim();
    if (this.__subscriptions[var_messageString] === undefined) {
        return false;
    }
    var index = this.__subscriptions[var_messageString].indexOf(var_callback);
    if (index < 0) {
        return false;
    }
    this.__subscriptions[var_messageString].splice(index, 1);
    if (this.__subscriptions[var_messageString].length < 1) {
        this.__subscriptions[var_messageString] = undefined;
    }
    return true;", false));
            builder.Append(ClassBridge.GenerateProxyMethod(identification, "__raise",
                                                           new[]
            {
                new ClassBridge.InternalParameterInfo("messageString"),
                new ClassBridge.InternalParameterInfo("arguments", true, null)
            }, @"
    var result = undefined;
    var_messageString = var_messageString.toLowerCase().trim();
    for (var messageString in this.__subscriptions) {
        if (!messageString || !var_messageString || messageString == var_messageString) {
            for (index = 0; index < this.__subscriptions[messageString].length; ++index) {
                result = this.__subscriptions[messageString][index].apply(this, [ var_arguments ]);
            }
        }
    }
    return result;", false));
            var instanceId = GlobalPool.GetInstanceId(HybridMessagingProxy);

            if (!string.IsNullOrEmpty(instanceId))
            {
                builder.AppendFormat("\r\n{0}.__instances[\"{1}\"].add_NewMessage({0}.__instances[\"{1}\"].__raise);",
                                     identification, instanceId);
            }
            OnPushJavascript(this, new FireJavascriptEventArgs(builder.ToString()));
        }
 /// <summary>
 ///     Creates a new instance of this class with the specific Javascript code, one <see cref="BridgeController" /> to
 ///     target and a callback function for result
 /// </summary>
 /// <param name="script">The Javascript code to be pushed</param>
 /// <param name="target">The <see cref="BridgeController" /> class to target</param>
 /// <param name="callback">The callback function to be used for the result of the operation</param>
 public PushJavascriptEventArgs(string script, BridgeController target, Action <object> callback)
 {
     Script   = script;
     Target   = target;
     Callback = callback;
 }
 /// <summary>
 ///     Creates a new instance of this class with the specific Javascript code and one <see cref="BridgeController" /> to
 ///     target
 /// </summary>
 /// <param name="script">The Javascript code to be pushed</param>
 /// <param name="target">The <see cref="BridgeController" /> class to target</param>
 public PushJavascriptEventArgs(string script, BridgeController target) : this(script, target, null)
 {
 }