예제 #1
0
        /// <summary>
        /// Produces a Pascal-case string from an input string.
        /// It compares the idenfier and compareIdentifier params, in case they're the same then the suffix Field is appended to the identifier.
        /// </summary>
        /// <param name="identifier">The name of a code entity, such as a method parameter.</param>
        /// <param name="compareIdentifier">The name of a code entity, such as a method parameter to compare.</param>
        /// <returns></returns>
        public static string ToPascalCase(string identifier, string compareIdentifier)
        {
            Guard.ArgumentNotNullOrEmptyString(identifier, "identifier");
            Guard.ArgumentNotNullOrEmptyString(compareIdentifier, "compareIdentifier");

            string pascalCase = CodeIdentifier.MakePascal(identifier);

            return(compareIdentifier == pascalCase ||
                   !csProvider.IsValidIdentifier(pascalCase) ? pascalCase + "Field" : pascalCase);
        }
예제 #2
0
 /// <devdoc>
 ///    <para>[To be supplied.]</para>
 /// </devdoc>
 public string MakeRightCase(string identifier)
 {
     if (_camelCase)
     {
         return(CodeIdentifier.MakeCamel(identifier));
     }
     else
     {
         return(CodeIdentifier.MakePascal(identifier));
     }
 }
예제 #3
0
        private static string Proper(string text)
        {
            if (text.Contains("_"))
            {
                StringBuilder sb = new StringBuilder();
                foreach (var section in text.Split('_'))
                {
                    sb.Append(CodeIdentifier.MakePascal(section));
                }

                return(sb.ToString());
            }
            else
            {
                return(CodeIdentifier.MakePascal(text));
            }
        }
        private void Initialize(OpenApiSchema schema, Entity entity, OpenApiOptions options)
        {
            if (entity.Initialized)
            {
                return;
            }

            entity.Initialized = true;
            AddPrimaryKeyProperty(entity, options);
            foreach (var kvp in schema.Properties)
            {
                //if (schema.Type == "array" || schema.Reference != null)
                //{
                //    continue;
                //}
                string        propertyName   = CodeIdentifier.MakePascal(kvp.Key);
                OpenApiSchema propertySchema = kvp.Value;
                string        propertyType   = Converter.ConvertToType(propertySchema);
                Property      property       = entity.AddProperty(propertyName, propertyType);
            }

            foreach (var kvp in schema.Properties)
            {
                string        propertyName   = kvp.Key;
                OpenApiSchema propertySchema = kvp.Value;
                if (propertySchema.Type == "array")
                {
                    Property property = entity.GetProperties().FirstOrDefault(p => p.Name == propertyName);
                    if (propertySchema.Items.Reference?.IsLocal == true)
                    {
                        string        findName        = propertySchema.Items.Reference.Id;
                        Entity        dependentEntity = Model.GetOrAddEntity(findName);
                        OpenApiSchema openApiSchema   = options.Document.Components.Schemas[findName];
                        Initialize(openApiSchema, dependentEntity, options);
                        Key    principalKey    = entity.FindPrimaryKey();
                        Entity principalEntity = entity;
                        string foreignKeyName  = principalKey.Property.Name;
                        dependentEntity.AddProperty(foreignKeyName, options.PrimaryKeyTypeName);
                        dependentEntity.AddProperty(principalEntity.Name, principalEntity.Name);
                    }
                }
            }
        }
예제 #5
0
 public static string MakeCommandIDName(string id)
 {
     return(string.Format("{0}CommandId", CodeIdentifier.MakePascal(id)));
 }
예제 #6
0
 public static string MakeBeforeQueryStatusMethodName(string id)
 {
     return(string.Format("OnBeforeQueryStatus{0}", CodeIdentifier.MakePascal(id)));
 }
예제 #7
0
 public static string MakeExecuteCommandMethodName(string id)
 {
     return(string.Format("OnExecute{0}", CodeIdentifier.MakePascal(id)));
 }
예제 #8
0
        /// <summary>
        /// Produces a Pascal-case string from an input string.
        /// </summary>
        /// <param name="identifier">The name of a code entity, such as a method parameter.</param>
        /// <returns></returns>
        public static string ToPascalCase(string identifier)
        {
            Guard.ArgumentNotNullOrEmptyString(identifier, "identifier");

            return(csProvider.CreateValidIdentifier(CodeIdentifier.MakePascal(identifier)));
        }
        void GenerateClassForBinding()
        {
            try {
                if (bindingCount == 1 && service != null && Style != ServiceDescriptionImportStyle.ServerInterface)
                {
                    // If there is only one binding, then use the name of the service
                    className = XmlConvert.DecodeName(service.Name);
                }
                else
                {
                    // If multiple bindings, then use the name of the binding
                    className = binding.Name;
                    if (Style == ServiceDescriptionImportStyle.ServerInterface)
                    {
                        // append "I" if we are generating interfaces
                        className = "I" + CodeIdentifier.MakePascal(className);
                    }
                }
                className      = XmlConvert.DecodeName(className);
                className      = ClassNames.AddUnique(CodeIdentifier.MakeValid(className), null);
                this.codeClass = BeginClass();
                int methodCount = 0;
                for (int i = 0; i < portType.Operations.Count; i++)
                {
                    MoveToOperation(portType.Operations[i]);

                    if (!IsOperationFlowSupported(operation.Messages.Flow))
                    {
                        //
                        switch (operation.Messages.Flow)
                        {
                        case OperationFlow.SolicitResponse:
                            UnsupportedOperationWarning(Res.GetString(Res.SolicitResponseIsNotSupported0));
                            continue;

                        case OperationFlow.RequestResponse:
                            UnsupportedOperationWarning(Res.GetString(Res.RequestResponseIsNotSupported0));
                            continue;

                        case OperationFlow.OneWay:
                            UnsupportedOperationWarning(Res.GetString(Res.OneWayIsNotSupported0));
                            continue;

                        case OperationFlow.Notification:
                            UnsupportedOperationWarning(Res.GetString(Res.NotificationIsNotSupported0));
                            continue;
                        }
                    }

                    CodeMemberMethod method;
                    try {
                        method = GenerateMethod();
                    }
                    catch (Exception e) {
                        if (e is ThreadAbortException || e is StackOverflowException || e is OutOfMemoryException)
                        {
                            throw;
                        }
                        throw new InvalidOperationException(Res.GetString(Res.UnableToImportOperation1, operation.Name), e);
                    }

                    if (method != null)
                    {
                        AddExtensionWarningComments(codeClass.Comments, operationBinding.Extensions);
                        if (operationBinding.Input != null)
                        {
                            AddExtensionWarningComments(codeClass.Comments, operationBinding.Input.Extensions);
                        }
                        if (operationBinding.Output != null)
                        {
                            AddExtensionWarningComments(codeClass.Comments, operationBinding.Output.Extensions);
                        }
                        methodCount++;
                    }
                }
                bool newAsync = (ServiceImporter.CodeGenerationOptions & CodeGenerationOptions.GenerateNewAsync) != 0 &&
                                ServiceImporter.CodeGenerator.Supports(GeneratorSupport.DeclareEvents) &&
                                ServiceImporter.CodeGenerator.Supports(GeneratorSupport.DeclareDelegates);
                if (newAsync && methodCount > 0 && Style == ServiceDescriptionImportStyle.Client)
                {
                    CodeAttributeDeclarationCollection metadata = new CodeAttributeDeclarationCollection();
                    string           cancelAsync       = "CancelAsync";
                    string           cancelMethodName  = MethodNames.AddUnique(cancelAsync, cancelAsync);
                    CodeMemberMethod asyncCancelMethod = WebCodeGenerator.AddMethod(this.CodeTypeDeclaration, cancelMethodName,
                                                                                    new CodeFlags[1], new string[] { typeof(object).FullName }, new string[] { "userState" },
                                                                                    typeof(void).FullName,
                                                                                    metadata,
                                                                                    CodeFlags.IsPublic | (cancelAsync != cancelMethodName ? 0 : CodeFlags.IsNew));

                    asyncCancelMethod.Comments.Add(new CodeCommentStatement(Res.GetString(Res.CodeRemarks), true));
                    CodeMethodInvokeExpression invoke = new CodeMethodInvokeExpression(new CodeBaseReferenceExpression(), cancelAsync);
                    invoke.Parameters.Add(new CodeArgumentReferenceExpression("userState"));
                    asyncCancelMethod.Statements.Add(invoke);
                }

                EndClass();

                if (portType.Operations.Count == 0)
                {
                    NoMethodsGeneratedWarning();
                }

                AddExtensionWarningComments(codeClass.Comments, binding.Extensions);
                if (port != null)
                {
                    AddExtensionWarningComments(codeClass.Comments, port.Extensions);
                }

                codeNamespace.Types.Add(codeClass);
            }
            catch (Exception e) {
                if (e is ThreadAbortException || e is StackOverflowException || e is OutOfMemoryException)
                {
                    throw;
                }
                throw new InvalidOperationException(Res.GetString(Res.UnableToImportBindingFromNamespace2, binding.Name, binding.ServiceDescription.TargetNamespace), e);
            }
        }
예제 #10
0
        // UNDONE Nullable
        private void SetArrayMappingType(ArrayMapping mapping)
        {
            bool useDefaultNs = false;

            string itemTypeName;
            string itemTypeNamespace;

            TypeMapping itemTypeMapping;

            if (mapping.Elements.Length == 1)
            {
                itemTypeMapping = mapping.Elements[0].Mapping;
            }
            else
            {
                itemTypeMapping = null;
            }

            if (itemTypeMapping is EnumMapping)
            {
                itemTypeNamespace = itemTypeMapping.Namespace;
                itemTypeName      = itemTypeMapping.TypeName;
            }
            else if (itemTypeMapping is PrimitiveMapping)
            {
                itemTypeNamespace = itemTypeMapping.TypeDesc.IsXsdType ? XmlSchema.Namespace : UrtTypes.Namespace;
                itemTypeName      = itemTypeMapping.TypeDesc.DataType.Name;
                useDefaultNs      = true;
            }
            else if (itemTypeMapping is StructMapping)
            {
                if (itemTypeMapping.TypeDesc.IsRoot)
                {
                    itemTypeNamespace = XmlSchema.Namespace;
                    itemTypeName      = Soap.UrType;
                    useDefaultNs      = true;
                }
                else
                {
                    itemTypeNamespace = itemTypeMapping.Namespace;
                    itemTypeName      = itemTypeMapping.TypeName;
                }
            }
            else if (itemTypeMapping is ArrayMapping)
            {
                itemTypeNamespace = itemTypeMapping.Namespace;
                itemTypeName      = itemTypeMapping.TypeName;
            }
            else
            {
                throw new InvalidOperationException(SR.Format(SR.XmlInvalidSoapArray, mapping.TypeDesc.FullName));
            }

            itemTypeName = CodeIdentifier.MakePascal(itemTypeName);
            string      uniqueName      = "ArrayOf" + itemTypeName;
            string      ns              = useDefaultNs ? _defaultNs : itemTypeNamespace;
            int         i               = 1;
            TypeMapping existingMapping = (TypeMapping)_types[uniqueName, ns];

            while (existingMapping != null)
            {
                if (existingMapping is ArrayMapping)
                {
                    ArrayMapping arrayMapping = (ArrayMapping)existingMapping;
                    if (AccessorMapping.ElementsMatch(arrayMapping.Elements, mapping.Elements))
                    {
                        break;
                    }
                }
                // need to re-name the mapping
                uniqueName      = itemTypeName + i.ToString(CultureInfo.InvariantCulture);
                existingMapping = (TypeMapping)_types[uniqueName, ns];
                i++;
            }
            mapping.Namespace = ns;
            mapping.TypeName  = uniqueName;
        }
예제 #11
0
 public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
 {
     return(System.Enum.Parse(typeof(JurisdictionType), CodeIdentifier.MakePascal(value.ToString())));
 }
예제 #12
0
        static string[] unwantedPrefixes = new string[] { "", "xsd", "abs", "cct" }; //,"ccts-cct" ,"ds", "xades" };


        /// <summary>
        /// </summary>
        public UblNamespaceManager(XmlSchemaSet schemaSet, string csDefaultNamespace, bool optimizeCommonBasicComponents)
        {
            this.schemaSet          = schemaSet;
            this.csDefaultNamespace = csDefaultNamespace;
            this.OptionOptimizeCommonBasicComponents = optimizeCommonBasicComponents;

            // Build a xml namespace(key) to csharp codenamespace/scope(value) dictionary by looking at all schema root xmlns attributes
            // Will bomb out on Distinct() if schemas use different namespace prefixes for the same namespace (empty ones are removed)
            xml2CSharpNamespaceDictionary = schemaSet.Schemas().Cast <XmlSchema>()
                                            .SelectMany(schema => schema.Namespaces.ToArray().Where(qname => !unwantedPrefixes.Contains(qname.Name)))
                                            .Select(qname => new { qname.Namespace, qname.Name })
                                            .Distinct()
                                            .ToDictionary(key => key.Namespace, val => $"{csDefaultNamespace}.{ CodeIdentifier.MakePascal(val.Name)}");

            // missing references in 2.1. Is it unused?
            xml2CSharpNamespaceDictionary.Add(Constants.CommonSignatureComponentsTargetNamespace, $"{csDefaultNamespace}.Csc");
            xml2CSharpNamespaceDictionary[Constants.Xadesv132TargetNamespace] = $"{csDefaultNamespace}.Xades";
            xml2CSharpNamespaceDictionary[Constants.Xadesv141TargetNamespace] = $"{csDefaultNamespace}.Xades";// 141"; // Probably incorrect

            // add key:xmlns value:cSharpScope for all maindocs. They all point to the same scope value string
            foreach (XmlSchema schema in schemaSet.MaindocSchemas().Cast <XmlSchema>())
            {
                string targetNamespace = schema.TargetNamespace;
                if (!xml2CSharpNamespaceDictionary.ContainsKey(targetNamespace))
                {
                    xml2CSharpNamespaceDictionary.Add(targetNamespace, csDefaultNamespace);
                }
            }

            // using directives in csharp files may vary depending on optimising of types
            if (this.OptionOptimizeCommonBasicComponents)
            {
                codeNamespaceUsings = codeNamespaceUsingsOptimized;
            }
            else
            {
                codeNamespaceUsings = codeNamespaceUsingsNonOptimized;
            }
            // prepend dictionary keys with default C# code namespace separated by a dot.
            codeNamespaceUsings = codeNamespaceUsings.ToDictionary(k => csDefaultNamespace + (k.Key == "" ? "" : ".") + k.Key, v => v.Value);
        }
예제 #13
0
        private void GenerateClassForBinding()
        {
            try
            {
                if (((this.bindingCount == 1) && (this.service != null)) && (this.Style != ServiceDescriptionImportStyle.ServerInterface))
                {
                    this.className = XmlConvert.DecodeName(this.service.Name);
                }
                else
                {
                    this.className = this.binding.Name;
                    if (this.Style == ServiceDescriptionImportStyle.ServerInterface)
                    {
                        this.className = "I" + CodeIdentifier.MakePascal(this.className);
                    }
                }
                this.className = XmlConvert.DecodeName(this.className);
                this.className = this.ClassNames.AddUnique(CodeIdentifier.MakeValid(this.className), null);
                this.codeClass = this.BeginClass();
                int num = 0;
                for (int i = 0; i < this.portType.Operations.Count; i++)
                {
                    CodeMemberMethod method;
                    this.MoveToOperation(this.portType.Operations[i]);
                    if (!this.IsOperationFlowSupported(this.operation.Messages.Flow))
                    {
                        switch (this.operation.Messages.Flow)
                        {
                        case OperationFlow.OneWay:
                        {
                            this.UnsupportedOperationWarning(System.Web.Services.Res.GetString("OneWayIsNotSupported0"));
                            continue;
                        }

                        case OperationFlow.Notification:
                        {
                            this.UnsupportedOperationWarning(System.Web.Services.Res.GetString("NotificationIsNotSupported0"));
                            continue;
                        }

                        case OperationFlow.RequestResponse:
                        {
                            this.UnsupportedOperationWarning(System.Web.Services.Res.GetString("RequestResponseIsNotSupported0"));
                            continue;
                        }

                        case OperationFlow.SolicitResponse:
                        {
                            this.UnsupportedOperationWarning(System.Web.Services.Res.GetString("SolicitResponseIsNotSupported0"));
                            continue;
                        }
                        }
                    }
                    try
                    {
                        method = this.GenerateMethod();
                    }
                    catch (Exception exception)
                    {
                        if (((exception is ThreadAbortException) || (exception is StackOverflowException)) || (exception is OutOfMemoryException))
                        {
                            throw;
                        }
                        throw new InvalidOperationException(System.Web.Services.Res.GetString("UnableToImportOperation1", new object[] { this.operation.Name }), exception);
                    }
                    if (method != null)
                    {
                        this.AddExtensionWarningComments(this.codeClass.Comments, this.operationBinding.Extensions);
                        if (this.operationBinding.Input != null)
                        {
                            this.AddExtensionWarningComments(this.codeClass.Comments, this.operationBinding.Input.Extensions);
                        }
                        if (this.operationBinding.Output != null)
                        {
                            this.AddExtensionWarningComments(this.codeClass.Comments, this.operationBinding.Output.Extensions);
                        }
                        num++;
                    }
                }
                if ((((((this.ServiceImporter.CodeGenerationOptions & CodeGenerationOptions.GenerateNewAsync) != CodeGenerationOptions.None) && this.ServiceImporter.CodeGenerator.Supports(GeneratorSupport.DeclareEvents)) && this.ServiceImporter.CodeGenerator.Supports(GeneratorSupport.DeclareDelegates)) && (num > 0)) && (this.Style == ServiceDescriptionImportStyle.Client))
                {
                    CodeAttributeDeclarationCollection metadata = new CodeAttributeDeclarationCollection();
                    string           identifier = "CancelAsync";
                    string           methodName = this.MethodNames.AddUnique(identifier, identifier);
                    CodeMemberMethod method2    = WebCodeGenerator.AddMethod(this.CodeTypeDeclaration, methodName, new CodeFlags[1], new string[] { typeof(object).FullName }, new string[] { "userState" }, typeof(void).FullName, metadata, CodeFlags.IsPublic | ((identifier != methodName) ? ((CodeFlags)0) : CodeFlags.IsNew));
                    method2.Comments.Add(new CodeCommentStatement(System.Web.Services.Res.GetString("CodeRemarks"), true));
                    CodeMethodInvokeExpression expression = new CodeMethodInvokeExpression(new CodeBaseReferenceExpression(), identifier, new CodeExpression[0]);
                    expression.Parameters.Add(new CodeArgumentReferenceExpression("userState"));
                    method2.Statements.Add(expression);
                }
                this.EndClass();
                if (this.portType.Operations.Count == 0)
                {
                    this.NoMethodsGeneratedWarning();
                }
                this.AddExtensionWarningComments(this.codeClass.Comments, this.binding.Extensions);
                if (this.port != null)
                {
                    this.AddExtensionWarningComments(this.codeClass.Comments, this.port.Extensions);
                }
                this.codeNamespace.Types.Add(this.codeClass);
            }
            catch (Exception exception2)
            {
                if (((exception2 is ThreadAbortException) || (exception2 is StackOverflowException)) || (exception2 is OutOfMemoryException))
                {
                    throw;
                }
                throw new InvalidOperationException(System.Web.Services.Res.GetString("UnableToImportBindingFromNamespace2", new object[] { this.binding.Name, this.binding.ServiceDescription.TargetNamespace }), exception2);
            }
        }