Compare commits

...

10 Commits

69 changed files with 8964 additions and 3312 deletions

View File

@ -1,6 +1,6 @@
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
namespace test.Controllers namespace EntityFrameworkBasics.Controllers
{ {
public class AboutController : Controller public class AboutController : Controller
{ {

View File

@ -1,12 +1,48 @@
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using System; using System;
using System.Linq;
namespace test.Controllers namespace EntityFrameworkBasics.Controllers
{ {
public class HomeController : Controller public class HomeController : Controller
{ {
#region Protected members
protected ApplicationDBContext context;
#endregion
/// <summary>
/// Default constructor
/// </summary>
/// <param name="_context">the injected context</param>
public HomeController(ApplicationDBContext _context)
{
context = _context;
}
public IActionResult Index() public IActionResult Index()
{ {
context.Database.EnsureCreated();
if (!context.Settings.Any())
{
context.Settings.Add(new SettingsDataModel
{
Name = "BackgroundColor",
Value = "Red"
});
var SettingsLocally = context.Settings.Local.Count();
var SettingsDatabase = context.Settings.Count();
var firstLocal = context.Settings.Local.FirstOrDefault();
var firstDatabase = context.Settings.FirstOrDefault();
context.SaveChanges();
}
return View(); return View();
} }

View File

@ -0,0 +1,42 @@
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace EntityFrameworkBasics
{
/// <summary>
/// The database representational model for application
/// </summary>
public class ApplicationDBContext : DbContext
{
#region Public properties
public DbSet<SettingsDataModel> Settings { get; set; }
#endregion
#region Constructor
/// <summary>
/// Default constructor, expecting database options passed in
/// </summary>
/// <param name="options">The database context options</param>
public ApplicationDBContext(DbContextOptions<ApplicationDBContext> options) : base(options)
{
}
#endregion
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
// Fluent Api
modelBuilder.Entity<SettingsDataModel>().HasIndex(c => c.Name).IsUnique();
}
}
}

View File

@ -0,0 +1,27 @@
using System.ComponentModel.DataAnnotations;
namespace EntityFrameworkBasics
{
/// <summary>
/// Our Settings database table representional model
/// </summary>
public class SettingsDataModel
{
/// <summary>
/// The unique Id for this entry
/// </summary>
[Key]
public string Id { get; set; }
/// <summary>
/// The settings name
/// </summary>
[MaxLength(256)]
public string Name { get; set; }
/// <summary>
/// The settings value
/// </summary>
[Required]
[MaxLength(2048)]
public string Value { get; set; }
}
}

View File

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk.Web"> <Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup> <PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework> <TargetFramework>netcoreapp2.0</TargetFramework>

View File

@ -0,0 +1,26 @@
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace EntityFrameworkBasics
{
/// <summary>
/// A shorthand access class to get DI services with nice clean short code
/// </summary>
public static class IoC
{
public static ApplicationDBContext ApplicationDbContext => IocContainer.Provider.GetService<ApplicationDBContext>();
}
/// <summary>
/// The dependency Injection container making use of the built in .Net Core service provider
/// </summary>
public static class IocContainer
{
/// <summary>
/// The service provider for this application
/// </summary>
public static ServiceProvider Provider { get; set; }
}
}

View File

@ -1,7 +1,8 @@
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using System.IO; using System.IO;
namespace test namespace EntityFrameworkBasics
{ {
public class Program public class Program
{ {
@ -12,9 +13,7 @@ namespace test
public static IWebHost BuildWebHost(string[] args) public static IWebHost BuildWebHost(string[] args)
{ {
return new WebHostBuilder() return WebHost.CreateDefaultBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseStartup<Startup>() .UseStartup<Startup>()
.Build(); .Build();
} }

View File

@ -4,10 +4,11 @@ using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
namespace test namespace EntityFrameworkBasics
{ {
public class Startup public class Startup
{ {
@ -21,12 +22,19 @@ namespace test
// This method gets called by the runtime. Use this method to add services to the container. // This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services) public void ConfigureServices(IServiceCollection services)
{ {
// Add ApplicationDbContext to DI
services.AddDbContext<ApplicationDBContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
services.AddMvc(); services.AddMvc();
} }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env) public void Configure(IApplicationBuilder app, IHostingEnvironment env, IServiceProvider serviceProvider)
{ {
// Store Instance of the DI service provider so our application can access it anywhere
IocContainer.Provider = (ServiceProvider)serviceProvider;
if (env.IsDevelopment()) if (env.IsDevelopment())
app.UseDeveloperExceptionPage(); app.UseDeveloperExceptionPage();
else else

View File

@ -1,2 +1,2 @@
@using test @using EntityFrameworkBasics
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers

View File

@ -1,4 +1,7 @@
{ {
"ConnectionStrings": {
"DefaultConnection": "Server=192.168.0.135;Database=entityframework;User ID=sa;Password=SAtfoubuntu1SA;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False;MultipleActiveResultSets=true;"
},
"Logging": { "Logging": {
"IncludeScopes": false, "IncludeScopes": false,
"LogLevel": { "LogLevel": {

View File

@ -1,9 +1,9 @@
 
Microsoft Visual Studio Solution File, Format Version 12.00 Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15 # Visual Studio Version 16
VisualStudioVersion = 15.0.27130.2010 VisualStudioVersion = 16.0.29509.3
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "test", "test.csproj", "{B6C91DFF-E4A2-4DD3-A357-F8BECCCA183A}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EntityFrameworkBasics", "EntityFrameworkBasics.csproj", "{B6C91DFF-E4A2-4DD3-A357-F8BECCCA183A}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution

View File

@ -0,0 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
</Project>

View File

@ -0,0 +1,23 @@
using System;
namespace DependencyExample
{
public static class DependencyProvider
{
// This would be from the DI service
public static IFileManager FileManager { get; set; }
public static ILogger Logger { get; set; }
}
public interface IFileManager
{
void WriteFileData(string path, string data);
string GetFileData(string path);
}
public interface ILogger
{
void LogMessage(string message);
}
}

View File

@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\DependencyExample.Core\DependencyExample.Core.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,20 @@
using System;
using System.IO;
namespace DependencyExample
{
public class WindowsFileManager : IFileManager
{
public string GetFileData(string path)
{
return File.ReadAllText(path);
}
public void WriteFileData(string path, string data)
{
DependencyProvider.Logger.LogMessage($"About to write `{data}` to `{path}`");
File.WriteAllText(path, data);
}
}
}

View File

@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\DependencyExample.Core\DependencyExample.Core.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,12 @@
using System;
namespace DependencyExample
{
public class Logger : ILogger
{
public void LogMessage(string message)
{
Console.WriteLine("LOG: " + message);
}
}
}

View File

@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\DependencyExample.Core\DependencyExample.Core.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,26 @@
using System;
namespace DependencyExample
{
public class MockFileManager : IFileManager
{
private string mData;
public bool FailOnPurpose { get; set; }
public string GetFileData(string path)
{
return mData;
}
public void WriteFileData(string path, string data)
{
DependencyProvider.Logger.LogMessage($"Mocking `{data}` to `{path}`, appending ` mock` to the end");
if (FailOnPurpose)
mData = $"{data} mock";
else
mData = data;
}
}
}

View File

@ -0,0 +1,49 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27703.2026
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DependencyExample", "DependencyExample\DependencyExample.csproj", "{4E2E48F3-A142-41EA-B220-D0DB9A1F5B6A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DependencyExample.Core", "DependencyExample.Core\DependencyExample.Core.csproj", "{E032293F-65C1-4679-B337-BED41E3F6CEE}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DependencyExample.FileManager", "DependencyExample.FileManager\DependencyExample.FileManager.csproj", "{4480631E-54CE-4443-9CA0-7F025D86710E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DependencyExample.MockFileManager", "DependencyExample.MemoryFileManager\DependencyExample.MockFileManager.csproj", "{5500D49A-0299-4671-B0D2-AB280190280E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DependencyExample.Logger", "DependencyExample.Logger\DependencyExample.Logger.csproj", "{9568AFCC-7D0E-4ACC-A575-520C5A77F311}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{4E2E48F3-A142-41EA-B220-D0DB9A1F5B6A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4E2E48F3-A142-41EA-B220-D0DB9A1F5B6A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4E2E48F3-A142-41EA-B220-D0DB9A1F5B6A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4E2E48F3-A142-41EA-B220-D0DB9A1F5B6A}.Release|Any CPU.Build.0 = Release|Any CPU
{E032293F-65C1-4679-B337-BED41E3F6CEE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E032293F-65C1-4679-B337-BED41E3F6CEE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E032293F-65C1-4679-B337-BED41E3F6CEE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E032293F-65C1-4679-B337-BED41E3F6CEE}.Release|Any CPU.Build.0 = Release|Any CPU
{4480631E-54CE-4443-9CA0-7F025D86710E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4480631E-54CE-4443-9CA0-7F025D86710E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4480631E-54CE-4443-9CA0-7F025D86710E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4480631E-54CE-4443-9CA0-7F025D86710E}.Release|Any CPU.Build.0 = Release|Any CPU
{5500D49A-0299-4671-B0D2-AB280190280E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5500D49A-0299-4671-B0D2-AB280190280E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5500D49A-0299-4671-B0D2-AB280190280E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5500D49A-0299-4671-B0D2-AB280190280E}.Release|Any CPU.Build.0 = Release|Any CPU
{9568AFCC-7D0E-4ACC-A575-520C5A77F311}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9568AFCC-7D0E-4ACC-A575-520C5A77F311}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9568AFCC-7D0E-4ACC-A575-520C5A77F311}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9568AFCC-7D0E-4ACC-A575-520C5A77F311}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {A96C376B-BF76-4B97-AC16-8B0C4DB26FBE}
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\DependencyExample.Core\DependencyExample.Core.csproj" />
<ProjectReference Include="..\DependencyExample.FileManager\DependencyExample.FileManager.csproj" />
<ProjectReference Include="..\DependencyExample.Logger\DependencyExample.Logger.csproj" />
<ProjectReference Include="..\DependencyExample.MemoryFileManager\DependencyExample.MockFileManager.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,34 @@
using System;
namespace DependencyExample
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
// Inject specific services
DependencyProvider.FileManager = new MockFileManager { FailOnPurpose = true };
DependencyProvider.Logger = new Logger();
// Write some file, and read it back
var data = "this is my test";
var path = @"C:\Users\Luke\Desktop\test.txt";
// Log
DependencyProvider.Logger.LogMessage($"Writing `{data}` to `{path}`");
// Write
DependencyProvider.FileManager.WriteFileData(path, data);
// Read back
var readBack = DependencyProvider.FileManager.GetFileData(path);
// Log
DependencyProvider.Logger.LogMessage($"Read back `{readBack}`");
Console.Read();
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 MiB

View File

@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27703.2026
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleApp1", "ConsoleApp1\ConsoleApp1.csproj", "{3B65C372-E1B4-412C-BB31-6B319B7C2402}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{3B65C372-E1B4-412C-BB31-6B319B7C2402}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3B65C372-E1B4-412C-BB31-6B319B7C2402}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3B65C372-E1B4-412C-BB31-6B319B7C2402}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3B65C372-E1B4-412C-BB31-6B319B7C2402}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {A95F76B1-5DE1-43C6-9B9B-5E9F8D1928FE}
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Dna.Framework" Version="1.0.7.1" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="2.1.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.1.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.1.0" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,83 @@
using Dna;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using System;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
// Add Microsoft.Extensions.DependencyInjection
// Microsoft.Extensions.Configuration(for ConfigurationBuilder)
// Microsoft.Extensions.Configuration.Json(for AddJsonFile)
//
// So its your job to distribute the service collection to any add-in,
// library or part of your code that needs to add its own dependecies
//
// If using configuration you should also pass that along
//
// Then once done you build the service collection into a service provider
// which is now your source of dependency injection where all of your code
// can get services from the provider.GetService<>
//
// So typically this provider is a static instance in a core library
// so all of your code can access it
//
// Create a new list of dependencies
var services = new ServiceCollection();
// At this point, all dependencies can be added to the DI system via the service collection
// Configurations are used heavily in the .Net Core DI for configuring services
// So we can make use of that
// Create our configuration sources
var configurationBuilder = new ConfigurationBuilder();
// Add environment variables
//.AddEnvironmentVariables();
// Add application settings json files
configurationBuilder.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);
// Build configuration
var configuration = configurationBuilder.Build();
// Inject configuration into services
services.AddSingleton<IConfiguration>(configuration);
// Build provider
var provider = services.BuildServiceProvider();
// After this point, DI is available and through the provider
//
// Dna framework
//
//
// Use Framework.Construct<FrameworkConstruction> for totally blank service provider
// containing just the FrameworkEnvironment service, no Configuration or anything else
// Use the DefaultFrameworkConstruction to add a Configuration similar to ASP.Net
// with the Configuration source of appsettings.json file, and to also add
// a basic console/debug logger and an exception handler that just logs errors
Framework.Construct<DefaultFrameworkConstruction>()
// Add further services like this
.AddFileLogger()
// And once done build
.Build();
// Now the service provider is here
Framework.Provider.GetService<ILogger>().LogCriticalSource("Some important message");
// Or shortcuts here
FrameworkDI.Logger.LogCriticalSource("Shortcut to important message");
}
}
}

File diff suppressed because it is too large Load Diff

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 154 B

View File

@ -1,7 +0,0 @@
If you get white side panel and top panel in control panel...
- Close everything on computer so no windows are open
- Run one of the Control Panel Dark exe files
- Restart PC
To revert to standard run Control Panel Default W10.exe

View File

@ -0,0 +1,27 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.28010.2003
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "App2", "AndroidLifecycle\AndroidLifecycle.csproj", "{3BC0AC7E-3B3B-4D3F-9CC0-B2BDECC460A6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{3BC0AC7E-3B3B-4D3F-9CC0-B2BDECC460A6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3BC0AC7E-3B3B-4D3F-9CC0-B2BDECC460A6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3BC0AC7E-3B3B-4D3F-9CC0-B2BDECC460A6}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
{3BC0AC7E-3B3B-4D3F-9CC0-B2BDECC460A6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3BC0AC7E-3B3B-4D3F-9CC0-B2BDECC460A6}.Release|Any CPU.Build.0 = Release|Any CPU
{3BC0AC7E-3B3B-4D3F-9CC0-B2BDECC460A6}.Release|Any CPU.Deploy.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {A57BA0BB-5685-40AC-B6DC-5723EA45AD37}
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,110 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{3BC0AC7E-3B3B-4D3F-9CC0-B2BDECC460A6}</ProjectGuid>
<ProjectTypeGuids>{EFBA0AD7-5A72-4C68-AF49-83D382785DCF};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<TemplateGuid>{84dd83c5-0fe3-4294-9419-09e7c8ba324f}</TemplateGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>AndroidLifecycle</RootNamespace>
<AssemblyName>AndroidLifecycle</AssemblyName>
<FileAlignment>512</FileAlignment>
<AndroidApplication>True</AndroidApplication>
<AndroidResgenFile>Resources\Resource.Designer.cs</AndroidResgenFile>
<AndroidResgenClass>Resource</AndroidResgenClass>
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
<AndroidUseLatestPlatformSdk>false</AndroidUseLatestPlatformSdk>
<TargetFrameworkVersion>v7.1</TargetFrameworkVersion>
<AndroidManifest>Properties\AndroidManifest.xml</AndroidManifest>
<MonoAndroidResourcePrefix>Resources</MonoAndroidResourcePrefix>
<MonoAndroidAssetsPrefix>Assets</MonoAndroidAssetsPrefix>
<AndroidHttpClientHandlerType>Xamarin.Android.Net.AndroidClientHandler</AndroidHttpClientHandlerType>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>True</DebugSymbols>
<DebugType>portable</DebugType>
<Optimize>False</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AndroidUseSharedRuntime>True</AndroidUseSharedRuntime>
<AndroidLinkMode>None</AndroidLinkMode>
<EmbedAssembliesIntoApk>False</EmbedAssembliesIntoApk>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>PdbOnly</DebugType>
<DebugSymbols>True</DebugSymbols>
<Optimize>True</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AndroidManagedSymbols>true</AndroidManagedSymbols>
<AndroidUseSharedRuntime>False</AndroidUseSharedRuntime>
<AndroidLinkMode>SdkOnly</AndroidLinkMode>
<EmbedAssembliesIntoApk>True</EmbedAssembliesIntoApk>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Xml" />
<Reference Include="System.Core" />
<Reference Include="Mono.Android" />
</ItemGroup>
<ItemGroup>
<Compile Include="MainActivity.cs" />
<Compile Include="Resources\Resource.Designer.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\AboutResources.txt" />
<None Include="Properties\AndroidManifest.xml" />
<None Include="Assets\AboutAssets.txt" />
</ItemGroup>
<ItemGroup>
<AndroidResource Include="Resources\layout\activity_main.axml">
<SubType>Designer</SubType>
</AndroidResource>
<AndroidResource Include="Resources\layout\content_main.axml">
<SubType>Designer</SubType>
</AndroidResource>
<AndroidResource Include="Resources\values\colors.xml" />
<AndroidResource Include="Resources\values\dimens.xml" />
<AndroidResource Include="Resources\values\ic_launcher_background.xml" />
<AndroidResource Include="Resources\values\strings.xml" />
<AndroidResource Include="Resources\values\styles.xml" />
<AndroidResource Include="Resources\menu\menu_main.xml" />
<AndroidResource Include="Resources\mipmap-anydpi-v26\ic_launcher.xml" />
<AndroidResource Include="Resources\mipmap-anydpi-v26\ic_launcher_round.xml" />
<AndroidResource Include="Resources\mipmap-hdpi\ic_launcher.png" />
<AndroidResource Include="Resources\mipmap-hdpi\ic_launcher_foreground.png" />
<AndroidResource Include="Resources\mipmap-hdpi\ic_launcher_round.png" />
<AndroidResource Include="Resources\mipmap-mdpi\ic_launcher.png" />
<AndroidResource Include="Resources\mipmap-mdpi\ic_launcher_foreground.png" />
<AndroidResource Include="Resources\mipmap-mdpi\ic_launcher_round.png" />
<AndroidResource Include="Resources\mipmap-xhdpi\ic_launcher.png" />
<AndroidResource Include="Resources\mipmap-xhdpi\ic_launcher_foreground.png" />
<AndroidResource Include="Resources\mipmap-xhdpi\ic_launcher_round.png" />
<AndroidResource Include="Resources\mipmap-xxhdpi\ic_launcher.png" />
<AndroidResource Include="Resources\mipmap-xxhdpi\ic_launcher_foreground.png" />
<AndroidResource Include="Resources\mipmap-xxhdpi\ic_launcher_round.png" />
<AndroidResource Include="Resources\mipmap-xxxhdpi\ic_launcher.png" />
<AndroidResource Include="Resources\mipmap-xxxhdpi\ic_launcher_foreground.png" />
<AndroidResource Include="Resources\mipmap-xxxhdpi\ic_launcher_round.png" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Xamarin.Android.Support.Design" Version="25.4.0.2" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View File

@ -0,0 +1,19 @@
Any raw assets you want to be deployed with your application can be placed in
this directory (and child directories) and given a Build Action of "AndroidAsset".
These files will be deployed with you package and will be accessible using Android's
AssetManager, like this:
public class ReadAsset : Activity
{
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
InputStream input = Assets.Open ("my_asset.txt");
}
}
Additionally, some Android functions will automatically load asset files:
Typeface tf = Typeface.CreateFromAsset (Context.Assets, "fonts/samplefont.ttf");

View File

@ -0,0 +1,206 @@
using Android.App;
using Android.OS;
using Android.Support.Design.Widget;
using Android.Support.V7.App;
using Android.Views;
using System;
namespace AndroidLifecycle
{
[Activity(Label = "@string/app_name", Theme = "@style/AppTheme.NoActionBar", MainLauncher = true)]
public class MainActivity : AppCompatActivity
{
//
// A good reference starting point for the actibity life cycle is here
// https://developer.android.com/reference/android/app/Activity
//
// Events on application creation
// =========================================
// ~~~~~~~~~~~~~~~~ OnCreate
// ~~~~~~~~~~~~~~~~ OnStart
// ~~~~~~~~~~~~~~~~ OnPostCreate
// ~~~~~~~~~~~~~~~~ OnStateNotSaved
// ~~~~~~~~~~~~~~~~ OnResume
// ~~~~~~~~~~~~~~~~ OnPostResume
//
//
// Events on back button press
// =========================================
// ~~~~~~~~~~~~~~~~ Finish
// ~~~~~~~~~~~~~~~~ OnPause
// ~~~~~~~~~~~~~~~~ OnStop
// ~~~~~~~~~~~~~~~~ OnDestroy
//
//
// Events on re-open after back button
// =========================================
// ~~~~~~~~~~~~~~~~ OnCreate
// ~~~~~~~~~~~~~~~~ OnStart
// ~~~~~~~~~~~~~~~~ OnPostCreate
// ~~~~~~~~~~~~~~~~ OnStateNotSaved
// ~~~~~~~~~~~~~~~~ OnResume
// ~~~~~~~~~~~~~~~~ OnPostResume
//
//
// Events on Home / Menu button press
// =========================================
// ~~~~~~~~~~~~~~~~ OnUserLeaveHint
// ~~~~~~~~~~~~~~~~ OnPause
// ~~~~~~~~~~~~~~~~ OnSaveInstanceState
// ~~~~~~~~~~~~~~~~ OnStop
//
//
// Events on re-open after Home / Menu
// =========================================
// ~~~~~~~~~~~~~~~~ OnStateNotSaved
// ~~~~~~~~~~~~~~~~ OnRestart
// ~~~~~~~~~~~~~~~~ OnStart
// ~~~~~~~~~~~~~~~~ OnResume
// ~~~~~~~~~~~~~~~~ OnPostResume
//
//
// Instant Kill
// =========================================
// No guaranteed calls
//
//
// DONT USE DISPOSE or JavaFinalize (Slide 44 onwards)
// Use OnDestroy instead
// https://www.slideshare.net/Xamarin/advanced-memory-management-on-ios-and-android-mark-probst-and-rodrigo-kumpera
//
protected override void OnCreate(Bundle savedInstanceState)
{
Console.WriteLine("~~~~~~~~~~~~~~~~ OnCreate");
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.activity_main);
Android.Support.V7.Widget.Toolbar toolbar = FindViewById<Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar);
SetSupportActionBar(toolbar);
FloatingActionButton fab = FindViewById<FloatingActionButton>(Resource.Id.fab);
fab.Click += FabOnClick;
}
public override void OnCreate(Bundle savedInstanceState, PersistableBundle persistentState)
{
Console.WriteLine("~~~~~~~~~~~~~~~~ OnCreate 2");
base.OnCreate(savedInstanceState, persistentState);
}
protected override void OnStart()
{
Console.WriteLine("~~~~~~~~~~~~~~~~ OnStart");
base.OnStart();
}
protected override void OnPostCreate(Bundle savedInstanceState)
{
Console.WriteLine("~~~~~~~~~~~~~~~~ OnPostCreate");
base.OnPostCreate(savedInstanceState);
}
public override void OnPostCreate(Bundle savedInstanceState, PersistableBundle persistentState)
{
Console.WriteLine("~~~~~~~~~~~~~~~~ OnPostCreate 2");
base.OnPostCreate(savedInstanceState, persistentState);
}
public override void OnStateNotSaved()
{
Console.WriteLine("~~~~~~~~~~~~~~~~ OnStateNotSaved");
base.OnStateNotSaved();
}
protected override void OnResume()
{
Console.WriteLine("~~~~~~~~~~~~~~~~ OnResume");
base.OnResume();
}
protected override void OnPostResume()
{
Console.WriteLine("~~~~~~~~~~~~~~~~ OnPostResume");
base.OnPostResume();
}
protected override void OnUserLeaveHint()
{
Console.WriteLine("~~~~~~~~~~~~~~~~ OnUserLeaveHint");
base.OnUserLeaveHint();
}
protected override void OnPause()
{
Console.WriteLine("~~~~~~~~~~~~~~~~ OnPause");
base.OnPause();
}
protected override void OnSaveInstanceState(Bundle outState)
{
Console.WriteLine("~~~~~~~~~~~~~~~~ OnSaveInstanceState");
base.OnSaveInstanceState(outState);
}
public override void OnSaveInstanceState(Bundle outState, PersistableBundle outPersistentState)
{
Console.WriteLine("~~~~~~~~~~~~~~~~ OnSaveInstanceState 2");
base.OnSaveInstanceState(outState, outPersistentState);
}
protected override void OnStop()
{
Console.WriteLine("~~~~~~~~~~~~~~~~ OnStop");
base.OnStop();
}
protected override void OnRestart()
{
Console.WriteLine("~~~~~~~~~~~~~~~~ OnRestart");
base.OnRestart();
}
protected override void OnDestroy()
{
Console.WriteLine("~~~~~~~~~~~~~~~~ OnDestroy");
base.OnDestroy();
}
public override void Finish()
{
Console.WriteLine("~~~~~~~~~~~~~~~~ Finish");
base.Finish();
}
#region App Specific Code
public override bool OnCreateOptionsMenu(IMenu menu)
{
MenuInflater.Inflate(Resource.Menu.menu_main, menu);
return true;
}
public override bool OnOptionsItemSelected(IMenuItem item)
{
int id = item.ItemId;
if (id == Resource.Id.action_settings)
{
return true;
}
return base.OnOptionsItemSelected(item);
}
private void FabOnClick(object sender, EventArgs eventArgs)
{
View view = (View) sender;
Snackbar.Make(view, "Replace with your own action", Snackbar.LengthLong)
.SetAction("Action", (Android.Views.View.IOnClickListener)null).Show();
}
#endregion
}
}

View File

@ -0,0 +1,5 @@
<?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="AndroidLifecycle.AndroidLifecycle" android:installLocation="auto">
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="25" />
<application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"></application>
</manifest>

View File

@ -0,0 +1,30 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using Android.App;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("AndroidLifecycle")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("AndroidLifecycle")]
[assembly: AssemblyCopyright("Copyright © 2018")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@ -0,0 +1,44 @@
Images, layout descriptions, binary blobs and string dictionaries can be included
in your application as resource files. Various Android APIs are designed to
operate on the resource IDs instead of dealing with images, strings or binary blobs
directly.
For example, a sample Android app that contains a user interface layout (main.axml),
an internationalization string table (strings.xml) and some icons (drawable-XXX/icon.png)
would keep its resources in the "Resources" directory of the application:
Resources/
drawable/
icon.png
layout/
main.axml
values/
strings.xml
In order to get the build system to recognize Android resources, set the build action to
"AndroidResource". The native Android APIs do not operate directly with filenames, but
instead operate on resource IDs. When you compile an Android application that uses resources,
the build system will package the resources for distribution and generate a class called "R"
(this is an Android convention) that contains the tokens for each one of the resources
included. For example, for the above Resources layout, this is what the R class would expose:
public class R {
public class drawable {
public const int icon = 0x123;
}
public class layout {
public const int main = 0x456;
}
public class strings {
public const int first_string = 0xabc;
public const int second_string = 0xbcd;
}
}
You would then use R.drawable.icon to reference the drawable/icon.png file, or R.layout.main
to reference the layout/main.axml file, or R.strings.first_string to reference the first
string in the dictionary file values/strings.xml.

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_main" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
app:srcCompat="@android:drawable/ic_dialog_email" />
</android.support.design.widget.CoordinatorLayout>

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:showIn="@layout/activity_main">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="Hello World!" />
</RelativeLayout>

View File

@ -0,0 +1,9 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:title="@string/action_settings"
app:showAsAction="never" />
</menu>

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@color/ic_launcher_background"/>
<foreground android:drawable="@mipmap/ic_launcher_foreground"/>
</adaptive-icon>

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@color/ic_launcher_background"/>
<foreground android:drawable="@mipmap/ic_launcher_foreground"/>
</adaptive-icon>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 958 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

View File

@ -0,0 +1,4 @@
<resources>
<string name="app_name">AndroidLifecycle</string>
<string name="action_settings">Settings</string>
</resources>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#2c3e50</color>
<color name="colorPrimaryDark">#1B3147</color>
<color name="colorAccent">#3498db</color>
</resources>

View File

@ -0,0 +1,3 @@
<resources>
<dimen name="fab_margin">16dp</dimen>
</resources>

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="ic_launcher_background">#2C3E50</color>
</resources>

View File

@ -0,0 +1,20 @@
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
</resources>