Skip to content

Commit

Permalink
io-connect-anything - cleanup, readme
Browse files Browse the repository at this point in the history
  • Loading branch information
stanislav-peichev committed Jul 8, 2024
1 parent 4d9f10a commit 644913b
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 5 deletions.
31 changes: 26 additions & 5 deletions io-connect-anything/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@

namespace io_connect_anything
{
/// <summary>
/// Demonstrates glueifying of 3rd party applications - in this case Notepad and Paint.
/// The applications are launched with a channel support and controlled by the host app, they can be saved, restored.
/// The interprocess communication to the apps is done via window messages and windows clipboard.
/// </summary>
internal class Program
{
[DllImport("user32.dll", SetLastError = true)]
Expand All @@ -32,6 +37,14 @@ static void Main(string[] args)
Dispatcher.Run();
}

/// <summary>
/// Renders text to image
/// </summary>
/// <param name="text"></param>
/// <param name="font"></param>
/// <param name="textColor"></param>
/// <param name="backColor"></param>
/// <returns></returns>
public static Image DrawText(string text, Font font, Color textColor, Color backColor)
{
if (text == null)
Expand Down Expand Up @@ -61,7 +74,12 @@ public static Image DrawText(string text, Font font, Color textColor, Color back
}
}

public static void DrawTextAndPaste(string text, IntPtr intPtr)
/// <summary>
/// Simple routine to draw text on image and paste it to a window given by its handle
/// </summary>
/// <param name="text"></param>
/// <param name="windowHandle"></param>
public static void DrawTextAndPaste(string text, IntPtr windowHandle)
{
var img = DrawText(text, new Font("Arial", 16), Color.Black, Color.White);
if (img == null)
Expand All @@ -70,7 +88,7 @@ public static void DrawTextAndPaste(string text, IntPtr intPtr)
}

Clipboard.SetImage(img);
Win32.SetForegroundWindow(intPtr);
Win32.SetForegroundWindow(windowHandle);
Thread.Sleep(100);
SendKeys.SendWait("^v");
}
Expand All @@ -85,7 +103,10 @@ private static async void MainThread()
// we're just launcher for other apps, so we don't need to be saved and restored
// otherwise we will be closed upon restoration
// if this is desired - put this to false
IgnoreFromLayouts = true
IgnoreFromLayouts = true,
// the factory app can be marked as singleton, to make sure there's only one instance
// this is up to the developer
AllowMultiple = false
}
});
Console.WriteLine(":::glue ready");
Expand All @@ -112,7 +133,7 @@ await glue.AppManager.RegisterAppFactoryAsync<object, LambdaApp<string>, string,
ChannelChanged = (channelContext, channel, arg3) =>
{
// or read from channelContext.GetValue<string>("partyPortfolio.ric");
Win32.SendMessage(editHandle, Win32.WM_SETTEXT, IntPtr.Zero, channel.Name);
Win32.SendMessage(editHandle, Win32.WM_SETTEXT, IntPtr.Zero, channel?.Name);
},
ChannelUpdate = (channelContext, channel, arg3) =>
{
Expand Down Expand Up @@ -161,7 +182,7 @@ await glue.AppManager.RegisterAppFactoryAsync<object, LambdaApp<string>, string,
GetState = () => Guid.NewGuid().ToString("N").AsCompletedTask()
};
});

Console.WriteLine(":::io-connect-anything ready");
}
}
Expand Down
Binary file added io-connect-anything/launch-anything.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions io-connect-anything/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# io-connect-anything

This repo contains a simple .net framework console application demonstrates glueifying of 3rd party applications - in this case Notepad and Paint.

### Notes:

- The applications are launched with a channel support and controlled by the host app, they can be saved, restored.
- The interprocess communication to the apps is done via window messages and windows clipboard.
- LambdaApp is a simple lambda implementation of the IGlueApp nomenclature to ease the implementation
- The main logic is inside the child factories : see _glue.AppManager.RegisterAppFactoryAsync_

## Images:

### You can launch any app and stick it in another io-connect group, with channel support and consume/publish any data.

![Launch anything](launch-anything.png)

### The apps can be then restored with the appropriate saved context.

![Restore anything](restore-anything.png)
Binary file added io-connect-anything/restore-anything.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 644913b

Please sign in to comment.