Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First implementation of Xamarin generation #489

Merged
merged 27 commits into from
Feb 19, 2021
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
801 changes: 801 additions & 0 deletions generators/client/files-xamarin.js

Large diffs are not rendered by default.

28 changes: 27 additions & 1 deletion generators/client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ const dotnet = require('../dotnet');
const writeAngularFiles = require('./files-angular').writeFiles;
const writeReactFiles = require('./files-react').writeFiles;
const writeBlazorFiles = require('./files-blazor').writeFiles;
const writeXamarinFiles = require('./files-xamarin').writeFiles;
const writeCommonFiles = require('./files-common').writeFiles;

const REACT = baseConstants.SUPPORTED_CLIENT_FRAMEWORKS.REACT;
const BLAZOR = constants.BLAZOR;
const XAMARIN = constants.XAMARIN;

module.exports = class extends ClientGenerator {
constructor(args, opts) {
Expand Down Expand Up @@ -106,6 +108,8 @@ module.exports = class extends ClientGenerator {
switch (this.clientFramework) {
case BLAZOR:
return writeBlazorFiles.call(this);
case XAMARIN:
return writeXamarinFiles.call(this);
case REACT:
baseWriteReactFiles.call(this);
writeCommonFiles.call(this);
Expand Down Expand Up @@ -139,7 +143,7 @@ module.exports = class extends ClientGenerator {
get end() {
return {
async end() {
if (this.clientFramework == BLAZOR) {
if (this.clientFramework === BLAZOR) {
this.log(chalk.green.bold(`\nCreating ${this.solutionName} .Net Core solution if it does not already exist.\n`));
try {
await dotnet.newSln(this.solutionName);
Expand All @@ -152,6 +156,28 @@ module.exports = class extends ClientGenerator {
`${constants.CLIENT_TEST_DIR}${this.clientTestProject}/${this.pascalizedBaseName}.Client.Test.csproj`,
]);
this.log(chalk.green.bold('\Client application generated successfully.\n'));
} else if (this.clientFramework === XAMARIN) {
this.log(chalk.green.bold(`\nCreating ${this.solutionName} .Net Core solution if it does not already exist.\n`));
try {
await dotnet.newSln(this.solutionName);
} catch (err) {
this.warning(`Failed to create ${this.solutionName} .Net Core solution: ${err}`);
}
await dotnet.slnAdd(`${this.solutionName}.sln`, [
`${constants.CLIENT_SRC_DIR}${this.mainClientDir}/${this.pascalizedBaseName}.Client.Xamarin.Core.csproj`,
`${constants.CLIENT_SRC_DIR}${this.sharedClientDir}/${this.pascalizedBaseName}.Client.Xamarin.Shared.csproj`,
]);
await dotnet.newSlnAddProj(this.solutionName, [
{
'path': `${constants.CLIENT_SRC_DIR}${this.androidClientDir}/${this.pascalizedBaseName}.Client.Xamarin.Android.csproj`,
'name' : `${this.pascalizedBaseName}.Client.Xamarin.Android`
},
{
'path': `${constants.CLIENT_SRC_DIR}${this.iOSClientDir}/${this.pascalizedBaseName}.Client.Xamarin.iOS.csproj`,
'name' : `${this.pascalizedBaseName}.Client.Xamarin.iOS`
}
]);
this.log(chalk.green.bold('\Client application generated successfully.\n'));
} else {
if (this.skipClient) return;
this.log(chalk.green.bold('\nClient application generated successfully.\n'));
Expand Down
98 changes: 98 additions & 0 deletions generators/client/needle-api/needle-client-xamarin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/**
* Copyright 2013-2020 the original author or authors from the JHipster project.
*
* This file is part of the JHipster project, see https://www.jhipster.tech/
* for more information.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
const needleBase = require('generator-jhipster/generators/needle-base');
const chalk = require('chalk');
const _ = require('lodash');

module.exports = class extends needleBase {
constructor(generator) {
super(generator);

this.mainClientDir = generator.mainClientDir;

if (!this.mainClientDir) {
generator.error('Client destination folder is missing');
}
}

addEntityToMenu(entityName) {
const errorMessage = `${chalk.yellow('Reference to ') + entityName} ${chalk.yellow('not added to menu.\n')}`;
const entityMenuPath = `src/${this.mainClientDir}/Views/MenuPage.xaml`;
const entityEntry =
// prettier-ignore
this.generator.stripMargin(
`|<Grid HorizontalOptions="FillAndExpand" VerticalOptions="StartAndExpand" Padding="8" BackgroundColor="LightBlue" IsVisible="{Binding IsConnected}">
| <Label Text="${entityName}" />
| <Grid.GestureRecognizers>
| <TapGestureRecognizer Tapped="ToggleClicked" Command="{Binding Show${entityName}Command}"/>
| </Grid.GestureRecognizers>
| </Grid>
|`);

const rewriteFileModel = this.generateFileModel(entityMenuPath, 'jhipster-needle-add-entity-to-menu', entityEntry);

this.addBlockContentToFile(rewriteFileModel, errorMessage);
}

declareCommandToMenu(entityName) {
const errorMessage = `${chalk.yellow('Reference to ') + entityName} ${chalk.yellow('not added to menu.\n')}`;
const entityMenuPath = `src/${this.mainClientDir}/ViewModels/MenuViewModel.cs`;
const entityEntry =
// prettier-ignore
this.generator.stripMargin(
`|public IMvxCommand Show${entityName}Command => new MvxAsyncCommand(${entityName}CommandClicked);`);

const rewriteFileModel = this.generateFileModel(entityMenuPath, 'jhipster-needle-declare-entity-command', entityEntry);

this.addBlockContentToFile(rewriteFileModel, errorMessage);
}

addCommandToMenu(entityName) {
const errorMessage = `${chalk.yellow('Reference to ') + entityName} ${chalk.yellow('not added to menu.\n')}`;
const entityMenuPath = `src/${this.mainClientDir}/ViewModels/MenuViewModel.cs`;
const entityEntry =
// prettier-ignore
this.generator.stripMargin(
`|private async Task ${entityName}CommandClicked()
| {
| await _navigationService.Navigate<${entityName}ViewModel>();
| }
`);

const rewriteFileModel = this.generateFileModel(entityMenuPath, 'jhipster-needle-add-entity-command', entityEntry);

this.addBlockContentToFile(rewriteFileModel, errorMessage);
}

addServiceInDI(entityName) {
const lowerCasedEntityName = _.kebabCase(entityName);
const lowerEntityName = _.toLower(entityName);
const errorMessage = `${chalk.yellow('Reference to ') + entityName} ${chalk.yellow('not added to Program.\n')}`;
const programPath = `src/${this.mainClientDir}/App.cs`;
const serviceEntry =
// prettier-ignore
this.generator.stripMargin(
`|var ${lowerEntityName}Service = new ${entityName}Service(httpClient);
| Mvx.IoCProvider.RegisterSingleton<I${entityName}Service>(${lowerEntityName}Service);`);

const rewriteFileModel = this.generateFileModel(programPath, 'jhipster-needle-add-services-in-di', serviceEntry);

this.addBlockContentToFile(rewriteFileModel, errorMessage);
}
};
7 changes: 6 additions & 1 deletion generators/client/prompts.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const constants = require('../generator-dotnetcore-constants');
const ANGULAR = baseConstants.SUPPORTED_CLIENT_FRAMEWORKS.ANGULAR;
const REACT = baseConstants.SUPPORTED_CLIENT_FRAMEWORKS.REACT;
const BLAZOR = constants.BLAZOR;
const XAMARIN = constants.XAMARIN;

module.exports = {
askForClient,
Expand All @@ -39,10 +40,14 @@ function askForClient() {
value: REACT,
name: 'React',
},
{
{
value: BLAZOR,
name: '[Alpha] - Blazor (WebAssembly)',
},
{
value: XAMARIN,
name: '[Alpha] - Xamarin',
},
{
value: 'no',
name: 'No client',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<%#
Copyright 2013-2020 the original author or authors from the JHipster project.
This file is part of the JHipster project, see https://www.jhipster.tech/
for more information.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-%>

using Android.App;
using Android.Content.PM;
using Android.OS;
using Android.Runtime;
using MvvmCross.Forms.Platforms.Android.Core;
using MvvmCross.Forms.Platforms.Android.Views;
using Xamarin.Essentials;

namespace <%= namespace %>.Client.Xamarin.Droid
{
[Activity(Label = "<%= namespace %>", Icon = "@mipmap/icon", Theme = "@style/MainTheme", MainLauncher = false,
ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode |
ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize)]
public class MainActivity : MvxFormsAppCompatActivity
{
protected override void OnCreate(Bundle savedInstanceState)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;

base.OnCreate(savedInstanceState);
}

public override void OnRequestPermissionsResult(int requestCode, string[] permissions,
[GeneratedEnum] Permission[] grantResults)
{
Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);

base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{55206BEA-B1A5-4EF4-8030-A53EE728F481}</ProjectGuid>
<ProjectTypeGuids>{EFBA0AD7-5A72-4C68-AF49-83D382785DCF};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<TemplateGuid>{c9e5eea5-ca05-42a1-839b-61506e0a37df}</TemplateGuid>
<OutputType>Library</OutputType>
<RootNamespace><%= namespace %>.Client.Xamarin.Droid</RootNamespace>
<AssemblyName><%= namespace %>.Client.Xamarin.Android</AssemblyName>
<Deterministic>True</Deterministic>
<AndroidApplication>True</AndroidApplication>
<AndroidResgenFile>Resources\Resource.designer.cs</AndroidResgenFile>
<AndroidResgenClass>Resource</AndroidResgenClass>
<AndroidManifest>Properties\AndroidManifest.xml</AndroidManifest>
<MonoAndroidResourcePrefix>Resources</MonoAndroidResourcePrefix>
<MonoAndroidAssetsPrefix>Assets</MonoAndroidAssetsPrefix>
<AndroidUseLatestPlatformSdk>false</AndroidUseLatestPlatformSdk>
<TargetFrameworkVersion>v10.0</TargetFrameworkVersion>
<AndroidEnableSGenConcurrent>true</AndroidEnableSGenConcurrent>
<AndroidUseAapt2>true</AndroidUseAapt2>
<AndroidHttpClientHandlerType>Xamarin.Android.Net.AndroidClientHandler</AndroidHttpClientHandlerType>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>portable</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug</OutputPath>
<DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AndroidLinkMode>None</AndroidLinkMode>
<AotAssemblies>false</AotAssemblies>
<EnableLLVM>false</EnableLLVM>
<AndroidEnableProfiledAot>false</AndroidEnableProfiledAot>
<BundleAssemblies>false</BundleAssemblies>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>portable</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AndroidManagedSymbols>true</AndroidManagedSymbols>
<AndroidUseSharedRuntime>false</AndroidUseSharedRuntime>
</PropertyGroup>
<ItemGroup>
<Reference Include="Mono.Android" />
<Reference Include="Mono.Android.Export" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Xml" />
<Reference Include="System.Numerics" />
<Reference Include="System.Numerics.Vectors" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="akavache">
<Version>7.1.1</Version>
</PackageReference>
<PackageReference Include="MvvmCross.Forms">
<Version>7.1.1</Version>
</PackageReference>
<PackageReference Include="Xamarin.Forms" Version="4.8.0.1687" />
<PackageReference Include="Xamarin.Essentials" Version="1.5.3.2" />
</ItemGroup>
<ItemGroup>
<Compile Include="SplashScreenActivity.cs" />
<Compile Include="MainActivity.cs" />
<Compile Include="Resources\Resource.designer.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="Assets\AboutAssets.txt" />
<None Include="Properties\AndroidManifest.xml" />
</ItemGroup>
<ItemGroup>
<AndroidResource Include="Resources\layout\Tabbar.xml" />
<AndroidResource Include="Resources\layout\Toolbar.xml" />
<AndroidResource Include="Resources\values\styles.xml" />
<AndroidResource Include="Resources\values\colors.xml" />
<AndroidResource Include="Resources\mipmap-anydpi-v26\icon.xml" />
<AndroidResource Include="Resources\mipmap-anydpi-v26\icon_round.xml" />
<AndroidResource Include="Resources\mipmap-hdpi\icon.png" />
<AndroidResource Include="Resources\mipmap-hdpi\launcher_foreground.png" />
<AndroidResource Include="Resources\mipmap-mdpi\icon.png" />
<AndroidResource Include="Resources\mipmap-mdpi\launcher_foreground.png" />
<AndroidResource Include="Resources\mipmap-xhdpi\icon.png" />
<AndroidResource Include="Resources\mipmap-xhdpi\launcher_foreground.png" />
<AndroidResource Include="Resources\mipmap-xxhdpi\icon.png" />
<AndroidResource Include="Resources\mipmap-xxhdpi\launcher_foreground.png" />
<AndroidResource Include="Resources\mipmap-xxxhdpi\icon.png" />
<AndroidResource Include="Resources\mipmap-xxxhdpi\launcher_foreground.png" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\<%= namespace %>.Client.Xamarin.Core\<%= namespace %>.Client.Xamarin.Core.csproj">
<Project>{73C411F6-14CB-4E3A-903B-7B42F8AC1651}</Project>
<Name><%= namespace %>.Client.Xamarin.Core</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<AndroidResource Include="Resources\layout\SplashScreen.xml">
<Generator>MSBuild:UpdateGeneratedFiles</Generator>
<SubType>Designer</SubType>
</AndroidResource>
</ItemGroup>
<ItemGroup>
<AndroidResource Include="Resources\drawable\splashscreen.png" />
</ItemGroup>
<ItemGroup>
<AndroidResource Include="Resources\drawable\menu.png" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
<ProjectExtensions>
<VisualStudio>
<UserProperties TriggeredFromHotReload="False" />
</VisualStudio>
</ProjectExtensions>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<SelectedDevice>pixel_2_pie_9_0_-_api_28</SelectedDevice>
<DefaultDevice>pixel_2_pie_9_0_-_api_28</DefaultDevice>
<AndroidDesignerPreferredDevice>Nexus 4</AndroidDesignerPreferredDevice>
<AndroidDesignerPreferredTheme>MainTheme</AndroidDesignerPreferredTheme>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0"
package="com.companyname.<%= namespace %>.Client.Xamarin" android:installLocation="auto">
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="29" />
<application android:label="<%= namespace %>.Client.Xamarin.Android" android:theme="@style/MainTheme"
android:usesCleartextTraffic="true">
</application>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
</manifest>
Loading