Пример #1
0
 internal Parameter(ParameterBuilder builder, Method method)
 {
     Debug.Assert(builder != null);
     Debug.Assert(builder.Position >= 0);
     Debug.Assert(method != null);
     
     _name = builder.Name;
     _parameterType = builder.ParameterType;
     _position = builder.Position;
     _isParamArray = builder.IsParamArray;
     _method = method;
 }
Пример #2
0
        private readonly Method[] _sortedMethods;    // FIXME: [ NonSerialized ]
        
        internal ServiceClass(ServiceClassBuilder classBuilder)
        {
            Debug.Assert(classBuilder != null);
            
            _serviceName = classBuilder.Name;
            _description = classBuilder.Description;

            //
            // Set up methods and their names.
            //

            ICollection methodBuilders = classBuilder.Methods;
            _methods = new Method[methodBuilders.Count];
            _methodNames = new string[methodBuilders.Count];
            int methodIndex = 0;

            foreach (MethodBuilder methodBuilder in methodBuilders)
            {
                Method method = new Method(methodBuilder, this);

                //
                // Check for duplicates.
                //

                if (Array.IndexOf(_methodNames, method.Name) >= 0)
                    throw new DuplicateMethodException(string.Format("The method '{0}' cannot be exported as '{1}' because this name has already been used by another method on the '{2}' service.", method.Name, method.InternalName, _serviceName));

                //
                // Add the method to the class and index it by its name.
                //

                _methods[methodIndex] = method;
                _methodNames[methodIndex++] = method.Name;
            }

            //
            // Keep a sorted list of parameters and their names so we can
            // do fast look ups using binary search.
            //
            
            _sortedMethods = (Method[]) _methods.Clone();
            InvariantStringArray.Sort(_methodNames, _sortedMethods);
        }
Пример #3
0
        private static object ReadParameters(Method method, JsonReader reader, ImportContext importContext)
        {
            Debug.Assert(method != null);
            Debug.Assert(reader != null);
            Debug.Assert(importContext != null);

            reader.MoveToContent();

            Parameter[] parameters = method.GetParameters();

            if (reader.TokenClass == JsonTokenClass.Array)
            {
                reader.Read();
                ArrayList argList = new ArrayList(parameters.Length);

                // TODO: This loop could bomb when more args are supplied that parameters available.

                for (int i = 0; i < parameters.Length && reader.TokenClass != JsonTokenClass.EndArray; i++)
                    argList.Add(importContext.Import(parameters[i].ParameterType, reader));

                reader.StepOut();
                return argList.ToArray();
            }
            else if (reader.TokenClass == JsonTokenClass.Object)
            {
                reader.Read();
                JsonObject argByName = new JsonObject();

                while (reader.TokenClass != JsonTokenClass.EndObject)
                {
                    // TODO: Imporve this lookup.
                    // FIXME: Does not work when argument is positional.

                    Type parameterType = AnyType.Value;
                    string name = reader.ReadMember();

                    foreach (Parameter parameter in parameters)
                    {
                        if (parameter.Name.Equals(name))
                        {
                            parameterType = parameter.ParameterType;
                            break;
                        }
                    }

                    argByName.Put(name, importContext.Import(parameterType, reader));
                }

                reader.Read();
                return argByName;
            }
            else
            {
                return importContext.Import(reader);
            }
        }
        private void WriteMethod(IndentedTextWriter writer, Method method)
        {
            string clientMethodName = method.Name.Replace(".", "_");

            writer.Write("def ");
            writer.Write(clientMethodName);
            writer.Write("(self");

            Parameter[] parameters = method.GetParameters();

            foreach (Parameter parameter in parameters)
            {
                writer.Write(", ");
                writer.Write(parameter.Name);
            }

            writer.WriteLine("):");
            writer.Indent++;

            if (method.Description.Length > 0)
            {
                // TODO: What to do if /* and */ appear in the summary?

                writer.Write(_docQuotes);
                writer.WriteLine(method.Description);
                writer.WriteLine(_docQuotes);
            }

            writer.Write("return self.__call('");
            writer.Write(method.Name);
            writer.Write("', (");

            foreach (Parameter parameter in parameters)
            {
                writer.Write(parameter.Name);
                writer.Write(", ");
            }

            writer.WriteLine("))");
            writer.Indent--;
            writer.WriteLine();
        }
Пример #5
0
        private static void AddSignature(Control parent, Method method)
        {
            Control methodSignatureSpan = AddSpan(parent, "method-sig", null);
            AddSpan(methodSignatureSpan, "method-param-open", "(");

            Parameter[] parameters = method.GetParameters();
            foreach (Parameter parameter in parameters)
            {
                if (parameter.Position > 0)
                    AddSpan(methodSignatureSpan, "method-param-delim", ", ");

                AddSpan(methodSignatureSpan, "method-param", parameter.Name);
            }

            AddSpan(methodSignatureSpan, "method-param-close", ")");
        }
Пример #6
0
        private static void AddMethod(Control parent, Method method)
        {
            Control methodTerm = AddGeneric(parent, "dt", "method");
            AddSpan(methodTerm, "method-name", method.Name);
            AddSignature(methodTerm, method);

            if (method.Description.Length > 0)
                AddGeneric(parent, "dd", "method-summary", method.Description);
        }
Пример #7
0
        private void AddMethod(Control parent, Method method)
        {
            JsonRpcObsoleteAttribute obsolete = (JsonRpcObsoleteAttribute) method.FindFirstCustomAttribute(typeof(JsonRpcObsoleteAttribute));
            
            Control methodTerm = AddGeneric(parent, "dt", obsolete == null ? "method" : "method obsolete-method");
            AddSpan(methodTerm, "method-name", method.Name);
            AddSignature(methodTerm, method);

            if (method.Description.Length > 0)
                AddGeneric(parent, "dd", "method-summary", method.Description);

            if (obsolete != null)
                AddGeneric(parent, "dd", "obsolete-message", " This method has been obsoleted. " + obsolete.Message);
        }
 protected abstract void WriteMethod(IndentedTextWriter writer, Method method);
 protected override void WriteMethod(IndentedTextWriter writer, Method method)
 {
     throw new NotImplementedException();
 }