当前位置: 首页>>代码示例>>C#>>正文


C# MetadataTypes类代码示例

本文整理汇总了C#中MetadataTypes的典型用法代码示例。如果您正苦于以下问题:C# MetadataTypes类的具体用法?C# MetadataTypes怎么用?C# MetadataTypes使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


MetadataTypes类属于命名空间,在下文中一共展示了MetadataTypes类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetDefaultNamespaces

        public static HashSet<string> GetDefaultNamespaces(this MetadataTypesConfig config, MetadataTypes metadata)
        {
            var namespaces = config.DefaultNamespaces.ToHashSet();
            config.AddNamespaces.Safe().Each(x => namespaces.Add(x));

            //Add any ignored namespaces used
            foreach (var ns in metadata.Namespaces)
            {
                //Ignored by IsUserType()
                if (!ns.StartsWith("System") && !config.IgnoreTypesInNamespaces.Contains(ns))
                    continue;

                if (!namespaces.Contains(ns))
                {
                    namespaces.Add(ns);
                }
            }

            return namespaces;
        }
开发者ID:CLupica,项目名称:ServiceStack,代码行数:20,代码来源:NativeTypesMetadata.cs

示例2: GetMetadataTypes

        public MetadataTypes GetMetadataTypes(IRequest req)
        {
            var metadata = new MetadataTypes
            {
                Config = config,
            };

            var skipTypes = new HashSet<Type>(config.SkipExistingTypes);
            config.IgnoreTypes.Each(x => skipTypes.Add(x));

            foreach (var operation in meta.Operations)
            {
                if (!meta.IsVisible(req, operation))
                    continue;

                metadata.Operations.Add(new MetadataOperationType
                {
                    Actions = operation.Actions,
                    Request = ToType(operation.RequestType),
                    Response = ToType(operation.ResponseType),
                });

                skipTypes.Add(operation.RequestType);
                if (operation.ResponseType != null)
                {
                    skipTypes.Add(operation.ResponseType);
                }
            }

            foreach (var type in meta.GetAllTypes())
            {
                if (skipTypes.Contains(type))
                    continue;

                metadata.Operations.Add(new MetadataOperationType
                {
                    Request = ToType(type),
                });

                skipTypes.Add(type);
            }

            var considered = new HashSet<Type>(skipTypes);
            var queue = new Queue<Type>(skipTypes);

            while (queue.Count > 0)
            {
                var type = queue.Dequeue();
                foreach (var pi in type.GetSerializableProperties())
                {
                    if (pi.PropertyType.IsUserType())
                    {
                        if (considered.Contains(pi.PropertyType))
                            continue;

                        considered.Add(pi.PropertyType);
                        queue.Enqueue(pi.PropertyType);
                        metadata.Types.Add(ToType(pi.PropertyType));
                    }
                }

                if (type.BaseType != null
                    && type.BaseType.IsUserType()
                    && !considered.Contains(type.BaseType))
                {
                    considered.Add(type.BaseType);
                    queue.Enqueue(type.BaseType);
                    metadata.Types.Add(ToType(type.BaseType));
                }
            }
            return metadata;
        }
开发者ID:vebin,项目名称:soa,代码行数:72,代码来源:NativeTypesMetadata.cs

示例3: ReferencesGson

 private bool ReferencesGson(MetadataTypes metadata)
 {
     var allTypes = GetAllMetadataTypes(metadata);
     return allTypes.Any(x => JavaGeneratorExtensions.JavaKeyWords.Contains(x.Name)
         || x.Properties.Safe().Any(p => p.DataMember != null && p.DataMember.Name != null)
         || (x.ReturnMarkerTypeName != null && x.ReturnMarkerTypeName.Name.IndexOf('`') >= 0)); //uses TypeToken<T>
 }
开发者ID:CLupica,项目名称:ServiceStack,代码行数:7,代码来源:JavaGenerator.cs

示例4: GetCode

        public string GetCode(MetadataTypes metadata, IRequest request, INativeTypesMetadata nativeTypes)
        {
            var typeNamespaces = new HashSet<string>();
            RemoveIgnoredTypes(metadata);
            metadata.Types.Each(x => typeNamespaces.Add(x.Namespace));
            metadata.Operations.Each(x => typeNamespaces.Add(x.Request.Namespace));

            var defaultImports = new List<string>(DefaultImports);
            if (!Config.DefaultImports.IsEmpty())
            {
                defaultImports = Config.DefaultImports;
            }
            else if (ReferencesGson(metadata))
            {
                if (!defaultImports.Contains(GSonAnnotationsNamespace))
                    defaultImports.Add(GSonAnnotationsNamespace);
                if (!defaultImports.Contains(GSonReflectNamespace))
                    defaultImports.Add(GSonReflectNamespace);
            }

            var defaultNamespace = Config.GlobalNamespace ?? DefaultGlobalNamespace;

            Func<string, string> defaultValue = k =>
                request.QueryString[k].IsNullOrEmpty() ? "//" : "";

            var sbInner = StringBuilderCache.Allocate();
            var sb = new StringBuilderWrapper(sbInner);
            sb.AppendLine("/* Options:");
            sb.AppendLine("Date: {0}".Fmt(DateTime.Now.ToString("s").Replace("T", " ")));
            sb.AppendLine("Version: {0}".Fmt(Env.ServiceStackVersion));
            sb.AppendLine("Tip: {0}".Fmt(HelpMessages.NativeTypesDtoOptionsTip.Fmt("//")));
            sb.AppendLine("BaseUrl: {0}".Fmt(Config.BaseUrl));
            sb.AppendLine();
            sb.AppendLine("{0}Package: {1}".Fmt(defaultValue("Package"), Config.Package));
            sb.AppendLine("{0}GlobalNamespace: {1}".Fmt(defaultValue("GlobalNamespace"), defaultNamespace));
            sb.AppendLine("{0}AddPropertyAccessors: {1}".Fmt(defaultValue("AddPropertyAccessors"), Config.AddPropertyAccessors));
            sb.AppendLine("{0}SettersReturnThis: {1}".Fmt(defaultValue("SettersReturnThis"), Config.SettersReturnThis));
            sb.AppendLine("{0}AddServiceStackTypes: {1}".Fmt(defaultValue("AddServiceStackTypes"), Config.AddServiceStackTypes));
            sb.AppendLine("{0}AddResponseStatus: {1}".Fmt(defaultValue("AddResponseStatus"), Config.AddResponseStatus));
            sb.AppendLine("{0}AddDescriptionAsComments: {1}".Fmt(defaultValue("AddDescriptionAsComments"), Config.AddDescriptionAsComments));
            sb.AppendLine("{0}AddImplicitVersion: {1}".Fmt(defaultValue("AddImplicitVersion"), Config.AddImplicitVersion));
            sb.AppendLine("{0}IncludeTypes: {1}".Fmt(defaultValue("IncludeTypes"), Config.IncludeTypes.Safe().ToArray().Join(",")));
            sb.AppendLine("{0}ExcludeTypes: {1}".Fmt(defaultValue("ExcludeTypes"), Config.ExcludeTypes.Safe().ToArray().Join(",")));
            sb.AppendLine("{0}TreatTypesAsStrings: {1}".Fmt(defaultValue("TreatTypesAsStrings"), Config.TreatTypesAsStrings.Safe().ToArray().Join(",")));
            sb.AppendLine("{0}DefaultImports: {1}".Fmt(defaultValue("DefaultImports"), defaultImports.Join(",")));

            sb.AppendLine("*/");
            sb.AppendLine();

            foreach (var typeName in Config.TreatTypesAsStrings.Safe())
            {
                TypeAliases[typeName] = "String";
            }

            if (Config.Package != null)
            {
                sb.AppendLine("package {0};".Fmt(Config.Package));
                sb.AppendLine();
            }

            string lastNS = null;

            var existingTypes = new HashSet<string>();

            var requestTypes = metadata.Operations.Select(x => x.Request).ToHashSet();
            var requestTypesMap = metadata.Operations.ToSafeDictionary(x => x.Request);
            var responseTypes = metadata.Operations
                .Where(x => x.Response != null)
                .Select(x => x.Response).ToHashSet();
            var types = metadata.Types.ToHashSet();

            AllTypes.AddRange(requestTypes);
            AllTypes.AddRange(responseTypes);
            AllTypes.AddRange(types);

            //TypeScript doesn't support reusing same type name with different generic airity
            var conflictPartialNames = AllTypes.Map(x => x.Name).Distinct()
                .GroupBy(g => g.LeftPart('`'))
                .Where(g => g.Count() > 1)
                .Select(g => g.Key)
                .ToList();

            this.conflictTypeNames = AllTypes
                .Where(x => conflictPartialNames.Any(name => x.Name.StartsWith(name)))
                .Map(x => x.Name);

            defaultImports.Each(x => sb.AppendLine("import {0};".Fmt(x)));
            sb.AppendLine();

            sb.AppendLine("public class {0}".Fmt(defaultNamespace.SafeToken()));
            sb.AppendLine("{");

            //ServiceStack core interfaces
            foreach (var type in AllTypes)
            {
                var fullTypeName = type.GetFullName();
                if (requestTypes.Contains(type))
                {
                    if (!existingTypes.Contains(fullTypeName))
                    {
//.........这里部分代码省略.........
开发者ID:CLupica,项目名称:ServiceStack,代码行数:101,代码来源:JavaGenerator.cs

示例5: ProcessRequest

        public void ProcessRequest(IHttpRequest httpReq, IHttpResponse httpRes, string operationName)
        {
            var metadata = new MetadataTypes {
                Config = Config,
            };
            var existingTypes = new HashSet<Type> {
                typeof(ResponseStatus),
                typeof(ErrorResponse),
            };

            var meta = EndpointHost.Metadata;
            foreach (var operation in meta.Operations)
            {
                if (!meta.IsVisible(httpReq, operation))
                    continue;

                metadata.Operations.Add(new MetadataOperationType {
                    Actions = operation.Actions,
                    Request = operation.RequestType.ToType(),
                    Response = operation.ResponseType.ToType(),
                });

                existingTypes.Add(operation.RequestType);
                existingTypes.Add(operation.ResponseType);
            }

            foreach (var type in meta.GetAllTypes())
            {
                if (existingTypes.Contains(type))
                    continue;

                metadata.Operations.Add(new MetadataOperationType {
                    Request = type.ToType(),
                });

                existingTypes.Add(type);
            }

            var considered = new HashSet<Type>(existingTypes);
            var queue = new Queue<Type>(existingTypes);

            while (queue.Count > 0)
            {
                var type = queue.Dequeue();
                foreach (var pi in type.GetSerializableProperties())
                {
                    if (pi.PropertyType.IsUserType())
                    {
                        if (considered.Contains(pi.PropertyType))
                            continue;

                        considered.Add(pi.PropertyType);
                        queue.Enqueue(pi.PropertyType);
                        metadata.Types.Add(pi.PropertyType.ToType());
                    }
                }

                if (type.BaseType != null
                    && type.BaseType.IsUserType()
                    && !considered.Contains(type.BaseType))
                {
                    considered.Add(type.BaseType);
                    queue.Enqueue(type.BaseType);
                    metadata.Types.Add(type.BaseType.ToType());
                }
            }

            httpRes.ContentType = "application/x-ssz-metatypes";
            var json = metadata.ToJson();
            var encJson = CryptUtils.Encrypt(EndpointHostConfig.PublicKey, json, RsaKeyLengths.Bit2048);
            httpRes.Write(encJson);
        }
开发者ID:mikkelfish,项目名称:ServiceStack,代码行数:72,代码来源:MetadataTypesHandler.cs

示例6: FindMetadataType

        static MetadataType FindMetadataType(MetadataTypes metadataTypes, string name, string @namespace = null)
        {
            if (@namespace != null && @namespace.StartsWith("System"))
                return null;

            var reqType = metadataTypes.Operations.FirstOrDefault(x => x.Request.Name == name);
            if (reqType != null)
                return reqType.Request;

            var resType = metadataTypes.Operations
                .FirstOrDefault(x => x.Response != null && x.Response.Name == name);

            if (resType != null)
                return resType.Response;

            var type = metadataTypes.Types.FirstOrDefault(x => x.Name == name
                && (@namespace == null || x.Namespace == @namespace));

            return type;
        }
开发者ID:jrmitch120,项目名称:ServiceStack,代码行数:20,代码来源:ServiceMetadata.cs

示例7: AddReferencedTypes

        private static void AddReferencedTypes(MetadataType metadataType, MetadataTypes metadataTypes, List<MetadataType> types)
        {
            if (metadataType.Inherits != null)
            {
                var type = FindMetadataType(metadataTypes, metadataType.Inherits.Name, metadataType.Inherits.Namespace);
                if (type != null && !types.Contains(type))
                {
                    types.Add(type);
                    AddReferencedTypes(type, metadataTypes, types);
                }

                if (!metadataType.Inherits.GenericArgs.IsEmpty())
                {
                    foreach (var arg in metadataType.Inherits.GenericArgs)
                    {
                        type = FindMetadataType(metadataTypes, arg);
                        if (type != null && !types.Contains(type))
                        {
                            types.Add(type);
                            AddReferencedTypes(type, metadataTypes, types);
                        }
                    }
                }
            }

            if (metadataType.Properties != null)
            {
                foreach (var p in metadataType.Properties)
                {
                    var type = FindMetadataType(metadataTypes, p.Type, p.TypeNamespace);
                    if (type != null && !types.Contains(type))
                    {
                        types.Add(type);
                        AddReferencedTypes(type, metadataTypes, types);
                    }

                    if (!p.GenericArgs.IsEmpty())
                    {
                        foreach (var arg in p.GenericArgs)
                        {
                            type = FindMetadataType(metadataTypes, arg);
                            if (type != null && !types.Contains(type))
                            {
                                types.Add(type);
                                AddReferencedTypes(type, metadataTypes, types);
                            }
                        }
                    }
                    else if (p.IsArray())
                    {
                        var elType = p.Type.SplitOnFirst('[')[0];
                        type = FindMetadataType(metadataTypes, elType);
                        if (type != null && !types.Contains(type))
                        {
                            types.Add(type);
                            AddReferencedTypes(type, metadataTypes, types);
                        }
                    }
                }
            }
        }
开发者ID:jrmitch120,项目名称:ServiceStack,代码行数:61,代码来源:ServiceMetadata.cs

示例8: GetIncludeList

        public static List<string> GetIncludeList(MetadataTypes metadata, MetadataTypesConfig config)
        {
            const string wildCard = ".*";

            if (config.IncludeTypes == null)
                return null;

            var typesToExpand = config.IncludeTypes
                .Where(s => s.Length > 2 && s.EndsWith(wildCard))
                .Map(s => s.Substring(0, s.Length - 2));

            if (typesToExpand.Count == 0)
                return config.IncludeTypes;

            // From IncludeTypes get the corresponding MetadataTypes
            var includedMetadataTypes = metadata.Operations
                .Select(o => o.Request)
                .Where(t => typesToExpand.Contains(t.Name))
                .ToList();

            var includeSet = includedMetadataTypes
                .Where(x => x.ReturnMarkerTypeName != null)
                .Select(x => x.ReturnMarkerTypeName.Name)
                .ToHashSet();

            var includedResponses = metadata.Operations
                .Where(t => typesToExpand.Contains(t.Request.Name) && t.Response != null)
                .Select(o => o.Response)
                .ToList();
            includedResponses.ForEach(x => includeSet.Add(x.Name));

            var returnTypesForInclude = metadata.Operations
                .Where(x => x.Response != null && includeSet.Contains(x.Response.Name))
                .Map(x => x.Response);

            // GetReferencedTypes for both request + response objects
            var referenceTypes = includedMetadataTypes
                .Union(returnTypesForInclude)
                .Where(x => x != null)
                .SelectMany(x => x.GetReferencedTypeNames());

            return referenceTypes
                .Union(config.IncludeTypes)
                .Union(typesToExpand)
                .Union(returnTypesForInclude.Select(x => x.Name))
                .Distinct()
                .ToList();
        }
开发者ID:ServiceStack,项目名称:ServiceStack,代码行数:48,代码来源:NativeTypesMetadata.cs

示例9: Get_MetadataReport

        internal XmlDocument Get_MetadataReport(string TargetObjectId, MetadataTypes metadataType)
        {
            XmlDocument RetVal;
            SDMXObjectModel.Message.GenericMetadataType Metadata;

            RetVal = null;
            Metadata = null;

            try
            {
                if (!string.IsNullOrEmpty(TargetObjectId))
                {
                    Metadata = this.Retrieve_Metadata_From_Database(metadataType, TargetObjectId,null);
                }

                if (Metadata != null)
                {
                    RetVal = Serializer.SerializeToXmlDocument(typeof(SDMXObjectModel.Message.GenericMetadataType), Metadata);
                }
                else
                {
                    RetVal = new XmlDocument();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
            }

            return RetVal;
        }
开发者ID:SDRC-India,项目名称:sdrcdevinfo,代码行数:34,代码来源:MetadataReportUtility.cs

示例10: Generate_MetadataReport

        internal bool Generate_MetadataReport(MetadataTypes metadataType, string filterNIds, string outputFolder)
        {
            bool RetVal;
            string Query, ColumnName, TargetObjectId, FileName;
            GenericMetadataType Metadata;
            DataTable DtTable;

            RetVal = false;
            Query = string.Empty;
            ColumnName = string.Empty;
            TargetObjectId = string.Empty;
            FileName = string.Empty;
            Metadata = null;
            DtTable = null;

            try
            {
                switch (metadataType)
                {
                    case MetadataTypes.Area:
                        Query = "SELECT Area_ID FROM UT_Area_" + this._language;

                        if (!string.IsNullOrEmpty(filterNIds))
                        {
                            Query += " WHERE Area_NId IN (" + filterNIds + ");";
                        }

                        ColumnName = "Area_ID";
                        break;
                    case MetadataTypes.Indicator:
                        Query = "SELECT Indicator_GId FROM UT_Indicator_" + this._language;

                        if (!string.IsNullOrEmpty(filterNIds))
                        {
                            Query += " WHERE Indicator_NId IN (" + filterNIds + ");";
                        }

                        ColumnName = "Indicator_GId";
                        break;
                    case MetadataTypes.Source:
                        Query = "SELECT IC_GId FROM UT_Indicator_Classifications_" + this._language + " WHERE IC_Type = 'SR'";

                        if (!string.IsNullOrEmpty(filterNIds))
                        {
                            Query += " AND IC_NId IN (" + filterNIds + ");";
                        }

                        ColumnName = "IC_GId";
                        break;
                    default:
                        break;
                }

                DtTable = this._diConnection.ExecuteDataTable(Regex.Replace(Query, "UT_", this._diConnection.DIDataSetDefault(), RegexOptions.IgnoreCase));

                foreach (DataRow DrTable in DtTable.Rows)
                {
                    TargetObjectId = DrTable[ColumnName].ToString();
                    Metadata = this.Retrieve_Metadata_From_Database(metadataType, TargetObjectId,null);

                    if (Metadata != null)
                    {
                        FileName = Path.Combine(outputFolder, TargetObjectId + Constants.XmlExtension);
                        Serializer.SerializeToFile(typeof(SDMXObjectModel.Message.GenericMetadataType), Metadata, FileName);
                    }
                }

                RetVal = true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
            }

            return RetVal;
        }
开发者ID:SDRC-India,项目名称:sdrcdevinfo,代码行数:79,代码来源:MetadataReportUtility.cs

示例11: Get_Appropriate_Header

        public SDMXObjectModel.Message.GenericMetadataHeaderType Get_Appropriate_Header(MetadataTypes metadataType)
        {
            SDMXObjectModel.Message.GenericMetadataHeaderType RetVal;
            SenderType Sender;
            PartyType Receiver;

            if (this._header == null)
            {
                Sender = new SenderType(Constants.Header.SenderId, Constants.Header.SenderName, Constants.DefaultLanguage, new SDMXObjectModel.Message.ContactType(Constants.Header.Sender, Constants.Header.SenderDepartment, Constants.Header.SenderRole, Constants.DefaultLanguage));
                Sender.Contact[0].Items = new string[] { Constants.Header.SenderTelephone, Constants.Header.SenderEmail, Constants.Header.SenderFax };
                Sender.Contact[0].ItemsElementName = new SDMXObjectModel.Message.ContactChoiceType[] { SDMXObjectModel.Message.ContactChoiceType.Telephone, SDMXObjectModel.Message.ContactChoiceType.Email, SDMXObjectModel.Message.ContactChoiceType.Fax };

                Receiver = new PartyType(Constants.Header.ReceiverId, Constants.Header.ReceiverName, Constants.DefaultLanguage, new SDMXObjectModel.Message.ContactType(Constants.Header.Receiver, Constants.Header.ReceiverDepartment, Constants.Header.ReceiverRole, Constants.DefaultLanguage));
                Receiver.Contact[0].Items = new string[] { Constants.Header.ReceiverTelephone, Constants.Header.ReceiverEmail, Constants.Header.ReceiverFax };
                Receiver.Contact[0].ItemsElementName = new SDMXObjectModel.Message.ContactChoiceType[] { SDMXObjectModel.Message.ContactChoiceType.Telephone, SDMXObjectModel.Message.ContactChoiceType.Email, SDMXObjectModel.Message.ContactChoiceType.Fax };

                RetVal = new GenericMetadataHeaderType(Constants.Header.Id, true, DateTime.Now, Sender, Receiver);
            }
            else
            {
                Sender = new SenderType(this._header.Sender.ID, this._header.Sender.Name, Constants.DefaultLanguage, new SDMXObjectModel.Message.ContactType(this._header.Sender.Contact.Name, this._header.Sender.Contact.Department, this._header.Sender.Contact.Role, Constants.DefaultLanguage));
                Sender.Contact[0].Items = new string[] { this._header.Sender.Contact.Telephone, this._header.Sender.Contact.Email, this._header.Sender.Contact.Fax };
                Sender.Contact[0].ItemsElementName = new SDMXObjectModel.Message.ContactChoiceType[] { SDMXObjectModel.Message.ContactChoiceType.Telephone, SDMXObjectModel.Message.ContactChoiceType.Email, SDMXObjectModel.Message.ContactChoiceType.Fax };

                Receiver = new PartyType(this._header.Receiver.ID, this._header.Receiver.Name, Constants.DefaultLanguage, new SDMXObjectModel.Message.ContactType(this._header.Receiver.Contact.Name, this._header.Receiver.Contact.Department, this._header.Receiver.Contact.Role, Constants.DefaultLanguage));
                Receiver.Contact[0].Items = new string[] { this._header.Receiver.Contact.Telephone, this._header.Receiver.Contact.Email, this._header.Receiver.Contact.Fax };
                Receiver.Contact[0].ItemsElementName = new SDMXObjectModel.Message.ContactChoiceType[] { SDMXObjectModel.Message.ContactChoiceType.Telephone, SDMXObjectModel.Message.ContactChoiceType.Email, SDMXObjectModel.Message.ContactChoiceType.Fax };

                RetVal = new GenericMetadataHeaderType(this._header.ID, true, DateTime.Now, Sender, Receiver);
            }

            RetVal.Structure = new List<GenericMetadataStructureType>();
            RetVal.Structure.Add(new GenericMetadataStructureType());

            switch (metadataType)
            {
                case MetadataTypes.Area:
                    RetVal.Structure[0].structureID = Constants.MSD.Area.Id;
                    RetVal.Structure[0].Item = new MetadataStructureReferenceType();
                    ((MetadataStructureReferenceType)RetVal.Structure[0].Item).Items = new List<object>();
                    ((MetadataStructureReferenceType)RetVal.Structure[0].Item).Items.Add(new MetadataStructureRefType(Constants.MSD.Area.Id, this._agencyId, Constants.MSD.Area.Version));
                    break;
                case MetadataTypes.Indicator:
                    RetVal.Structure[0].structureID = Constants.MSD.Indicator.Id;
                    RetVal.Structure[0].Item = new MetadataStructureReferenceType();
                    ((MetadataStructureReferenceType)RetVal.Structure[0].Item).Items = new List<object>();
                    ((MetadataStructureReferenceType)RetVal.Structure[0].Item).Items.Add(new MetadataStructureRefType(Constants.MSD.Indicator.Id, this._agencyId, Constants.MSD.Indicator.Version));
                    break;
                case MetadataTypes.Source:
                    RetVal.Structure[0].structureID = Constants.MSD.Source.Id;
                    RetVal.Structure[0].Item = new MetadataStructureReferenceType();
                    ((MetadataStructureReferenceType)RetVal.Structure[0].Item).Items = new List<object>();
                    ((MetadataStructureReferenceType)RetVal.Structure[0].Item).Items.Add(new MetadataStructureRefType(Constants.MSD.Source.Id, this._agencyId, Constants.MSD.Source.Version));
                    break;
                case MetadataTypes.Layer:
                    RetVal.Structure[0].structureID = Constants.MSD.Area.Id;
                    RetVal.Structure[0].Item = new MetadataStructureReferenceType();
                    ((MetadataStructureReferenceType)RetVal.Structure[0].Item).Items = new List<object>();
                    ((MetadataStructureReferenceType)RetVal.Structure[0].Item).Items.Add(new MetadataStructureRefType(Constants.MSD.Area.Id, this._agencyId, Constants.MSD.Area.Version));
                    break;
                default:
                    break;
            }

            ((MetadataStructureRefType)((MetadataStructureReferenceType)RetVal.Structure[0].Item).Items[0]).local = false;
            ((MetadataStructureRefType)((MetadataStructureReferenceType)RetVal.Structure[0].Item).Items[0]).localSpecified = true;

            ((MetadataStructureRefType)((MetadataStructureReferenceType)RetVal.Structure[0].Item).Items[0])[email protected] = ObjectTypeCodelistType.MetadataStructure;
            ((MetadataStructureRefType)((MetadataStructureReferenceType)RetVal.Structure[0].Item).Items[0]).classSpecified = true;

            ((MetadataStructureRefType)((MetadataStructureReferenceType)RetVal.Structure[0].Item).Items[0]).package = PackageTypeCodelistType.metadatastructure;
            ((MetadataStructureRefType)((MetadataStructureReferenceType)RetVal.Structure[0].Item).Items[0]).packageSpecified = true;

            return RetVal;
        }
开发者ID:SDRC-India,项目名称:sdrcdevinfo,代码行数:75,代码来源:MetadataReportUtility.cs

示例12: GetMetadataTypes

        public MetadataTypes GetMetadataTypes(IRequest req)
        {
            var metadata = new MetadataTypes
            {
                Config = config,
            };

            var skipTypes = config.IgnoreTypes ?? new HashSet<Type>();
            var opTypes = new HashSet<Type>();
            var ignoreNamespaces = config.IgnoreTypesInNamespaces ?? new List<string>();

            foreach (var operation in meta.Operations)
            {
                if (!meta.IsVisible(req, operation))
                    continue;

                if (opTypes.Contains(operation.RequestType))
                    continue;

                if (skipTypes.Contains(operation.RequestType))
                    continue;

                if (ignoreNamespaces.Contains(operation.RequestType.Namespace))
                    continue;

                var opType = new MetadataOperationType
                {
                    Actions = operation.Actions,
                    Request = ToType(operation.RequestType),
                    Response = ToType(operation.ResponseType),
                };
                metadata.Operations.Add(opType);
                opTypes.Add(operation.RequestType);
                
                if (operation.ResponseType != null)
                {
                    if (skipTypes.Contains(operation.ResponseType))
                    {
                        //Config.IgnoreTypesInNamespaces in CSharpGenerator
                        opType.Response = null;
                    }
                    else
                    {
                        opTypes.Add(operation.ResponseType);
                    }
                }
            }

            var considered = new HashSet<Type>(opTypes);
            var queue = new Queue<Type>(opTypes);

            Func<Type, bool> ignoreTypeFn = t => 
                t == null 
                || considered.Contains(t)
                || skipTypes.Contains(t)
                || ignoreNamespaces.Contains(t.Namespace);

            Action<Type> registerTypeFn = t => {
                if (t.IsArray || t == typeof(Array))
                    return;

                considered.Add(t);
                queue.Enqueue(t);
                if (t.IsUserType())
                    metadata.Types.Add(ToType(t));
            };

            while (queue.Count > 0)
            {
                var type = queue.Dequeue();
                foreach (var pi in type.GetSerializableProperties()
                    .Where(pi => !ignoreTypeFn(pi.PropertyType)))
                {
                    registerTypeFn(pi.PropertyType);
                }

                if (!ignoreTypeFn(type.BaseType))
                {
                    registerTypeFn(type.BaseType);
                }

                if (!type.IsGenericType()) continue;
                
                var args = type.GetGenericArguments();
                foreach (var arg in args.Where(arg => !ignoreTypeFn(arg)))
                {
                    registerTypeFn(arg);
                }
            }

            return metadata;
        }
开发者ID:Kanarej,项目名称:ServiceStack,代码行数:92,代码来源:NativeTypesMetadata.cs

示例13: GetCode

        public string GetCode(MetadataTypes metadata)
        {
            var namespaces = new HashSet<string>();
            Config.DefaultNamespaces.Each(x => namespaces.Add(x));
            metadata.Types.Each(x => namespaces.Add(x.Namespace));
            metadata.Operations.Each(x => namespaces.Add(x.Request.Namespace));

            var sb = new StringBuilderWrapper(new StringBuilder());
            sb.AppendLine("/* Options:");
            sb.AppendLine("Version: {0}".Fmt(Version));
            sb.AppendLine("BaseUrl: {0}".Fmt(Config.BaseUrl));
            sb.AppendLine();
            sb.AppendLine("ServerVersion: {0}".Fmt(metadata.Version));
            sb.AppendLine("MakePartial: {0}".Fmt(Config.MakePartial));
            sb.AppendLine("MakeVirtual: {0}".Fmt(Config.MakeVirtual));
            sb.AppendLine("MakeDataContractsExtensible: {0}".Fmt(Config.MakeDataContractsExtensible));
            sb.AppendLine("AddReturnMarker: {0}".Fmt(Config.AddReturnMarker));
            sb.AppendLine("AddDescriptionAsComments: {0}".Fmt(Config.AddDescriptionAsComments));
            sb.AppendLine("AddDataContractAttributes: {0}".Fmt(Config.AddDataContractAttributes));
            sb.AppendLine("AddDataAnnotationAttributes: {0}".Fmt(Config.AddDataAnnotationAttributes));
            sb.AppendLine("AddIndexesToDataMembers: {0}".Fmt(Config.AddIndexesToDataMembers));
            sb.AppendLine("AddResponseStatus: {0}".Fmt(Config.AddResponseStatus));
            sb.AppendLine("AddImplicitVersion: {0}".Fmt(Config.AddImplicitVersion));
            sb.AppendLine("InitializeCollections: {0}".Fmt(Config.InitializeCollections));
            sb.AppendLine("AddDefaultXmlNamespace: {0}".Fmt(Config.AddDefaultXmlNamespace));
            //sb.AppendLine("DefaultNamespaces: {0}".Fmt(Config.DefaultNamespaces.ToArray().Join(", ")));
            sb.AppendLine("*/");
            sb.AppendLine();

            namespaces.Each(x => sb.AppendLine("using {0};".Fmt(x)));

            if (Config.AddDataContractAttributes
                && Config.AddDefaultXmlNamespace != null)
            {
                sb.AppendLine();

                namespaces.Where(x => !Config.DefaultNamespaces.Contains(x)).ToList()
                    .ForEach(x =>
                        sb.AppendLine("[assembly: ContractNamespace(\"{0}\", ClrNamespace=\"{1}\")]"
                            .Fmt(Config.AddDefaultXmlNamespace, x)));
            }

            sb.AppendLine();

            string lastNS = null;

            var existingOps = new HashSet<string>();

            var requestTypes = metadata.Operations.Select(x => x.Request).ToHashSet();
            var requestTypesMap = metadata.Operations.ToSafeDictionary(x => x.Request);
            var responseTypes = metadata.Operations
                .Where(x => x.Response != null)
                .Select(x => x.Response).ToHashSet();
            var types = metadata.Types.ToHashSet();

            var allTypes = new List<MetadataType>();
            allTypes.AddRange(requestTypes);
            allTypes.AddRange(responseTypes);
            allTypes.AddRange(types);
            var orderedTypes = allTypes
                .OrderBy(x => x.Namespace)
                .ThenBy(x => x.Name);

            foreach (var type in orderedTypes)
            {
                var fullTypeName = type.GetFullName();
                if (requestTypes.Contains(type))
                {
                    if (!existingOps.Contains(fullTypeName))
                    {
                        MetadataType response = null;
                        MetadataOperationType operation;
                        if (requestTypesMap.TryGetValue(type, out operation))
                        {
                            response = operation.Response;
                        }

                        lastNS = AppendType(ref sb, type, lastNS,
                            new CreateTypeOptions
                            {
                                ImplementsFn = () =>
                                {
                                    if (!Config.AddReturnMarker
                                        && !type.ReturnVoidMarker
                                        && type.ReturnMarkerTypeName == null)
                                        return null;

                                    if (type.ReturnVoidMarker)
                                        return "IReturnVoid";
                                    if (type.ReturnMarkerTypeName != null)
                                        return Type("IReturn`1", new[] { Type(type.ReturnMarkerTypeName) });
                                    return response != null
                                        ? Type("IReturn`1", new[] { Type(type.Name, type.GenericArgs) })
                                        : null;
                                },
                                IsRequest = true,
                            });

                        existingOps.Add(fullTypeName);
                    }
//.........这里部分代码省略.........
开发者ID:Krave-n,项目名称:ServiceStack,代码行数:101,代码来源:CSharpGenerator.cs

示例14: GetCode

        public string GetCode(MetadataTypes metadata, IRequest request)
        {
            var namespaces = Config.GetDefaultNamespaces(metadata);

            var typeNamespaces = new HashSet<string>();
            metadata.RemoveIgnoredTypesForNet(Config);
            metadata.Types.Each(x => typeNamespaces.Add(x.Namespace));
            metadata.Operations.Each(x => typeNamespaces.Add(x.Request.Namespace));

            // Look first for shortest Namespace ending with `ServiceModel` convention, else shortest ns
            var globalNamespace = Config.GlobalNamespace
                ?? typeNamespaces.Where(x => x.EndsWith("ServiceModel"))
                    .OrderBy(x => x).FirstOrDefault()
                ?? typeNamespaces.OrderBy(x => x).First();

            Func<string, string> defaultValue = k =>
                request.QueryString[k].IsNullOrEmpty() ? "//" : "";

            var sb = new StringBuilderWrapper(new StringBuilder());
            sb.AppendLine("(* Options:");
            sb.AppendLine("Date: {0}".Fmt(DateTime.Now.ToString("s").Replace("T", " ")));
            sb.AppendLine("Version: {0}".Fmt(Env.ServiceStackVersion));
            sb.AppendLine("Tip: {0}".Fmt(HelpMessages.NativeTypesDtoOptionsTip.Fmt("//")));
            sb.AppendLine("BaseUrl: {0}".Fmt(Config.BaseUrl));
            sb.AppendLine();
            sb.AppendLine("{0}GlobalNamespace: {1}".Fmt(defaultValue("GlobalNamespace"), Config.GlobalNamespace));
            sb.AppendLine("{0}MakeDataContractsExtensible: {1}".Fmt(defaultValue("MakeDataContractsExtensible"), Config.MakeDataContractsExtensible));
            sb.AppendLine("{0}AddReturnMarker: {1}".Fmt(defaultValue("AddReturnMarker"), Config.AddReturnMarker));
            sb.AppendLine("{0}AddDescriptionAsComments: {1}".Fmt(defaultValue("AddDescriptionAsComments"), Config.AddDescriptionAsComments));
            sb.AppendLine("{0}AddDataContractAttributes: {1}".Fmt(defaultValue("AddDataContractAttributes"), Config.AddDataContractAttributes));
            sb.AppendLine("{0}AddIndexesToDataMembers: {1}".Fmt(defaultValue("AddIndexesToDataMembers"), Config.AddIndexesToDataMembers));
            sb.AppendLine("{0}AddGeneratedCodeAttributes: {1}".Fmt(defaultValue("AddGeneratedCodeAttributes"), Config.AddGeneratedCodeAttributes));
            sb.AppendLine("{0}AddResponseStatus: {1}".Fmt(defaultValue("AddResponseStatus"), Config.AddResponseStatus));
            sb.AppendLine("{0}AddImplicitVersion: {1}".Fmt(defaultValue("AddImplicitVersion"), Config.AddImplicitVersion));
            sb.AppendLine("{0}IncludeTypes: {1}".Fmt(defaultValue("IncludeTypes"), Config.IncludeTypes.Safe().ToArray().Join(",")));
            sb.AppendLine("{0}ExcludeTypes: {1}".Fmt(defaultValue("ExcludeTypes"), Config.ExcludeTypes.Safe().ToArray().Join(",")));
            sb.AppendLine("{0}InitializeCollections: {1}".Fmt(defaultValue("InitializeCollections"), Config.InitializeCollections));
            //sb.AppendLine("{0}AddDefaultXmlNamespace: {1}".Fmt(defaultValue("AddDefaultXmlNamespace"), Config.AddDefaultXmlNamespace));
            //sb.AppendLine("{0}DefaultNamespaces: {1}".Fmt(defaultValue("DefaultNamespaces"), Config.DefaultNamespaces.ToArray().Join(", ")));
            sb.AppendLine("*)");
            sb.AppendLine();

            string lastNS = null;

            var existingTypes = new HashSet<string>();

            var requestTypes = metadata.Operations.Select(x => x.Request).ToHashSet();
            var requestTypesMap = metadata.Operations.ToSafeDictionary(x => x.Request);
            var responseTypes = metadata.Operations
                .Where(x => x.Response != null)
                .Select(x => x.Response).ToHashSet();
            var types = metadata.Types.ToHashSet();

            var allTypes = new List<MetadataType>();
            allTypes.AddRange(types);
            allTypes.AddRange(responseTypes);
            allTypes.AddRange(requestTypes);

            var orderedTypes = allTypes.OrderTypesByDeps();

            sb.AppendLine("namespace {0}".Fmt(globalNamespace.SafeToken()));
            sb.AppendLine();
            foreach (var ns in namespaces.Where(x => !string.IsNullOrEmpty(x)))
            {
                sb.AppendLine("open " + ns);
            }
            if (Config.AddGeneratedCodeAttributes)
                sb.AppendLine("open System.CodeDom.Compiler");

            foreach (var type in orderedTypes)
            {
                var fullTypeName = type.GetFullName();
                if (requestTypes.Contains(type))
                {
                    if (!existingTypes.Contains(fullTypeName))
                    {
                        MetadataType response = null;
                        MetadataOperationType operation;
                        if (requestTypesMap.TryGetValue(type, out operation))
                        {
                            response = operation.Response;
                        }

                        lastNS = AppendType(ref sb, type, lastNS,
                            new CreateTypeOptions
                            {
                                ImplementsFn = () =>
                                {
                                    if (!Config.AddReturnMarker
                                        && !type.ReturnVoidMarker
                                        && type.ReturnMarkerTypeName == null)
                                        return null;

                                    if (type.ReturnVoidMarker)
                                        return "IReturnVoid";
                                    if (type.ReturnMarkerTypeName != null)
                                        return Type("IReturn`1", new[] { Type(type.ReturnMarkerTypeName) });
                                    return response != null
                                        ? Type("IReturn`1", new[] { Type(response.Name, response.GenericArgs) })
                                        : null;
//.........这里部分代码省略.........
开发者ID:jin29neci,项目名称:ServiceStack,代码行数:101,代码来源:FSharpGenerator.cs

示例15: ProcessRequestAsync

        public override Task ProcessRequestAsync(IRequest httpReq, IResponse httpRes, string operationName)
        {
            var metadata = new MetadataTypes
            {
                Config = Config,
            };
            var existingTypes = new HashSet<Type> {
                typeof(ResponseStatus),
                typeof(ErrorResponse),
            };

            var meta = HostContext.Metadata;
            foreach (var operation in meta.Operations)
            {
                if (!meta.IsVisible(httpReq, operation))
                    continue;

                metadata.Operations.Add(new MetadataOperationType
                {
                    Actions = operation.Actions,
                    Request = operation.RequestType.ToType(),
                    Response = operation.ResponseType.ToType(),
                });

                existingTypes.Add(operation.RequestType);
                if (operation.ResponseType != null)
                {
                    existingTypes.Add(operation.ResponseType);
                }
            }

            foreach (var type in meta.GetAllTypes())
            {
                if (existingTypes.Contains(type))
                    continue;

                metadata.Operations.Add(new MetadataOperationType
                {
                    Request = type.ToType(),
                });

                existingTypes.Add(type);
            }

            var considered = new HashSet<Type>(existingTypes);
            var queue = new Queue<Type>(existingTypes);

            while (queue.Count > 0)
            {
                var type = queue.Dequeue();
                foreach (var pi in type.GetSerializableProperties())
                {
                    if (pi.PropertyType.IsUserType())
                    {
                        if (considered.Contains(pi.PropertyType))
                            continue;

                        considered.Add(pi.PropertyType);
                        queue.Enqueue(pi.PropertyType);
                        metadata.Types.Add(pi.PropertyType.ToType());
                    }
                }

                if (type.BaseType != null
                    && type.BaseType.IsUserType()
                    && !considered.Contains(type.BaseType))
                {
                    considered.Add(type.BaseType);
                    queue.Enqueue(type.BaseType);
                    metadata.Types.Add(type.BaseType.ToType());
                }
            }

            return httpRes.WriteToResponse(httpReq, metadata);
        }
开发者ID:BBSDeadEye,项目名称:ServiceStack,代码行数:75,代码来源:MetadataTypesHandler.cs


注:本文中的MetadataTypes类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。