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


Monday, May 07, 2018

Getting __MigrationHistory Table

                 HistoryContext hc = new HistoryContext(myContext.Database.Connection,"dbo");
                    var migrations = hc.History.ToList();

Thursday, April 19, 2018

simple sql server merge for insert or update for single row

merge targetTableName as target
using (values (@Key)) as source (keyname)
on [Key]=source.keyname
when matched then
update set bla=@bla
when not matched then
insert ([key], bla)
values (@key, @bla)

Flags


      [Flags]
        public enum SettingFlags : long
        {
            /// <summary>
            /// hidden in config tool for normal users
            /// </summary>
            myflag = 0b1,
            AdvancedSetting = 0b10
        }

       [NotMapped]
        public bool AdvancedSetting
        {
            get => Flags.HasFlag(SettingFlags.AdvancedSetting);
            set => Flags=SetFlag(Flags, value, SettingFlags.AdvancedSetting);
        }

        public static SettingFlags SetFlag(SettingFlags flags, bool value, SettingFlags flag)
        {
            if (value)
                flags |= flag;
            else
                flags &= flag;
            return flags;
        }





oldschool:
        private bool GetBit(SettingFlags position)
        {
            var pos = (byte)position;
            var mask = (1 << pos);
            var bit = Flags & mask;
            return 0<bit ;
        }

        private void SetBit(bool value, SettingFlags position)
        {
            var pos = (byte) position;
            var mask = (1 << pos);
            if (value)
                Flags |= mask;
            else
                Flags &= ~mask;
        }

Wednesday, March 07, 2018

Useful Tools and Settings for Visual Studio

Tools -> Options:

Environment -> InternationalSettings

Language

Environment -> General

Color Theme Dark

Environment -> Fonts & Colors -> Inactive Selected Item

xaml editor better visible

Projects and Solutions –> General

Track Active Item in Solution Explorer

TextEditor -> c# -> Advanced

Outlining - Collapse #regions when collapsing to definitions



Tools:

Match Margin: 
https://marketplace.visualstudio.com/items?itemName=VisualStudioProductTeam.MatchMargin


Monday, March 05, 2018

WinForm bei Bedarf in Gui Task zurück

wichtig: Gui im Gui Thread öffnen !

        /// <summary>
        /// 1) check if correct thread, if not call in correct thread
        /// 2) sets Text of Control c
        /// </summary>
        /// <param name="c"></param>
        /// <param name="text"></param>
        public void _SetText(Control c, string text)
        {
            if (this.InvokeRequired)
                this.Invoke(new Action<Control, string>(_SetText), c, text);
            else
                c.Text = text;
        }



        public void _SetMax(int max)
        {
            if (this.InvokeRequired)
                this.Invoke(new Action<int>(_SetMax),max);
            else
                progressBar1.Maximum = max;
        }

        public void _IncProgressBar()
        {
            if (this.InvokeRequired)
                this.Invoke(new Action(_IncProgressBar));
            else
                progressBar1.Value += 1;
        }

longrunning c# Task mit Fehlerbehandlung

                var t = new Task(() => { ImportFile(tablename, conStr, ofd.FileName); },TaskCreationOptions.LongRunning);
                var nextTask = t.ContinueWith(antecedent =>
                {
                    if (antecedent.IsFaulted)
                    {
                        PLog.ShowAndLogError("SqlTools.ImportFile Error: " + antecedent?.Exception?.Message +antecedent?.Exception?.InnerException?.Message);
                    }
                    else if (antecedent.IsCanceled)
                    {
                        PLog.LogWarning("SqlTools.ImportFile Canceled: ");
                    }
                    else
                    {
                        PLog.LogInfo("SqlTools.ImportFile succeeded ! ");
                    }
                });
                t.Start();

Tuesday, February 20, 2018

Visual Studio aktive Datei im Solution Explorer anzeigen

Tools - Options - Projects and Solutions - Track Active Item in Solution Explorer

Friday, February 16, 2018

windows 10 prozesse

nach dem aufsetzten fall creators 35 hintergrundprozesse, 74 windows prozesse

Monday, February 05, 2018

gamil gruppen bearbeiten

In der Kontaktansicht mehrere Kontkte auswählen, dann erscheint oben ein Gruppenicon, damit kann man die Kontakte zu Gruppen hinzufügen

Saturday, February 03, 2018

linux owndrive, flash


sudo apt-get install flashplugin-installer
sudo apt-get install owncloud-client

Friday, February 02, 2018

creating TPL Tasks c#


Task.Factory.StartNew(() => CalDaysAndSendMail(taskList), TaskCreationOptions.LongRunning);


Task has constructor from Action or Action:

Action a = myVoidMethodWithoutParameters;
Task t = new Task(a);

kurz: var t = new Task(myVoidMethodWithoutParameters);

           Action a = DoSomething;
            Task t = new Task(a,obj);

void DoSomething(object o)

from https://www.codeproject.com/articles/189374/the-basics-of-task-parallelism-via-c:

        // use an Action delegate and named method
        Task task1 = new Task(new Action(printMessage));
        // use an anonymous delegate
        Task task2 = new Task(delegate { printMessage() });
        // use a lambda expression and a named method
        Task task3 = new Task(() => printMessage());
        // use a lambda expression and an anonymous method
        Task task4 = new Task(() => { printMessage() });:

    private static void printMessage() {
        Console.WriteLine("Hello, world!");
    }

Thursday, February 01, 2018

Shortcuts

WINDOWS X, C ... Computerverwaltung
WINDOWS I ... neue Systemeinstellungs App
WINDOWS Q Cortana

Wednesday, January 31, 2018

Rechner aufräumen / Bereinigen, Performance

Services abdrehen:
Adobe

Deinstallieren:
Bonjour Apple Dienst

Einstellungs App / Persionalisierung / Farben / unten: Transparenz abschalten
Windows Taste + Pause => erweiterte Systemeinstellungen / Erweitert / Visuelle Effekte

Friday, January 26, 2018

sql server FileTable: Create Path

 
DECLARE @Val as nvarchar(4000)
DECLARE @NextVal as nvarchar(4000)
DECLARE @Pathlocator as hierarchyid = NULL
DECLARE @ParentLocator as hierarchyid = NULL
DECLARE @LastChildLocator as hierarchyid =NULL
DECLARE curInserted CURSOR LOCAL FOR  (select * from STRING_SPLIT('a1\b2\c1.txt','\'))
OPEN curInserted
FETCH NEXT FROM curInserted INTO @NextVal
SET @Val=@NextVal
WHILE (@@FETCH_STATUS = 0)
BEGIN
FETCH NEXT FROM curInserted INTO @NextVal

--check if Directory named Val already there (in Dir with parentLocator)
if (@ParentLocator is null)
BEGIN --------- root level => need parent_Path_locator is null
SET @Pathlocator = (select path_locator from MyFile where name like @Val and  parent_Path_locator is null ) -- from main Dir
SET @LastChildLocator = (select top 1 path_locator from MyFile where parent_Path_locator is null order by path_locator desc) -- get latest child
SET @ParentLocator = hierarchyid::GetRoot()
END
ELSE ----- not root level - query with parent_Path_locator = @ParentLocator
BEGIN
SET @Pathlocator = (select path_locator from MyFile where name like @Val and  parent_Path_locator = @ParentLocator ) -- from subdir
SET @LastChildLocator = (select top 1 path_locator from MyFile where parent_Path_locator=@ParentLocator order by path_locator desc) -- get latest child
END

if (@Pathlocator is null) --doesn't exist => have to create
BEGIN
-- get new PathLocator in parent Folder
SET @Pathlocator = @ParentLocator.GetDescendant(@LastChildLocator,NULL)
if (@@FETCH_STATUS = 0) -- not the last entry => its a dir
BEGIN
PRINT 'Create SubDir:' + @Val
INSERT INTO [dbo].MyFile ([name],is_directory,path_locator) SELECT @Val, 1, @Pathlocator  -- insert next child
END
ELSE --last entry =>  file
BEGIN
PRINT 'Create File:' + @Val
INSERT INTO [dbo].MyFile ([name],[file_stream],path_locator) SELECT @Val, CONVERT(VARBINARY(MAX),'TestFileText'), @Pathlocator  -- insert next child
END
END
ELSE
BEGIN
PRINT @Val +' already exists ...'
END
SET @Val=@NextVal
SET @ParentLocator = @Pathlocator
END --WHILE
CLOSE curInserted


select file_stream.GetFileNamespacePath() as RelativePath,  * from MyFile order by creation_time desc
select * from vMyFile where file_stream is null

Thursday, January 25, 2018

sql server: FileTable and hierarchyid, insert folders and files into filetable by tsql

-- Filetablename: MyFile


--create testfolder
INSERT INTO MyFile (name, is_directory)   VALUES ('testFolder', 1)

--insert first file into testfolder:
DECLARE @ParentLocator as hierarchyid = (select path_locator from MyFile where parent_Path_locator is NULL and name like 'testfolder') --get parent
INSERT INTO [dbo].MyFile ([name],[file_stream],path_locator) SELECT 't2.txt', CONVERT(VARBINARY(MAX),'TestFileText'), @ParentLocator.GetDescendant(NULL,NULL) -- insert next child

DECLARE @ParentLocator as hierarchyid = (select path_locator from MyFile where parent_Path_locator is NULL and name like 'testfolder') --get parent

DECLARE @Child1Locator as hierarchyid = (select top 1 path_locator from MyFile where parent_Path_locator=@ParentLocator order by path_locator desc) -- get latest child

INSERT INTO [dbo].MyFile ([name],[file_stream],path_locator) SELECT 't2.txt', CONVERT(VARBINARY(MAX),'TestFileText'), @ParentLocator.GetDescendant(@Child1Locator,NULL) -- insert next child



sql server STRING_SPLIT

--select * from STRING_SPLIT('\dir1\d2\test.txt','\')


 
DECLARE @Val as nvarchar(4000)
DECLARE curInserted CURSOR LOCAL FOR  (select * from STRING_SPLIT('\dir1\d2\test.txt','\'))
OPEN curInserted
FETCH NEXT FROM curInserted INTO @Val
WHILE (@@FETCH_STATUS = 0)
BEGIN
PRINT @Val
  FETCH NEXT FROM curInserted INTO @Val
END
CLOSE curInserted