Wednesday, October 31, 2018

Exchange Server Version



            string exchangeVersion = "";
            exchangeVersion = OwaTools.GetExchangeServerVersion("foo.bar@outlook.com", "pwd", "https://outlook.office365.com/EWS/Exchange.asmx");


using Microsoft.Exchange.WebServices.Data;


        /// <summary>
        /// gets Exchange Server Version
        /// </summary>
        /// <param name="userName">Domain\Username or email adress in some cases (office365)</param>
        /// <param name="userPassword">pwd</param>
        /// <param name="uri">https://server/EWS/EWS/Exchange.asmx e.g. https://outlook.office365.com/EWS/Exchange.asmx  </param>
        /// <returns></returns>
        public static string GetExchangeServerVersion(string userName, string userPassword, string uri)
        {
            var service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
            service.Credentials = new NetworkCredential(userName, userPassword);
            service.Url = new Uri(uri);
            ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true; // ignore invalid or self signed certificates
            var inbox = Folder.Bind(service, WellKnownFolderName.Contacts);
            var esi = inbox.Service.ServerInfo;
            return esi.VersionString;
        }

Monday, October 01, 2018

wpf Default Style überschreiben, Datatrigger

                        <TextBox x:Name="Tb_Id" Text="bla">
                            <TextBox.Style>
                                <Style TargetType="TextBox" BasedOn="{StaticResource {x:Type TextBox}}">
                                    <Setter Property="ToolTip" Value="tip1"></Setter>
                                    <Style.Triggers>
                                        <DataTrigger Binding="{Binding Id}" Value="ded371c8-ca5c-416f-9879-6325650e279b">
                                            <Setter Property="ToolTip" Value="Tip2"></Setter>
                                        </DataTrigger>
                                    </Style.Triggers>
                                </Style>
                            </TextBox.Style>

                        </TextBox>

wpf datatemplate usercontrol

<UserControl x:Class="isiQiri.ConfigTool.View.SupportView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             >
    <UserControl.Resources>
        <DataTemplate DataType="{x:Type class1}">
            <StackPanel Orientation="Horizontal" >
                <TextBlock Text="Shift"></TextBlock>
            </StackPanel>
        </DataTemplate>

        <DataTemplate DataType="{x:Type class2}">
            <StackPanel Orientation="Horizontal" DataContext="{Binding}">
                <TextBlock Text="EditorViewModel: " />
            </StackPanel>
        </DataTemplate>
     
    </UserControl.Resources>

   
    <StackPanel>


   <ContentControl Content="{Binding}"></ContentControl>

Wednesday, August 22, 2018

wpf validierung IDataErrorInfo, ValidatesOnDataErrors=True, NotifyOnValidationError=True

um eigene DataError Validierung durchzuführen, muß das Viewmodel IDataErrorInfo implementieren - das ist ein INdexer auf das Viewmodel, dem als string der Properyname der zu validierenden Eigenschaft übergeben wird, und ein string mit validierungsmessage zurückgibt. null bedeutet kein Fehler.
Im Xaml müssen im Databinding ValidatesOnDataErrors=True, NotifyOnValidationError=True gesetz sein

IDataErrorInfo implementierung:

ganz einfach (in viewmodelbaseclass z.b.)
        public virtual string this[string columnName] => null; // nothing to validate here
        public virtual string Error => EditorResources.DefaultErrorMessage;


oder dann ausimplementiert:

      public override string this[string columnName]
        {
            get
            {
                switch (columnName)
                {
                    case nameof(MinNumericValue):
                    case nameof(MaxNumericValue):
                        return _validateMinMax(_doNumericValidation, MinNumericValue, MaxNumericValue);

                    case nameof(MinDecimalValue):
                    case nameof(MaxDecimalValue):
                        return _validateMinMax(_doDecimalValidation, MinDecimalValue, MaxDecimalValue);

                    case nameof(MinDateTimeValue):
                    case nameof(MaxDateTimeValue):
                        return _validateMinMax(_doDateTimeValidation, MinDateTimeValue, MaxDateTimeValue);

                    default:
                        return null;
                }
            }
        }


die Propery Setter:

        public int? MaxNumericValue
        {
            get => _maxNumericValue;
            set
            {
                _maxNumericValue = value;
                _doNumericValidation = true;
                OnPropertyChanged();
                OnPropertyChanged(nameof(MinNumericValue));
                _doNumericValidation = false;
                IsModified = true;
             
            }
        }



        public int? MinNumericValue
        {
            get => _minNumericValue;
            set
            {
                _minNumericValue = value;
                _doNumericValidation = true;
                OnPropertyChanged();
                OnPropertyChanged(nameof(MaxNumericValue));
                _doNumericValidation = false;
                IsModified = true;
            }
        }

usw.

einfache Min Max Validierung:



        private string _validateMinMax <T>(bool doValidation, T? min, T? max) where T: struct, IComparable<T>
        {
            if (!doValidation || null == min || null == max) return null;


            if (0 >= min.Value.CompareTo(max.Value))
                return null;
            return EditorResources.MinMax_Validation;

        }

auch gut:
https://www.codeproject.com/Tips/858492/WPF-Validation-Using-IDataErrorInfo

Tuesday, August 14, 2018

linux netzwerk befehle

ip a
dhclient interfacename

Monday, July 02, 2018

raspberry pi linux first steps - fixe statische IP Adresse

Keyboard de


sudo nano /etc/default/keyboard
xkblayout="de"

sudo shutdown -r now

sudo raspi-config

fixe statische IP Adresse

sudo nano /etc/dhcpcd.conf:

interface eth0
static ip_address=192.168.1.2/24
static routers=192.168.1.1
static domain_name_servers=192.168.1.1
 

interface wlan0
static ip_address=192.168.1.6/24
static routers=192.168.1.1
static domain_name_servers=192.168.1.1

Zeitzone

der link /etc/localtime verweist auf die aktuelle lokale Zeitzoneen datei, cat /etc/localtime zeigt diese an, auf CET (Central European Time) setzten mittels:

sudo ln -sf /usr/share/zoneinfo/CET /etc/localtime

überprüfen mit:
date
date -u 

 

Wednesday, June 27, 2018

sql server Row number / Zeilen nummer

select ROW_NUMBER() OVER (ORDER by ColumnDefinition) as rownumber, *
 from sb.RowDefinition  order by ColumnDefinition

Tuesday, June 26, 2018

posh-git power shell erweiterung

auf github posh-git repro runterladen:
git clone https://github.com/dahlbyk/posh-git.git

Power shell Profile Script anlegen wenn noch nicht vorhanden (autoexec):
New-Item -ItemType File -Path $Profile -Force

%HOMEPATH%/Documents/WindowsPowerShell\Microsoft.PowerShell_profile (z.b. C:\Users\xxx\Documents\WindowsPowerShell )

im profile hinzufügen:

$installDir = "D:\github\posh-git"
Import-Module $installDir\src\posh-git.psd1
Add-PoshGitToProfile -WhatIf:$WhatIf -Force:$Force -Verbose:$Verbose

Friday, June 22, 2018

xaml basics (Binding ...)

Element.Eigenschaftsschreibweise

normalerweise werden Attribute (Eigenschaften) als String angegebeen:
<Button Width="100" Background="blue"> (parser creiert Button und setzt dessen Background Eigenschaft vom Typ Brush auf einen Solid...Brush den er aus einem StringToColorConverter erzeugt)

<Button Width="100">
<Button.Background>
<LinearGradientBrush>
<GradientStop Color="RoyalBlue" Offset="0.0" />
<GradientStop Color="White" Offset="1.0" />
</LinearGradientBrush>
</Button.Background>
</Button>

Markup Erweiterungen

system.Windows.Data.Binding, StaticResource, DynamicResource x

Binding:

Quellen: DataContext, Source, RelativSource, Elementname

Default mäßig genügt es eine Eigenschaft des Datacontextes anzugeben (und damit aufs Viewmodel=Datacontext zu binden, dieses wird solange im Baum aufwärts gesucht bis irgendein DataContext gefunden wird):

{Binding MyDatacontextProperty}

 - es ist aber auch möglich auf Eigenschaften von GUI Elemente zu binden mittels der Eigenschaft Elementname:
Text="{Binding MyText, ElementName=MyUserControl}"

<Binding Path ="Foreground" RelativeSource="{RelativeSource Mode=FindAncestor,AncestorType=UserControl}"/>

Parent: {RelativeSource AncestorType=ContentControl}

multiBinding:



                            <TextBlock.Foreground>
                                <MultiBinding Converter="{StaticResource ColorStringToBrush}">
                                    <Binding Path="FgColor" />
                                    <Binding Path ="Foreground, Elementname=Root"/>
                                </MultiBinding>
                            </TextBlock.Foreground>


Default Brushes:


_textbox.SystemColors.WindowTextBrush

_textbox.Background = SystemColors.WindowBrush;

c# if (x is Brush brush)

type abfrage gleich in variable

Thursday, June 21, 2018

Wpf Converter with DependendyProperty



    public class ColorStringToBrushConverter : DependencyObject, IValueConverter
    {
        public static readonly DependencyProperty DefaultBrush_PROPERTY = DependencyProperty.Register("DefaultBrush", typeof(Brush), typeof(ColorStringToBrushConverter));

        public Brush DefaultBrush
        {
            get => (Brush)GetValue(DefaultBrush_PROPERTY);
            set => SetValue(DefaultBrush_PROPERTY, value);
        }

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {

            var brush = DefaultBrush;
            string colorString = value as string;

            if (string.IsNullOrEmpty(colorString)) //use parameter if value not set
                colorString = parameter as string;

            if (!string.IsNullOrEmpty(colorString))
            {
                var colorObject = ColorConverter.ConvertFromString(colorString);
                if (null != colorObject)
                {
                    var color = (Color)colorObject;
                    brush = new SolidColorBrush(color);
                }

            }

            return brush;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }

Tuesday, June 19, 2018

linux hibernate / Ruhezustand

systemctl suspend
sudo pm-suspend

.net colors

            var c1 = System.Drawing.Color.Aqua;
            var c2 = SystemColors.ActiveBorderBrush;
            var c3 = System.Windows.Media.Color.FromRgb(3, 0, 0);

in Wpf gibts vordefinierte Brushes:
System.Windows.Media.Brushes ... eine Liste von SolidColorBrushes

Monday, June 18, 2018

BIOS / Bootmenu

Marke: BIOS / Bootmenu:

Lenovo: F1 / F12

Thursday, June 07, 2018

android debug bridge adb, shell basics Samsung



adb reboot bootloader

adb installieren und starten

entweder android Studio oder sdk installieren, adb.exe ist in
C:\Program Files (x86)\Android\android-sdk\platform-tools

adb befehle

adb devices //listet alle verbundenen geräte auf
adb shell //linux shell auf android gerät aufmachen

Adb Shell

partitionen

cat /proc/partitions
df

Wednesday, June 06, 2018

power shell parameter example cmdlet

<#

    .SYNOPSIS

    Upload a ConfigFile over Default Configuration

 



    .DESCRIPTION

    Uploads File with given Path over Default Configuration (is overwritten !!!)

    of a Database (default Db) of a sql SERVERINSTANCE (default localhost\sqlexpress)



    .EXAMPLE

        .\UploadConfigFile.ps1 D:\temp\Configuration.

            uploads the file Configuration. over the Default Configuration

    .EXAMPLE

        .\UploadConfigFile.ps1 D:\temp\Configuration. -ServerInstance myserver -Database db1

            uploads the file Configuration. over the Default Configuration on Database db1 of Sql Server myserver



    .PARAMETER FilePath

        mandatory, file to be uploaded over the default  configuration

    .PARAMETER Database

        optional, name of Database (default=Db)

    .PARAMETER ServerInstance

        optional, name of Sql Server Instance (default localhost/sqlexpress)







     

#>

[CmdletBinding()]

param

(

    [Parameter(Mandatory=$true)]

    [string]$FilePath,

    [string]$Database="Db",

    [string]$ServerInstance="localhost\sqlexpress"

)



$sqlCmd="exec UpdateConfigFile '$FilePath'"

Write-Debug "invoke-SqlCmd: $sqlcmd"

Invoke-Sqlcmd -ServerInstance $ServerInstance -Database $Database -Query $sqlCmd -QueryTimeout 65000

Write-Host "File uploaded over Default Configuration !"

Monday, June 04, 2018

mysql auf raspi

login von cmd:
mysql -u root -p

show databases;


Friday, May 18, 2018

c# CallerMemberName attribute gibt namen der aufrufender methode zurück

    private string HelpMe([CallerMemberName] string param = "")
    {
        return param;
    }

Wednesday, May 09, 2018

power shell debug verbose

dir variable:*pref*



$DebugPreference = "Continue"

 $VerbosePreference = "Continue"

Programmpfad herausfinden in shell (where in cmd oder power shell)

linux / unix: which
windows cmd: where.exe
power shell: where.exe

n powershell muß man where.exe schreiben, da where abkürzung für Where-Object ist