Exemplo n.º 1
0
        public static async Task StartToReadingClientData(ClientInfo client, ServerBase serverBase)
        {
            try
            {
                Console.WriteLine($"WebSocket Client Connected: {client.IPAddress}");
                Shared.IO.PipeNetworkStream stream = client.ClientStream;
                while (true)
                {
                    byte oneByteOfDataType = await client.StreamHelper.ReadOneByteAsync(stream);

                    //type of data
                    DataType dataType = (DataType)oneByteOfDataType;
                    if (dataType == DataType.PingPong)
                    {
                        await client.StreamHelper.WriteToStreamAsync(client.ClientStream, new byte[] { 5 });

                        continue;
                    }
                    //compress mode of data
                    CompressMode compressMode = (CompressMode)await client.StreamHelper.ReadOneByteAsync(stream);

                    //a server service method called from client
                    if (dataType == DataType.CallMethod)
                    {
                        string json = "";
                        //if (client.IsOwinClient)
                        //{
                        //    json = await stream.ReadLineAsync("#end");
                        //    if (json.EndsWith("#end"))
                        //        json = json.Substring(0, json.Length - 4);
                        //}
                        //else
                        //{
                        byte[] bytes = await client.StreamHelper.ReadBlockToEndAsync(stream, compressMode, serverBase.ProviderSetting.MaximumReceiveDataBlock);

                        //if (ClientsSettings.ContainsKey(client))
                        //    bytes = DecryptBytes(bytes, client);
                        json = Encoding.UTF8.GetString(bytes);
                        //}
                        MethodCallInfo callInfo = ServerSerializationHelper.Deserialize <MethodCallInfo>(json, serverBase);
                        if (callInfo.PartNumber != 0)
                        {
                            SegmentManager segmentManager = new SegmentManager();
                            ISegment       result         = segmentManager.GenerateAndMixSegments(callInfo);
                            if (result != null)
                            {
                                callInfo = (MethodCallInfo)result;
                            }
                            else
                            {
                                continue;
                            }
                        }
#if (NET35 || NET40)
                        MethodCallbackInfo callbackResult = CallMethod(callInfo, client, json, serverBase).Result;
                        SendCallbackData(callbackResult, client, serverBase);
#else
                        Task <MethodCallbackInfo> callbackResult = CallMethod(callInfo, client, json, serverBase);
                        SendCallbackData(callbackResult, client, serverBase);
#endif
                    }

                    //reponse of client method that server called to client
                    else if (dataType == DataType.ResponseCallMethod)
                    {
                        byte[] bytes = await client.StreamHelper.ReadBlockToEndAsync(stream, compressMode, serverBase.ProviderSetting.MaximumReceiveDataBlock);

                        //if (ClientsSettings.ContainsKey(client))
                        //    bytes = DecryptBytes(bytes, client);
                        string             json     = Encoding.UTF8.GetString(bytes);
                        MethodCallbackInfo callback = ServerSerializationHelper.Deserialize <MethodCallbackInfo>(json, serverBase);
                        if (callback == null)
                        {
                            serverBase.AutoLogger.LogText($"{client.IPAddress} {client.ClientId} callback is null:" + json);
                        }
                        if (callback.PartNumber != 0)
                        {
                            SegmentManager segmentManager = new SegmentManager();
                            ISegment       result         = segmentManager.GenerateAndMixSegments(callback);
                            if (result != null)
                            {
                                callback = (MethodCallbackInfo)result;
                            }
                            else
                            {
                                continue;
                            }
                        }
                        if (serverBase.ClientServiceCallMethodsResult.TryGetValue(callback.Guid, out KeyValue <Type, object> resultTask))
                        {
                            if (callback.IsException)
                            {
                                resultTask.Value.GetType().FindMethod("SetException").Invoke(resultTask.Value, new object[] { new Exception(callback.Data) });
                            }
                            else
                            {
                                resultTask.Value.GetType().FindMethod("SetResult").Invoke(resultTask.Value, new object[] { ServerSerializationHelper.Deserialize(callback.Data, resultTask.Key, serverBase) });
                            }
                        }
                    }
                    else if (dataType == DataType.GetServiceDetails)
                    {
                        byte[] bytes = await client.StreamHelper.ReadBlockToEndAsync(stream, compressMode, serverBase.ProviderSetting.MaximumReceiveDataBlock);

                        //if (ClientsSettings.ContainsKey(client))
                        //    bytes = DecryptBytes(bytes, client);
                        string json    = Encoding.UTF8.GetString(bytes);
                        string hostUrl = ServerSerializationHelper.Deserialize <string>(json, serverBase);
                        ServerServicesManager serverServicesManager = new ServerServicesManager();
                        ProviderDetailsInfo   detail = serverServicesManager.SendServiceDetail(hostUrl, serverBase);
                        json = ServerSerializationHelper.SerializeObject(detail, serverBase);
                        List <byte> resultBytes = new List <byte>
                        {
                            (byte)DataType.GetServiceDetails,
                            (byte)CompressMode.None
                        };
                        byte[] jsonBytes = Encoding.UTF8.GetBytes(json);
                        byte[] dataLen   = BitConverter.GetBytes(jsonBytes.Length);
                        resultBytes.AddRange(dataLen);
                        resultBytes.AddRange(jsonBytes);
                        await client.StreamHelper.WriteToStreamAsync(client.ClientStream, resultBytes.ToArray());
                    }
                    else if (dataType == DataType.GetMethodParameterDetails)
                    {
                        byte[] bytes = await client.StreamHelper.ReadBlockToEndAsync(stream, compressMode, serverBase.ProviderSetting.MaximumReceiveDataBlock);

                        //if (ClientsSettings.ContainsKey(client))
                        //    bytes = DecryptBytes(bytes, client);
                        string json = Encoding.UTF8.GetString(bytes);
                        MethodParameterDetails detail = ServerSerializationHelper.Deserialize <MethodParameterDetails>(json, serverBase);

                        if (!serverBase.RegisteredServiceTypes.TryGetValue(detail.ServiceName, out Type serviceType))
                        {
                            throw new Exception($"{client.IPAddress} {client.ClientId} Service {detail.ServiceName} not found");
                        }
                        if (serviceType == null)
                        {
                            throw new Exception($"{client.IPAddress} {client.ClientId} serviceType {detail.ServiceName} not found");
                        }

                        ServerServicesManager serverServicesManager = new ServerServicesManager();

                        json = serverServicesManager.SendMethodParameterDetail(serviceType, detail, serverBase);
                        List <byte> resultBytes = new List <byte>
                        {
                            (byte)DataType.GetMethodParameterDetails,
                            (byte)CompressMode.None
                        };

                        byte[] jsonBytes = Encoding.UTF8.GetBytes(json);
                        byte[] dataLen   = BitConverter.GetBytes(jsonBytes.Length);
                        resultBytes.AddRange(dataLen);
                        resultBytes.AddRange(jsonBytes);
                        await client.StreamHelper.WriteToStreamAsync(client.ClientStream, resultBytes.ToArray());
                    }
                    else if (dataType == DataType.GetClientId)
                    {
                        byte[]      bytes  = Encoding.UTF8.GetBytes(client.ClientId);
                        List <byte> result = new List <byte>();
                        result.Add((byte)DataType.GetClientId);
                        result.Add((byte)CompressMode.None);

                        result.AddRange(BitConverter.GetBytes(bytes.Length));
                        result.AddRange(bytes);
                        //if (ClientsSettings.ContainsKey(client))
                        //    bytes = EncryptBytes(bytes, client);
                        if (result.Count > serverBase.ProviderSetting.MaximumSendDataBlock)
                        {
                            throw new Exception($"{client.IPAddress} {client.ClientId} GetClientId data length exceeds MaximumSendDataBlock");
                        }

                        await client.StreamHelper.WriteToStreamAsync(client.ClientStream, result.ToArray());
                    }
                    else
                    {
                        //throw new Exception($"Correct DataType Data {dataType}");
                        serverBase.AutoLogger.LogText($"Correct DataType Data {oneByteOfDataType} {client.ClientId} {client.IPAddress}");
                        break;
                    }
                }
                serverBase.DisposeClient(client, null, "StartToReadingClientData while break");
            }
            catch (Exception ex)
            {
                serverBase.AutoLogger.LogError(ex, $"{client.IPAddress} {client.ClientId} ServerBase SignalGoDuplexServiceProvider StartToReadingClientData");
                serverBase.DisposeClient(client, null, "SignalGoDuplexServiceProvider StartToReadingClientData exception");
            }
        }
Exemplo n.º 2
0
        internal ProviderDetailsInfo SendServiceDetail(string hostUrl, ServerBase serverBase)
        {
            //try
            //{
            if (!hostUrl.StartsWith("http://", StringComparison.OrdinalIgnoreCase))
            {
                hostUrl += "http://";
            }
            if (Uri.TryCreate(hostUrl, UriKind.Absolute, out Uri uri))
            {
                hostUrl = uri.Host + ":" + uri.Port;
            }
            using (XmlCommentLoader xmlCommentLoader = new XmlCommentLoader())
            {
                List <Type>         modelTypes = new List <Type>();
                int                 id         = 1;
                ProviderDetailsInfo result     = new ProviderDetailsInfo()
                {
                    Id = id
                };
                foreach (KeyValuePair <string, Type> service in serverBase.RegisteredServiceTypes.Where(x => x.Value.IsServerService()))
                {
                    id++;
                    ServiceDetailsInfo serviceDetail = new ServiceDetailsInfo()
                    {
                        ServiceName   = service.Key,
                        FullNameSpace = service.Value.FullName,
                        NameSpace     = service.Value.Name,
                        Id            = id
                    };
                    result.Services.Add(serviceDetail);
                    List <Type> types = new List <Type>();
                    types.Add(service.Value);
                    foreach (Type item in CSCodeInjection.GetListOfTypes(service.Value))
                    {
                        if (item.GetCustomAttributes <ServiceContractAttribute>(false).Length > 0 && !types.Contains(item))
                        {
                            types.Add(item);
                            types.AddRange(CSCodeInjection.GetListOfTypes(service.Value).Where(x => !types.Contains(x)));
                        }
                    }

                    foreach (Type serviceType in types)
                    {
                        if (serviceType == typeof(object))
                        {
                            continue;
                        }
                        List <MethodInfo> methods = serviceType.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance).Where(x => !(x.IsSpecialName && (x.Name.StartsWith("set_") || x.Name.StartsWith("get_"))) && x.DeclaringType != typeof(object)).ToList();
                        if (methods.Count == 0)
                        {
                            continue;
                        }
                        CommentOfClassInfo comment = xmlCommentLoader.GetComment(serviceType);
                        id++;
                        ServiceDetailsInterface interfaceInfo = new ServiceDetailsInterface()
                        {
                            NameSpace     = serviceType.Name,
                            FullNameSpace = serviceType.FullName,
                            Comment       = comment?.Summery,
                            Id            = id
                        };
                        serviceDetail.Services.Add(interfaceInfo);
                        List <ServiceDetailsMethod> serviceMethods = new List <ServiceDetailsMethod>();
                        foreach (MethodInfo method in methods)
                        {
                            SerializeObjectType pType = SerializeHelper.GetTypeCodeOfObject(method.ReturnType);
                            if (pType == SerializeObjectType.Enum)
                            {
                                AddEnumAndNewModels(ref id, method.ReturnType, result, SerializeObjectType.Enum, xmlCommentLoader);
                            }
                            CommentOfMethodInfo methodComment = comment == null ? null : (from x in comment.Methods where x.Name == method.Name && x.Parameters.Count == method.GetParameters().Length select x).FirstOrDefault();
                            string exceptions = "";
                            if (methodComment?.Exceptions != null && methodComment?.Exceptions.Count > 0)
                            {
                                foreach (CommentOfExceptionInfo ex in methodComment.Exceptions)
                                {
                                    try
                                    {
                                        if (ex.RefrenceType.LastIndexOf('.') != -1)
                                        {
                                            string baseNameOfEnum = ex.RefrenceType.Substring(0, ex.RefrenceType.LastIndexOf('.'));
                                            Type   type           = GetEnumType(baseNameOfEnum);
#if (NETSTANDARD1_6 || NETCOREAPP1_1)
                                            if (type != null && type.GetTypeInfo().IsEnum)
#else
                                            if (type != null && type.IsEnum)
#endif
                                            {
                                                object value    = Enum.Parse(type, ex.RefrenceType.Substring(ex.RefrenceType.LastIndexOf('.') + 1, ex.RefrenceType.Length - ex.RefrenceType.LastIndexOf('.') - 1));
                                                int    exNumber = (int)value;
                                                exceptions += ex.RefrenceType + $" ({exNumber}) : " + ex.Comment + TextHelper.NewLine;
                                                continue;
                                            }
                                        }
                                    }
                                    catch
                                    {
                                    }

                                    exceptions += ex.RefrenceType + ":" + ex.Comment + TextHelper.NewLine;
                                }
                            }
                            id++;
                            ServiceDetailsMethod info = new ServiceDetailsMethod()
                            {
                                MethodName = method.Name,
#if (!NET35)
                                Requests = new System.Collections.ObjectModel.ObservableCollection <ServiceDetailsRequestInfo>()
                                {
                                    new ServiceDetailsRequestInfo()
                                    {
                                        Name = "Default", Parameters = new List <ServiceDetailsParameterInfo>(), IsSelected = true
                                    }
                                },
#endif
                                ReturnType        = method.ReturnType.GetFriendlyName(),
                                Comment           = methodComment?.Summery,
                                ReturnComment     = methodComment?.Returns,
                                ExceptionsComment = exceptions,
                                Id = id
                            };
                            RuntimeTypeHelper.GetListOfUsedTypes(method.ReturnType, ref modelTypes);
                            foreach (System.Reflection.ParameterInfo paramInfo in method.GetParameters())
                            {
                                pType = SerializeHelper.GetTypeCodeOfObject(paramInfo.ParameterType);
                                if (pType == SerializeObjectType.Enum)
                                {
                                    AddEnumAndNewModels(ref id, paramInfo.ParameterType, result, SerializeObjectType.Enum, xmlCommentLoader);
                                }
                                string parameterComment = "";
                                if (methodComment != null)
                                {
                                    parameterComment = (from x in methodComment.Parameters where x.Name == paramInfo.Name select x.Comment).FirstOrDefault();
                                }
                                id++;
                                ServiceDetailsParameterInfo p = new ServiceDetailsParameterInfo()
                                {
                                    Name         = paramInfo.Name,
                                    Type         = paramInfo.ParameterType.GetFriendlyName(),
                                    FullTypeName = paramInfo.ParameterType.FullName,
                                    Comment      = parameterComment,
                                    Id           = id
                                };
#if (!NET35)
                                info.Requests.First().Parameters.Add(p);
#endif
                                RuntimeTypeHelper.GetListOfUsedTypes(paramInfo.ParameterType, ref modelTypes);
                            }
                            serviceMethods.Add(info);
                        }
                        interfaceInfo.Methods.AddRange(serviceMethods);
                    }
                }



                foreach (KeyValuePair <string, Type> service in serverBase.RegisteredServiceTypes.Where(x => x.Value.IsClientService()))
                {
                    id++;
                    CallbackServiceDetailsInfo serviceDetail = new CallbackServiceDetailsInfo()
                    {
                        ServiceName   = service.Key,
                        FullNameSpace = service.Value.FullName,
                        NameSpace     = service.Value.Name,
                        Id            = id
                    };

                    result.Callbacks.Add(serviceDetail);
                    List <Type> types = new List <Type>();
                    types.Add(service.Value);
                    foreach (Type item in CSCodeInjection.GetListOfTypes(service.Value))
                    {
                        if (item.GetCustomAttributes <ServiceContractAttribute>(false).Length > 0 && !types.Contains(item))
                        {
                            types.Add(item);
                            types.AddRange(CSCodeInjection.GetListOfTypes(service.Value).Where(x => !types.Contains(x)));
                        }
                    }

                    List <MethodInfo> methods = service.Value.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance).Where(x => !(x.IsSpecialName && (x.Name.StartsWith("set_") || x.Name.StartsWith("get_"))) && x.DeclaringType != typeof(object)).ToList();
                    if (methods.Count == 0)
                    {
                        continue;
                    }
                    CommentOfClassInfo          comment        = xmlCommentLoader.GetComment(service.Value);
                    List <ServiceDetailsMethod> serviceMethods = new List <ServiceDetailsMethod>();
                    foreach (MethodInfo method in methods)
                    {
                        SerializeObjectType pType = SerializeHelper.GetTypeCodeOfObject(method.ReturnType);
                        if (pType == SerializeObjectType.Enum)
                        {
                            AddEnumAndNewModels(ref id, method.ReturnType, result, SerializeObjectType.Enum, xmlCommentLoader);
                        }
                        CommentOfMethodInfo methodComment = comment == null ? null : (from x in comment.Methods where x.Name == method.Name && x.Parameters.Count == method.GetParameters().Length select x).FirstOrDefault();
                        string exceptions = "";
                        if (methodComment?.Exceptions != null && methodComment?.Exceptions.Count > 0)
                        {
                            foreach (CommentOfExceptionInfo ex in methodComment.Exceptions)
                            {
                                try
                                {
                                    if (ex.RefrenceType.LastIndexOf('.') != -1)
                                    {
                                        string baseNameOfEnum = ex.RefrenceType.Substring(0, ex.RefrenceType.LastIndexOf('.'));
                                        Type   type           = GetEnumType(baseNameOfEnum);
#if (NETSTANDARD1_6 || NETCOREAPP1_1)
                                        if (type != null && type.GetTypeInfo().IsEnum)
#else
                                        if (type != null && type.IsEnum)
#endif
                                        {
                                            object value    = Enum.Parse(type, ex.RefrenceType.Substring(ex.RefrenceType.LastIndexOf('.') + 1, ex.RefrenceType.Length - ex.RefrenceType.LastIndexOf('.') - 1));
                                            int    exNumber = (int)value;
                                            exceptions += ex.RefrenceType + $" ({exNumber}) : " + ex.Comment + TextHelper.NewLine;
                                            continue;
                                        }
                                    }
                                }
                                catch
                                {
                                }

                                exceptions += ex.RefrenceType + ":" + ex.Comment + TextHelper.NewLine;
                            }
                        }
                        id++;
                        ServiceDetailsMethod info = new ServiceDetailsMethod()
                        {
                            MethodName = method.Name,
#if (!NET35)
                            Requests = new System.Collections.ObjectModel.ObservableCollection <ServiceDetailsRequestInfo>()
                            {
                                new ServiceDetailsRequestInfo()
                                {
                                    Name = "Default", Parameters = new List <ServiceDetailsParameterInfo>(), IsSelected = true
                                }
                            },
#endif
                            ReturnType        = method.ReturnType.GetFriendlyName(),
                            Comment           = methodComment?.Summery,
                            ReturnComment     = methodComment?.Returns,
                            ExceptionsComment = exceptions,
                            Id = id
                        };
                        RuntimeTypeHelper.GetListOfUsedTypes(method.ReturnType, ref modelTypes);
                        foreach (System.Reflection.ParameterInfo paramInfo in method.GetParameters())
                        {
                            pType = SerializeHelper.GetTypeCodeOfObject(paramInfo.ParameterType);
                            if (pType == SerializeObjectType.Enum)
                            {
                                AddEnumAndNewModels(ref id, paramInfo.ParameterType, result, SerializeObjectType.Enum, xmlCommentLoader);
                            }
                            string parameterComment = "";
                            if (methodComment != null)
                            {
                                parameterComment = (from x in methodComment.Parameters where x.Name == paramInfo.Name select x.Comment).FirstOrDefault();
                            }
                            id++;
                            ServiceDetailsParameterInfo p = new ServiceDetailsParameterInfo()
                            {
                                Name         = paramInfo.Name,
                                Type         = paramInfo.ParameterType.GetFriendlyName(),
                                FullTypeName = paramInfo.ParameterType.FullName,
                                Comment      = parameterComment,
                                Id           = id
                            };
#if (!NET35)
                            info.Requests.First().Parameters.Add(p);
#endif
                            RuntimeTypeHelper.GetListOfUsedTypes(paramInfo.ParameterType, ref modelTypes);
                        }
                        serviceMethods.Add(info);
                    }
                    serviceDetail.Methods.AddRange(serviceMethods);
                }



                foreach (KeyValuePair <string, Type> httpServiceType in serverBase.RegisteredServiceTypes.Where(x => x.Value.IsHttpService()))
                {
                    id++;
                    HttpControllerDetailsInfo controller = new HttpControllerDetailsInfo()
                    {
                        Id  = id,
                        Url = httpServiceType.Value.GetCustomAttributes <ServiceContractAttribute>(true).Length > 0 ? httpServiceType.Value.GetCustomAttributes <ServiceContractAttribute>(true)[0].Name : httpServiceType.Key,
                    };
                    id++;
                    result.WebApiDetailsInfo.Id = id;
                    result.WebApiDetailsInfo.HttpControllers.Add(controller);
                    List <MethodInfo> methods = httpServiceType.Value.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance).Where(x => !(x.IsSpecialName && (x.Name.StartsWith("set_") || x.Name.StartsWith("get_"))) && x.DeclaringType != typeof(object)).ToList();
                    if (methods.Count == 0)
                    {
                        continue;
                    }
                    CommentOfClassInfo          comment        = xmlCommentLoader.GetComment(httpServiceType.Value);
                    List <ServiceDetailsMethod> serviceMethods = new List <ServiceDetailsMethod>();
                    foreach (MethodInfo method in methods)
                    {
                        SerializeObjectType pType = SerializeHelper.GetTypeCodeOfObject(method.ReturnType);
                        if (pType == SerializeObjectType.Enum)
                        {
                            AddEnumAndNewModels(ref id, method.ReturnType, result, SerializeObjectType.Enum, xmlCommentLoader);
                        }
                        CommentOfMethodInfo methodComment = comment == null ? null : (from x in comment.Methods where x.Name == method.Name && x.Parameters.Count == method.GetParameters().Length select x).FirstOrDefault();
                        string exceptions = "";
                        if (methodComment?.Exceptions != null && methodComment?.Exceptions.Count > 0)
                        {
                            foreach (CommentOfExceptionInfo ex in methodComment.Exceptions)
                            {
                                try
                                {
                                    if (ex.RefrenceType.LastIndexOf('.') != -1)
                                    {
                                        string baseNameOfEnum = ex.RefrenceType.Substring(0, ex.RefrenceType.LastIndexOf('.'));
                                        Type   type           = GetEnumType(baseNameOfEnum);
#if (NETSTANDARD1_6 || NETCOREAPP1_1)
                                        if (type != null && type.GetTypeInfo().IsEnum)
#else
                                        if (type != null && type.IsEnum)
#endif
                                        {
                                            object value    = Enum.Parse(type, ex.RefrenceType.Substring(ex.RefrenceType.LastIndexOf('.') + 1, ex.RefrenceType.Length - ex.RefrenceType.LastIndexOf('.') - 1));
                                            int    exNumber = (int)value;
                                            exceptions += ex.RefrenceType + $" ({exNumber}) : " + ex.Comment + TextHelper.NewLine;
                                            continue;
                                        }
                                    }
                                }
                                catch
                                {
                                }

                                exceptions += ex.RefrenceType + ":" + ex.Comment + TextHelper.NewLine;
                            }
                        }
                        id++;
                        ServiceDetailsMethod info = new ServiceDetailsMethod()
                        {
                            Id         = id,
                            MethodName = method.Name,
#if (!NET35)
                            Requests = new System.Collections.ObjectModel.ObservableCollection <ServiceDetailsRequestInfo>()
                            {
                                new ServiceDetailsRequestInfo()
                                {
                                    Name = "Default", Parameters = new List <ServiceDetailsParameterInfo>(), IsSelected = true
                                }
                            },
#endif
                            ReturnType        = method.ReturnType.GetFriendlyName(),
                            Comment           = methodComment?.Summery,
                            ReturnComment     = methodComment?.Returns,
                            ExceptionsComment = exceptions,
                            TestExample       = hostUrl + "/" + controller.Url + "/" + method.Name
                        };

                        RuntimeTypeHelper.GetListOfUsedTypes(method.ReturnType, ref modelTypes);
                        string testExampleParams = "";
                        foreach (System.Reflection.ParameterInfo paramInfo in method.GetParameters())
                        {
                            pType = SerializeHelper.GetTypeCodeOfObject(paramInfo.ParameterType);
                            if (pType == SerializeObjectType.Enum)
                            {
                                AddEnumAndNewModels(ref id, paramInfo.ParameterType, result, SerializeObjectType.Enum, xmlCommentLoader);
                            }
                            string parameterComment = "";
                            if (methodComment != null)
                            {
                                parameterComment = (from x in methodComment.Parameters where x.Name == paramInfo.Name select x.Comment).FirstOrDefault();
                            }
                            id++;
                            ServiceDetailsParameterInfo p = new ServiceDetailsParameterInfo()
                            {
                                Id           = id,
                                Name         = paramInfo.Name,
                                Type         = paramInfo.ParameterType.Name,
                                FullTypeName = paramInfo.ParameterType.FullName,
                                Comment      = parameterComment
                            };
#if (!NET35)
                            info.Requests.First().Parameters.Add(p);
#endif
                            if (string.IsNullOrEmpty(testExampleParams))
                            {
                                testExampleParams += "?";
                            }
                            else
                            {
                                testExampleParams += "&";
                            }
                            testExampleParams += paramInfo.Name + "=" + DataExchangeConverter.GetDefault(paramInfo.ParameterType) ?? "null";
                            RuntimeTypeHelper.GetListOfUsedTypes(paramInfo.ParameterType, ref modelTypes);
                        }
                        info.TestExample += testExampleParams;
                        serviceMethods.Add(info);
                    }
                    controller.Methods = serviceMethods;
                }

                foreach (Type type in modelTypes)
                {
                    try
                    {
                        SerializeObjectType pType = SerializeHelper.GetTypeCodeOfObject(type);
                        AddEnumAndNewModels(ref id, type, result, pType, xmlCommentLoader);
                        //                                var mode = SerializeHelper.GetTypeCodeOfObject(type);
                        //                                if (mode == SerializeObjectType.Object)
                        //                                {
                        //                                    if (type.Name.Contains("`") || type == typeof(CustomAttributeTypedArgument) || type == typeof(CustomAttributeNamedArgument) ||
                        //#if (NETSTANDARD1_6 || NETCOREAPP1_1)
                        //                                        type.GetTypeInfo().BaseType == typeof(Attribute))
                        //#else
                        //                                    type.BaseType == typeof(Attribute))
                        //#endif
                        //                                        continue;

                        //                                    var instance = Activator.CreateInstance(type);
                        //                                    string jsonResult = JsonConvert.SerializeObject(instance, Formatting.Indented, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Include });
                        //                                    var refactorResult = (JObject)JsonConvert.DeserializeObject(jsonResult);
                        //                                    foreach (var item in refactorResult.Properties())
                        //                                    {
                        //                                        var find = type.GetProperties().FirstOrDefault(x => x.Name == item.Name);
                        //                                        refactorResult[item.Name] = find.PropertyType.FullName;
                        //                                    }
                        //                                    jsonResult = JsonConvert.SerializeObject(refactorResult, Formatting.Indented, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Include });

                        //                                    if (jsonResult == "{}" || jsonResult == "[]")
                        //                                        continue;
                        //                                    var comment = xmlCommentLoader.GetComment(type);
                        //                                    id++;
                        //                                    result.ProjectDomainDetailsInfo.Id = id;
                        //                                    id++;
                        //                                    result.ProjectDomainDetailsInfo.Models.Add(new ModelDetailsInfo()
                        //                                    {
                        //                                        Id = id,
                        //                                        Comment = comment?.Summery,
                        //                                        Name = type.Name,
                        //                                        FullNameSpace = type.FullName,
                        //                                        ObjectType = mode,
                        //                                        JsonTemplate = jsonResult
                        //                                    });
                        //                                    foreach (var property in type.GetProperties())
                        //                                    {
                        //                                        var pType = SerializeHelper.GetTypeCodeOfObject(property.PropertyType);
                        //                                        if (pType == SerializeObjectType.Enum)
                        //                                        {
                        //                                            AddEnumAndNewModels(ref id, property.PropertyType, result, SerializeObjectType.Enum, xmlCommentLoader);
                        //                                        }
                        //                                    }
                        //                                }
                    }
                    catch (Exception ex)
                    {
                        serverBase.AutoLogger.LogError(ex, "Model Type Add error: " + ex.ToString());
                    }
                }

                return(result);
                //string json = ServerSerializationHelper.SerializeObject(result, serverBase);
                //List<byte> bytes = new List<byte>
                // {
                //                (byte)DataType.GetServiceDetails,
                //                (byte)CompressMode.None
                // };
                //byte[] jsonBytes = Encoding.UTF8.GetBytes(json);
                //byte[] dataLen = BitConverter.GetBytes(jsonBytes.Length);
                //bytes.AddRange(dataLen);
                //bytes.AddRange(jsonBytes);
                //await client.StreamHelper.WriteToStreamAsync(client.ClientStream, bytes.ToArray());
            }
            //}
            //catch (Exception ex)
            //{
            //    try
            //    {
            //        string json = ServerSerializationHelper.SerializeObject(new Exception(ex.ToString()), serverBase);
            //        List<byte> bytes = new List<byte>
            //         {
            //            (byte)DataType.GetServiceDetails,
            //            (byte)CompressMode.None
            //         };
            //        byte[] jsonBytes = Encoding.UTF8.GetBytes(json);
            //        byte[] dataLen = BitConverter.GetBytes(jsonBytes.Length);
            //        bytes.AddRange(dataLen);
            //        bytes.AddRange(jsonBytes);
            //        await client.StreamHelper.WriteToStreamAsync(client.ClientStream, bytes.ToArray());

            //    }
            //    catch (Exception)
            //    {

            //    }
            //    serverBase.AutoLogger.LogError(ex, $"{client.IPAddress} {client.ClientId} ServerBase CallMethod");
            //}
            //finally
            //{
            //    skippedTypes.Clear();
            //}

            void AddEnumAndNewModels(ref int id, Type type, ProviderDetailsInfo result, SerializeObjectType objType, XmlCommentLoader xmlCommentLoader)
            {
                if (result.ProjectDomainDetailsInfo.Models.Any(x => x.FullNameSpace == type.FullName) || skippedTypes.Contains(type))
                {
                    return;
                }
                id++;
                result.ProjectDomainDetailsInfo.Id = id;
                id++;
                if (objType == SerializeObjectType.Enum)
                {
                    List <string> items = new List <string>();
                    foreach (Enum obj in Enum.GetValues(type))
                    {
                        int x = Convert.ToInt32(obj); // x is the integer value of enum
                        items.Add(obj.ToString() + " = " + x);
                    }

                    result.ProjectDomainDetailsInfo.Models.Add(new ModelDetailsInfo()
                    {
                        Id            = id,
                        Name          = type.Name,
                        FullNameSpace = type.FullName,
                        ObjectType    = objType,
                        JsonTemplate  = JsonConvert.SerializeObject(items, Formatting.Indented, new JsonSerializerSettings()
                        {
                            NullValueHandling = NullValueHandling.Include
                        })
                    });
                }
                else
                {
                    try
                    {
                        if (type.Name.Contains("`") || type == typeof(CustomAttributeTypedArgument) || type == typeof(CustomAttributeNamedArgument) ||
#if (NETSTANDARD1_6 || NETCOREAPP1_1)
                            type.GetTypeInfo().BaseType == typeof(Attribute) || type.GetTypeInfo().BaseType == null)
#else
                            type.BaseType == typeof(Attribute) || type.BaseType == null)
#endif
                        {
                            skippedTypes.Add(type);
                            return;
                        }

                        object instance   = Activator.CreateInstance(type);
                        string jsonResult = JsonConvert.SerializeObject(instance, Formatting.Indented, new JsonSerializerSettings()
                        {
                            NullValueHandling = NullValueHandling.Include
                        });
                        JObject refactorResult = (JObject)JsonConvert.DeserializeObject(jsonResult);
                        foreach (JProperty item in refactorResult.Properties())
                        {
                            PropertyInfo find = type.GetProperties().FirstOrDefault(x => x.Name == item.Name);
                            refactorResult[item.Name] = find.PropertyType.GetFriendlyName();
                        }
                        jsonResult = JsonConvert.SerializeObject(refactorResult, Formatting.Indented, new JsonSerializerSettings()
                        {
                            NullValueHandling = NullValueHandling.Include
                        });

                        if (jsonResult == "{}" || jsonResult == "[]")
                        {
                            skippedTypes.Add(type);
                            return;
                        }
                        CommentOfClassInfo comment = xmlCommentLoader.GetComment(type);
                        id++;
                        result.ProjectDomainDetailsInfo.Id = id;
                        id++;
                        result.ProjectDomainDetailsInfo.Models.Add(new ModelDetailsInfo()
                        {
                            Id            = id,
                            Comment       = comment?.Summery,
                            Name          = type.Name,
                            FullNameSpace = type.FullName,
                            ObjectType    = objType,
                            JsonTemplate  = jsonResult
                        });
                    }
                    catch
                    {
                        skippedTypes.Add(type);
                    }
                }

                foreach (Type item in type.GetListOfGenericArguments())
                {
                    SerializeObjectType pType = SerializeHelper.GetTypeCodeOfObject(item);
                    AddEnumAndNewModels(ref id, item, result, pType, xmlCommentLoader);
                }

                foreach (Type item in type.GetListOfInterfaces())
                {
                    SerializeObjectType pType = SerializeHelper.GetTypeCodeOfObject(item);
                    AddEnumAndNewModels(ref id, item, result, pType, xmlCommentLoader);
                }

                foreach (Type item in type.GetListOfNestedTypes())
                {
                    SerializeObjectType pType = SerializeHelper.GetTypeCodeOfObject(item);
                    AddEnumAndNewModels(ref id, item, result, pType, xmlCommentLoader);
                }

                foreach (Type item in type.GetListOfBaseTypes())
                {
                    SerializeObjectType pType = SerializeHelper.GetTypeCodeOfObject(item);
                    AddEnumAndNewModels(ref id, item, result, pType, xmlCommentLoader);
                }
                foreach (PropertyInfo property in type.GetProperties())
                {
                    SerializeObjectType pType = SerializeHelper.GetTypeCodeOfObject(property.PropertyType);
                    AddEnumAndNewModels(ref id, property.PropertyType, result, pType, xmlCommentLoader);
                }
            }
        }