Thursday, March 28, 2019

wpf binding examples

Satic Resource und Converter:

Width="{Binding Source ={StaticResource ColorPickerColumnDefaultWidth}, Converter={StaticResource DoubleToGridLengthConverter},Mode=OneWay}" />

Dependency property in User Control:
Text="{Binding TitleText, ElementName=MyUserControl}"


<TextBlock Text="{Binding Name, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}} }"/>
<TextBlock Text="{Binding Name, ElementName=UcPaneHeader}"/>

<TextBlock Text="{Binding Name, ElementName=PaneTitle}"/>

Thursday, March 21, 2019

asp.net core and EF (asp.net types: empty, API)

Connection Strings

InMemory Datenbank:

services.AddDbContext<TodoContext>(opt => opt.UseInMemoryDatabase("TodoList"));

LocalDb

aus https://docs.microsoft.com/en-us/ef/core/get-started/aspnetcore/new-db?tabs=visual-studio

var connection = @"Server=(localdb)\mssqllocaldb;Database=EFGetStarted.AspNetCore.NewDb;Trusted_Connection=True;ConnectRetryCount=0";
    services.AddDbContext<BloggingContext>
        (options => options.UseSqlServer(connection));

leere Web App

Programm.cs startet Webhost mit class Startup und Methode Configure, z.b.: 

            app.Run(async (context) =>
            {
                await context.Response.WriteAsync("Hello World!");
            });

einfaches Webservice (API)

webApi Template Projekt erstellen - liefert value1, value2 durch ValuesController, der einfach auf GET Request mit Konstantem String antwortet, dazu genügen die Attribute:
    [Route("api/[controller]")] // antwortet auf SubDir mit Controllername (schneided Controller Suffix weg)
    [ApiController]

in Startup.cs: app.UseMvc();


füge Model Klasse und DbContext hinzu:

Model(s):

    public class TodoItem
    {
        public long Id { get; set; }
        public string Name { get; set; }
        public bool IsComplete { get; set; }
    }

DbContext:

public class TodoContext : DbContext
    {
        public TodoContext(DbContextOptions<TodoContext> options)
            : base(options)
        {
        }
        public DbSet<TodoItem> TodoItems { get; set; }
    }

in Startup.cs DbContext hinzufügen:
public void ConfigureServices(IServiceCollection services)
        {
            services.AddDbContext<TodoContext>(opt => opt.UseInMemoryDatabase("TodoList"));
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
        }


Controller hinzufügen (rechte Maustaste auf Controller Ordner )

1)MVC-Controller leer
2) MVC Controller mit Ansichten unter Verwendung von EF
3) MVC Controller mit Lese/SchreibAktionen
4) API-Controller leer:
    [Route("api/[controller]")]
    [ApiController]
    public class EmptyController : ControllerBase
    {
    }
5) API-Controller mit Lese/Schreibaktionen:
fügt get, post,put und delete Methoden hinzu, unter Annahme einer id vom Typ int,, gibt string "value" zurück
6) API-Controller mit Aktionen unter Verwendung von EF:
in Maske Context und Modell Klasse auswählen => generiert API mit put, get usw.


Statische Files

schließlich jquery static file dass die api nutzt:
in Startup.onfigure:
            app.UseDefaultFiles();
            app.UseStaticFiles();



Wednesday, March 20, 2019

clean obj bin

Get-ChildItem .\ -include bin,obj -Recurse | foreach ($_) { remove-item $_.fullname -Force -Recurse }

asp.net core EF core migrations

1) add a model
    public class TestEntity
    {
        public int Id { get; set; }

        public string TestString { get; set; }

    }

2) add a context
    public class TestContext1 : DbContext
    {
        DbSet<TestEntity> TestEntities { get; set; }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            base.OnConfiguring(optionsBuilder);
            if (!optionsBuilder.IsConfigured)
            {
#warning To protect potentially sensitive information in your connection string, you should move it out of source code. See http://go.microsoft.com/fwlink/?LinkId=723263 for guidance on storing connection strings.
                optionsBuilder.UseSqlServer(@"Server=localhost\sqlexpress;Database=test;Trusted_Connection=True;");
            }
         

        }
    }

3) start Nuget Package Manager Console: ALT T N O
select the project with your model and context as start project
Add-Migration M0001
update-database

WICHTIG: Projekt mit Context muß als Startup projekt und in Nuget Manager Console ausgewählt sein ! Bei Asp.Net muß der Context auch in der Startup Klasse sein ...

asp.net core using existing db

https://docs.microsoft.com/en-us/ef/core/get-started/aspnetcore/existing-db

1) in Packet-Manager-Console: Scaffold-DbContext "Server=localhost\sqlexpress;Database=test;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models
=> erzeugt Context und EF Models
2) in Startup.cs Context regisitrieren:
services.AddDbContext<testContext>();

3) rechts click auf Controllers, Add Controller, MVC Controller mit Ansichten (Views) unter Verwendung von EF

4) Starten, und in adresszeile den Modellnamen hinzufügen

Monday, March 18, 2019

einfaches css beispiel

<link rel="stylesheet" type="text/css" href="style.css" />
<h1>header1</h1>
normal
<p style="color:green; font-weight: bold; ">absatz</p>

direkt im code: style="Eigenschaft:wert"

in style.css (einbinden mit link rel="stylesheet" type="text/css" href="style.css" )

h1 { color:red}

wordpress grundlagen

https://www.miss-webdesign.at/wordpress-grundlagen/

theme:
jedes jahr bringt wordpress ein neues theme raus - 2015 twentyFifteen stellt das menü in der sidebar als Baum dar, 2017 twentySeventeen bringt die menüpunkte nebeneinander

child theme:
neuen ordner in wp_content/themes mit parentTheme-child name und 3 dateien: style.css, functions.php und screenshot.png:

siteurls usw. in db in wp_options tabelle

define('FS_METHOD','direct');
chown www-data:www-data wordpress -R


wordpress auf linux

Apache, php installieren und testen:

sudo apt install apache2 php libapache2-mod-php -y
sudo service apache2 restart
cd /var/www/html/
create index.php:
<?php echo "hello world"; ?>
<?php echo date('Y-m-d H:i:s'); ?>
<?php phpinfo(); ?>

mysql installieren

sudo apt install mysql-server php-mysql phpmyadmin -y
sudo wget http://wordpress.org/latest.tar.gz
sudo tar xzf latest.tar.gz
=> test localhost/wordpress Directory sollte etwas anzeigen
sudo chown -R www-data: .
sudo mysql_secure_installation

Datenbank anlegen

sudo mysql -uroot -p
create database wordpress;
GRANT ALL PRIVILEGES ON wordpress.* TO 'root'@'localhost' IDENTIFIED BY 'PASSWORD';
FLUSH PRIVILEGES;
Exit the MariaDB database management tool with Ctrl + D.

Wordpress installieren

initial Seite wordpress aufrufen und db daten eingeben

Thursday, March 14, 2019

wpf dependency Properties

Definition 

in z.b. UserControl
public partial class MyUserControl : UserControl
{
        public static readonly DependencyProperty HeaderProperty =
            DependencyProperty.Register("Header", typeof(string), typeof(MyUserControl ), new FrameworkPropertyMetadata("DefaultHeaderText"));

//zusätzlich um einfacheen Setzten / Lesen der Dep.property:
        public string Header
        {
            get => (string)GetValue(HeaderProperty);
            set => SetValue(HeaderProperty, value);
        }
...

Binding 

im Usercontrol:
<UserControl x:Name="myUserControl"

<TextBlock Text="{Binding Header, ElementName=myUserControl}"/>

wichtig mit ElementName=myUserControl wird richtiger Context hergestellt

asp.net core simple web

create a dir
dotnet new web
creates Startup.cs and other files
dotnet run
browse localhost:5000


static files:
https://docs.microsoft.com/en-us/aspnet/core/fundamentals/static-files?view=aspnetcore-2.2
in Startup.cs

  public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {

            app.UseStaticFiles(); }

then create test.htm in wwwroot with any text in it
browse localhost:5000/test.htm

or:
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {

            app.UseStaticFiles();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.Run(async (context) =>
            {
                await context.Response.WriteAsync("Hello World!");
            });
        }

Wednesday, March 13, 2019

asp.net core on raspi (rasbian)

Installieren .netcore am rasperry:

This section is sourced from Dave the Engineer’s post on the Microsoft blog website.
The following commands need to be run on the Raspberry Pi whilst connected over an SSH session or via a terminal in the PIXEL desktop environment.
  • Run sudo apt-get install curl libunwind8 gettext. This will use the apt-get package manager to install three prerequiste packages.
  • Run curl -sSL -o dotnet.tar.gz https://dotnetcli.blob.core.windows.net/dotnet/Runtime/release/2.0.0/dotnet-runtime-latest-linux-arm.tar.gz to download the latest .NET Core Runtime for ARM32. This is refereed to as armhf on the Daily Builds page.
  • Run sudo mkdir -p /opt/dotnet && sudo tar zxf dotnet.tar.gz -C /opt/dotnet to create a destination folder and extract the downloaded package into it.
  • Run sudo ln -s /opt/dotnet/dotnet /usr/local/bin` to set up a symbolic link…a shortcut to you Windows folks 😉 to the dotnet executable.
  • Test the installation by typing dotnet -h or dotnet --help

Erstellen einer hello world console app mit windows .net core sdk:

dotnet new console --output sample1 dotnet run --project sample1