www.inqu.de




.NET User Group Dresden

            Real World Scenario
 Deeplinking in eine WinForms-Anwendung

               01.03.2012
         InQu Informatics GmbH
             Marco Wagner
www.inqu.de


die vorhandene Anwendung

 unternehmensinternes Bestellsystem
 WinForms-Client auf Terminalserver




                            Marco Wagner | InQu Informatics GmbH | http://inqu.de | http://raumwolken.de
www.inqu.de


das Ziel

 Migration ins Web
 neue Features
 Einsparung Terminalserver




                              Marco Wagner | InQu Informatics GmbH | http://inqu.de | http://raumwolken.de
www.inqu.de


das (Zwischen)Ergebnis

 Bestellansicht




                         Marco Wagner | InQu Informatics GmbH | http://inqu.de | http://raumwolken.de
www.inqu.de


Herausforderung

 2 Systeme
 Medienbruch Win/Web
 „nicht aus einem Guß“

 Mindestanforderung: Navigation zwischen beiden Systemen




                            Marco Wagner | InQu Informatics GmbH | http://inqu.de | http://raumwolken.de
www.inqu.de


Navigation zwischen Win & Web



      vonnach   Win                          Web
      Win        Nav zw. Modulen              Hyperlink
      Web        ?                            Hyperlink




                       Marco Wagner | InQu Informatics GmbH | http://inqu.de | http://raumwolken.de
www.inqu.de


Nachrichten vom Web ins Win?

 Skype?
 MSDN?




                     Marco Wagner | InQu Informatics GmbH | http://inqu.de | http://raumwolken.de
www.inqu.de


Custom URL Protocol

 eigenen URL-Protokollhandler registrieren und
  implementieren

 http://
 ms-help://
 skype://

 shop://

   MSDN: http://msdn.microsoft.com/en-us/library/ie/aa767914(v=vs.85).aspx



                                       Marco Wagner | InQu Informatics GmbH | http://inqu.de | http://raumwolken.de
www.inqu.de


URL-Protokoll registrieren

 siehe shop.reg in MessageDispatcher.csproj




                              Marco Wagner | InQu Informatics GmbH | http://inqu.de | http://raumwolken.de
www.inqu.de


Windows Registry

HKEY_CLASSES_ROOT     COM-Registrierung; Dateitypen / Erweiterungen
HKEY_CURRENT_USER     Profil aktueller User
HKEY_LOCAL_MACHINE    Nutzerübergreifende Einstellungen
HKEY_USERS            Nutzerstamm
HKEY_CURRENT_CONFIG   Profil aktuelle Hardware




                                   Marco Wagner | InQu Informatics GmbH | http://inqu.de | http://raumwolken.de
www.inqu.de


Kommunikation über Prozessgrenzen hinweg

 Problem
    Prozesse haben separate Adressräume

 Lösungen
      Pipes
      Events / Nachrichten
      Funktionsaufrufe / Remote Procedure Calls
      Shared Memory




                                       Marco Wagner | InQu Informatics GmbH | http://inqu.de | http://raumwolken.de
www.inqu.de


Navigation von Web nach Win (auch) per Hyperlink




                        Marco Wagner | InQu Informatics GmbH | http://inqu.de | http://raumwolken.de
www.inqu.de


Demo Prototyp

 siehe Solution




                   Marco Wagner | InQu Informatics GmbH | http://inqu.de | http://raumwolken.de
www.inqu.de


Übersicht Prototyp




                     Marco Wagner | InQu Informatics GmbH | http://inqu.de | http://raumwolken.de
www.inqu.de


Pause?




         Marco Wagner | InQu Informatics GmbH | http://inqu.de | http://raumwolken.de
www.inqu.de


URL



      shop://component=Bestellungen;id=2




                      Marco Wagner | InQu Informatics GmbH | http://inqu.de | http://raumwolken.de
www.inqu.de


Nachricht

 Nachrichtentyp: WM_COPYDATA
    http://msdn.microsoft.com/en-
     us/library/windows/desktop/ms649011(v=vs.85).aspx
 Nachrichtenstruktur: COPYDATASTRUCT
    http://msdn.microsoft.com/en-
     us/library/windows/desktop/ms649010(v=vs.85).aspx

 siehe Shared




                                    Marco Wagner | InQu Informatics GmbH | http://inqu.de | http://raumwolken.de
www.inqu.de


URL via Dispatcher weiterreichen
(Nachricht senden)
 vgl. MessageDispatcher.Program
        [DllImport("user32.dll")]
        public static extern int SendMessage(
               IntPtr hWnd,
               int Msg,
               IntPtr wParam,
               ref WndMessage lParam);

 SendMessage schickt direkt ans Ziel und wartet bis
  Abarbeitung (Message Loop; synchron)
 PostMessage legt Message in Queue und kehrt sofort zurück
  (Message Queue; asynchron)
                             Marco Wagner | InQu Informatics GmbH | http://inqu.de | http://raumwolken.de
www.inqu.de


URL/ Parameter im Legacy Shop verarbeiten
(Nachricht empfangen)
 siehe WndProc in LegacyShop


protected override void WndProc(ref Message m)

…

var messageData = (WndMessage)Marshal
       .PtrToStructure(m.LParam, typeof(WndMessage));

var message = Marshal.PtrToStringUni(messageData.lpData);




                               Marco Wagner | InQu Informatics GmbH | http://inqu.de | http://raumwolken.de
www.inqu.de


proprietäre Nachrichteninterpretation

              shop://component=Bestellungen;id=2



var formatPattern =
       @"shop://component=(?<componentKey>w+);id=(?<id>d+)";
var match = Regex.Match(message, formatPattern);

var componentKey = match.Groups["componentKey"].Value;
var idText = match.Groups["id"].Value;




                               Marco Wagner | InQu Informatics GmbH | http://inqu.de | http://raumwolken.de
www.inqu.de


Fragen?




          Marco Wagner | InQu Informatics GmbH | http://inqu.de | http://raumwolken.de
www.inqu.de


Slides & Code

 demnächst auf
    http://raumwolken.de
    http://dd-dotnet.de/

 Fragen
    marco.wagner@inqu.de




                            Marco Wagner | InQu Informatics GmbH | http://inqu.de | http://raumwolken.de

Deeplinking in eine WinForms-Anwendung

  • 1.
    www.inqu.de .NET User GroupDresden Real World Scenario Deeplinking in eine WinForms-Anwendung 01.03.2012 InQu Informatics GmbH Marco Wagner
  • 2.
    www.inqu.de die vorhandene Anwendung unternehmensinternes Bestellsystem  WinForms-Client auf Terminalserver Marco Wagner | InQu Informatics GmbH | http://inqu.de | http://raumwolken.de
  • 3.
    www.inqu.de das Ziel  Migrationins Web  neue Features  Einsparung Terminalserver Marco Wagner | InQu Informatics GmbH | http://inqu.de | http://raumwolken.de
  • 4.
    www.inqu.de das (Zwischen)Ergebnis  Bestellansicht Marco Wagner | InQu Informatics GmbH | http://inqu.de | http://raumwolken.de
  • 5.
    www.inqu.de Herausforderung  2 Systeme Medienbruch Win/Web  „nicht aus einem Guß“  Mindestanforderung: Navigation zwischen beiden Systemen Marco Wagner | InQu Informatics GmbH | http://inqu.de | http://raumwolken.de
  • 6.
    www.inqu.de Navigation zwischen Win& Web vonnach Win Web Win Nav zw. Modulen Hyperlink Web ? Hyperlink Marco Wagner | InQu Informatics GmbH | http://inqu.de | http://raumwolken.de
  • 7.
    www.inqu.de Nachrichten vom Webins Win?  Skype?  MSDN? Marco Wagner | InQu Informatics GmbH | http://inqu.de | http://raumwolken.de
  • 8.
    www.inqu.de Custom URL Protocol eigenen URL-Protokollhandler registrieren und implementieren  http://  ms-help://  skype://  shop://  MSDN: http://msdn.microsoft.com/en-us/library/ie/aa767914(v=vs.85).aspx Marco Wagner | InQu Informatics GmbH | http://inqu.de | http://raumwolken.de
  • 9.
    www.inqu.de URL-Protokoll registrieren  sieheshop.reg in MessageDispatcher.csproj Marco Wagner | InQu Informatics GmbH | http://inqu.de | http://raumwolken.de
  • 10.
    www.inqu.de Windows Registry HKEY_CLASSES_ROOT COM-Registrierung; Dateitypen / Erweiterungen HKEY_CURRENT_USER Profil aktueller User HKEY_LOCAL_MACHINE Nutzerübergreifende Einstellungen HKEY_USERS Nutzerstamm HKEY_CURRENT_CONFIG Profil aktuelle Hardware Marco Wagner | InQu Informatics GmbH | http://inqu.de | http://raumwolken.de
  • 11.
    www.inqu.de Kommunikation über Prozessgrenzenhinweg  Problem  Prozesse haben separate Adressräume  Lösungen  Pipes  Events / Nachrichten  Funktionsaufrufe / Remote Procedure Calls  Shared Memory Marco Wagner | InQu Informatics GmbH | http://inqu.de | http://raumwolken.de
  • 12.
    www.inqu.de Navigation von Webnach Win (auch) per Hyperlink Marco Wagner | InQu Informatics GmbH | http://inqu.de | http://raumwolken.de
  • 13.
    www.inqu.de Demo Prototyp  sieheSolution Marco Wagner | InQu Informatics GmbH | http://inqu.de | http://raumwolken.de
  • 14.
    www.inqu.de Übersicht Prototyp Marco Wagner | InQu Informatics GmbH | http://inqu.de | http://raumwolken.de
  • 15.
    www.inqu.de Pause? Marco Wagner | InQu Informatics GmbH | http://inqu.de | http://raumwolken.de
  • 16.
    www.inqu.de URL shop://component=Bestellungen;id=2 Marco Wagner | InQu Informatics GmbH | http://inqu.de | http://raumwolken.de
  • 17.
    www.inqu.de Nachricht  Nachrichtentyp: WM_COPYDATA  http://msdn.microsoft.com/en- us/library/windows/desktop/ms649011(v=vs.85).aspx  Nachrichtenstruktur: COPYDATASTRUCT  http://msdn.microsoft.com/en- us/library/windows/desktop/ms649010(v=vs.85).aspx  siehe Shared Marco Wagner | InQu Informatics GmbH | http://inqu.de | http://raumwolken.de
  • 18.
    www.inqu.de URL via Dispatcherweiterreichen (Nachricht senden)  vgl. MessageDispatcher.Program [DllImport("user32.dll")] public static extern int SendMessage( IntPtr hWnd, int Msg, IntPtr wParam, ref WndMessage lParam);  SendMessage schickt direkt ans Ziel und wartet bis Abarbeitung (Message Loop; synchron)  PostMessage legt Message in Queue und kehrt sofort zurück (Message Queue; asynchron) Marco Wagner | InQu Informatics GmbH | http://inqu.de | http://raumwolken.de
  • 19.
    www.inqu.de URL/ Parameter imLegacy Shop verarbeiten (Nachricht empfangen)  siehe WndProc in LegacyShop protected override void WndProc(ref Message m) … var messageData = (WndMessage)Marshal .PtrToStructure(m.LParam, typeof(WndMessage)); var message = Marshal.PtrToStringUni(messageData.lpData); Marco Wagner | InQu Informatics GmbH | http://inqu.de | http://raumwolken.de
  • 20.
    www.inqu.de proprietäre Nachrichteninterpretation shop://component=Bestellungen;id=2 var formatPattern = @"shop://component=(?<componentKey>w+);id=(?<id>d+)"; var match = Regex.Match(message, formatPattern); var componentKey = match.Groups["componentKey"].Value; var idText = match.Groups["id"].Value; Marco Wagner | InQu Informatics GmbH | http://inqu.de | http://raumwolken.de
  • 21.
    www.inqu.de Fragen? Marco Wagner | InQu Informatics GmbH | http://inqu.de | http://raumwolken.de
  • 22.
    www.inqu.de Slides & Code demnächst auf  http://raumwolken.de  http://dd-dotnet.de/  Fragen  marco.wagner@inqu.de Marco Wagner | InQu Informatics GmbH | http://inqu.de | http://raumwolken.de