Exemple #1
0
 private void AddToGenerate(Type type)
 {
     if (!TypeToGenerate.Contains(type) && !CannotGenerateAssemblyTypes(type) && !type.IsGenericParameter)
     {
         TypeToGenerate.Add(type);
     }
 }
Exemple #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="nameSpace"></param>
        /// <param name="serverBase"></param>
        /// <returns></returns>
        public NamespaceReferenceInfo GetServiceReferenceCSharpCode(string nameSpace, ServerBase serverBase)
        {
            NamespaceReferenceInfo.Name   = nameSpace;
            ModellingReferencesAssemblies = serverBase.ModellingReferencesAssemblies;
            AddUsingIfNotExist(typeof(ServiceContractAttribute));
            AddUsingIfNotExist(typeof(System.Threading.Tasks.Task));
            AddUsingIfNotExist(typeof(NotifyPropertyChangedBase));
            ModellingReferencesAssemblies.Add(typeof(NotifyPropertyChangedBase).GetAssembly());
            ModellingReferencesAssemblies.Add(typeof(ServerBase).GetAssembly());
            List <string> generatedServices = new List <string>();

            foreach (KeyValuePair <string, Type> serviceInfo in serverBase.RegisteredServiceTypes)
            {
                ServiceContractAttribute[] attributes = null;
                if (serviceInfo.Value.HasServiceAttribute())
                {
                    attributes = serviceInfo.Value.GetServiceContractAttributes();
                }
                else
                {
                    attributes = new ServiceContractAttribute[0];
                }
                if (!generatedServices.Contains(serviceInfo.Key) && attributes.Any(x => x.ServiceType == ServiceType.ServerService && x.GetServiceName(false) == serviceInfo.Key))
                {
                    generatedServices.Add(serviceInfo.Key);
                    GenerateServiceClass(serviceInfo.Key, serviceInfo.Value, ClassReferenceType.ServiceLevel, ServiceType.ServerService);
                }
                if (!generatedServices.Contains(serviceInfo.Key) && attributes.Any(x => x.ServiceType == ServiceType.ClientService && x.GetServiceName(false) == serviceInfo.Key))
                {
                    generatedServices.Add(serviceInfo.Key);
                    GenerateServiceClass(serviceInfo.Key, serviceInfo.Value, ClassReferenceType.CallbackLevel, ServiceType.ClientService);
                }
                if (!generatedServices.Contains(serviceInfo.Key) && attributes.Any(x => x.ServiceType == ServiceType.StreamService && x.GetServiceName(false) == serviceInfo.Key))
                {
                    generatedServices.Add(serviceInfo.Key);
                    GenerateServiceClass(serviceInfo.Key, serviceInfo.Value, ClassReferenceType.StreamLevel, ServiceType.StreamService);
                }
                if (!generatedServices.Contains(serviceInfo.Key) && attributes.Any(x => x.ServiceType == ServiceType.OneWayService && x.GetServiceName(false) == serviceInfo.Key))
                {
                    generatedServices.Add(serviceInfo.Key);
                    GenerateServiceClass(serviceInfo.Key, serviceInfo.Value, ClassReferenceType.OneWayLevel, ServiceType.OneWayService);
                }
                if (!generatedServices.Contains(serviceInfo.Key) && (attributes.Any(x => x.ServiceType == ServiceType.HttpService && x.GetServiceName(false) == serviceInfo.Key) || attributes.Length == 0))
                {
                    generatedServices.Add(serviceInfo.Key);
                    GenerateServiceClass(serviceInfo.Key, serviceInfo.Value, ClassReferenceType.HttpServiceLevel, ServiceType.HttpService);
                }
            }
            //foreach (var serviceInfo in serverBase.RegisteredServiceTypes)
            //{
            //    GenerateServiceClass(serviceInfo.Key, serviceInfo.Value, ClassReferenceType.ServiceLevel, ServiceType.ServerService);
            //}

            //foreach (var serviceInfo in serverBase.RegisteredServiceTypes.Where(x=>x.Value))
            //{
            //    GenerateServiceClass(serviceInfo.Key, serviceInfo.Value, ClassReferenceType.CallbackLevel, ServiceType.ClientService);
            //}


            //foreach (var serviceInfo in serverBase.StreamServices)
            //{
            //    GenerateServiceClass(serviceInfo.Key, serviceInfo.Value.GetType(), ClassReferenceType.StreamLevel, ServiceType.StreamService);
            //}

            //foreach (var serviceInfo in serverBase.RegisteredHttpServiceTypes)
            //{
            //    GenerateHttpServiceClass(serviceInfo.Key, serviceInfo.Value);
            //}

            //foreach (var serviceInfo in serverBase.OneWayServices)
            //{
            //    GenerateServiceClass(serviceInfo.Key, serviceInfo.Value.GetType(), ClassReferenceType.OneWayLevel, ServiceType.OneWayService);
            //}

            Type find = null;

            while ((find = TypeToGenerate.FirstOrDefault()) != null)
            {
                if (find.GetIsClass())
                {
                    GenerateModelClass(find);
                }
                else if (find.GetIsInterface())
                {
                    GenerateModelInterface(find);
                }
                else if (find.GetIsEnum())
                {
                    GenerateModelEnum(find);
                }

                TypeToGenerate.Remove(find);
            }

            return(NamespaceReferenceInfo);
        }