Exemple #1
0
        public override bool Execute()
        {
            InitializeServices();

            var apiControllers = TypeService.GetControllers(Config.WebApiModuleFileName);

            var endpointBlock = EndpointsService.CreateEndpointBlock();
            var serviceBlock  = AngularEndpointsService.CreateServiceBlock();

            StartAnalysis("controllers and actions");

            foreach (var apiController in apiControllers)
            {
                var webApiController = new WebApiController(apiController);

                EndpointsService.WriteEndpointClassToBlock(endpointBlock, webApiController);
                AngularEndpointsService.WriteServiceObjectToBlock(serviceBlock.Children.First() as TypeScriptBlock, webApiController);
            }

            StopAnalysis();

            CreateFileForBlock(endpointBlock, Config.EndpointsOutputDirectory, Config.EndpointsFileName);
            CreateFileForBlock(serviceBlock, Config.ServiceOutputDirectory, Config.ServiceFileName);

            var enumsBlock      = EnumsService.CreateEnumsBlock();
            var interfacesBlock = InterfaceService.CreateInterfacesBlock();

            if (Config.GenerateInterfaces)
            {
                StartAnalysis("interfaces");

                InterfaceService.AddMatchingInterfaces();
                InterfaceService.WriteInterfacesToBlock(interfacesBlock);

                StopAnalysis();

                CreateFileForBlock(interfacesBlock, Config.InterfacesOutputDirectory, Config.InterfacesFileName);
            }

            if (Config.GenerateEnums)
            {
                StartAnalysis("enumerations");

                EnumsService.WriteEnumsToBlock(enumsBlock);

                StopAnalysis();

                CreateFileForBlock(enumsBlock, Config.EnumsOutputDirectory, Config.EnumsFileName);
            }

            return(true);
        }
Exemple #2
0
        private void InitializeServices()
        {
            Config = GetConfig(ConfigFilePath);

            TypeService = new TypeService();
            TypeService.LoadAllTypes(Config.WebApiModuleFileName);

            EnumsService     = new EnumsService();
            InterfaceService = new InterfaceService();

            EndpointsService        = new EndpointsService();
            AngularEndpointsService = new AngularEndpointsService();
        }
Exemple #3
0
        private void InitializeServices()
        {
            Config = GetConfig(ConfigFilePath);

            TypeService = new TypeService();
            LoadAllTypes();

            EnumsService     = new EnumsService();
            InterfaceService = new InterfaceService();

            EndpointsService        = new EndpointsService();
            MobileEndpointsService  = new MobileEndpointsService();
            AngularEndpointsService = new AngularEndpointsService();

            ViewsService    = new ViewsService();
            ResourceService = new ResourceService();
        }
Exemple #4
0
        private async void Delete()
        {
            var response = await _messageService.ShowOnAlertYesNoClicked("Do you want to delete your user?");

            if (!response)
            {
                return;
            }

            try
            {
                await _sqliteService.DeleteWithChildren(_user);

                await _messageService.ShowMessage(EnumsService.GetMessageSuccessUser(SuccessUser.UserDeleted, _user.Name));

                await _navigationService.NavigationWithoutBackButton(ViewName.LoginPage);
            }
            catch (Exception e)
            {
                Logs.Logs.Error(e);
                await _messageService.ShowMessageError(EnumsService.GetMessageErrorSystem(ErrorSystem.Generic));
            }
        }
Exemple #5
0
        public override bool Execute()
        {
            InitializeServices();

            var apiControllers = Config.WebApiModuleFileNames
                                 .SelectMany(f => TypeService.GetControllers(f))
                                 .ToArray();

            if (Config.GenerateViews)
            {
                StartAnalysis("views");

                foreach (var viewsBlock in ViewsService.GetBlocksForViews())
                {
                    CreateFileForBlock(viewsBlock.TypeScriptBlock, Config.ViewsOutputDirectory, viewsBlock.Filename);
                }

                StopAnalysis();
            }

            if (Config.GenerateResources)
            {
                StartAnalysis("resources");

                foreach (var resourceBlock in ResourceService.GetBlocksForResources())
                {
                    CreateFileForBlock(resourceBlock.TypeScriptBlock, Config.ResourcesOutputDirectory, resourceBlock.Filename);
                }

                StopAnalysis();
            }

            if (Config.GenerateEndpoints || Config.GenerateService)
            {
                StartAnalysis("controllers and actions");

                var endpointBlock       = EndpointsService.CreateEndpointBlock();
                var mobileEndpointBlock = MobileEndpointsService.CreateEndpointBlock();
                var serviceBlock        = AngularEndpointsService.CreateServiceBlock();

                foreach (var apiController in apiControllers)
                {
                    var webApiController = new WebApiController(apiController);

                    if (Config.GenerateEndpoints || Config.GenerateService)
                    {
                        EndpointsService.WriteEndpointClassToBlock(endpointBlock, webApiController);
                    }

                    if (Config.GenerateMobileEndpoints && webApiController.Actions.Any(a => a.IsMobileAction))
                    {
                        MobileEndpointsService.WriteEndpointClassToBlock(mobileEndpointBlock, webApiController);
                    }

                    if (Config.GenerateService)
                    {
                        var classBlock = serviceBlock.Children
                                         .OfType <TypeScriptBlock>()
                                         .First();

                        AngularEndpointsService.WriteServiceObjectToBlock(classBlock, webApiController);
                    }
                }

                if (Config.GenerateEndpoints || Config.GenerateService)
                {
                    CreateFileForBlock(endpointBlock, Config.EndpointsOutputDirectory, Config.EndpointsFileName);
                }

                if (Config.GenerateMobileEndpoints)
                {
                    CreateFileForBlock(mobileEndpointBlock, Config.MobileEndpointsOutputDirectory, Config.MobileEndpointsFileName);
                }

                if (Config.GenerateService)
                {
                    CreateFileForBlock(serviceBlock, Config.ServiceOutputDirectory, Config.ServiceFileName);
                }

                StopAnalysis();
            }

            if (Config.GenerateInterfaces)
            {
                StartAnalysis("interfaces");

                var interfacesBlock = InterfaceService.CreateInterfacesBlock();
                InterfaceService.AddMatchingInterfaces();
                InterfaceService.WriteInterfacesToBlock(interfacesBlock);

                StopAnalysis();

                CreateFileForBlock(interfacesBlock, Config.InterfacesOutputDirectory, Config.InterfacesFileName);
            }

            if (Config.GenerateEnums)
            {
                StartAnalysis("enumerations");

                var enumsBlock = EnumsService.CreateEnumsBlock();
                EnumsService.AddMatchingEnums();
                EnumsService.WriteEnumsToBlock(enumsBlock);

                StopAnalysis();

                CreateFileForBlock(enumsBlock, Config.EnumsOutputDirectory, Config.EnumsFileName);
            }

            WriteServiceLogMessages();

            return(true);
        }
        public InterfaceNode AddInterfaceNode(TypeDefinition typeDefinition)
        {
            Debug.Assert(typeDefinition != null);

            var interfaceNode = SearchForInterfaceNode(InterfaceNode, typeDefinition);

            if (interfaceNode != null)
            {
                return(interfaceNode);
            }

            if (typeDefinition.IsInterface)
            {
                return(null);
            }

            interfaceNode = AddInterfaceNode(typeDefinition, InterfaceNode);

            var baseInterfaceNode = InterfaceNode;

            var baseType = typeDefinition.BaseType;

            if (baseType.IsGenericInstance)
            {
                var genericBaseType = baseType as GenericInstanceType;
                var elementType     = genericBaseType?.ElementType as TypeDefinition;

                if (elementType != null && elementType != typeDefinition)
                {
                    baseInterfaceNode = AddInterfaceNode(elementType);
                }
            }
            else
            {
                var baseClass            = TypeService.GetTypeDefinition(typeDefinition.BaseType.FullName);
                var isBaseClassNotObject = baseClass != null && baseClass.FullName != "System.Object";

                if (isBaseClassNotObject && baseClass != typeDefinition)
                {
                    baseInterfaceNode = AddInterfaceNode(baseClass);
                }
            }

            interfaceNode = AdjustBaseClass(interfaceNode, baseInterfaceNode);

            var things = GetMembers(typeDefinition)
                         .Where(m => !m.CSharpType.IsGenericParameter);

            foreach (var thing in things)
            {
                var thingType = thing.CSharpType.TypeDefinition;

                var typeMapping = TypeService.GetTypeScriptType(thingType, thing.Name);
                if (typeMapping != null)
                {
                    continue;
                }

                if (thingType.IsEnum && Config.GenerateEnums)
                {
                    EnumsService.AddEnum(thingType);
                }
                else if (!thingType.IsPrimitive)
                {
                    AddInterfaceNode(thingType);
                }
            }

            return(interfaceNode);
        }
 public ShipController(DatabaseContext ctx, ShipService shipService, EnumsService enumsService) : base(ctx)
 {
     this.shipService  = shipService;
     this.enumsService = enumsService;
 }
Exemple #8
0
 public SqliteServiceException(TableSql tableSql, string table, string errorMessage) : base(
         EnumsService.GetMessageErrorSqlService(tableSql, table, errorMessage))
 {
 }
Exemple #9
0
 public SqliteServiceException(TableSql tableSql, string table, Exception innerException) : base(
         EnumsService.GetMessageErrorSqlService(tableSql, table, innerException.Message))
 {
 }
Exemple #10
0
 public UserController(DatabaseContext ctx, UserService userService, EnumsService enumsService) : base(ctx)
 {
     _userService  = userService;
     _enumsService = enumsService;
 }
Exemple #11
0
        public TypeScriptType GetTypeScriptType(TypeReference cSharpType, string parameterName, Func <string, string, TypeMapping> getTypeMapping)
        {
            var result = new TypeScriptType();

            var type     = cSharpType;
            var typeName = type.FullName;

            var typeMapping = getTypeMapping(parameterName, cSharpType.FullName);

            if (typeMapping != null)
            {
                var tsTypeName = typeMapping.TypeScriptTypeName;
                result.TypeName      = tsTypeName;
                result.InterfaceName = tsTypeName;
                result.IsPrimitive   = TypeService.IsPrimitiveTypeScriptType(result.TypeName);
                result.IsEnum        = tsTypeName.StartsWith($"{Config.EnumsNamespace}") ||
                                       result.IsPrimitive;

                return(result);
            }

            typeName = TypeService.StripNullable(type) ?? typeName;

            var collectionType = TypeService.StripCollection(type);

            result.IsCollection = collectionType != null;
            typeName            = collectionType ?? typeName;

            var typeDefinition = TypeService.GetTypeDefinition(typeName);

            if (typeDefinition?.IsEnum ?? false)
            {
                if (!Config.GenerateEnums)
                {
                    result.TypeName      = "number";
                    result.InterfaceName = "number";
                    result.IsPrimitive   = true;
                }
                else
                {
                    EnumsService.AddEnum(typeDefinition);

                    result.TypeName      = $"{Config.EnumsNamespace}.{typeDefinition.Name}";
                    result.InterfaceName = $"{Config.EnumsNamespace}.{typeDefinition.Name}";
                    result.IsPrimitive   = false;
                }

                result.IsEnum = true;
                return(result);
            }

            var primitiveType = TypeService.GetPrimitiveTypeScriptType(typeName);

            if (!string.IsNullOrEmpty(primitiveType))
            {
                result.TypeName      = primitiveType;
                result.InterfaceName = primitiveType;
                result.IsPrimitive   = true;

                return(result);
            }

            if (!typeDefinition?.IsValueType ?? false)
            {
                if (!Config.GenerateInterfaces)
                {
                    result.TypeName      = $"{WebApiToTypeScript.IHaveQueryParams}";
                    result.InterfaceName = "any";
                }
                else
                {
                    InterfaceService.AddInterfaceNode(typeDefinition);

                    result.TypeName      = $"{Config.InterfacesNamespace}.{typeDefinition.Name}";
                    result.InterfaceName = $"{Config.InterfacesNamespace}.I{typeDefinition.Name}";
                }

                return(result);
            }

            throw new NotSupportedException("Maybe it is a generic class, or a yet unsupported collection, or chain thereof?");
        }