예제 #1
0
        private void AddParameterElements(XElement complexType, ParameterInfo[] parameters, string[] requiredParameters)
        {
            XElement sequence = new XElement(_Namespace + "sequence");

            foreach (var parameter in from parameter in parameters
                     let typeName = MagickTypes.GetXsdElementType(parameter)
                                    where typeName != null
                                    orderby parameter.Name
                                    select new
            {
                Name = parameter.Name,
                TypeName = typeName,
                IsRequired = requiredParameters.Contains(parameter.Name)
            })
            {
                XElement element = new XElement(_Namespace + "element",
                                                new XAttribute("name", parameter.Name));

                if (!parameter.IsRequired)
                {
                    element.Add(new XAttribute("minOccurs", "0"));
                }

                element.Add(new XAttribute("type", parameter.TypeName));

                sequence.Add(element);
            }

            if (sequence.HasElements)
            {
                complexType.Add(sequence);
            }
        }
예제 #2
0
        private XElement CreateElement(PropertyInfo property)
        {
            string name = MagickTypes.GetXsdName(property);

            string attributeTypeName = MagickTypes.GetXsdAttributeType(property);

            if (attributeTypeName != null)
            {
                XElement complexType = new XElement(_Namespace + "complexType");
                complexType.Add(new XElement(_Namespace + "attribute",
                                             new XAttribute("name", "value"),
                                             new XAttribute("use", "required"),
                                             new XAttribute("type", attributeTypeName)));

                return(new XElement(_Namespace + "element",
                                    new XAttribute("name", name),
                                    complexType));
            }
            else
            {
                return(new XElement(_Namespace + "element",
                                    new XAttribute("name", name),
                                    new XAttribute("type", MagickTypes.GetXsdElementType(property))));
            }
        }
예제 #3
0
        private void AddParameterAttributes(XElement complexType, ParameterInfo[] parameters, string[] requiredParameters)
        {
            foreach (var parameter in from parameter in parameters
                     let typeName = MagickTypes.GetXsdAttributeType(parameter)
                                    where typeName != null
                                    orderby parameter.Name
                                    select new
            {
                Name = parameter.Name,
                TypeName = typeName,
                IsRequired = requiredParameters.Contains(parameter.Name)
            })
            {
                XElement attribute = new XElement(_Namespace + "attribute",
                                                  new XAttribute("name", parameter.Name));

                if (parameter.IsRequired)
                {
                    attribute.Add(new XAttribute("use", "required"));
                }

                attribute.Add(new XAttribute("type", parameter.TypeName));

                complexType.Add(attribute);
            }
        }
예제 #4
0
        private XElement CreateElement(PropertyInfo property)
        {
            string name = MagickTypes.GetXsdName(property);

            string attributeTypeName = MagickTypes.GetXsdAttributeType(property);

            if (attributeTypeName != null)
            {
                XElement complexType = new XElement(_Namespace + "complexType");
                complexType.Add(new XElement(_Namespace + "attribute",
                                             new XAttribute("name", "value"),
                                             new XAttribute("use", "required"),
                                             new XAttribute("type", attributeTypeName)));

                return(new XElement(_Namespace + "element",
                                    new XAttribute("name", name),
                                    complexType));
            }
            else
            {
                string elementTypeName = MagickTypes.GetXsdElementType(property);
                if (string.IsNullOrEmpty(elementTypeName))
                {
                    throw new NotImplementedException("CreateElement: " + name);
                }

                return(new XElement(_Namespace + "element",
                                    new XAttribute("name", name),
                                    new XAttribute("type", elementTypeName)));
            }
        }
예제 #5
0
        private void AddMethods(XElement element, IEnumerable <MethodBase> methods)
        {
            ParameterInfo[] parameters = (from method in methods
                                          from parameter in method.GetParameters()
                                          select parameter).ToArray();
            if (parameters.Length == 0)
            {
                element.Add(new XAttribute("type", "empty"));
                return;
            }

            if (methods.Count() == 1 && IsTypedElement(methods.First(), parameters))
            {
                string elementTypeName = MagickTypes.GetXsdElementType(parameters[0]);
                if (string.IsNullOrEmpty(elementTypeName))
                {
                    throw new NotImplementedException("AddMethods: " + methods.First().Name);
                }

                element.Add(new XAttribute("type", elementTypeName));
                return;
            }

            XElement complexType = new XElement(_Namespace + "complexType");

            AddArguments(complexType, methods);

            element.Add(complexType);
        }
예제 #6
0
        private XElement CreateElement(IEnumerable <MethodBase> methods)
        {
            XElement element = new XElement(_Namespace + "element",
                                            new XAttribute("name", MagickTypes.GetXsdName(methods.First())));

            AddMethods(element, methods);
            return(element);
        }
예제 #7
0
        public XsdGenerator(QuantumDepth depth)
        {
            _Depth = depth;
            _Types = new MagickTypes(depth);

            _Namespaces = new XmlNamespaceManager(new NameTable());
            _Namespaces.AddNamespace("xs", _Namespace.ToString());
        }
예제 #8
0
 private void ReplaceIReadDefines(XElement annotation)
 {
     annotation.ReplaceWith(
         from type in _Types.GetInterfaceTypes("IReadDefines")
         let name = MagickTypes.GetXsdName(type)
                    select new XElement(_Namespace + "element",
                                        new XAttribute("name", name),
                                        new XAttribute("type", name)));
 }
예제 #9
0
        public void Write(MagickTypes types)
        {
            Types = types;

            WriteStart("ImageMagick");
            WriteLine("public sealed partial class MagickScript");
            WriteStartColon();
            WriteCode();
            WriteEndColon();
            WriteEnd();
        }
예제 #10
0
        private void WriteCallMethods()
        {
            foreach (MethodBase method in Methods)
            {
                string          xsdMethodName = MagickTypes.GetXsdName(method);
                ParameterInfo[] parameters    = method.GetParameters();

                Write("XmlElement ");
                Write(xsdMethodName);
                Write(" = (XmlElement)element.SelectSingleNode(\"");
                Write(xsdMethodName);
                WriteLine("\");");

                Write("if (");
                Write(xsdMethodName);
                WriteLine(" != null)");
                WriteStartColon();

                foreach (ParameterInfo parameter in parameters)
                {
                    string typeName = GetName(parameter);

                    Write(typeName);
                    Write(" ");
                    Write(parameter.Name);
                    Write("_ = XmlHelper.GetAttribute<");
                    Write(typeName);
                    Write(">(");
                    Write(xsdMethodName);
                    Write(", \"");
                    Write(parameter.Name);
                    WriteLine("\");");
                }

                Write("result.");
                Write(method.Name);
                Write("(");

                for (int i = 0; i < parameters.Length; i++)
                {
                    if (i > 0)
                    {
                        Write(",");
                    }

                    Write(parameters[i].Name);
                    Write("_");
                }

                WriteLine(");");
                WriteEndColon();
            }
        }
예제 #11
0
        public void Write(IndentedTextWriter writer, MagickTypes types)
        {
            Types = types;

            WriteHeader(writer);
            WriteUsing(writer);
            WriteStartNamespace(writer);
            writer.WriteLine("public sealed partial class MagickScript");
            WriteStartColon(writer);
            WriteCode(writer);
            WriteEndColon(writer);
            WriteEndColon(writer);
        }
예제 #12
0
        private void ReplaceDefines(XElement annotation)
        {
            List <XElement> types = new List <XElement>();

            foreach (Type interfaceType in _Types.GetInterfaceTypes("IDefines"))
            {
                XElement complexType = new XElement(_Namespace + "complexType",
                                                    new XAttribute("name", MagickTypes.GetXsdName(interfaceType)));
                AddClass(complexType, interfaceType);
                types.Add(complexType);
            }

            annotation.ReplaceWith(types.ToArray());
        }
 private void WriteCode(string className)
 {
     Write("private ");
     Write(className);
     Write(" Create");
     Write(className);
     WriteLine("(XmlElement parent)");
     WriteStartColon();
     WriteCheckNull("parent");
     WriteLine("XmlElement element = (XmlElement)parent.FirstChild;");
     WriteCheckNull("element");
     WriteSwitch(from type in Types.GetInterfaceTypes(className)
                 select MagickTypes.GetXsdName(type));
     WriteEndColon();
 }
예제 #14
0
 private void WriteCode(IndentedTextWriter writer, string className)
 {
     WriteSeparator(writer);
     writer.Write("private ");
     writer.Write(className);
     writer.Write(" Create");
     writer.Write(className);
     writer.WriteLine("(XmlElement parent)");
     WriteStartColon(writer);
     CheckNull(writer, "parent");
     writer.WriteLine("XmlElement element = (XmlElement)parent.FirstChild;");
     CheckNull(writer, "element");
     WriteSwitch(writer, from type in Types.GetInterfaceTypes(className)
                 select MagickTypes.GetXsdName(type));
     WriteEndColon(writer);
 }
예제 #15
0
        private void WriteGetValue(ParameterInfo parameter)
        {
            string typeName    = GetName(parameter);
            string xsdTypeName = MagickTypes.GetXsdAttributeType(parameter);

            if (xsdTypeName != null)
            {
                WriteGetElementValue(typeName, parameter.Name);
            }
            else
            {
                WriteCreateMethod(typeName);
                Write("(");
                WriteSelectElement(typeName, parameter.Name);
                WriteLine(");");
            }
        }
예제 #16
0
        private void WriteGetValue(PropertyInfo property)
        {
            string typeName    = GetName(property);
            string xsdTypeName = MagickTypes.GetXsdAttributeType(property);

            if (xsdTypeName != null)
            {
                WriteGetElementValue(typeName, MagickTypes.GetXsdName(property));
            }
            else
            {
                WriteCreateMethod(typeName);
                Write("(");
                WriteSelectElement(typeName, MagickTypes.GetXsdName(property));
                WriteLine(");");
            }
        }
예제 #17
0
        protected void WriteGetValue(IndentedTextWriter writer, PropertyInfo property)
        {
            string typeName    = GetName(property);
            string xsdTypeName = MagickTypes.GetXsdAttributeType(property);

            if (xsdTypeName != null)
            {
                WriteGetElementValue(writer, typeName, "value");
            }
            else
            {
                WriteCreateMethod(writer, typeName);
                writer.Write("(");
                WriteSelectElement(writer, typeName, null);
                writer.WriteLine(");");
            }
        }
예제 #18
0
        private void Write()
        {
            string folder     = MagickTypes.GetFolderName(_Depth);
            string outputFile = Path.GetFullPath(AppDomain.CurrentDomain.BaseDirectory + @"..\..\..\..\Magick.NET\Resources\" + folder + @"\MagickScript.xsd");

            Console.WriteLine("Creating: " + outputFile);

            XmlWriterSettings settings = new XmlWriterSettings();

            settings.Indent      = true;
            settings.IndentChars = "  ";

            using (XmlWriter writer = XmlWriter.Create(outputFile, settings))
            {
                _Document.Save(writer);
            }
        }
예제 #19
0
 private void AddClassAttributes(XElement complexType, IEnumerable <PropertyInfo> properties)
 {
     foreach (var property in from property in properties
              let typeName = MagickTypes.GetXsdAttributeType(property)
                             where typeName != null
                             let name = MagickTypes.GetXsdName(property)
                                        orderby name
                                        select new
     {
         Name = name,
         TypeName = typeName
     })
     {
         complexType.Add(new XElement(_Namespace + "attribute",
                                      new XAttribute("name", property.Name),
                                      new XAttribute("type", property.TypeName)));
     }
 }
예제 #20
0
        private void WriteAttributeForEach(ParameterInfo[] allParameters)
        {
            ParameterInfo[] parameters = allParameters.Where(p => MagickTypes.GetXsdAttributeType(p) != null).ToArray();
            if (parameters.Length == 0)
            {
                return;
            }

            parameters = parameters.OrderBy(p => p.Name).ToArray();

            WriteLine("foreach (XmlAttribute attribute in element.Attributes)");
            WriteStartColon();

            if (parameters.DistinctBy(p => GetName(p)).Count() == 1)
            {
                Write("arguments[attribute.Name] = Variables.GetValue<");
                Write(GetName(parameters[0]));
                WriteLine(">(attribute);");
            }
            else
            {
                for (int i = 0; i < parameters.Length; i++)
                {
                    string xsdName = MagickTypes.GetXsdName(parameters[i]);

                    if (i > 0)
                    {
                        Write("else ");
                    }

                    Write("if (attribute.Name == \"");
                    Write(xsdName);
                    WriteLine("\")");
                    Indent++;
                    Write("arguments[\"");
                    Write(xsdName);
                    Write("\"] = ");
                    WriteGetAttributeValue(GetName(parameters[i]));
                    Indent--;
                }
            }

            WriteEndColon();
        }
예제 #21
0
        private void WriteElementForEach(ParameterInfo[] allParameters)
        {
            ParameterInfo[] parameters = allParameters.Where(p => MagickTypes.GetXsdAttributeType(p) == null).ToArray();
            if (parameters.Length == 0)
            {
                return;
            }

            WriteLine("foreach (XmlElement elem in element.SelectNodes(\"*\"))");
            WriteStartColon();

            if (parameters.DistinctBy(p => GetName(p)).Count() == 1)
            {
                Write("arguments[elem.Name] = ");
                WriteCreateMethod(GetName(parameters[0]));
                WriteLine("(elem);");
            }
            else
            {
                for (int i = 0; i < parameters.Length; i++)
                {
                    string xsdName = MagickTypes.GetXsdName(parameters[i]);

                    if (i > 0)
                    {
                        Write("else ");
                    }

                    Write("if (elem.Name == \"");
                    Write(xsdName);
                    WriteLine("\")");
                    Indent++;
                    Write("arguments[\"");
                    Write(xsdName);
                    Write("\"] = ");
                    WriteCreateMethod(GetName(parameters[i]));
                    WriteLine("(elem);");
                    Indent--;
                }
            }

            WriteEndColon();
        }
예제 #22
0
        private void AddClassElements(XElement complexType, IEnumerable <PropertyInfo> properties, IEnumerable <MethodInfo> methods)
        {
            XElement sequence = new XElement(_Namespace + "sequence");

            foreach (var property in from property in properties
                     let typeName = MagickTypes.GetXsdElementType(property)
                                    where typeName != null
                                    let name = MagickTypes.GetXsdName(property)
                                               orderby name
                                               select new
            {
                Name = name,
                TypeName = typeName
            })
            {
                XElement element = new XElement(_Namespace + "element",
                                                new XAttribute("name", property.Name),
                                                new XAttribute("minOccurs", "0"));

                element.Add(new XAttribute("type", property.TypeName));

                sequence.Add(element);
            }

            if (methods.Count() > 0)
            {
                foreach (MethodBase method in methods)
                {
                    XElement element = new XElement(_Namespace + "element",
                                                    new XAttribute("name", MagickTypes.GetXsdName(methods.First())),
                                                    new XAttribute("minOccurs", "0"),
                                                    new XAttribute("maxOccurs", "unbounded"));
                    AddMethods(element, new MethodBase[] { method });
                    sequence.Add(element);
                }
            }

            if (sequence.HasElements)
            {
                complexType.Add(sequence);
            }
        }
예제 #23
0
        protected sealed override void WriteCase(IndentedTextWriter writer, string name)
        {
            MemberInfo member = (from property in Properties
                                 where MagickTypes.GetXsdName(property).Equals(name, StringComparison.OrdinalIgnoreCase)
                                 select property).FirstOrDefault();

            if (member == null)
            {
                member = (from overloads in Methods
                          let method = overloads[overloads.Length - 1]
                                       where MagickTypes.GetXsdName(method).Equals(name, StringComparison.OrdinalIgnoreCase)
                                       select method).FirstOrDefault();
            }


            if (ReturnType != "void")
            {
                writer.Write("return ");
            }
            writer.Write("Execute");
            if (member == null)
            {
                writer.Write(char.ToUpper(name[0], CultureInfo.InvariantCulture));
                writer.Write(name.Substring(1));
            }
            else
            {
                writer.Write(GetName(member));
            }
            writer.Write("(");
            if (member == null || !HasParameters(member))
            {
                writer.Write("element, ");
            }
            writer.Write(ExecuteArgument.Split(' ').Last());
            writer.WriteLine(");");
            if (ReturnType == "void")
            {
                writer.WriteLine("return;");
            }
        }
예제 #24
0
        private void WriteExecute(IndentedTextWriter writer)
        {
            writer.WriteLine("[SuppressMessage(\"Microsoft.Maintainability\", \"CA1502:AvoidExcessiveComplexity\")]");
            writer.WriteLine("[SuppressMessage(\"Microsoft.Maintainability\", \"CA1505:AvoidUnmaintainableCode\")]");
            writer.Write("private ");
            writer.Write(ReturnType);
            writer.Write(" Execute");
            writer.Write(ExecuteName);
            writer.Write("(XmlElement element, ");
            writer.Write(ExecuteArgument);
            writer.WriteLine(")");
            WriteStartColon(writer);

            IEnumerable <string> names = (from property in Properties
                                          select MagickTypes.GetXsdName(property)).Concat(
                from method in Methods
                select MagickTypes.GetXsdName(method[0])).Concat(
                CustomMethods);

            WriteSwitch(writer, names);
            WriteEndColon(writer);
        }
예제 #25
0
        private void AddMethods(XElement element, IEnumerable <MethodBase> methods)
        {
            ParameterInfo[] parameters = (from method in methods
                                          from parameter in method.GetParameters()
                                          select parameter).ToArray();
            if (parameters.Length == 0)
            {
                element.Add(new XAttribute("type", "empty"));
                return;
            }

            if (methods.Count() == 1 && IsTypedElement(methods.First(), parameters))
            {
                element.Add(new XAttribute("type", MagickTypes.GetXsdElementType(parameters[0])));
                return;
            }

            XElement complexType = new XElement(_Namespace + "complexType");

            AddArguments(complexType, methods);

            element.Add(complexType);
        }
예제 #26
0
        private bool IsStatic(MethodBase[] methods)
        {
            if (methods == null)
            {
                return(false);
            }

            if (methods.Length != 1)
            {
                return(false);
            }

            ParameterInfo[] parameters = methods[0].GetParameters();

            if (parameters.Length == 0)
            {
                return(true);
            }

            foreach (ParameterInfo parameter in parameters)
            {
                string xsdTypeName = MagickTypes.GetXsdAttributeType(parameter);
                if (xsdTypeName != null)
                {
                    return(false);
                }

                string typeName = GetName(parameter);
                if (!HasStaticCreateMethod(typeName))
                {
                    return(false);
                }
            }

            return(true);
        }
예제 #27
0
 protected static string GetName(MemberInfo member)
 {
     return(MagickTypes.GetName(member));
 }
예제 #28
0
 private void WriteInvalidCombinations(MethodBase[] methods)
 {
     WriteLine("else");
     Indent++;
     Write("throw new ArgumentException(\"Invalid argument combination for '" + MagickTypes.GetXsdName(methods[0]) + "', allowed combinations are:");
     foreach (MethodBase method in methods)
     {
         Write(" [");
         ParameterInfo[] parameters = method.GetParameters();
         for (int i = 0; i < parameters.Length; i++)
         {
             Write(parameters[i].Name);
             if (i != parameters.Length - 1)
             {
                 Write(", ");
             }
         }
         Write("]");
     }
     WriteLine("\");");
     Indent--;
 }
 private MagickScriptGenerator()
 {
     _OutputFolder = SetOutputFolder(@"Magick.NET\Core\Script\Generated");
     _Types        = new MagickTypes(QuantumDepth.Q16HDRI);
 }
예제 #30
0
 public void WriteCode(MagickTypes types)
 {
     Types = types;
     WriteCode();
 }
예제 #31
0
    public void Write(IndentedTextWriter writer, MagickTypes types)
    {
      Types = types;

      WriteHeader(writer);
      WriteUsing(writer);
      WriteStartNamespace(writer);
      writer.WriteLine("public sealed partial class MagickScript");
      WriteStartColon(writer);
      WriteCode(writer);
      WriteEndColon(writer);
      WriteEndColon(writer);
    }
예제 #32
0
 public void WriteCode(IndentedTextWriter writer, MagickTypes types)
 {
   Types = types;
   WriteCode(writer);
 }
예제 #33
0
 private MagickScriptGenerator()
 {
   _OutputFolder = SetOutputFolder(@"Magick.NET\Script\Generated");
   _Types = new MagickTypes(QuantumDepth.Q16HDRI);
 }
예제 #34
0
    public XsdGenerator(QuantumDepth depth)
    {
      _Depth = depth;
      _Types = new MagickTypes(depth);

      _Namespaces = new XmlNamespaceManager(new NameTable());
      _Namespaces.AddNamespace("xs", _Namespace.ToString());
    }