Esempio n. 1
0
        private void WriteMethod(TextWriter writer, JsonMethodDescription method)
        {
            if (EcmaScriptIdentifier.IsValidIdentifier(method.Name, false))
            {
                writer.Write(this.formatter.MethodBeginFormat, this.ProxyNamespace, method.Name, this.ConvertParamType(method.Return.Type));
            }
            else
            {
                writer.Write(this.formatter.SafeMethodBeginFormat, this.ProxyNamespace, EcmaScriptWriter.Serialize(method.Name), this.ConvertParamType(method.Return.Type));
            }

            foreach (JsonNamedParameterDescription param in method.Params)
            {
                this.WriteParameter(writer, param);
            }

            writer.Write(this.formatter.MethodMiddleFormat, EcmaScriptWriter.Serialize(method.Name));

            if (method.Params.Length > 0)
            {
                string[] args = new string[method.Params.Length];
                for (int i = 0; i < method.Params.Length; i++)
                {
                    args[i] = method.Params[i].Name;
                }
                writer.Write(this.formatter.ArgsFormat, String.Join(",", args));
            }
            else
            {
                writer.Write("null");
            }

            writer.Write(this.formatter.MethodEndFormat);
        }
Esempio n. 2
0
 private void WriteProperty(TextWriter writer, string name, object value)
 {
     if (EcmaScriptIdentifier.IsValidIdentifier(name, false))
     {
         writer.Write(this.formatter.PropertyFormat, this.ProxyNamespace, name, EcmaScriptWriter.Serialize(value));
     }
     else
     {
         writer.Write(this.formatter.SafePropertyFormat, this.ProxyNamespace, EcmaScriptWriter.Serialize(name), EcmaScriptWriter.Serialize(value));
     }
 }
Esempio n. 3
0
        /// <summary>
        /// Processes each argument allowing string literals to code expressions to function calls.
        /// </summary>
        /// <param name="defaultValue">the default value if none was supplied</param>
        /// <param name="keys">an ordered list of keys to check</param>
        /// <returns>the resulting expression</returns>
        protected string ProcessArgument(string defaultValue, params string[] keys)
        {
            object argument = null;

            foreach (string key in keys)
            {
                if (this.Attributes.ContainsKey(key))
                {
                    argument = this.Attributes[key];
                    break;
                }
            }

            string value;

            if (argument == null)
            {
                value = defaultValue;
            }
            else if (argument is string)
            {
                // directly use as inline expression
                value = (string)argument;
            }
            else if (argument is JbstExpressionBlock)
            {
                // convert to inline expression
                value = ((JbstExpressionBlock)argument).Code;
            }
            else if (argument is JbstCodeBlock)
            {
                // convert to anonymous function expression
                value = String.Format(
                    FunctionEvalExpression,
                    EcmaScriptWriter.Serialize(argument));
            }
            else
            {
                // convert to literal expression
                value = EcmaScriptWriter.Serialize(argument);
            }

            return((value ?? String.Empty).Trim());
        }
Esempio n. 4
0
        public void OutputProxy(TextWriter writer, bool prettyPrint)
        {
            lock (this.SyncLock)
            {
                // locking because changing Formatter based upon debug switch

                if (prettyPrint)
                {
                    this.formatter = new DebugJsonServiceProxyFormat();
                }
                else
                {
                    this.formatter = new JsonServiceProxyFormat();
                }

                this.WriteNamespaces(writer);

                writer.Write(this.formatter.ProxyInstantiationFormat, this.ProxyNamespace, EcmaScriptWriter.Serialize(this.service.Address));

                foreach (JsonMethodDescription method in this.Service.Methods)
                {
                    this.WriteMethod(writer, method);
                }

                if (prettyPrint)
                {
                    this.WriteProperty(writer, "isDebug", true);
                }
            }
        }